summaryrefslogtreecommitdiffstats
path: root/examples/serialbus/can
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2015-08-21 01:03:47 +0300
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-08-31 09:17:20 +0000
commit0982955739c6b98b9dbe63efb6575cbf01aee1ec (patch)
treeed5dada3a4741a573944df26de142393cb4141d5 /examples/serialbus/can
parentd36bf099fcec17c19f42baea8ea313926544584b (diff)
Refactor the UI of CAN example application
* The SettingsDialog class is added * The menu-bar actions and icons are added * All widgets are wrapped with layouts * A code related to device accessing is modified Change-Id: I45d056951163441195f61df411669d1130a41867 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'examples/serialbus/can')
-rw-r--r--examples/serialbus/can/can.pro11
-rw-r--r--examples/serialbus/can/can.qrc9
-rw-r--r--examples/serialbus/can/images/application-exit.pngbin0 -> 11200 bytes
-rw-r--r--examples/serialbus/can/images/clear.pngbin0 -> 12543 bytes
-rw-r--r--examples/serialbus/can/images/connect.pngbin0 -> 15374 bytes
-rw-r--r--examples/serialbus/can/images/disconnect.pngbin0 -> 15092 bytes
-rw-r--r--examples/serialbus/can/images/settings.pngbin0 -> 16039 bytes
-rw-r--r--examples/serialbus/can/mainwindow.cpp180
-rw-r--r--examples/serialbus/can/mainwindow.h32
-rw-r--r--examples/serialbus/can/mainwindow.ui474
-rw-r--r--examples/serialbus/can/settingsdialog.cpp93
-rw-r--r--examples/serialbus/can/settingsdialog.h89
-rw-r--r--examples/serialbus/can/settingsdialog.ui145
13 files changed, 667 insertions, 366 deletions
diff --git a/examples/serialbus/can/can.pro b/examples/serialbus/can/can.pro
index 3e85168..a5e2b19 100644
--- a/examples/serialbus/can/can.pro
+++ b/examples/serialbus/can/can.pro
@@ -4,8 +4,13 @@ TARGET = can
TEMPLATE = app
SOURCES += main.cpp \
- mainwindow.cpp
+ mainwindow.cpp \
+ settingsdialog.cpp
-HEADERS += mainwindow.h
+HEADERS += mainwindow.h \
+ settingsdialog.h
-FORMS += mainwindow.ui
+FORMS += mainwindow.ui \
+ settingsdialog.ui
+
+RESOURCES += can.qrc
diff --git a/examples/serialbus/can/can.qrc b/examples/serialbus/can/can.qrc
new file mode 100644
index 0000000..0b49879
--- /dev/null
+++ b/examples/serialbus/can/can.qrc
@@ -0,0 +1,9 @@
+<RCC>
+ <qresource prefix="/">
+ <file>images/connect.png</file>
+ <file>images/disconnect.png</file>
+ <file>images/application-exit.png</file>
+ <file>images/settings.png</file>
+ <file>images/clear.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/serialbus/can/images/application-exit.png b/examples/serialbus/can/images/application-exit.png
new file mode 100644
index 0000000..32be6b3
--- /dev/null
+++ b/examples/serialbus/can/images/application-exit.png
Binary files differ
diff --git a/examples/serialbus/can/images/clear.png b/examples/serialbus/can/images/clear.png
new file mode 100644
index 0000000..aa612f1
--- /dev/null
+++ b/examples/serialbus/can/images/clear.png
Binary files differ
diff --git a/examples/serialbus/can/images/connect.png b/examples/serialbus/can/images/connect.png
new file mode 100644
index 0000000..dd5a51e
--- /dev/null
+++ b/examples/serialbus/can/images/connect.png
Binary files differ
diff --git a/examples/serialbus/can/images/disconnect.png b/examples/serialbus/can/images/disconnect.png
new file mode 100644
index 0000000..fd58f7a
--- /dev/null
+++ b/examples/serialbus/can/images/disconnect.png
Binary files differ
diff --git a/examples/serialbus/can/images/settings.png b/examples/serialbus/can/images/settings.png
new file mode 100644
index 0000000..3d1042e
--- /dev/null
+++ b/examples/serialbus/can/images/settings.png
Binary files differ
diff --git a/examples/serialbus/can/mainwindow.cpp b/examples/serialbus/can/mainwindow.cpp
index 2320c30..8ea4701 100644
--- a/examples/serialbus/can/mainwindow.cpp
+++ b/examples/serialbus/can/mainwindow.cpp
@@ -40,9 +40,10 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
+#include "settingsdialog.h"
-#include <QtSerialBus>
#include <QCanBusFrame>
+#include <QCanBus>
#include <QtCore/qbytearray.h>
#include <QtCore/qvariant.h>
@@ -50,53 +51,49 @@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
- deviceName(QStringLiteral("")),
- ui(new Ui::MainWindow)
+ m_ui(new Ui::MainWindow),
+ m_canDevice(Q_NULLPTR)
{
- ui->setupUi(this);
- init();
-}
+ m_ui->setupUi(this);
-MainWindow::~MainWindow()
-{
- delete ui;
-}
+ m_settings = new SettingsDialog;
+ m_status = new QLabel;
+ m_ui->statusBar->addWidget(m_status);
-void MainWindow::init()
-{
- QPointer<QCanBus> canBus = QCanBus::instance();
+ m_ui->sendMessagesBox->setEnabled(false);
+
+ initActionsConnections();
- plugins = canBus->plugins();
- for (int i = 0; i < plugins.size(); i++)
- ui->pluginBox->insertItem(i, plugins.at(i));
- connectDevice(ui->pluginBox->currentIndex());
+ connect(m_ui->sendButton, &QPushButton::clicked, this, &MainWindow::sendMessage);
}
-void MainWindow::connectDevice(int pluginIndex)
+MainWindow::~MainWindow()
{
- QPointer<QCanBus> canBus = QCanBus::instance();
-
- canDevice = canBus->createDevice(plugins.at(pluginIndex), deviceName);
-
- if (canDevice.isNull())
- return;
- connect(canDevice.data(), &QCanBusDevice::errorOccurred, this, &MainWindow::receiveError);
+ if (m_canDevice)
+ delete m_canDevice;
- if (!canDevice->connectDevice()) {
- canDevice.clear();
- return;
- }
- canDevice->setConfigurationParameter(QCanBusDevice::ReceiveOwnKey, QVariant(true));
- canDevice->setConfigurationParameter(
- QCanBusDevice::ErrorFilterKey,
- QVariant::fromValue(QCanBusFrame::FrameErrors(QCanBusFrame::AnyError)));
- connect(canDevice.data(), &QCanBusDevice::frameReceived,
- this, &MainWindow::checkMessages);
+ delete m_settings;
+ delete m_ui;
+}
- ui->deviceLabel->setText("Connected to: " + deviceName);
+void MainWindow::showStatusMessage(const QString &message)
+{
+ m_status->setText(message);
+}
- checkMessages();
+void MainWindow::initActionsConnections()
+{
+ m_ui->actionConnect->setEnabled(true);
+ m_ui->actionDisconnect->setEnabled(false);
+ m_ui->actionQuit->setEnabled(true);
+ m_ui->actionConfigure->setEnabled(true);
+
+ connect(m_ui->actionConnect, &QAction::triggered, this, &MainWindow::connectDevice);
+ connect(m_ui->actionDisconnect, &QAction::triggered, this, &MainWindow::disconnectDevice);
+ connect(m_ui->actionQuit, SIGNAL(triggered()), this, SLOT(close()));
+ connect(m_ui->actionConfigure, &QAction::triggered, m_settings, &SettingsDialog::show);
+ connect(m_ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
}
void MainWindow::receiveError(QCanBusDevice::CanBusError error) const
@@ -107,18 +104,71 @@ void MainWindow::receiveError(QCanBusDevice::CanBusError error) const
case QCanBusDevice::ConnectionError:
case QCanBusDevice::ConfigurationError:
case QCanBusDevice::UnknownError:
- qWarning() << canDevice->errorString();
+ qWarning() << m_canDevice->errorString();
default:
break;
}
}
+void MainWindow::connectDevice()
+{
+ const SettingsDialog::Settings p = m_settings->settings();
+
+ m_canDevice = QCanBus::instance()->createDevice(p.backendName.toLocal8Bit(), p.deviceInterfaceName);
+ if (!m_canDevice) {
+ showStatusMessage(tr("Connection error"));
+ return;
+ }
+
+ connect(m_canDevice, &QCanBusDevice::errorOccurred, this, &MainWindow::receiveError);
+ connect(m_canDevice, &QCanBusDevice::frameReceived, this, &MainWindow::checkMessages);
+
+ if (p.useConfigurationEnabled) {
+ foreach (const SettingsDialog::ConfigurationItem &item, p.configurations)
+ m_canDevice->setConfigurationParameter(item.first, item.second);
+ }
+
+ if (!m_canDevice->connectDevice()) {
+ delete m_canDevice;
+ m_canDevice = Q_NULLPTR;
+
+ showStatusMessage(tr("Connection error"));
+ } else {
+ m_ui->actionConnect->setEnabled(false);
+ m_ui->actionDisconnect->setEnabled(true);
+ m_ui->actionConfigure->setEnabled(false);
+
+ m_ui->sendMessagesBox->setEnabled(true);
+
+ showStatusMessage(tr("Backend: %1, Connected to: %2")
+ .arg(p.backendName).arg(p.deviceInterfaceName));
+ }
+}
+
+void MainWindow::disconnectDevice()
+{
+ if (!m_canDevice)
+ return;
+
+ m_canDevice->disconnectDevice();
+ delete m_canDevice;
+ m_canDevice = Q_NULLPTR;
+
+ m_ui->actionConnect->setEnabled(true);
+ m_ui->actionDisconnect->setEnabled(false);
+ m_ui->actionConfigure->setEnabled(true);
+
+ m_ui->sendMessagesBox->setEnabled(false);
+
+ showStatusMessage(tr("Disconnected"));
+}
+
void MainWindow::checkMessages()
{
- if (canDevice.isNull())
+ if (!m_canDevice)
return;
- const QCanBusFrame frame = canDevice->readFrame();
+ const QCanBusFrame frame = m_canDevice->readFrame();
if (frame.payload().isEmpty())
return;
@@ -140,68 +190,52 @@ void MainWindow::checkMessages()
}
if (frame.frameType() == QCanBusFrame::RemoteRequestFrame) {
- ui->requestList->addItem(view);
+ m_ui->requestList->addItem(view);
} else if (frame.frameType() == QCanBusFrame::ErrorFrame) {
- ui->errorList->addItem(view);
+ m_ui->errorList->addItem(view);
} else {
- ui->listWidget->addItem(view);
+ m_ui->listWidget->addItem(view);
}
}
-void MainWindow::on_sendButton_clicked() const
+void MainWindow::sendMessage() const
{
- if (canDevice.isNull())
+ if (!m_canDevice)
return;
- QByteArray writings = ui->lineEdit->displayText().toUtf8();
- ui->lineEdit->clear();
+ QByteArray writings = m_ui->lineEdit->displayText().toUtf8();
+ m_ui->lineEdit->clear();
QCanBusFrame frame;
- const int maxPayload = ui->fdBox->checkState() ? 64 : 8;
+ const int maxPayload = m_ui->fdBox->checkState() ? 64 : 8;
int size = writings.size();
if (size > maxPayload)
size = maxPayload;
writings = writings.left(size);
frame.setPayload(writings);
- qint32 id = ui->idEdit->displayText().toInt();
- ui->idEdit->clear();
- if (!ui->EFF->checkState() && id > 2047) //11 bits
+ qint32 id = m_ui->idEdit->displayText().toInt();
+ m_ui->idEdit->clear();
+ if (!m_ui->EFF->checkState() && id > 2047) //11 bits
id = 2047;
frame.setFrameId(id);
- frame.setExtendedFrameFormat(ui->EFF->checkState());
+ frame.setExtendedFrameFormat(m_ui->EFF->checkState());
- if (ui->remoteFrame->isChecked())
+ if (m_ui->remoteFrame->isChecked())
frame.setFrameType(QCanBusFrame::RemoteRequestFrame);
- else if (ui->errorFrame->isChecked())
+ else if (m_ui->errorFrame->isChecked())
frame.setFrameType(QCanBusFrame::ErrorFrame);
else
frame.setFrameType(QCanBusFrame::DataFrame);
- canDevice->writeFrame(frame);
-}
-
-void MainWindow::on_connectButton_clicked()
-{
- canDevice.clear();
- deviceName = ui->deviceEdit->text();
- ui->deviceEdit->clear();
- ui->deviceLabel->setText("Connected to:");
- connectDevice(ui->pluginBox->currentIndex());
-}
-
-void MainWindow::on_pluginBox_activated(int index)
-{
- canDevice.clear();
- ui->deviceLabel->setText("Connected to:");
- connectDevice(index);
+ m_canDevice->writeFrame(frame);
}
void MainWindow::interpretError(QString &view, const QCanBusFrame &frame)
{
- if (canDevice.isNull())
+ if (!m_canDevice)
return;
- view = canDevice->interpretErrorFrame(frame);
+ view = m_canDevice->interpretErrorFrame(frame);
}
diff --git a/examples/serialbus/can/mainwindow.h b/examples/serialbus/can/mainwindow.h
index 876c679..fe7e63c 100644
--- a/examples/serialbus/can/mainwindow.h
+++ b/examples/serialbus/can/mainwindow.h
@@ -41,17 +41,17 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
-#include <QCanBusDevice>
+#include <QCanBusDevice> // for CanBusError
#include <QMainWindow>
-#include <QPointer>
QT_BEGIN_NAMESPACE
-class QSerialBusBackend;
-class QCanBus;
-class QSerialBusDevice;
+class QLabel;
+
class QCanBusFrame;
+class SettingsDialog;
+
namespace Ui {
class MainWindow;
}
@@ -68,23 +68,21 @@ public:
~MainWindow();
private Q_SLOTS:
-
void checkMessages();
- void on_sendButton_clicked() const;
+ void sendMessage() const;
void receiveError(QCanBusDevice::CanBusError) const;
- void on_connectButton_clicked();
- void on_pluginBox_activated(int index);
+ void connectDevice();
+ void disconnectDevice();
private:
- void init();
- void connectDevice(int pluginIndex);
- void interpretError(QString&, const QCanBusFrame&);
-
- QPointer<QCanBusDevice> canDevice;
- QString deviceName;
- QList<QByteArray> plugins;
+ void showStatusMessage(const QString &message);
+ void initActionsConnections();
+ void interpretError(QString &, const QCanBusFrame &);
- Ui::MainWindow *ui;
+ Ui::MainWindow *m_ui;
+ QLabel *m_status;
+ SettingsDialog *m_settings;
+ QCanBusDevice *m_canDevice;
};
#endif // MAINWINDOW_H
diff --git a/examples/serialbus/can/mainwindow.ui b/examples/serialbus/can/mainwindow.ui
index fe32841..19d8188 100644
--- a/examples/serialbus/can/mainwindow.ui
+++ b/examples/serialbus/can/mainwindow.ui
@@ -6,292 +6,174 @@
<rect>
<x>0</x>
<y>0</y>
- <width>1254</width>
- <height>852</height>
+ <width>551</width>
+ <height>481</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
- <widget class="QLineEdit" name="lineEdit">
- <property name="geometry">
- <rect>
- <x>180</x>
- <y>40</y>
- <width>191</width>
- <height>27</height>
- </rect>
- </property>
- </widget>
- <widget class="QPushButton" name="sendButton">
- <property name="geometry">
- <rect>
- <x>190</x>
- <y>130</y>
- <width>191</width>
- <height>61</height>
- </rect>
- </property>
- <property name="text">
- <string>send</string>
- </property>
- </widget>
- <widget class="QListWidget" name="listWidget">
- <property name="geometry">
- <rect>
- <x>20</x>
- <y>250</y>
- <width>391</width>
- <height>541</height>
- </rect>
- </property>
- </widget>
- <widget class="QLineEdit" name="idEdit">
- <property name="geometry">
- <rect>
- <x>40</x>
- <y>40</y>
- <width>113</width>
- <height>27</height>
- </rect>
- </property>
- </widget>
- <widget class="QLabel" name="label">
- <property name="geometry">
- <rect>
- <x>40</x>
- <y>20</y>
- <width>67</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>Id</string>
- </property>
- </widget>
- <widget class="QLabel" name="label_2">
- <property name="geometry">
- <rect>
- <x>190</x>
- <y>20</y>
- <width>67</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>Data</string>
- </property>
- </widget>
- <widget class="QCheckBox" name="EFF">
- <property name="geometry">
- <rect>
- <x>320</x>
- <y>100</y>
- <width>97</width>
- <height>22</height>
- </rect>
- </property>
- <property name="text">
- <string>EFF</string>
- </property>
- </widget>
- <widget class="QListWidget" name="requestList">
- <property name="geometry">
- <rect>
- <x>420</x>
- <y>250</y>
- <width>411</width>
- <height>541</height>
- </rect>
- </property>
- </widget>
- <widget class="QListWidget" name="errorList">
- <property name="geometry">
- <rect>
- <x>840</x>
- <y>250</y>
- <width>401</width>
- <height>541</height>
- </rect>
- </property>
- </widget>
- <widget class="QLabel" name="label_4">
- <property name="geometry">
- <rect>
- <x>20</x>
- <y>230</y>
- <width>67</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>Messages</string>
- </property>
- </widget>
- <widget class="QLabel" name="label_5">
- <property name="geometry">
- <rect>
- <x>430</x>
- <y>227</y>
- <width>67</width>
- <height>20</height>
- </rect>
- </property>
- <property name="text">
- <string>Requests</string>
- </property>
- </widget>
- <widget class="QLabel" name="label_6">
- <property name="geometry">
- <rect>
- <x>860</x>
- <y>230</y>
- <width>67</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>Errors</string>
- </property>
- </widget>
- <widget class="QCheckBox" name="fdBox">
- <property name="geometry">
- <rect>
- <x>190</x>
- <y>100</y>
- <width>161</width>
- <height>22</height>
- </rect>
- </property>
- <property name="text">
- <string>Flexible Data-Rate</string>
- </property>
- </widget>
- <widget class="QPushButton" name="connectButton">
- <property name="geometry">
- <rect>
- <x>530</x>
- <y>130</y>
- <width>131</width>
- <height>61</height>
- </rect>
- </property>
- <property name="text">
- <string>Connect</string>
- </property>
- </widget>
- <widget class="QLineEdit" name="deviceEdit">
- <property name="geometry">
- <rect>
- <x>530</x>
- <y>40</y>
- <width>231</width>
- <height>27</height>
- </rect>
- </property>
- </widget>
- <widget class="QLabel" name="label_3">
- <property name="geometry">
- <rect>
- <x>530</x>
- <y>20</y>
- <width>67</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>Device</string>
- </property>
- </widget>
- <widget class="QLabel" name="deviceLabel">
- <property name="geometry">
- <rect>
- <x>530</x>
- <y>70</y>
- <width>441</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>Connected to:</string>
- </property>
- </widget>
- <widget class="QComboBox" name="pluginBox">
- <property name="geometry">
- <rect>
- <x>960</x>
- <y>40</y>
- <width>241</width>
- <height>27</height>
- </rect>
- </property>
- </widget>
- <widget class="QLabel" name="label_7">
- <property name="geometry">
- <rect>
- <x>960</x>
- <y>20</y>
- <width>67</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>Plugin</string>
- </property>
- </widget>
- <widget class="QGroupBox" name="groupBox">
- <property name="geometry">
- <rect>
- <x>40</x>
- <y>80</y>
- <width>141</width>
- <height>111</height>
- </rect>
- </property>
- <property name="title">
- <string>Frame Type</string>
- </property>
- <property name="checkable">
- <bool>false</bool>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QRadioButton" name="dataFrame">
- <property name="text">
- <string>Data</string>
- </property>
- <property name="checked">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QRadioButton" name="remoteFrame">
- <property name="text">
- <string>Remote Request</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QRadioButton" name="errorFrame">
- <property name="text">
- <string>Error</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="0" column="0">
+ <widget class="QGroupBox" name="sendMessagesBox">
+ <property name="title">
+ <string>Send CAN message</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Id</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="idEdit"/>
+ </item>
+ <item row="0" column="2" rowspan="3">
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Frame Type</string>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QRadioButton" name="dataFrame">
+ <property name="text">
+ <string>Data</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="remoteFrame">
+ <property name="text">
+ <string>Re&amp;mote Request</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="errorFrame">
+ <property name="text">
+ <string>Error</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="0" column="3">
+ <widget class="QCheckBox" name="fdBox">
+ <property name="text">
+ <string>Flexible Data-Rate</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3">
+ <widget class="QCheckBox" name="EFF">
+ <property name="text">
+ <string>EFF</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="3">
+ <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="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Data</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Messages</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Requests</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Errors</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QListWidget" name="listWidget"/>
+ </item>
+ <item row="1" column="1">
+ <widget class="QListWidget" name="requestList"/>
+ </item>
+ <item row="1" column="2">
+ <widget class="QListWidget" name="errorList"/>
+ </item>
+ </layout>
+ </item>
+ </layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>1254</width>
- <height>20</height>
+ <width>551</width>
+ <height>23</height>
</rect>
</property>
+ <widget class="QMenu" name="menuCalls">
+ <property name="title">
+ <string>&amp;Calls</string>
+ </property>
+ <addaction name="actionConnect"/>
+ <addaction name="actionDisconnect"/>
+ <addaction name="separator"/>
+ <addaction name="actionQuit"/>
+ </widget>
+ <widget class="QMenu" name="menuTools">
+ <property name="title">
+ <string>Too&amp;ls</string>
+ </property>
+ <addaction name="actionConfigure"/>
+ </widget>
+ <widget class="QMenu" name="menuHelp">
+ <property name="title">
+ <string>Help</string>
+ </property>
+ <addaction name="actionAboutQt"/>
+ </widget>
+ <addaction name="menuCalls"/>
+ <addaction name="menuTools"/>
+ <addaction name="menuHelp"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
@@ -300,10 +182,56 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
+ <addaction name="actionConnect"/>
+ <addaction name="actionDisconnect"/>
+ <addaction name="actionConfigure"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
+ <action name="actionConnect">
+ <property name="icon">
+ <iconset resource="can.qrc">
+ <normaloff>:/images/connect.png</normaloff>:/images/connect.png</iconset>
+ </property>
+ <property name="text">
+ <string>&amp;Connect</string>
+ </property>
+ </action>
+ <action name="actionDisconnect">
+ <property name="icon">
+ <iconset resource="can.qrc">
+ <normaloff>:/images/disconnect.png</normaloff>:/images/disconnect.png</iconset>
+ </property>
+ <property name="text">
+ <string>&amp;Disconnect</string>
+ </property>
+ </action>
+ <action name="actionQuit">
+ <property name="icon">
+ <iconset resource="can.qrc">
+ <normaloff>:/images/application-exit.png</normaloff>:/images/application-exit.png</iconset>
+ </property>
+ <property name="text">
+ <string>&amp;Quit</string>
+ </property>
+ </action>
+ <action name="actionConfigure">
+ <property name="icon">
+ <iconset resource="can.qrc">
+ <normaloff>:/images/settings.png</normaloff>:/images/settings.png</iconset>
+ </property>
+ <property name="text">
+ <string>&amp;Configure</string>
+ </property>
+ </action>
+ <action name="actionAboutQt">
+ <property name="text">
+ <string>&amp;About Qt</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
- <resources/>
+ <resources>
+ <include location="can.qrc"/>
+ </resources>
<connections/>
</ui>
diff --git a/examples/serialbus/can/settingsdialog.cpp b/examples/serialbus/can/settingsdialog.cpp
new file mode 100644
index 0000000..f082689
--- /dev/null
+++ b/examples/serialbus/can/settingsdialog.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the QtSerialBus module.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "settingsdialog.h"
+#include "ui_settingsdialog.h"
+
+#include <QCanBus>
+
+QT_USE_NAMESPACE
+
+SettingsDialog::SettingsDialog(QWidget *parent) :
+ QDialog(parent),
+ m_ui(new Ui::SettingsDialog)
+{
+ m_ui->setupUi(this);
+
+ connect(m_ui->applyButton, &QPushButton::clicked, this, &SettingsDialog::apply);
+ connect(m_ui->useConfigurationBox, &QCheckBox::clicked, m_ui->configurationBox, &QGroupBox::setEnabled);
+
+ fillBackends();
+
+ updateSettings();
+}
+
+SettingsDialog::~SettingsDialog()
+{
+ delete m_ui;
+}
+
+SettingsDialog::Settings SettingsDialog::settings() const
+{
+ return m_currentSettings;
+}
+
+void SettingsDialog::apply()
+{
+ updateSettings();
+ hide();
+}
+
+void SettingsDialog::updateSettings()
+{
+ m_currentSettings.backendName = m_ui->backendListBox->currentText();
+ m_currentSettings.deviceInterfaceName = m_ui->interfaceNameEdit->text();
+ m_currentSettings.useConfigurationEnabled = m_ui->useConfigurationBox->isChecked();
+
+ if (m_currentSettings.useConfigurationEnabled) {
+ // FIXME: update configuration
+ }
+}
+
+void SettingsDialog::fillBackends()
+{
+ foreach (const QByteArray &backend, QCanBus::instance()->plugins())
+ m_ui->backendListBox->addItem(backend);
+}
diff --git a/examples/serialbus/can/settingsdialog.h b/examples/serialbus/can/settingsdialog.h
new file mode 100644
index 0000000..0b62b3a
--- /dev/null
+++ b/examples/serialbus/can/settingsdialog.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the QtSerialBus module.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SETTINGSDIALOG_H
+#define SETTINGSDIALOG_H
+
+#include <QCanBusDevice>
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+
+namespace Ui {
+class SettingsDialog;
+}
+
+QT_END_NAMESPACE
+
+QT_USE_NAMESPACE
+
+class SettingsDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ typedef QPair<QCanBusDevice::ConfigurationKey, QVariant> ConfigurationItem;
+
+ struct Settings {
+ QString backendName;
+ QString deviceInterfaceName;
+ QList<ConfigurationItem> configurations;
+ bool useConfigurationEnabled;
+ };
+
+ explicit SettingsDialog(QWidget *parent = 0);
+ ~SettingsDialog();
+
+ Settings settings() const;
+
+private slots:
+ void apply();
+
+private:
+ void updateSettings();
+ void fillBackends();
+
+private:
+ Ui::SettingsDialog *m_ui;
+ Settings m_currentSettings;
+};
+
+#endif // SETTINGSDIALOG_H
diff --git a/examples/serialbus/can/settingsdialog.ui b/examples/serialbus/can/settingsdialog.ui
new file mode 100644
index 0000000..deebda0
--- /dev/null
+++ b/examples/serialbus/can/settingsdialog.ui
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SettingsDialog</class>
+ <widget class="QDialog" name="SettingsDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>406</width>
+ <height>246</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Settings</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_4">
+ <item row="0" column="0">
+ <widget class="QGroupBox" name="selectBackendBox">
+ <property name="title">
+ <string>Select CAN backend</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QComboBox" name="backendListBox"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="0" column="1" rowspan="3">
+ <widget class="QGroupBox" name="configurationBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="title">
+ <string>Specify Configuration</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QLabel" name="rawFilterLabel">
+ <property name="text">
+ <string>RAW Filter</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="rawFilterEdit"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="errorFilterLabel">
+ <property name="text">
+ <string>Error Filter</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="errorFilterEdit"/>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="loopbackLabel">
+ <property name="text">
+ <string>Loopback</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="lopbackEdit"/>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="receiveOwnLabel">
+ <property name="text">
+ <string>Receive Own</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLineEdit" name="receiveOwnEdit"/>
+ </item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="speedLabel">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Speed</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QLineEdit" name="speedEdit">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QGroupBox" name="specifyInterfaceNameBox">
+ <property name="title">
+ <string>Specify CAN interface name</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="0" column="0">
+ <widget class="QLineEdit" name="interfaceNameEdit"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QCheckBox" name="useConfigurationBox">
+ <property name="text">
+ <string>Use configuration</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" colspan="2">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>96</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="applyButton">
+ <property name="text">
+ <string>Apply</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>