Utils: Add StringAspect::{append,remove}Value{,s} convenience functions

Change-Id: I3893d9512b7600328e127693da9dc07c771b305a
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2021-03-01 08:48:25 +01:00
parent 60a9529485
commit e6fe923392
2 changed files with 37 additions and 0 deletions

View File

@@ -1703,6 +1703,38 @@ void StringListAspect::setValue(const QStringList &value)
BaseAspect::setValue(value); BaseAspect::setValue(value);
} }
void StringListAspect::appendValue(const QString &s, bool allowDuplicates)
{
QStringList val = value();
if (allowDuplicates || !val.contains(s))
val.append(s);
setValue(val);
}
void StringListAspect::removeValue(const QString &s)
{
QStringList val = value();
val.removeAll(s);
setValue(val);
}
void StringListAspect::appendValues(const QStringList &values, bool allowDuplicates)
{
QStringList val = value();
for (const QString &s : values) {
if (allowDuplicates || !val.contains(s))
val.append(s);
}
setValue(val);
}
void StringListAspect::removeValues(const QStringList &values)
{
QStringList val = value();
for (const QString &s : values)
val.removeAll(s);
setValue(val);
}
/*! /*!
\class Utils::TextDisplay \class Utils::TextDisplay

View File

@@ -428,6 +428,11 @@ public:
QStringList value() const; QStringList value() const;
void setValue(const QStringList &val); void setValue(const QStringList &val);
void appendValue(const QString &value, bool allowDuplicates = true);
void removeValue(const QString &value);
void appendValues(const QStringList &values, bool allowDuplicates = true);
void removeValues(const QStringList &values);
private: private:
std::unique_ptr<Internal::StringListAspectPrivate> d; std::unique_ptr<Internal::StringListAspectPrivate> d;
}; };