/[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 1508 by schoenebeck, Thu Nov 22 02:48:41 2007 UTC
# 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) {
# 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 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 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 935  Qt::ItemFlags AbstractDeviceParamModel:: Line 970  Qt::ItemFlags AbstractDeviceParamModel::
970      return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;      return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
971  }  }
972    
 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();  
     }  
   
     DeviceParameterRow item;  
     item.name  = params->keys()[index.row()];  
     item.param = (*params)[item.name];  
   
     //std::cout << "item["<<index.row()<<"]=[" << item.name.toUtf8().constData() << "]\n" << std::flush;  
   
     return QVariant::fromValue(item);  
 }  
   
973  QVariant AbstractDeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const {  QVariant AbstractDeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const {
974      if (role != Qt::DisplayRole) return QVariant();      if (role != Qt::DisplayRole) return QVariant();
975    
# Line 991  DeviceParamModel::DeviceParamModel(QObje Line 1007  DeviceParamModel::DeviceParamModel(QObje
1007      device = NULL;      device = NULL;
1008  }  }
1009    
1010    QVariant DeviceParamModel::data(const QModelIndex &index, int role) const {
1011        if (!index.isValid()) {
1012            //std::cout << "inavlid device model index\n" << std::flush;
1013            return QVariant();
1014        }
1015        if (role != Qt::DisplayRole) {
1016            //std::cout << "inavlid display role\n" << std::flush;
1017            return QVariant();
1018        }
1019    
1020        DeviceParameterRow item;
1021        item.name  = params->keys()[index.row()];
1022        item.param = (*params)[item.name];
1023        item.alive = device != NULL && device->deviceID() >= 0;
1024    
1025        return QVariant::fromValue(item);
1026    }
1027    
1028  bool DeviceParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {  bool DeviceParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {
1029      if (!index.isValid()) {      if (!index.isValid()) {
1030          return false;          return false;
# Line 1021  PortParamModel::PortParamModel(QObject* Line 1055  PortParamModel::PortParamModel(QObject*
1055      port = NULL;      port = NULL;
1056  }  }
1057    
1058    QVariant PortParamModel::data(const QModelIndex &index, int role) const {
1059        if (!index.isValid()) {
1060            //std::cout << "inavlid device model index\n" << std::flush;
1061            return QVariant();
1062        }
1063        if (role != Qt::DisplayRole) {
1064            //std::cout << "inavlid display role\n" << std::flush;
1065            return QVariant();
1066        }
1067    
1068        DeviceParameterRow item;
1069        item.name  = params->keys()[index.row()];
1070        item.param = (*params)[item.name];
1071        item.alive = port != NULL && port->portID() >= 0;
1072    
1073        return QVariant::fromValue(item);
1074    }
1075    
1076  bool PortParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {  bool PortParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {
1077      if (!index.isValid()) {      if (!index.isValid()) {
1078          return false;          return false;
# Line 1060  QWidget* DeviceParamDelegate::createEdit Line 1112  QWidget* DeviceParamDelegate::createEdit
1112    
1113      DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>();      DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>();
1114    
1115      const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix);      const bool bEnabled = (r.alive) ? !r.param.fix : true;
1116    
1117        QString val = (r.alive) ? r.param.value : r.param.defaultv;
1118    
1119      switch (index.column()) {      switch (index.column()) {
1120          case 0:          case 0:
# Line 1068  QWidget* DeviceParamDelegate::createEdit Line 1122  QWidget* DeviceParamDelegate::createEdit
1122          case 1: {          case 1: {
1123              if (r.param.type == LSCP_TYPE_BOOL) {              if (r.param.type == LSCP_TYPE_BOOL) {
1124                  QCheckBox* pCheckBox = new QCheckBox(parent);                  QCheckBox* pCheckBox = new QCheckBox(parent);
1125                  pCheckBox->setChecked(r.param.value.toLower() == "true");                  if (val != QString::null)
1126                        pCheckBox->setChecked(val.toLower() == "true");
1127                  pCheckBox->setEnabled(bEnabled);                  pCheckBox->setEnabled(bEnabled);
1128                  return pCheckBox;                  return pCheckBox;
1129              } else if (r.param.possibilities.count() > 0) {              } else if (r.param.possibilities.count() > 0) {
# Line 1080  QWidget* DeviceParamDelegate::createEdit Line 1135  QWidget* DeviceParamDelegate::createEdit
1135                  if (r.param.value.isEmpty())                  if (r.param.value.isEmpty())
1136                      pComboBox->setCurrentIndex(0);                      pComboBox->setCurrentIndex(0);
1137                  else                  else
1138                      pComboBox->setCurrentIndex(pComboBox->findText(r.param.value));                      pComboBox->setCurrentIndex(pComboBox->findText(val));
1139                  pComboBox->setEnabled(bEnabled);                  pComboBox->setEnabled(bEnabled);
1140                  return pComboBox;                  return pComboBox;
1141              } else if (r.param.type == LSCP_TYPE_INT              } else if (r.param.type == LSCP_TYPE_INT && bEnabled) {
                        && !r.param.range_min.isEmpty()  
                        && !r.param.range_max.isEmpty()) {  
1142                  QSpinBox* pSpinBox = new QSpinBox(parent);                  QSpinBox* pSpinBox = new QSpinBox(parent);
1143                  pSpinBox->setValue(r.param.value.toInt());                  pSpinBox->setMinimum(
1144                  pSpinBox->setMinimum(r.param.range_min.toInt());                      (!r.param.range_min.isEmpty()) ?
1145                  pSpinBox->setMaximum(r.param.range_max.toInt());                          r.param.range_min.toInt() : 0 // or better a negative default min value ?
1146                  pSpinBox->setEnabled(bEnabled);                  );
1147                    pSpinBox->setMaximum(
1148                        (!r.param.range_max.isEmpty()) ?
1149                            r.param.range_max.toInt() : (1 << 16) // or better a nigher default max value ?
1150                    );
1151                    pSpinBox->setValue(val.toInt());
1152                  return pSpinBox;                  return pSpinBox;
1153              } else {              } else if (bEnabled) {
1154                  QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent);                  QLineEdit* pLineEdit = new QLineEdit(val, parent);
                 pLineEdit->setEnabled(bEnabled);  
1155                  return pLineEdit;                  return pLineEdit;
1156                } else {
1157                    QLabel* pLabel = new QLabel(val, parent);
1158                    return pLabel;
1159              }              }
1160          }          }
1161          case 2:          case 2:
# Line 1112  void DeviceParamDelegate::setEditorData( Line 1172  void DeviceParamDelegate::setEditorData(
1172  void DeviceParamDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {  void DeviceParamDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {
1173      if (index.column() == 1) {      if (index.column() == 1) {
1174          DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>();          DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>();
1175          if (r.param.type == LSCP_TYPE_BOOL) {          if (editor->metaObject()->className() == "QCheckBox") {
1176              QCheckBox* pCheckBox = static_cast<QCheckBox*>(editor);              QCheckBox* pCheckBox = static_cast<QCheckBox*>(editor);
1177              model->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked));              model->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked));
1178          } else if (r.param.possibilities.count() > 0) {          } else if (editor->metaObject()->className() == "QComboBox") {
1179              QComboBox* pComboBox = static_cast<QComboBox*>(editor);              QComboBox* pComboBox = static_cast<QComboBox*>(editor);
1180              model->setData(index, pComboBox->currentText());              model->setData(index, pComboBox->currentText());
1181          } else if (r.param.type == LSCP_TYPE_INT) {          } else if (editor->metaObject()->className() == "QSpinBox") {
1182              QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor);              QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor);
1183              model->setData(index, pSpinBox->value());              model->setData(index, pSpinBox->value());
1184          } else {          } else if (editor->metaObject()->className() == "QLineEdit") {
1185              QLineEdit* pLineEdit = static_cast<QLineEdit*>(editor);              QLineEdit* pLineEdit = static_cast<QLineEdit*>(editor);
1186              model->setData(index, pLineEdit->text());              model->setData(index, pLineEdit->text());
1187            } else if (editor->metaObject()->className() == "QLabel") {
1188                QLabel* pLabel = static_cast<QLabel*>(editor);
1189                model->setData(index, pLabel->text());
1190          }          }
1191      }      }
1192  }  }

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

  ViewVC Help
Powered by ViewVC