diff options
author | Rainer Keller <Rainer.Keller@qt.io> | 2018-09-13 10:04:07 +0200 |
---|---|---|
committer | Rainer Keller <Rainer.Keller@qt.io> | 2018-09-17 13:44:02 +0000 |
commit | cdf465babd7fbf406498d9963be28084d956e290 (patch) | |
tree | eb0f53b770e08702df0a2be2b4f724f39d352c08 | |
parent | 7a0eca889996309c04aca65a2fceea2a45d1a343 (diff) |
Convert QLocalizedText to a gadget
This will not add any overhead to execution but saves a lot of QML hassle
because the wrapper that was present before needs to have additional
converter functions to allow QML to unwrap LocalizedText to QLocalizedText
in case it is returned in a QVariant. This happens for example if a node
method called on a server returns such types.
Change-Id: I664c417d1bebdc266764d51d564d12d98a4101a9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r-- | src/imports/opcua/opcua.pro | 2 | ||||
-rw-r--r-- | src/imports/opcua/opcua_plugin.cpp | 3 | ||||
-rw-r--r-- | src/imports/opcua/opcuanode.cpp | 8 | ||||
-rw-r--r-- | src/imports/opcua/opcuanode.h | 14 | ||||
-rw-r--r-- | src/imports/opcua/opcuatype.cpp | 81 | ||||
-rw-r--r-- | src/imports/opcua/opcuatype.h | 58 | ||||
-rw-r--r-- | src/opcua/client/qopcuatype.cpp | 23 | ||||
-rw-r--r-- | src/opcua/client/qopcuatype.h | 4 |
8 files changed, 39 insertions, 154 deletions
diff --git a/src/imports/opcua/opcua.pro b/src/imports/opcua/opcua.pro index 64b2d6b..cacf552 100644 --- a/src/imports/opcua/opcua.pro +++ b/src/imports/opcua/opcua.pro @@ -14,7 +14,6 @@ SOURCES += \ opcuapathresolver.cpp \ opcuaattributevalue.cpp \ opcuaattributecache.cpp \ - opcuatype.cpp \ HEADERS += \ opcua_plugin.h \ @@ -30,7 +29,6 @@ HEADERS += \ opcuapathresolver.h \ opcuaattributecache.h \ opcuaattributevalue.h \ - opcuatype.h \ load(qml_plugin) diff --git a/src/imports/opcua/opcua_plugin.cpp b/src/imports/opcua/opcua_plugin.cpp index c99e367..7fefb15 100644 --- a/src/imports/opcua/opcua_plugin.cpp +++ b/src/imports/opcua/opcua_plugin.cpp @@ -42,7 +42,7 @@ #include "opcuaconnection.h" #include "opcuarelativenodepath.h" #include "opcuarelativenodeid.h" -#include "opcuatype.h" +#include "qopcuatype.h" #include <QLoggingCategory> #include <qqml.h> @@ -79,7 +79,6 @@ void OpcUaPlugin::registerTypes(const char *uri) qmlRegisterType<OpcUaRelativeNodePath>(uri, major, minor, "RelativeNodePath"); qmlRegisterType<OpcUaRelativeNodeId>(uri, major, minor, "RelativeNodeId"); qmlRegisterUncreatableMetaObject(Constants::staticMetaObject, uri, major, minor, "Constants", "This type can not be created."); - qmlRegisterUncreatableType<LocalizedText>(uri, major, minor, "LocalizedText", "This type can only be accessed as member of other elements"); // insert new versions here diff --git a/src/imports/opcua/opcuanode.cpp b/src/imports/opcua/opcuanode.cpp index edefaa3..28fe73c 100644 --- a/src/imports/opcua/opcuanode.cpp +++ b/src/imports/opcua/opcuanode.cpp @@ -192,26 +192,26 @@ QOpcUa::NodeClass OpcUaNode::nodeClass() return m_attributeCache.attributeValue(QOpcUa::NodeAttribute::NodeClass).value<QOpcUa::NodeClass>(); } -void OpcUaNode::setDisplayName(const LocalizedText &value) +void OpcUaNode::setDisplayName(const QOpcUa::QLocalizedText &value) { if (!m_connection || !m_node) return; m_node->writeAttribute(QOpcUa::NodeAttribute::DisplayName, value); } -LocalizedText OpcUaNode::displayName() +QOpcUa::QLocalizedText OpcUaNode::displayName() { return m_attributeCache.attributeValue(QOpcUa::NodeAttribute::DisplayName).value<QOpcUa::QLocalizedText>(); } -void OpcUaNode::setDescription(const LocalizedText &value) +void OpcUaNode::setDescription(const QOpcUa::QLocalizedText &value) { if (!m_connection || !m_node) return; m_node->writeAttribute(QOpcUa::NodeAttribute::Description, value); } -LocalizedText OpcUaNode::description() +QOpcUa::QLocalizedText OpcUaNode::description() { return m_attributeCache.attributeValue(QOpcUa::NodeAttribute::Description).value<QOpcUa::QLocalizedText>(); } diff --git a/src/imports/opcua/opcuanode.h b/src/imports/opcua/opcuanode.h index 9148fbf..c5763bd 100644 --- a/src/imports/opcua/opcuanode.h +++ b/src/imports/opcua/opcuanode.h @@ -37,7 +37,7 @@ #pragma once #include <QObject> -#include "opcuatype.h" +#include "qopcuatype.h" #include "universalnode.h" #include "opcuaattributecache.h" @@ -58,8 +58,8 @@ class OpcUaNode : public QObject // basic node properties Q_PROPERTY(QString browseName READ browseName WRITE setBrowseName NOTIFY browseNameChanged) Q_PROPERTY(QOpcUa::NodeClass nodeClass READ nodeClass NOTIFY nodeClassChanged) - Q_PROPERTY(LocalizedText displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged) - Q_PROPERTY(LocalizedText description READ description WRITE setDescription NOTIFY descriptionChanged) + Q_PROPERTY(QOpcUa::QLocalizedText displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged) + Q_PROPERTY(QOpcUa::QLocalizedText description READ description WRITE setDescription NOTIFY descriptionChanged) Q_ENUM(QOpcUa::NodeClass); @@ -75,11 +75,11 @@ public: QOpcUa::NodeClass nodeClass(); - void setDisplayName(const LocalizedText &value); - LocalizedText displayName(); + void setDisplayName(const QOpcUa::QLocalizedText &value); + QOpcUa::QLocalizedText displayName(); - void setDescription(const LocalizedText &value); - LocalizedText description(); + void setDescription(const QOpcUa::QLocalizedText &value); + QOpcUa::QLocalizedText description(); // This function is not exposed to QML const UniversalNode &resolvedNode() const; diff --git a/src/imports/opcua/opcuatype.cpp b/src/imports/opcua/opcuatype.cpp deleted file mode 100644 index 7b60f6d..0000000 --- a/src/imports/opcua/opcuatype.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt OPC UA module. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "opcuatype.h" - -QT_BEGIN_NAMESPACE - -/*! - \qmltype LocalizedText - \inqmlmodule QtOpcUa - \brief Contains a text with associated locale. - \since QtOpcUa 5.12 - - The two members of this type contain the actual text and the locale of the text. -*/ - -/*! - \qmlproperty string LocalizedText::text - - Textual content. -*/ - -/*! - \qmlproperty string LocalizedText::locale - - Locale of the contained text. - This has to be in a modified ISO standard notation, for example \c en-US. - See OPC UA specification part 3, 8.4 for details. -*/ - -LocalizedText::LocalizedText() -{ -} - -LocalizedText::LocalizedText(const QOpcUa::QLocalizedText &other) - : QLocalizedText(other) -{ -} - -LocalizedText &LocalizedText::operator=(const LocalizedText &rhs) -{ - if (this != &rhs) - QLocalizedText::operator =(rhs); - return *this; -} - -QT_END_NAMESPACE - diff --git a/src/imports/opcua/opcuatype.h b/src/imports/opcua/opcuatype.h deleted file mode 100644 index 8568ec7..0000000 --- a/src/imports/opcua/opcuatype.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt OPC UA module. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#pragma once - -#include <qopcuatype.h> - -QT_BEGIN_NAMESPACE - -class LocalizedText : public QOpcUa::QLocalizedText -{ - Q_GADGET - Q_PROPERTY(QString locale READ locale WRITE setLocale) - Q_PROPERTY(QString text READ text WRITE setText) - -public: - LocalizedText(); - LocalizedText(const QLocalizedText &other); - LocalizedText &operator=(const LocalizedText &); -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(LocalizedText) - diff --git a/src/opcua/client/qopcuatype.cpp b/src/opcua/client/qopcuatype.cpp index 45e6a7c..4512b17 100644 --- a/src/opcua/client/qopcuatype.cpp +++ b/src/opcua/client/qopcuatype.cpp @@ -621,6 +621,29 @@ void QOpcUa::QQualifiedName::setName(const QString &name) It can be used to provide multiple text strings in different languages for a value using an array of LocalizedText elements. */ +/*! + \qmltype LocalizedText + \inqmlmodule QtOpcUa + \brief Contains a text with associated locale. + \since QtOpcUa 5.12 + + The two members of this type contain the actual text and the locale of the text. +*/ + +/*! + \qmlproperty string LocalizedText::text + + Textual content. +*/ + +/*! + \qmlproperty string LocalizedText::locale + + Locale of the contained text. + This has to be in a modified ISO standard notation, for example \c en-US. + See OPC UA specification part 3, 8.4 for details. +*/ + class QOpcUa::QLocalizedTextData : public QSharedData { public: diff --git a/src/opcua/client/qopcuatype.h b/src/opcua/client/qopcuatype.h index 75ab057..77905be 100644 --- a/src/opcua/client/qopcuatype.h +++ b/src/opcua/client/qopcuatype.h @@ -513,6 +513,10 @@ private: class QLocalizedTextData; class Q_OPCUA_EXPORT QLocalizedText { + Q_GADGET + Q_PROPERTY(QString locale READ locale WRITE setLocale) + Q_PROPERTY(QString text READ text WRITE setText) + public: QLocalizedText(); QLocalizedText(const QOpcUa::QLocalizedText &); |