KeysFiles: fix WalletKeysFilesModel, should be instantiable QML type

This commit is contained in:
xiphon 2020-07-14 01:45:34 +00:00
parent c137a6ea36
commit 13ee9b1f26
4 changed files with 19 additions and 17 deletions

View file

@ -354,6 +354,7 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw
// registering types for QML
qmlRegisterType<clipboardAdapter>("moneroComponents.Clipboard", 1, 0, "Clipboard");
qmlRegisterType<Downloader>("moneroComponents.Downloader", 1, 0, "Downloader");
qmlRegisterType<WalletKeysFilesModel>("moneroComponents.WalletKeysFilesModel", 1, 0, "WalletKeysFilesModel");
// Temporary Qt.labs.settings replacement
qmlRegisterType<MoneroSettings>("moneroComponents.Settings", 1, 0, "MoneroSettings");
@ -373,9 +374,6 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw
qmlRegisterUncreatableType<TranslationManager>("moneroComponents.TranslationManager", 1, 0, "TranslationManager",
"TranslationManager can't be instantiated directly");
qmlRegisterUncreatableType<WalletKeysFilesModel>("moneroComponents.walletKeysFilesModel", 1, 0, "WalletKeysFilesModel",
"walletKeysFilesModel can't be instantiated directly");
qmlRegisterUncreatableType<TransactionHistoryModel>("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())

View file

@ -81,17 +81,15 @@ quint8 WalletKeysFiles::networkType() const
WalletKeysFilesModel::WalletKeysFilesModel(QObject *parent)
: QAbstractListModel(parent)
{
this->m_walletKeysFilesItemModel = qobject_cast<QAbstractItemModel *>(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()

View file

@ -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<int, QByteArray> roleNames() const;
private:
QSortFilterProxyModel *proxyModel();
protected:
signals:
void proxyModelChanged() const;
private:
QList<WalletKeysFiles> m_walletKeyFiles;
QAbstractItemModel *m_walletKeysFilesItemModel;
QSortFilterProxyModel m_walletKeysFilesModelProxy;
};

View file

@ -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