diff --git a/.gitmodules b/.gitmodules index 963a78d4941cc5d3bfc70e6bff136c5fc1a1362c..849c3bc03923a8ce85f4bb8e40b248f5a8a36c19 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ +[submodule "libdap"] + path = libdap + url = https://github.com/kelvinblockchain/libdap.git + branch = master [submodule "libdap-qt-ui-qml"] path = libdap-qt-ui-qml url = git://github.com/kelvinblockchain/libdap-qt-ui-qml.git diff --git a/KelvinDashboardGUI/DapScreenDialog.cpp b/KelvinDashboardGUI/DapScreenDialog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f044c6616751016e7696c6dfb7e831624b692b22 --- /dev/null +++ b/KelvinDashboardGUI/DapScreenDialog.cpp @@ -0,0 +1,19 @@ +#include "DapScreenDialog.h" + +DapScreenDialog::DapScreenDialog(QObject *parent) : QObject(parent) +{ + m_proxyModel = new QSortFilterProxyModel; + m_proxyModel->setSourceModel(&DapUiQmlWidgetModel::getInstance()); + m_proxyModel->setFilterRegExp(QRegExp("true")); + m_proxyModel->setFilterRole(VisibleRole); +} + +QSortFilterProxyModel *DapScreenDialog::proxyModel() const +{ + return m_proxyModel; +} + +void DapScreenDialog::setProxyModel(QSortFilterProxyModel *proxyModel) +{ + m_proxyModel = proxyModel; +} diff --git a/KelvinDashboardGUI/DapScreenDialog.h b/KelvinDashboardGUI/DapScreenDialog.h index c3a5028c8c1f0b82f82674fbbdfdcf1f77a0a0c3..039794888c94f520ba4354e15cf6bcb8c5530ef8 100644 --- a/KelvinDashboardGUI/DapScreenDialog.h +++ b/KelvinDashboardGUI/DapScreenDialog.h @@ -1,11 +1,27 @@ -#ifndef DAPUIQMLSCREENDIALOG_H -#define DAPUIQMLSCREENDIALOG_H +#ifndef DAPSCREENDIALOG_H +#define DAPSCREENDIALOG_H +#include <QObject> +#include <QSortFilterProxyModel> -class DapUiQmlScreenDialog +#include "DapUiQmlWidgetModel.h" + +class DapScreenDialog : public QObject { + Q_OBJECT + + QSortFilterProxyModel *m_proxyModel; public: - DapUiQmlScreenDialog(); + explicit DapScreenDialog(QObject *parent = nullptr); + + Q_PROPERTY(QSortFilterProxyModel* ProxyModel MEMBER m_proxyModel READ proxyModel WRITE setProxyModel NOTIFY proxyModelChanged) + + QSortFilterProxyModel *proxyModel() const; + void setProxyModel(QSortFilterProxyModel *proxyModel); + +signals: + void proxyModelChanged(QSortFilterProxyModel *proxyModel); +public slots: }; -#endif // DAPUIQMLSCREENDIALOG_H +#endif // DAPSCREENDIALOG_H diff --git a/KelvinDashboardGUI/DapScreenDialogChangeWidget.cpp b/KelvinDashboardGUI/DapScreenDialogChangeWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea0f064d124c6375c6fb2f9f6f317c3f13831b94 --- /dev/null +++ b/KelvinDashboardGUI/DapScreenDialogChangeWidget.cpp @@ -0,0 +1,19 @@ +#include "DapScreenDialogChangeWidget.h" + +DapScreenDialogChangeWidget::DapScreenDialogChangeWidget(QObject *parent) : QObject(parent) +{ + m_proxyModel = new QSortFilterProxyModel; + m_proxyModel->setSourceModel(&DapUiQmlWidgetModel::getInstance()); + m_proxyModel->setFilterRegExp(QRegExp("false")); + m_proxyModel->setFilterRole(VisibleRole); +} + +QSortFilterProxyModel *DapScreenDialogChangeWidget::proxyModel() const +{ + return m_proxyModel; +} + +void DapScreenDialogChangeWidget::setProxyModel(QSortFilterProxyModel *proxyModel) +{ + m_proxyModel = proxyModel; +} diff --git a/KelvinDashboardGUI/DapScreenDialogChangeWidget.h b/KelvinDashboardGUI/DapScreenDialogChangeWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..ed0d1da2ab2b13b9d4134b811e790216b3de5acb --- /dev/null +++ b/KelvinDashboardGUI/DapScreenDialogChangeWidget.h @@ -0,0 +1,26 @@ +#ifndef DAPSCREENDIALOGCHANGEWIDGET_H +#define DAPSCREENDIALOGCHANGEWIDGET_H + +#include <QObject> +#include <QSortFilterProxyModel> + +#include "DapUiQmlWidgetModel.h" + +class DapScreenDialogChangeWidget : public QObject +{ + Q_OBJECT + + QSortFilterProxyModel *m_proxyModel; +public: + explicit DapScreenDialogChangeWidget(QObject *parent = nullptr); + + Q_PROPERTY(QSortFilterProxyModel* ProxyModel MEMBER m_proxyModel READ proxyModel WRITE setProxyModel NOTIFY proxyModelChanged) + + QSortFilterProxyModel *proxyModel() const; + void setProxyModel(QSortFilterProxyModel *proxyModel); +signals: + void proxyModelChanged(QSortFilterProxyModel *proxyModel); +public slots: +}; + +#endif // DAPSCREENDIALOGCHANGEWIDGET_H diff --git a/KelvinDashboardGUI/DapUiQmlListModelWidgets.qml b/KelvinDashboardGUI/DapUiQmlListModelWidgets.qml deleted file mode 100644 index c97243ad31ec076f6d006354bdcb7e0f5e85eca5..0000000000000000000000000000000000000000 --- a/KelvinDashboardGUI/DapUiQmlListModelWidgets.qml +++ /dev/null @@ -1,30 +0,0 @@ -import QtQuick 2.0 - -ListModel { - id: listModelMenu - - ListElement { - name: qsTr("Blockchain explorer") - page: "DapUiQmlWidgetChainBlockExplorer.ui.qml" - } - ListElement { - name: qsTr("Exchanges") - page: "DapUiQmlWidgetChainExchanges.ui.qml" - } - ListElement { - name: qsTr("Services client") - page: "DapUiQmlWidgetChainServicesClient.ui.qml" - } - ListElement { - name: qsTr("Services share control") - page: "DapUiQmlWidgetChainServicesShareControl.ui.qml" - } - ListElement { - name: qsTr("Settings") - page: "DapUiQmlWidgetChainSettings.ui.qml" - } - ListElement { - name: qsTr("Wallet") - page: "DapUiQmlWidgetChainWallet.ui.qml" - } -} diff --git a/KelvinDashboardGUI/DapUiQmlScreenChangeWidget.qml b/KelvinDashboardGUI/DapUiQmlScreenChangeWidget.qml new file mode 100644 index 0000000000000000000000000000000000000000..26ffd1655711ff9e6e2acf997f0433c329f7f3cc --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlScreenChangeWidget.qml @@ -0,0 +1,160 @@ +import QtQuick 2.9 +import QtQml 2.11 +import QtQuick.Controls 1.4 +import QtQuick.Controls 2.4 +import QtQuick.Layouts 1.2 +import QtQml.Models 2.2 +import KelvinDashboard 1.0 + +Dialog { + id: dialogChangeWidget + + function addWidget() { + dialogChangeWidget.open(); + } + + width: parent.width/1.5 + height: parent.width/1.5 + + x: parent.width / 2 - width / 2 + y: parent.height / 2 - height / 2 + + focus: true + modal: true + title: qsTr("Change widget...") + + contentItem: + + Rectangle { + id: b + width: dialogChangeWidget.width + height: dialogChangeWidget.height + border.color: "gray" + clip: true + + DapScreenDialogChangeWidget { + id: widgetModel + } + +// DelegateModel { +// id: delegateModel + +// model: widgetModel.ProxyModel + +// groups: [ +// DelegateModelGroup { +// id: group +// name: "selected" +// } +// ] + +// delegate: +// Rectangle { +// id: item +// height: text.height+10 +// width: listViewDapWidgets.width +// RowLayout { +// anchors.fill: parent + +// Text { +// id: text +// text: name +// Layout.alignment: Qt.AlignVCenter +// Layout.leftMargin: 10 +// } +// } +// MouseArea { +// anchors.fill: parent +// onClicked: +// { +// item.DelegateModel.inSelected = !item.DelegateModel.inSelected + +// if (item.DelegateModel.inSelected) +// { +// item.color = "aliceblue" +// } +// else +// { +// item.color = "transparent" +// } +// } +// } +// } +// } + +// ListView { + +// id: listViewDapWidgets + +// anchors.fill: parent + +// anchors.margins: 1 + +// model: delegateModel + +// ScrollBar.vertical: ScrollBar { } +// } + ListView { + + id: listViewDapWidgets + + anchors.fill: parent + + anchors.margins: 1 + + model: DapUiQmlWidgetModel + + clip: true + + delegate: + Rectangle { + id: itemWidget + height: checkBoxWidget.height+10 + width: listViewDapWidgets.width + Row { + anchors.fill: parent + + CheckBox { + id: checkBoxWidget + checkable: true + anchors.verticalCenter: parent.verticalCenter + anchors.leftMargin: 10 + } + + Text + { + id: textWidget + text: qsTr(name) + anchors.verticalCenter: parent.verticalCenter + } + } + + MouseArea { + anchors.fill: parent + onClicked: + { + listViewDapWidgets.currentIndex = index + var item = DapUiQmlWidgetModel.get(index) + DapUiQmlWidgetModel.set(index, DapUiQmlWidgetModel.get(index).name, DapUiQmlWidgetModel.get(index).URLpage, DapUiQmlWidgetModel.get(index).image, !item.visible) + console.log("I: " +index + " : " + DapUiQmlWidgetModel.get(index) + " value = " + !item.visible) + + if(checkBoxWidget.checked) + { + checkBoxWidget.checkState = Qt.Unchecked + } + else + { + checkBoxWidget.checkState = Qt.Checked + } + } + } + } + + ScrollBar.vertical: ScrollBar { } + + highlight: Rectangle { color: "aliceblue"; radius: 5 } + + focus: true + } + } +} diff --git a/KelvinDashboardGUI/DapUiQmlScreenDialog.cpp b/KelvinDashboardGUI/DapUiQmlScreenDialog.cpp deleted file mode 100644 index 5621b7849fdbf5c54c4a69d7ebf0dcb4ed74ae48..0000000000000000000000000000000000000000 --- a/KelvinDashboardGUI/DapUiQmlScreenDialog.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "DapScreenDialog.h" - -DapUiQmlScreenDialog::DapUiQmlScreenDialog() -{ - -} diff --git a/KelvinDashboardGUI/DapUiQmlScreenDialog.qml b/KelvinDashboardGUI/DapUiQmlScreenDialog.qml index a6d222603c18deecc4e0a3b567d185798c59ddb9..b463f1a93ea903d32fd8a23c017475e0147d1d16 100644 --- a/KelvinDashboardGUI/DapUiQmlScreenDialog.qml +++ b/KelvinDashboardGUI/DapUiQmlScreenDialog.qml @@ -1,63 +1,60 @@ import QtQuick 2.9 import QtQuick.Controls 2.4 +import KelvinDashboard 1.0 Page { id: dapUiQmlScreenDialog title: qsTr("Dashboard") anchors.fill: parent + DapUiQmlScreenChangeWidget { + id: listViewDapWidgets + } + + DapScreenDialog { + id: widgetModel + } + Rectangle { color: "white" anchors.fill: parent GridView { id: gridViewDashboard + + signal pressAndHold(int index) + anchors.fill: parent cellWidth: width/3; cellHeight: height/2 focus: true - model: DapUiQmlListModelWidgets {} + model: widgetModel.ProxyModel highlight: Rectangle { width: gridViewDashboard.cellWidth; height: gridViewDashboard.cellHeight; radius: width/50; color: "aliceblue" } - delegate: Item { + delegate: DapUiQmlWidgetDelegateForm { width: gridViewDashboard.cellWidth height: gridViewDashboard.cellHeight - Rectangle { - anchors.fill: parent - border.color: "grey" - color: "transparent" - radius: width/50 - anchors.margins: 5 - clip: true - - Column { - width: parent.width - anchors.centerIn: parent - spacing: width / 10 - anchors.margins: width / 10 - Image { - id: iconWidget - source: "qrc:/Resources/Icons/add.png" - width: parent.width * 2/3 - height: width - anchors.horizontalCenter: parent.horizontalCenter - } - Text { - text: name - color: "darkgrey" - anchors.horizontalCenter: parent.horizontalCenter - } - } - } + MouseArea { anchors.fill: parent onClicked: { parent.GridView.view.currentIndex = index; - stackView.push(Qt.resolvedUrl(page), StackView.Immediate); + stackView.push(Qt.resolvedUrl(URLpage), StackView.Immediate); } } } } } + + RoundButton { + text: qsTr("+") + highlighted: true + anchors.margins: 10 + anchors.right: parent.right + anchors.bottom: parent.bottom + onClicked: { + listViewDapWidgets.addWidget() + } + } } diff --git a/KelvinDashboardGUI/DapUiQmlWidget.cpp b/KelvinDashboardGUI/DapUiQmlWidget.cpp index 59598aa4c5a19e72e3b861108185800ed5c57aa5..5502b8281663969cdf6ee7e6e77c2b38230f0d5a 100644 --- a/KelvinDashboardGUI/DapUiQmlWidget.cpp +++ b/KelvinDashboardGUI/DapUiQmlWidget.cpp @@ -1,6 +1,49 @@ #include "DapUiQmlWidget.h" -DapUiQmlWidget::DapUiQmlWidget() +bool DapUiQmlWidget::getVisible() const { - + return m_visible; +} + +void DapUiQmlWidget::setVisible(bool visible) +{ + m_visible = visible; +} + +DapUiQmlWidget::DapUiQmlWidget(const QString &name, const QString &URLpage, const QString &image, const bool &visible, QObject *parent) : QObject(parent) +{ + setName(name); + setURLpage(URLpage); + setImage(image); + setVisible(visible); +} + +QString DapUiQmlWidget::getName() const +{ + return m_name; +} + +void DapUiQmlWidget::setName(const QString &name) +{ + m_name = name; +} + +QString DapUiQmlWidget::getURLpage() const +{ + return m_URLpage; +} + +void DapUiQmlWidget::setURLpage(const QString &URLpage) +{ + m_URLpage = URLpage; +} + +QString DapUiQmlWidget::getImage() const +{ + return m_image; +} + +void DapUiQmlWidget::setImage(const QString &image) +{ + m_image = image; } diff --git a/KelvinDashboardGUI/DapUiQmlWidget.h b/KelvinDashboardGUI/DapUiQmlWidget.h index 06ebafdc6182a1d48bfc9c9b6202a5e281ed6de8..d321690e3dbd67679e5f55b33ea38b94598149d4 100644 --- a/KelvinDashboardGUI/DapUiQmlWidget.h +++ b/KelvinDashboardGUI/DapUiQmlWidget.h @@ -1,11 +1,49 @@ #ifndef DAPUIQMLWIDGET_H #define DAPUIQMLWIDGET_H +#include <QObject> -class DapUiQmlWidget +class DapUiQmlWidget : public QObject { + Q_OBJECT + +protected: + QString m_name; + QString m_URLpage; + QString m_image; + bool m_visible{false}; public: - DapUiQmlWidget(); + explicit DapUiQmlWidget(QObject *parent = nullptr); + explicit DapUiQmlWidget(const QString &name, const QString &URLpage, const QString &image, const bool &visible = false, QObject *parent = nullptr); + + /// + Q_PROPERTY(QString Name MEMBER m_nameService READ getName WRITE setName NOTIFY nameChanged) + /// + Q_PROPERTY(QString URLpage MEMBER m_nameService READ getURLpage WRITE setURLpage NOTIFY URLpageChanged) + /// + Q_PROPERTY(QString Image MEMBER m_nameService READ getImage WRITE setImage NOTIFY imageChanged) + /// + Q_PROPERTY(bool Visible MEMBER m_nameService READ getVisible WRITE setVisible NOTIFY visibleChanged) + + QString getName() const; + void setName(const QString &name); + + QString getURLpage() const; + void setURLpage(const QString &URLpage); + + QString getImage() const; + void setImage(const QString &image); + + bool getVisible() const; + void setVisible(bool visible); + +signals: + void nameChanged(const QString &name); + void URLpageChanged(const QString &URLpage); + void imageChanged(const QString &image); + void visibleChanged(const bool &visible); + +public slots: }; -#endif // DAPUIQMLWIDGET_H \ No newline at end of file +#endif // DAPUIQMLWIDGET_H diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainBallance.cpp b/KelvinDashboardGUI/DapUiQmlWidgetChainBallance.cpp index 68da31745da72d965fa4cd3bce1b461968246a83..4a7b8233a4911a799cda5b1cf99e86e5339a3c52 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainBallance.cpp +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainBallance.cpp @@ -1,6 +1,6 @@ #include "DapUiQmlWidgetChainBallance.h" -DapUiQmlWidgetChainBallance::DapUiQmlWidgetChainBallance() +DapUiQmlWidgetChainBallance::DapUiQmlWidgetChainBallance(const QString &name, const QString &URLpage, const QString &image) : DapUiQmlWidget(name, URLpage, image) { } diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainBallance.h b/KelvinDashboardGUI/DapUiQmlWidgetChainBallance.h index be7239552f011864e4c2ef5ecb6b74e9cc257da9..aea12f51fb60e3d914b4201ae83157ba8ca8a465 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainBallance.h +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainBallance.h @@ -6,7 +6,8 @@ class DapUiQmlWidgetChainBallance : public DapUiQmlWidget { public: - DapUiQmlWidgetChainBallance(); + explicit DapUiQmlWidgetChainBallance(const QString &name, const QString &URLpage, const QString &image); + }; #endif // DAPUIQMLWIDGETCHAINBALLANCE_H diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainBlockExplorer.cpp b/KelvinDashboardGUI/DapUiQmlWidgetChainBlockExplorer.cpp index 28ce99bd360f5a368f4cbef43a65fa945b9b4c56..c125c66ac657cd452243e53106b989879522f78d 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainBlockExplorer.cpp +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainBlockExplorer.cpp @@ -1,6 +1,6 @@ #include "DapUiQmlWidgetChainBlockExplorer.h" -DapUiQmlWidgetChainBlockExplorer::DapUiQmlWidgetChainBlockExplorer() +DapUiQmlWidgetChainBlockExplorer::DapUiQmlWidgetChainBlockExplorer(const QString &name, const QString &URLpage, const QString &image) : DapUiQmlWidget(name, URLpage, image) { } diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainBlockExplorer.h b/KelvinDashboardGUI/DapUiQmlWidgetChainBlockExplorer.h index dfcb58894dc748f019d925f59d88b7e4b9a55286..135d4ffb15b277921cb2fc32a6e5da79bb0afed5 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainBlockExplorer.h +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainBlockExplorer.h @@ -6,7 +6,7 @@ class DapUiQmlWidgetChainBlockExplorer : public DapUiQmlWidget { public: - DapUiQmlWidgetChainBlockExplorer(); + DapUiQmlWidgetChainBlockExplorer(const QString &name, const QString &URLpage, const QString &image); }; #endif // DAPUIQMLWIDGETCHAINBLOCKEXPLORER_H diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainNodeLogs.cpp b/KelvinDashboardGUI/DapUiQmlWidgetChainNodeLogs.cpp index 36ef984482f16eb614708b017e7c83d38d68a850..0dae3836f4719fa526b8368c2e58605876a6fa45 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainNodeLogs.cpp +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainNodeLogs.cpp @@ -1,6 +1,6 @@ #include "DapUiQmlWidgetChainNodeLogs.h" -DapUiQmlWidgetChainNodeLogs::DapUiQmlWidgetChainNodeLogs() +DapUiQmlWidgetChainNodeLogs::DapUiQmlWidgetChainNodeLogs(const QString &name, const QString &URLpage, const QString &image) : DapUiQmlWidget(name, URLpage, image) { } diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainNodeLogs.h b/KelvinDashboardGUI/DapUiQmlWidgetChainNodeLogs.h index 07123ebffdfde9cbfbad6995112402936ce5e188..debcc446393fdbe26b369caeea3b0341f294b9f0 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainNodeLogs.h +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainNodeLogs.h @@ -6,7 +6,7 @@ class DapUiQmlWidgetChainNodeLogs : public DapUiQmlWidget { public: - DapUiQmlWidgetChainNodeLogs(); + explicit DapUiQmlWidgetChainNodeLogs(const QString &name, const QString &URLpage, const QString &image); }; #endif // DAPUIQMLWIDGETCHAINNODELOGS_H diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainOperations.cpp b/KelvinDashboardGUI/DapUiQmlWidgetChainOperations.cpp index 2aff6130d0ed86da1c0f7742ab42a79eeb81c791..1c22b7338e570e3805929b43b835296317154376 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainOperations.cpp +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainOperations.cpp @@ -1,6 +1,6 @@ #include "DapUiQmlWidgetChainOperations.h" -DapUiQmlWidgeChainOperations::DapUiQmlWidgeChainOperations() +DapUiQmlWidgeChainOperations::DapUiQmlWidgeChainOperations(const QString &name, const QString &URLpage, const QString &image) : DapUiQmlWidget(name, URLpage, image) { } diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainOperations.h b/KelvinDashboardGUI/DapUiQmlWidgetChainOperations.h index 458778325c376405de920d752b0470aa3148de9d..25d25fed895f715bff353eea79df6f7b5c144492 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainOperations.h +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainOperations.h @@ -6,7 +6,7 @@ class DapUiQmlWidgeChainOperations : public DapUiQmlWidget { public: - DapUiQmlWidgeChainOperations(); + explicit DapUiQmlWidgeChainOperations(const QString &name, const QString &URLpage, const QString &image); }; #endif // DAPUIQMLWIDGECHAINOPERATIONS_H diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainTransctions.cpp b/KelvinDashboardGUI/DapUiQmlWidgetChainTransctions.cpp index 654f78de1a143a15b28efcca5628566d6ede75b4..df9441b200c3591a16804430750e74c08af174b4 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainTransctions.cpp +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainTransctions.cpp @@ -1,6 +1,6 @@ #include "DapUiQmlWidgetChainTransctions.h" -DapUiQmlWidgetChainTransctions::DapUiQmlWidgetChainTransctions() +DapUiQmlWidgetChainTransctions::DapUiQmlWidgetChainTransctions(const QString &name, const QString &URLpage, const QString &image) : DapUiQmlWidget(name, URLpage, image) { } diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainTransctions.h b/KelvinDashboardGUI/DapUiQmlWidgetChainTransctions.h index 2595d04e62de3aba2535b29b6dfa330adb3fc637..3fe4c1a73e4753334b2fd01ae243c06fc29263d9 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainTransctions.h +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainTransctions.h @@ -6,7 +6,7 @@ class DapUiQmlWidgetChainTransctions : public DapUiQmlWidget { public: - DapUiQmlWidgetChainTransctions(); + explicit DapUiQmlWidgetChainTransctions(const QString &name, const QString &URLpage, const QString &image); }; #endif // DAPUIQMLWIDGETCHAINTRANSCTIONS_H diff --git a/KelvinDashboardGUI/DapUiQmlWidgetDelegate.qml b/KelvinDashboardGUI/DapUiQmlWidgetDelegate.qml new file mode 100644 index 0000000000000000000000000000000000000000..607a49ad604901c412cf8142dd676b18e3af0d20 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetDelegate.qml @@ -0,0 +1,4 @@ +import QtQuick 2.4 + +DapUiQmlWidgetDelegateForm { +} diff --git a/KelvinDashboardGUI/DapUiQmlWidgetDelegateForm.ui.qml b/KelvinDashboardGUI/DapUiQmlWidgetDelegateForm.ui.qml new file mode 100644 index 0000000000000000000000000000000000000000..638d3db2cc3ae467eaf0055ac9bd3aa1f277c0d0 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetDelegateForm.ui.qml @@ -0,0 +1,36 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.1 + +ItemDelegate { + id: itemDelegateDapWidget + + checkable: true + + contentItem: Rectangle { + anchors.fill: parent + border.color: "grey" + color: "transparent" + radius: width/50 + anchors.margins: 5 + clip: true + + Column { + width: parent.width + anchors.centerIn: parent + spacing: width / 10 + anchors.margins: width / 10 + Image { + id: iconWidget + source: image + width: parent.width * 2/3 + height: width + anchors.horizontalCenter: parent.horizontalCenter + } + Text { + text: name + color: "darkgrey" + anchors.horizontalCenter: parent.horizontalCenter + } + } + } +} diff --git a/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp b/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2f8cef3afc9bb545a1d73a550f6f52eca8f2f7b6 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp @@ -0,0 +1,98 @@ +#include "DapUiQmlWidgetModel.h" + +DapUiQmlWidgetModel::DapUiQmlWidgetModel(QObject *parent) : QAbstractListModel(parent) +{ + m_dapUiQmlWidgets.append(new DapUiQmlWidget("Blockchain explorer", "DapUiQmlWidgetChainBlockExplorer.ui.qml", "qrc:/Resources/Icons/add.png")); + m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Exchanges", "DapUiQmlWidgetChainExchanges.ui.qml", "qrc:/Resources/Icons/add.png")); + m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Services client", "DapUiQmlWidgetChainServicesClient.ui.qml", "qrc:/Resources/Icons/add.png")); + m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Services share control", "DapUiQmlWidgetChainServicesShareControl.ui.qml", "qrc:/Resources/Icons/add.png")); + m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Settings", "DapUiQmlWidgetChainSettings.ui.qml", "qrc:/Resources/Icons/add.png")); + m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Wallet", "DapUiQmlWidgetChainWallet.ui.qml", "qrc:/Resources/Icons/add.png")); +} + +DapUiQmlWidgetModel &DapUiQmlWidgetModel::getInstance() +{ + static DapUiQmlWidgetModel instance; + return instance; +} + +int DapUiQmlWidgetModel::rowCount(const QModelIndex &) const +{ + return m_dapUiQmlWidgets.count(); +} + +QVariant DapUiQmlWidgetModel::data(const QModelIndex &index, int role) const +{ + if (index.row() < rowCount()) + switch (role) { + case NameRole: return m_dapUiQmlWidgets.at(index.row())->getName(); + case URLPageRole: return m_dapUiQmlWidgets.at(index.row())->getURLpage(); + case ImageRole: return m_dapUiQmlWidgets.at(index.row())->getImage(); + case VisibleRole: return m_dapUiQmlWidgets.at(index.row())->getVisible(); + default: + return QVariant(); + } + return QVariant(); +} + +QHash<int, QByteArray> DapUiQmlWidgetModel::roleNames() const +{ + static const QHash<int, QByteArray> roles { + { NameRole, "name" }, + { URLPageRole, "URLpage" }, + { ImageRole, "image" }, + { VisibleRole, "visible" } + }; + + return roles; +} + +QVariantMap DapUiQmlWidgetModel::get(int row) const +{ + const DapUiQmlWidget *widget = m_dapUiQmlWidgets.value(row); + return { {"name", widget->getName()}, {"URLpage", widget->getURLpage()}, {"image", widget->getImage()}, {"visible", widget->getVisible()} }; +} + +void DapUiQmlWidgetModel::append(const QString &name, const QString &URLpage, const QString &image, const bool &visible) +{ + int row = 0; + while (row < m_dapUiQmlWidgets.count() && name > m_dapUiQmlWidgets.at(row)->getName()) + ++row; + beginInsertRows(QModelIndex(), row, row); + m_dapUiQmlWidgets.insert(row, new DapUiQmlWidget(name, URLpage, image, visible)); + endInsertRows(); +} + +void DapUiQmlWidgetModel::set(int row, const QString &name, const QString &URLpage, const QString &image, const bool &visible) +{ + if (row < 0 || row >= m_dapUiQmlWidgets.count()) + return; + + DapUiQmlWidget *widget = m_dapUiQmlWidgets.value(row); + widget->setName(name); + widget->setURLpage(URLpage); + widget->setImage(image); + widget->setVisible(visible); + dataChanged(index(row, 0), index(row, 0), { NameRole, URLPageRole, ImageRole, VisibleRole }); +} + +void DapUiQmlWidgetModel::remove(int row) +{ + if (row < 0 || row >= m_dapUiQmlWidgets.count()) + return; + + beginRemoveRows(QModelIndex(), row, row); + m_dapUiQmlWidgets.removeAt(row); + endRemoveRows(); +} + +/// Method that implements the singleton pattern for the qml layer. +/// @param engine QML application. +/// @param scriptEngine The QJSEngine class provides an environment for evaluating JavaScript code. +QObject *DapUiQmlWidgetModel::singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + + return &getInstance(); +} diff --git a/KelvinDashboardGUI/DapUiQmlWidgetModel.h b/KelvinDashboardGUI/DapUiQmlWidgetModel.h new file mode 100644 index 0000000000000000000000000000000000000000..9613864d2c6ae2fdc2b3da0a18a1699dd16f0824 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetModel.h @@ -0,0 +1,54 @@ +#ifndef DAPUIQMLWIDGETMODEL_H +#define DAPUIQMLWIDGETMODEL_H + +#include <QObject> +#include <QAbstractListModel> +#include <QList> +#include <QQmlEngine> +#include <QJSEngine> +#include <QXmlStreamWriter> +#include <QXmlStreamReader> +#include <QXmlStreamAttribute> + +#include "DapUiQmlWidget.h" + +enum DapUiQmlWidgetRole { + NameRole = Qt::DisplayRole, + URLPageRole = Qt::UserRole, + ImageRole, + VisibleRole + }; + +class DapUiQmlWidgetModel : public QAbstractListModel +{ + Q_OBJECT + + QList<DapUiQmlWidget*> m_dapUiQmlWidgets; + + DapUiQmlWidgetModel(QObject *parent = nullptr); +public: + + /// Get an instance of a class. + /// @return Instance of a class. + Q_INVOKABLE static DapUiQmlWidgetModel &getInstance(); + + + Q_ENUM(DapUiQmlWidgetRole) + + int rowCount(const QModelIndex & = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + + Q_INVOKABLE QVariantMap get(int row) const; + Q_INVOKABLE void append(const QString &name, const QString &URLpage, const QString &image, const bool &visible); + Q_INVOKABLE void set(int row, const QString &name, const QString &URLpage, const QString &image, const bool &visible); + Q_INVOKABLE void remove(int row); + +public slots: + /// Method that implements the singleton pattern for the qml layer. + /// @param engine QML application. + /// @param scriptEngine The QJSEngine class provides an environment for evaluating JavaScript code. + static QObject *singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine); +}; + +#endif // DAPUIQMLWIDGETMODEL_H diff --git a/KelvinDashboardGUI/KelvinDashboardGUI.pro b/KelvinDashboardGUI/KelvinDashboardGUI.pro index df8eb7cede7e99568ad529b3cd569cd501539292..592c6e8d5830d708885b8072e5e3abb0ec5a9ede 100644 --- a/KelvinDashboardGUI/KelvinDashboardGUI.pro +++ b/KelvinDashboardGUI/KelvinDashboardGUI.pro @@ -38,15 +38,17 @@ ICON = icon.ico SOURCES += \ main.cpp \ - DapUiQmlWidget.cpp \ DapUiQmlWidgetChainBallance.cpp \ - DapUiQmlScreenDialog.cpp \ DapUiQmlWidgetChainBlockExplorer.cpp \ DapUiQmlWidgetChainNodeLogs.cpp \ DapUiQmlWidgetChainTransctions.cpp \ DapUiQmlWidgetChainOperations.cpp \ DapScreenLogin.cpp \ - DapClient.cpp + DapClient.cpp \ + DapUiQmlWidgetModel.cpp \ + DapUiQmlWidget.cpp \ + DapScreenDialog.cpp \ + DapScreenDialogChangeWidget.cpp RESOURCES += qml.qrc @@ -62,16 +64,22 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ - DapUiQmlWidget.h \ DapUiQmlWidgetChainBallance.h \ DapUiQmlWidgetChainBlockExplorer.h \ DapUiQmlWidgetChainNodeLogs.h \ DapUiQmlWidgetChainTransctions.h \ DapUiQmlScreenDashboard.h \ DapUiQmlWidgetChainOperations.h \ - DapScreenDialog.h \ DapScreenLogin.h \ - DapClient.h + DapClient.h \ + DapUiQmlWidgetModel.h \ + DapUiQmlWidget.h \ + DapScreenDialog.h \ + DapScreenDialogChangeWidget.h + include (../libKelvinDashboardCommon/libKelvinDashboardCommon.pri) -INCLUDEPATH += $$_PRO_FILE_PWD_/../libKelvinDashboardCommon/ +INCLUDEPATH += $$_PRO_FILE_PWD_/../libKelvinDashboardCommon/; + $$_PRO_FILE_PWD_/../libdap/ + +DISTFILES += diff --git a/KelvinDashboardGUI/Resources/Settings.json b/KelvinDashboardGUI/Resources/Settings.json new file mode 100755 index 0000000000000000000000000000000000000000..e3729e3deed63c20b5d0863841bf2a794546bc3b --- /dev/null +++ b/KelvinDashboardGUI/Resources/Settings.json @@ -0,0 +1,12 @@ + { + "user": "Andrey", + "widgets": + [ + {"name": "Blockchain explorer", "URLpage": "DapUiQmlWidgetChainBlockExplorer.ui.qml", "image": "qrc:/Resources/Icons/add.png", "visible": "false"}, + {"name": "Exchanges", "URLpage": "DapUiQmlWidgetChainExchanges.ui.qml", "image": "qrc:/Resources/Icons/add.png", "visible": "false"}, + {"name": "Services client", "URLpage": "DapUiQmlWidgetChainServicesClient.ui.qml", "image": "qrc:/Resources/Icons/add.png", "visible": "false"}, + {"name": "Services share control", "URLpage": "DapUiQmlWidgetChainServicesShareControl.ui.qml", "image": "qrc:/Resources/Icons/add.png", "visible": "false"}, + {"name": "Settings", "URLpage": "DapUiQmlWidgetChainSettings.ui.qml", "image": "qrc:/Resources/Icons/add.png", "visible": "false"}, + {"name": "Wallet", "URLpage": "DapUiQmlWidgetChainWallet.ui.qml", "image": "qrc:/Resources/Icons/add.png", "visible": "false"} + ] + } diff --git a/KelvinDashboardGUI/main.cpp b/KelvinDashboardGUI/main.cpp index e60dff573ee0df2c8d5bad00fc9f6450b3fff9c4..ac42f11850839b16bdb0772d9ed9cd75ce745b12 100644 --- a/KelvinDashboardGUI/main.cpp +++ b/KelvinDashboardGUI/main.cpp @@ -10,6 +10,11 @@ #include "DapHalper.h" #include "DapClient.h" #include "DapScreenLogin.h" +#include "DapScreenDialog.h" +#include "DapScreenDialogChangeWidget.h" +#include "DapUiQmlWidgetModel.h" +#include "DapSettings.h" +#include "DapSettingsCipher.h" int main(int argc, char *argv[]) { @@ -41,12 +46,23 @@ int main(int argc, char *argv[]) DapClient::getInstance().connectToService("Kelvin Client"); qmlRegisterType<DapScreenLogin>("KelvinDashboard", 1, 0, "DapScreenLogin"); + qmlRegisterType<DapScreenDialog>("KelvinDashboard", 1, 0, "DapScreenDialog"); + qmlRegisterType<DapScreenDialogChangeWidget>("KelvinDashboard", 1, 0, "DapScreenDialogChangeWidget"); qmlRegisterSingletonType<DapClient>("KelvinDashboard", 1, 0, "DapClient", DapClient::singletonProvider); + qmlRegisterSingletonType<DapUiQmlWidgetModel>("KelvinDashboard", 1, 0, "DapUiQmlWidgetModel", DapUiQmlWidgetModel::singletonProvider); QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("dapClient", &DapClient::getInstance()); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + DapSettings &settings = DapSettings::getInstance("Settings.json"); + DapSettingsCipher &set = DapSettingsCipher::getInstance(settings); + qDebug() << "Settings file name: " << set.getFileName(); + set.setKeyValue("user", "Vasy"); + bool f = false; + set.setGroupPropertyValue("widgets", "name", "Services client", "visible", f); + qDebug() << set.getGroupPropertyValue("widgets", "name", "Services client", "visible").toBool(); + qDebug() << set.getKeyValue("user"); if (engine.rootObjects().isEmpty()) return -1; diff --git a/KelvinDashboardGUI/main.qml b/KelvinDashboardGUI/main.qml index d4cb179c1f283d82e6e1fa7b7c55c6cab09841f4..f80a6edc2f9f9b2bb33c64aa46af5cf9405b524f 100644 --- a/KelvinDashboardGUI/main.qml +++ b/KelvinDashboardGUI/main.qml @@ -4,6 +4,7 @@ import QtQuick.Controls 2.4 import QtQuick.Window 2.0 import QtQuick.Controls.Styles 1.4 import Qt.labs.platform 1.0 +import KelvinDashboard 1.0 ApplicationWindow { id: window @@ -102,11 +103,7 @@ ApplicationWindow { ListView { id: listViewMenu anchors.fill: parent - model: listModelMenu - - DapUiQmlListModelWidgets { - id: listModelMenu - } + model: DapUiQmlWidgetModel delegate: Component { @@ -133,12 +130,13 @@ ApplicationWindow { onClicked: { listViewMenu.currentIndex = index - stackView.push(Qt.resolvedUrl(page), StackView.Immediate) + stackView.push(Qt.resolvedUrl(URLpage), StackView.Immediate) drawerMenu.close() } } } } + highlight: Rectangle { color: "aliceblue"; radius: 5 } focus: true } diff --git a/KelvinDashboardGUI/qml.qrc b/KelvinDashboardGUI/qml.qrc index 175c215a6a73c3c823aa9d7cb29e78bb07aa98b2..259fa3884c435b408c2f2d83a6f9938429ff0fd2 100644 --- a/KelvinDashboardGUI/qml.qrc +++ b/KelvinDashboardGUI/qml.qrc @@ -14,12 +14,14 @@ <file>DapUiQmlScreenDialog.qml</file> <file>Resources/Icons/icon.png</file> <file>Resources/Icons/icon.ico</file> - <file>DapUiQmlListModelWidgets.qml</file> <file>Resources/Icons/add.png</file> <file>DapQmlScreenLogin.qml</file> <file>DapUiQmlScreenAbout.ui.qml</file> <file>DapQmlScreenAbout.qml</file> <file>Resources/Icons/iconErrorNetwork.png</file> <file>Resources/Icons/iconNetwork.png</file> + <file>DapUiQmlWidgetDelegate.qml</file> + <file>DapUiQmlWidgetDelegateForm.ui.qml</file> + <file>DapUiQmlScreenChangeWidget.qml</file> </qresource> </RCC> diff --git a/KelvinDashboardService/KelvinDashboardService.pro b/KelvinDashboardService/KelvinDashboardService.pro index 8f5f5c19bf01ba50becf65efcbd6c13201070bef..3448c2f0b97e8154619782d0652631e9bbfabd4f 100644 --- a/KelvinDashboardService/KelvinDashboardService.pro +++ b/KelvinDashboardService/KelvinDashboardService.pro @@ -49,7 +49,8 @@ HEADERS += \ DapChainNodeCache.h include (../libKelvinDashboardCommon/libKelvinDashboardCommon.pri) -INCLUDEPATH += $$_PRO_FILE_PWD_/../libKelvinDashboardCommon/ +INCLUDEPATH += $$_PRO_FILE_PWD_/../libKelvinDashboardCommon/; + $$_PRO_FILE_PWD_/../libdap/ RESOURCES += \ KelvinDashboardService.qrc diff --git a/Resources/Icons/add.png b/Resources/Icons/add.png deleted file mode 100644 index f3c75ff7cc06fe9833492a80f6bd7ddcfefe3072..0000000000000000000000000000000000000000 Binary files a/Resources/Icons/add.png and /dev/null differ diff --git a/Resources/Icons/icon.ico b/Resources/Icons/icon.ico deleted file mode 100644 index 41230db92cb8101b8f24cf6f861082c6dfb827e1..0000000000000000000000000000000000000000 Binary files a/Resources/Icons/icon.ico and /dev/null differ diff --git a/Resources/Icons/icon.png b/Resources/Icons/icon.png deleted file mode 100644 index 52525ef9e99b9d42242dcddc0f5f5a25eaeee901..0000000000000000000000000000000000000000 Binary files a/Resources/Icons/icon.png and /dev/null differ diff --git a/libKelvinDashboardCommon/DapSettings.cpp b/libKelvinDashboardCommon/DapSettings.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9cbf5b96d2627c2e42163a01144438fd565627a5 --- /dev/null +++ b/libKelvinDashboardCommon/DapSettings.cpp @@ -0,0 +1,254 @@ +#include "DapSettings.h" + +/// Standart constructor. +DapSettings::DapSettings(QObject *parent) : QObject(parent) +{ + Q_UNUSED(parent) + + init(); +} + +/// Overloaded constructor. +/// @param fileName Settings file name. +/// @param parent Parent. +DapSettings::DapSettings(const QString &fileName, QObject *parent) +{ + Q_UNUSED(parent) + + init(); + + setFileName(fileName); +} + +/// Initialize the components. +void DapSettings::init() +{ + connect(this, &DapSettings::fileNameChanged, this, [=] (const QString &fileName) + { + m_file.setFileName(fileName); + }); +} + +/// Read settings file. +/// @return Virtual json file. +QJsonDocument DapSettings::readFile() +{ + qDebug() << "File name " << m_file.fileName(); + m_file.open(QIODevice::ReadOnly | QIODevice::Text); + QString textFile = decrypt(m_file.readAll()); + m_file.close(); + return QJsonDocument::fromJson(textFile.toUtf8()); +} + +/// Write settings to file. +/// @param json Virtual json file. +/// @return Returns true if the recording was successful, false if the recording failed. +bool DapSettings::writeFile(const QJsonDocument &json) +{ + if(!m_file.open(QIODevice::WriteOnly)) + { + qDebug() << "Couldn't open write file." << m_file.errorString(); + return false; + } + else + { + m_file.open(QIODevice::WriteOnly); + m_file.write(encrypt(json.toJson())); + m_file.close(); + return true; + } +} + +QByteArray DapSettings::encrypt(const QByteArray &byteArray) const +{ + return byteArray; +} + +QByteArray DapSettings::decrypt(const QByteArray &byteArray) const +{ + return byteArray; +} + +/// Get an instance of a class. +/// @return Instance of a class. +DapSettings &DapSettings::getInstance() +{ + static DapSettings instance; + return instance; +} + +/// Get an instance of a class. +/// @return Instance of a class. +DapSettings &DapSettings::getInstance(const QString &fileName) +{ + static DapSettings instance(fileName); + return instance; +} + +/// Set property value in group by key property. +/// @details The search in the group is carried out according to the signs +/// defining the object: the name of the key property and its value. +/// To change the value of a property in an object, you must specify +/// the property parameter and its value. For example, setGroupPropertyValue +/// ("widgets", "name", "Services client", "visible", true); "name" +/// is the key property, "Services client" is the value of the key +/// property, "visible" is a modifiable property, true are the set value. +/// @param group Group name. +/// @param keyProperty Key property. +/// @param valueKeyProperty Key property value. +/// @param property Settable property. +/// @param valuePropery The value of the property being set. +void DapSettings::setGroupPropertyValue(const QString &group, const QString &keyProperty, + const QVariant &valueKeyProperty, const QString &property, const QVariant &valuePropery) +{ + if(group.isEmpty() || group.isNull()) + return; + + auto list = getGroupValue(group); + + for(QMap<QString, QVariant> &map : list) + if(map.find(keyProperty) != map.end() && map.value(keyProperty) == valueKeyProperty) + map.insert(property, valuePropery); + + setGroupValue(group, list); +} + +/// Get property value from group by key property value. +/// @details The search in the group is carried out according to the signs +/// defining the object: the name of the key property and its value. +/// To change the value of a property in an object, you must specify +/// the property parameter and its value. For example, setGroupPropertyValue +/// ("widgets", "name", "Services client", "visible", true); "name" +/// is the key property, "Services client" is the value of the key +/// property, "visible" is a modifiable property, true are the set value. +/// See also setGroupPropertyValue. +/// @param group Group name. +/// @param keyProperty Key property. +/// @param valueKeyProperty Key property value. +/// @param property Settable property. +/// @param defaultValue The key value to be inserted in case the key is not found. +/// The default is non-valid value. +QVariant DapSettings::getGroupPropertyValue(const QString &group, const QString &keyProperty, const QString &valueKeyProperty, const QString &property, const QVariant& defaultValue) +{ + for(QMap<QString, QVariant> &map : getGroupValue(group)) + if(map.find(keyProperty) != map.end() && map.value(keyProperty) == valueKeyProperty) + return map.value(property); + return defaultValue; +} + +/// Get key value. +/// @details If the key does not exist, the function returns an invalid value. +/// @param key Key name. +/// @param defaultValue The key value to be inserted in case the key is not found. +/// The default is non-valid value. +QVariant DapSettings::getKeyValue(const QString &key, const QVariant& defaultValue) +{ + QJsonObject root = readFile().object(); + + QJsonValue jv = root.value(key); + + if(!jv.isArray()) + { + return jv.toVariant(); + } + + return defaultValue; +} + +/// Set key value. +/// @param key Key. +/// @param value Key value. +void DapSettings::setKeyValue(const QString &key, const QVariant &value) +{ + if(key.isEmpty() || key.isNull()) + return; + + QJsonDocument jsonDocument = readFile(); + QJsonObject jsonObject = jsonDocument.object(); + jsonObject.insert(key, value.toJsonValue()); + QJsonDocument jsonDocumentSave(jsonObject); + writeFile(jsonDocumentSave); +} + +/// Get a collection of values by name group. +/// @details If the group is not found, the function returns an empty list. +/// @param group Group name. +/// @return Group values collection. +QList<QMap<QString, QVariant>> DapSettings::getGroupValue(const QString &group) +{ + QJsonObject root = readFile().object(); + + QJsonValue jv = root.value(group); + + QList<QMap<QString, QVariant>> arrayValue; + + if(jv.isArray()) + { + QJsonArray ja = jv.toArray(); + for(QJsonValue jsonValue : ja) + { + QJsonObject jsonObject = jsonValue.toObject(); + QMap<QString, QVariant> object; + for(QString key : jsonObject.keys()) + { + object.insert(key, jsonObject.value(key).toVariant()); + } + arrayValue.push_back(object); + } + } + + return arrayValue; +} + +/// Set key values for group. +/// @param group Group name. +/// @param values Collection of group values. +void DapSettings::setGroupValue(const QString &group, const QList<QMap<QString, QVariant> > &values) +{ + if(group.isEmpty() || group.isNull()) + return; + + QJsonDocument jsonDocument = readFile(); + QJsonObject jsonObject = jsonDocument.object(); + + QJsonArray groupValues; + for(QMap<QString,QVariant> var : values) + { + QJsonObject itemObject; + for(auto key : var.keys()) + { + itemObject.insert(key, var.value(key).toJsonValue()); + } + groupValues.append(itemObject); + } + + jsonObject.insert(group, groupValues); + QJsonDocument jsonDocumentSave(jsonObject); + writeFile(jsonDocumentSave); +} + +/// Get the name of the settings file. +/// @return The name of the settings file. +QString DapSettings::getFileName() const +{ + return m_fileName; +} + +/// Set the name of the settings file. +/// @param fileName The name of the settings file. +void DapSettings::setFileName(const QString &fileName) +{ + m_fileName = fileName; + emit fileNameChanged(m_fileName); +} + +/// Method that implements the singleton pattern for the qml layer. +/// @param engine QML application. +/// @param scriptEngine The QJSEngine class provides an environment for evaluating JavaScript code. +QObject *DapSettings::singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + + return &getInstance(); +} diff --git a/libKelvinDashboardCommon/DapSettings.h b/libKelvinDashboardCommon/DapSettings.h new file mode 100644 index 0000000000000000000000000000000000000000..d4c23431a4fc2a0f11d65a764634380b085e9de1 --- /dev/null +++ b/libKelvinDashboardCommon/DapSettings.h @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** This file is part of the KelvinDashboardGUI application. +** +** The class provides an interface for managing application settings. +** Record format - Json. +** +** Implements a singleton pattern. +** +****************************************************************************/ + +#ifndef DAPSETTINGS_H +#define DAPSETTINGS_H + +#include <QObject> +#include <QFile> +#include <QQmlEngine> +#include <QJSEngine> +#include <QJsonDocument> +#include <QJsonObject> +#include <QJsonArray> +#include <QIODevice> +#include <QDebug> + +class DapSettings : public QObject +{ + Q_OBJECT + +protected: + /// Standart constructor. + explicit DapSettings(QObject *parent = nullptr); + /// Overloaded constructor. + /// @param fileName Settings file name. + /// @param parent Parent. + explicit DapSettings(const QString &fileName, QObject *parent = nullptr); + + /// Settings file. + QFile m_file; + /// Settings file name. + QString m_fileName; + + /// Initialize the components. + virtual void init(); + /// Read settings file. + /// @return Virtual json file. + virtual QJsonDocument readFile(); + /// Write settings to file. + /// @param json Virtual json file. + /// @return Returns true if the recording was successful, false if the recording failed. + virtual bool writeFile(const QJsonDocument& json); + + + +public: + virtual QByteArray encrypt(const QByteArray &byteArray) const; + + virtual QByteArray decrypt(const QByteArray &byteArray) const; + + /// Removed as part of the implementation of the pattern sington. + DapSettings(const DapSettings&) = delete; + DapSettings& operator= (const DapSettings &) = delete; + + /// Get an instance of a class. + /// @return Instance of a class. + Q_INVOKABLE static DapSettings &getInstance(); + /// Get an instance of a class. + /// @return Instance of a class. + Q_INVOKABLE static DapSettings &getInstance(const QString &fileName); + + ///******************************************** + /// Property + /// ******************************************* + + /// Settings file name. + Q_PROPERTY(QString FileName MEMBER m_fileName READ getFileName WRITE setFileName NOTIFY fileNameChanged) + + ///******************************************** + /// Interface + /// ******************************************* + + /// Set property value in group by key property. + /// @details The search in the group is carried out according to the signs + /// defining the object: the name of the key property and its value. + /// To change the value of a property in an object, you must specify + /// the property parameter and its value. For example, setGroupPropertyValue + /// ("widgets", "name", "Services client", "visible", true); "name" + /// is the key property, "Services client" is the value of the key + /// property, "visible" is a modifiable property, true are the set value. + /// @param group Group name. + /// @param keyProperty Key property. + /// @param valueKeyProperty Key property value. + /// @param property Settable property. + /// @param valuePropery The value of the property being set. + Q_INVOKABLE void setGroupPropertyValue(const QString &group, const QString &keyProperty, const QVariant &valueKeyProperty, const QString &property, const QVariant &valuePropery); + /// Get property value from group by key property value. + /// @details The search in the group is carried out according to the signs + /// defining the object: the name of the key property and its value. + /// To change the value of a property in an object, you must specify + /// the property parameter and its value. For example, setGroupPropertyValue + /// ("widgets", "name", "Services client", "visible", true); "name" + /// is the key property, "Services client" is the value of the key + /// property, "visible" is a modifiable property, true are the set value. + /// See also setGroupPropertyValue. + /// @param group Group name. + /// @param keyProperty Key property. + /// @param valueKeyProperty Key property value. + /// @param property Settable property. + /// @param defaultValue The key value to be inserted in case the key is not found. + /// The default is non-valid value. + Q_INVOKABLE QVariant getGroupPropertyValue(const QString &group, const QString &keyProperty, const QString &valueKeyProperty, const QString &property, const QVariant &defaultValue = QVariant()); + /// Get key value. + /// @details If the key does not exist, the function returns an invalid value. + /// @param key Key name. + /// @param defaultValue The key value to be inserted in case the key is not found. + /// The default is non-valid value. + Q_INVOKABLE QVariant getKeyValue(const QString &key, const QVariant &defaultValue = QVariant()); + /// Set key value. + /// @param key Key. + /// @param value Key value. + Q_INVOKABLE void setKeyValue(const QString &key, const QVariant &value); + /// Get a collection of values by name group. + /// @details If the group is not found, the function returns an empty list. + /// @param group Group name. + /// @return Group values collection. + Q_INVOKABLE QList<QMap<QString, QVariant> > getGroupValue(const QString &group); + /// Set key values for group. + /// @param group Group name. + /// @param values Collection of group values. + Q_INVOKABLE void setGroupValue(const QString &group, const QList<QMap<QString, QVariant>> &values); + /// Get the name of the settings file. + /// @return The name of the settings file. + QString getFileName() const; + /// Set the name of the settings file. + /// @param fileName The name of the settings file. + void setFileName(const QString &fileName); + +signals: + /// The signal is emitted when the FileName property changes. + /// @param fileName The name of the settings file. + void fileNameChanged(const QString &fileName); + +public slots: + /// Method that implements the singleton pattern for the qml layer. + /// @param engine QML application. + /// @param scriptEngine The QJSEngine class provides an environment for evaluating JavaScript code. + static QObject *singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine); +}; + +#endif // DAPSETTINGS_H diff --git a/libKelvinDashboardCommon/DapSettingsCipher.cpp b/libKelvinDashboardCommon/DapSettingsCipher.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c0129be074349a332ae33c5889c69803d9d3de37 --- /dev/null +++ b/libKelvinDashboardCommon/DapSettingsCipher.cpp @@ -0,0 +1,23 @@ +#include "DapSettingsCipher.h" + +DapSettingsCipher::DapSettingsCipher(const DapSettings& settings) + : DapSettings(), m_settings(settings) +{ + setFileName(settings.getFileName()); +} + +QByteArray DapSettingsCipher::encrypt(const QByteArray &byteArray) const +{ + return m_settings.encrypt(byteArray); +} + +QByteArray DapSettingsCipher::decrypt(const QByteArray &byteArray) const +{ + return m_settings.decrypt(byteArray); +} + +DapSettingsCipher &DapSettingsCipher::getInstance(const DapSettings& settings) +{ + static DapSettingsCipher instance(settings); + return instance; +} diff --git a/libKelvinDashboardCommon/DapSettingsCipher.h b/libKelvinDashboardCommon/DapSettingsCipher.h new file mode 100644 index 0000000000000000000000000000000000000000..b0d9bebe16246c4a173390f4cd717c0978d948ca --- /dev/null +++ b/libKelvinDashboardCommon/DapSettingsCipher.h @@ -0,0 +1,32 @@ +#ifndef DAPSETTINGSCIPHER_H +#define DAPSETTINGSCIPHER_H + +#include <QObject> + +#include "DapSettings.h" + +class DapSettingsCipher : public DapSettings +{ + Q_OBJECT + +protected: + + const DapSettings &m_settings; + + DapSettingsCipher(const DapSettings& settings); + +public: + virtual QByteArray encrypt(const QByteArray &byteArray) const override; + + virtual QByteArray decrypt(const QByteArray &byteArray) const override; + + /// Removed as part of the implementation of the pattern sington. + DapSettingsCipher(const DapSettingsCipher&) = delete; + DapSettingsCipher& operator= (const DapSettingsCipher &) = delete; + + /// Get an instance of a class. + /// @return Instance of a class. + Q_INVOKABLE static DapSettingsCipher &getInstance(const DapSettings& settings); +}; + +#endif // DAPSETTINGSCIPHER_H diff --git a/libKelvinDashboardCommon/libKelvinDashboardCommon.pri b/libKelvinDashboardCommon/libKelvinDashboardCommon.pri index babffc9bf13edec1868c857f88b033324eda6643..7c81a6284c6ab35731f946a61fbe872fa1432c93 100644 --- a/libKelvinDashboardCommon/libKelvinDashboardCommon.pri +++ b/libKelvinDashboardCommon/libKelvinDashboardCommon.pri @@ -9,14 +9,20 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 +QT += quick quickwidgets + SOURCES +=\ $$PWD/DapCommand.cpp \ $$PWD/DapLocalServer.cpp \ $$PWD/DapLocalClient.cpp \ - $$PWD/DapHalper.cpp + $$PWD/DapHalper.cpp \ + $$PWD/DapSettings.cpp \ + $$PWD/DapSettingsCipher.cpp HEADERS +=\ $$PWD/DapCommand.h \ $$PWD/DapLocalServer.h \ $$PWD/DapLocalClient.h \ - $$PWD/DapHalper.h + $$PWD/DapHalper.h \ + $$PWD/DapSettings.h \ + $$PWD/DapSettingsCipher.h