Utils: Let registered aspects know about their containers

Will help to set up macroexpanders with less boiler plate.

Change-Id: I521af3dc9d49524cf855e82eecc0132d1bcc40db
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-07-10 17:27:47 +02:00
parent 6346952380
commit e1ca7cf53f
2 changed files with 11 additions and 1 deletions

View File

@@ -52,6 +52,8 @@ namespace Internal {
class BaseAspectPrivate
{
public:
explicit BaseAspectPrivate(AspectContainer *container) : m_container(container) {}
Id m_id;
std::function<QVariant(const QVariant &)> m_toSettings;
std::function<QVariant(const QVariant &)> m_fromSettings;
@@ -64,6 +66,7 @@ public:
QIcon m_icon;
QPointer<QLabel> m_label; // Owned by configuration widget
QPointer<QAction> m_action; // Owned by us.
AspectContainer *m_container = nullptr; // Not owned by us.
bool m_visible = true;
bool m_enabled = true;
@@ -106,7 +109,7 @@ public:
If \a container is non-null, the aspect is made known to the container.
*/
BaseAspect::BaseAspect(AspectContainer *container)
: d(new Internal::BaseAspectPrivate)
: d(new Internal::BaseAspectPrivate(container))
{
if (container)
container->registerAspect(this);
@@ -438,6 +441,11 @@ QAction *BaseAspect::action()
return d->m_action;
}
AspectContainer *BaseAspect::container() const
{
return d->m_container;
}
/*!
Adds the visual representation of this aspect to the layout with the
specified \a parent using a layout builder.

View File

@@ -94,6 +94,8 @@ public:
virtual QAction *action();
AspectContainer *container() const;
virtual void fromMap(const QVariantMap &map);
virtual void toMap(QVariantMap &map) const;
virtual void toActiveMap(QVariantMap &map) const { toMap(map); }