diff options
author | kuzulis <scapig2@yandex.ru> | 2011-11-14 22:00:09 +0400 |
---|---|---|
committer | kuzulis <kuzulis@kuzulis.localdomain> | 2011-11-14 22:00:09 +0400 |
commit | 68a5a39241d86dcd57644d005314ecdeeb25bf0c (patch) | |
tree | f876c306650b72e8184d7696f0a70ed341384e85 /tests | |
parent | 33d23363d4c189149e8bc7ece1ef265f042b17da (diff) | |
download | qtserialport-68a5a39241d86dcd57644d005314ecdeeb25bf0c.tar.gz |
/tests/guiapp: Moved from QWidget to QDialog.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/guiapp/guiapp.pro | 18 | ||||
-rw-r--r-- | tests/guiapp/main.cpp | 6 | ||||
-rw-r--r-- | tests/guiapp/maindialog.cpp | 181 | ||||
-rw-r--r-- | tests/guiapp/maindialog.h | 51 | ||||
-rw-r--r-- | tests/guiapp/maindialog.ui | 275 | ||||
-rw-r--r-- | tests/guiapp/optionsdialog.cpp | 249 | ||||
-rw-r--r-- | tests/guiapp/optionsdialog.h | 39 | ||||
-rw-r--r-- | tests/guiapp/optionsdialog.ui | 91 | ||||
-rw-r--r-- | tests/guiapp/tracedialog.cpp | 79 | ||||
-rw-r--r-- | tests/guiapp/tracedialog.h | 34 | ||||
-rw-r--r-- | tests/guiapp/tracedialog.ui | 70 |
11 files changed, 1081 insertions, 12 deletions
diff --git a/tests/guiapp/guiapp.pro b/tests/guiapp/guiapp.pro index 211e569..6ce7708 100644 --- a/tests/guiapp/guiapp.pro +++ b/tests/guiapp/guiapp.pro @@ -16,15 +16,15 @@ HEADERS += \ include(../../src/src.pri) SOURCES += main.cpp\ - mainwidget.cpp \ - optionswidget.cpp \ - tracewidget.cpp -HEADERS += mainwidget.h \ - optionswidget.h \ - tracewidget.h -FORMS += mainwidget.ui \ - optionswidget.ui \ - tracewidget.ui + maindialog.cpp \ + optionsdialog.cpp \ + tracedialog.cpp +HEADERS += maindialog.h \ + optionsdialog.h \ + tracedialog.h +FORMS += maindialog.ui \ + optionsdialog.ui \ + tracedialog.ui CONFIG(debug, debug|release) { DESTDIR = debug diff --git a/tests/guiapp/main.cpp b/tests/guiapp/main.cpp index 0f3e020..494c410 100644 --- a/tests/guiapp/main.cpp +++ b/tests/guiapp/main.cpp @@ -1,11 +1,11 @@ #include <QtGui/QApplication> -#include "mainwidget.h" +#include "maindialog.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); - MainWidget w; - w.show(); + MainDialog dlg; + dlg.show(); return a.exec(); } diff --git a/tests/guiapp/maindialog.cpp b/tests/guiapp/maindialog.cpp new file mode 100644 index 0000000..88bdf2e --- /dev/null +++ b/tests/guiapp/maindialog.cpp @@ -0,0 +1,181 @@ +#include <QtCore/QStringList> +#include <QtCore/QTimer> +//#include <QtCore/QDebug> + +#include "maindialog.h" +#include "ui_maindialog.h" +#include "optionsdialog.h" +#include "tracedialog.h" + +#include "serialportinfo.h" +#include "serialport.h" + + +/* Public methods */ + + +MainDialog::MainDialog(QWidget *parent) + : QDialog(parent) + , ui(new Ui::MainDialog) + , m_optionsDialog(0) + , m_traceDialog(0) + , m_port(0) + , m_timer(0) + , m_rts(false) + , m_dtr(false) +{ + ui->setupUi(this); + fillOpenModeComboBox(); + + m_port = new SerialPort(this); + m_timer = new QTimer(this); + m_timer->setInterval(500); + + connect(m_timer, SIGNAL(timeout()), this, SLOT(procUpdateLines())); + + procShowPorts(); + int idx = ui->boxName->currentIndex(); + if (idx >= 0) + procItemPortChanged(idx); + + connect(ui->boxName, SIGNAL(currentIndexChanged(int)), this, SLOT(procItemPortChanged(int))); + connect(ui->controlButton, SIGNAL(clicked()), this, SLOT(procControlButtonClick())); + connect(ui->optionsButton, SIGNAL(clicked()), this, SLOT(procOptionsButtonClick())); + connect(ui->ioButton, SIGNAL(clicked()), this, SLOT(procIOButtonClick())); + connect(ui->rtsButton, SIGNAL(clicked()), this, SLOT(procRtsButtonClick())); + connect(ui->dtrButton, SIGNAL(clicked()), this, SLOT(procDtrButtonClick())); +} + +MainDialog::~MainDialog() +{ + if (m_port->isOpen()) + m_port->close(); + if (m_optionsDialog) + delete m_optionsDialog; + if (m_traceDialog) + delete m_traceDialog; + delete ui; +} + + +/* Protected methods */ + + +void MainDialog::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + + +/* Private slots */ + + +void MainDialog::procShowPorts() +{ + ui->boxName->clear(); + foreach(SerialPortInfo inf, SerialPortInfo::availablePorts()) { + QStringList sl; + sl << inf.systemLocation() << inf.description() << inf.manufacturer(); + ui->boxName->addItem(inf.portName(), QVariant(sl)); + } +} + +void MainDialog::procItemPortChanged(int idx) +{ + QStringList sl = ui->boxName->itemData(idx).toStringList(); + ui->lbLocation->setText(sl.at(0)); + ui->lbDescr->setText(sl.at(1)); + ui->lbMfg->setText(sl.at(2)); +} + +void MainDialog::procControlButtonClick() +{ + if (m_port->isOpen()) { + m_timer->stop(); + m_port->close(); + ui->controlButton->setText(tr("Open")); + ui->optionsButton->setEnabled(false); + ui->ioButton->setEnabled(false); + ui->rtsButton->setEnabled(false); + ui->dtrButton->setEnabled(false); + ui->boxName->setEnabled(true); + ui->modeGroupBox->setEnabled(true); + } else { + m_port->setPort(ui->boxName->currentText()); + int idx = ui->modeComboBox->currentIndex(); + bool ok = false; + idx = ui->modeComboBox->itemData(idx).toInt(&ok); + if (ok && m_port->open((QIODevice::OpenMode)idx)) { + ui->controlButton->setText(tr("Close")); + ui->optionsButton->setEnabled(true); + ui->ioButton->setEnabled(true); + ui->rtsButton->setEnabled(true); + ui->dtrButton->setEnabled(true); + ui->boxName->setEnabled(false); + ui->modeGroupBox->setEnabled(false); + m_timer->start(); + } + } +} + +void MainDialog::procOptionsButtonClick() +{ + if (!m_optionsDialog) + m_optionsDialog = new OptionsDialog(m_port); + m_optionsDialog->show(); +} + +void MainDialog::procIOButtonClick() +{ + if (!m_traceDialog) + m_traceDialog = new TraceDialog(m_port); + m_traceDialog->show(); +} + +void MainDialog::procRtsButtonClick() +{ + m_port->setRts(!m_rts); +} + +void MainDialog::procDtrButtonClick() +{ + m_port->setDtr(!m_dtr); +} + +void MainDialog::procUpdateLines() +{ + SerialPort::Lines lines = m_port->lines(); + m_rts = SerialPort::Rts & lines; + m_dtr = SerialPort::Dtr & lines; + + ui->leLabel->setEnabled(SerialPort::Le & lines); + ui->dtrLabel->setEnabled(m_dtr); + ui->rtsLabel->setEnabled(m_rts); + //ui->stLabel->setEnabled(SerialPort::St & lines); + //ui->srLabel->setEnabled(SerialPort::Sr & lines); + ui->ctsLabel->setEnabled(SerialPort::Cts & lines); + ui->dcdLabel->setEnabled(SerialPort::Dcd & lines); + ui->ringLabel->setEnabled(SerialPort::Ri & lines); + ui->dsrLabel->setEnabled(SerialPort::Dsr & lines); + + ui->rtsButton->setText((m_rts) ? tr("Clear RTS") : tr("Set RTS")); + ui->dtrButton->setText((m_dtr) ? tr("Clear DTR") : tr("Set DTR")); +} + + +/* Private methods */ + + +void MainDialog::fillOpenModeComboBox() +{ + ui->modeComboBox->addItem(QString(tr("Read and write")), QVariant(QIODevice::ReadWrite)); + ui->modeComboBox->addItem(QString(tr("Read only")), QVariant(QIODevice::ReadOnly)); + ui->modeComboBox->addItem(QString(tr("Write only")), QVariant(QIODevice::WriteOnly)); +} diff --git a/tests/guiapp/maindialog.h b/tests/guiapp/maindialog.h new file mode 100644 index 0000000..b2cb779 --- /dev/null +++ b/tests/guiapp/maindialog.h @@ -0,0 +1,51 @@ +#ifndef MAINDIALOG_H +#define MAINDIALOG_H + +#include <QtGui/QDialog> + +namespace Ui { +class MainDialog; +} + +class SerialPort; +class OptionsDialog; +class TraceDialog; +class QTimer; + +class MainDialog : public QDialog +{ + Q_OBJECT +public: + explicit MainDialog(QWidget *parent = 0); + ~MainDialog(); + +protected: + void changeEvent(QEvent *e); + +private slots: + void procShowPorts(); + void procItemPortChanged(int idx); + + void procControlButtonClick(); + void procOptionsButtonClick(); + void procIOButtonClick(); + void procRtsButtonClick(); + void procDtrButtonClick(); + + void procUpdateLines(); + +private: + Ui::MainDialog *ui; + OptionsDialog *m_optionsDialog; + TraceDialog *m_traceDialog; + SerialPort *m_port; + QTimer *m_timer; + + bool m_rts; + bool m_dtr; + + void fillOpenModeComboBox(); + +}; + +#endif // MAINDIALOG_H diff --git a/tests/guiapp/maindialog.ui b/tests/guiapp/maindialog.ui new file mode 100644 index 0000000..ed54e13 --- /dev/null +++ b/tests/guiapp/maindialog.ui @@ -0,0 +1,275 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainDialog</class> + <widget class="QDialog" name="MainDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>411</width> + <height>240</height> + </rect> + </property> + <property name="windowTitle"> + <string>Simple GUI application for demonstrating the use of QSerialDevice.</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0"> + <widget class="QGroupBox" name="modeGroupBox"> + <property name="title"> + <string>Open mode:</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QComboBox" name="modeComboBox"/> + </item> + </layout> + </widget> + </item> + <item row="0" column="1" rowspan="5"> + <widget class="QGroupBox" name="infoGroupBox"> + <property name="title"> + <string>Available ports:</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label_1"> + <property name="text"> + <string>Name:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="boxName"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Location:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="lbLocation"> + <property name="text"> + <string>***</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Description:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLabel" name="lbDescr"> + <property name="text"> + <string>***</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Manufacturer:</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLabel" name="lbMfg"> + <property name="text"> + <string>***</string> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Busy:</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QLabel" name="lbBusy"> + <property name="text"> + <string>***</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="0"> + <widget class="QPushButton" name="controlButton"> + <property name="text"> + <string>Open</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QPushButton" name="optionsButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Options</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QPushButton" name="ioButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Input/Output</string> + </property> + </widget> + </item> + <item row="4" column="0" rowspan="2"> + <widget class="QPushButton" name="rtsButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Set RTS</string> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QLabel" name="lineLabel"> + <property name="text"> + <string>Serial lines states</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="6" column="0"> + <widget class="QPushButton" name="dtrButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Set DTR</string> + </property> + </widget> + </item> + <item row="6" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="Line" name="line1"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="dsrLabel"> + <property name="text"> + <string>DSR</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="dtrLabel"> + <property name="text"> + <string>DTR</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="ctsLabel"> + <property name="text"> + <string>CTS</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="rtsLabel"> + <property name="text"> + <string>RTS</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="dcdLabel"> + <property name="text"> + <string>DCD</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="ringLabel"> + <property name="text"> + <string>RING</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_4"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="leLabel"> + <property name="text"> + <string>LE</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_5"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections/> +</ui> diff --git a/tests/guiapp/optionsdialog.cpp b/tests/guiapp/optionsdialog.cpp new file mode 100644 index 0000000..0af227e --- /dev/null +++ b/tests/guiapp/optionsdialog.cpp @@ -0,0 +1,249 @@ +#include <QtGui/QMessageBox> + +#include "optionsdialog.h" +#include "ui_optionsdialog.h" + +#include "serialport.h" + + +/* Public methods */ + + +OptionsDialog::OptionsDialog(SerialPort *port, QWidget *parent) + : QDialog(parent) + , ui(new Ui::OptionsDialog) + , m_port(port) + , m_rate(0), m_data(0), m_parity(0), m_stop(0), m_flow(0), m_policy(0) +{ + ui->setupUi(this); + procFillingOptions(); + + connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(procApplyButtonClick())); +} + +OptionsDialog::~OptionsDialog() +{ + delete ui; +} + + +/* Protected methods. */ + + +void OptionsDialog::showEvent(QShowEvent *e) +{ + Q_UNUSED(e) + detectOptions(); +} + + +/* Private slots */ + + +void OptionsDialog::procFillingOptions() +{ + ui->baudBox->addItem(tr("9600"), SerialPort::Rate9600); + ui->baudBox->addItem(tr("19200"), SerialPort::Rate19200); + ui->baudBox->addItem(tr("38400"), SerialPort::Rate38400); + ui->baudBox->addItem(tr("57600"), SerialPort::Rate57600); + ui->baudBox->addItem(tr("115200"), SerialPort::Rate115200); + ui->baudBox->addItem(tr("Unknown"), SerialPort::UnknownRate); + + ui->dataBox->addItem(tr("5"), SerialPort::Data5); + ui->dataBox->addItem(tr("6"), SerialPort::Data6); + ui->dataBox->addItem(tr("7"), SerialPort::Data7); + ui->dataBox->addItem(tr("8"), SerialPort::Data8); + ui->dataBox->addItem(tr("Unknown"), SerialPort::UnknownDataBits); + + ui->parityBox->addItem(tr("None"), SerialPort::NoParity); + ui->parityBox->addItem(tr("Even"), SerialPort::EvenParity); + ui->parityBox->addItem(tr("Odd"), SerialPort::OddParity); + ui->parityBox->addItem(tr("Mark"), SerialPort::MarkParity); + ui->parityBox->addItem(tr("Space"), SerialPort::SpaceParity); + ui->parityBox->addItem(tr("Unknown"), SerialPort::UnknownParity); + + ui->stopBox->addItem(tr("1"), SerialPort::OneStop); + ui->stopBox->addItem(tr("1.5"), SerialPort::OneAndHalfStop); + ui->stopBox->addItem(tr("2"), SerialPort::TwoStop); + ui->stopBox->addItem(tr("Unknown"), SerialPort::UnknownStopBits); + + ui->flowBox->addItem(tr("Off"), SerialPort::NoFlowControl); + ui->flowBox->addItem(tr("Hardware"), SerialPort::HardwareControl); + ui->flowBox->addItem(tr("Software"), SerialPort::SoftwareControl); + ui->flowBox->addItem(tr("Unknown"), SerialPort::UnknownFlowControl); + + ui->policyBox->addItem(tr("Skip"), SerialPort::SkipPolicy); + ui->policyBox->addItem(tr("PassZero"), SerialPort::PassZeroPolicy); + ui->policyBox->addItem(tr("Ignore"), SerialPort::IgnorePolicy); + ui->policyBox->addItem(tr("StopReceiving"), SerialPort::StopReceivingPolicy); + ui->policyBox->addItem(tr("Unknown"), SerialPort::UnknownPolicy); +} + +void OptionsDialog::procApplyButtonClick() +{ + bool ok; + bool hasChanged = false; + + int val = ui->baudBox->itemData(ui->baudBox->currentIndex()).toInt(&ok); + if (val != m_rate) { + m_port->setRate(SerialPort::Rate(val)); + hasChanged = true; + } + + val = ui->dataBox->itemData(ui->dataBox->currentIndex()).toInt(&ok); + if (val != m_data) { + m_port->setDataBits(SerialPort::DataBits(val)); + hasChanged = true; + } + + val = ui->parityBox->itemData(ui->parityBox->currentIndex()).toInt(&ok); + if (val != m_parity) { + m_port->setParity(SerialPort::Parity(val)); + hasChanged = true; + } + + val = ui->stopBox->itemData(ui->stopBox->currentIndex()).toInt(&ok); + if (val != m_stop) { + m_port->setStopBits(SerialPort::StopBits(val)); + hasChanged = true; + } + + val = ui->flowBox->itemData(ui->flowBox->currentIndex()).toInt(&ok); + if (val != m_flow) { + m_port->setFlowControl(SerialPort::FlowControl(val)); + hasChanged = true; + } + + val = ui->policyBox->itemData(ui->policyBox->currentIndex()).toInt(&ok); + if (val != m_policy) { + m_port->setDataErrorPolicy(SerialPort::DataErrorPolicy(val)); + hasChanged = true; + } + + if (hasChanged) + detectOptions(); +} + + +/* Private methods */ + + +void OptionsDialog::detectOptions() +{ + m_rate = m_port->rate(); + switch (m_rate) { + case SerialPort::Rate9600: + case SerialPort::Rate19200: + case SerialPort::Rate38400: + case SerialPort::Rate57600: + case SerialPort::Rate115200: + break; + default: m_rate = SerialPort::UnknownRate; + } + int count = ui->baudBox->count(); + for (int i = 0; i < count; ++i) { + bool ok; + if (ui->baudBox->itemData(i).toInt(&ok) == m_rate) { + ui->baudBox->setCurrentIndex(i); + break; + } + } + + m_data = m_port->dataBits(); + switch (m_data) { + case SerialPort::Data5: + case SerialPort::Data6: + case SerialPort::Data7: + case SerialPort::Data8: + break; + default: m_data = SerialPort::UnknownDataBits; + } + count = ui->dataBox->count(); + for (int i = 0; i < count; ++i) { + bool ok; + if (ui->dataBox->itemData(i).toInt(&ok) == m_data) { + ui->dataBox->setCurrentIndex(i); + break; + } + } + + m_parity = m_port->parity(); + switch (m_parity) { + case SerialPort::NoParity: + case SerialPort::EvenParity: + case SerialPort::OddParity: + case SerialPort::MarkParity: + case SerialPort::SpaceParity: + break; + default: m_parity = SerialPort::UnknownParity; + } + count = ui->parityBox->count(); + for (int i = 0; i < count; ++i) { + bool ok; + if (ui->parityBox->itemData(i).toInt(&ok) == m_parity) { + ui->parityBox->setCurrentIndex(i); + break; + } + } + + m_stop = m_port->stopBits(); + switch (m_stop) { + case SerialPort::OneStop: + case SerialPort::OneAndHalfStop: + case SerialPort::TwoStop: + break; + default: m_stop = SerialPort::UnknownStopBits; + } + count = ui->stopBox->count(); + for (int i = 0; i < count; ++i) { + bool ok; + if (ui->stopBox->itemData(i).toInt(&ok) == m_stop) { + ui->stopBox->setCurrentIndex(i); + break; + } + } + + m_flow = m_port->flowControl(); + switch (m_flow) { + case SerialPort::NoFlowControl: + case SerialPort::HardwareControl: + case SerialPort::SoftwareControl: + break; + default: m_flow = SerialPort::UnknownFlowControl; + } + count = ui->flowBox->count(); + for (int i = 0; i < count; ++i) { + bool ok; + if (ui->flowBox->itemData(i).toInt(&ok) == m_flow) { + ui->flowBox->setCurrentIndex(i); + break; + } + } + + m_policy = m_port->dataErrorPolicy(); + switch (m_policy) { + case SerialPort::PassZeroPolicy: + case SerialPort::IgnorePolicy: + case SerialPort::StopReceivingPolicy: + break; + default: m_flow = SerialPort::UnknownPolicy; + } + count = ui->policyBox->count(); + for (int i = 0; i < count; ++i) { + bool ok; + if (ui->policyBox->itemData(i).toInt(&ok) == m_policy) { + ui->policyBox->setCurrentIndex(i); + break; + } + } +} + + + + + + + + + + diff --git a/tests/guiapp/optionsdialog.h b/tests/guiapp/optionsdialog.h new file mode 100644 index 0000000..c4ac69d --- /dev/null +++ b/tests/guiapp/optionsdialog.h @@ -0,0 +1,39 @@ +#ifndef OPTIONSDIALOG_H +#define OPTIONSDIALOG_H + +#include <QtGui/QDialog> + +namespace Ui { +class OptionsDialog; +} + +class SerialPort; + +class OptionsDialog : public QDialog +{ + Q_OBJECT +public: + explicit OptionsDialog(SerialPort *port, QWidget *parent = 0); + ~OptionsDialog(); + +protected: + void showEvent(QShowEvent *e); + +private slots: + void procFillingOptions(); + void procApplyButtonClick(); + +private: + Ui::OptionsDialog *ui; + SerialPort *m_port; + int m_rate; + int m_data; + int m_parity; + int m_stop; + int m_flow; + int m_policy; + + void detectOptions(); +}; + +#endif // OPTIONSDIALOG_H diff --git a/tests/guiapp/optionsdialog.ui b/tests/guiapp/optionsdialog.ui new file mode 100644 index 0000000..743ef87 --- /dev/null +++ b/tests/guiapp/optionsdialog.ui @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>OptionsDialog</class> + <widget class="QDialog" name="OptionsDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>161</width> + <height>197</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="Label1"> + <property name="text"> + <string>Baud rate:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="baudBox"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="Label2"> + <property name="text"> + <string>Data bits:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QComboBox" name="dataBox"/> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="Label3"> + <property name="text"> + <string>Parity:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QComboBox" name="parityBox"/> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="Label4"> + <property name="text"> + <string>Stop bits:</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QComboBox" name="stopBox"/> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="Label5"> + <property name="text"> + <string>Flow control:</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QComboBox" name="flowBox"/> + </item> + <item row="5" column="0"> + <widget class="QLabel" name="Label6"> + <property name="text"> + <string>Policy:</string> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QComboBox" name="policyBox"/> + </item> + <item row="6" column="1"> + <widget class="QPushButton" name="applyButton"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Apply</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/guiapp/tracedialog.cpp b/tests/guiapp/tracedialog.cpp new file mode 100644 index 0000000..c0e2abc --- /dev/null +++ b/tests/guiapp/tracedialog.cpp @@ -0,0 +1,79 @@ +#include <QtGui/QScrollBar> + +#include "tracedialog.h" +#include "ui_tracedialog.h" + +#include "serialport.h" + + +/* Public methods */ + + +TraceDialog::TraceDialog(SerialPort *port, QWidget *parent) + : QDialog(parent) + , ui(new Ui::TraceDialog) + , m_port(port) +{ + ui->setupUi(this); + ui->textEdit->document()->setMaximumBlockCount(100); + + connect(ui->sendButton, SIGNAL(clicked()), this, SLOT(procSendButtonClick())); + connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(procClearButtonClick())); + + connect(m_port, SIGNAL(readyRead()), this, SLOT(procReadyRead())); +} + +TraceDialog::~TraceDialog() +{ + delete ui; +} + + +/* Protected methods */ + + +void TraceDialog::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + + +/* Private slots */ + + +void TraceDialog::printTrace(const QByteArray &data, bool directionRx) +{ + ui->textEdit->setTextColor((directionRx) ? Qt::darkBlue : Qt::darkGreen); + ui->textEdit->insertPlainText(QString(data)); + + QScrollBar *bar = ui->textEdit->verticalScrollBar(); + bar->setValue(bar->maximum()); +} + +void TraceDialog::procSendButtonClick() +{ + QByteArray data; + data.append(ui->lineEdit->text()); + if (data.size() > 0) { + m_port->write(data); + printTrace(data, false); + } +} + +void TraceDialog::procClearButtonClick() +{ + ui->textEdit->clear(); +} + +void TraceDialog::procReadyRead() +{ + QByteArray data = m_port->readAll(); + printTrace(data, true); +} diff --git a/tests/guiapp/tracedialog.h b/tests/guiapp/tracedialog.h new file mode 100644 index 0000000..8d5c58a --- /dev/null +++ b/tests/guiapp/tracedialog.h @@ -0,0 +1,34 @@ +#ifndef TRACEDIALOG_H +#define TRACEDIALOG_H + +#include <QtGui/QDialog> + +namespace Ui { +class TraceDialog; +} + +class SerialPort; + +class TraceDialog : public QDialog +{ + Q_OBJECT +public: + explicit TraceDialog(SerialPort *port, QWidget *parent = 0); + ~TraceDialog(); + +protected: + void changeEvent(QEvent *e); + +private slots: + void printTrace(const QByteArray &data, bool directionRx); + void procSendButtonClick(); + void procClearButtonClick(); + void procReadyRead(); + +private: + Ui::TraceDialog *ui; + + SerialPort *m_port; +}; + +#endif // TRACEDIALOG_H diff --git a/tests/guiapp/tracedialog.ui b/tests/guiapp/tracedialog.ui new file mode 100644 index 0000000..23ac69a --- /dev/null +++ b/tests/guiapp/tracedialog.ui @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>TraceDialog</class> + <widget class="QDialog" name="TraceDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>322</width> + <height>276</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" colspan="2"> + <widget class="QTextEdit" name="textEdit"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QPushButton" name="sendButton"> + <property name="text"> + <string>Send</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="lineEdit"/> + </item> + <item row="2" column="0"> + <widget class="QPushButton" name="clearButton"> + <property name="text"> + <string>Clear trace</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLabel" name="label_1"> + <property name="text"> + <string>(Here enter a line in text a format for sending, + for example: I will be transferred)</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Last error:</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLabel" name="lbError"> + <property name="text"> + <string>***</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> |