forked from qt-creator/qt-creator
ProjectExplorer: Introduce an AspectContainer class
For further use in conglomerates like OverrideMakeFlagAspect. Change-Id: I845ff085d15779e43431ab3858c5c1b55824f694 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -150,6 +150,12 @@ public:
|
||||
QStringList m_value;
|
||||
};
|
||||
|
||||
class AspectContainerPrivate
|
||||
{
|
||||
public:
|
||||
QList<ProjectConfigurationAspect *> m_items;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
|
||||
/*!
|
||||
@@ -870,4 +876,39 @@ void StringListAspect::setValue(const QStringList &value)
|
||||
d->m_value = value;
|
||||
}
|
||||
|
||||
/*!
|
||||
\class ProjectExplorer::AspectContainer
|
||||
*/
|
||||
|
||||
AspectContainer::AspectContainer()
|
||||
: d(new Internal::AspectContainerPrivate)
|
||||
{}
|
||||
|
||||
AspectContainer::~AspectContainer() = default;
|
||||
|
||||
void AspectContainer::addAspectHelper(ProjectConfigurationAspect *aspect)
|
||||
{
|
||||
d->m_items.append(aspect);
|
||||
}
|
||||
|
||||
void AspectContainer::addToLayout(LayoutBuilder &builder)
|
||||
{
|
||||
for (ProjectConfigurationAspect *aspect : d->m_items) {
|
||||
if (aspect->isVisible())
|
||||
aspect->addToLayout(builder);
|
||||
}
|
||||
}
|
||||
|
||||
void AspectContainer::fromMap(const QVariantMap &map)
|
||||
{
|
||||
for (ProjectConfigurationAspect *aspect : d->m_items)
|
||||
aspect->fromMap(map);
|
||||
}
|
||||
|
||||
void AspectContainer::toMap(QVariantMap &map) const
|
||||
{
|
||||
for (ProjectConfigurationAspect *aspect : d->m_items)
|
||||
aspect->toMap(map);
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -37,6 +37,7 @@
|
||||
namespace ProjectExplorer {
|
||||
|
||||
namespace Internal {
|
||||
class AspectContainerPrivate;
|
||||
class BoolAspectPrivate;
|
||||
class IntegerAspectPrivate;
|
||||
class SelectionAspectPrivate;
|
||||
@@ -256,6 +257,33 @@ private:
|
||||
std::unique_ptr<Internal::StringListAspectPrivate> d;
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT AspectContainer : public ProjectConfigurationAspect
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AspectContainer();
|
||||
~AspectContainer() override;
|
||||
|
||||
template <class Aspect, typename ...Args>
|
||||
Aspect *addAspect(Args && ...args)
|
||||
{
|
||||
auto aspect = new Aspect(args...);
|
||||
addAspectHelper(aspect);
|
||||
return aspect;
|
||||
}
|
||||
|
||||
void addToLayout(LayoutBuilder &builder) override;
|
||||
|
||||
void fromMap(const QVariantMap &map) override;
|
||||
void toMap(QVariantMap &map) const override;
|
||||
|
||||
private:
|
||||
void addAspectHelper(ProjectConfigurationAspect *aspect);
|
||||
|
||||
std::unique_ptr<Internal::AspectContainerPrivate> d;
|
||||
};
|
||||
|
||||
// FIXME: For migration. Remove after 4.15
|
||||
using BaseBoolAspect = BoolAspect;
|
||||
using BaseIntegerAspect = IntegerAspect;
|
||||
|
Reference in New Issue
Block a user