From 213e3743e19d4845ff3f032f54200c32fb489779 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 11 Apr 2023 23:34:39 +0800 Subject: [PATCH] Expose account and serverRelativePath of FileTagModel as QPROPERTYs Signed-off-by: Claudio Cambra --- src/gui/filetagmodel.cpp | 43 ++++++++++++++++++++++++++++++++++++++++ src/gui/filetagmodel.h | 17 ++++++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/gui/filetagmodel.cpp b/src/gui/filetagmodel.cpp index 2000d2392..3f49032de 100644 --- a/src/gui/filetagmodel.cpp +++ b/src/gui/filetagmodel.cpp @@ -92,4 +92,47 @@ void FileTagModel::processFileTagRequestFinishedWithError() qCWarning(lcFileTagModel) << "File tag fetch request job ended with error."; } +void FileTagModel::resetForNewFile() +{ + beginResetModel(); + _tags.clear(); + endResetModel(); + + fetchFileTags(); +} + +QString FileTagModel::serverRelativePath() const +{ + return _serverRelativePath; +} + +void FileTagModel::setServerRelativePath(const QString &serverRelativePath) +{ + if (_serverRelativePath == serverRelativePath) { + return; + } + + _serverRelativePath = serverRelativePath; + Q_EMIT serverRelativePathChanged(); + + resetForNewFile(); +} + +AccountPtr FileTagModel::account() const +{ + return _account; +} + +void FileTagModel::setAccount(const AccountPtr &account) +{ + if (_account == account) { + return; + } + + _account = account; + Q_EMIT accountChanged(); + + resetForNewFile(); +} + } diff --git a/src/gui/filetagmodel.h b/src/gui/filetagmodel.h index 3808ba65d..918c50cd1 100644 --- a/src/gui/filetagmodel.h +++ b/src/gui/filetagmodel.h @@ -24,14 +24,27 @@ class FileTagModel : public QAbstractListModel { Q_OBJECT + Q_PROPERTY(QString serverRelativePath READ serverRelativePath WRITE setServerRelativePath NOTIFY serverRelativePathChanged) + Q_PROPERTY(AccountPtr account READ account WRITE setAccount NOTIFY accountChanged) public: explicit FileTagModel(const QString &serverRelativePath, const AccountPtr &account, QObject * const parent = nullptr); - // Basic functionality: [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; - [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + [[nodiscard]] QString serverRelativePath() const; + [[nodiscard]] AccountPtr account() const; + +signals: + void serverRelativePathChanged(); + void accountChanged(); + +public slots: + void setServerRelativePath(const QString &serverRelativePath); + void setAccount(const OCC::AccountPtr &account); + + void resetForNewFile(); + private slots: void fetchFileTags(); void processFileTagRequestFinished(const QVariantMap &result); -- 2.30.2