26 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
27 |
#include "qsamplerDeviceForm.h" |
#include "qsamplerDeviceForm.h" |
28 |
|
|
29 |
#include <qspinbox.h> |
#include <QCheckBox> |
30 |
#include <qlineedit.h> |
#include <QSpinBox> |
31 |
|
#include <QLineEdit> |
32 |
|
|
33 |
|
|
34 |
using namespace QSampler; |
using namespace QSampler; |
35 |
|
|
109 |
// Constructor. |
// Constructor. |
110 |
qsamplerDevice::qsamplerDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
qsamplerDevice::qsamplerDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
111 |
{ |
{ |
112 |
m_ports.setAutoDelete(true); |
// m_ports.setAutoDelete(true); |
113 |
|
|
114 |
setDevice(deviceType, iDeviceID); |
setDevice(deviceType, iDeviceID); |
115 |
} |
} |
117 |
// Default destructor. |
// Default destructor. |
118 |
qsamplerDevice::~qsamplerDevice (void) |
qsamplerDevice::~qsamplerDevice (void) |
119 |
{ |
{ |
120 |
|
qDeleteAll(m_ports); |
121 |
|
m_ports.clear(); |
122 |
} |
} |
123 |
|
|
124 |
// Copy constructor. |
// Copy constructor. |
125 |
qsamplerDevice::qsamplerDevice ( const qsamplerDevice& device ) |
qsamplerDevice::qsamplerDevice ( const qsamplerDevice& device ) |
126 |
: m_params(device.m_params), m_ports(m_ports) |
: m_params(device.m_params), m_ports(device.m_ports) |
127 |
{ |
{ |
128 |
m_iDeviceID = device.m_iDeviceID; |
m_iDeviceID = device.m_iDeviceID; |
129 |
m_deviceType = device.m_deviceType; |
m_deviceType = device.m_deviceType; |
148 |
|
|
149 |
// Reset device parameters and ports anyway. |
// Reset device parameters and ports anyway. |
150 |
m_params.clear(); |
m_params.clear(); |
151 |
|
qDeleteAll(m_ports); |
152 |
m_ports.clear(); |
m_ports.clear(); |
153 |
|
|
154 |
// Retrieve device info, if any. |
// Retrieve device info, if any. |
188 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
189 |
switch (deviceType) { |
switch (deviceType) { |
190 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
191 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
192 |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
193 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
194 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
195 |
break; |
break; |
196 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
197 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
198 |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
199 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
200 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
201 |
break; |
break; |
202 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
203 |
break; |
break; |
204 |
} |
} |
205 |
if (pParamInfo) { |
if (pParamInfo) { |
206 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
207 |
pDeviceInfo->params[i].value); |
pDeviceInfo->params[i].value); |
208 |
} |
} |
209 |
} |
} |
230 |
|
|
231 |
// Reset device parameters and ports anyway. |
// Reset device parameters and ports anyway. |
232 |
m_params.clear(); |
m_params.clear(); |
233 |
|
qDeleteAll(m_ports); |
234 |
m_ports.clear(); |
m_ports.clear(); |
235 |
|
|
236 |
// Retrieve driver info, if any. |
// Retrieve driver info, if any. |
238 |
switch (m_deviceType) { |
switch (m_deviceType) { |
239 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
240 |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
241 |
sDriverName.latin1())) == NULL) |
sDriverName.toUtf8().constData())) == NULL) |
242 |
appendMessagesClient("lscp_get_audio_driver_info"); |
appendMessagesClient("lscp_get_audio_driver_info"); |
243 |
break; |
break; |
244 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
245 |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
246 |
sDriverName.latin1())) == NULL) |
sDriverName.toUtf8().constData())) == NULL) |
247 |
appendMessagesClient("lscp_get_midi_driver_info"); |
appendMessagesClient("lscp_get_midi_driver_info"); |
248 |
break; |
break; |
249 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
263 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
264 |
switch (m_deviceType) { |
switch (m_deviceType) { |
265 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
266 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
267 |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), sDriverName.toUtf8().constData(), |
268 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
269 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
270 |
break; |
break; |
271 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
272 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
273 |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), sDriverName.toUtf8().constData(), |
274 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
275 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
276 |
break; |
break; |
277 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
278 |
break; |
break; |
279 |
} |
} |
280 |
if (pParamInfo) { |
if (pParamInfo) { |
281 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
282 |
pParamInfo->defaultv); |
pParamInfo->defaultv); |
283 |
} |
} |
284 |
} |
} |
332 |
return false; |
return false; |
333 |
|
|
334 |
// Set proper device parameter. |
// Set proper device parameter. |
335 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.toUpper()].value = sValue; |
336 |
|
|
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.latin1(); |
param.key = (char *) finalParamKey.constData(); |
350 |
param.value = (char *) sValue.latin1(); |
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) { |
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.data().value == QString::null) continue; |
if (iter.value().value == QString::null) continue; |
420 |
pParams[iParam].key = (char *) iter.key().latin1(); |
finalKeys.push_back(iter.key().toUtf8()); |
421 |
pParams[iParam].value = (char *) iter.data().value.latin1(); |
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; |
438 |
switch (m_deviceType) { |
switch (m_deviceType) { |
439 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
440 |
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
441 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
442 |
appendMessagesClient("lscp_create_audio_device"); |
appendMessagesClient("lscp_create_audio_device"); |
443 |
break; |
break; |
444 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
445 |
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
446 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
447 |
appendMessagesClient("lscp_create_midi_device"); |
appendMessagesClient("lscp_create_midi_device"); |
448 |
break; |
break; |
449 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
541 |
break; |
break; |
542 |
} |
} |
543 |
// Retrieve port/channel information... |
// Retrieve port/channel information... |
544 |
|
qDeleteAll(m_ports); |
545 |
m_ports.clear(); |
m_ports.clear(); |
546 |
for (int iPort = 0; iPort < iPorts; iPort++) |
for (int iPort = 0; iPort < iPorts; iPort++) |
547 |
m_ports.append(new qsamplerDevicePort(*this, iPort)); |
m_ports.append(new qsamplerDevicePort(*this, iPort)); |
560 |
int iDepends = 0; |
int iDepends = 0; |
561 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
562 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
563 |
const QStringList& depends = iter.data().depends; |
const QStringList& depends = iter.value().depends; |
564 |
if (depends.find(sParam) != depends.end()) |
if (depends.indexOf(sParam) >= 0) |
565 |
iDepends += refreshParam(iter.key()); |
iDepends += refreshParam(iter.key()); |
566 |
} |
} |
567 |
// Return how many dependencies have been refreshed... |
// Return how many dependencies have been refreshed... |
579 |
return 0; |
return 0; |
580 |
|
|
581 |
// Check if we have dependencies... |
// Check if we have dependencies... |
582 |
qsamplerDeviceParam& param = m_params[sParam.upper()]; |
qsamplerDeviceParam& param = m_params[sParam.toUpper()]; |
583 |
if (param.depends.isEmpty()) |
if (param.depends.isEmpty()) |
584 |
return 0; |
return 0; |
585 |
|
|
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.latin1(); |
// C-style char* pointers for liblscp would immediately be invalidated |
595 |
pDepends[iDepend].value = (char *) m_params[sDepend.upper()].value.latin1(); |
QList<QByteArray> finalKeys; |
596 |
|
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. |
618 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
619 |
switch (m_deviceType) { |
switch (m_deviceType) { |
620 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
621 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
622 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
623 |
|
sParam.toUtf8().constData(), pDepends)) == NULL) |
624 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
625 |
break; |
break; |
626 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
627 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
628 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
629 |
|
sParam.toUtf8().constData(), pDepends)) == NULL) |
630 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
631 |
break; |
break; |
632 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
633 |
break; |
break; |
634 |
} |
} |
635 |
if (pParamInfo) { |
if (pParamInfo) { |
636 |
if (param.value != QString::null) |
param = qsamplerDeviceParam(pParamInfo, |
637 |
param = qsamplerDeviceParam(pParamInfo, param.value); |
param.value.isEmpty() ? NULL : param.value.toUtf8().constData()); |
|
else |
|
|
param = qsamplerDeviceParam(pParamInfo, NULL); |
|
638 |
iRefresh++; |
iRefresh++; |
639 |
} |
} |
640 |
|
|
795 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
796 |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
797 |
pMainForm->client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
798 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
799 |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
800 |
break; |
break; |
801 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
802 |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
803 |
pMainForm->client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
804 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
805 |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
806 |
break; |
break; |
807 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
808 |
break; |
break; |
809 |
} |
} |
810 |
if (pParamInfo) { |
if (pParamInfo) { |
811 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
812 |
pPortInfo->params[i].value); |
pPortInfo->params[i].value); |
813 |
} |
} |
814 |
} |
} |
844 |
return false; |
return false; |
845 |
|
|
846 |
// Set proper port/channel parameter. |
// Set proper port/channel parameter. |
847 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.toUpper()].value = sValue; |
848 |
|
|
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.latin1(); |
param.key = (char *) finalParamKey.constData(); |
862 |
param.value = (char *) sValue.latin1(); |
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()) { |
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.toLatin1().data() << "]\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 |
|
|
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; |
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; |
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: |
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.lower() == "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) { |
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: |
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 |
} |
} |