Add overflow tag string property to filetagmodel which stringifies omitted tags
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 27 Apr 2023 13:23:40 +0000 (21:23 +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 5927ffcd4a1f4d49070b03ee785c3c821cfb371e..64cab4486a4f98ce6c925910c986e94cfffad401 100644 (file)
@@ -101,6 +101,7 @@ void FileTagModel::processFileTagRequestFinished(const QVariantMap &result)
     _tags << normalTags << systemTagStringList;
 
     Q_EMIT totalTagsChanged();
+    updateOverflowTagsString();
     endResetModel();
 }
 
@@ -181,6 +182,25 @@ void FileTagModel::setMaxTags(const int maxTags)
     }
 
     Q_EMIT maxTagsChanged();
+    updateOverflowTagsString();
+}
+
+QString FileTagModel::overflowTagsString() const
+{
+    return _overflowTagsString;
+}
+
+void FileTagModel::updateOverflowTagsString()
+{
+    if (totalTags() <= _maxTags) {
+        _overflowTagsString = "";
+    } else {
+        const auto overflowingTags = _tags.mid(_maxTags + 1);
+        _overflowTagsString = overflowingTags.join(", ");
+    }
+
+    qDebug() << _overflowTagsString;
+    Q_EMIT overflowTagsStringChanged();
 }
 
 int FileTagModel::totalTags() const
index ac82b20a549f329f23bf9de028daf0f8928159cd..618702e8b5b09d802dfd4f24a71081bc7b7369b1 100644 (file)
@@ -28,6 +28,7 @@ class FileTagModel : public QAbstractListModel
     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)
+    Q_PROPERTY(QString overflowTagsString READ overflowTagsString NOTIFY overflowTagsStringChanged)
 
 public:
     explicit FileTagModel(const QString &serverRelativePath, const AccountPtr &account, QObject * const parent = nullptr);
@@ -41,18 +42,22 @@ public:
     [[nodiscard]] int maxTags() const;
     [[nodiscard]] int totalTags() const;
 
+    [[nodiscard]] QString overflowTagsString() const;
+
 signals:
     void serverRelativePathChanged();
     void accountChanged();
 
     void maxTagsChanged();
     void totalTagsChanged();
+    void overflowTagsStringChanged();
 
 public slots:
     void setServerRelativePath(const QString &serverRelativePath);
     void setAccount(const OCC::AccountPtr &account);
 
     void setMaxTags(const int maxTags);
+    void updateOverflowTagsString();
 
     void resetForNewFile();
 
@@ -67,6 +72,7 @@ private:
     QStringList _tags;
 
     int _maxTags = 0;
+    QString _overflowTagsString;
 };
 
 }