Skip to content

Commit

Permalink
Add settings entry for the maximum number of events per object
Browse files Browse the repository at this point in the history
  • Loading branch information
basyskom-jvoe authored and khaexy committed Apr 2, 2024
1 parent fd992aa commit 9b3e2e2
Show file tree
Hide file tree
Showing 16 changed files with 199 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ qt_add_qml_module(appOPC_UA_Browser
qml/controls/StyledMenuItem.qml
qml/controls/StyledMenuSeparator.qml
qml/controls/StyledScrollBar.qml
qml/controls/StyledSpinBox.qml
qml/controls/StyledTabButton.qml
qml/controls/StyledTextField.qml
qml/style/Style.qml
Expand Down Expand Up @@ -73,6 +74,7 @@ qt_add_qml_module(appOPC_UA_Browser
qml/style/ThemeScrollBar.qml
qml/style/ThemeSettingsView.qml
qml/style/ThemeSideMenu.qml
qml/style/ThemeSpinBox.qml
qml/style/ThemeTabButton.qml
qml/style/ThemeTextField.qml
SOURCES attribute.h attribute.cpp
Expand Down Expand Up @@ -128,6 +130,7 @@ qt_add_resources(appOPC_UA_Browser "icons"
icons/menu.svg
icons/plus.svg
icons/refresh.svg
icons/minus.svg
icons/save.svg
icons/settings.svg
languages/English.png
Expand Down
32 changes: 31 additions & 1 deletion src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ BackEnd::BackEnd(QObject *parent)
//! [Application Identity]

QSettings settings;

mMaxEventsPerObject = settings.value(Constants::SettingsKey::MaxEventPerObject,
Constants::Defaults::MaxEventsPerObject)
.toInt();

settings.beginGroup(Constants::SettingsKey::DashboardsVariables);
QStringList keys = settings.childKeys();
settings.endGroup();
Expand Down Expand Up @@ -216,6 +221,13 @@ const QVector<CompanionSpecDevice> &BackEnd::companionSpecDevices() const noexce
}

OpcUaModel *BackEnd::getOpcUaModelForNode(QOpcUaNode *node)
{
const auto backend = getBackEndForNode(node);

return backend ? backend->mOpcUaModel : nullptr;
}

BackEnd *BackEnd::getBackEndForNode(QOpcUaNode *node)
{
if (!node)
return nullptr;
Expand All @@ -224,7 +236,7 @@ OpcUaModel *BackEnd::getOpcUaModelForNode(QOpcUaNode *node)
if (entry == mBackendMapping.constEnd())
return nullptr;

return entry.value() ? entry.value()->mOpcUaModel : nullptr;
return entry.value();
}

QOpcUaClient *BackEnd::getOpcUaClient()
Expand Down Expand Up @@ -1101,6 +1113,24 @@ QFuture<QString> BackEnd::findAllSubtypes(const QString &nodeId,
return future;
}

int BackEnd::maxEventsPerObject() const
{
return mMaxEventsPerObject;
}

void BackEnd::setMaxEventsPerObject(int newMaxEventsPerObject)
{
if (mMaxEventsPerObject == newMaxEventsPerObject)
return;

mMaxEventsPerObject = newMaxEventsPerObject;

QSettings settings;
settings.setValue(Constants::SettingsKey::MaxEventPerObject, newMaxEventsPerObject);

emit maxEventsPerObjectChanged();
}

CompanionSpecDevice *BackEnd::getCompanionSpecDeviceForNodeId(const QString &nodeId)
{
const auto entry = std::find_if(
Expand Down
11 changes: 11 additions & 0 deletions src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class BackEnd : public QObject
Q_PROPERTY(QVector<CompanionSpecDevice> companionSpecDevices READ companionSpecDevices NOTIFY
companionSpecDevicesChanged FINAL)

Q_PROPERTY(int maxEventsPerObject READ maxEventsPerObject WRITE setMaxEventsPerObject NOTIFY
maxEventsPerObjectChanged FINAL)

explicit BackEnd(QObject *parent = nullptr);
~BackEnd();

Expand Down Expand Up @@ -178,6 +181,7 @@ class BackEnd : public QObject
int instantiateCompanionSpecEventDashboard(const QString &name);

static OpcUaModel *getOpcUaModelForNode(QOpcUaNode *node);
static BackEnd *getBackEndForNode(QOpcUaNode *node);
QOpcUaClient *getOpcUaClient();

void addDefaultVariableDashboard(const QString &name);
Expand Down Expand Up @@ -219,6 +223,9 @@ class BackEnd : public QObject

Q_INVOKABLE void removeRecentConnection(const QString &name);

int maxEventsPerObject() const;
void setMaxEventsPerObject(int newMaxEventsPerObject);

signals:
void recentConnectionsChanged();
void serverListChanged();
Expand All @@ -238,6 +245,8 @@ class BackEnd : public QObject

void companionSpecDevicesChanged();

void maxEventsPerObjectChanged();

private slots:
void findServersComplete(const QList<QOpcUaApplicationDescription> &servers,
QOpcUa::UaStatusCode statusCode);
Expand Down Expand Up @@ -314,6 +323,8 @@ private slots:
QHash<QString, QList<DefaultEventDashboardNode>> mCompanionSpecEventDashboards;

QStringList mSelectedEventSourceNodes;

int mMaxEventsPerObject = 0;
};

#endif // BACKEND_H
1 change: 1 addition & 0 deletions src/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const QString SettingsKey::EventFilters = QStringLiteral("eventFilters");
const QString SettingsKey::RecentConnections = QStringLiteral("recentConnections");
const QString SettingsKey::Url = QStringLiteral("url");
const QString SettingsKey::Language = QStringLiteral("language");
const QString SettingsKey::MaxEventPerObject = QStringLiteral("maxEventsPerObject");

const QString CertInfo::CommonName = QStringLiteral("OpcUaBrowser");
const QString CertInfo::CountryName = QStringLiteral("DE");
Expand Down
7 changes: 7 additions & 0 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SettingsKey
const static QString RecentConnections;
const static QString Url;
const static QString Language;
const static QString MaxEventPerObject;
};

class CertInfo
Expand All @@ -68,6 +69,12 @@ class NamespaceUri
const static QString Woodworking;
const static QString Machinery;
};

class Defaults
{
public:
const static int MaxEventsPerObject = 25;
};
} // namespace Constants

#endif // CONSTANTS_H
1 change: 1 addition & 0 deletions src/icons/minus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/icons/minus.svg.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Google LLC

SPDX-License-Identifier: Apache-2.0
4 changes: 4 additions & 0 deletions src/languages/English_en_GB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,5 +454,9 @@
<source>Enter new dashboard name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Max. events per object</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
4 changes: 4 additions & 0 deletions src/languages/German_de_DE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,5 +454,9 @@
<source>Enter new dashboard name</source>
<translation>Neuen Dashboardnamen eingeben</translation>
</message>
<message>
<source>Max. events per object</source>
<translation>Max. Events pro Objekt</translation>
</message>
</context>
</TS>
11 changes: 9 additions & 2 deletions src/monitoreditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <QOpcUaNode>
#include <QOpcUaQualifiedName>

#include "backend.h"
#include "constants.h"
#include "monitoreditem.h"
#include "opcuahelper.h"

Expand Down Expand Up @@ -145,8 +147,13 @@ void MonitoredItem::handleEvent(const QVariantList &eventFields)
}

mLastEvents.push_front(eventStrings);
if (mLastEvents.length() > 25)
mLastEvents.pop_back();

const auto backend = BackEnd::getBackEndForNode(mOpcNode.get());
const auto maxEvents =
backend ? backend->maxEventsPerObject() : Constants::Defaults::MaxEventsPerObject;

if (mLastEvents.length() > maxEvents)
mLastEvents.resize(maxEvents);

emit lastEventsChanged();
}
Expand Down
23 changes: 23 additions & 0 deletions src/qml/SettingsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,29 @@ Rectangle {
}
}

// Dashboard settings
Column {
width: parent.width - content.leftPadding - content.rightPadding
spacing: 5

Text {
color: view.theme.textColor
font {
pointSize: 14
bold: true
}
text: qsTranslate("Dashboard", "Dashboard")
}

StyledSpinBox {
captionText: qsTranslate("Settings", "Max. events per object")
from: 1
to: 150
value: BackEnd.maxEventsPerObject
onValueChanged: BackEnd.maxEventsPerObject = value
}
}

// Certificate list view
Column {
width: parent.width - content.leftPadding - content.rightPadding
Expand Down
73 changes: 73 additions & 0 deletions src/qml/controls/StyledSpinBox.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* SPDX-FileCopyrightText: 2024 basysKom GmbH
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

import OPC_UA_Browser

ColumnLayout {
id: layout

property ThemeSpinBox theme: Style.spinBox
property alias captionText: caption.text
property alias from: spinBox.from
property alias to: spinBox.to
property alias value: spinBox.value

Text {
id: caption

verticalAlignment: Qt.AlignVCenter
color: layout.theme.textColor
font.bold: true
}

SpinBox {
id: spinBox
height: 30

background: Rectangle {
implicitWidth: 100
color: "transparent"
border.color: "transparent"
border.width: 0
}

contentItem: TextInput {
z: 2
text: spinBox.textFromValue(spinBox.value, spinBox.locale)

font: spinBox.font
color: theme.textColor
selectionColor: theme.textBackgroundSelected
selectedTextColor: theme.textColor
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter

readOnly: !spinBox.editable
validator: spinBox.validator
inputMethodHints: Qt.ImhFormattedNumbersOnly
}

up.indicator: IconImage {
x: spinBox.mirrored ? 0 : parent.width - width
sourceSize.width: 30
sourceSize.height: 30
source: "qrc:/icons/plus.svg"
color: spinBox.up.pressed || spinBox.to == value ? theme.buttonBackgroundSelected : theme.textColor
}

down.indicator: IconImage {
x: spinBox.mirrored ? parent.width - width : 0
sourceSize.width: 30
sourceSize.height: 30
source: "qrc:/icons/minus.svg"
color: spinBox.down.pressed || spinBox.from == value ? theme.buttonBackgroundSelected : theme.textColor
}
}
}
1 change: 1 addition & 0 deletions src/qml/style/Style.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ThemeDefault {
listView: currentTheme.listView
button: currentTheme.button
comboBox: currentTheme.comboBox
spinBox: currentTheme.spinBox
textField: currentTheme.textField
tabButton: currentTheme.tabButton
iconTabButton: currentTheme.iconTabButton
Expand Down
10 changes: 10 additions & 0 deletions src/qml/style/ThemeBright.qml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ ThemeDefault {
background: mediumLight
}

spinBox {
textColor: anthrazite

buttonBackground: foreground
buttonBackgroundSelected: mediumLight

textBackground: foreground
textBackgroundSelected: mediumLight
}

textField {
captionTextColor: anthrazite
background: foreground
Expand Down
1 change: 1 addition & 0 deletions src/qml/style/ThemeDefault.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ StyleDefinitions {
property ThemeIconTabButton iconTabButton: ThemeIconTabButton {}
property ThemeScrollBar scrollBar: ThemeScrollBar {}
property ThemeItemSelector itemSelector: ThemeItemSelector {}
property ThemeSpinBox spinBox: ThemeSpinBox {}
}
17 changes: 17 additions & 0 deletions src/qml/style/ThemeSpinBox.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* SPDX-FileCopyrightText: 2024 basysKom GmbH
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import QtQuick

StyleDefinitions {
property color textColor: foreground

property color buttonBackground: dark
property color buttonBackgroundSelected: mediumDark

property color textBackground: dark
property color textBackgroundSelected: mediumDark
}

0 comments on commit 9b3e2e2

Please sign in to comment.