/[svn]/qsampler/trunk/src/qsamplerDevice.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerDevice.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1499 by capela, Tue Nov 20 16:48:04 2007 UTC revision 1518 by schoenebeck, Fri Nov 23 21:50:01 2007 UTC
# Line 107  void qsamplerDeviceParam::setParam ( lsc Line 107  void qsamplerDeviceParam::setParam ( lsc
107  //  //
108    
109  // Constructor.  // Constructor.
110  qsamplerDevice::qsamplerDevice ( qsamplerDeviceType deviceType, int iDeviceID )  qsamplerDevice::qsamplerDevice ( DeviceType deviceType, int iDeviceID )
111  {  {
112  //      m_ports.setAutoDelete(true);  //      m_ports.setAutoDelete(true);
113    
# Line 134  qsamplerDevice::qsamplerDevice ( const q Line 134  qsamplerDevice::qsamplerDevice ( const q
134    
135    
136  // Initializer.  // Initializer.
137  void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID )  void qsamplerDevice::setDevice ( DeviceType deviceType, int iDeviceID )
138  {  {
139          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
140          if (pMainForm == NULL)          if (pMainForm == NULL)
# Line 296  int qsamplerDevice::deviceID (void) cons Line 296  int qsamplerDevice::deviceID (void) cons
296          return m_iDeviceID;          return m_iDeviceID;
297  }  }
298    
299  qsamplerDevice::qsamplerDeviceType qsamplerDevice::deviceType (void) const  qsamplerDevice::DeviceType qsamplerDevice::deviceType (void) const
300  {  {
301          return m_deviceType;          return m_deviceType;
302  }  }
# Line 316  QString qsamplerDevice::deviceName (void Line 316  QString qsamplerDevice::deviceName (void
316  {  {
317          QString sPrefix;          QString sPrefix;
318          if (m_iDeviceID >= 0)          if (m_iDeviceID >= 0)
319              sPrefix += m_sDeviceType + ' ';                  sPrefix += m_sDeviceType + ' ';
320          return sPrefix + m_sDeviceName;          return sPrefix + m_sDeviceName;
321  }  }
322    
# Line 337  bool qsamplerDevice::setParam ( const QS Line 337  bool qsamplerDevice::setParam ( const QS
337          // If the device already exists, things get immediate...          // If the device already exists, things get immediate...
338          int iRefresh = 0;          int iRefresh = 0;
339          if (m_iDeviceID >= 0 && sValue != QString::null) {          if (m_iDeviceID >= 0 && sValue != QString::null) {
340    
341                    // we need temporary byte arrrays with the final strings, because
342                    // i.e. QString::toUtf8() only returns a temporary object and the
343                    // C-style char* pointers for liblscp would immediately be invalidated
344                    QByteArray finalParamKey = sParam.toUtf8();
345                    QByteArray finalParamVal = sValue.toUtf8();
346    
347                  // Prepare parameter struct.                  // Prepare parameter struct.
348                  lscp_param_t param;                  lscp_param_t param;
349                  param.key   = (char *) sParam.toUtf8().constData();                  param.key   = (char *) finalParamKey.constData();
350                  param.value = (char *) sValue.toUtf8().constData();                  param.value = (char *) finalParamVal.constData();
351                  // Now it depends on the device type...                  // Now it depends on the device type...
352                  lscp_status_t ret = LSCP_FAILED;                  lscp_status_t ret = LSCP_FAILED;
353                  switch (m_deviceType) {                  switch (m_deviceType) {
354                  case qsamplerDevice::Audio:                  case qsamplerDevice::Audio:
355                      if (sParam == "CHANNELS") iRefresh++;                          if (sParam == "CHANNELS") iRefresh++;
356                          if ((ret = ::lscp_set_audio_device_param(pMainForm->client(),                          if ((ret = ::lscp_set_audio_device_param(pMainForm->client(),
357                                          m_iDeviceID, &param)) != LSCP_OK)                                          m_iDeviceID, &param)) != LSCP_OK)
358                                  appendMessagesClient("lscp_set_audio_device_param");                                  appendMessagesClient("lscp_set_audio_device_param");
359                          break;                          break;
360                  case qsamplerDevice::Midi:                  case qsamplerDevice::Midi:
361                      if (sParam == "PORTS") iRefresh++;                          if (sParam == "PORTS") iRefresh++;
362                          if ((ret = ::lscp_set_midi_device_param(pMainForm->client(),                          if ((ret = ::lscp_set_midi_device_param(pMainForm->client(),
363                                          m_iDeviceID, &param)) != LSCP_OK)                                          m_iDeviceID, &param)) != LSCP_OK)
364                                  appendMessagesClient("lscp_set_midi_device_param");                                  appendMessagesClient("lscp_set_midi_device_param");
# Line 401  bool qsamplerDevice::createDevice (void) Line 408  bool qsamplerDevice::createDevice (void)
408          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
409                  return false;                  return false;
410    
411          // Build the parameter list...          // we need temporary lists with the final strings, because i.e.
412          lscp_param_t *pParams = new lscp_param_t [m_params.count() + 1];          // QString::toUtf8() only returns a temporary object and the
413          int iParam = 0;          // C-style char* pointers for liblscp would immediately be invalidated
414            QList<QByteArray> finalKeys;
415            QList<QByteArray> finalVals;
416    
417          qsamplerDeviceParamMap::ConstIterator iter;          qsamplerDeviceParamMap::ConstIterator iter;
418          for (iter = m_params.begin(); iter != m_params.end(); ++iter) {          for (iter = m_params.begin(); iter != m_params.end(); ++iter) {
419                  if (iter.value().value == QString::null) continue;                  if (iter.value().value == QString::null) continue;
420                  pParams[iParam].key   = (char *) iter.key().toUtf8().constData();                  finalKeys.push_back(iter.key().toUtf8());
421                  pParams[iParam].value = (char *) iter.value().value.toUtf8().constData();                  finalVals.push_back(iter.value().value.toUtf8());
422                  ++iParam;          }
423    
424            // yeah, we DO HAVE to do the two loops separately !
425    
426            // Build the parameter list...
427            lscp_param_t *pParams = new lscp_param_t [finalKeys.count() + 1];
428            int iParam;
429            for (iParam = 0; iParam < finalKeys.count(); iParam++) {
430                    pParams[iParam].key   = (char *) finalKeys[iParam].constData();
431                    pParams[iParam].value = (char *) finalVals[iParam].constData();
432          }          }
433          // Null terminated.          // Null terminated.
434          pParams[iParam].key   = NULL;          pParams[iParam].key   = NULL;
# Line 492  int qsamplerDevice::refreshParams (void) Line 511  int qsamplerDevice::refreshParams (void)
511  {  {
512          // This should only make sense for scratch devices...          // This should only make sense for scratch devices...
513          if (m_iDeviceID >= 0)          if (m_iDeviceID >= 0)
514              return 0;                  return 0;
515          // Refresh all parameters that have dependencies...          // Refresh all parameters that have dependencies...
516          int iParams = 0;          int iParams = 0;
517          qsamplerDeviceParamMap::ConstIterator iter;          qsamplerDeviceParamMap::ConstIterator iter;
# Line 508  int qsamplerDevice::refreshPorts (void) Line 527  int qsamplerDevice::refreshPorts (void)
527  {  {
528          // This should only make sense for actual devices...          // This should only make sense for actual devices...
529          if (m_iDeviceID < 0)          if (m_iDeviceID < 0)
530              return 0;                  return 0;
531          // Port/channel count determination...          // Port/channel count determination...
532          int iPorts = 0;          int iPorts = 0;
533          switch (m_deviceType) {          switch (m_deviceType) {
# Line 536  int qsamplerDevice::refreshDepends ( con Line 555  int qsamplerDevice::refreshDepends ( con
555  {  {
556          // This should only make sense for scratch devices...          // This should only make sense for scratch devices...
557          if (m_iDeviceID >= 0)          if (m_iDeviceID >= 0)
558              return 0;                  return 0;
559          // Refresh all parameters that depend on this one...          // Refresh all parameters that depend on this one...
560          int iDepends = 0;          int iDepends = 0;
561          qsamplerDeviceParamMap::ConstIterator iter;          qsamplerDeviceParamMap::ConstIterator iter;
# Line 569  int qsamplerDevice::refreshParam ( const Line 588  int qsamplerDevice::refreshParam ( const
588          // Build dependency list...          // Build dependency list...
589          lscp_param_t *pDepends = new lscp_param_t [param.depends.count() + 1];          lscp_param_t *pDepends = new lscp_param_t [param.depends.count() + 1];
590          int iDepend = 0;          int iDepend = 0;
591          QStringList::ConstIterator iter;  
592          for (iter = param.depends.begin(); iter != param.depends.end(); ++iter) {          // we need temporary lists with the final strings, because i.e.
593                  const QString& sDepend = *iter;          // QString::toUtf8() only returns a temporary object and the
594                  pDepends[iDepend].key   = (char *) sDepend.toUtf8().constData();          // C-style char* pointers for liblscp would immediately be invalidated
595                  pDepends[iDepend].value = (char *) m_params[sDepend.toUpper()].value          QList<QByteArray> finalKeys;
596                          .toUtf8().constData();          QList<QByteArray> finalVals;
597            for (int i = 0; i < param.depends.count(); i++) {
598                    const QString& sDepend = param.depends[i];
599                    finalKeys.push_back(sDepend.toUtf8());
600                    finalVals.push_back(m_params[sDepend.toUpper()].value.toUtf8());
601            }
602            // yeah, we DO HAVE to do those two loops separately !
603            for (int i = 0; i < param.depends.count(); i++) {
604                    pDepends[iDepend].key   = (char *) finalKeys[i].constData();
605                    pDepends[iDepend].value = (char *) finalVals[i].constData();
606                  ++iDepend;                  ++iDepend;
607          }          }
608          // Null terminated.          // Null terminated.
# Line 658  void qsamplerDevice::appendMessagesClien Line 686  void qsamplerDevice::appendMessagesClien
686    
687  // Device ids enumerator.  // Device ids enumerator.
688  int *qsamplerDevice::getDevices ( lscp_client_t *pClient,  int *qsamplerDevice::getDevices ( lscp_client_t *pClient,
689          qsamplerDeviceType deviceType )          DeviceType deviceType )
690  {  {
691          int *piDeviceIDs = NULL;          int *piDeviceIDs = NULL;
692          switch (deviceType) {          switch (deviceType) {
# Line 677  int *qsamplerDevice::getDevices ( lscp_c Line 705  int *qsamplerDevice::getDevices ( lscp_c
705    
706  // Driver names enumerator.  // Driver names enumerator.
707  QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient,  QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient,
708          qsamplerDeviceType deviceType )          DeviceType deviceType )
709  {  {
710          QStringList drivers;          QStringList drivers;
711    
# Line 821  bool qsamplerDevicePort::setParam ( cons Line 849  bool qsamplerDevicePort::setParam ( cons
849          // If the device already exists, things get immediate...          // If the device already exists, things get immediate...
850          int iRefresh = 0;          int iRefresh = 0;
851          if (m_device.deviceID() >= 0 && m_iPortID >= 0) {          if (m_device.deviceID() >= 0 && m_iPortID >= 0) {
852    
853                    // we need temporary byte arrrays with the final strings, because
854                    // i.e. QString::toUtf8() only returns a temporary object and the
855                    // C-style char* pointers for liblscp would immediately be invalidated
856                    QByteArray finalParamKey = sParam.toUtf8();
857                    QByteArray finalParamVal = sValue.toUtf8();
858    
859                  // Prepare parameter struct.                  // Prepare parameter struct.
860                  lscp_param_t param;                  lscp_param_t param;
861                  param.key   = (char *) sParam.toUtf8().constData();                  param.key   = (char *) finalParamKey.constData();
862                  param.value = (char *) sValue.toUtf8().constData();                  param.value = (char *) finalParamVal.constData();
863                  // Now it depends on the device type...                  // Now it depends on the device type...
864                  lscp_status_t ret = LSCP_FAILED;                  lscp_status_t ret = LSCP_FAILED;
865                  switch (m_device.deviceType()) {                  switch (m_device.deviceType()) {
# Line 864  bool qsamplerDevicePort::setParam ( cons Line 899  bool qsamplerDevicePort::setParam ( cons
899    
900  // Constructors.  // Constructors.
901  qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidget* pTreeWidget,  qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidget* pTreeWidget,
902          qsamplerDevice::qsamplerDeviceType deviceType )          qsamplerDevice::DeviceType deviceType )
903          : QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM),          : QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM),
904        m_device(deviceType)          m_device(deviceType)
905  {  {
906          switch(m_device.deviceType()) {          switch(m_device.deviceType()) {
907          case qsamplerDevice::Audio:          case qsamplerDevice::Audio:
# Line 883  qsamplerDeviceItem::qsamplerDeviceItem ( Line 918  qsamplerDeviceItem::qsamplerDeviceItem (
918  }  }
919    
920  qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidgetItem* pItem,  qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidgetItem* pItem,
921          qsamplerDevice::qsamplerDeviceType deviceType,          qsamplerDevice::DeviceType deviceType,
922          int iDeviceID )          int iDeviceID )
923          : QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM),          : QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM),
924        m_device(deviceType, iDeviceID)          m_device(deviceType, iDeviceID)
925  {  {
926          switch(m_device.deviceType()) {          switch(m_device.deviceType()) {
927          case qsamplerDevice::Audio:          case qsamplerDevice::Audio:
# Line 918  qsamplerDevice& qsamplerDeviceItem::devi Line 953  qsamplerDevice& qsamplerDeviceItem::devi
953  // AbstractDeviceParamModel - data model base class for device parameters  // AbstractDeviceParamModel - data model base class for device parameters
954  //  //
955    
956  AbstractDeviceParamModel::AbstractDeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) {  AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent )
957      params = NULL;          : QAbstractTableModel(pParent), m_bEditable(false)
958    {
959            m_pParams = NULL;
960  }  }
961    
962  int AbstractDeviceParamModel::rowCount(const QModelIndex& /*parent*/) const {  
963      //std::cout << "model size=" << params.size() << "\n" << std::flush;  int AbstractDeviceParamModel::rowCount ( const QModelIndex& /*parent*/) const
964      return (params) ? params->size() : 0;  {
965            //std::cout << "model size=" << params.size() << "\n" << std::flush;
966            return (m_pParams ? m_pParams->size() : 0);
967  }  }
968    
969  int AbstractDeviceParamModel::columnCount(const QModelIndex& /*parent*/) const {  
970      return 3;  int AbstractDeviceParamModel::columnCount ( const QModelIndex& /*parent*/) const
971    {
972            return 3;
973  }  }
974    
975  Qt::ItemFlags AbstractDeviceParamModel::flags(const QModelIndex& /*index*/) const {  
976      return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;  Qt::ItemFlags AbstractDeviceParamModel::flags ( const QModelIndex& /*index*/) const
977    {
978            return Qt::ItemIsEditable | Qt::ItemIsEnabled;
979  }  }
980    
 QVariant AbstractDeviceParamModel::data(const QModelIndex &index, int role) const {  
     if (!index.isValid()) {  
         //std::cout << "inavlid device model index\n" << std::flush;  
         return QVariant();  
     }  
     if (role != Qt::DisplayRole) {  
         //std::cout << "inavlid display role\n" << std::flush;  
         return QVariant();  
     }  
981    
982      DeviceParameterRow item;  QVariant AbstractDeviceParamModel::headerData (
983      item.name  = params->keys()[index.row()];          int section, Qt::Orientation orientation, int role) const
984      item.param = (*params)[item.name];  {
985            if (role != Qt::DisplayRole)
986                    return QVariant();
987    
988      //std::cout << "item["<<index.row()<<"]=[" << item.name.toUtf8().constData() << "]\n" << std::flush;          if (orientation == Qt::Horizontal) {
989                    switch (section) {
990                            case 0:  return tr("Parameter");
991                            case 1:  return tr("Value");
992                            case 2:  return tr("Description");
993                            default: return QVariant();
994                    }
995            }
996    
997      return QVariant::fromValue(item);          return QVariant();
998  }  }
999    
 QVariant AbstractDeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const {  
     if (role != Qt::DisplayRole) return QVariant();  
   
     if (orientation == Qt::Horizontal) {  
         switch (section) {  
             case 0:  return tr("Parameter");  
             case 1:  return tr("Value");  
             case 2:  return tr("Description");  
             default: return QVariant();  
         }  
     }  
1000    
1001      return QVariant();  void AbstractDeviceParamModel::refresh (
1002            const qsamplerDeviceParamMap* pParams, bool bEditable )
1003    {
1004            m_pParams   = pParams;
1005            m_bEditable = bEditable;
1006            // inform the outer world (QTableView) that our data changed
1007            QAbstractTableModel::reset();
1008  }  }
1009    
 void AbstractDeviceParamModel::refresh(const qsamplerDeviceParamMap* params, bool bEditable) {  
     this->params    = params;  
     this->bEditable = bEditable;  
     // inform the outer world (QTableView) that our data changed  
     QAbstractTableModel::reset();  
 }  
1010    
1011  void AbstractDeviceParamModel::clear() {  void AbstractDeviceParamModel::clear (void)
1012      params = NULL;  {
1013      // inform the outer world (QTableView) that our data changed          m_pParams = NULL;
1014      QAbstractTableModel::reset();          // inform the outer world (QTableView) that our data changed
1015            QAbstractTableModel::reset();
1016  }  }
1017    
1018    
# Line 987  void AbstractDeviceParamModel::clear() { Line 1020  void AbstractDeviceParamModel::clear() {
1020  // DeviceParamModel - data model for device parameters (used for QTableView)  // DeviceParamModel - data model for device parameters (used for QTableView)
1021  //  //
1022    
1023  DeviceParamModel::DeviceParamModel(QObject* parent) : AbstractDeviceParamModel(parent) {  DeviceParamModel::DeviceParamModel ( QObject *pParent )
1024      device = NULL;          : AbstractDeviceParamModel(pParent)
1025    {
1026            m_pDevice = NULL;
1027  }  }
1028    
1029  bool DeviceParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {  QVariant DeviceParamModel::data (
1030      if (!index.isValid()) {          const QModelIndex &index, int role) const
1031          return false;  {
1032      }          if (!index.isValid())
1033      QString key = params->keys()[index.row()];                  return QVariant();
1034      //params[key].value = value.toString();  
1035      device->setParam(key, value.toString());          if (role != Qt::DisplayRole)
1036      emit dataChanged(index, index);                  return QVariant();
1037      return true;  
1038            DeviceParameterRow item;
1039            item.name  = m_pParams->keys()[index.row()];
1040            item.param = (*m_pParams)[item.name];
1041            item.alive = (m_pDevice && m_pDevice->deviceID() >= 0);
1042    
1043            return QVariant::fromValue(item);
1044  }  }
1045    
1046  void DeviceParamModel::refresh(qsamplerDevice* pDevice, bool bEditable) {  
1047      device = pDevice;  bool DeviceParamModel::setData (
1048      AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable);          const QModelIndex& index, const QVariant& value, int /*role*/)
1049    {
1050            if (!index.isValid())
1051                    return false;
1052    
1053            QString key = m_pParams->keys()[index.row()];
1054            //m_pParams[key].value = value.toString();
1055            m_pDevice->setParam(key, value.toString());
1056            emit dataChanged(index, index);
1057            return true;
1058  }  }
1059    
1060  void DeviceParamModel::clear() {  
1061      AbstractDeviceParamModel::clear();  void DeviceParamModel::refresh ( qsamplerDevice* pDevice, bool bEditable )
1062      device = NULL;  {
1063            m_pDevice = pDevice;
1064            AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable);
1065    }
1066    
1067    
1068    void DeviceParamModel::clear (void)
1069    {
1070            AbstractDeviceParamModel::clear();
1071            m_pDevice = NULL;
1072  }  }
1073    
1074    
# Line 1017  void DeviceParamModel::clear() { Line 1076  void DeviceParamModel::clear() {
1076  // PortParamModel - data model for port parameters (used for QTableView)  // PortParamModel - data model for port parameters (used for QTableView)
1077  //  //
1078    
1079  PortParamModel::PortParamModel(QObject* parent) : AbstractDeviceParamModel(parent) {  PortParamModel::PortParamModel ( QObject *pParent)
1080      port = NULL;          : AbstractDeviceParamModel(pParent)
1081    {
1082            m_pPort = NULL;
1083  }  }
1084    
1085  bool PortParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {  QVariant PortParamModel::data ( const QModelIndex &index, int role ) const
1086      if (!index.isValid()) {  {
1087          return false;          if (!index.isValid())
1088      }                  return QVariant();
1089      QString key = params->keys()[index.row()];  
1090      //params[key].value = value.toString();          if (role != Qt::DisplayRole)
1091      port->setParam(key, value.toString());                  return QVariant();
1092      emit dataChanged(index, index);  
1093      return true;          DeviceParameterRow item;
1094            item.name  = m_pParams->keys()[index.row()];
1095            item.param = (*m_pParams)[item.name];
1096            item.alive = (m_pPort && m_pPort->portID() >= 0);
1097    
1098            return QVariant::fromValue(item);
1099  }  }
1100    
1101  void PortParamModel::refresh(qsamplerDevicePort* pPort, bool bEditable) {  
1102      port = pPort;  bool PortParamModel::setData (
1103      AbstractDeviceParamModel::refresh(&pPort->params(), bEditable);          const QModelIndex& index, const QVariant& value, int /*role*/)
1104    {
1105            if (!index.isValid())
1106                    return false;
1107    
1108            QString key = m_pParams->keys()[index.row()];
1109            //params[key].value = value.toString();
1110            m_pPort->setParam(key, value.toString());
1111            emit dataChanged(index, index);
1112            return true;
1113  }  }
1114    
1115  void PortParamModel::clear() {  
1116      AbstractDeviceParamModel::clear();  void PortParamModel::refresh ( qsamplerDevicePort* pPort, bool bEditable )
1117      port = NULL;  {
1118            m_pPort = pPort;
1119            AbstractDeviceParamModel::refresh(&pPort->params(), bEditable);
1120    }
1121    
1122    
1123    void PortParamModel::clear (void)
1124    {
1125            AbstractDeviceParamModel::clear();
1126            m_pPort = NULL;
1127  }  }
1128    
1129    
# Line 1047  void PortParamModel::clear() { Line 1131  void PortParamModel::clear() {
1131  // DeviceParamDelegate - table cell renderer for device/port parameters  // DeviceParamDelegate - table cell renderer for device/port parameters
1132  //  //
1133    
1134  DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) {  DeviceParamDelegate::DeviceParamDelegate ( QObject *pParent)
1135            : QItemDelegate(pParent)
1136    {
1137  }  }
1138    
1139  QWidget* DeviceParamDelegate::createEditor(QWidget *parent,  
1140          const QStyleOptionViewItem &/* option */,  QWidget* DeviceParamDelegate::createEditor ( QWidget *pParent,
1141          const QModelIndex& index) const          const QStyleOptionViewItem& /* option */, const QModelIndex& index ) const
1142  {  {
1143      if (!index.isValid()) {          if (!index.isValid())
1144          return NULL;                  return NULL;
1145      }  
1146            DeviceParameterRow r = index.model()->data(index,
1147      DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>();                  Qt::DisplayRole).value<DeviceParameterRow>();
1148    
1149      const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix);          const bool bEnabled = (r.alive) ? !r.param.fix : true;
1150    
1151      switch (index.column()) {          QString val = (r.alive) ? r.param.value : r.param.defaultv;
1152          case 0:  
1153              return new QLabel(r.name, parent);          switch (index.column()) {
1154          case 1: {                  case 0:
1155              if (r.param.type == LSCP_TYPE_BOOL) {                          return new QLabel(r.name, pParent);
1156                  QCheckBox* pCheckBox = new QCheckBox(parent);                  case 1: {
1157                  pCheckBox->setChecked(r.param.value.toLower() == "true");                          if (r.param.type == LSCP_TYPE_BOOL) {
1158                  pCheckBox->setEnabled(bEnabled);                                  QCheckBox *pCheckBox = new QCheckBox(pParent);
1159                  return pCheckBox;                                  if (val != QString::null)
1160              } else if (r.param.possibilities.count() > 0) {                                          pCheckBox->setChecked(val.toLower() == "true");
1161                  QStringList opts = r.param.possibilities;                                  pCheckBox->setEnabled(bEnabled);
1162                  if (r.param.multiplicity)                                  return pCheckBox;
1163                      opts.prepend(tr("(none)"));                          } else if (r.param.possibilities.count() > 0) {
1164                  QComboBox* pComboBox = new QComboBox(parent);                                  QStringList opts = r.param.possibilities;
1165                  pComboBox->addItems(opts);                                  if (r.param.multiplicity)
1166                  if (r.param.value.isEmpty())                                          opts.prepend(tr("(none)"));
1167                      pComboBox->setCurrentIndex(0);                                  QComboBox *pComboBox = new QComboBox(pParent);
1168                  else                                  pComboBox->addItems(opts);
1169                      pComboBox->setCurrentIndex(pComboBox->findText(r.param.value));                                  if (r.param.value.isEmpty())
1170                  pComboBox->setEnabled(bEnabled);                                          pComboBox->setCurrentIndex(0);
1171                  return pComboBox;                                  else
1172              } else if (r.param.type == LSCP_TYPE_INT                                          pComboBox->setCurrentIndex(pComboBox->findText(val));
1173                         && !r.param.range_min.isEmpty()                                  pComboBox->setEnabled(bEnabled);
1174                         && !r.param.range_max.isEmpty()) {                                  return pComboBox;
1175                  QSpinBox* pSpinBox = new QSpinBox(parent);                          } else if (r.param.type == LSCP_TYPE_INT && bEnabled) {
1176                  pSpinBox->setValue(r.param.value.toInt());                                  QSpinBox *pSpinBox = new QSpinBox(pParent);
1177                  pSpinBox->setMinimum(r.param.range_min.toInt());                                  pSpinBox->setMinimum(
1178                  pSpinBox->setMaximum(r.param.range_max.toInt());                                          (!r.param.range_min.isEmpty()) ?
1179                  pSpinBox->setEnabled(bEnabled);                                                  r.param.range_min.toInt() : 0 // or better a negative default min value ?
1180                  return pSpinBox;                                  );
1181              } else {                                  pSpinBox->setMaximum(
1182                  QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent);                                          (!r.param.range_max.isEmpty()) ?
1183                  pLineEdit->setEnabled(bEnabled);                                                  r.param.range_max.toInt() : (1 << 16) // or better a nigher default max value ?
1184                  return pLineEdit;                                  );
1185              }                                  pSpinBox->setValue(val.toInt());
1186          }                                  return pSpinBox;
1187          case 2:                          } else if (bEnabled) {
1188              return new QLabel(r.param.description, parent);                                  QLineEdit *pLineEdit = new QLineEdit(val, pParent);
1189          default:                                  return pLineEdit;
1190              return NULL;                          } else {
1191      }                                  QLabel *pLabel = new QLabel(val, pParent);
1192  }                                  return pLabel;
1193                            }
1194  void DeviceParamDelegate::setEditorData(QWidget* /*editor*/, const QModelIndex& /*index*/) const {                  }
1195      // unused, since we set the editor data already in createEditor()                  case 2:
1196  }                          return new QLabel(r.param.description, pParent);
1197                    default:
1198  void DeviceParamDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {                          return NULL;
1199      if (index.column() == 1) {          }
1200          DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>();  }
1201          if (r.param.type == LSCP_TYPE_BOOL) {  
1202              QCheckBox* pCheckBox = static_cast<QCheckBox*>(editor);  
1203              model->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked));  void DeviceParamDelegate::setEditorData (
1204          } else if (r.param.possibilities.count() > 0) {          QWidget* /*pEditor*/, const QModelIndex& /*index*/) const
1205              QComboBox* pComboBox = static_cast<QComboBox*>(editor);  {
1206              model->setData(index, pComboBox->currentText());          // Unused, since we set the editor data already in createEditor()
1207          } else if (r.param.type == LSCP_TYPE_INT) {  }
1208              QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor);  
1209              model->setData(index, pSpinBox->value());  
1210          } else {  void DeviceParamDelegate::setModelData ( QWidget *pEditor,
1211              QLineEdit* pLineEdit = static_cast<QLineEdit*>(editor);          QAbstractItemModel *pModel, const QModelIndex& index ) const
1212              model->setData(index, pLineEdit->text());  {
1213          }          if (index.column() == 1) {
1214      }                  DeviceParameterRow r = index.model()->data(index,
1215                            Qt::DisplayRole).value<DeviceParameterRow> ();
1216                    if (pEditor->metaObject()->className() == QString("QCheckBox")) {
1217                            QCheckBox* pCheckBox = static_cast<QCheckBox*> (pEditor);
1218                            pModel->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked));
1219                    } else if (pEditor->metaObject()->className() == QString("QComboBox")) {
1220                            QComboBox* pComboBox = static_cast<QComboBox*> (pEditor);
1221                            pModel->setData(index, pComboBox->currentText());
1222                    } else if (pEditor->metaObject()->className() == QString("QSpinBox")) {
1223                            QSpinBox* pSpinBox = static_cast<QSpinBox*> (pEditor);
1224                            pModel->setData(index, pSpinBox->value());
1225                    } else if (pEditor->metaObject()->className() == QString("QLineEdit")) {
1226                            QLineEdit* pLineEdit = static_cast<QLineEdit*> (pEditor);
1227                            pModel->setData(index, pLineEdit->text());
1228                    } else if (pEditor->metaObject()->className() == QString("QLabel")) {
1229                            QLabel* pLabel = static_cast<QLabel*> (pEditor);
1230                            pModel->setData(index, pLabel->text());
1231                    }
1232            }
1233  }  }
1234    
1235  void DeviceParamDelegate::updateEditorGeometry(QWidget* editor,  void DeviceParamDelegate::updateEditorGeometry ( QWidget *pEditor,
1236          const QStyleOptionViewItem &option, const QModelIndex &/* index */) const          const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
1237  {  {
1238      if (editor) editor->setGeometry(option.rect);          if (pEditor)
1239                    pEditor->setGeometry(option.rect);
1240  }  }
1241    
1242  // end of qsamplerDevice.cpp  // end of qsamplerDevice.cpp

Legend:
Removed from v.1499  
changed lines
  Added in v.1518

  ViewVC Help
Powered by ViewVC