- Extending Qt Creator Manual
- QtCreator
- BaseAspect
- Extending Qt Creator Manual 14.0.2

# BaseAspect Class

class Utils::BaseAspect

The `BaseAspect` class provides a common base for classes implementing aspects. More...

Header: | `#include <BaseAspect>`
Inherited By: | Utils::AspectContainer, Utils::TextDisplay, and Utils::TypedAspect

- List of all members, including inherited members

## Public Types

enum | Announcement { DoEmit, BeQuiet }

## Public Functions

| BaseAspect(Utils::AspectContainer *container = nullptr)
virtual | ~BaseAspect() override
virtual void | addToLayout(Layouting::Layout &parent)
virtual void | apply()
virtual void | cancel()
QString | displayName() const
virtual void | fromMap(const Utils::Store &map)
QString | labelText() const
virtual void | setAutoApply(bool on)
void | setEnabler(Utils::BoolAspect *checker)
void | setLabelPixmap(const QPixmap &labelPixmap)
void | setLabelText(const QString &labelText)
void | setSettingsKey(const Utils::Key &key)
void | setSettingsKey(const Utils::Key &group, const Utils::Key &key)
void | setToolTip(const QString &tooltip)
virtual void | setVariantValue(const QVariant &value, Utils::BaseAspect::Announcement howToAnnounce = DoEmit)
void | setVisible(bool visible)
Utils::Key | settingsKey() const
virtual void | toMap(Utils::Store &map) const
void | writeToSettingsImmediatly() const

## Detailed Description

An aspect is a hunk of data like a property or collection of related properties of some object, together with a description of its behavior for common operations like visualizing or persisting.

Simple aspects are, for example, a boolean property represented by a QCheckBox in the user interface, or a string property represented by a PathChooser, for selecting directories in the filesystem.

While aspects implementations usually can visualize and persist their data, or use an ID, neither of these is mandatory.

The derived classes can implement addToLayout() to create a UI.

Implement `guiToBuffer()` and `bufferToGui()` to synchronize the UI with the internal data.

## Member Type Documentation

### enum BaseAspect::Announcement

Whether to emit a signal when a value changes.

Constant | Value | Description
--- | --- | ---
`Utils::BaseAspect::DoEmit` | `0` | Emit a signal.
`Utils::BaseAspect::BeQuiet` | `1` | Don't emit a signal.

## Member Function Documentation

### BaseAspect::BaseAspect(Utils::AspectContainer *container = nullptr)

Constructs a base aspect.

If container is non-null, the aspect is made known to the container.

### `[override virtual noexcept]` BaseAspect::~BaseAspect()

Destructs a BaseAspect.

### `[virtual]` void BaseAspect::addToLayout(Layouting::Layout &parent)

Adds the visual representation of this aspect to the layout with the specified parent using a layout builder.

### `[virtual]` void BaseAspect::apply()

Updates this aspect's value from user-initiated changes in the widget.

Emits changed() if the value changed.

### `[virtual]` void BaseAspect::cancel()

Discard user changes in the widget and restore widget contents from aspect's value.

This has only an effect if `isAutoApply` is false.

### QString BaseAspect::displayName() const

Returns the string that should be used when this action appears in menus or other places that are typically used with Book style capitalization.

If no display name is set, the label text will be used as fallback.

### `[virtual]` void BaseAspect::fromMap(const Utils::Store &map)

Retrieves the internal value of this BaseAspect from the Store map.

### QString BaseAspect::labelText() const

Returns the current text for the separate label in the visual representation of this aspect.

See also setLabelText().

### `[virtual]` void BaseAspect::setAutoApply(bool on)

Sets auto-apply mode. When auto-apply mode is on, user interaction to this aspect's widget will not modify the `value` of the aspect until `apply()` is called programmatically.

See also setSettingsKey().

### void BaseAspect::setEnabler(Utils::BoolAspect *checker)

Makes the enabled state of this aspect depend on the checked state of checker.

### void BaseAspect::setLabelPixmap(const QPixmap &labelPixmap)

Sets labelPixmap as pixmap for the separate label in the visual representation of this aspect.

### void BaseAspect::setLabelText(const QString &labelText)

Sets labelText as text for the separate label in the visual representation of this aspect.

See also labelText().

### void BaseAspect::setSettingsKey(const Utils::Key &key)

Sets the key to be used when accessing the settings.

See also settingsKey().

### void BaseAspect::setSettingsKey(const Utils::Key &group, const Utils::Key &key)

Sets the key and group to be used when accessing the settings.

See also settingsKey().

### void BaseAspect::setToolTip(const QString &tooltip)

Sets tooltip as tool tip for the visual representation of this aspect.

### `[virtual]` void BaseAspect::setVariantValue(const QVariant &value, Utils::BaseAspect::Announcement howToAnnounce = DoEmit)

Sets value.

If howToAnnounce is set to `DoEmit`, emits the `valueChanged` signal.

Prefer the typed `setValue()` of the derived classes.

### void BaseAspect::setVisible(bool visible)

Shows or hides the visual representation of this aspect depending on the value of visible. By default, it is visible.

### Utils::Key BaseAspect::settingsKey() const

Returns the key to be used when accessing the settings.

See also setSettingsKey().

### `[virtual]` void BaseAspect::toMap(Utils::Store &map) const

Stores the internal value of this BaseAspect into the Store map.

### void BaseAspect::writeToSettingsImmediatly() const

Immediately writes the value of this aspect into its specified settings, taking a potential container's settings group specification into account.

Note: This is expensive, so it should only be used with good reason.