diff --git a/src/libclient/brushes/brushpresetmodel.cpp b/src/libclient/brushes/brushpresetmodel.cpp index 711f2c1179..dd8c7df3a1 100644 --- a/src/libclient/brushes/brushpresetmodel.cpp +++ b/src/libclient/brushes/brushpresetmodel.cpp @@ -51,7 +51,7 @@ struct CachedTag { }; struct CachedPreset : Preset { - QVector tagIds; + QSet tagIds; }; struct PresetChange { @@ -755,7 +755,7 @@ class BrushPresetTagModel::Private { return s.isNull() ? QStringLiteral("") : s; } - static void parseGroupedTagIds(const QString &input, QVector &tagIds) + static void parseGroupedTagIds(const QString &input, QSet &tagIds) { QStringList tagIdStrings = input.split(QChar(','), compat::SkipEmptyParts); @@ -764,7 +764,7 @@ class BrushPresetTagModel::Private { bool ok; int tagId = tagIdString.toInt(&ok); if(ok && tagId > 0) { - tagIds.append(tagId); + tagIds.insert(tagId); } } } @@ -1136,7 +1136,7 @@ class BrushPresetTagModel::Private { int m_tagIdToFilter = -1; }; -bool Tag::accepts(const QVector &tagIds) const +bool Tag::accepts(const QSet &tagIds) const { switch(id) { case ALL_ID: @@ -2209,7 +2209,7 @@ QList BrushPresetModel::getTagAssignments(int presetId) if(i == -1) { return d->readTagAssignmentsByPresetId(presetId); } else { - const QVector assignedTagIds = d->getCachedPreset(i).tagIds; + const QSet assignedTagIds = d->getCachedPreset(i).tagIds; QList tagAssignments; int tagCount = d->tagCacheSize(); for(int j = 0; j < tagCount; ++j) { @@ -2255,6 +2255,16 @@ bool BrushPresetModel::changeTagAssignment( int tagIdToFilter = d->tagIdToFilter(); switch(tagIdToFilter) { case ALL_ID: + if(int i = d->getCachedPresetIndexById(presetId); i != -1) { + CachedPreset &cp = d->getCachedPreset(i); + if(assigned) { + cp.tagIds.insert(tagId); + } else { + cp.tagIds.remove(tagId); + } + QModelIndex idx = index(i); + emit dataChanged(idx, idx); + } break; case UNTAGGED_ID: if(assigned) { @@ -2277,6 +2287,15 @@ bool BrushPresetModel::changeTagAssignment( beginRemoveRows(QModelIndex(), i, i); d->removeCachedPreset(i); endRemoveRows(); + } else { + CachedPreset &cp = d->getCachedPreset(i); + if(assigned) { + cp.tagIds.insert(tagId); + } else { + cp.tagIds.remove(tagId); + } + QModelIndex idx = index(i); + emit dataChanged(idx, idx); } } break; diff --git a/src/libclient/brushes/brushpresetmodel.h b/src/libclient/brushes/brushpresetmodel.h index 5bd9814814..9a33a38cc9 100644 --- a/src/libclient/brushes/brushpresetmodel.h +++ b/src/libclient/brushes/brushpresetmodel.h @@ -29,7 +29,7 @@ struct Tag { bool isAssignable() const { return id > 0; } bool isEditable() const { return id > 0; } - bool accepts(const QVector &tagIds) const; + bool accepts(const QSet &tagIds) const; }; struct TagAssignment { @@ -83,7 +83,7 @@ struct ShortcutPreset { QString name; QPixmap thumbnail; QKeySequence shortcut; - QVector tagIds; + QSet tagIds; }; struct PresetMetadata { diff --git a/src/libclient/utils/brushshortcutmodel.cpp b/src/libclient/utils/brushshortcutmodel.cpp index a8db1c2aa0..5b99a5b1f0 100644 --- a/src/libclient/utils/brushshortcutmodel.cpp +++ b/src/libclient/utils/brushshortcutmodel.cpp @@ -178,7 +178,7 @@ const QKeySequence &BrushShortcutModel::shortcutAt(int row) return m_presets[row].shortcut; } -const QVector &BrushShortcutModel::tagIdsAt(int row) +const QSet &BrushShortcutModel::tagIdsAt(int row) { Q_ASSERT(row >= 0); Q_ASSERT(row < m_presets.size()); diff --git a/src/libclient/utils/brushshortcutmodel.h b/src/libclient/utils/brushshortcutmodel.h index ad0efa0eba..ba31a6a750 100644 --- a/src/libclient/utils/brushshortcutmodel.h +++ b/src/libclient/utils/brushshortcutmodel.h @@ -39,7 +39,7 @@ class BrushShortcutModel final : public QAbstractTableModel { Qt::ItemFlags flags(const QModelIndex &index) const override; const QKeySequence &shortcutAt(int row); - const QVector &tagIdsAt(int row); + const QSet &tagIdsAt(int row); QModelIndex indexById(int presetId, int column = 0) const;