mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-08-04 23:12:25 -04:00
Device user arguments (5)
This commit is contained in:
parent
597a526527
commit
4f89e22cc2
@ -20,6 +20,16 @@
|
|||||||
#include "util/simpleserializer.h"
|
#include "util/simpleserializer.h"
|
||||||
#include "deviceuserargs.h"
|
#include "deviceuserargs.h"
|
||||||
|
|
||||||
|
QDataStream &operator<<(QDataStream &ds, const DeviceUserArgs::Args &inObj)
|
||||||
|
{
|
||||||
|
ds << inObj.m_id << inObj.m_sequence << inObj.m_args;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDataStream &operator>>(QDataStream &ds, DeviceUserArgs::Args &outObj)
|
||||||
|
{
|
||||||
|
ds >> outObj.m_id >> outObj.m_sequence >> outObj.m_args;
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray DeviceUserArgs::serialize() const
|
QByteArray DeviceUserArgs::serialize() const
|
||||||
{
|
{
|
||||||
SimpleSerializer s(1);
|
SimpleSerializer s(1);
|
||||||
@ -54,30 +64,96 @@ bool DeviceUserArgs::deserialize(const QByteArray& data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceUserArgs::splitDeviceKey(const QString& key, QString& id, int& sequence)
|
QList<DeviceUserArgs::Args>::iterator DeviceUserArgs::findDeviceArgs(const QString& id, int sequence)
|
||||||
{
|
{
|
||||||
QStringList elms = key.split('-');
|
DeviceUserArgs::Args args;
|
||||||
|
args.m_id = id;
|
||||||
|
args.m_sequence = sequence;
|
||||||
|
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin();
|
||||||
|
|
||||||
if (elms.size() > 0) {
|
for (; it != m_argsByDevice.end(); ++it)
|
||||||
id = elms[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (elms.size() > 1)
|
|
||||||
{
|
{
|
||||||
bool ok;
|
if (*it == args) {
|
||||||
QString seqStr = elms[1];
|
return it;
|
||||||
int seq = seqStr.toInt(&ok);
|
|
||||||
|
|
||||||
if (ok) {
|
|
||||||
sequence = seq;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceUserArgs::composeDeviceKey(const QString& id, int sequence, QString& key)
|
void DeviceUserArgs::addDeviceArgs(const QString& id, int sequence, const QString& deviceArgs)
|
||||||
{
|
{
|
||||||
QStringList strList;
|
Args args;
|
||||||
strList.append(id);
|
args.m_id = id;
|
||||||
strList.append(QString::number(sequence));
|
args.m_sequence = sequence;
|
||||||
key = strList.join('-');
|
args.m_args = deviceArgs;
|
||||||
|
|
||||||
|
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin();
|
||||||
|
|
||||||
|
for (; it != m_argsByDevice.end(); ++it)
|
||||||
|
{
|
||||||
|
if (*it == args) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it == m_argsByDevice.end()) {
|
||||||
|
m_argsByDevice.push_back(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceUserArgs::addOrUpdateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs)
|
||||||
|
{
|
||||||
|
Args args;
|
||||||
|
args.m_id = id;
|
||||||
|
args.m_sequence = sequence;
|
||||||
|
args.m_args = deviceArgs;
|
||||||
|
|
||||||
|
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin();
|
||||||
|
|
||||||
|
for (; it != m_argsByDevice.end(); ++it)
|
||||||
|
{
|
||||||
|
if (*it == args)
|
||||||
|
{
|
||||||
|
it->m_args = deviceArgs;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it == m_argsByDevice.end()) {
|
||||||
|
m_argsByDevice.push_back(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceUserArgs::updateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs)
|
||||||
|
{
|
||||||
|
Args args;
|
||||||
|
args.m_id = id;
|
||||||
|
args.m_sequence = sequence;
|
||||||
|
|
||||||
|
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin();
|
||||||
|
|
||||||
|
for (; it != m_argsByDevice.end(); ++it)
|
||||||
|
{
|
||||||
|
if (*it == args)
|
||||||
|
{
|
||||||
|
it->m_args = deviceArgs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceUserArgs::deleteDeviceArgs(const QString& id, int sequence)
|
||||||
|
{
|
||||||
|
Args args;
|
||||||
|
args.m_id = id;
|
||||||
|
args.m_sequence = sequence;
|
||||||
|
|
||||||
|
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin();
|
||||||
|
|
||||||
|
for (; it != m_argsByDevice.end(); ++it)
|
||||||
|
{
|
||||||
|
if (*it == args)
|
||||||
|
{
|
||||||
|
m_argsByDevice.erase(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#ifndef SDRBASE_DEVICE_DEVICEUSERARGS_H_
|
#ifndef SDRBASE_DEVICE_DEVICEUSERARGS_H_
|
||||||
#define SDRBASE_DEVICE_DEVICEUSERARGS_H_
|
#define SDRBASE_DEVICE_DEVICEUSERARGS_H_
|
||||||
|
|
||||||
#include <QMap>
|
#include <QList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
|
||||||
@ -27,13 +27,29 @@
|
|||||||
struct DEVICES_API DeviceUserArgs
|
struct DEVICES_API DeviceUserArgs
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
struct Args {
|
||||||
|
QString m_id;
|
||||||
|
int m_sequence;
|
||||||
|
QString m_args;
|
||||||
|
|
||||||
|
bool operator==(const Args& rhs) { //!< reference equality
|
||||||
|
return (m_id == rhs.m_id) && (m_sequence == rhs.m_sequence);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend QDataStream &operator << (QDataStream &ds, const Args &inObj);
|
||||||
|
friend QDataStream &operator >> (QDataStream &ds, Args &outObj);
|
||||||
|
};
|
||||||
|
|
||||||
QByteArray serialize() const;
|
QByteArray serialize() const;
|
||||||
bool deserialize(const QByteArray& data);
|
bool deserialize(const QByteArray& data);
|
||||||
|
QList<Args>::iterator findDeviceArgs(const QString& id, int sequence);
|
||||||
|
void addDeviceArgs(const QString& id, int sequence, const QString& args); //!< Will not add if it exists for same reference
|
||||||
|
void addOrUpdateDeviceArgs(const QString& id, int sequence, const QString& args); //!< Add or update if it exists for same reference
|
||||||
|
void updateDeviceArgs(const QString& id, int sequence, const QString& args); //!< Will not update if reference does not exist
|
||||||
|
void deleteDeviceArgs(const QString& id, int sequence);
|
||||||
|
const QList<Args>& getArgsByDevice() const { return m_argsByDevice; }
|
||||||
|
|
||||||
static void splitDeviceKey(const QString& key, QString& id, int& sequence);
|
QList<Args> m_argsByDevice; //!< args corresponding to a device
|
||||||
static void composeDeviceKey(const QString& id, int sequence, QString& key);
|
|
||||||
|
|
||||||
QMap<QString, QString> m_argsByDevice; //!< "id-sequence" to arg map. Id is hardwareId when referencing hardware device but not limited to it
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "device/deviceenumerator.h"
|
#include "device/deviceenumerator.h"
|
||||||
#include "device/deviceuserargs.h"
|
|
||||||
#include "ui_deviceuserargsdialog.h"
|
#include "ui_deviceuserargsdialog.h"
|
||||||
#include "deviceuserargsdialog.h"
|
#include "deviceuserargsdialog.h"
|
||||||
|
|
||||||
@ -29,9 +28,8 @@ DeviceUserArgsDialog::DeviceUserArgsDialog(
|
|||||||
ui(new Ui::DeviceUserArgsDialog),
|
ui(new Ui::DeviceUserArgsDialog),
|
||||||
m_deviceEnumerator(deviceEnumerator),
|
m_deviceEnumerator(deviceEnumerator),
|
||||||
m_hardwareDeviceUserArgs(hardwareDeviceUserArgs),
|
m_hardwareDeviceUserArgs(hardwareDeviceUserArgs),
|
||||||
m_argsByDeviceCopy(hardwareDeviceUserArgs.m_argsByDevice)
|
m_deviceUserArgsCopy(hardwareDeviceUserArgs)
|
||||||
{
|
{
|
||||||
qDebug("DeviceUserArgsDialog::DeviceUserArgsDialog");
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
for (int i = 0; i < m_deviceEnumerator->getNbRxSamplingDevices(); i++) {
|
for (int i = 0; i < m_deviceEnumerator->getNbRxSamplingDevices(); i++) {
|
||||||
@ -68,25 +66,24 @@ DeviceUserArgsDialog::~DeviceUserArgsDialog()
|
|||||||
|
|
||||||
void DeviceUserArgsDialog::displayArgsByDevice()
|
void DeviceUserArgsDialog::displayArgsByDevice()
|
||||||
{
|
{
|
||||||
|
ui->argsTree->blockSignals(true);
|
||||||
ui->argsTree->clear();
|
ui->argsTree->clear();
|
||||||
ui->argStringEdit->clear();
|
ui->argStringEdit->clear();
|
||||||
|
|
||||||
QMap<QString, QString>::iterator it = m_argsByDeviceCopy.begin();
|
QList<DeviceUserArgs::Args>::const_iterator it = m_deviceUserArgsCopy.getArgsByDevice().begin();
|
||||||
|
|
||||||
for (; it != m_argsByDeviceCopy.end(); ++it)
|
for (; it != m_deviceUserArgsCopy.getArgsByDevice().end(); ++it)
|
||||||
{
|
{
|
||||||
QString hardwareId;
|
|
||||||
int sequence;
|
|
||||||
DeviceUserArgs::splitDeviceKey(it.key(), hardwareId, sequence);
|
|
||||||
QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->argsTree);
|
QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->argsTree);
|
||||||
treeItem->setText(0, hardwareId);
|
treeItem->setText(0, it->m_id);
|
||||||
treeItem->setText(1, tr("%1").arg(sequence));
|
treeItem->setText(1, tr("%1").arg(it->m_sequence));
|
||||||
treeItem->setText(2, m_argsByDeviceCopy.value(it.value()));
|
treeItem->setText(2, it->m_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->argsTree->resizeColumnToContents(0);
|
ui->argsTree->resizeColumnToContents(0);
|
||||||
ui->argsTree->resizeColumnToContents(1);
|
ui->argsTree->resizeColumnToContents(1);
|
||||||
ui->argsTree->resizeColumnToContents(2);
|
ui->argsTree->resizeColumnToContents(2);
|
||||||
|
ui->argsTree->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceUserArgsDialog::pushHWDeviceReference(const PluginInterface::SamplingDevice *samplingDevice)
|
void DeviceUserArgsDialog::pushHWDeviceReference(const PluginInterface::SamplingDevice *samplingDevice)
|
||||||
@ -113,7 +110,7 @@ void DeviceUserArgsDialog::pushHWDeviceReference(const PluginInterface::Sampling
|
|||||||
|
|
||||||
void DeviceUserArgsDialog::accept()
|
void DeviceUserArgsDialog::accept()
|
||||||
{
|
{
|
||||||
m_hardwareDeviceUserArgs.m_argsByDevice = m_argsByDeviceCopy;
|
m_hardwareDeviceUserArgs = m_deviceUserArgsCopy;
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,18 +123,9 @@ void DeviceUserArgsDialog::on_importDevice_clicked(bool checked)
|
|||||||
{
|
{
|
||||||
(void) checked;
|
(void) checked;
|
||||||
QTreeWidgetItem *deviceItem = ui->deviceTree->currentItem();
|
QTreeWidgetItem *deviceItem = ui->deviceTree->currentItem();
|
||||||
QStringList strList;
|
bool ok;
|
||||||
strList.append(deviceItem->text(0));
|
int sequence = deviceItem->text(1).toInt(&ok);
|
||||||
strList.append(deviceItem->text(1));
|
m_deviceUserArgsCopy.addDeviceArgs(deviceItem->text(0), sequence, "");
|
||||||
QString key = strList.join('-');
|
|
||||||
qDebug("DeviceUserArgsDialog::on_importDevice_clicked: key: %s", qPrintable(key));
|
|
||||||
|
|
||||||
QMap<QString, QString>::iterator it = m_argsByDeviceCopy.find(key);
|
|
||||||
|
|
||||||
if (it == m_argsByDeviceCopy.end()) {
|
|
||||||
m_argsByDeviceCopy[key] = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
displayArgsByDevice();
|
displayArgsByDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,13 +135,21 @@ void DeviceUserArgsDialog::on_deleteArgs_clicked(bool checked)
|
|||||||
QTreeWidgetItem *deviceItem = ui->argsTree->currentItem();
|
QTreeWidgetItem *deviceItem = ui->argsTree->currentItem();
|
||||||
bool ok;
|
bool ok;
|
||||||
int sequence = deviceItem->text(1).toInt(&ok);
|
int sequence = deviceItem->text(1).toInt(&ok);
|
||||||
QString key;
|
m_deviceUserArgsCopy.deleteDeviceArgs(deviceItem->text(0), sequence);
|
||||||
DeviceUserArgs::composeDeviceKey(deviceItem->text(0), sequence, key);
|
|
||||||
m_argsByDeviceCopy.remove(key);
|
|
||||||
displayArgsByDevice();
|
displayArgsByDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceUserArgsDialog::on_argStringEdit_returnPressed()
|
void DeviceUserArgsDialog::on_argsTree_currentItemChanged(QTreeWidgetItem* currentItem, QTreeWidgetItem* previousItem)
|
||||||
{
|
{
|
||||||
|
(void) previousItem;
|
||||||
|
ui->argStringEdit->setText(currentItem->text(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceUserArgsDialog::on_argStringEdit_editingFinished()
|
||||||
|
{
|
||||||
|
QTreeWidgetItem *deviceItem = ui->argsTree->currentItem();
|
||||||
|
bool ok;
|
||||||
|
int sequence = deviceItem->text(1).toInt(&ok);
|
||||||
|
m_deviceUserArgsCopy.updateDeviceArgs(deviceItem->text(0), sequence, ui->argStringEdit->text());
|
||||||
|
displayArgsByDevice();
|
||||||
}
|
}
|
@ -22,11 +22,11 @@
|
|||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
#include "plugin/plugininterface.h"
|
#include "plugin/plugininterface.h"
|
||||||
|
#include "device/deviceuserargs.h"
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
|
|
||||||
class QTreeWidgetItem;
|
class QTreeWidgetItem;
|
||||||
class DeviceEnumerator;
|
class DeviceEnumerator;
|
||||||
struct DeviceUserArgs;
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class DeviceUserArgsDialog;
|
class DeviceUserArgsDialog;
|
||||||
@ -57,7 +57,7 @@ private:
|
|||||||
DeviceEnumerator* m_deviceEnumerator;
|
DeviceEnumerator* m_deviceEnumerator;
|
||||||
DeviceUserArgs& m_hardwareDeviceUserArgs;
|
DeviceUserArgs& m_hardwareDeviceUserArgs;
|
||||||
std::vector<HWDeviceReference> m_availableHWDevices;
|
std::vector<HWDeviceReference> m_availableHWDevices;
|
||||||
QMap<QString, QString> m_argsByDeviceCopy;
|
DeviceUserArgs m_deviceUserArgsCopy;
|
||||||
|
|
||||||
void pushHWDeviceReference(const PluginInterface::SamplingDevice *samplingDevice);
|
void pushHWDeviceReference(const PluginInterface::SamplingDevice *samplingDevice);
|
||||||
void displayArgsByDevice();
|
void displayArgsByDevice();
|
||||||
@ -67,7 +67,8 @@ private slots:
|
|||||||
void reject();
|
void reject();
|
||||||
void on_importDevice_clicked(bool checked);
|
void on_importDevice_clicked(bool checked);
|
||||||
void on_deleteArgs_clicked(bool checked);
|
void on_deleteArgs_clicked(bool checked);
|
||||||
void on_argStringEdit_returnPressed();
|
void on_argsTree_currentItemChanged(QTreeWidgetItem* currentItem, QTreeWidgetItem* previousItem);
|
||||||
|
void on_argStringEdit_editingFinished();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SDRGUI_GUI_DEVICEUSERARGSDIALOG_H
|
#endif // SDRGUI_GUI_DEVICEUSERARGSDIALOG_H
|
@ -51,7 +51,7 @@
|
|||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>User argument string to open hardware</string>
|
<string>Arguments for hardware</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
@ -69,6 +69,9 @@
|
|||||||
<height>151</height>
|
<height>151</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>List of available hardware</string>
|
||||||
|
</property>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>HwID</string>
|
<string>HwID</string>
|
||||||
@ -104,7 +107,7 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Add the key</string>
|
<string>Add the selected hardware in the list below</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
@ -136,7 +139,7 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Add the key</string>
|
<string>Delete arguments and remove hardware from list above</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
@ -155,9 +158,6 @@
|
|||||||
<height>22</height>
|
<height>22</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
|
||||||
<string>Edit value</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Args</string>
|
<string>Args</string>
|
||||||
</property>
|
</property>
|
||||||
@ -166,7 +166,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="argStringEdit">
|
<widget class="QLineEdit" name="argStringEdit">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Value</string>
|
<string>Edit user arguments of hardware selected above</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -181,6 +181,9 @@
|
|||||||
<height>151</height>
|
<height>151</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>List of hardware with user arguments</string>
|
||||||
|
</property>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>HwID</string>
|
<string>HwID</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user