326 |
|
|
327 |
// If the device already exists, things get immediate... |
// If the device already exists, things get immediate... |
328 |
int iRefresh = 0; |
int iRefresh = 0; |
329 |
if (m_iDeviceID >= 0) { |
if (m_iDeviceID >= 0 && sValue != QString::null) { |
330 |
// Prepare parameter struct. |
// Prepare parameter struct. |
331 |
lscp_param_t param; |
lscp_param_t param; |
332 |
param.key = (char *) sParam.latin1(); |
param.key = (char *) sParam.latin1(); |
396 |
int iParam = 0; |
int iParam = 0; |
397 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
398 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
399 |
|
if (iter.data().value == QString::null) continue; |
400 |
pParams[iParam].key = (char *) iter.key().latin1(); |
pParams[iParam].key = (char *) iter.key().latin1(); |
401 |
pParams[iParam].value = (char *) iter.data().value.latin1(); |
pParams[iParam].value = (char *) iter.data().value.latin1(); |
402 |
++iParam; |
++iParam; |
591 |
break; |
break; |
592 |
} |
} |
593 |
if (pParamInfo) { |
if (pParamInfo) { |
594 |
param = qsamplerDeviceParam(pParamInfo, QString(param.value)); |
if (param.value != QString::null) |
595 |
|
param = qsamplerDeviceParam(pParamInfo, param.value); |
596 |
|
else |
597 |
|
param = qsamplerDeviceParam(pParamInfo, NULL); |
598 |
iRefresh++; |
iRefresh++; |
599 |
} |
} |
600 |
|
|
887 |
break; |
break; |
888 |
} |
} |
889 |
|
|
890 |
setText(1, m_device.deviceName()); |
setText(0, m_device.deviceName()); |
891 |
} |
} |
892 |
|
|
893 |
// Default destructor. |
// Default destructor. |
902 |
} |
} |
903 |
|
|
904 |
|
|
|
|
|
905 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
906 |
// qsamplerDeviceParamTable - Device parameter view table. |
// AbstractDeviceParamModel - data model base class for device parameters |
907 |
// |
// |
|
#if 0 |
|
|
// Constructor. |
|
|
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
|
|
const char *pszName ) |
|
|
: QTable(pParent, pszName) |
|
|
{ |
|
|
// Set fixed number of columns. |
|
|
QTable::setNumCols(3); |
|
|
QTable::setShowGrid(false); |
|
|
QTable::setSorting(false); |
|
|
QTable::setFocusStyle(QTable::FollowStyle); |
|
|
QTable::setSelectionMode(QTable::NoSelection); |
|
|
// No vertical header. |
|
|
QTable::verticalHeader()->hide(); |
|
|
QTable::setLeftMargin(0); |
|
|
// Initialize the fixed table column headings. |
|
|
QHeader *pHeader = QTable::horizontalHeader(); |
|
|
pHeader->setLabel(0, tr("Parameter")); |
|
|
pHeader->setLabel(1, tr("Description")); |
|
|
pHeader->setLabel(2, tr("Value")); |
|
|
// Set read-onlyness of each column |
|
|
QTable::setColumnReadOnly(0, true); |
|
|
QTable::setColumnReadOnly(1, true); |
|
|
// QTable::setColumnReadOnly(2, false); -- of course not. |
|
|
QTable::setColumnStretchable(1, true); |
|
|
} |
|
|
|
|
|
// Default destructor. |
|
|
qsamplerDeviceParamTable::~qsamplerDeviceParamTable (void) |
|
|
{ |
|
|
} |
|
|
|
|
|
|
|
|
// Common parameter table renderer. |
|
|
void qsamplerDeviceParamTable::refresh ( const qsamplerDeviceParamMap& params, |
|
|
bool bEditable ) |
|
|
{ |
|
|
// Always (re)start it empty. |
|
|
QTable::setUpdatesEnabled(false); |
|
|
QTable::setNumRows(0); |
|
|
|
|
|
// Fill the parameter table... |
|
|
QTable::insertRows(0, params.count()); |
|
|
int iRow = 0; |
|
|
qsamplerDeviceParamMap::ConstIterator iter; |
|
|
for (iter = params.begin(); iter != params.end(); ++iter) { |
|
|
const qsamplerDeviceParam& param = iter.data(); |
|
|
bool bEnabled = (bEditable || !param.fix); |
|
|
QTable::setText(iRow, 0, iter.key()); |
|
|
QTable::setText(iRow, 1, param.description); |
|
|
if (param.type == LSCP_TYPE_BOOL) { |
|
|
QStringList opts; |
|
|
opts.append(tr("false")); |
|
|
opts.append(tr("true")); |
|
|
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
|
|
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
|
|
pComboItem->setEnabled(bEnabled); |
|
|
QTable::setItem(iRow, 2, pComboItem); |
|
|
} else if (param.possibilities.count() > 0 && bEnabled) { |
|
|
QStringList opts = param.possibilities; |
|
|
if (param.multiplicity) |
|
|
opts.prepend(tr("(none)")); |
|
|
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
|
|
if (param.value.isEmpty()) |
|
|
pComboItem->setCurrentItem(0); |
|
|
else |
|
|
pComboItem->setCurrentItem(param.value); |
|
|
pComboItem->setEnabled(bEnabled); |
|
|
QTable::setItem(iRow, 2, pComboItem); |
|
|
} else if (param.type == LSCP_TYPE_INT && bEnabled |
|
|
&& !param.range_min.isEmpty() |
|
|
&& !param.range_max.isEmpty()) { |
|
|
qsamplerDeviceParamTableSpinBox *pSpinItem = |
|
|
new qsamplerDeviceParamTableSpinBox(this, |
|
|
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
|
|
param.value); |
|
|
pSpinItem->setMinValue(param.range_min.toInt()); |
|
|
pSpinItem->setMaxValue(param.range_max.toInt()); |
|
|
QTable::setItem(iRow, 2, pSpinItem); |
|
|
} else { |
|
|
qsamplerDeviceParamTableEditBox *pEditItem = |
|
|
new qsamplerDeviceParamTableEditBox(this, |
|
|
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
|
|
param.value); |
|
|
QTable::setItem(iRow, 2, pEditItem); |
|
|
} |
|
|
++iRow; |
|
|
} |
|
|
|
|
|
// Adjust optimal column widths. |
|
|
QTable::adjustColumn(0); |
|
|
QTable::adjustColumn(2); |
|
908 |
|
|
909 |
QTable::setUpdatesEnabled(true); |
AbstractDeviceParamModel::AbstractDeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) { |
910 |
QTable::updateContents(); |
params = NULL; |
911 |
} |
} |
|
#endif |
|
912 |
|
|
913 |
DeviceParamModel::DeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) { |
int AbstractDeviceParamModel::rowCount(const QModelIndex& /*parent*/) const { |
914 |
|
//std::cout << "model size=" << params.size() << "\n" << std::flush; |
915 |
|
return (params) ? params->size() : 0; |
916 |
} |
} |
917 |
|
|
918 |
int DeviceParamModel::rowCount(const QModelIndex& /*parent*/) const { |
int AbstractDeviceParamModel::columnCount(const QModelIndex& /*parent*/) const { |
919 |
return params.size(); |
return 3; |
920 |
} |
} |
921 |
|
|
922 |
int DeviceParamModel::columnCount(const QModelIndex& /*parent*/) const { |
Qt::ItemFlags AbstractDeviceParamModel::flags(const QModelIndex& /*index*/) const { |
923 |
return 3; |
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
924 |
} |
} |
925 |
|
|
926 |
QVariant DeviceParamModel::data(const QModelIndex &index, int role) const { |
QVariant AbstractDeviceParamModel::data(const QModelIndex &index, int role) const { |
927 |
if (!index.isValid()) |
if (!index.isValid()) { |
928 |
|
//std::cout << "inavlid device model index\n" << std::flush; |
929 |
return QVariant(); |
return QVariant(); |
930 |
if (role != Qt::DisplayRole) |
} |
931 |
|
if (role != Qt::DisplayRole) { |
932 |
|
//std::cout << "inavlid display role\n" << std::flush; |
933 |
return QVariant(); |
return QVariant(); |
934 |
|
} |
935 |
|
|
936 |
DeviceParameterRow item; |
DeviceParameterRow item; |
937 |
item.name = params.keys()[index.row()]; |
item.name = params->keys()[index.row()]; |
938 |
item.param = params[item.name]; |
item.param = (*params)[item.name]; |
939 |
|
|
940 |
|
//std::cout << "item["<<index.row()<<"]=[" << item.name.toLatin1().data() << "]\n" << std::flush; |
941 |
|
|
942 |
return QVariant::fromValue(item); |
return QVariant::fromValue(item); |
943 |
} |
} |
944 |
|
|
945 |
QVariant DeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const { |
QVariant AbstractDeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const { |
946 |
if (role != Qt::DisplayRole) return QVariant(); |
if (role != Qt::DisplayRole) return QVariant(); |
947 |
|
|
948 |
if (orientation == Qt::Horizontal) { |
if (orientation == Qt::Horizontal) { |
957 |
return QVariant(); |
return QVariant(); |
958 |
} |
} |
959 |
|
|
960 |
void DeviceParamModel::refresh(const qsamplerDeviceParamMap& params, bool bEditable) |
void AbstractDeviceParamModel::refresh(const qsamplerDeviceParamMap* params, bool bEditable) { |
|
{ |
|
961 |
this->params = params; |
this->params = params; |
962 |
this->bEditable = bEditable; |
this->bEditable = bEditable; |
963 |
|
// inform the outer world (QTableView) that our data changed |
964 |
|
QAbstractTableModel::reset(); |
965 |
|
} |
966 |
|
|
967 |
|
void AbstractDeviceParamModel::clear() { |
968 |
|
params = NULL; |
969 |
|
// inform the outer world (QTableView) that our data changed |
970 |
|
QAbstractTableModel::reset(); |
971 |
|
} |
972 |
|
|
973 |
|
|
974 |
|
//------------------------------------------------------------------------- |
975 |
|
// DeviceParamModel - data model for device parameters (used for QTableView) |
976 |
|
// |
977 |
|
|
978 |
|
DeviceParamModel::DeviceParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
979 |
|
device = NULL; |
980 |
|
} |
981 |
|
|
982 |
|
bool DeviceParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
983 |
|
if (!index.isValid()) { |
984 |
|
return false; |
985 |
|
} |
986 |
|
QString key = params->keys()[index.row()]; |
987 |
|
//params[key].value = value.toString(); |
988 |
|
device->setParam(key, value.toString()); |
989 |
|
emit dataChanged(index, index); |
990 |
|
return true; |
991 |
|
} |
992 |
|
|
993 |
|
void DeviceParamModel::refresh(qsamplerDevice* pDevice, bool bEditable) { |
994 |
|
device = pDevice; |
995 |
|
AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable); |
996 |
} |
} |
997 |
|
|
998 |
void DeviceParamModel::clear() { |
void DeviceParamModel::clear() { |
999 |
params.clear(); |
AbstractDeviceParamModel::clear(); |
1000 |
|
device = NULL; |
1001 |
|
} |
1002 |
|
|
1003 |
|
|
1004 |
|
//------------------------------------------------------------------------- |
1005 |
|
// PortParamModel - data model for port parameters (used for QTableView) |
1006 |
|
// |
1007 |
|
|
1008 |
|
PortParamModel::PortParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
1009 |
|
port = NULL; |
1010 |
|
} |
1011 |
|
|
1012 |
|
bool PortParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
1013 |
|
if (!index.isValid()) { |
1014 |
|
return false; |
1015 |
|
} |
1016 |
|
QString key = params->keys()[index.row()]; |
1017 |
|
//params[key].value = value.toString(); |
1018 |
|
port->setParam(key, value.toString()); |
1019 |
|
emit dataChanged(index, index); |
1020 |
|
return true; |
1021 |
|
} |
1022 |
|
|
1023 |
|
void PortParamModel::refresh(qsamplerDevicePort* pPort, bool bEditable) { |
1024 |
|
port = pPort; |
1025 |
|
AbstractDeviceParamModel::refresh(&pPort->params(), bEditable); |
1026 |
} |
} |
1027 |
|
|
1028 |
|
void PortParamModel::clear() { |
1029 |
|
AbstractDeviceParamModel::clear(); |
1030 |
|
port = NULL; |
1031 |
|
} |
1032 |
|
|
1033 |
|
|
1034 |
|
//------------------------------------------------------------------------- |
1035 |
|
// DeviceParamDelegate - table cell renderer for device/port parameters |
1036 |
|
// |
1037 |
|
|
1038 |
DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) { |
DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) { |
1039 |
} |
} |
1042 |
const QStyleOptionViewItem &/* option */, |
const QStyleOptionViewItem &/* option */, |
1043 |
const QModelIndex& index) const |
const QModelIndex& index) const |
1044 |
{ |
{ |
1045 |
|
if (!index.isValid()) { |
1046 |
|
return NULL; |
1047 |
|
} |
1048 |
|
|
1049 |
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
1050 |
|
|
1051 |
const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix); |
const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix); |
1059 |
pCheckBox->setChecked(r.param.value.lower() == "true"); |
pCheckBox->setChecked(r.param.value.lower() == "true"); |
1060 |
pCheckBox->setEnabled(bEnabled); |
pCheckBox->setEnabled(bEnabled); |
1061 |
return pCheckBox; |
return pCheckBox; |
1062 |
} else if (r.param.possibilities.count() > 0 && bEnabled) { |
} else if (r.param.possibilities.count() > 0) { |
1063 |
QStringList opts = r.param.possibilities; |
QStringList opts = r.param.possibilities; |
1064 |
if (r.param.multiplicity) |
if (r.param.multiplicity) |
1065 |
opts.prepend(tr("(none)")); |
opts.prepend(tr("(none)")); |
1071 |
pComboBox->setCurrentIndex(pComboBox->findText(r.param.value)); |
pComboBox->setCurrentIndex(pComboBox->findText(r.param.value)); |
1072 |
pComboBox->setEnabled(bEnabled); |
pComboBox->setEnabled(bEnabled); |
1073 |
return pComboBox; |
return pComboBox; |
1074 |
} else if (r.param.type == LSCP_TYPE_INT && bEnabled |
} else if (r.param.type == LSCP_TYPE_INT |
1075 |
&& !r.param.range_min.isEmpty() |
&& !r.param.range_min.isEmpty() |
1076 |
&& !r.param.range_max.isEmpty()) { |
&& !r.param.range_max.isEmpty()) { |
1077 |
QSpinBox* pSpinBox = new QSpinBox(parent); |
QSpinBox* pSpinBox = new QSpinBox(parent); |
1078 |
pSpinBox->setValue(r.param.value.toInt()); |
pSpinBox->setValue(r.param.value.toInt()); |
1079 |
pSpinBox->setMinimum(r.param.range_min.toInt()); |
pSpinBox->setMinimum(r.param.range_min.toInt()); |
1080 |
pSpinBox->setMaximum(r.param.range_max.toInt()); |
pSpinBox->setMaximum(r.param.range_max.toInt()); |
1081 |
|
pSpinBox->setEnabled(bEnabled); |
1082 |
return pSpinBox; |
return pSpinBox; |
1083 |
} else { |
} else { |
1084 |
QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent); |
QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent); |
1085 |
|
pLineEdit->setEnabled(bEnabled); |
1086 |
return pLineEdit; |
return pLineEdit; |
1087 |
} |
} |
1088 |
} |
} |
1093 |
} |
} |
1094 |
} |
} |
1095 |
|
|
1096 |
void DeviceParamDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { |
void DeviceParamDelegate::setEditorData(QWidget* /*editor*/, const QModelIndex& /*index*/) const { |
1097 |
/* |
// unused, since we set the editor data already in createEditor() |
|
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
|
|
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
|
|
comboBox->setCurrentIndex(item.selection); |
|
|
*/ |
|
1098 |
} |
} |
1099 |
|
|
1100 |
void DeviceParamDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { |
void DeviceParamDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { |
1101 |
/* |
if (index.column() == 1) { |
1102 |
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
1103 |
model->setData(index, comboBox->currentIndex()); |
if (r.param.type == LSCP_TYPE_BOOL) { |
1104 |
*/ |
QCheckBox* pCheckBox = static_cast<QCheckBox*>(editor); |
1105 |
|
model->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked)); |
1106 |
|
} else if (r.param.possibilities.count() > 0) { |
1107 |
|
QComboBox* pComboBox = static_cast<QComboBox*>(editor); |
1108 |
|
model->setData(index, pComboBox->currentText()); |
1109 |
|
} else if (r.param.type == LSCP_TYPE_INT) { |
1110 |
|
QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor); |
1111 |
|
model->setData(index, pSpinBox->value()); |
1112 |
|
} else { |
1113 |
|
QLineEdit* pLineEdit = static_cast<QLineEdit*>(editor); |
1114 |
|
model->setData(index, pLineEdit->text()); |
1115 |
|
} |
1116 |
|
} |
1117 |
} |
} |
1118 |
|
|
1119 |
void DeviceParamDelegate::updateEditorGeometry(QWidget* editor, |
void DeviceParamDelegate::updateEditorGeometry(QWidget* editor, |
1122 |
if (editor) editor->setGeometry(option.rect); |
if (editor) editor->setGeometry(option.rect); |
1123 |
} |
} |
1124 |
|
|
|
//------------------------------------------------------------------------- |
|
|
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
|
|
// |
|
|
|
|
|
#if 0 |
|
|
// Constructor. |
|
|
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
|
|
QTable *pTable, EditType editType, const QString& sText ) |
|
|
: QTableItem(pTable, editType, sText) |
|
|
{ |
|
|
m_iValue = sText.toInt(); |
|
|
m_iMinValue = m_iMaxValue = 0; |
|
|
} |
|
|
|
|
|
// Public accessors. |
|
|
void qsamplerDeviceParamTableSpinBox::setValue ( int iValue ) |
|
|
{ |
|
|
m_iValue = iValue; |
|
|
QTableItem::setText(QString::number(m_iValue)); |
|
|
} |
|
|
|
|
|
void qsamplerDeviceParamTableSpinBox::setMinValue ( int iMinValue ) |
|
|
{ |
|
|
m_iMinValue = iMinValue; |
|
|
} |
|
|
|
|
|
void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue ) |
|
|
{ |
|
|
m_iMaxValue = iMaxValue; |
|
|
} |
|
|
|
|
|
// Virtual implemetations. |
|
|
QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const |
|
|
{ |
|
|
QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport()); |
|
|
QObject::connect(pSpinBox, SIGNAL(valueChanged(int)), |
|
|
QTableItem::table(), SLOT(doValueChanged())); |
|
|
if (m_iValue >= m_iMinValue && m_iMaxValue >= m_iValue) { |
|
|
pSpinBox->setMinValue(m_iMinValue); |
|
|
pSpinBox->setMaxValue(m_iMaxValue); |
|
|
} |
|
|
pSpinBox->setValue(m_iValue); |
|
|
return pSpinBox; |
|
|
} |
|
|
|
|
|
void qsamplerDeviceParamTableSpinBox::setContentFromEditor ( QWidget *pWidget ) |
|
|
{ |
|
|
if (pWidget->inherits("QSpinBox")) |
|
|
QTableItem::setText(QString::number(((QSpinBox *) pWidget)->value())); |
|
|
else |
|
|
QTableItem::setContentFromEditor(pWidget); |
|
|
} |
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------- |
|
|
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
|
|
// |
|
|
|
|
|
// Constructor. |
|
|
qsamplerDeviceParamTableEditBox::qsamplerDeviceParamTableEditBox ( |
|
|
QTable *pTable, EditType editType, const QString& sText ) |
|
|
: QTableItem(pTable, editType, sText) |
|
|
{ |
|
|
} |
|
|
|
|
|
// Virtual implemetations. |
|
|
QWidget *qsamplerDeviceParamTableEditBox::createEditor (void) const |
|
|
{ |
|
|
QLineEdit *pEditBox = new QLineEdit(QTableItem::table()->viewport()); |
|
|
QObject::connect(pEditBox, SIGNAL(returnPressed()), |
|
|
QTableItem::table(), SLOT(doValueChanged())); |
|
|
pEditBox->setText(QTableItem::text()); |
|
|
return pEditBox; |
|
|
} |
|
|
|
|
|
void qsamplerDeviceParamTableEditBox::setContentFromEditor ( QWidget *pWidget ) |
|
|
{ |
|
|
if (pWidget->inherits("QLineEdit")) |
|
|
QTableItem::setText(((QLineEdit *) pWidget)->text()); |
|
|
else |
|
|
QTableItem::setContentFromEditor(pWidget); |
|
|
} |
|
|
#endif |
|
|
|
|
|
|
|
1125 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |