forked from qt-creator/qt-creator
Utils: Introduce a few AspectContainer convenience functions
Change-Id: I89832ab1971d263e4db9b8be5e89d581fd598b41 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -2078,6 +2078,40 @@ void AspectContainer::finish()
|
|||||||
aspect->finish();
|
aspect->finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AspectContainer::reset()
|
||||||
|
{
|
||||||
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
||||||
|
aspect->setValueQuietly(aspect->defaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
void AspectContainer::fromMap(const QString &prefix, const QVariantMap &map)
|
||||||
|
{
|
||||||
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
||||||
|
aspect->setValue(map.value(prefix + aspect->settingsKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AspectContainer::toMap(const QString &prefix, QVariantMap &map) const
|
||||||
|
{
|
||||||
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
||||||
|
map.insert(prefix + aspect->settingsKey(), aspect->value());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AspectContainer::equals(const AspectContainer &other) const
|
||||||
|
{
|
||||||
|
// FIXME: Expensive, but should not really be needed in a fully aspectified world.
|
||||||
|
QVariantMap thisMap, thatMap;
|
||||||
|
toMap(thisMap);
|
||||||
|
other.toMap(thatMap);
|
||||||
|
return thisMap == thatMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AspectContainer::copyFrom(const AspectContainer &other)
|
||||||
|
{
|
||||||
|
QVariantMap map;
|
||||||
|
other.toMap(map);
|
||||||
|
fromMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
void AspectContainer::forEachAspect(const std::function<void(BaseAspect *)> &run) const
|
void AspectContainer::forEachAspect(const std::function<void(BaseAspect *)> &run) const
|
||||||
{
|
{
|
||||||
for (BaseAspect *aspect : qAsConst(d->m_items)) {
|
for (BaseAspect *aspect : qAsConst(d->m_items)) {
|
||||||
|
@@ -533,6 +533,12 @@ public:
|
|||||||
void cancel() override;
|
void cancel() override;
|
||||||
void finish() override;
|
void finish() override;
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
void fromMap(const QString &prefix, const QVariantMap &map);
|
||||||
|
void toMap(const QString &prefix, QVariantMap &map) const;
|
||||||
|
bool equals(const AspectContainer &other) const;
|
||||||
|
void copyFrom(const AspectContainer &other);
|
||||||
|
|
||||||
void forEachAspect(const std::function<void(BaseAspect *)> &run) const;
|
void forEachAspect(const std::function<void(BaseAspect *)> &run) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user