summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDenis Shienkov <scapig2@yandex.ru>2011-07-28 18:05:13 +0400
committerDenis Shienkov <scapig2@yandex.ru>2011-07-28 18:05:13 +0400
commit38fb5ad9b7ee16b4ab1b9f1b494a154e46f0a547 (patch)
treee4b4e3b8df77bc4748a679939cd0e3cbb36691df /tests
parenta4378f21c372c9ed6719eb4a1cc5cbd967a7403f (diff)
In directory /test added simple GUI application (guiapp) for testing library.
Diffstat (limited to 'tests')
-rw-r--r--tests/guiapp/guiapp.pro38
-rw-r--r--tests/guiapp/main.cpp11
-rw-r--r--tests/guiapp/mainwidget.cpp135
-rw-r--r--tests/guiapp/mainwidget.h40
-rw-r--r--tests/guiapp/mainwidget.ui263
-rw-r--r--tests/guiapp/optionswidget.cpp249
-rw-r--r--tests/guiapp/optionswidget.h39
-rw-r--r--tests/guiapp/optionswidget.ui91
-rw-r--r--tests/guiapp/tracewidget.cpp79
-rw-r--r--tests/guiapp/tracewidget.h34
-rw-r--r--tests/guiapp/tracewidget.ui70
11 files changed, 1049 insertions, 0 deletions
diff --git a/tests/guiapp/guiapp.pro b/tests/guiapp/guiapp.pro
new file mode 100644
index 00000000..415a32e5
--- /dev/null
+++ b/tests/guiapp/guiapp.pro
@@ -0,0 +1,38 @@
+QT += core gui
+TEMPLATE = app
+
+INCLUDEPATH += \
+ ../../include \
+ ../../src
+
+HEADERS += \
+ ../../include/serialport.h \
+ ../../include/serialportinfo.h
+
+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
+
+CONFIG(debug, debug|release) {
+ DESTDIR = debug
+ TARGET = guiappd
+} else {
+ DESTDIR = release
+ TARGET = guiapp
+}
+
+win32 {
+ LIBS += -lsetupapi -luuid -ladvapi32
+}
+unix:!macx {
+ LIBS += -ludev
+}
diff --git a/tests/guiapp/main.cpp b/tests/guiapp/main.cpp
new file mode 100644
index 00000000..0f3e0205
--- /dev/null
+++ b/tests/guiapp/main.cpp
@@ -0,0 +1,11 @@
+#include <QtGui/QApplication>
+#include "mainwidget.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWidget w;
+ w.show();
+
+ return a.exec();
+}
diff --git a/tests/guiapp/mainwidget.cpp b/tests/guiapp/mainwidget.cpp
new file mode 100644
index 00000000..f44e6352
--- /dev/null
+++ b/tests/guiapp/mainwidget.cpp
@@ -0,0 +1,135 @@
+#include <QtCore/QStringList>
+//#include <QtCore/QDebug>
+
+#include "mainwidget.h"
+#include "ui_mainwidget.h"
+#include "optionswidget.h"
+#include "tracewidget.h"
+
+#include "serialportinfo.h"
+#include "serialport.h"
+
+
+/* Public methods */
+
+
+MainWidget::MainWidget(QWidget *parent)
+ : QWidget(parent)
+ , ui(new Ui::MainWidget)
+ , m_optionsWidget(0)
+ , m_traceWidget(0)
+ , m_port(0)
+{
+ ui->setupUi(this);
+ m_port = new SerialPort(this);
+
+ procShowPorts();
+ procItemPortChanged(ui->boxName->currentIndex());
+
+ 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()));
+}
+
+MainWidget::~MainWidget()
+{
+ if (m_port->isOpen())
+ m_port->close();
+ if (m_optionsWidget)
+ delete m_optionsWidget;
+ if (m_traceWidget)
+ delete m_traceWidget;
+ delete ui;
+}
+
+
+/* Protected methods */
+
+
+void MainWidget::changeEvent(QEvent *e)
+{
+ QWidget::changeEvent(e);
+ switch (e->type()) {
+ case QEvent::LanguageChange:
+ ui->retranslateUi(this);
+ break;
+ default:
+ break;
+ }
+}
+
+
+/* Private slots */
+
+
+void MainWidget::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 MainWidget::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 MainWidget::procControlButtonClick()
+{
+ if (m_port->isOpen()) {
+ 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);
+ }
+ else {
+ m_port->setPort(ui->boxName->currentText());
+ if (m_port->open(QIODevice::ReadWrite)) {
+ 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);
+ }
+ }
+}
+
+void MainWidget::procOptionsButtonClick()
+{
+ if (!m_optionsWidget)
+ m_optionsWidget = new OptionsWidget(m_port);
+ m_optionsWidget->show();
+}
+
+void MainWidget::procIOButtonClick()
+{
+ if (!m_traceWidget)
+ m_traceWidget = new TraceWidget(m_port);
+ m_traceWidget->show();
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/guiapp/mainwidget.h b/tests/guiapp/mainwidget.h
new file mode 100644
index 00000000..4f249006
--- /dev/null
+++ b/tests/guiapp/mainwidget.h
@@ -0,0 +1,40 @@
+#ifndef MAINWIDGET_H
+#define MAINWIDGET_H
+
+#include <QtGui/QWidget>
+
+namespace Ui {
+ class MainWidget;
+}
+
+class SerialPort;
+class OptionsWidget;
+class TraceWidget;
+
+class MainWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit MainWidget(QWidget *parent = 0);
+ ~MainWidget();
+
+protected:
+ void changeEvent(QEvent *e);
+
+private slots:
+ void procShowPorts();
+ void procItemPortChanged(int idx);
+
+ void procControlButtonClick();
+ void procOptionsButtonClick();
+ void procIOButtonClick();
+
+private:
+ Ui::MainWidget *ui;
+ OptionsWidget *m_optionsWidget;
+ TraceWidget *m_traceWidget;
+ SerialPort *m_port;
+
+};
+
+#endif // MAINWIDGET_H
diff --git a/tests/guiapp/mainwidget.ui b/tests/guiapp/mainwidget.ui
new file mode 100644
index 00000000..69847f57
--- /dev/null
+++ b/tests/guiapp/mainwidget.ui
@@ -0,0 +1,263 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWidget</class>
+ <widget class="QWidget" name="MainWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>344</width>
+ <height>207</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="QPushButton" name="controlButton">
+ <property name="text">
+ <string>Open</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" rowspan="3">
+ <widget class="QGroupBox" name="groupBox">
+ <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="optionsButton">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Options</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" 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="3" column="0">
+ <widget class="QPushButton" name="rtsButton">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Set RTS</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" 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="4" 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="4" 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/optionswidget.cpp b/tests/guiapp/optionswidget.cpp
new file mode 100644
index 00000000..c47be9a7
--- /dev/null
+++ b/tests/guiapp/optionswidget.cpp
@@ -0,0 +1,249 @@
+#include <QtGui/QMessageBox>
+
+#include "optionswidget.h"
+#include "ui_optionswidget.h"
+
+#include "serialport.h"
+
+
+/* Public methods */
+
+
+OptionsWidget::OptionsWidget(SerialPort *port, QWidget *parent)
+ : QWidget(parent)
+ , ui(new Ui::OptionsWidget)
+ , 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()));
+}
+
+OptionsWidget::~OptionsWidget()
+{
+ delete ui;
+}
+
+
+/* Protected methods. */
+
+
+void OptionsWidget::showEvent(QShowEvent *e)
+{
+ Q_UNUSED(e)
+ detectOptions();
+}
+
+
+/* Private slots */
+
+
+void OptionsWidget::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 OptionsWidget::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 OptionsWidget::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/optionswidget.h b/tests/guiapp/optionswidget.h
new file mode 100644
index 00000000..063bc5b6
--- /dev/null
+++ b/tests/guiapp/optionswidget.h
@@ -0,0 +1,39 @@
+#ifndef OPTIONSWIDGET_H
+#define OPTIONSWIDGET_H
+
+#include <QtGui/QWidget>
+
+namespace Ui {
+ class OptionsWidget;
+}
+
+class SerialPort;
+
+class OptionsWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit OptionsWidget(SerialPort *port, QWidget *parent = 0);
+ ~OptionsWidget();
+
+protected:
+ void showEvent(QShowEvent *e);
+
+private slots:
+ void procFillingOptions();
+ void procApplyButtonClick();
+
+private:
+ Ui::OptionsWidget *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 // OPTIONSWIDGET_H
diff --git a/tests/guiapp/optionswidget.ui b/tests/guiapp/optionswidget.ui
new file mode 100644
index 00000000..9bce9295
--- /dev/null
+++ b/tests/guiapp/optionswidget.ui
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>OptionsWidget</class>
+ <widget class="QWidget" name="OptionsWidget">
+ <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/tracewidget.cpp b/tests/guiapp/tracewidget.cpp
new file mode 100644
index 00000000..b194dafb
--- /dev/null
+++ b/tests/guiapp/tracewidget.cpp
@@ -0,0 +1,79 @@
+#include <QtGui/QScrollBar>
+
+#include "tracewidget.h"
+#include "ui_tracewidget.h"
+
+#include "serialport.h"
+
+
+/* Public methods */
+
+
+TraceWidget::TraceWidget(SerialPort *port, QWidget *parent)
+ : QWidget(parent)
+ , ui(new Ui::TraceWidget)
+ , 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()));
+}
+
+TraceWidget::~TraceWidget()
+{
+ delete ui;
+}
+
+
+/* Protected methods */
+
+
+void TraceWidget::changeEvent(QEvent *e)
+{
+ QWidget::changeEvent(e);
+ switch (e->type()) {
+ case QEvent::LanguageChange:
+ ui->retranslateUi(this);
+ break;
+ default:
+ break;
+ }
+}
+
+
+/* Private slots */
+
+
+void TraceWidget::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 TraceWidget::procSendButtonClick()
+{
+ QByteArray data;
+ data.append(ui->lineEdit->text());
+ if (data.size() > 0) {
+ m_port->write(data);
+ printTrace(data, false);
+ }
+}
+
+void TraceWidget::procClearButtonClick()
+{
+ ui->textEdit->clear();
+}
+
+void TraceWidget::procReadyRead()
+{
+ QByteArray data = m_port->readAll();
+ printTrace(data, true);
+}
diff --git a/tests/guiapp/tracewidget.h b/tests/guiapp/tracewidget.h
new file mode 100644
index 00000000..da1a71d3
--- /dev/null
+++ b/tests/guiapp/tracewidget.h
@@ -0,0 +1,34 @@
+#ifndef TRACEWIDGET_H
+#define TRACEWIDGET_H
+
+#include <QtGui/QWidget>
+
+namespace Ui {
+ class TraceWidget;
+}
+
+class SerialPort;
+
+class TraceWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit TraceWidget(SerialPort *port, QWidget *parent = 0);
+ ~TraceWidget();
+
+protected:
+ void changeEvent(QEvent *e);
+
+private slots:
+ void printTrace(const QByteArray &data, bool directionRx);
+ void procSendButtonClick();
+ void procClearButtonClick();
+ void procReadyRead();
+
+private:
+ Ui::TraceWidget *ui;
+
+ SerialPort *m_port;
+};
+
+#endif // TRACEWIDGET_H
diff --git a/tests/guiapp/tracewidget.ui b/tests/guiapp/tracewidget.ui
new file mode 100644
index 00000000..a2668976
--- /dev/null
+++ b/tests/guiapp/tracewidget.ui
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TraceWidget</class>
+ <widget class="QWidget" name="TraceWidget">
+ <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>