diff --git a/CellFrameDashboardGUI/DapChainWalletModel.cpp b/CellFrameDashboardGUI/DapChainWalletModel.cpp index 58d5c3d38694d550e868fcb1933206147d289073..1a5d6fd2ed5028a8fc5d81d9cb1603c53fb58403 100644 --- a/CellFrameDashboardGUI/DapChainWalletModel.cpp +++ b/CellFrameDashboardGUI/DapChainWalletModel.cpp @@ -3,7 +3,7 @@ DapChainWalletModel::DapChainWalletModel(QObject *parent) : QAbstractListModel(parent) { - m_currentWallet = "private"; + } DapChainWalletModel& DapChainWalletModel::instance() @@ -24,12 +24,12 @@ QVariant DapChainWalletModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); switch (role) { + case WalletListDisplayRole: return walletList(); case WalletNameDisplayRole: return m_walletList[index.row()].first.Name; case WalletAddressDisplayRole: return m_walletList[index.row()].first.Address; case WalletIconDisplayRole: return m_walletList[index.row()].first.IconPath; case NetworkDisplayRole: return m_walletList[index.row()].first.Network; case WalletTokenListDisplayRole: - qDebug() << "search item list by address" << m_walletList[index.row()].first.Address; return QVariant::fromValue<QList<QObject*>>(tokeListByIndex(index.row())); default: break; } @@ -45,23 +45,28 @@ QHash<int, QByteArray> DapChainWalletModel::roleNames() const roles[WalletIconDisplayRole] = "walletIconDisplayRole"; roles[WalletTokenListDisplayRole] = "walletTokenListDisplayRole"; roles[NetworkDisplayRole] = "networkDisplayRole"; + roles[WalletListDisplayRole] = "walletListDisplayRole"; return roles; } -double DapChainWalletModel::walletBalance(const QString& aAddress) const +QStringList DapChainWalletModel::walletList() const +{ + return m_wallets; +} + +double DapChainWalletModel::walletBalance(const QString& aName) const { double balance = 0.0; + for(int i = 0; i < m_walletList.count(); i++) { - if(m_walletList[i].first.Address == aAddress) + if(m_walletList[i].first.Name == aName || aName == TITLE_ALL_WALLETS) { DapChainWalletTokenItemList tokenList = m_walletList[i].second; for(int m = 0; m < tokenList.count(); m++) { - balance += tokenList[i]->balance(); + balance += tokenList[m]->balance(); } - - break; } } @@ -108,39 +113,12 @@ QList<QObject*> DapChainWalletModel::tokeListByIndex(const int aIndex) const return tokenList; } -double DapChainWalletModel::walletBalance() const -{ - return m_walletBalance; -} - -QList<QObject*> DapChainWalletModel::tokenList() const -{ - return m_tokenList; -} - -void DapChainWalletModel::setCurrentWallet(const QString& aWalletAddress) -{ - if(aWalletAddress == m_currentWallet) return; - beginResetModel(); - m_currentWallet = aWalletAddress; - m_walletBalance = walletBalance(aWalletAddress); - m_tokenList = tokeListByWallet(aWalletAddress); - endResetModel(); - - emit walletBalanceChanged(m_walletBalance); - emit tokenListChanged(m_tokenList); -} - -void DapChainWalletModel::setCurrentWallet(const int aWalletIndex) -{ - QString address = m_walletList[aWalletIndex].first.Address; - setCurrentWallet(address); -} - void DapChainWalletModel::setWalletData(const QByteArray& aData) { beginResetModel(); -// m_walletList.clear(); + m_walletList.clear(); + m_wallets.clear(); + m_wallets << TITLE_ALL_WALLETS; QList<QPair<DapChainWalletData, QList<DapChainWalletTokenData>>> walletData; QDataStream in(aData); in >> walletData; @@ -149,19 +127,18 @@ void DapChainWalletModel::setWalletData(const QByteArray& aData) { DapChainWalletPair walletPair(walletData[i].first, DapChainWalletTokenItemList()); QList<DapChainWalletTokenData> tokeData = walletData[i].second; + if(!m_wallets.contains(walletData[i].first.Name)) + m_wallets.append(walletData[i].first.Name); for(int m = 0; m < tokeData.count(); m++) { - qDebug() << "network: " << walletPair.first.Network; walletPair.second.append(new DapChainWalletTokenItem(walletData[i].first.Address, tokeData[m], this)); - qDebug() << "wallet: " << walletPair.first.Name << walletPair.first.Address; - qDebug() << "token: " << walletPair.second.last()->name() << walletPair.second.last()->balance(); - qDebug() << "-----------------------"; } m_walletList.append(walletPair); } + emit walletListChanged(m_wallets); endResetModel(); } diff --git a/CellFrameDashboardGUI/DapChainWalletModel.h b/CellFrameDashboardGUI/DapChainWalletModel.h index 454d5c6c859885d9c0c7336bd205da9af5007ebd..3a7c9c7c421507f2abce6511d9f6d51fc7af893c 100644 --- a/CellFrameDashboardGUI/DapChainWalletModel.h +++ b/CellFrameDashboardGUI/DapChainWalletModel.h @@ -5,12 +5,12 @@ #include <QDebug> #include "DapChainWallet.h" +#define TITLE_ALL_WALLETS tr("all wallets") + class DapChainWalletModel : public QAbstractListModel { Q_OBJECT - - Q_PROPERTY(double walletBalance READ walletBalance NOTIFY walletBalanceChanged) - Q_PROPERTY(QList<QObject*> tokenList READ tokenList NOTIFY tokenListChanged) + Q_PROPERTY(QStringList wallets READ walletList NOTIFY walletListChanged) public: enum { @@ -18,14 +18,14 @@ public: WalletAddressDisplayRole, WalletIconDisplayRole, WalletTokenListDisplayRole, + WalletListDisplayRole, NetworkDisplayRole, }; private: - QString m_currentWallet; - double m_walletBalance; + QStringList m_wallets; QList<DapChainWalletPair> m_walletList; - QList<QObject*> m_tokenList; + public: explicit DapChainWalletModel(QObject *parent = nullptr); @@ -38,7 +38,9 @@ public: QHash<int, QByteArray> roleNames() const override; - double walletBalance(const QString& aAddress) const; + Q_INVOKABLE QStringList walletList() const; + + Q_INVOKABLE double walletBalance(const QString& aName) const; Q_INVOKABLE double walletBalance(const int aWalletIndex) const; @@ -46,16 +48,8 @@ public: QList<QObject*> tokeListByIndex(const int aIndex) const; - double walletBalance() const; - - QList<QObject*> tokenList() const; - public slots: - Q_INVOKABLE void setCurrentWallet(const QString& aWalletAddress); - - Q_INVOKABLE void setCurrentWallet(const int aWalletIndex); - void setWalletData(const QByteArray& aData); void appendWallet(const DapChainWalletData& aWallet); @@ -67,10 +61,9 @@ public slots: void removeWallet(const int aWalletIndex); signals: - void walletBalanceChanged(double walletBalance); void sigAppendWallet(QString name); void sigRemoveWallet(QString address); - void tokenListChanged(QList<QObject*> tokenList); + void walletListChanged(QStringList walletList); }; #endif // DAPCHAINWALLETMODEL_H diff --git a/CellFrameDashboardGUI/DapUiQmlScreenDialog.qml b/CellFrameDashboardGUI/DapUiQmlScreenDialog.qml index 4f130465458419cca3830b34c27260b424404a00..6dde7af472f6292935c8f56f3d6154329c8bef0d 100644 --- a/CellFrameDashboardGUI/DapUiQmlScreenDialog.qml +++ b/CellFrameDashboardGUI/DapUiQmlScreenDialog.qml @@ -42,7 +42,7 @@ Page { id: listViewToken Layout.fillWidth: true Layout.fillHeight: true - model: dapWalletModel + model: dapWalletFilterModel section.property: "networkDisplayRole" section.criteria: ViewSection.FullString section.delegate: Rectangle { @@ -122,42 +122,36 @@ Page { anchors.fill: parent anchors.topMargin: 1 - Row { - anchors.fill: parent - spacing: 16 * pt - - Label { - anchors.left: parent.left - verticalAlignment: Qt.AlignVCenter - height: parent.height - font.family: fontRobotoRegular.name - font.pixelSize: 18 * pt - color: "#070023" - text: model.modelData.name - } - - Label { - anchors.horizontalCenter: parent.horizontalCenter - width: 300 - height: parent.height - verticalAlignment: Qt.AlignVCenter - font.family: fontRobotoRegular.name - font.pixelSize: 12 * pt - color: "#070023" - text: model.modelData.balance + " " + model.modelData.name - } - - Label { - anchors.right: parent.right - height: parent.height - verticalAlignment: Qt.AlignVCenter - horizontalAlignment: Qt.AlignRight - font.family: fontRobotoRegular.name - font.pixelSize: 12 * pt - color: "#757184" - text: "$ " + model.modelData.balance + " USD" - } + Label { + anchors.left: parent.left + verticalAlignment: Qt.AlignVCenter + height: parent.height + font.family: fontRobotoRegular.name + font.pixelSize: 18 * pt + color: "#070023" + text: model.modelData.name + } + + Label { + anchors.horizontalCenter: parent.horizontalCenter + width: 1 + height: parent.height + verticalAlignment: Qt.AlignVCenter + font.family: fontRobotoRegular.name + font.pixelSize: 12 * pt + color: "#070023" + text: model.modelData.balance + " " + model.modelData.name + } + Label { + anchors.right: parent.right + height: parent.height + verticalAlignment: Qt.AlignVCenter + horizontalAlignment: Qt.AlignRight + font.family: fontRobotoRegular.name + font.pixelSize: 12 * pt + color: "#757184" + text: "$ " + model.modelData.balance + " USD" } } diff --git a/CellFrameDashboardGUI/DapUiQmlScreenMainWindowForm.ui.qml b/CellFrameDashboardGUI/DapUiQmlScreenMainWindowForm.ui.qml index 3ca416191aa376c649168587875d05ad8d5e9da5..84f9a4a2cc439e9588636a0ae3362ed925903a45 100644 --- a/CellFrameDashboardGUI/DapUiQmlScreenMainWindowForm.ui.qml +++ b/CellFrameDashboardGUI/DapUiQmlScreenMainWindowForm.ui.qml @@ -109,42 +109,39 @@ Page { } focus: true -// DapUiQmlWidgetStatusBar { -// id: rectangleStatusBar -// anchors.left: rectangleTabsBorder.right -// anchors.top: parent.top -// anchors.right: parent.right -// color: "#B5B5B5" -// height: 60 * pt - } + } + + Rectangle { + id: mainDashboard + anchors.left: rectangleTabsBorder.right + anchors.top: rectangleStatusBar.bottom + anchors.bottom: parent.bottom + anchors.right: parent.right + border.color: "whitesmoke" - Rectangle { - id: mainDashboard - anchors.left: rectangleTabsBorder.right - anchors.top: rectangleStatusBar.bottom + Loader { + id: stackViewScreenDashboard + anchors.left: parent.left anchors.bottom: parent.bottom - anchors.right: parent.right - border.color: "whitesmoke" - - Loader { - id: stackViewScreenDashboard - clip: true - anchors.fill: parent - source: "DapUiQmlScreenDialog.qml" - } + anchors.top: parent.top + anchors.right: lastActionWidget.left + clip: true + source: "DapUiQmlScreenDialog.qml" } -// DapUiQmlWidgetLastActions { -// viewModel: dapHistoryModel -// viewDelegate: DapUiQmlWidgetLastActionsDelegateForm {} -// viewSection.property: "date" -// viewSection.criteria: ViewSection.FullString -// viewSection.delegate: DapUiQmlWidgetLastActionsSectionForm { -// width: parent.width -// height: 30 * pt -// } -// } + DapUiQmlWidgetLastActions { + id: lastActionWidget + viewModel: dapHistoryModel + viewDelegate: DapUiQmlWidgetLastActionsDelegateForm {} + viewSection.property: "date" + viewSection.criteria: ViewSection.FullString + viewSection.delegate: DapUiQmlWidgetLastActionsSectionForm { + width: parent.width + height: 30 * pt + } + } } +} //} diff --git a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBar.qml b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBar.qml index ee0910fb6bc3b88d730f2afb0eb1e154dc385cd8..9410a694f8b1166325b574904a6df8c9a07fc93d 100644 --- a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBar.qml +++ b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBar.qml @@ -57,7 +57,8 @@ Rectangle { font.family: fontRobotoRegular.name font.pixelSize: 16 * pt color: "#FFFFFF" - text: dapChainConvertor.toConvertCurrency(dapWalletModel.walletBalance) + text: dapChainConvertor.toConvertCurrency( + dapWalletModel.walletBalance(comboboxWallet.currentText)) } } diff --git a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml index ec8a5f1a42330de4d6863ef4cfc14088a022f322..ec27692a890716b433b57f7d53d90a84ec5b9f9f 100644 --- a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml +++ b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml @@ -7,19 +7,14 @@ import QtQml 2.13 DapUiQmlWidgetStatusBarComboBoxWalletForm { property Label fieldBalance: Label {} -// model: dapChainWalletsModel - model: dapWalletModel - textRole: "walletNameDisplayRole" + model: dapWalletModel.wallets delegate: DapUiQmlWidgetStatusBarComboBoxDelegate { - delegateContentText: walletNameDisplayRole + delegateContentText: modelData } - onCurrentIndexChanged: { - dapWalletModel.setCurrentWallet(currentIndex); -// var money = 0.0 -// for(var i = 0; i < dapChainWalletsModel.get(currentIndex).count; i += 3) -// money += parseFloat(dapChainWalletsModel.get(currentIndex).tokens[i]); -// fieldBalance.text = money; + onCurrentTextChanged: { + dapWalletFilterModel.setWalletFilter(currentText); + } } diff --git a/CellFrameDashboardGUI/DapWalletFilterModel.cpp b/CellFrameDashboardGUI/DapWalletFilterModel.cpp index 3683749f886f7160ec336f033fa5ab5c12e49bf0..3228100fb3b02a3ef68a0ad597c11aae1cc8885f 100644 --- a/CellFrameDashboardGUI/DapWalletFilterModel.cpp +++ b/CellFrameDashboardGUI/DapWalletFilterModel.cpp @@ -1,6 +1,8 @@ #include "DapWalletFilterModel.h" -DapWalletFilterModel::DapWalletFilterModel(QObject *parent) : QSortFilterProxyModel(parent) +DapWalletFilterModel::DapWalletFilterModel(QObject *parent) : + QSortFilterProxyModel(parent), + m_filterWalletName(TITLE_ALL_WALLETS) { sort(0, Qt::DescendingOrder); } @@ -11,9 +13,26 @@ DapWalletFilterModel& DapWalletFilterModel::instance() return instance; } +void DapWalletFilterModel::setWalletFilter(const QString& aName) +{ + if(m_filterWalletName == aName) return; + m_filterWalletName = aName; + setFilterKeyColumn(0); +} + bool DapWalletFilterModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const { QString first = source_left.data(DapChainWalletModel::NetworkDisplayRole).toString(); QString second = source_right.data(DapChainWalletModel::NetworkDisplayRole).toString(); return first < second; } + +bool DapWalletFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const +{ + if(m_filterWalletName == TITLE_ALL_WALLETS) return true; + + QModelIndex index = sourceModel()->index(source_row, 0, source_parent); + QString wallet = index.data(DapChainWalletModel::WalletNameDisplayRole).toString(); + + return wallet == m_filterWalletName; +} diff --git a/CellFrameDashboardGUI/DapWalletFilterModel.h b/CellFrameDashboardGUI/DapWalletFilterModel.h index 888ab6758d9f3cbf238d76712ddb8dab3353c501..39b9b1e56c9325f2a5dbd112b49e9a99de320bad 100644 --- a/CellFrameDashboardGUI/DapWalletFilterModel.h +++ b/CellFrameDashboardGUI/DapWalletFilterModel.h @@ -8,13 +8,20 @@ class DapWalletFilterModel : public QSortFilterProxyModel { Q_OBJECT +private: + QString m_filterWalletName; + protected: bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const; -// bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; + bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; public: explicit DapWalletFilterModel(QObject *parent = nullptr); static DapWalletFilterModel& instance(); + +public slots: + Q_INVOKABLE void setWalletFilter(const QString& aName); + }; #endif // DAPWALLETFILTERMODEL_H diff --git a/CellFrameDashboardGUI/main.cpp b/CellFrameDashboardGUI/main.cpp index e397456c904dcde714b46fb042b3c277ab175610..0faab64f446a9664c828145529ad2d63967e7160 100755 --- a/CellFrameDashboardGUI/main.cpp +++ b/CellFrameDashboardGUI/main.cpp @@ -90,7 +90,8 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("dapHistoryModel", &DapScreenHistoryFilterModel::getInstance()); engine.rootContext()->setContextProperty("dapSettingsNetworkModel", &DapSettingsNetworkModel::getInstance()); engine.rootContext()->setContextProperty("dapChainConvertor", &DapChainConvertor::getInstance()); - engine.rootContext()->setContextProperty("dapWalletModel", &DapWalletFilterModel::instance()); + engine.rootContext()->setContextProperty("dapWalletFilterModel", &DapWalletFilterModel::instance()); + engine.rootContext()->setContextProperty("dapWalletModel", &DapChainWalletModel::instance()); engine.rootContext()->setContextProperty("pt", 1.3); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));