From fe05d3905f8b8997cd74ae1ff483a6fbbe5ccb4e Mon Sep 17 00:00:00 2001 From: Roman Vladimirov Date: Thu, 8 Feb 2024 21:39:48 +0300 Subject: [PATCH] * Remake changes mark on simple notification --- src/ListModels/globalvariableslistmodel.cpp | 28 ++++++--------------- src/ListModels/globalvariableslistmodel.h | 12 ++++----- src/Views/GlobalVariablesWindow.qml | 28 ++++++++++++++++----- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/ListModels/globalvariableslistmodel.cpp b/src/ListModels/globalvariableslistmodel.cpp index 06d6181..aae782e 100644 --- a/src/ListModels/globalvariableslistmodel.cpp +++ b/src/ListModels/globalvariableslistmodel.cpp @@ -142,7 +142,6 @@ void GlobalVariablesListModel::addLine() endResetModel(); emit hasLinesChanged(); - setChanges(); } void GlobalVariablesListModel::addLineBefore() @@ -158,7 +157,6 @@ void GlobalVariablesListModel::addLineBefore() endResetModel(); emit hasLinesChanged(); - setChanges(); } void GlobalVariablesListModel::addLineToEnd() @@ -171,7 +169,6 @@ void GlobalVariablesListModel::addLineToEnd() setSelected(m_lines.size() - 1); emit hasLinesChanged(); - setChanges(); } void GlobalVariablesListModel::removeSelectedLine() @@ -185,7 +182,6 @@ void GlobalVariablesListModel::removeSelectedLine() setSelected(m_selected >= m_lines.size() ? m_selected - 1 : m_selected); emit hasLinesChanged(); - setChanges(); } void GlobalVariablesListModel::removeAllLines() @@ -199,7 +195,6 @@ void GlobalVariablesListModel::removeAllLines() setSelected(0); emit hasLinesChanged(); - setChanges(); } void GlobalVariablesListModel::addVariable(const QString &name, const QString &value) @@ -207,6 +202,14 @@ void GlobalVariablesListModel::addVariable(const QString &name, const QString &v m_variables.insert(name, value); } +void GlobalVariablesListModel::setNeedShowSaveNotifications(bool needShowSaveNotifications) noexcept +{ + if (m_needShowSaveNotifications == needShowSaveNotifications) return; + + m_needShowSaveNotifications = needShowSaveNotifications; + emit needShowSaveNotificationsChanged(); +} + void GlobalVariablesListModel::setSelectedTab(const QString &selectedTab) noexcept { if (m_selectedTab == selectedTab) return; @@ -263,7 +266,6 @@ void GlobalVariablesListModel::fillLines() endResetModel(); emit hasLinesChanged(); - clearChanges(); if (m_selected >= m_lines.size()) setSelected(0); } @@ -313,7 +315,6 @@ void GlobalVariablesListModel::parseLines() } writeCache(); - clearChanges(); } void GlobalVariablesListModel::readCache() @@ -478,16 +479,3 @@ QString GlobalVariablesListModel::timeNowVariable(const QString &content) auto spaced = "{{ " + m_time24HoursNowGlobalVariable + " }}"; return QString(content).replace(nospaced, timeAsAstring).replace(spaced, timeAsAstring); } - -void GlobalVariablesListModel::setChanges() -{ - m_hasChanges = true; - emit hasChangesChanged(); -} - -void GlobalVariablesListModel::clearChanges() -{ - m_hasChanges = false; - emit hasChangesChanged(); -} - diff --git a/src/ListModels/globalvariableslistmodel.h b/src/ListModels/globalvariableslistmodel.h index ef0173a..45055e3 100644 --- a/src/ListModels/globalvariableslistmodel.h +++ b/src/ListModels/globalvariableslistmodel.h @@ -29,7 +29,7 @@ class GlobalVariablesListModel : public QAbstractListModel Q_PROPERTY(QStringList tabs READ tabs NOTIFY tabsChanged) Q_PROPERTY(QString selectedTab READ selectedTab WRITE setSelectedTab NOTIFY selectedTabChanged) Q_PROPERTY(bool hasLines READ hasLines NOTIFY hasLinesChanged FINAL) - Q_PROPERTY(bool hasChanges READ hasChanges NOTIFY hasChangesChanged FINAL) + Q_PROPERTY(bool needShowSaveNotifications READ needShowSaveNotifications WRITE setNeedShowSaveNotifications NOTIFY needShowSaveNotificationsChanged FINAL) private: enum GlobaVariablesRoles { @@ -50,7 +50,7 @@ class GlobalVariablesListModel : public QAbstractListModel bool m_helpVisible { false }; QStringList m_tabs { QStringList() }; QString m_selectedTab { "" }; - bool m_hasChanges { false }; + bool m_needShowSaveNotifications { true }; const QString VariablesTab { "Variables" }; const QString m_helpCommand { "globalvariableshelp" }; const QString m_closeWindowCommand { "globalvariablesclosewindow" }; @@ -98,7 +98,9 @@ class GlobalVariablesListModel : public QAbstractListModel QStringList tabs() const noexcept { return m_tabs; } bool hasLines() const noexcept { return !m_lines.isEmpty(); } - bool hasChanges() const noexcept { return m_hasChanges; } + + bool needShowSaveNotifications() const noexcept { return m_needShowSaveNotifications; } + void setNeedShowSaveNotifications(bool needShowSaveNotifications) noexcept; QString selectedTab() const noexcept { return m_selectedTab; } void setSelectedTab(const QString& selectedTab) noexcept; @@ -118,8 +120,6 @@ class GlobalVariablesListModel : public QAbstractListModel void fillHelpShortcuts(); QString dateTimeNowVariable(const QString& content); QString timeNowVariable(const QString& content); - void setChanges(); - void clearChanges(); signals: void selectedChanged(); @@ -129,7 +129,7 @@ class GlobalVariablesListModel : public QAbstractListModel void selectedTabChanged(); void tabsChanged(); void hasLinesChanged(); - void hasChangesChanged(); + void needShowSaveNotificationsChanged(); }; diff --git a/src/Views/GlobalVariablesWindow.qml b/src/Views/GlobalVariablesWindow.qml index 898deed..999ee16 100644 --- a/src/Views/GlobalVariablesWindow.qml +++ b/src/Views/GlobalVariablesWindow.qml @@ -114,13 +114,13 @@ ApplicationWindow { Item { id: notificationContainer - visible: backend.globalVariables.hasChanges + visible: backend.globalVariables.needShowSaveNotifications anchors.right: parent.right anchors.bottom: parent.bottom anchors.bottomMargin: 4 anchors.rightMargin: 4 - width: 200 - height: 60 + width: 260 + height: 80 Rectangle { anchors.fill: parent @@ -136,14 +136,30 @@ ApplicationWindow { anchors.left: parent.left anchors.leftMargin: 4 verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter + horizontalAlignment: Text.AlignJustify wrapMode: Text.WordWrap - font.pointSize: 9 + font.pointSize: 10 maximumLineCount: 3 elide: Text.ElideRight - color: "#996633" text: "Any changes will be discarded once the window is closed. Save your changes by pressing Ctrl-S." } + + IconButton { + id: closeButton + anchors.right: parent.right + anchors.top: parent.top + anchors.topMargin: 2 + anchors.rightMargin: 2 + icon: storagePaths.icons + "cancel.svg" + width: 22 + height: 22 + iconWidth: 20 + iconHeight: 20 + tooltipMessage: "Close notification" + onPressed: { + backend.globalVariables.needShowSaveNotifications = false; + } + } } ShorcutsHelperPanel {