From: Claudio Cambra Date: Thu, 27 Apr 2023 13:23:40 +0000 (+0800) Subject: Add overflow tag string property to filetagmodel which stringifies omitted tags X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~10^2~49^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=30830b44ccd97049d4a15037105f0428c349a410;p=nextcloud-desktop.git Add overflow tag string property to filetagmodel which stringifies omitted tags Signed-off-by: Claudio Cambra --- diff --git a/src/gui/filetagmodel.cpp b/src/gui/filetagmodel.cpp index 5927ffcd4..64cab4486 100644 --- a/src/gui/filetagmodel.cpp +++ b/src/gui/filetagmodel.cpp @@ -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 diff --git a/src/gui/filetagmodel.h b/src/gui/filetagmodel.h index ac82b20a5..618702e8b 100644 --- a/src/gui/filetagmodel.h +++ b/src/gui/filetagmodel.h @@ -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; }; }