From 13ee9b1f26831b208b33bb977d0fdda61bfec452 Mon Sep 17 00:00:00 2001 From: xiphon Date: Tue, 14 Jul 2020 01:45:34 +0000 Subject: [PATCH] KeysFiles: fix WalletKeysFilesModel, should be instantiable QML type --- src/main/main.cpp | 9 +-------- src/qt/KeysFiles.cpp | 8 +++----- src/qt/KeysFiles.h | 10 ++++++++-- wizard/WizardOpenWallet1.qml | 9 +++++++-- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/main.cpp b/src/main/main.cpp index 41b41faa..b17c0e19 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -354,6 +354,7 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw // registering types for QML qmlRegisterType("moneroComponents.Clipboard", 1, 0, "Clipboard"); qmlRegisterType("moneroComponents.Downloader", 1, 0, "Downloader"); + qmlRegisterType("moneroComponents.WalletKeysFilesModel", 1, 0, "WalletKeysFilesModel"); // Temporary Qt.labs.settings replacement qmlRegisterType("moneroComponents.Settings", 1, 0, "MoneroSettings"); @@ -373,9 +374,6 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw qmlRegisterUncreatableType("moneroComponents.TranslationManager", 1, 0, "TranslationManager", "TranslationManager can't be instantiated directly"); - qmlRegisterUncreatableType("moneroComponents.walletKeysFilesModel", 1, 0, "WalletKeysFilesModel", - "walletKeysFilesModel can't be instantiated directly"); - qmlRegisterUncreatableType("moneroComponents.TransactionHistoryModel", 1, 0, "TransactionHistoryModel", "TransactionHistoryModel can't be instantiated directly"); @@ -475,11 +473,6 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw engine.rootContext()->setContextProperty("desktopFolder", desktopFolder); #endif - // Wallet .keys files model (wizard -> open wallet) - WalletKeysFilesModel walletKeysFilesModel; - engine.rootContext()->setContextProperty("walletKeysFilesModel", &walletKeysFilesModel); - engine.rootContext()->setContextProperty("walletKeysFilesModelProxy", &walletKeysFilesModel.proxyModel()); - // Get default account name QString accountName = qgetenv("USER"); // mac/linux if (accountName.isEmpty()) diff --git a/src/qt/KeysFiles.cpp b/src/qt/KeysFiles.cpp index 15f7c6eb..dfd17c40 100644 --- a/src/qt/KeysFiles.cpp +++ b/src/qt/KeysFiles.cpp @@ -81,17 +81,15 @@ quint8 WalletKeysFiles::networkType() const WalletKeysFilesModel::WalletKeysFilesModel(QObject *parent) : QAbstractListModel(parent) { - this->m_walletKeysFilesItemModel = qobject_cast(this); - - this->m_walletKeysFilesModelProxy.setSourceModel(this->m_walletKeysFilesItemModel); + this->m_walletKeysFilesModelProxy.setSourceModel(this); this->m_walletKeysFilesModelProxy.setSortRole(WalletKeysFilesModel::ModifiedRole); this->m_walletKeysFilesModelProxy.setDynamicSortFilter(true); this->m_walletKeysFilesModelProxy.sort(0, Qt::DescendingOrder); } -QSortFilterProxyModel &WalletKeysFilesModel::proxyModel() +QSortFilterProxyModel *WalletKeysFilesModel::proxyModel() { - return m_walletKeysFilesModelProxy; + return &m_walletKeysFilesModelProxy; } void WalletKeysFilesModel::clear() diff --git a/src/qt/KeysFiles.h b/src/qt/KeysFiles.h index a8a0dbe2..610c3c3a 100644 --- a/src/qt/KeysFiles.h +++ b/src/qt/KeysFiles.h @@ -56,6 +56,8 @@ private: class WalletKeysFilesModel : public QAbstractListModel { Q_OBJECT + Q_PROPERTY(QSortFilterProxyModel *proxyModel READ proxyModel NOTIFY proxyModelChanged) + public: enum KeysFilesRoles { FileNameRole = Qt::UserRole + 1, @@ -74,16 +76,20 @@ public: void addWalletKeysFile(const WalletKeysFiles &walletKeysFile); int rowCount(const QModelIndex & parent = QModelIndex()) const; - QSortFilterProxyModel &proxyModel(); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QHash roleNames() const; +private: + QSortFilterProxyModel *proxyModel(); + protected: +signals: + void proxyModelChanged() const; + private: QList m_walletKeyFiles; - QAbstractItemModel *m_walletKeysFilesItemModel; QSortFilterProxyModel m_walletKeysFilesModelProxy; }; diff --git a/wizard/WizardOpenWallet1.qml b/wizard/WizardOpenWallet1.qml index 85bc48d7..9385b88b 100644 --- a/wizard/WizardOpenWallet1.qml +++ b/wizard/WizardOpenWallet1.qml @@ -33,6 +33,7 @@ import QtQuick.Controls 2.0 import QtGraphicalEffects 1.0 import Qt.labs.folderlistmodel 2.1 import moneroComponents.NetworkType 1.0 +import moneroComponents.WalletKeysFilesModel 1.0 import "../js/Wizard.js" as Wizard import "../components" @@ -45,7 +46,11 @@ Rectangle { color: "transparent" property alias pageHeight: pageRoot.height property string viewName: "wizardOpenWallet1" - property int walletCount: walletKeysFilesModel ? walletKeysFilesModel.rowCount() : 0 + property int walletCount: walletKeysFilesModel.rowCount() + + WalletKeysFilesModel { + id: walletKeysFilesModel + } ColumnLayout { id: pageRoot @@ -112,7 +117,7 @@ Rectangle { Repeater { id: recentList clip: true - model: walletKeysFilesModelProxy + model: walletKeysFilesModel.proxyModel Layout.fillWidth: true Layout.minimumWidth: flow.itemHeight Layout.preferredHeight: parent.height