Add ability to limit maximum amount of tags displayed
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 11 Apr 2023 15:43:59 +0000 (23:43 +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 3f49032de146dfe787a9d41a603237242a6fc778..4f00e41f2a26c6e79eb178a298d4c3f5dbfb44c6 100644 (file)
@@ -34,9 +34,11 @@ int FileTagModel::rowCount(const QModelIndex &parent) const
 {
     if (parent.isValid()) {
         return 0;
+    } else if (_maxTags <= 0) {
+        return totalTags();
+    } else {
+        return qMin(totalTags(), maxTags());
     }
-
-    return _tags.count();
 }
 
 QVariant FileTagModel::data(const QModelIndex &index, int role) const
@@ -84,6 +86,7 @@ void FileTagModel::processFileTagRequestFinished(const QVariantMap &result)
 
     beginResetModel();
     _tags = result.value(QStringLiteral("tags")).toStringList();
+    Q_EMIT totalTagsChanged();
     endResetModel();
 }
 
@@ -96,6 +99,7 @@ void FileTagModel::resetForNewFile()
 {
     beginResetModel();
     _tags.clear();
+    Q_EMIT totalTagsChanged();
     endResetModel();
 
     fetchFileTags();
@@ -135,4 +139,24 @@ void FileTagModel::setAccount(const AccountPtr &account)
     resetForNewFile();
 }
 
+int FileTagModel::maxTags() const
+{
+    return _maxTags;
+}
+
+void FileTagModel::setMaxTags(const int maxTags)
+{
+    if (_maxTags == maxTags) {
+        return;
+    }
+
+    _maxTags = maxTags;
+    Q_EMIT maxTagsChanged();
+}
+
+int FileTagModel::totalTags() const
+{
+    return _tags.count();
+}
+
 }
index 918c50cd1bed2bcdf5de4910bc0b817913087e50..d0f41f6cbd8a15815f2c67544f82bd8685fada72 100644 (file)
@@ -26,6 +26,9 @@ class FileTagModel : public QAbstractListModel
 
     Q_PROPERTY(QString serverRelativePath READ serverRelativePath WRITE setServerRelativePath NOTIFY serverRelativePathChanged)
     Q_PROPERTY(AccountPtr account READ account WRITE setAccount NOTIFY accountChanged)
+    Q_PROPERTY(int maxTags READ maxTags WRITE setMaxTags NOTIFY maxTagsChanged)
+    Q_PROPERTY(int totalTags READ totalTags NOTIFY totalTagsChanged)
+
 public:
     explicit FileTagModel(const QString &serverRelativePath, const AccountPtr &account, QObject * const parent = nullptr);
 
@@ -35,14 +38,22 @@ public:
     [[nodiscard]] QString serverRelativePath() const;
     [[nodiscard]] AccountPtr account() const;
 
+    [[nodiscard]] int maxTags() const;
+    [[nodiscard]] int totalTags() const;
+
 signals:
     void serverRelativePathChanged();
     void accountChanged();
 
+    void maxTagsChanged();
+    void totalTagsChanged();
+
 public slots:
     void setServerRelativePath(const QString &serverRelativePath);
     void setAccount(const OCC::AccountPtr &account);
 
+    void setMaxTags(const int maxTags);
+
     void resetForNewFile();
 
 private slots:
@@ -54,6 +65,9 @@ private:
     QString _serverRelativePath;
     AccountPtr _account;
     QStringList _tags;
+
+    int _maxTags = 0;
+    int _totalTags = 0;
 };
 
 }