Expose account and serverRelativePath of FileTagModel as QPROPERTYs
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 11 Apr 2023 15:34:39 +0000 (23:34 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 16 May 2023 10:23:33 +0000 (18:23 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/filetagmodel.cpp
src/gui/filetagmodel.h

index 2000d239246c3a5e612e1749f6290cd5e64da928..3f49032de146dfe787a9d41a603237242a6fc778 100644 (file)
@@ -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();
+}
+
 }
index 3808ba65d6f44d4dbdf2e7578e65ccc5711bf3e1..918c50cd1bed2bcdf5de4910bc0b817913087e50 100644 (file)
@@ -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);