/[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 1509 by capela, Thu Nov 22 11:10:44 2007 UTC revision 1510 by capela, Thu Nov 22 14:17:24 2007 UTC
# Line 956  qsamplerDevice& qsamplerDeviceItem::devi Line 956  qsamplerDevice& qsamplerDeviceItem::devi
956  AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent )  AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent )
957          : QAbstractTableModel(pParent), m_bEditable(false)          : QAbstractTableModel(pParent), m_bEditable(false)
958  {  {
959          m_params = NULL;          m_pParams = NULL;
960  }  }
961    
962    
963  int AbstractDeviceParamModel::rowCount ( const QModelIndex& /*parent*/) const  int AbstractDeviceParamModel::rowCount ( const QModelIndex& /*parent*/) const
964  {  {
965          //std::cout << "model size=" << params.size() << "\n" << std::flush;          //std::cout << "model size=" << params.size() << "\n" << std::flush;
966          return (m_params) ? m_params->size() : 0;          return (m_pParams ? m_pParams->size() : 0);
967  }  }
968    
969    
# Line 999  QVariant AbstractDeviceParamModel::heade Line 999  QVariant AbstractDeviceParamModel::heade
999    
1000    
1001  void AbstractDeviceParamModel::refresh (  void AbstractDeviceParamModel::refresh (
1002          const qsamplerDeviceParamMap* params, bool bEditable )          const qsamplerDeviceParamMap* pParams, bool bEditable )
1003  {  {
1004          m_params    = params;          m_pParams   = pParams;
1005          m_bEditable = bEditable;          m_bEditable = bEditable;
1006          // inform the outer world (QTableView) that our data changed          // inform the outer world (QTableView) that our data changed
1007          QAbstractTableModel::reset();          QAbstractTableModel::reset();
# Line 1010  void AbstractDeviceParamModel::refresh ( Line 1010  void AbstractDeviceParamModel::refresh (
1010    
1011  void AbstractDeviceParamModel::clear (void)  void AbstractDeviceParamModel::clear (void)
1012  {  {
1013          m_params = NULL;          m_pParams = NULL;
1014          // inform the outer world (QTableView) that our data changed          // inform the outer world (QTableView) that our data changed
1015          QAbstractTableModel::reset();          QAbstractTableModel::reset();
1016  }  }
# Line 1023  void AbstractDeviceParamModel::clear (vo Line 1023  void AbstractDeviceParamModel::clear (vo
1023  DeviceParamModel::DeviceParamModel ( QObject *pParent )  DeviceParamModel::DeviceParamModel ( QObject *pParent )
1024          : AbstractDeviceParamModel(pParent)          : AbstractDeviceParamModel(pParent)
1025  {  {
1026          m_device = NULL;          m_pDevice = NULL;
1027  }  }
1028    
1029  QVariant DeviceParamModel::data (  QVariant DeviceParamModel::data (
# Line 1036  QVariant DeviceParamModel::data ( Line 1036  QVariant DeviceParamModel::data (
1036                  return QVariant();                  return QVariant();
1037    
1038          DeviceParameterRow item;          DeviceParameterRow item;
1039          item.name  = m_params->keys()[index.row()];          item.name  = m_pParams->keys()[index.row()];
1040          item.param = (*m_params)[item.name];          item.param = (*m_pParams)[item.name];
1041          item.alive = m_device != NULL && m_device->deviceID() >= 0;          item.alive = (m_pDevice && m_pDevice->deviceID() >= 0);
1042    
1043          return QVariant::fromValue(item);          return QVariant::fromValue(item);
1044  }  }
# Line 1050  bool DeviceParamModel::setData ( Line 1050  bool DeviceParamModel::setData (
1050          if (!index.isValid())          if (!index.isValid())
1051                  return false;                  return false;
1052    
1053          QString key = m_params->keys()[index.row()];          QString key = m_pParams->keys()[index.row()];
1054          //m_params[key].value = value.toString();          //m_pParams[key].value = value.toString();
1055          m_device->setParam(key, value.toString());          m_pDevice->setParam(key, value.toString());
1056          emit dataChanged(index, index);          emit dataChanged(index, index);
1057          return true;          return true;
1058  }  }
# Line 1060  bool DeviceParamModel::setData ( Line 1060  bool DeviceParamModel::setData (
1060    
1061  void DeviceParamModel::refresh ( qsamplerDevice* pDevice, bool bEditable )  void DeviceParamModel::refresh ( qsamplerDevice* pDevice, bool bEditable )
1062  {  {
1063          m_device = pDevice;          m_pDevice = pDevice;
1064          AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable);          AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable);
1065  }  }
1066    
# Line 1068  void DeviceParamModel::refresh ( qsample Line 1068  void DeviceParamModel::refresh ( qsample
1068  void DeviceParamModel::clear (void)  void DeviceParamModel::clear (void)
1069  {  {
1070          AbstractDeviceParamModel::clear();          AbstractDeviceParamModel::clear();
1071          m_device = NULL;          m_pDevice = NULL;
1072  }  }
1073    
1074    
# Line 1079  void DeviceParamModel::clear (void) Line 1079  void DeviceParamModel::clear (void)
1079  PortParamModel::PortParamModel ( QObject *pParent)  PortParamModel::PortParamModel ( QObject *pParent)
1080          : AbstractDeviceParamModel(pParent)          : AbstractDeviceParamModel(pParent)
1081  {  {
1082          m_port = NULL;          m_pPort = NULL;
1083  }  }
1084    
1085  QVariant PortParamModel::data ( const QModelIndex &index, int role ) const  QVariant PortParamModel::data ( const QModelIndex &index, int role ) const
# Line 1091  QVariant PortParamModel::data ( const QM Line 1091  QVariant PortParamModel::data ( const QM
1091                  return QVariant();                  return QVariant();
1092    
1093          DeviceParameterRow item;          DeviceParameterRow item;
1094          item.name  = m_params->keys()[index.row()];          item.name  = m_pParams->keys()[index.row()];
1095          item.param = (*m_params)[item.name];          item.param = (*m_pParams)[item.name];
1096          item.alive = m_port != NULL && m_port->portID() >= 0;          item.alive = (m_pPort && m_pPort->portID() >= 0);
1097    
1098          return QVariant::fromValue(item);          return QVariant::fromValue(item);
1099  }  }
# Line 1105  bool PortParamModel::setData ( Line 1105  bool PortParamModel::setData (
1105          if (!index.isValid())          if (!index.isValid())
1106                  return false;                  return false;
1107    
1108          QString key = m_params->keys()[index.row()];          QString key = m_pParams->keys()[index.row()];
1109          //params[key].value = value.toString();          //params[key].value = value.toString();
1110          m_port->setParam(key, value.toString());          m_pPort->setParam(key, value.toString());
1111          emit dataChanged(index, index);          emit dataChanged(index, index);
1112          return true;          return true;
1113  }  }
# Line 1115  bool PortParamModel::setData ( Line 1115  bool PortParamModel::setData (
1115    
1116  void PortParamModel::refresh ( qsamplerDevicePort* pPort, bool bEditable )  void PortParamModel::refresh ( qsamplerDevicePort* pPort, bool bEditable )
1117  {  {
1118          m_port = pPort;          m_pPort = pPort;
1119          AbstractDeviceParamModel::refresh(&m_port->params(), bEditable);          AbstractDeviceParamModel::refresh(&pPort->params(), bEditable);
1120  }  }
1121    
1122    
1123  void PortParamModel::clear (void)  void PortParamModel::clear (void)
1124  {  {
1125          AbstractDeviceParamModel::clear();          AbstractDeviceParamModel::clear();
1126          m_port = NULL;          m_pPort = NULL;
1127  }  }
1128    
1129    
# Line 1155  QWidget* DeviceParamDelegate::createEdit Line 1155  QWidget* DeviceParamDelegate::createEdit
1155                          return new QLabel(r.name, pParent);                          return new QLabel(r.name, pParent);
1156                  case 1: {                  case 1: {
1157                          if (r.param.type == LSCP_TYPE_BOOL) {                          if (r.param.type == LSCP_TYPE_BOOL) {
1158                                  QCheckBox* pCheckBox = new QCheckBox(pParent);                                  QCheckBox *pCheckBox = new QCheckBox(pParent);
1159                                  if (val != QString::null)                                  if (val != QString::null)
1160                                          pCheckBox->setChecked(val.toLower() == "true");                                          pCheckBox->setChecked(val.toLower() == "true");
1161                                  pCheckBox->setEnabled(bEnabled);                                  pCheckBox->setEnabled(bEnabled);
# Line 1164  QWidget* DeviceParamDelegate::createEdit Line 1164  QWidget* DeviceParamDelegate::createEdit
1164                                  QStringList opts = r.param.possibilities;                                  QStringList opts = r.param.possibilities;
1165                                  if (r.param.multiplicity)                                  if (r.param.multiplicity)
1166                                          opts.prepend(tr("(none)"));                                          opts.prepend(tr("(none)"));
1167                                  QComboBox* pComboBox = new QComboBox(pParent);                                  QComboBox *pComboBox = new QComboBox(pParent);
1168                                  pComboBox->addItems(opts);                                  pComboBox->addItems(opts);
1169                                  if (r.param.value.isEmpty())                                  if (r.param.value.isEmpty())
1170                                          pComboBox->setCurrentIndex(0);                                          pComboBox->setCurrentIndex(0);
# Line 1173  QWidget* DeviceParamDelegate::createEdit Line 1173  QWidget* DeviceParamDelegate::createEdit
1173                                  pComboBox->setEnabled(bEnabled);                                  pComboBox->setEnabled(bEnabled);
1174                                  return pComboBox;                                  return pComboBox;
1175                          } else if (r.param.type == LSCP_TYPE_INT && bEnabled) {                          } else if (r.param.type == LSCP_TYPE_INT && bEnabled) {
1176                                  QSpinBox* pSpinBox = new QSpinBox(pParent);                                  QSpinBox *pSpinBox = new QSpinBox(pParent);
1177                                  pSpinBox->setMinimum(                                  pSpinBox->setMinimum(
1178                                          (!r.param.range_min.isEmpty()) ?                                          (!r.param.range_min.isEmpty()) ?
1179                                                  r.param.range_min.toInt() : 0 // or better a negative default min value ?                                                  r.param.range_min.toInt() : 0 // or better a negative default min value ?
# Line 1185  QWidget* DeviceParamDelegate::createEdit Line 1185  QWidget* DeviceParamDelegate::createEdit
1185                                  pSpinBox->setValue(val.toInt());                                  pSpinBox->setValue(val.toInt());
1186                                  return pSpinBox;                                  return pSpinBox;
1187                          } else if (bEnabled) {                          } else if (bEnabled) {
1188                                  QLineEdit* pLineEdit = new QLineEdit(val, pParent);                                  QLineEdit *pLineEdit = new QLineEdit(val, pParent);
1189                                  return pLineEdit;                                  return pLineEdit;
1190                          } else {                          } else {
1191                                  QLabel* pLabel = new QLabel(val, pParent);                                  QLabel *pLabel = new QLabel(val, pParent);
1192                                  return pLabel;                                  return pLabel;
1193                          }                          }
1194                  }                  }
# Line 1208  void DeviceParamDelegate::setEditorData Line 1208  void DeviceParamDelegate::setEditorData
1208    
1209    
1210  void DeviceParamDelegate::setModelData ( QWidget *pEditor,  void DeviceParamDelegate::setModelData ( QWidget *pEditor,
1211          QAbstractItemModel *model, const QModelIndex& index ) const          QAbstractItemModel *pModel, const QModelIndex& index ) const
1212  {  {
1213          if (index.column() == 1) {          if (index.column() == 1) {
1214                  DeviceParameterRow r = index.model()->data(index,                  DeviceParameterRow r = index.model()->data(index,
1215                          Qt::DisplayRole).value<DeviceParameterRow> ();                          Qt::DisplayRole).value<DeviceParameterRow> ();
1216                  if (pEditor->metaObject()->className() == "QCheckBox") {                  if (pEditor->metaObject()->className() == "QCheckBox") {
1217                          QCheckBox* pCheckBox = static_cast<QCheckBox*> (pEditor);                          QCheckBox* pCheckBox = static_cast<QCheckBox*> (pEditor);
1218                          model->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked));                          pModel->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked));
1219                  } else if (pEditor->metaObject()->className() == "QComboBox") {                  } else if (pEditor->metaObject()->className() == "QComboBox") {
1220                          QComboBox* pComboBox = static_cast<QComboBox*> (pEditor);                          QComboBox* pComboBox = static_cast<QComboBox*> (pEditor);
1221                          model->setData(index, pComboBox->currentText());                          pModel->setData(index, pComboBox->currentText());
1222                  } else if (pEditor->metaObject()->className() == "QSpinBox") {                  } else if (pEditor->metaObject()->className() == "QSpinBox") {
1223                          QSpinBox* pSpinBox = static_cast<QSpinBox*> (pEditor);                          QSpinBox* pSpinBox = static_cast<QSpinBox*> (pEditor);
1224                          model->setData(index, pSpinBox->value());                          pModel->setData(index, pSpinBox->value());
1225                  } else if (pEditor->metaObject()->className() == "QLineEdit") {                  } else if (pEditor->metaObject()->className() == "QLineEdit") {
1226                          QLineEdit* pLineEdit = static_cast<QLineEdit*> (pEditor);                          QLineEdit* pLineEdit = static_cast<QLineEdit*> (pEditor);
1227                          model->setData(index, pLineEdit->text());                          pModel->setData(index, pLineEdit->text());
1228                  } else if (pEditor->metaObject()->className() == "QLabel") {                  } else if (pEditor->metaObject()->className() == "QLabel") {
1229                          QLabel* pLabel = static_cast<QLabel*> (pEditor);                          QLabel* pLabel = static_cast<QLabel*> (pEditor);
1230                          model->setData(index, pLabel->text());                          pModel->setData(index, pLabel->text());
1231                  }                  }
1232          }          }
1233  }  }

Legend:
Removed from v.1509  
changed lines
  Added in v.1510

  ViewVC Help
Powered by ViewVC