Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnumValueType support #4

Open
wants to merge 37 commits into
base: dev
Choose a base branch
from
Open

EnumValueType support #4

wants to merge 37 commits into from

Conversation

CarlottaPat
Copy link

I would like to suggest a possible addition to the QOpcUa code.
In fact, the current version seems to lack the management of user-defined enum data types on the OPC UA server.
In my local code version I have inserted my two new files qopcuaenumvaluetype.cpp and qopcuaenumvaluetype.h in the folder qtopcua\src\opcua\client.

  • qopcuaenumvaluetype.h
#ifndef QOpcUaEnumValueType_H
#define QOpcUaEnumValueType_H

#include <QtOpcUa/qopcuaglobal.h>

#include <QtCore/qshareddata.h>
#include <QtCore/qvariant.h>

QT_BEGIN_NAMESPACE

class QOpcUaLocalizedText;
class QOpcUaEnumValueTypeData;

class Q_OPCUA_EXPORT QOpcUaEnumValueType
{
public:
    QOpcUaEnumValueType();
    QOpcUaEnumValueType(const QOpcUaEnumValueType&);
    QOpcUaEnumValueType(qint32 value, const QOpcUaLocalizedText& displayName, const QOpcUaLocalizedText& description);
    QOpcUaEnumValueType& operator=(const QOpcUaEnumValueType&);
    bool operator==(const QOpcUaEnumValueType& rhs) const;
    operator QVariant() const;
    ~QOpcUaEnumValueType();

    qint64 value() const;
    void setValue(qint64 value);

    QOpcUaLocalizedText displayName() const;
    void setDisplayName(const QOpcUaLocalizedText& displayName);

    QOpcUaLocalizedText description() const;
    void setDescription(const QOpcUaLocalizedText& description);

private:
    QSharedDataPointer<QOpcUaEnumValueTypeData> data;
};

QT_END_NAMESPACE

Q_DECLARE_METATYPE(QOpcUaEnumValueType)

#endif // QOpcUaEnumValueType_H

  • qopcuaenumvaluetype.cpp
#include "qopcuaenumvaluetype.h"
#include "qopcualocalizedtext.h"

QT_BEGIN_NAMESPACE

/*!
    \class QOpcUaEnumValueType
    \inmodule QtOpcUa
    \brief The OPC UA EnumValueType.

    This is the Qt OPC UA representation for the OPC UA XVType type defined in OPC-UA part 8, 5.6.8.
    This type is used to position values of float precision on an axis with double precision.
*/

class QOpcUaEnumValueTypeData : public QSharedData
{
public:
    qint64 value;
    QOpcUaLocalizedText displayName;
    QOpcUaLocalizedText description;
};

QOpcUaEnumValueType::QOpcUaEnumValueType()
    : data(new QOpcUaEnumValueTypeData)
{
}

/*!
    Constructs an XValue from \a rhs.
*/
QOpcUaEnumValueType::QOpcUaEnumValueType(const QOpcUaEnumValueType& rhs)
    : data(rhs.data)
{
}

/*!
    Constructs an XValue with position \a x and value \a value.
*/
QOpcUaEnumValueType::QOpcUaEnumValueType(qint32 value, const QOpcUaLocalizedText& displayName, const QOpcUaLocalizedText& description)
    : data(new QOpcUaEnumValueTypeData)
{
    data->value = value;
    data->displayName = displayName;
    data->description = description;
}

/*!
    Sets the values from \a rhs in this enum value type.
*/
QOpcUaEnumValueType& QOpcUaEnumValueType::operator=(const QOpcUaEnumValueType& rhs)
{
    if (this != &rhs)
        data.operator=(rhs.data);
    return *this;
}

/*!
    Returns \c true if this enum value type has the same value as \a rhs.
*/
bool QOpcUaEnumValueType::operator==(const QOpcUaEnumValueType& rhs) const
{
    return data->value == rhs.value() &&
        data->displayName == rhs.displayName() &&
        data->description == rhs.description();
}

/*!
    Converts this XValue to \l QVariant.
*/
QOpcUaEnumValueType::operator QVariant() const
{
    return QVariant::fromValue(*this);
}

QOpcUaEnumValueType::~QOpcUaEnumValueType()
{
}

/*!
    Returns the value.
*/
qint64 QOpcUaEnumValueType::value() const
{
    return data->value;
}

/*!
    Sets the value.
*/
void QOpcUaEnumValueType::setValue(qint64 value)
{
    data->value = value;
}

/*!
    Returns the display name.
*/
QOpcUaLocalizedText QOpcUaEnumValueType::displayName() const
{
    return data->displayName;
}

/*!
    Sets the display name.
*/
void QOpcUaEnumValueType::setDisplayName(const QOpcUaLocalizedText& displayName)
{
    data->displayName = displayName;
}

/*!
    Returns the description.
*/
QOpcUaLocalizedText QOpcUaEnumValueType::description() const
{
    return data->description;
}

/*!
    Sets the description.
*/
void QOpcUaEnumValueType::setDescription(const QOpcUaLocalizedText& description)
{
    data->description = description;
}

QT_END_NAMESPACE

In addition, I have also modified the following files:

  • I added my .h file include and the QOpcUaBinaryDataEncoding::decode method in qtopcua\src\opcua\client\qopcuabinarydataencoding.h

      #include <QtOpcUa/qopcuaenumvaluetype.h>
      . . . . . . . . .
      . . . . . . . . .
      template <>
      inline QOpcUaEnumValueType QOpcUaBinaryDataEncoding::decode<QOpcUaEnumValueType>(bool& success)
      {
          QOpcUaEnumValueType temp;
      
          temp.setValue(decode<qint64>(success));
          if (!success)
              return QOpcUaEnumValueType();
      
          temp.setDisplayName(decode<QOpcUaLocalizedText>(success));
          if (!success)
              return QOpcUaEnumValueType();
      
          temp.setDescription(decode<QOpcUaLocalizedText>(success));
          if (!success)
              return QOpcUaEnumValueType();
      
          return temp;
      }
    
  • I added my .h file include in qtopcua\src\opcua\core\qopcuaprovider.cpp
    #include <QtOpcUa/qopcuaenumvaluetype.h>

  • I had to modify the existing toQVariant method in qtopcua\src\plugins\opcua\open62541\qopen62541valueconverter.cpp (I added the case UA_TYPES_ENUMVALUETYPE statement):

   QVariant toQVariant(const UA_Variant &value)
   {
      if (value.type == nullptr) {
            return QVariant();
      }
      switch (value.type->typeIndex) {
      case UA_TYPES_BOOLEAN:
          return arrayToQVariant<bool, UA_Boolean>(value, QMetaType::Bool);
      case UA_TYPES_SBYTE:
          return arrayToQVariant<signed char, UA_SByte>(value, QMetaType::SChar);
          . . . . . . . . .
          . . . . . . . . .
      case UA_TYPES_DOUBLECOMPLEXNUMBERTYPE:
          return arrayToQVariant<QOpcUaDoubleComplexNumber, UA_DoubleComplexNumberType>(value);
      case UA_TYPES_XVTYPE:
          return arrayToQVariant<QOpcUaXValue, UA_XVType>(value);
      case UA_TYPES_ENUMVALUETYPE:
          return arrayToQVariant<QOpcUaEnumValueType, UA_EnumValueType>(value);
      default:
          qCWarning(QT_OPCUA_PLUGINS_OPEN62541) << "Variant conversion from Open62541 for typeName" << value.type->typeName << " not implemented";
          return QVariant();
      }
  }

I have added the scalarToQt<QOpcUaEnumValueType, UA_EnumValueType> method:

template<>
QOpcUaEnumValueType scalarToQt<QOpcUaEnumValueType, UA_EnumValueType>(const UA_EnumValueType* data)
 {
     return QOpcUaEnumValueType(data->value,
         scalarToQt<QOpcUaLocalizedText, UA_LocalizedText>(&data->displayName),
         scalarToQt<QOpcUaLocalizedText, UA_LocalizedText>(&data->description));
 }

I have modified the scalarToQt<QVariant, UA_ExtensionObject> method:

  template <>
  QVariant scalarToQt<QVariant, UA_ExtensionObject>(const UA_ExtensionObject *data)
  {
      // OPC-UA part 6, Table 13 states that an extension object can have no body, a ByteString encoded body
      // or an XML encoded body.
  
      // Handle extension object without body
      if (data->encoding == UA_EXTENSIONOBJECT_ENCODED_NOBODY) {
          QOpcUaExtensionObject obj;
          obj.setEncoding(QOpcUaExtensionObject::Encoding::NoBody);
          return QVariant::fromValue(obj);
      }
      . . . . . . . . .
      . . . . . . . . .
        if (data->content.decoded.type == &UA_TYPES[UA_TYPES_XVTYPE] && data->content.decoded.data) {
            return scalarToQt<QOpcUaXValue, UA_XVType>
                    (reinterpret_cast<UA_XVType *>(data->content.decoded.data));
        }

        if (data->content.decoded.type == &UA_TYPES[UA_TYPES_ENUMVALUETYPE] && data->content.decoded.data) {
            return scalarToQt<QOpcUaEnumValueType, UA_EnumValueType>
                (reinterpret_cast<UA_EnumValueType*>(data->content.decoded.data));
        }

        qCWarning(QT_OPCUA_PLUGINS_OPEN62541) << "Unsupported decoded extension object type, unable to convert" << data->content.decoded.type->typeName;
        return QVariant();
    }

  • Finally, in qtopcua\src\opcua\CMakeLists.txt also put my two added files:

     qt_internal_add_module(OpcUa
     PLUGIN_TYPES opcua
     SOURCES
     . . . . . . . . .
     client/qopcuaenumvaluetype.cpp client/qopcuaenumvaluetype.h
    

After these code additions and changes I successfully rebuilt the QOpcUa project and could access my custom enum types from my client (with the open62541 backend).
Would it be possible to contribute to the QOpcUa project with the above modifications?

kkoehne and others added 30 commits December 13, 2022 10:59
* Use qt_standard_project_setup()
* Use Qt6:: prefix, instead of Qt::
* Use private linkage wherever possible

Change-Id: I8af4fdeed78f7cba26308f1c7932e6f9fc256ade
Reviewed-by: Alexandru Croitor <[email protected]>
(cherry picked from commit c323ecb)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
Change-Id: I2d4d9b857e0a288b31e89e952465d8b98889deb6
Reviewed-by: Qt Submodule Update Bot <[email protected]>
All qt modules share a common documentation namespace. So avoid
overly generic page names - security is not only relevant in the
OPC UA context.

Change-Id: I188a1d66ee0b9e56ea7d7df2d598c79d1b64104f
Reviewed-by: Frank Meerkoetter <[email protected]>
(cherry picked from commit 471f739)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
Change-Id: I0227b003f39e3e2ba2da8d8db2d5312eac3675e3
Reviewed-by: Qt Submodule Update Bot <[email protected]>
- for Qt major greater than 5, look up the sources in 'Src' folder in
  the Qt installation
- the orginal relative path for MODULE_SOURCES given was also wrong.
  This is now fixed.

Fixes: QTBUG-109096
Change-Id: Iabcf8baaf1a440b863aaf9ead3cfbb63c98d8b02
Reviewed-by: Alexandru Croitor <[email protected]>
(cherry picked from commit 9b122a2)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
Change-Id: Iaaa36e090e791ad25e7eb7e5d9fa6bef338241fe
Reviewed-by: Qt Submodule Update Bot <[email protected]>
The custom Qt namespace should be reserved for Qt library types,
not example types. THerefore remove QT_BEGIN_NAMESPACE,
QT_END_NAMESPACE macros.

To keep compatibility with a namespaced Qt, we now include the
respective headers, instead of pre-declaring Qt types. Also
sort include lines while at it.

Change-Id: I8c4c6f5f2b5768eae297923e0081820ade8e50f4
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Frank Meerkoetter <[email protected]>
(cherry picked from commit 9130e53)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
Change-Id: I76183946f2d3e007fa695d5f50a1ccdff0a1a2bf
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: Ied7ce2c591bd66c3647ba5ce2a1f5242447e0555
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: I3433e2b64f522b94a940e815b69a506fb812278c
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: Icc2a49a97661dadc192454549a0f88bf218046a1
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: I527bb5cd6ad4255873f62a10954d6d853f85d4d0
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: Ifc44891eb8a8dd58071f9e238522b67b5e87354f
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Option has not effect anymore.

Change-Id: I5b714f75e954aa8c6ab997b60aa356fcab7e9eb4
Reviewed-by: Kai Köhne <[email protected]>
(cherry picked from commit 9d7b496)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
Change-Id: I469d17aec0613ad7059e634b31e30fb20c15dcf7
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: I596acc884a0f9258e55fbb1446c46dea527e6772
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: I9240450a41ad384be8eab874938c0fbecc936383
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: I3c074cf64e312ab1c0cd3ae4c1b884b11d455fd3
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: I2f4098bc91fbdbbc3db79deded2f13e3163f7252
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Namespaces are always uncreatable.

Fixes: QTBUG-110837
Change-Id: I9382acc5fefba1b17a1490aa0f53437f0a5c8608
Reviewed-by: Semih Yavuz <[email protected]>
Reviewed-by: Frank Meerkoetter <[email protected]>
(cherry picked from commit 54cec1b)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
Add missing header guards and exclude problematic source file.

Task-number: QTBUG-109394
Change-Id: I170824448de8b030b444ce9a5d9b15eeca145a22
Reviewed-by: Amir Masoud Abdol <[email protected]>
Reviewed-by: Frank Meerkoetter <[email protected]>
(cherry picked from commit 3adfac4)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
Change-Id: I17b48757cf0de6b123c96db4dfc7d227c6384071
Reviewed-by: Amir Masoud Abdol <[email protected]>
Reviewed-by: Frank Meerkoetter <[email protected]>
(cherry picked from commit ebe1296)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
Change-Id: Ide7badf35bc3f9009e11b92e5fecbb3d67c78e6d
Reviewed-by: Qt Submodule Update Bot <[email protected]>
We pulled in open62541 1.3.4 for the 6.5 release

Change-Id: Icad578676cbb36b8955730ec54dd5edfc5feccab
Reviewed-by: Frank Meerkoetter <[email protected]>
Change-Id: I51b2136694f4e6eae46246bf13f153ebf6169ee7
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: If7b4975f0a8f93602f7b46139f610e869d9bac9c
Reviewed-by: Qt Submodule Update Bot <[email protected]>
The logic to locate files relative to the binary is fragile. It is
currently broken for CMake on Windows, and not actually implemented
in qmake. Furthermore, it requires the binary directory to be
writable at runtime, because additional folders will be created
there.

Instead, embed the files via qrc, and extract them at runtime
into AppLocalDataLocation, which we know we can read/write to.

Fixes: QTBUG-109097
Change-Id: Ia6994339f4eba94ee6ef0cd82eadcc72563b7d47
Reviewed-by: Ivan Solovev <[email protected]>
(cherry picked from commit ddfe363)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
Change-Id: I1dcffa30ee6f82b23aec6e69fc45822bed95629c
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: I6138828d48d666cd561b5dd4a61e58074366df28
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: Ic2d08987b91e75e0ff64de5d455dc353b3323f0b
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Qt Submodule Update Bot added 6 commits March 11, 2023 02:14
Change-Id: I712f6fd5f4f159741b8bf6554bd4d455b504e4ce
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: Ib850601ac4a1a42845e6a0877e9bfad6e3438eec
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: I49463a71a1b9b5f5f12947dbf4c89e811ed202f3
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: Ic79082742f19a7c96849cde50206ac3ae9743158
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: I441745de20b7f037d7ea0c6b829b0ec8da80b880
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Change-Id: I4c907c29b3a0d3e07cae44d88a2456328f73c9c6
Reviewed-by: Qt Submodule Update Bot <[email protected]>
@CarlottaPat CarlottaPat changed the title 6.5.0 EnumValueType support Mar 27, 2023
Change-Id: Ic0094844704e5ded4e6e55189be28e7f1b38ae92
Reviewed-by: Qt Submodule Update Bot <[email protected]>
Copy link

cla-assistant bot commented Nov 15, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 6 committers have signed the CLA.

❌ Qt Submodule Update Bot
❌ kkoehne
❌ ShyamQt
❌ FriedemannKleint
❌ basyskom-meerkoetter
❌ semlanik


Qt Submodule Update Bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants