From 0ff3fd32122a22d7c56a289faa6402351f425873 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Sun, 2 Oct 2016 21:40:40 +0300 Subject: added TransactionHistoryModel; renamings --- src/libwalletqt/Wallet.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/libwalletqt/Wallet.cpp') diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 987f4640..4dcf9add 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -1,6 +1,7 @@ #include "Wallet.h" #include "PendingTransaction.h" #include "TransactionHistory.h" +#include "model/TransactionHistoryModel.h" #include "wallet/wallet2_api.h" #include @@ -59,7 +60,10 @@ private: Wallet * m_wallet; }; - +Wallet::Wallet(QObject * parent) + : Wallet(nullptr, parent) +{ +} QString Wallet::getSeed() const { @@ -202,6 +206,16 @@ TransactionHistory *Wallet::history() return m_history; } +TransactionHistoryModel *Wallet::historyModel() +{ + if (!m_historyModel) { + m_historyModel = new TransactionHistoryModel(this); + m_historyModel->setTransactionHistory(this->history()); + } + + return m_historyModel; +} + QString Wallet::generatePaymentId() const { @@ -228,6 +242,7 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent) : QObject(parent) , m_walletImpl(w) , m_history(nullptr) + , m_historyModel(nullptr) , m_daemonBlockChainHeight(0) , m_daemonBlockChainHeightTtl(DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS) { @@ -236,5 +251,6 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent) Wallet::~Wallet() { + Bitmonero::WalletManagerFactory::getWalletManager()->closeWallet(m_walletImpl); } -- cgit v1.2.3 From af70c81082bad6fc83fdf3b591fd19a1fc8bdc26 Mon Sep 17 00:00:00 2001 From: Jacob Brydolf Date: Mon, 3 Oct 2016 23:29:30 +0200 Subject: Added daemon BC sync progress bar depends on https://github.com/monero-project/monero/pull/1173 Signed-off-by: Jacob Brydolf --- LeftPanel.qml | 10 ++++- components/DaemonProgress.qml | 90 +++++++++++++++++++++++++++++++++++++++++++ main.qml | 5 +++ qml.qrc | 1 + src/libwalletqt/Wallet.cpp | 6 +++ src/libwalletqt/Wallet.h | 5 ++- 6 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 components/DaemonProgress.qml (limited to 'src/libwalletqt/Wallet.cpp') diff --git a/LeftPanel.qml b/LeftPanel.qml index 59793659..93290bc6 100644 --- a/LeftPanel.qml +++ b/LeftPanel.qml @@ -36,6 +36,7 @@ Rectangle { property alias unlockedBalanceText: unlockedBalanceText.text property alias balanceText: balanceText.text property alias networkStatus : networkStatus + property alias daemonProgress : daemonProgress signal dashboardClicked() signal historyClicked() @@ -352,9 +353,16 @@ Rectangle { id: networkStatus anchors.left: parent.left anchors.right: parent.right - anchors.bottom: parent.bottom + anchors.bottom: (daemonProgress.visible)? daemonProgress.top : parent.bottom; connected: false } + + DaemonProgress { + id: daemonProgress + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + } } // indicate disabled state Desaturate { diff --git a/components/DaemonProgress.qml b/components/DaemonProgress.qml new file mode 100644 index 00000000..1ed533e3 --- /dev/null +++ b/components/DaemonProgress.qml @@ -0,0 +1,90 @@ +// Copyright (c) 2014-2015, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import QtQuick 2.0 + +Item { + id: item + property int fillLevel: 0 + height: 44 + anchors.margins: 10 + visible: false + //clip: true + + function updateProgress(currentBlock,targetBlock){ + if(targetBlock > 0) { + var progressLevel = ((currentBlock/targetBlock) * 100).toFixed(0); + fillLevel = progressLevel + console.log("target block: ",progressLevel) + progressText.text = qsTr("Synchronizing blocks %1/%2").arg(currentBlock.toFixed(0)).arg(targetBlock.toFixed(0)); + console.log("Progress text: " + progressText.text); + + // TODO: lower daemon block height cache, ttl and refresh interval? + + item.visible = (currentBlock < targetBlock) + + } + } + + Rectangle { + id: bar + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + height: 18 + //radius: 4 + color: "#FFFFFF" + + Rectangle { + id: fillRect + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.margins: 2 + property int maxWidth: parent.width - 4 + width: (maxWidth * fillLevel) / 100 + + color: { + if(item.fillLevel < 99) return "#FF6C3C" + //if(item.fillLevel < 99) return "#FFE00A" + return "#36B25C" + } + + } + } + + Text { + id:progressText + anchors.bottom: parent.bottom + font.family: "Arial" + font.pixelSize: 12 + color: "#545454" + text: qsTr("Synchronizing blocks") + } + +} diff --git a/main.qml b/main.qml index 1a97a5d1..82f5c17f 100644 --- a/main.qml +++ b/main.qml @@ -221,6 +221,9 @@ ApplicationWindow { if (splash.visible) { hideProcessingSplash() } + var dCurrentBlock = currentWallet.daemonBlockChainHeight(); + var dTargetBlock = currentWallet.daemonBlockChainTargetHeight(); + leftPanel.daemonProgress.updateProgress(dCurrentBlock,dTargetBlock); // Store wallet after first refresh. To prevent broken wallet after a crash // TODO: Move this to libwallet? @@ -231,6 +234,7 @@ ApplicationWindow { } leftPanel.networkStatus.connected = currentWallet.connected + onWalletUpdate(); } @@ -247,6 +251,7 @@ ApplicationWindow { } + function walletsFound() { var wallets = walletManager.findWallets(moneroAccountsDir); if (wallets.length === 0) { diff --git a/qml.qrc b/qml.qrc index a44266b9..ad47ba44 100644 --- a/qml.qrc +++ b/qml.qrc @@ -116,5 +116,6 @@ lang/flags/italy.png components/PasswordDialog.qml components/ProcessingSplash.qml + components/DaemonProgress.qml diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 4dcf9add..9f0908b9 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -157,6 +157,12 @@ quint64 Wallet::daemonBlockChainHeight() const return m_daemonBlockChainHeight; } +quint64 Wallet::daemonBlockChainTargetHeight() const +{ + m_daemonBlockChainTargetHeight = m_walletImpl->daemonBlockChainTargetHeight(); + return m_daemonBlockChainTargetHeight; +} + bool Wallet::refresh() { bool result = m_walletImpl->refresh(); diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 1a6459d4..d3ca4085 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -92,6 +92,9 @@ public: //! returns daemon's blockchain height Q_INVOKABLE quint64 daemonBlockChainHeight() const; + //! returns daemon's blockchain target height + Q_INVOKABLE quint64 daemonBlockChainTargetHeight() const; + //! refreshes the wallet Q_INVOKABLE bool refresh(); @@ -162,7 +165,7 @@ private: mutable QTime m_daemonBlockChainHeightTime; mutable quint64 m_daemonBlockChainHeight; int m_daemonBlockChainHeightTtl; - + mutable quint64 m_daemonBlockChainTargetHeight; }; -- cgit v1.2.3 From 522b0671adf946bb4def414f1bbdbca492cf0cd6 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 4 Oct 2016 23:12:58 +0300 Subject: Simple transaction history --- components/HistoryTable.qml | 53 +++++++++++++++++++++------------- main.cpp | 3 ++ pages/History.qml | 5 +++- src/libwalletqt/TransactionHistory.cpp | 8 +++++ src/libwalletqt/TransactionInfo.cpp | 16 ++++++++-- src/libwalletqt/TransactionInfo.h | 15 +++++++--- src/libwalletqt/Wallet.cpp | 13 ++++++--- src/model/TransactionHistoryModel.cpp | 20 +++++++++++++ src/model/TransactionHistoryModel.h | 13 ++++++--- 9 files changed, 110 insertions(+), 36 deletions(-) (limited to 'src/libwalletqt/Wallet.cpp') diff --git a/components/HistoryTable.qml b/components/HistoryTable.qml index 15e3a7d8..13bf3775 100644 --- a/components/HistoryTable.qml +++ b/components/HistoryTable.qml @@ -29,10 +29,12 @@ import QtQuick 2.0 import moneroComponents.Clipboard 1.0 + ListView { id: listView clip: true boundsBehavior: ListView.StopAtBounds + property var previousItem footer: Rectangle { height: 127 @@ -48,7 +50,7 @@ ListView { } } - property var previousItem + delegate: Rectangle { id: delegate height: 114 @@ -63,13 +65,13 @@ ListView { anchors.right: parent.right anchors.top: parent.top anchors.topMargin: 14 - + // -- direction indicator Rectangle { id: dot width: 14 height: width radius: width / 2 - color: out ? "#FF4F41" : "#36B05B" + color: isOut ? "#FF4F41" : "#36B05B" } Item { //separator @@ -77,6 +79,7 @@ ListView { height: 14 } + // -- description aka recepient name from address book (TODO) Text { id: descriptionText width: text.length ? (descriptionArea.containsMouse ? parent.width - x - 12 : 120) : 0 @@ -100,7 +103,7 @@ ListView { height: 14 visible: !descriptionArea.containsMouse } - + // -- address (in case outgoing transaction) - N/A in case of incoming Text { id: addressText anchors.verticalCenter: dot.verticalCenter @@ -109,11 +112,11 @@ ListView { font.family: "Arial" font.pixelSize: 14 color: "#545454" - text: address + text: hash visible: !descriptionArea.containsMouse } } - + // -- "PaymentID" title Text { id: paymentLabel anchors.left: parent.left @@ -128,7 +131,7 @@ ListView { color: "#535353" text: paymentId !== "" ? qsTr("Payment ID:") + translationManager.emptyString : "" } - + // -- "PaymentID" value Text { anchors.bottom: paymentLabel.bottom anchors.left: paymentLabel.right @@ -143,7 +146,7 @@ ListView { color: "#545454" text: paymentId } - + // -- "Date", "Balance" and "Amound" section Row { anchors.left: parent.left anchors.bottom: parent.bottom @@ -155,6 +158,7 @@ ListView { height: 14 } + // -- "Date" column Column { anchors.top: parent.top width: 215 @@ -189,10 +193,13 @@ ListView { } } } - + // -- "Balance" column + // XXX: we don't have a balance + /* Column { anchors.top: parent.top width: 148 + visible: false Text { anchors.left: parent.left @@ -210,7 +217,9 @@ ListView { text: balance } } + */ + // -- "Amount column Column { anchors.top: parent.top width: 148 @@ -230,8 +239,8 @@ ListView { anchors.bottomMargin: 3 font.family: "Arial" font.pixelSize: 16 - color: out ? "#FF4F41" : "#36B05B" - text: out ? "↓" : "↑" + color: isOut ? "#FF4F41" : "#36B05B" + text: isOut ? "↓" : "↑" } Text { @@ -239,22 +248,16 @@ ListView { font.family: "Arial" font.pixelSize: 18 font.letterSpacing: -1 - color: out ? "#FF4F41" : "#36B05B" + color: isOut ? "#FF4F41" : "#36B05B" text: amount } } } } - ListModel { - id: dropModel - ListElement { name: "Copy address to clipboard"; icon: "../images/dropdownCopy.png" } - ListElement { name: "Add to address book"; icon: "../images/dropdownAdd.png" } - ListElement { name: "Send to same destination"; icon: "../images/dropdownSend.png" } - ListElement { name: "Find similar transactions"; icon: "../images/dropdownSearch.png" } - } - Clipboard { id: clipboard } + + TableDropdown { id: dropdown anchors.right: parent.right @@ -283,4 +286,14 @@ ListView { color: "#DBDBDB" } } + + ListModel { + id: dropModel + ListElement { name: "Copy address to clipboard"; icon: "../images/dropdownCopy.png" } + ListElement { name: "Add to address book"; icon: "../images/dropdownAdd.png" } + ListElement { name: "Send to same destination"; icon: "../images/dropdownSend.png" } + ListElement { name: "Find similar transactions"; icon: "../images/dropdownSearch.png" } + } + + Clipboard { id: clipboard } } diff --git a/main.cpp b/main.cpp index d7c510b5..1709dc88 100644 --- a/main.cpp +++ b/main.cpp @@ -39,6 +39,7 @@ #include "Wallet.h" #include "PendingTransaction.h" #include "TranslationManager.h" +#include "TransactionInfo.h" #include "model/TransactionHistoryModel.h" @@ -72,6 +73,8 @@ int main(int argc, char *argv[]) qRegisterMetaType(); + qRegisterMetaType(); + qmlRegisterUncreatableType("moneroComponents", 1, 0, "TransactionHistoryModel", "TranslationManager can't be instantiated directly"); diff --git a/pages/History.qml b/pages/History.qml index 8fce5110..15cf1bc0 100644 --- a/pages/History.qml +++ b/pages/History.qml @@ -33,10 +33,13 @@ import moneroComponents.WalletManager 1.0 Rectangle { id: root - property ListModel model: testModel + property var model: testModel color: "#F0EEEE" + onModelChanged: { + console.log("model.rowCount: " + model.rowCount()) + } Text { diff --git a/src/libwalletqt/TransactionHistory.cpp b/src/libwalletqt/TransactionHistory.cpp index 7466038f..8f52f07e 100644 --- a/src/libwalletqt/TransactionHistory.cpp +++ b/src/libwalletqt/TransactionHistory.cpp @@ -2,11 +2,18 @@ #include "TransactionInfo.h" #include +#include + TransactionInfo *TransactionHistory::transaction(int index) { // box up Bitmonero::TransactionInfo Bitmonero::TransactionInfo * impl = m_pimpl->transaction(index); + if (!impl) { + qCritical("%s: no transaction info for index %d", __FUNCTION__, index); + qCritical("%s: there's %d transactions in backend", __FUNCTION__, m_pimpl->count()); + return nullptr; + } TransactionInfo * result = new TransactionInfo(impl, this); return result; } @@ -34,6 +41,7 @@ QList TransactionHistory::getAll() const void TransactionHistory::refresh() { // XXX this invalidates previously saved history that might be used by clients + emit refreshStarted(); m_pimpl->refresh(); emit refreshFinished(); diff --git a/src/libwalletqt/TransactionInfo.cpp b/src/libwalletqt/TransactionInfo.cpp index 40711765..3aa7334c 100644 --- a/src/libwalletqt/TransactionInfo.cpp +++ b/src/libwalletqt/TransactionInfo.cpp @@ -39,13 +39,23 @@ QString TransactionInfo::hash() const return QString::fromStdString(m_pimpl->hash()); } -QString TransactionInfo::timestamp() +QDateTime TransactionInfo::timestamp() const { - QString result = QDateTime::fromTime_t(m_pimpl->timestamp()).toString(Qt::ISODate); + QDateTime result = QDateTime::fromTime_t(m_pimpl->timestamp()); return result; } -QString TransactionInfo::paymentId() +QString TransactionInfo::date() const +{ + return timestamp().date().toString(Qt::ISODate); +} + +QString TransactionInfo::time() const +{ + return timestamp().time().toString(Qt::ISODate); +} + +QString TransactionInfo::paymentId() const { return QString::fromStdString(m_pimpl->paymentId()); } diff --git a/src/libwalletqt/TransactionInfo.h b/src/libwalletqt/TransactionInfo.h index 4dabc5b4..3381131a 100644 --- a/src/libwalletqt/TransactionInfo.h +++ b/src/libwalletqt/TransactionInfo.h @@ -1,8 +1,9 @@ #ifndef TRANSACTIONINFO_H #define TRANSACTIONINFO_H -#include #include +#include +#include class TransactionInfo : public QObject { @@ -14,7 +15,9 @@ class TransactionInfo : public QObject Q_PROPERTY(QString fee READ fee) Q_PROPERTY(quint64 blockHeight READ blockHeight) Q_PROPERTY(QString hash READ hash) - Q_PROPERTY(QString timestamp READ timestamp) + Q_PROPERTY(QDateTime timestamp READ timestamp) + Q_PROPERTY(QString date READ date) + Q_PROPERTY(QString time READ time) Q_PROPERTY(QString paymentId READ paymentId) public: @@ -41,8 +44,11 @@ public: quint64 blockHeight() const; //! transaction_id QString hash() const; - QString timestamp(); - QString paymentId(); + QDateTime timestamp() const; + QString date() const; + QString time() const; + QString paymentId() const; + // TODO: implement it //! only applicable for output transactions @@ -57,4 +63,5 @@ private: // in order to wrap it to QVariant Q_DECLARE_METATYPE(TransactionInfo*) + #endif // TRANSACTIONINFO_H diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 9f0908b9..39d40a17 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -40,12 +40,14 @@ public: virtual void newBlock(uint64_t height) { // qDebug() << __FUNCTION__; + m_wallet->m_history->refresh(); emit m_wallet->newBlock(height); } virtual void updated() { qDebug() << __FUNCTION__; + m_wallet->m_history->refresh(); emit m_wallet->updated(); } @@ -53,6 +55,7 @@ public: virtual void refreshed() { qDebug() << __FUNCTION__; + emit m_wallet->refreshed(); } @@ -166,6 +169,7 @@ quint64 Wallet::daemonBlockChainTargetHeight() const bool Wallet::refresh() { bool result = m_walletImpl->refresh(); + m_history->refresh(); if (result) emit updated(); return result; @@ -205,10 +209,10 @@ void Wallet::disposeTransaction(PendingTransaction *t) TransactionHistory *Wallet::history() { - if (!m_history) { - Bitmonero::TransactionHistory * impl = m_walletImpl->history(); - m_history = new TransactionHistory(impl, this); - } +// if (m_history->count() == 0) { +// m_history->refresh(); +// } + return m_history; } @@ -252,6 +256,7 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent) , m_daemonBlockChainHeight(0) , m_daemonBlockChainHeightTtl(DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS) { + m_history = new TransactionHistory(m_walletImpl->history(), this); m_walletImpl->setListener(new WalletListenerImpl(this)); } diff --git a/src/model/TransactionHistoryModel.cpp b/src/model/TransactionHistoryModel.cpp index 1666981c..b8f23f68 100644 --- a/src/model/TransactionHistoryModel.cpp +++ b/src/model/TransactionHistoryModel.cpp @@ -2,6 +2,8 @@ #include "TransactionHistory.h" #include "TransactionInfo.h" +#include + TransactionHistoryModel::TransactionHistoryModel(QObject *parent) : QAbstractListModel(parent), m_transactionHistory(nullptr) @@ -14,6 +16,12 @@ void TransactionHistoryModel::setTransactionHistory(TransactionHistory *th) beginResetModel(); m_transactionHistory = th; endResetModel(); + + connect(m_transactionHistory, &TransactionHistory::refreshStarted, + this, &TransactionHistoryModel::beginResetModel); + connect(m_transactionHistory, &TransactionHistory::refreshFinished, + this, &TransactionHistoryModel::endResetModel); + emit transactionHistoryChanged(); } @@ -72,6 +80,15 @@ QVariant TransactionHistoryModel::data(const QModelIndex &index, int role) const case TransactionPaymentIdRole: result = tInfo->paymentId(); break; + case TransactionIsOutRole: + result = tInfo->direction() == TransactionInfo::Direction_Out; + break; + case TransactionDateRole: + result = tInfo->date(); + break; + case TransactionTimeRole: + result = tInfo->time(); + break; } return result; @@ -96,6 +113,9 @@ QHash TransactionHistoryModel::roleNames() const roleNames.insert(TransactionHashRole, "hash"); roleNames.insert(TransactionTimeStampRole, "timeStamp"); roleNames.insert(TransactionPaymentIdRole, "paymentId"); + roleNames.insert(TransactionIsOutRole, "isOut"); + roleNames.insert(TransactionDateRole, "date"); + roleNames.insert(TransactionTimeRole, "time"); return roleNames; } diff --git a/src/model/TransactionHistoryModel.h b/src/model/TransactionHistoryModel.h index 2813a89a..96d3ff32 100644 --- a/src/model/TransactionHistoryModel.h +++ b/src/model/TransactionHistoryModel.h @@ -25,7 +25,12 @@ public: TransactionBlockHeightRole, TransactionHashRole, TransactionTimeStampRole, - TransactionPaymentIdRole + TransactionPaymentIdRole, + // extra role (alias) for TransactionDirectionRole (as UI currently wants just boolean "out") + TransactionIsOutRole, + // extra roles for date and time (as UI wants date and time separately) + TransactionDateRole, + TransactionTimeRole }; TransactionHistoryModel(QObject * parent = 0); @@ -33,9 +38,9 @@ public: TransactionHistory * transactionHistory() const; /// QAbstractListModel - virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; - virtual int rowCount(const QModelIndex & parent = QModelIndex()) const override; - virtual QHash roleNames() const override; + virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; + virtual int rowCount(const QModelIndex & parent = QModelIndex()) const override; + virtual QHash roleNames() const override; signals: void transactionHistoryChanged(); -- cgit v1.2.3 From 0498c3ba64ace2bd8898a5d0ba3107a2f024c692 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 7 Oct 2016 00:47:28 +0300 Subject: Transaction history is not crashing and refreshing properly --- components/HistoryTable.qml | 7 +++++-- main.cpp | 6 +++++- main.qml | 26 ++++++++++++++++++++++--- pages/History.qml | 5 +++-- src/libwalletqt/TransactionHistory.cpp | 35 +++++++++++++++++----------------- src/libwalletqt/TransactionHistory.h | 6 +++--- src/libwalletqt/Wallet.cpp | 20 +++++++++---------- src/libwalletqt/Wallet.h | 14 +++++++++----- 8 files changed, 74 insertions(+), 45 deletions(-) (limited to 'src/libwalletqt/Wallet.cpp') diff --git a/components/HistoryTable.qml b/components/HistoryTable.qml index 13bf3775..441fbcf5 100644 --- a/components/HistoryTable.qml +++ b/components/HistoryTable.qml @@ -80,6 +80,7 @@ ListView { } // -- description aka recepient name from address book (TODO) + /* Text { id: descriptionText width: text.length ? (descriptionArea.containsMouse ? parent.width - x - 12 : 120) : 0 @@ -97,12 +98,14 @@ ListView { hoverEnabled: true } } - + */ + /* Item { //separator width: descriptionText.width ? 12 : 0 height: 14 visible: !descriptionArea.containsMouse } + */ // -- address (in case outgoing transaction) - N/A in case of incoming Text { id: addressText @@ -113,7 +116,7 @@ ListView { font.pixelSize: 14 color: "#545454" text: hash - visible: !descriptionArea.containsMouse + // visible: !descriptionArea.containsMouse } } // -- "PaymentID" title diff --git a/main.cpp b/main.cpp index 1709dc88..9c87628f 100644 --- a/main.cpp +++ b/main.cpp @@ -40,6 +40,7 @@ #include "PendingTransaction.h" #include "TranslationManager.h" #include "TransactionInfo.h" +#include "TransactionHistory.h" #include "model/TransactionHistoryModel.h" @@ -57,6 +58,7 @@ int main(int argc, char *argv[]) filter *eventFilter = new filter; app.installEventFilter(eventFilter); + // registering types for QML qmlRegisterType("moneroComponents.Clipboard", 1, 0, "Clipboard"); qmlRegisterUncreatableType("moneroComponents.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly"); @@ -77,7 +79,9 @@ int main(int argc, char *argv[]) qmlRegisterUncreatableType("moneroComponents", 1, 0, "TransactionHistoryModel", - "TranslationManager can't be instantiated directly"); + "TransactionHistoryModel can't be instantiated directly"); + qmlRegisterUncreatableType("moneroComponents", 1, 0, "TransactionHistory", + "TransactionHistory can't be instantiated directly"); QQmlApplicationEngine engine; diff --git a/main.qml b/main.qml index d6d45409..97ea5738 100644 --- a/main.qml +++ b/main.qml @@ -55,6 +55,8 @@ ApplicationWindow { property alias password : passwordDialog.password property int splashCounter: 0 property bool isNewWallet: false + // true if wallet ever synchronized + property bool walletInitialized : false function altKeyReleased() { ctrlPressed = false; } @@ -168,11 +170,10 @@ ApplicationWindow { currentWallet.refreshed.connect(onWalletRefresh) currentWallet.updated.connect(onWalletUpdate) currentWallet.newBlock.connect(onWalletNewBlock) - + currentWallet.moneySpent.connect(onWalletMoneySent) + currentWallet.moneyReceived.connect(onWalletMoneyReceived) console.log("initializing with daemon address: ", persistentSettings.daemon_address) - currentWallet.initAsync(persistentSettings.daemon_address, 0); - } function walletPath() { @@ -241,6 +242,13 @@ ApplicationWindow { console.log("wallet stored after first successfull refresh") } + // initialize transaction history once wallet is initializef first time; + if (!walletInitialized) { + currentWallet.history.refresh() + walletInitialized = true + + } + leftPanel.networkStatus.connected = currentWallet.connected onWalletUpdate(); @@ -258,6 +266,18 @@ ApplicationWindow { } } + function onWalletMoneyReceived(txId, amount) { + // refresh transaction history here + currentWallet.refresh() + currentWallet.history.refresh() // this will refresh model + } + + function onWalletMoneySent(txId, amount) { + // refresh transaction history here + currentWallet.refresh() + currentWallet.history.refresh() // this will refresh model + } + function walletsFound() { diff --git a/pages/History.qml b/pages/History.qml index 15cf1bc0..d1934629 100644 --- a/pages/History.qml +++ b/pages/History.qml @@ -33,7 +33,7 @@ import moneroComponents.WalletManager 1.0 Rectangle { id: root - property var model: testModel + property var model color: "#F0EEEE" @@ -340,7 +340,7 @@ Rectangle { offset: 20 onSortRequest: console.log("column: " + column + " desc: " + desc) } - + /* ListModel { id: testModel ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 AM"; amount: "0.000709159241"; balance: "19301.870709159241"; description: "Client from Australia"; out: false } @@ -354,6 +354,7 @@ Rectangle { ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 AM"; amount: "0.000709159241"; balance: "19301.870709159241"; description: "Client from Australia"; out: false } ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 AM"; amount: "0.000709159241"; balance: "19301.870709159241"; description: ""; out: false } } + */ Scroll { id: flickableScroll diff --git a/src/libwalletqt/TransactionHistory.cpp b/src/libwalletqt/TransactionHistory.cpp index 8f52f07e..e94816f2 100644 --- a/src/libwalletqt/TransactionHistory.cpp +++ b/src/libwalletqt/TransactionHistory.cpp @@ -7,54 +7,53 @@ TransactionInfo *TransactionHistory::transaction(int index) { - // box up Bitmonero::TransactionInfo - Bitmonero::TransactionInfo * impl = m_pimpl->transaction(index); - if (!impl) { + + if (index < 0 || index >= m_tinfo.size()) { qCritical("%s: no transaction info for index %d", __FUNCTION__, index); qCritical("%s: there's %d transactions in backend", __FUNCTION__, m_pimpl->count()); return nullptr; } - TransactionInfo * result = new TransactionInfo(impl, this); - return result; + return m_tinfo.at(index); } -TransactionInfo *TransactionHistory::transaction(const QString &id) -{ - // box up Bitmonero::TransactionInfo - Bitmonero::TransactionInfo * impl = m_pimpl->transaction(id.toStdString()); - TransactionInfo * result = new TransactionInfo(impl, this); - return result; -} +//// XXX: not sure if this method really needed; +//TransactionInfo *TransactionHistory::transaction(const QString &id) +//{ +// return nullptr; +//} QList TransactionHistory::getAll() const { + // XXX this invalidates previously saved history that might be used by model + emit refreshStarted(); qDeleteAll(m_tinfo); m_tinfo.clear(); TransactionHistory * parent = const_cast(this); for (const auto i : m_pimpl->getAll()) { TransactionInfo * ti = new TransactionInfo(i, parent); + qDebug() << ti->hash(); m_tinfo.append(ti); } + emit refreshFinished(); return m_tinfo; } void TransactionHistory::refresh() { - // XXX this invalidates previously saved history that might be used by clients - - emit refreshStarted(); + // rebuilding transaction list in wallet_api; m_pimpl->refresh(); - emit refreshFinished(); + // copying list here and keep track on every item to avoid memleaks + getAll(); } quint64 TransactionHistory::count() const { - return m_pimpl->count(); + return m_tinfo.count(); } TransactionHistory::TransactionHistory(Bitmonero::TransactionHistory *pimpl, QObject *parent) : QObject(parent), m_pimpl(pimpl) { - + // this->refresh(); } diff --git a/src/libwalletqt/TransactionHistory.h b/src/libwalletqt/TransactionHistory.h index 560b8df8..d7a7278e 100644 --- a/src/libwalletqt/TransactionHistory.h +++ b/src/libwalletqt/TransactionHistory.h @@ -17,14 +17,14 @@ class TransactionHistory : public QObject public: Q_INVOKABLE TransactionInfo *transaction(int index); - Q_INVOKABLE TransactionInfo * transaction(const QString &id); + // Q_INVOKABLE TransactionInfo * transaction(const QString &id); Q_INVOKABLE QList getAll() const; Q_INVOKABLE void refresh(); quint64 count() const; signals: - void refreshStarted(); - void refreshFinished(); + void refreshStarted() const; + void refreshFinished() const; public slots: diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 39d40a17..14e0a868 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -32,7 +32,6 @@ public: virtual void moneyReceived(const std::string &txId, uint64_t amount) { - qDebug() << __FUNCTION__; emit m_wallet->moneyReceived(QString::fromStdString(txId), amount); } @@ -40,14 +39,12 @@ public: virtual void newBlock(uint64_t height) { // qDebug() << __FUNCTION__; - m_wallet->m_history->refresh(); emit m_wallet->newBlock(height); } virtual void updated() { qDebug() << __FUNCTION__; - m_wallet->m_history->refresh(); emit m_wallet->updated(); } @@ -55,7 +52,6 @@ public: virtual void refreshed() { qDebug() << __FUNCTION__; - emit m_wallet->refreshed(); } @@ -93,6 +89,11 @@ bool Wallet::connected() const return m_walletImpl->connected(); } +bool Wallet::synchronized() const +{ + return m_walletImpl->synchronized(); +} + QString Wallet::errorString() const { return QString::fromStdString(m_walletImpl->errorString()); @@ -207,19 +208,16 @@ void Wallet::disposeTransaction(PendingTransaction *t) delete t; } -TransactionHistory *Wallet::history() +TransactionHistory *Wallet::history() const { -// if (m_history->count() == 0) { -// m_history->refresh(); -// } - return m_history; } -TransactionHistoryModel *Wallet::historyModel() +TransactionHistoryModel *Wallet::historyModel() const { if (!m_historyModel) { - m_historyModel = new TransactionHistoryModel(this); + Wallet * w = const_cast(this); + m_historyModel = new TransactionHistoryModel(w); m_historyModel->setTransactionHistory(this->history()); } diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index d3ca4085..159a08b0 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -22,6 +22,7 @@ class Wallet : public QObject Q_PROPERTY(QString seedLanguage READ getSeedLanguage) Q_PROPERTY(Status status READ status) Q_PROPERTY(bool connected READ connected) + Q_PROPERTY(bool synchronized READ synchronized) Q_PROPERTY(QString errorString READ errorString) Q_PROPERTY(QString address READ address) Q_PROPERTY(quint64 balance READ balance) @@ -52,9 +53,13 @@ public: //! returns last operation's status Status status() const; - //! returns of wallet connected + //! returns true if wallet connected bool connected() const; + //! returns true if wallet was ever synchronized + bool synchronized() const; + + //! returns last operation's error message QString errorString() const; @@ -98,7 +103,6 @@ public: //! refreshes the wallet Q_INVOKABLE bool refresh(); - //! refreshes the wallet asynchronously Q_INVOKABLE void refreshAsync(); @@ -116,10 +120,10 @@ public: Q_INVOKABLE void disposeTransaction(PendingTransaction * t); //! returns transaction history - TransactionHistory * history(); + TransactionHistory * history() const; //! returns transaction history model - TransactionHistoryModel * historyModel(); + TransactionHistoryModel * historyModel() const; //! generate payment id Q_INVOKABLE QString generatePaymentId() const; @@ -160,7 +164,7 @@ private: // history lifetime managed by wallet; TransactionHistory * m_history; // Used for UI history view - TransactionHistoryModel * m_historyModel; + mutable TransactionHistoryModel * m_historyModel; QString m_paymentId; mutable QTime m_daemonBlockChainHeightTime; mutable quint64 m_daemonBlockChainHeight; -- cgit v1.2.3 From 612c497608cc64234a05cd413d4269160f17100c Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 7 Oct 2016 23:05:51 +0300 Subject: TransactionHistory sorting --- components/HistoryTable.qml | 2 +- main.cpp | 18 ++++--- monero-core.pro | 6 ++- pages/History.qml | 49 +++++++++++++++---- src/libwalletqt/TransactionInfo.cpp | 8 +++- src/libwalletqt/TransactionInfo.h | 6 ++- src/libwalletqt/Wallet.cpp | 7 ++- src/libwalletqt/Wallet.h | 6 ++- src/model/TransactionHistoryModel.cpp | 4 ++ src/model/TransactionHistoryModel.h | 17 ++++++- src/model/TransactionHistorySortFilterModel.cpp | 64 ++++++++++++++++++++++++- src/model/TransactionHistorySortFilterModel.h | 34 ++++++++++--- wizard/WizardCreateWallet.qml | 4 +- wizard/WizardManageWalletUI.qml | 2 +- 14 files changed, 191 insertions(+), 36 deletions(-) (limited to 'src/libwalletqt/Wallet.cpp') diff --git a/components/HistoryTable.qml b/components/HistoryTable.qml index 441fbcf5..0cca1148 100644 --- a/components/HistoryTable.qml +++ b/components/HistoryTable.qml @@ -252,7 +252,7 @@ ListView { font.pixelSize: 18 font.letterSpacing: -1 color: isOut ? "#FF4F41" : "#36B05B" - text: amount + text: displayAmount } } } diff --git a/main.cpp b/main.cpp index 9c87628f..58ca60f8 100644 --- a/main.cpp +++ b/main.cpp @@ -42,7 +42,7 @@ #include "TransactionInfo.h" #include "TransactionHistory.h" #include "model/TransactionHistoryModel.h" - +#include "model/TransactionHistorySortFilterModel.h" int main(int argc, char *argv[]) @@ -70,19 +70,23 @@ int main(int argc, char *argv[]) qmlRegisterUncreatableType("moneroComponents.WalletManager", 1, 0, "WalletManager", "WalletManager can't be instantiated directly"); - qmlRegisterUncreatableType("moneroComponents", 1, 0, "TranslationManager", + qmlRegisterUncreatableType("moneroComponents.TranslationManager", 1, 0, "TranslationManager", "TranslationManager can't be instantiated directly"); - qRegisterMetaType(); - - qRegisterMetaType(); - qmlRegisterUncreatableType("moneroComponents", 1, 0, "TransactionHistoryModel", + qmlRegisterUncreatableType("moneroComponents.TransactionHistoryModel", 1, 0, "TransactionHistoryModel", "TransactionHistoryModel can't be instantiated directly"); - qmlRegisterUncreatableType("moneroComponents", 1, 0, "TransactionHistory", + + qmlRegisterUncreatableType("moneroComponents.TransactionHistorySortFilterModel", 1, 0, "TransactionHistorySortFilterModel", + "TransactionHistorySortFilterModel can't be instantiated directly"); + + qmlRegisterUncreatableType("moneroComponents.TransactionHistory", 1, 0, "TransactionHistory", "TransactionHistory can't be instantiated directly"); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); QQmlApplicationEngine engine; diff --git a/monero-core.pro b/monero-core.pro index 6f21e6ea..daa1378d 100644 --- a/monero-core.pro +++ b/monero-core.pro @@ -24,7 +24,8 @@ HEADERS += \ src/libwalletqt/TransactionInfo.h \ oshelper.h \ TranslationManager.h \ - src/model/TransactionHistoryModel.h + src/model/TransactionHistoryModel.h \ + src/model/TransactionHistorySortFilterModel.h SOURCES += main.cpp \ @@ -38,7 +39,8 @@ SOURCES += main.cpp \ src/libwalletqt/TransactionInfo.cpp \ oshelper.cpp \ TranslationManager.cpp \ - src/model/TransactionHistoryModel.cpp + src/model/TransactionHistoryModel.cpp \ + src/model/TransactionHistorySortFilterModel.cpp lupdate_only { SOURCES = *.qml \ diff --git a/pages/History.qml b/pages/History.qml index d1934629..f8337c5b 100644 --- a/pages/History.qml +++ b/pages/History.qml @@ -27,9 +27,13 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import QtQuick 2.0 -import "../components" + import moneroComponents.Wallet 1.0 import moneroComponents.WalletManager 1.0 +import moneroComponents.TransactionHistory 1.0 +import moneroComponents.TransactionHistoryModel 1.0 + +import "../components" Rectangle { id: root @@ -57,6 +61,8 @@ Rectangle { text: qsTr("Filter transactions history") + translationManager.emptyString } + // Filter by Address input (senseless, removing) + /* Label { id: addressLabel anchors.left: parent.left @@ -77,11 +83,14 @@ Rectangle { anchors.rightMargin: 17 anchors.topMargin: 5 } + */ + + // Filter by Payment ID input Label { id: paymentIdLabel anchors.left: parent.left - anchors.top: addressLine.bottom + anchors.top: filterHeaderText.bottom // addressLine.bottom anchors.leftMargin: 17 anchors.topMargin: 17 text: qsTr("Payment ID (Optional)") + translationManager.emptyString @@ -94,12 +103,14 @@ Rectangle { id: paymentIdLine anchors.left: parent.left anchors.right: parent.right - anchors.top: paymentIdLabel.bottom + anchors.top: paymentIdLabel.bottom // addressLabel.bottom anchors.leftMargin: 17 anchors.rightMargin: 17 anchors.topMargin: 5 } + // Filter by description input (not implemented yet) + /* Label { id: descriptionLabel anchors.left: parent.left @@ -120,11 +131,14 @@ Rectangle { anchors.rightMargin: 17 anchors.topMargin: 5 } + */ + + // DateFrom picker Label { id: dateFromText anchors.left: parent.left - anchors.top: descriptionLine.bottom + anchors.top: paymentIdLine.bottom // descriptionLine.bottom anchors.leftMargin: 17 anchors.topMargin: 17 width: 156 @@ -142,10 +156,11 @@ Rectangle { z: 2 } + // DateTo picker Label { id: dateToText anchors.left: dateFromText.right - anchors.top: descriptionLine.bottom + anchors.top: paymentIdLine.bottom //descriptionLine.bottom anchors.leftMargin: 17 anchors.topMargin: 17 text: qsTr("To") @@ -322,10 +337,11 @@ Rectangle { ListModel { id: columnsModel - ListElement { columnName: "Address"; columnWidth: 127 } + + ListElement { columnName: "Payment ID"; columnWidth: 127 } ListElement { columnName: "Date"; columnWidth: 100 } ListElement { columnName: "Amount"; columnWidth: 148 } - ListElement { columnName: "Description"; columnWidth: 148 } + // ListElement { columnName: "Description"; columnWidth: 148 } } TableHeader { @@ -338,7 +354,24 @@ Rectangle { anchors.rightMargin: 14 dataModel: columnsModel offset: 20 - onSortRequest: console.log("column: " + column + " desc: " + desc) + onSortRequest: { + console.log("column: " + column + " desc: " + desc) + switch (column) { + case 0: + // Payment ID + model.sortRole = TransactionHistoryModel.TransactionPaymentIdRole + break; + case 1: + // Date; + model.sortRole = TransactionHistoryModel.TransactionDateRole + break; + case 2: + // Amount; + model.sortRole = TransactionHistoryModel.TransactionAmountRole + break; + } + model.sort(0, desc ? Qt.DescendingOrder : Qt.AscendingOrder) + } } /* ListModel { diff --git a/src/libwalletqt/TransactionInfo.cpp b/src/libwalletqt/TransactionInfo.cpp index 3aa7334c..248fd73e 100644 --- a/src/libwalletqt/TransactionInfo.cpp +++ b/src/libwalletqt/TransactionInfo.cpp @@ -19,7 +19,13 @@ bool TransactionInfo::isFailed() const } -QString TransactionInfo::amount() const +double TransactionInfo::amount() const +{ + // there's no unsigned uint64 for JS, so better use double + return WalletManager::instance()->displayAmount(m_pimpl->amount()).toDouble(); +} + +QString TransactionInfo::displayAmount() const { return WalletManager::instance()->displayAmount(m_pimpl->amount()); } diff --git a/src/libwalletqt/TransactionInfo.h b/src/libwalletqt/TransactionInfo.h index 3381131a..b614dfc8 100644 --- a/src/libwalletqt/TransactionInfo.h +++ b/src/libwalletqt/TransactionInfo.h @@ -11,7 +11,8 @@ class TransactionInfo : public QObject Q_PROPERTY(Direction direction READ direction) Q_PROPERTY(bool isPending READ isPending) Q_PROPERTY(bool isFailed READ isFailed) - Q_PROPERTY(QString amount READ amount) + Q_PROPERTY(double amount READ amount) + Q_PROPERTY(QString displayAmount READ displayAmount) Q_PROPERTY(QString fee READ fee) Q_PROPERTY(quint64 blockHeight READ blockHeight) Q_PROPERTY(QString hash READ hash) @@ -39,7 +40,8 @@ public: Direction direction() const; bool isPending() const; bool isFailed() const; - QString amount() const; + double amount() const; + QString displayAmount() const; QString fee() const; quint64 blockHeight() const; //! transaction_id diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 14e0a868..b52963bc 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -2,6 +2,7 @@ #include "PendingTransaction.h" #include "TransactionHistory.h" #include "model/TransactionHistoryModel.h" +#include "model/TransactionHistorySortFilterModel.h" #include "wallet/wallet2_api.h" #include @@ -213,15 +214,17 @@ TransactionHistory *Wallet::history() const return m_history; } -TransactionHistoryModel *Wallet::historyModel() const +TransactionHistorySortFilterModel *Wallet::historyModel() const { if (!m_historyModel) { Wallet * w = const_cast(this); m_historyModel = new TransactionHistoryModel(w); m_historyModel->setTransactionHistory(this->history()); + m_historySortFilterModel = new TransactionHistorySortFilterModel(w); + m_historySortFilterModel->setSourceModel(m_historyModel); } - return m_historyModel; + return m_historySortFilterModel; } diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 159a08b0..f9bca5a3 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -14,6 +14,7 @@ namespace Bitmonero { class TransactionHistory; class TransactionHistoryModel; +class TransactionHistorySortFilterModel; class Wallet : public QObject { @@ -29,7 +30,7 @@ class Wallet : public QObject Q_PROPERTY(quint64 unlockedBalance READ unlockedBalance) Q_PROPERTY(TransactionHistory * history READ history) Q_PROPERTY(QString paymentId READ paymentId WRITE setPaymentId) - Q_PROPERTY(TransactionHistoryModel * historyModel READ historyModel) + Q_PROPERTY(TransactionHistorySortFilterModel * historyModel READ historyModel) public: @@ -123,7 +124,7 @@ public: TransactionHistory * history() const; //! returns transaction history model - TransactionHistoryModel * historyModel() const; + TransactionHistorySortFilterModel *historyModel() const; //! generate payment id Q_INVOKABLE QString generatePaymentId() const; @@ -165,6 +166,7 @@ private: TransactionHistory * m_history; // Used for UI history view mutable TransactionHistoryModel * m_historyModel; + mutable TransactionHistorySortFilterModel * m_historySortFilterModel; QString m_paymentId; mutable QTime m_daemonBlockChainHeightTime; mutable quint64 m_daemonBlockChainHeight; diff --git a/src/model/TransactionHistoryModel.cpp b/src/model/TransactionHistoryModel.cpp index b8f23f68..1ad17944 100644 --- a/src/model/TransactionHistoryModel.cpp +++ b/src/model/TransactionHistoryModel.cpp @@ -65,6 +65,9 @@ QVariant TransactionHistoryModel::data(const QModelIndex &index, int role) const case TransactionAmountRole: result = tInfo->amount(); break; + case TransactionDisplayAmountRole: + result = tInfo->displayAmount(); + break; case TransactionFeeRole: result = tInfo->fee(); break; @@ -108,6 +111,7 @@ QHash TransactionHistoryModel::roleNames() const roleNames.insert(TransactionPendingRole, "isPending"); roleNames.insert(TransactionFailedRole, "isFailed"); roleNames.insert(TransactionAmountRole, "amount"); + roleNames.insert(TransactionDisplayAmountRole, "displayAmount"); roleNames.insert(TransactionFeeRole, "fee"); roleNames.insert(TransactionBlockHeightRole, "blockHeight"); roleNames.insert(TransactionHashRole, "hash"); diff --git a/src/model/TransactionHistoryModel.h b/src/model/TransactionHistoryModel.h index 96d3ff32..0960ceae 100644 --- a/src/model/TransactionHistoryModel.h +++ b/src/model/TransactionHistoryModel.h @@ -9,6 +9,7 @@ class TransactionInfo; /** * @brief The TransactionHistoryModel class - read-only list model for Transaction History */ + class TransactionHistoryModel : public QAbstractListModel { Q_OBJECT @@ -21,6 +22,7 @@ public: TransactionPendingRole, TransactionFailedRole, TransactionAmountRole, + TransactionDisplayAmountRole, TransactionFeeRole, TransactionBlockHeightRole, TransactionHashRole, @@ -32,10 +34,24 @@ public: TransactionDateRole, TransactionTimeRole }; + Q_ENUM(TransactionInfoRole) TransactionHistoryModel(QObject * parent = 0); void setTransactionHistory(TransactionHistory * th); TransactionHistory * transactionHistory() const; + /** + * @brief dateFrom - returns firstmost transaction datetime + * @return + */ + QDateTime firstDateTime() const; + + /** + * @brief dateTo - returns lastmost transaction datetime + * @return + */ + QDateTime lastDateTime() const; + + /// QAbstractListModel virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; @@ -47,7 +63,6 @@ signals: private: TransactionHistory * m_transactionHistory; - }; #endif // TRANSACTIONHISTORYMODEL_H diff --git a/src/model/TransactionHistorySortFilterModel.cpp b/src/model/TransactionHistorySortFilterModel.cpp index 67d7b84a..946137c6 100644 --- a/src/model/TransactionHistorySortFilterModel.cpp +++ b/src/model/TransactionHistorySortFilterModel.cpp @@ -1,6 +1,66 @@ -#include "TransactionHistorySortFiltrerModel.h" +#include "TransactionHistorySortFilterModel.h" +#include "TransactionHistoryModel.h" -TransactionHistorySortFiltrerModel::TransactionHistorySortFiltrerModel() +#include + +TransactionHistorySortFilterModel::TransactionHistorySortFilterModel(QObject *parent) + : QSortFilterProxyModel(parent) +{ + +} + +QString TransactionHistorySortFilterModel::paymentIdFilter() const { } + +void TransactionHistorySortFilterModel::setPaymentIdFilter(const QString &arg) +{ + +} + +void TransactionHistorySortFilterModel::sort(int column, Qt::SortOrder order) +{ + QSortFilterProxyModel::sort(column, order); +} + +bool TransactionHistorySortFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +{ + + if (source_row < 0 || source_row >= sourceModel()->rowCount()) { + return false; + } + + QModelIndex index = sourceModel()->index(source_row, 0, source_parent); + if (!index.isValid()) { + return false; + } + + bool result = true; + + for (int role : m_filterValues.keys()) { + if (m_filterValues.contains(role)) { + QVariant data = sourceModel()->data(index, role); + result = data.toString().contains(m_filterValues.value(role).toString()); + if (result) + break; + } + } + + return result; +} + +bool TransactionHistorySortFilterModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const +{ + return QSortFilterProxyModel::lessThan(source_left, source_right); +} + +QVariant TransactionHistorySortFilterModel::filterValue(int role) +{ + return m_filterValues.value(role); +} + +void TransactionHistorySortFilterModel::setFilterValue(int role, const QVariant &filterValue) +{ + m_filterValues[role] = filterValue; +} diff --git a/src/model/TransactionHistorySortFilterModel.h b/src/model/TransactionHistorySortFilterModel.h index bdcab079..c1d3d2c2 100644 --- a/src/model/TransactionHistorySortFilterModel.h +++ b/src/model/TransactionHistorySortFilterModel.h @@ -1,12 +1,34 @@ -#ifndef TRANSACTIONHISTORYSORTFILTRERMODEL_H -#define TRANSACTIONHISTORYSORTFILTRERMODEL_H +#ifndef TRANSACTIONHISTORYSORTFILTERMODEL_H +#define TRANSACTIONHISTORYSORTFILTERMODEL_H -#include -class TransactionHistorySortFiltrerModel : public QSortFilterProxyModel +#include +#include +#include + + +class TransactionHistorySortFilterModel: public QSortFilterProxyModel { +Q_OBJECT public: - TransactionHistorySortFiltrerModel(); + TransactionHistorySortFilterModel(QObject * parent = nullptr); + QString paymentIdFilter() const; + void setPaymentIdFilter(const QString &arg); + + + Q_INVOKABLE void sort(int column, Qt::SortOrder order); +protected: + // QSortFilterProxyModel overrides + virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const; + + +private: + QVariant filterValue(int role); + void setFilterValue(int role, const QVariant &filterValue); + +private: + QMap m_filterValues; }; -#endif // TRANSACTIONHISTORYSORTFILTRERMODEL_H \ No newline at end of file +#endif // TRANSACTIONHISTORYSORTFILTERMODEL_H diff --git a/wizard/WizardCreateWallet.qml b/wizard/WizardCreateWallet.qml index f0344a94..8506a8e7 100644 --- a/wizard/WizardCreateWallet.qml +++ b/wizard/WizardCreateWallet.qml @@ -27,7 +27,9 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import QtQuick 2.2 -import moneroComponents 1.0 +import moneroComponents.WalletManager 1.0 +import moneroComponents.Wallet 1.0 + import QtQuick.Dialogs 1.2 import 'utils.js' as Utils diff --git a/wizard/WizardManageWalletUI.qml b/wizard/WizardManageWalletUI.qml index cc8a5be3..ede68b13 100644 --- a/wizard/WizardManageWalletUI.qml +++ b/wizard/WizardManageWalletUI.qml @@ -27,7 +27,7 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import QtQuick 2.2 -import moneroComponents 1.0 +import moneroComponents.TranslationManager 1.0 import QtQuick.Dialogs 1.2 // Reusable component for managing wallet (account name, path, private key) -- cgit v1.2.3