From: Claudio Cambra Date: Tue, 11 Apr 2023 15:43:59 +0000 (+0800) Subject: Add ability to limit maximum amount of tags displayed X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~10^2~49^2~24 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c6d29e7d77c00bc4797568b541e1918bcd57fb99;p=nextcloud-desktop.git Add ability to limit maximum amount of tags displayed Signed-off-by: Claudio Cambra --- diff --git a/src/gui/filetagmodel.cpp b/src/gui/filetagmodel.cpp index 3f49032de..4f00e41f2 100644 --- a/src/gui/filetagmodel.cpp +++ b/src/gui/filetagmodel.cpp @@ -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(); +} + } diff --git a/src/gui/filetagmodel.h b/src/gui/filetagmodel.h index 918c50cd1..d0f41f6cb 100644 --- a/src/gui/filetagmodel.h +++ b/src/gui/filetagmodel.h @@ -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; }; }