mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-03-23 20:58:42 -04:00
Device user arguments (5)
This commit is contained in:
parent
597a526527
commit
4f89e22cc2
@ -20,6 +20,16 @@
|
||||
#include "util/simpleserializer.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
|
||||
{
|
||||
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) {
|
||||
id = elms[0];
|
||||
}
|
||||
|
||||
if (elms.size() > 1)
|
||||
for (; it != m_argsByDevice.end(); ++it)
|
||||
{
|
||||
bool ok;
|
||||
QString seqStr = elms[1];
|
||||
int seq = seqStr.toInt(&ok);
|
||||
|
||||
if (ok) {
|
||||
sequence = seq;
|
||||
if (*it == args) {
|
||||
return it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceUserArgs::composeDeviceKey(const QString& id, int sequence, QString& key)
|
||||
void DeviceUserArgs::addDeviceArgs(const QString& id, int sequence, const QString& deviceArgs)
|
||||
{
|
||||
QStringList strList;
|
||||
strList.append(id);
|
||||
strList.append(QString::number(sequence));
|
||||
key = strList.join('-');
|
||||
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) {
|
||||
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_
|
||||
#define SDRBASE_DEVICE_DEVICEUSERARGS_H_
|
||||
|
||||
#include <QMap>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
|
||||
@ -27,13 +27,29 @@
|
||||
struct DEVICES_API DeviceUserArgs
|
||||
{
|
||||
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;
|
||||
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);
|
||||
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
|
||||
QList<Args> m_argsByDevice; //!< args corresponding to a device
|
||||
};
|
||||
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "device/deviceenumerator.h"
|
||||
#include "device/deviceuserargs.h"
|
||||
#include "ui_deviceuserargsdialog.h"
|
||||
#include "deviceuserargsdialog.h"
|
||||
|
||||
@ -29,9 +28,8 @@ DeviceUserArgsDialog::DeviceUserArgsDialog(
|
||||
ui(new Ui::DeviceUserArgsDialog),
|
||||
m_deviceEnumerator(deviceEnumerator),
|
||||
m_hardwareDeviceUserArgs(hardwareDeviceUserArgs),
|
||||
m_argsByDeviceCopy(hardwareDeviceUserArgs.m_argsByDevice)
|
||||
m_deviceUserArgsCopy(hardwareDeviceUserArgs)
|
||||
{
|
||||
qDebug("DeviceUserArgsDialog::DeviceUserArgsDialog");
|
||||
ui->setupUi(this);
|
||||
|
||||
for (int i = 0; i < m_deviceEnumerator->getNbRxSamplingDevices(); i++) {
|
||||
@ -68,25 +66,24 @@ DeviceUserArgsDialog::~DeviceUserArgsDialog()
|
||||
|
||||
void DeviceUserArgsDialog::displayArgsByDevice()
|
||||
{
|
||||
ui->argsTree->blockSignals(true);
|
||||
ui->argsTree->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);
|
||||
treeItem->setText(0, hardwareId);
|
||||
treeItem->setText(1, tr("%1").arg(sequence));
|
||||
treeItem->setText(2, m_argsByDeviceCopy.value(it.value()));
|
||||
treeItem->setText(0, it->m_id);
|
||||
treeItem->setText(1, tr("%1").arg(it->m_sequence));
|
||||
treeItem->setText(2, it->m_args);
|
||||
}
|
||||
|
||||
ui->argsTree->resizeColumnToContents(0);
|
||||
ui->argsTree->resizeColumnToContents(1);
|
||||
ui->argsTree->resizeColumnToContents(2);
|
||||
ui->argsTree->blockSignals(false);
|
||||
}
|
||||
|
||||
void DeviceUserArgsDialog::pushHWDeviceReference(const PluginInterface::SamplingDevice *samplingDevice)
|
||||
@ -113,7 +110,7 @@ void DeviceUserArgsDialog::pushHWDeviceReference(const PluginInterface::Sampling
|
||||
|
||||
void DeviceUserArgsDialog::accept()
|
||||
{
|
||||
m_hardwareDeviceUserArgs.m_argsByDevice = m_argsByDeviceCopy;
|
||||
m_hardwareDeviceUserArgs = m_deviceUserArgsCopy;
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
@ -126,18 +123,9 @@ void DeviceUserArgsDialog::on_importDevice_clicked(bool checked)
|
||||
{
|
||||
(void) checked;
|
||||
QTreeWidgetItem *deviceItem = ui->deviceTree->currentItem();
|
||||
QStringList strList;
|
||||
strList.append(deviceItem->text(0));
|
||||
strList.append(deviceItem->text(1));
|
||||
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] = "";
|
||||
}
|
||||
|
||||
bool ok;
|
||||
int sequence = deviceItem->text(1).toInt(&ok);
|
||||
m_deviceUserArgsCopy.addDeviceArgs(deviceItem->text(0), sequence, "");
|
||||
displayArgsByDevice();
|
||||
}
|
||||
|
||||
@ -147,13 +135,21 @@ void DeviceUserArgsDialog::on_deleteArgs_clicked(bool checked)
|
||||
QTreeWidgetItem *deviceItem = ui->argsTree->currentItem();
|
||||
bool ok;
|
||||
int sequence = deviceItem->text(1).toInt(&ok);
|
||||
QString key;
|
||||
DeviceUserArgs::composeDeviceKey(deviceItem->text(0), sequence, key);
|
||||
m_argsByDeviceCopy.remove(key);
|
||||
m_deviceUserArgsCopy.deleteDeviceArgs(deviceItem->text(0), sequence);
|
||||
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 "plugin/plugininterface.h"
|
||||
#include "device/deviceuserargs.h"
|
||||
#include "export.h"
|
||||
|
||||
class QTreeWidgetItem;
|
||||
class DeviceEnumerator;
|
||||
struct DeviceUserArgs;
|
||||
|
||||
namespace Ui {
|
||||
class DeviceUserArgsDialog;
|
||||
@ -57,7 +57,7 @@ private:
|
||||
DeviceEnumerator* m_deviceEnumerator;
|
||||
DeviceUserArgs& m_hardwareDeviceUserArgs;
|
||||
std::vector<HWDeviceReference> m_availableHWDevices;
|
||||
QMap<QString, QString> m_argsByDeviceCopy;
|
||||
DeviceUserArgs m_deviceUserArgsCopy;
|
||||
|
||||
void pushHWDeviceReference(const PluginInterface::SamplingDevice *samplingDevice);
|
||||
void displayArgsByDevice();
|
||||
@ -67,7 +67,8 @@ private slots:
|
||||
void reject();
|
||||
void on_importDevice_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
|
@ -51,7 +51,7 @@
|
||||
</font>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>User argument string to open hardware</string>
|
||||
<string>Arguments for hardware</string>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
@ -69,6 +69,9 @@
|
||||
<height>151</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>List of available hardware</string>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>HwID</string>
|
||||
@ -104,7 +107,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Add the key</string>
|
||||
<string>Add the selected hardware in the list below</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
@ -136,7 +139,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Add the key</string>
|
||||
<string>Delete arguments and remove hardware from list above</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
@ -155,9 +158,6 @@
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Edit value</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Args</string>
|
||||
</property>
|
||||
@ -166,7 +166,7 @@
|
||||
<item>
|
||||
<widget class="QLineEdit" name="argStringEdit">
|
||||
<property name="toolTip">
|
||||
<string>Value</string>
|
||||
<string>Edit user arguments of hardware selected above</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -181,6 +181,9 @@
|
||||
<height>151</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>List of hardware with user arguments</string>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>HwID</string>
|
||||
|
Loading…
Reference in New Issue
Block a user