Skip to content

Commit

Permalink
Add option to edit saved dashboard names
Browse files Browse the repository at this point in the history
  • Loading branch information
basyskom-jvoe committed Mar 15, 2024
1 parent 31b0dc9 commit 6771da6
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ qt_add_resources(appOPC_UA_Browser "icons"
font/SwanseaBold.ttf
icons/arrow_right.svg
icons/back.svg
icons/cancel.svg
icons/checkmark.svg
icons/connect.svg
icons/dashboard.svg
icons/delete.svg
icons/disconnect.svg
icons/edit.svg
icons/event.svg
icons/expert.svg
icons/forward.svg
Expand Down
32 changes: 32 additions & 0 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,38 @@ int BackEnd::instantiateDefaultVariableDashboard(const QString &name)
return -1;
}

void BackEnd::renameSavedVariableDashboard(const QString &previousName, const QString &newName)
{

QSettings settings;
const QString settingsGroupName =
Constants::SettingsKey::DashboardsVariables % QChar::fromLatin1('/') % previousName;

if (previousName == newName
|| !mSavedVariableDashboardsModel->stringList().contains(previousName)
|| mSavedVariableDashboardsModel->stringList().contains(newName)
|| !settings.contains(settingsGroupName))
return;

const auto nodeIds = settings.value(Constants::SettingsKey::DashboardsVariables
% QChar::fromLatin1('/') % previousName)
.toStringList();

removeSavedVariableDashboard(previousName);

settings.setValue(Constants::SettingsKey::DashboardsVariables % QChar::fromLatin1('/')
% newName,
nodeIds);
addItemToStringListModel(mSavedVariableDashboardsModel, newName);

mDashboardItemModel->renameItem(previousName, newName);
}

bool BackEnd::hasSavedVariableDashboard(const QString &name) const
{
return mSavedVariableDashboardsModel->stringList().contains(name);
}

int BackEnd::instantiateCompanionSpecVariableDashboard(const QString &name)
{
assert(mDashboardItemModel);
Expand Down
3 changes: 3 additions & 0 deletions src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ class BackEnd : public QObject
Q_INVOKABLE void removeSavedVariableDashboard(const QString &name);
Q_INVOKABLE void loadDashboard(const QString &name);
Q_INVOKABLE int instantiateDefaultVariableDashboard(const QString &name);
Q_INVOKABLE void renameSavedVariableDashboard(const QString &previousName,
const QString &newName);
Q_INVOKABLE bool hasSavedVariableDashboard(const QString &name) const;

Q_INVOKABLE void loadLastDashboardsFromSettings();

Expand Down
17 changes: 17 additions & 0 deletions src/dashboarditemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ int DashboardItemModel::addItem(DashboardItem::DashboardType type, const QString
return pos;
}

void DashboardItemModel::renameItem(const QString &previousName, const QString &newName)
{
const auto item =
std::find_if(mItems.begin(), mItems.end(), [previousName](const DashboardItem *item) {
return item->name() == previousName;
});

if (item == mItems.end())
return;

(*item)->setName(newName);
const auto index = createIndex(std::distance(mItems.begin(), item), 0);
emit dataChanged(index, index, QList<int>() << DisplayNameRole);

saveDashboardsToSettings();
}

void DashboardItemModel::removeItem(int index)
{
// Add item is last item
Expand Down
1 change: 1 addition & 0 deletions src/dashboarditemmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class DashboardItemModel : public QAbstractListModel
bool containsItem(const QString &name) const noexcept;
int getIndexOfItem(const QString &name) const noexcept;
Q_INVOKABLE int addItem(DashboardItem::DashboardType type, const QString &name = QString());
void renameItem(const QString &previousName, const QString &newName);
Q_INVOKABLE void removeItem(int index);
void clearItems();

Expand Down
1 change: 1 addition & 0 deletions src/icons/cancel.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/cancel.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
1 change: 1 addition & 0 deletions src/icons/edit.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/edit.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
116 changes: 116 additions & 0 deletions src/qml/SettingsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ Rectangle {
spacing: 10

Text {
id: dashboardName
Layout.fillWidth: true
Layout.rightMargin: 5
Layout.leftMargin: 5
Expand All @@ -275,6 +276,22 @@ Rectangle {
elide: Text.ElideRight
}

IconImage {
Layout.alignment: Qt.AlignVCenter
sourceSize.width: 24
sourceSize.height: 24
source: "qrc:/icons/edit.svg"
color: view.theme.textColor

MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: function() {
dashboardNameEditPopup.showEdit(display)
}
}
}

IconImage {
Layout.alignment: Qt.AlignVCenter
Layout.rightMargin: 10
Expand Down Expand Up @@ -621,4 +638,103 @@ Rectangle {
}
}
}

Popup {
id: dashboardNameEditPopup
modal: true

implicitWidth: contentColumn.width
implicitHeight: contentColumn.height
padding: 0

clip: true
closePolicy: Popup.NoAutoClose

anchors.centerIn: parent

property string previousName

function showEdit(currentName: string) {
previousName = currentName
nameTextEdit.text = currentName
nameTextEdit.cursorPosition = currentName.length
open()
nameTextEdit.forceActiveFocus()
}

background: Rectangle {
radius: 3
opacity: 0.8
color: view.theme.popupBackground
}

ColumnLayout {
width: view.width - 50
id: contentColumn
Text {
padding: 3
font {
pointSize: 12
bold: true
}
color: view.theme.textColor
text: qsTranslate("Settings", "Enter new dashboard name")
}

TextEdit {
Layout.maximumWidth: contentColumn.width
id: nameTextEdit
padding: 3
font {
pointSize: 10
}
color: view.theme.textColor
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
cursorVisible: true
}

RowLayout {
IconImage {
Layout.margins: 5
Layout.alignment: Qt.AlignVCenter
sourceSize.width: 24
sourceSize.height: 24
source: "qrc:/icons/cancel.svg"
color: view.theme.textColor

MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: function() {
dashboardNameEditPopup.close()
}
}
}

Item {
Layout.fillWidth: true
height: 24
}

IconImage {
Layout.margins: 5
Layout.alignment: Qt.AlignVCenter
sourceSize.width: 24
sourceSize.height: 24
source: "qrc:/icons/checkmark.svg"
color: enabled ? view.theme.textColor : "lightgrey"
enabled: nameTextEdit.text !== "" && !BackEnd.hasSavedVariableDashboard(nameTextEdit.text)

MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: function() {
BackEnd.renameSavedVariableDashboard(dashboardNameEditPopup.previousName, nameTextEdit.text)
dashboardNameEditPopup.close()
}
}
}
}
}
}
}
1 change: 1 addition & 0 deletions src/qml/style/ThemeSettingsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ StyleDefinitions {
property color backgroundListView: dark
property color backgroundSelected: mediumDark
property color textColor: foreground
property color popupBackground: accent
}

0 comments on commit 6771da6

Please sign in to comment.