1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-27 15:26:33 -04:00

Device user arguments: implemented non discoverable devices specification in GUI

This commit is contained in:
f4exb 2019-12-15 00:19:50 +01:00
parent 4abeefff82
commit 8d2f65f967
5 changed files with 150 additions and 25 deletions

View File

@ -22,13 +22,13 @@
QDataStream &operator<<(QDataStream &ds, const DeviceUserArgs::Args &inObj) QDataStream &operator<<(QDataStream &ds, const DeviceUserArgs::Args &inObj)
{ {
ds << inObj.m_id << inObj.m_sequence << inObj.m_args; ds << inObj.m_id << inObj.m_sequence << inObj.m_args << inObj.m_nonDiscoverable;
return ds; return ds;
} }
QDataStream &operator>>(QDataStream &ds, DeviceUserArgs::Args &outObj) QDataStream &operator>>(QDataStream &ds, DeviceUserArgs::Args &outObj)
{ {
ds >> outObj.m_id >> outObj.m_sequence >> outObj.m_args; ds >> outObj.m_id >> outObj.m_sequence >> outObj.m_args >> outObj.m_nonDiscoverable;
return ds; return ds;
} }
@ -78,7 +78,7 @@ QString DeviceUserArgs::findUserArgs(const QString& id, int sequence)
return ""; return "";
} }
void DeviceUserArgs::addDeviceArgs(const QString& id, int sequence, const QString& deviceArgs) void DeviceUserArgs::addDeviceArgs(const QString& id, int sequence, const QString& deviceArgs, bool nonDiscoverable)
{ {
int i = 0; int i = 0;
@ -90,11 +90,11 @@ void DeviceUserArgs::addDeviceArgs(const QString& id, int sequence, const QStrin
} }
if (i == m_argsByDevice.size()) { if (i == m_argsByDevice.size()) {
m_argsByDevice.push_back(Args(id, sequence, deviceArgs)); m_argsByDevice.push_back(Args(id, sequence, deviceArgs, nonDiscoverable));
} }
} }
void DeviceUserArgs::addOrUpdateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs) void DeviceUserArgs::addOrUpdateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs, bool nonDiscoverable)
{ {
int i = 0; int i = 0;
@ -106,18 +106,20 @@ void DeviceUserArgs::addOrUpdateDeviceArgs(const QString& id, int sequence, cons
} }
if (i == m_argsByDevice.size()) { if (i == m_argsByDevice.size()) {
m_argsByDevice.push_back(Args(id, sequence, deviceArgs)); m_argsByDevice.push_back(Args(id, sequence, deviceArgs, nonDiscoverable));
} }
} }
void DeviceUserArgs::updateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs) void DeviceUserArgs::updateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs, bool nonDiscoverable)
{ {
int i = 0; int i = 0;
for (; i < m_argsByDevice.size(); i++) for (; i < m_argsByDevice.size(); i++)
{ {
if ((m_argsByDevice.at(i).m_id == id) && (m_argsByDevice.at(i).m_sequence == sequence)) { if ((m_argsByDevice.at(i).m_id == id) && (m_argsByDevice.at(i).m_sequence == sequence))
{
m_argsByDevice[i].m_args = deviceArgs; m_argsByDevice[i].m_args = deviceArgs;
m_argsByDevice[i].m_nonDiscoverable = nonDiscoverable;
} }
} }
} }

View File

@ -31,17 +31,20 @@ public:
QString m_id; QString m_id;
int m_sequence; int m_sequence;
QString m_args; QString m_args;
bool m_nonDiscoverable;
Args() : Args() :
m_id(""), m_id(""),
m_sequence(0), m_sequence(0),
m_args("") m_args(""),
m_nonDiscoverable(false)
{} {}
Args(const QString id, int sequence, const QString& args) : Args(const QString id, int sequence, const QString& args, bool nonDiscoverable) :
m_id(id), m_id(id),
m_sequence(sequence), m_sequence(sequence),
m_args(args) m_args(args),
m_nonDiscoverable(nonDiscoverable)
{} {}
friend QDataStream &operator << (QDataStream &ds, const Args &inObj); friend QDataStream &operator << (QDataStream &ds, const Args &inObj);
@ -51,9 +54,9 @@ public:
QByteArray serialize() const; QByteArray serialize() const;
bool deserialize(const QByteArray& data); bool deserialize(const QByteArray& data);
QString findUserArgs(const QString& id, int sequence); QString findUserArgs(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 addDeviceArgs(const QString& id, int sequence, const QString& args, bool nonDiscoverable); //!< 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 addOrUpdateDeviceArgs(const QString& id, int sequence, const QString& args, bool nonDiscoverable); //!< 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 updateDeviceArgs(const QString& id, int sequence, const QString& args, bool nonDiscoverable); //!< Will not update if reference does not exist
void deleteDeviceArgs(const QString& id, int sequence); void deleteDeviceArgs(const QString& id, int sequence);
const QList<Args>& getArgsByDevice() const { return m_argsByDevice; } const QList<Args>& getArgsByDevice() const { return m_argsByDevice; }

View File

@ -28,7 +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_deviceUserArgsCopy(hardwareDeviceUserArgs) m_deviceUserArgsCopy(hardwareDeviceUserArgs),
m_xDeviceSequence(0)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -57,6 +58,9 @@ DeviceUserArgsDialog::DeviceUserArgsDialog(
ui->deviceTree->resizeColumnToContents(2); ui->deviceTree->resizeColumnToContents(2);
displayArgsByDevice(); displayArgsByDevice();
ui->addDeviceHwIDEdit->setText(m_xDeviceHardwareId);
ui->addDeviceSeqEdit->setText(tr("%1").arg(m_xDeviceSequence));
} }
DeviceUserArgsDialog::~DeviceUserArgsDialog() DeviceUserArgsDialog::~DeviceUserArgsDialog()
@ -75,14 +79,16 @@ void DeviceUserArgsDialog::displayArgsByDevice()
for (; it != m_deviceUserArgsCopy.getArgsByDevice().end(); ++it) for (; it != m_deviceUserArgsCopy.getArgsByDevice().end(); ++it)
{ {
QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->argsTree); QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->argsTree);
treeItem->setText(0, it->m_id); treeItem->setText(0, it->m_nonDiscoverable ? "ND" : " ");
treeItem->setText(1, tr("%1").arg(it->m_sequence)); treeItem->setText(1, it->m_id);
treeItem->setText(2, it->m_args); treeItem->setText(2, tr("%1").arg(it->m_sequence));
treeItem->setText(3, 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->resizeColumnToContents(3);
ui->argsTree->blockSignals(false); ui->argsTree->blockSignals(false);
} }
@ -128,7 +134,7 @@ void DeviceUserArgsDialog::on_importDevice_clicked(bool checked)
{ {
bool ok; bool ok;
int sequence = deviceItem->text(1).toInt(&ok); int sequence = deviceItem->text(1).toInt(&ok);
m_deviceUserArgsCopy.addDeviceArgs(deviceItem->text(0), sequence, ""); m_deviceUserArgsCopy.addDeviceArgs(deviceItem->text(0), sequence, "", false);
displayArgsByDevice(); displayArgsByDevice();
} }
} }
@ -141,8 +147,8 @@ void DeviceUserArgsDialog::on_deleteArgs_clicked(bool checked)
if (deviceItem) if (deviceItem)
{ {
bool ok; bool ok;
int sequence = deviceItem->text(1).toInt(&ok); int sequence = deviceItem->text(2).toInt(&ok);
m_deviceUserArgsCopy.deleteDeviceArgs(deviceItem->text(0), sequence); m_deviceUserArgsCopy.deleteDeviceArgs(deviceItem->text(1), sequence);
displayArgsByDevice(); displayArgsByDevice();
} }
} }
@ -150,7 +156,7 @@ void DeviceUserArgsDialog::on_deleteArgs_clicked(bool checked)
void DeviceUserArgsDialog::on_argsTree_currentItemChanged(QTreeWidgetItem* currentItem, QTreeWidgetItem* previousItem) void DeviceUserArgsDialog::on_argsTree_currentItemChanged(QTreeWidgetItem* currentItem, QTreeWidgetItem* previousItem)
{ {
(void) previousItem; (void) previousItem;
ui->argStringEdit->setText(currentItem->text(2)); ui->argStringEdit->setText(currentItem->text(3));
} }
void DeviceUserArgsDialog::on_argStringEdit_editingFinished() void DeviceUserArgsDialog::on_argStringEdit_editingFinished()
@ -160,8 +166,30 @@ void DeviceUserArgsDialog::on_argStringEdit_editingFinished()
if (deviceItem) if (deviceItem)
{ {
bool ok; bool ok;
int sequence = deviceItem->text(1).toInt(&ok); int sequence = deviceItem->text(2).toInt(&ok);
m_deviceUserArgsCopy.updateDeviceArgs(deviceItem->text(0), sequence, ui->argStringEdit->text()); bool nonDiscoverable = deviceItem->text(0) == "ND";
m_deviceUserArgsCopy.updateDeviceArgs(deviceItem->text(1), sequence, ui->argStringEdit->text(), nonDiscoverable);
displayArgsByDevice(); displayArgsByDevice();
} }
} }
void DeviceUserArgsDialog::on_addDeviceHwIDEdit_editingFinished()
{
m_xDeviceHardwareId = ui->addDeviceHwIDEdit->text();
}
void DeviceUserArgsDialog::on_addDeviceSeqEdit_editingFinished()
{
bool ok;
int sequence = ui->addDeviceSeqEdit->text().toInt(&ok);
if (ok) {
m_xDeviceSequence = sequence;
}
}
void DeviceUserArgsDialog::on_addDevice_clicked(bool checked)
{
m_deviceUserArgsCopy.addDeviceArgs(m_xDeviceHardwareId, m_xDeviceSequence, "", true);
displayArgsByDevice();
}

View File

@ -58,6 +58,8 @@ private:
DeviceUserArgs& m_hardwareDeviceUserArgs; DeviceUserArgs& m_hardwareDeviceUserArgs;
std::vector<HWDeviceReference> m_availableHWDevices; std::vector<HWDeviceReference> m_availableHWDevices;
DeviceUserArgs m_deviceUserArgsCopy; DeviceUserArgs m_deviceUserArgsCopy;
QString m_xDeviceHardwareId;
unsigned int m_xDeviceSequence;
void pushHWDeviceReference(const PluginInterface::SamplingDevice *samplingDevice); void pushHWDeviceReference(const PluginInterface::SamplingDevice *samplingDevice);
void displayArgsByDevice(); void displayArgsByDevice();
@ -69,6 +71,9 @@ private slots:
void on_deleteArgs_clicked(bool checked); void on_deleteArgs_clicked(bool checked);
void on_argsTree_currentItemChanged(QTreeWidgetItem* currentItem, QTreeWidgetItem* previousItem); void on_argsTree_currentItemChanged(QTreeWidgetItem* currentItem, QTreeWidgetItem* previousItem);
void on_argStringEdit_editingFinished(); void on_argStringEdit_editingFinished();
void on_addDeviceHwIDEdit_editingFinished();
void on_addDeviceSeqEdit_editingFinished();
void on_addDevice_clicked(bool checked);
}; };
#endif // SDRGUI_GUI_DEVICEUSERARGSDIALOG_H #endif // SDRGUI_GUI_DEVICEUSERARGSDIALOG_H

View File

@ -118,6 +118,76 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="addDeviceHwIDLabel">
<property name="text">
<string>HwID</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="addDeviceHwIDEdit">
<property name="toolTip">
<string>Hardware Id of non discoverable device</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="addDeviceSeqLabel">
<property name="text">
<string>Seq</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="addDeviceSeqEdit">
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Sequence of non discoverable device</string>
</property>
<property name="inputMask">
<string>00</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addDevice">
<property name="maximumSize">
<size>
<width>24</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Add non discoverable device </string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/res.qrc">
<normaloff>:/plusw.png</normaloff>:/plusw.png</iconset>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="horizontalLayoutWidget_5"> <widget class="QWidget" name="horizontalLayoutWidget_5">
@ -184,20 +254,37 @@
<property name="toolTip"> <property name="toolTip">
<string>List of hardware with user arguments</string> <string>List of hardware with user arguments</string>
</property> </property>
<column>
<property name="text">
<string>ND</string>
</property>
<property name="toolTip">
<string>Non discoverable</string>
</property>
</column>
<column> <column>
<property name="text"> <property name="text">
<string>HwID</string> <string>HwID</string>
</property> </property>
<property name="toolTip">
<string>Hardware ID</string>
</property>
</column> </column>
<column> <column>
<property name="text"> <property name="text">
<string>Seq</string> <string>Seq</string>
</property> </property>
<property name="toolTip">
<string>Sequence</string>
</property>
</column> </column>
<column> <column>
<property name="text"> <property name="text">
<string>Arg string</string> <string>Arg string</string>
</property> </property>
<property name="toolTip">
<string>Argument string</string>
</property>
</column> </column>
</widget> </widget>
</widget> </widget>