Notify change in tags when maxTags set in filetagmodel
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 25 Apr 2023 03:44:47 +0000 (11:44 +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 a9bd35bbda825f8e0ac343b1369d7c2af534e3a4..5927ffcd4a1f4d49070b03ee785c3c821cfb371e 100644 (file)
@@ -164,7 +164,22 @@ void FileTagModel::setMaxTags(const int maxTags)
         return;
     }
 
+    const auto totalTagCount = totalTags();
+    const auto tagsWillBeTruncated = maxTags < totalTagCount;
+
+    // Summary tag will be after the last tag
+    const auto notifyOverflowingTagsRemoved = tagsWillBeTruncated && totalTagCount > maxTags;
+
+    if (notifyOverflowingTagsRemoved) {
+        beginResetModel();
+    }
+
     _maxTags = maxTags;
+
+    if (notifyOverflowingTagsRemoved) {
+        endResetModel();
+    }
+
     Q_EMIT maxTagsChanged();
 }
 
index d0f41f6cbd8a15815f2c67544f82bd8685fada72..ac82b20a549f329f23bf9de028daf0f8928159cd 100644 (file)
@@ -67,7 +67,6 @@ private:
     QStringList _tags;
 
     int _maxTags = 0;
-    int _totalTags = 0;
 };
 
 }