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 |
|
|
975 |
|
|
976 |
Qt::ItemFlags AbstractDeviceParamModel::flags ( const QModelIndex& /*index*/) const |
Qt::ItemFlags AbstractDeviceParamModel::flags ( const QModelIndex& /*index*/) const |
977 |
{ |
{ |
978 |
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
return Qt::ItemIsEditable | Qt::ItemIsEnabled; |
979 |
} |
} |
980 |
|
|
981 |
|
|
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(); |
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 |
} |
} |
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 ( |
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 |
} |
} |
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 |
} |
} |
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 |
|
|
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 |
|
|
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 |
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 |
} |
} |
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 |
} |
} |
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 |
|
|
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); |
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); |
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 ? |
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 |
} |
} |
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() == QString("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() == QString("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() == QString("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() == QString("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() == QString("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 |
} |
} |