diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-19 18:00:52 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-19 18:00:52 +0100 |
| commit | e73fe498e86dbb20d74f8d6ca13b541642676b82 (patch) | |
| tree | 572593fd880d10ae23544986116847271ee49f99 /src/BobinkNode.cpp | |
| parent | 50c62c35463b62a3a7acebf9ebe22d44f1c6dca2 (diff) | |
| download | BobinkQtOpcUa-e73fe498e86dbb20d74f8d6ca13b541642676b82.tar.gz BobinkQtOpcUa-e73fe498e86dbb20d74f8d6ca13b541642676b82.zip | |
Rename QML singleton to Bobink and simplify singleton lifecycle
Replace QML_ELEMENT with QML_NAMED_ELEMENT(Bobink) so QML references
use `Bobink` instead of `BobinkClient`. Remove instance()/create()
factory in favor of inline s_instance set in the constructor. Import
BobinkPlugin statically in demo, link demo to BobinkQtOpcUaplugin,
and make library link dependencies PUBLIC. Add .qtcreator to gitignore.
Diffstat (limited to 'src/BobinkNode.cpp')
| -rw-r--r-- | src/BobinkNode.cpp | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/BobinkNode.cpp b/src/BobinkNode.cpp index a39c195..fed87bc 100644 --- a/src/BobinkNode.cpp +++ b/src/BobinkNode.cpp @@ -104,7 +104,7 @@ BobinkNode::componentComplete () QQuickItem::componentComplete (); m_componentComplete = true; - auto *client = BobinkClient::instance (); + auto *client = BobinkClient::s_instance; if (client) connect (client, &BobinkClient::connectedChanged, this, &BobinkNode::handleClientConnectedChanged); @@ -137,7 +137,7 @@ BobinkNode::startMonitoring () if (m_opcuaNode || m_nodeId.isEmpty ()) return; - auto *client = BobinkClient::instance (); + auto *client = BobinkClient::s_instance; if (!client || !client->connected ()) return; @@ -245,11 +245,10 @@ BobinkNode::handleAttributeWritten (QOpcUa::NodeAttribute attr, void BobinkNode::handleClientConnectedChanged () { - auto *client = BobinkClient::instance (); - if (!client) + if (!BobinkClient::s_instance) return; - if (client->connected ()) + if (BobinkClient::s_instance->connected ()) { if (m_componentComplete && isVisible ()) startMonitoring (); @@ -263,8 +262,7 @@ BobinkNode::handleClientConnectedChanged () void BobinkNode::handleAttributeReadFinished (QOpcUa::NodeAttributes attrs) { - auto *client = BobinkClient::instance (); - if (!client || !m_opcuaNode) + if (!BobinkClient::s_instance || !m_opcuaNode) return; for (int bit = 0; bit < 27; ++bit) @@ -276,12 +274,12 @@ BobinkNode::handleAttributeReadFinished (QOpcUa::NodeAttributes attrs) auto sc = m_opcuaNode->attributeError (attr); QLatin1StringView name = nameFromAttribute (attr); if (sc == QOpcUa::UaStatusCode::Good) - emit client->statusMessage ( + emit BobinkClient::s_instance->statusMessage ( QStringLiteral ("Read %1.%2 = %3") .arg (m_nodeId, name, m_opcuaNode->attribute (attr).toString ())); else - emit client->statusMessage ( + emit BobinkClient::s_instance->statusMessage ( QStringLiteral ("Read %1.%2 failed: 0x%3") .arg (m_nodeId, name) .arg (static_cast<quint32> (sc), 8, 16, QLatin1Char ('0'))); @@ -292,15 +290,14 @@ void BobinkNode::handleEnableMonitoringFinished (QOpcUa::NodeAttribute, QOpcUa::UaStatusCode statusCode) { - auto *client = BobinkClient::instance (); - if (!client) + if (!BobinkClient::s_instance) return; if (statusCode == QOpcUa::Good) - emit client->statusMessage ( + emit BobinkClient::s_instance->statusMessage ( QStringLiteral ("Monitoring started: %1").arg (m_nodeId)); else - emit client->statusMessage ( + emit BobinkClient::s_instance->statusMessage ( QStringLiteral ("Monitoring failed for %1: 0x%2") .arg (m_nodeId) .arg (static_cast<quint32> (statusCode), 8, 16, @@ -311,15 +308,14 @@ void BobinkNode::handleDisableMonitoringFinished (QOpcUa::NodeAttribute, QOpcUa::UaStatusCode statusCode) { - auto *client = BobinkClient::instance (); - if (!client) + if (!BobinkClient::s_instance) return; if (statusCode == QOpcUa::Good) - emit client->statusMessage ( + emit BobinkClient::s_instance->statusMessage ( QStringLiteral ("Monitoring stopped: %1").arg (m_nodeId)); else - emit client->statusMessage ( + emit BobinkClient::s_instance->statusMessage ( QStringLiteral ("Stop monitoring failed for %1: 0x%2") .arg (m_nodeId) .arg (static_cast<quint32> (statusCode), 8, 16, |
