summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-09-17 03:04:54 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-09-17 03:05:00 +0200
commit0d3980e9282fb539671247a1c36810511ed43739 (patch)
tree173a0badd66dfa7585913c58ccb1648f8668612d
parentfb8b611a63a30aed7e3afe31de63929f3f293867 (diff)
parent8675d44f8f37793910e0d80a6ed5b40822f542cd (diff)
Merge "Merge remote-tracking branch 'origin/5.14' into 5.15"
-rw-r--r--examples/opcua/opcuaviewer/certificatedialog.cpp3
-rw-r--r--examples/opcua/opcuaviewer/mainwindow.cpp228
-rw-r--r--examples/opcua/opcuaviewer/mainwindow.h24
-rw-r--r--examples/opcua/opcuaviewer/mainwindow.ui184
-rw-r--r--examples/opcua/opcuaviewer/opcuaviewer.pro3
-rw-r--r--examples/opcua/opcuaviewer/treeitem.cpp66
-rw-r--r--examples/opcua/waterpump/simulationserver/simulationserver.cpp2
7 files changed, 332 insertions, 178 deletions
diff --git a/examples/opcua/opcuaviewer/certificatedialog.cpp b/examples/opcua/opcuaviewer/certificatedialog.cpp
index dd1b61a..2f98d6f 100644
--- a/examples/opcua/opcuaviewer/certificatedialog.cpp
+++ b/examples/opcua/opcuaviewer/certificatedialog.cpp
@@ -81,7 +81,8 @@ int CertificateDialog::showCertificate(const QString &message, const QByteArray
void CertificateDialog::saveCertificate()
{
const QByteArray digest = m_cert.digest();
- const QString path = m_trustListDirectory + "/" + digest.toHex() + ".der";
+ const QString path = m_trustListDirectory + QLatin1Char('/')
+ + QLatin1String(digest.toHex()) + QLatin1String(".der");
QFile file(path);
if (file.open(QIODevice::WriteOnly)) {
diff --git a/examples/opcua/opcuaviewer/mainwindow.cpp b/examples/opcua/opcuaviewer/mainwindow.cpp
index 589cd6d..810577d 100644
--- a/examples/opcua/opcuaviewer/mainwindow.cpp
+++ b/examples/opcua/opcuaviewer/mainwindow.cpp
@@ -51,21 +51,13 @@
#include "mainwindow.h"
#include "opcuamodel.h"
#include "certificatedialog.h"
+#include "ui_mainwindow.h"
-#include <QCoreApplication>
+#include <QApplication>
#include <QDir>
-#include <QLineEdit>
-#include <QComboBox>
#include <QMessageBox>
-#include <QHBoxLayout>
-#include <QVBoxLayout>
-#include <QPushButton>
-#include <QLabel>
#include <QTextCharFormat>
-#include <QPlainTextEdit>
#include <QTextBlock>
-#include <QTreeView>
-#include <QHeaderView>
#include <QOpcUaProvider>
#include <QOpcUaAuthenticationInformation>
#include <QOpcUaErrorState>
@@ -80,29 +72,34 @@ static void messageHandler(QtMsgType type, const QMessageLogContext &context, co
if (!mainWindowGlobal)
return;
- QString message = "%1: %2";
- QString contextStr = " (%1:%2, %3)";
- QString typeString;
-
- if (type == QtDebugMsg)
- typeString = QObject::tr("Debug");
- else if (type == QtInfoMsg)
- typeString = QObject::tr("Info");
- else if (type == QtWarningMsg)
- typeString = QObject::tr("Warning");
- else if (type == QtCriticalMsg)
- typeString = QObject::tr("Critical");
- else if (type == QtFatalMsg)
- typeString = QObject::tr("Fatal");
-
- message = message.arg(typeString).arg(msg);
- contextStr = contextStr.arg(context.file).arg(context.line).arg(context.function);
-
+ QString message;
QColor color = Qt::black;
- if (type == QtFatalMsg || type == QtCriticalMsg)
- color = Qt::darkRed;
- else if (type == QtWarningMsg)
+
+ switch (type) {
+ case QtWarningMsg:
+ message = QObject::tr("Warning");
color = Qt::darkYellow;
+ break;
+ case QtCriticalMsg:
+ message = QObject::tr("Critical");
+ color = Qt::darkRed;
+ break;
+ case QtFatalMsg:
+ message = QObject::tr("Fatal");
+ color = Qt::darkRed;
+ break;
+ case QtInfoMsg:
+ message = QObject::tr("Info");
+ break;
+ case QtDebugMsg:
+ message = QObject::tr("Debug");
+ break;
+ }
+ message += QLatin1String(": ");
+ message += msg;
+
+ const QString contextStr =
+ QStringLiteral(" (%1:%2, %3)").arg(context.file).arg(context.line).arg(context.function);
// Logging messages from backends are sent from different threads and need to be
// synchronized with the GUI thread.
@@ -116,70 +113,36 @@ static void messageHandler(QtMsgType type, const QMessageLogContext &context, co
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
- , mOpcUaPlugin(new QComboBox(this))
- , mHost(new QLineEdit(this))
- , mServers(new QComboBox(this))
- , mEndpoints(new QComboBox(this))
- , mFindServersButton(new QPushButton(tr("Find Servers"), this))
- , mGetEndpointsButton(new QPushButton(tr("Get Endpoints"), this))
- , mConnectButton(new QPushButton(tr("Connect"), this))
- , mLog(new QPlainTextEdit(this))
- , mTreeView(new QTreeView(this))
+ , ui(new Ui::MainWindow)
, mOpcUaModel(new OpcUaModel(this))
, mOpcUaProvider(new QOpcUaProvider(this))
- , mOpcUaClient(nullptr)
- , mClientConnected(false)
{
- int row = 0;
+ ui->setupUi(this);
mainWindowGlobal = this;
- auto grid = new QGridLayout;
- grid->addWidget(new QLabel(tr("Select OPC UA Backend:")), row, 0);
- grid->addWidget(mOpcUaPlugin, row, 1);
- grid->addWidget(new QLabel(tr("Select host to discover:")), ++row, 0);
- grid->addWidget(mHost, row, 1);
- grid->addWidget(mFindServersButton, row, 2);
- grid->addWidget(new QLabel(tr("Select OPC UA Server:")), ++row, 0);
- grid->addWidget(mServers, row, 1);
- grid->addWidget(mGetEndpointsButton, row, 2);
- grid->addWidget(new QLabel(tr("Select OPC UA Endpoint:")), ++row, 0);
- grid->addWidget(mEndpoints, row, 1);
- grid->addWidget(mConnectButton, row, 2);
-
- auto vbox = new QVBoxLayout;
- vbox->addLayout(grid);
- vbox->addWidget(mTreeView);
- vbox->addWidget(new QLabel(tr("Log:")));
- vbox->addWidget(mLog);
-
- auto widget = new QWidget;
- widget->setLayout(vbox);
- setCentralWidget(widget);
-
- mHost->setText("opc.tcp://localhost:48010");
- mEndpoints->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ connect(ui->quitAction, &QAction::triggered, this, &QWidget::close);
+ ui->quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
+
+ connect(ui->aboutAction, &QAction::triggered, this, &QApplication::aboutQt);
+ ui->aboutAction->setShortcut(QKeySequence(QKeySequence::HelpContents));
updateUiState();
- mOpcUaPlugin->addItems(mOpcUaProvider->availableBackends());
- mLog->setReadOnly(true);
- mLog->setLineWrapMode(QPlainTextEdit::NoWrap);
- setMinimumWidth(800);
- mTreeView->setModel(mOpcUaModel);
- mTreeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
- mTreeView->setTextElideMode(Qt::ElideRight);
- mTreeView->setAlternatingRowColors(true);
- mTreeView->setSelectionBehavior(QAbstractItemView::SelectItems);
-
- if (mOpcUaPlugin->count() == 0) {
- mOpcUaPlugin->setDisabled(true);
- mConnectButton->setDisabled(true);
+ ui->opcUaPlugin->addItems(mOpcUaProvider->availableBackends());
+ ui->treeView->setModel(mOpcUaModel);
+ ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
+
+ if (ui->opcUaPlugin->count() == 0) {
+ ui->opcUaPlugin->setDisabled(true);
+ ui->connectButton->setDisabled(true);
QMessageBox::critical(this, tr("No OPCUA plugins available"), tr("The list of available OPCUA plugins is empty. No connection possible."));
}
- connect(mFindServersButton, &QPushButton::clicked, this, &MainWindow::findServers);
- connect(mGetEndpointsButton, &QPushButton::clicked, this, &MainWindow::getEndpoints);
- connect(mConnectButton, &QPushButton::clicked, this, &MainWindow::connectToServer);
+ connect(ui->findServersButton, &QPushButton::clicked, this, &MainWindow::findServers);
+ connect(ui->host, &QLineEdit::returnPressed, this->ui->findServersButton,
+ [this]() { this->ui->findServersButton->animateClick(); });
+ connect(ui->getEndpointsButton, &QPushButton::clicked, this, &MainWindow::getEndpoints);
+ connect(ui->connectButton, &QPushButton::clicked, this, &MainWindow::connectToServer);
oldMessageHandler = qInstallMessageHandler(&messageHandler);
setupPkiConfiguration();
@@ -189,6 +152,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
//! [Application Identity]
}
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
//! [PKI Configuration]
void MainWindow::setupPkiConfiguration()
{
@@ -212,7 +180,7 @@ void MainWindow::setupPkiConfiguration()
void MainWindow::createClient()
{
if (mOpcUaClient == nullptr) {
- mOpcUaClient = mOpcUaProvider->createClient(mOpcUaPlugin->currentText());
+ mOpcUaClient = mOpcUaProvider->createClient(ui->opcUaPlugin->currentText());
if (!mOpcUaClient) {
const QString message(tr("Connecting to the given sever failed. See the log for details."));
log(message, QString(), Qt::red);
@@ -243,7 +211,7 @@ void MainWindow::findServers()
{
QStringList localeIds;
QStringList serverUris;
- QUrl url(mHost->text());
+ QUrl url(ui->host->text());
updateUiState();
@@ -262,11 +230,11 @@ void MainWindow::findServersComplete(const QVector<QOpcUaApplicationDescription>
QOpcUaApplicationDescription server;
if (isSuccessStatus(statusCode)) {
- mServers->clear();
+ ui->servers->clear();
for (const auto &server : servers) {
QVector<QString> urls = server.discoveryUrls();
for (const auto &url : qAsConst(urls))
- mServers->addItem(url);
+ ui->servers->addItem(url);
}
}
@@ -275,11 +243,11 @@ void MainWindow::findServersComplete(const QVector<QOpcUaApplicationDescription>
void MainWindow::getEndpoints()
{
- mEndpoints->clear();
+ ui->endpoints->clear();
updateUiState();
- if (mServers->currentIndex() >= 0) {
- const QString serverUrl = mServers->currentText();
+ if (ui->servers->currentIndex() >= 0) {
+ const QString serverUrl = ui->servers->currentText();
createClient();
mOpcUaClient->requestEndpoints(serverUrl);
}
@@ -306,7 +274,7 @@ void MainWindow::getEndpointsComplete(const QVector<QOpcUaEndpointDescription> &
const QString EndpointName = QString("%1 (%2)")
.arg(endpoint.securityPolicy())
.arg(modes[endpoint.securityMode()]);
- mEndpoints->addItem(EndpointName, index++);
+ ui->endpoints->addItem(EndpointName, index++);
}
}
@@ -320,8 +288,8 @@ void MainWindow::connectToServer()
return;
}
- if (mEndpoints->currentIndex() >= 0) {
- m_endpoint = mEndpointList[mEndpoints->currentIndex()];
+ if (ui->endpoints->currentIndex() >= 0) {
+ m_endpoint = mEndpointList[ui->endpoints->currentIndex()];
createClient();
mOpcUaClient->connectToEndpoint(m_endpoint);
}
@@ -354,7 +322,7 @@ void MainWindow::namespacesArrayUpdated(const QStringList &namespaceArray)
disconnect(mOpcUaClient, &QOpcUaClient::namespaceArrayUpdated, this, &MainWindow::namespacesArrayUpdated);
mOpcUaModel->setOpcUaClient(mOpcUaClient);
- mTreeView->header()->setSectionResizeMode(1 /* Value column*/, QHeaderView::Interactive);
+ ui->treeView->header()->setSectionResizeMode(1 /* Value column*/, QHeaderView::Interactive);
}
void MainWindow::clientError(QOpcUaClient::ClientError error)
@@ -370,46 +338,44 @@ void MainWindow::clientState(QOpcUaClient::ClientState state)
void MainWindow::updateUiState()
{
// allow changing the backend only if it was not already created
- mOpcUaPlugin->setEnabled(mOpcUaClient == nullptr);
- mConnectButton->setText(mClientConnected?tr("Disconnect"):tr("Connect"));
+ ui->opcUaPlugin->setEnabled(mOpcUaClient == nullptr);
+ ui->connectButton->setText(mClientConnected ? tr("Disconnect") : tr("Connect"));
if (mClientConnected) {
- mHost->setEnabled(false);
- mServers->setEnabled(false);
- mEndpoints->setEnabled(false);
- mFindServersButton->setEnabled(false);
- mGetEndpointsButton->setEnabled(false);
- mConnectButton->setEnabled(true);
- mConnectButton->setText(tr("Disconnect"));
+ ui->host->setEnabled(false);
+ ui->servers->setEnabled(false);
+ ui->endpoints->setEnabled(false);
+ ui->findServersButton->setEnabled(false);
+ ui->getEndpointsButton->setEnabled(false);
+ ui->connectButton->setEnabled(true);
} else {
- mHost->setEnabled(true);
- mServers->setEnabled(mServers->count() > 0);
- mEndpoints->setEnabled(mEndpoints->count() > 0);
-
- mFindServersButton->setDisabled(mHost->text().isEmpty());
- mGetEndpointsButton->setEnabled(mServers->currentIndex() != -1);
- mConnectButton->setEnabled(mEndpoints->currentIndex() != -1);
- mConnectButton->setText(tr("Connect"));
+ ui->host->setEnabled(true);
+ ui->servers->setEnabled(ui->servers->count() > 0);
+ ui->endpoints->setEnabled(ui->endpoints->count() > 0);
+
+ ui->findServersButton->setDisabled(ui->host->text().isEmpty());
+ ui->getEndpointsButton->setEnabled(ui->servers->currentIndex() != -1);
+ ui->connectButton->setEnabled(ui->endpoints->currentIndex() != -1);
}
if (!mOpcUaClient) {
- mServers->setEnabled(false);
- mEndpoints->setEnabled(false);
- mGetEndpointsButton->setEnabled(false);
- mConnectButton->setEnabled(false);
+ ui->servers->setEnabled(false);
+ ui->endpoints->setEnabled(false);
+ ui->getEndpointsButton->setEnabled(false);
+ ui->connectButton->setEnabled(false);
}
}
void MainWindow::log(const QString &text, const QString &context, QColor color)
{
- auto cf = mLog->currentCharFormat();
+ auto cf = ui->log->currentCharFormat();
cf.setForeground(color);
- mLog->setCurrentCharFormat(cf);
- mLog->appendPlainText(text);
+ ui->log->setCurrentCharFormat(cf);
+ ui->log->appendPlainText(text);
if (!context.isEmpty()) {
cf.setForeground(Qt::gray);
- mLog->setCurrentCharFormat(cf);
- mLog->insertPlainText(context);
+ ui->log->setCurrentCharFormat(cf);
+ ui->log->insertPlainText(context);
}
}
@@ -424,11 +390,10 @@ bool MainWindow::createPkiPath(const QString &path)
QDir dir;
const bool ret = dir.mkpath(path);
- if (ret) {
+ if (ret)
qDebug() << msg.arg(path).arg("SUCCESS.");
- } else {
- qCritical(msg.arg(path).arg("FAILED.").toLocal8Bit());
- }
+ else
+ qCritical("%s", qPrintable(msg.arg(path).arg("FAILED.")));
return ret;
}
@@ -456,23 +421,22 @@ bool MainWindow::createPkiFolders()
void MainWindow::showErrorDialog(QOpcUaErrorState *errorState)
{
- QString msg;
- CertificateDialog dlg;
int result = 0;
const QString statuscode = QOpcUa::statusToString(errorState->errorCode());
- if (errorState->isClientSideError())
- msg = tr("The client reported: ");
- else
- msg = tr("The server reported: ");
+ QString msg = errorState->isClientSideError() ? tr("The client reported: ") : tr("The server reported: ");
switch (errorState->connectionStep()) {
- case QOpcUaErrorState::ConnectionStep::CertificateValidation:
+ case QOpcUaErrorState::ConnectionStep::Unknown:
+ break;
+ case QOpcUaErrorState::ConnectionStep::CertificateValidation: {
+ CertificateDialog dlg(this);
msg += tr("Server certificate validation failed with error 0x%1 (%2).\nClick 'Abort' to abort the connect, or 'Ignore' to continue connecting.")
.arg(static_cast<ulong>(errorState->errorCode()), 8, 16, QLatin1Char('0')).arg(statuscode);
result = dlg.showCertificate(msg, m_endpoint.serverCertificate(), m_pkiConfig.trustListDirectory());
errorState->setIgnoreError(result == 1);
+ }
break;
case QOpcUaErrorState::ConnectionStep::OpenSecureChannel:
msg += tr("OpenSecureChannel failed with error 0x%1 (%2).").arg(errorState->errorCode(), 8, 16, QLatin1Char('0')).arg(statuscode);
diff --git a/examples/opcua/opcuaviewer/mainwindow.h b/examples/opcua/opcuaviewer/mainwindow.h
index cf8b5a6..c506df6 100644
--- a/examples/opcua/opcuaviewer/mainwindow.h
+++ b/examples/opcua/opcuaviewer/mainwindow.h
@@ -56,19 +56,19 @@
QT_BEGIN_NAMESPACE
-class QPlainTextEdit;
-class QLineEdit;
-class QComboBox;
-class QPushButton;
class QOpcUaProvider;
-class QTreeView;
class OpcUaModel;
+namespace Ui {
+class MainWindow;
+}
+
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
+ ~MainWindow();
Q_INVOKABLE void log(const QString &text, const QString &context, QColor color);
void log(const QString &text, QColor color = Qt::black);
@@ -93,20 +93,12 @@ private:
bool createPkiPath(const QString &path);
private:
- QComboBox *mOpcUaPlugin;
- QLineEdit *mHost;
- QComboBox *mServers;
- QComboBox *mEndpoints;
- QPushButton *mFindServersButton;
- QPushButton *mGetEndpointsButton;
- QPushButton *mConnectButton;
- QPlainTextEdit *mLog;
- QTreeView *mTreeView;
+ Ui::MainWindow *ui;
OpcUaModel *mOpcUaModel;
QOpcUaProvider *mOpcUaProvider;
- QOpcUaClient *mOpcUaClient;
+ QOpcUaClient *mOpcUaClient = nullptr;
QVector<QOpcUaEndpointDescription> mEndpointList;
- bool mClientConnected;
+ bool mClientConnected = false;
QOpcUaApplicationIdentity m_identity;
QOpcUaPkiConfiguration m_pkiConfig;
QOpcUaEndpointDescription m_endpoint; // current endpoint used to connect
diff --git a/examples/opcua/opcuaviewer/mainwindow.ui b/examples/opcua/opcuaviewer/mainwindow.ui
new file mode 100644
index 0000000..429a4e4
--- /dev/null
+++ b/examples/opcua/opcuaviewer/mainwindow.ui
@@ -0,0 +1,184 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>800</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="1" column="0">
+ <widget class="QTreeView" name="treeView">
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectItems</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Select OPC UA Backend:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QPushButton" name="findServersButton">
+ <property name="text">
+ <string>Find Servers</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2">
+ <widget class="QPushButton" name="getEndpointsButton">
+ <property name="text">
+ <string>Get Endpoints</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QComboBox" name="servers"/>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Select OPC UA Server:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="host">
+ <property name="text">
+ <string>opc.tcp://localhost:48010</string>
+ </property>
+ <property name="clearButtonEnabled">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="opcUaPlugin"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Select host to discover:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Select OPC UA Endpoint:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QComboBox" name="endpoints">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="2">
+ <widget class="QPushButton" name="connectButton">
+ <property name="text">
+ <string>Connect</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Log:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QPlainTextEdit" name="log">
+ <property name="lineWrapMode">
+ <enum>QPlainTextEdit::NoWrap</enum>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>30</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuFile">
+ <property name="title">
+ <string>File</string>
+ </property>
+ <addaction name="quitAction"/>
+ </widget>
+ <widget class="QMenu" name="menuHelp">
+ <property name="title">
+ <string>Help</string>
+ </property>
+ <addaction name="aboutAction"/>
+ </widget>
+ <addaction name="menuFile"/>
+ <addaction name="menuHelp"/>
+ </widget>
+ <widget class="QStatusBar" name="statusbar"/>
+ <action name="quitAction">
+ <property name="text">
+ <string>Quit</string>
+ </property>
+ </action>
+ <action name="actionHelp">
+ <property name="text">
+ <string>Help</string>
+ </property>
+ </action>
+ <action name="actionAbout_Qt">
+ <property name="text">
+ <string>About Qt</string>
+ </property>
+ </action>
+ <action name="aboutAction">
+ <property name="text">
+ <string>About Qt</string>
+ </property>
+ </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/opcua/opcuaviewer/opcuaviewer.pro b/examples/opcua/opcuaviewer/opcuaviewer.pro
index bc641d0..cbe8057 100644
--- a/examples/opcua/opcuaviewer/opcuaviewer.pro
+++ b/examples/opcua/opcuaviewer/opcuaviewer.pro
@@ -19,4 +19,5 @@ HEADERS += \
certificatedialog.h
FORMS += \
- certificatedialog.ui
+ certificatedialog.ui \
+ mainwindow.ui \
diff --git a/examples/opcua/opcuaviewer/treeitem.cpp b/examples/opcua/opcuaviewer/treeitem.cpp
index b069189..cbffd53 100644
--- a/examples/opcua/opcuaviewer/treeitem.cpp
+++ b/examples/opcua/opcuaviewer/treeitem.cpp
@@ -129,9 +129,9 @@ int TreeItem::columnCount() const
QVariant TreeItem::data(int column)
{
- if (column == 0) {
+ if (column == 0)
return mNodeBrowseName;
- } else if (column == 1) {
+ if (column == 1) {
if (!mAttributesReady)
return tr("Loading ...");
@@ -139,11 +139,13 @@ QVariant TreeItem::data(int column)
const auto value = mOpcNode->attribute(QOpcUa::NodeAttribute::Value);
return variantToString(value, type);
- } else if (column == 2) {
+ }
+ if (column == 2) {
QMetaEnum metaEnum = QMetaEnum::fromType<QOpcUa::NodeClass>();
QString name = metaEnum.valueToKey((uint)mNodeClass);
return name + " (" + QString::number((uint)mNodeClass) + ")";
- } else if (column == 3) {
+ }
+ if (column == 3) {
if (!mAttributesReady)
return tr("Loading ...");
@@ -153,15 +155,15 @@ QVariant TreeItem::data(int column)
if (enumEntry == QOpcUa::NodeIds::Namespace0::Unknown)
return typeId;
return QOpcUa::namespace0IdName(enumEntry) + " (" + typeId + ")";
- } else if (column == 4) {
+ }
+ if (column == 4)
return mNodeId;
- } else if (column == 5) {
+ if (column == 5)
return mNodeDisplayName;
- } else if (column == 6) {
- if (!mAttributesReady)
- return tr("Loading ...");
-
- return mOpcNode->attribute(QOpcUa::NodeAttribute::Description).value<QOpcUaLocalizedText>().text();
+ if (column == 6) {
+ return mAttributesReady
+ ? mOpcNode->attribute(QOpcUa::NodeAttribute::Description).value<QOpcUaLocalizedText>().text()
+ : tr("Loading ...");
}
return QVariant();
}
@@ -294,54 +296,64 @@ QString TreeItem::variantToString(const QVariant &value, const QString &typeNode
}
if (typeNodeId == QLatin1String("ns=0;i=2")) // Char
return QString::number(value.toInt());
- else if (typeNodeId == QLatin1String("ns=0;i=3")) // SChar
+ if (typeNodeId == QLatin1String("ns=0;i=3")) // SChar
return QString::number(value.toUInt());
- else if (typeNodeId == QLatin1String("ns=0;i=4")) // Int16
+ if (typeNodeId == QLatin1String("ns=0;i=4")) // Int16
return QString::number(value.toInt());
- else if (typeNodeId == QLatin1String("ns=0;i=5")) // UInt16
+ if (typeNodeId == QLatin1String("ns=0;i=5")) // UInt16
return QString::number(value.toUInt());
- else if (value.type() == QVariant::ByteArray)
+ if (value.type() == QVariant::ByteArray)
return QLatin1String("0x") + value.toByteArray().toHex();
- else if (value.type() == QVariant::DateTime)
+ if (value.type() == QVariant::DateTime)
return value.toDateTime().toString(Qt::ISODate);
- else if (value.canConvert<QOpcUaQualifiedName>()) {
+ if (value.canConvert<QOpcUaQualifiedName>()) {
const auto name = value.value<QOpcUaQualifiedName>();
return QStringLiteral("[NamespaceIndex: %1, Name: \"%2\"]").arg(name.namespaceIndex()).arg(name.name());
- } else if (value.canConvert<QOpcUaLocalizedText>()) {
+ }
+ if (value.canConvert<QOpcUaLocalizedText>()) {
const auto text = value.value<QOpcUaLocalizedText>();
return localizedTextToString(text);
- } else if (value.canConvert<QOpcUaRange>()) {
+ }
+ if (value.canConvert<QOpcUaRange>()) {
const auto range = value.value<QOpcUaRange>();
return rangeToString(range);
- } else if (value.canConvert<QOpcUaComplexNumber>()) {
+ }
+ if (value.canConvert<QOpcUaComplexNumber>()) {
const auto complex = value.value<QOpcUaComplexNumber>();
return QStringLiteral("[Real: %1, Imaginary: %2]").arg(complex.real()).arg(complex.imaginary());
- } else if (value.canConvert<QOpcUaDoubleComplexNumber>()) {
+ }
+ if (value.canConvert<QOpcUaDoubleComplexNumber>()) {
const auto complex = value.value<QOpcUaDoubleComplexNumber>();
return QStringLiteral("[Real: %1, Imaginary: %2]").arg(complex.real()).arg(complex.imaginary());
- } else if (value.canConvert<QOpcUaXValue>()) {
+ }
+ if (value.canConvert<QOpcUaXValue>()) {
const auto xv = value.value<QOpcUaXValue>();
return QStringLiteral("[X: %1, Value: %2]").arg(xv.x()).arg(xv.value());
- } else if (value.canConvert<QOpcUaEUInformation>()) {
+ }
+ if (value.canConvert<QOpcUaEUInformation>()) {
const auto info = value.value<QOpcUaEUInformation>();
return euInformationToString(info);
- } else if (value.canConvert<QOpcUaAxisInformation>()) {
+ }
+ if (value.canConvert<QOpcUaAxisInformation>()) {
const auto info = value.value<QOpcUaAxisInformation>();
return QStringLiteral("[EUInformation: %1, EURange: %2, Title: %3 , AxisScaleType: %4, AxisSteps: %5]").arg(
euInformationToString(info.engineeringUnits())).arg(rangeToString(info.eURange())).arg(localizedTextToString(info.title())).arg(
info.axisScaleType() == QOpcUa::AxisScale::Linear ? "Linear" : (info.axisScaleType() == QOpcUa::AxisScale::Ln) ? "Ln" : "Log").arg(
numberArrayToString(info.axisSteps()));
- } else if (value.canConvert<QOpcUaExpandedNodeId>()) {
+ }
+ if (value.canConvert<QOpcUaExpandedNodeId>()) {
const auto id = value.value<QOpcUaExpandedNodeId>();
return QStringLiteral("[NodeId: \"%1\", ServerIndex: \"%2\", NamespaceUri: \"%3\"]").arg(
id.nodeId()).arg(id.serverIndex()).arg(id.namespaceUri());
- } else if (value.canConvert<QOpcUaArgument>()) {
+ }
+ if (value.canConvert<QOpcUaArgument>()) {
const auto a = value.value<QOpcUaArgument>();
return QStringLiteral("[Name: \"%1\", DataType: \"%2\", ValueRank: \"%3\", ArrayDimensions: %4, Description: %5]").arg(
a.name()).arg(a.dataTypeId()).arg(a.valueRank()).arg(numberArrayToString(a.arrayDimensions())).arg(
localizedTextToString(a.description()));
- } else if (value.canConvert<QOpcUaExtensionObject>()) {
+ }
+ if (value.canConvert<QOpcUaExtensionObject>()) {
const auto obj = value.value<QOpcUaExtensionObject>();
return QStringLiteral("[TypeId: \"%1\", Encoding: %2, Body: 0x%3]").arg(obj.encodingTypeId()).arg(
obj.encoding() == QOpcUaExtensionObject::Encoding::NoBody ?
diff --git a/examples/opcua/waterpump/simulationserver/simulationserver.cpp b/examples/opcua/waterpump/simulationserver/simulationserver.cpp
index 7e8014d..edce931 100644
--- a/examples/opcua/waterpump/simulationserver/simulationserver.cpp
+++ b/examples/opcua/waterpump/simulationserver/simulationserver.cpp
@@ -95,7 +95,7 @@ bool DemoServer::init()
if (!m_server)
return false;
- UA_StatusCode result = UA_ServerConfig_setMinimal(UA_Server_getConfig(m_server), 34433, nullptr);
+ UA_StatusCode result = UA_ServerConfig_setMinimal(UA_Server_getConfig(m_server), 43344, nullptr);
if (result != UA_STATUSCODE_GOOD)
return false;