Serial port field is now drop-down list
This commit is contained in:
parent
25d45fd9db
commit
46a79c6bb5
6 changed files with 158 additions and 26 deletions
|
|
@ -10,11 +10,35 @@
|
|||
#include "DMXSettingsEntry.h"
|
||||
#include "ui_DMXSettingsEntry.h"
|
||||
|
||||
#include "serial_port.h"
|
||||
#include <QStandardItemModel>
|
||||
|
||||
DMXSettingsEntry::DMXSettingsEntry(QWidget *parent) :
|
||||
BaseManualDeviceEntry(parent),
|
||||
ui(new Ui::DMXSettingsEntry)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
std::vector<std::string> serialPorts = serial_port::getSerialPorts();
|
||||
for(size_t i = 0; i < serialPorts.size(); ++i)
|
||||
{
|
||||
ui->PortComboBox->addItem(QString::fromStdString(serialPorts[i]));
|
||||
}
|
||||
if(serialPorts.empty())
|
||||
{
|
||||
/*---------------------------------------------------*\
|
||||
| When no ports were found, add an unselectable entry |
|
||||
| denoting this fact istead |
|
||||
\*---------------------------------------------------*/
|
||||
QStandardItemModel* comboBoxModel = qobject_cast<QStandardItemModel *>(ui->PortComboBox->model());
|
||||
if(comboBoxModel != nullptr)
|
||||
{
|
||||
ui->PortComboBox->addItem(tr("No serial ports found"));
|
||||
QStandardItem *item = comboBoxModel->item(0);
|
||||
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
|
||||
}
|
||||
}
|
||||
ui->PortComboBox->clearEditText();
|
||||
}
|
||||
|
||||
DMXSettingsEntry::~DMXSettingsEntry()
|
||||
|
|
@ -39,7 +63,7 @@ void DMXSettingsEntry::loadFromSettings(const json& data)
|
|||
|
||||
if(data.contains("port"))
|
||||
{
|
||||
ui->PortEdit->setText(QString::fromStdString(data["port"]));
|
||||
ui->PortComboBox->setCurrentText(QString::fromStdString(data["port"]));
|
||||
}
|
||||
|
||||
if(data.contains("red_channel"))
|
||||
|
|
@ -75,7 +99,7 @@ json DMXSettingsEntry::saveSettings()
|
|||
| Required parameters |
|
||||
\*-------------------------------------------------*/
|
||||
result["name"] = ui->NameEdit->text().toStdString();
|
||||
result["port"] = ui->PortEdit->text().toStdString();
|
||||
result["port"] = ui->PortComboBox->currentText().toStdString();
|
||||
result["red_channel"] = ui->RedEdit->text().toUInt();
|
||||
result["green_channel"] = ui->GreenEdit->text().toUInt();
|
||||
result["blue_channel"] = ui->BlueEdit->text().toUInt();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>531</width>
|
||||
<height>199</height>
|
||||
<height>206</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
|
@ -94,7 +94,14 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="1" column="5">
|
||||
<widget class="QLineEdit" name="PortEdit"/>
|
||||
<widget class="QComboBox" name="PortComboBox">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="insertPolicy">
|
||||
<enum>QComboBox::NoInsert</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@
|
|||
#include "SerialSettingsEntry.h"
|
||||
#include "ui_SerialSettingsEntry.h"
|
||||
|
||||
#include "serial_port.h"
|
||||
#include <QStandardItemModel>
|
||||
|
||||
SerialSettingsEntry::SerialSettingsEntry(QWidget *parent) :
|
||||
BaseManualDeviceEntry(parent),
|
||||
ui(new Ui::SerialSettingsEntry)
|
||||
|
|
@ -20,6 +23,27 @@ SerialSettingsEntry::SerialSettingsEntry(QWidget *parent) :
|
|||
ui->ProtocolComboBox->addItem("Adalight");
|
||||
ui->ProtocolComboBox->addItem("TPM2");
|
||||
ui->ProtocolComboBox->addItem("Basic I2C");
|
||||
|
||||
std::vector<std::string> serialPorts = serial_port::getSerialPorts();
|
||||
for(size_t i = 0; i < serialPorts.size(); ++i)
|
||||
{
|
||||
ui->PortComboBox->addItem(QString::fromStdString(serialPorts[i]));
|
||||
}
|
||||
if(serialPorts.empty())
|
||||
{
|
||||
/*---------------------------------------------------*\
|
||||
| When no ports were found, add an unselectable entry |
|
||||
| denoting this fact istead |
|
||||
\*---------------------------------------------------*/
|
||||
QStandardItemModel* comboBoxModel = qobject_cast<QStandardItemModel *>(ui->PortComboBox->model());
|
||||
if(comboBoxModel != nullptr)
|
||||
{
|
||||
ui->PortComboBox->addItem(tr("No serial ports found"));
|
||||
QStandardItem *item = comboBoxModel->item(0);
|
||||
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
|
||||
}
|
||||
}
|
||||
ui->PortComboBox->clearEditText();
|
||||
}
|
||||
|
||||
SerialSettingsEntry::~SerialSettingsEntry()
|
||||
|
|
@ -56,7 +80,7 @@ void SerialSettingsEntry::loadFromSettings(const json& data)
|
|||
|
||||
if(data.contains("port"))
|
||||
{
|
||||
ui->PortEdit->setText(QString::fromStdString(data["port"]));
|
||||
ui->PortComboBox->setCurrentText(QString::fromStdString(data["port"]));
|
||||
}
|
||||
|
||||
if(data.contains("baud"))
|
||||
|
|
@ -99,7 +123,7 @@ json SerialSettingsEntry::saveSettings()
|
|||
| Required parameters |
|
||||
\*-------------------------------------------------*/
|
||||
result["name"] = ui->NameEdit->text().toStdString();
|
||||
result["port"] = ui->PortEdit->text().toStdString();
|
||||
result["port"] = ui->PortComboBox->currentText().toStdString();
|
||||
result["num_leds"] = ui->NumLEDsEdit->text().toUInt();
|
||||
result["baud"] = ui->BaudEdit->text().toUInt();
|
||||
|
||||
|
|
|
|||
|
|
@ -26,11 +26,12 @@
|
|||
<string>Serial Device</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="5">
|
||||
<widget class="QLineEdit" name="PortEdit"/>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLineEdit" name="NameEdit"/>
|
||||
<item row="2" column="4">
|
||||
<widget class="QLabel" name="NumLEDsLabel">
|
||||
<property name="text">
|
||||
<string>Number of LEDs:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="BaudLabel">
|
||||
|
|
@ -39,6 +40,9 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QComboBox" name="ProtocolComboBox"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="NameLabel">
|
||||
<property name="text">
|
||||
|
|
@ -46,17 +50,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<widget class="QLabel" name="NumLEDsLabel">
|
||||
<property name="text">
|
||||
<string>Number of LEDs:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLineEdit" name="NameEdit"/>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QLabel" name="PortLabel">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="ProtocolLabel">
|
||||
<property name="text">
|
||||
<string>Port:</string>
|
||||
<string>Protocol:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -66,15 +66,22 @@
|
|||
<item row="2" column="5">
|
||||
<widget class="QLineEdit" name="NumLEDsEdit"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="ProtocolLabel">
|
||||
<item row="1" column="4">
|
||||
<widget class="QLabel" name="PortLabel">
|
||||
<property name="text">
|
||||
<string>Protocol:</string>
|
||||
<string>Port:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QComboBox" name="ProtocolComboBox"/>
|
||||
<item row="1" column="5">
|
||||
<widget class="QComboBox" name="PortComboBox">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="insertPolicy">
|
||||
<enum>QComboBox::NoInsert</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
|
@ -83,7 +90,6 @@
|
|||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>NameEdit</tabstop>
|
||||
<tabstop>PortEdit</tabstop>
|
||||
<tabstop>BaudEdit</tabstop>
|
||||
<tabstop>NumLEDsEdit</tabstop>
|
||||
<tabstop>ProtocolComboBox</tabstop>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue