- Extending Qt Creator Manual
- QtCreator
- StringAspect
- Extending Qt Creator Manual 10.0.0-beta2

# StringAspect Class

class Utils::StringAspect

A string aspect is a string-like property of some object, together with a description of its behavior for common operations like visualizing or persisting. More...

Header: | #include <StringAspect>
Inherits: | Utils::BaseAspect

- List of all members, including inherited members

## Public Types

enum | DisplayStyle { LabelDisplay, LineEditDisplay, TextEditDisplay, PathChooserDisplay }

## Public Functions

| StringAspect()
Utils::FilePath | filePath() const
bool | isChecked() const
void | makeCheckable(Utils::StringAspect::CheckBoxPlacement checkBoxPlacement, const QString &checkerLabel, const QString &checkerKey)
void | setChecked(bool checked)
void | setDisplayFilter(const std::function<QString (const QString &)> &displayFilter)
void | setDisplayStyle(Utils::StringAspect::DisplayStyle displayStyle)
void | setElideMode(Qt::TextElideMode elideMode)
void | setExpectedKind(const PathChooser::Kind expectedKind)
void | setFilePath(const Utils::FilePath &value)
void | setHistoryCompleter(const QString &historyCompleterKey)
void | setPlaceHolderText(const QString &placeHolderText)
void | setValue(const QString &val)
QString | value() const

## Reimplemented Public Functions

virtual void | fromMap(const QVariantMap &map) override
virtual void | toMap(QVariantMap &map) const override

## Detailed Description

String aspects can represent for example a parameter for an external commands, paths in a file system, or simply strings.

The string can be displayed using a QLabel, QLineEdit, QTextEdit or Utils::PathChooser.

The visual representation often contains a label in front of the display of the actual value.

## Member Type Documentation

### enum StringAspect::DisplayStyle

The DisplayStyle enum describes the main visual characteristics of a string aspect.

Constant | Value | Description
--- | --- | ---
`Utils::StringAspect::LabelDisplay` | `0` | Based on QLabel, used for text that cannot be changed by the user in this place, for example names of executables that are defined in the build system.
`Utils::StringAspect::LineEditDisplay` | `1` | Based on QLineEdit, used for user-editable strings that usually fit on a line.
`Utils::StringAspect::TextEditDisplay` | `2` | Based on QTextEdit, used for user-editable strings that often do not fit on a line.
`Utils::StringAspect::PathChooserDisplay` | `3` | Based on Utils::PathChooser.

See also Utils::PathChooser.

## Member Function Documentation

### StringAspect::StringAspect()

Constructs a StringAspect.

### Utils::FilePath StringAspect::filePath() const

Returns the value of this string aspect as `Utils::FilePath`.

Note: This simply uses `FilePath::fromUserInput()` for the conversion. It does not use any check that the value is actually a valid file path.

See also setFilePath().

### `[override virtual]` void StringAspect::fromMap(const QVariantMap &map)

Reimplements: BaseAspect::fromMap(const QVariantMap &map).

### bool StringAspect::isChecked() const

Returns the check box value.

See also makeCheckable() and setChecked().

### void StringAspect::makeCheckable(Utils::StringAspect::CheckBoxPlacement checkBoxPlacement, const QString &checkerLabel, const QString &checkerKey)

Adds a check box with a checkerLabel according to checkBoxPlacement to the line edit.

The state of the check box is made persistent when using a non-emtpy checkerKey.

### void StringAspect::setChecked(bool checked)

Sets the check box of this aspect to checked.

See also makeCheckable() and isChecked().

### void StringAspect::setDisplayFilter(const std::function<QString (const QString &)> &displayFilter)

Sets a displayFilter for fine-tuning the visual appearance of the value of this string aspect.

### void StringAspect::setDisplayStyle(Utils::StringAspect::DisplayStyle displayStyle)

Selects the main display characteristics of the aspect according to displayStyle.

Note: Not all StringAspect features are available with all display styles.

See also Utils::StringAspect::DisplayStyle.

### void StringAspect::setElideMode(Qt::TextElideMode elideMode)

Sets elideMode as label elide mode.

### void StringAspect::setExpectedKind(const PathChooser::Kind expectedKind)

Sets expectedKind as expected kind for path chooser displays.

See also Utils::PathChooser::setExpectedKind().

### void StringAspect::setFilePath(const Utils::FilePath &value)

Sets the value of this string aspect to value.

Note: This simply uses `FilePath::toUserOutput()` for the conversion. It does not use any check that the value is actually a file path.

See also filePath().

### void StringAspect::setHistoryCompleter(const QString &historyCompleterKey)

Sets historyCompleterKey as key for the history completer settings for line edits and path chooser displays.

See also Utils::PathChooser::setExpectedKind().

### void StringAspect::setPlaceHolderText(const QString &placeHolderText)

Sets placeHolderText as place holder for line and text displays.

### void StringAspect::setValue(const QString &val)

Sets the value of this StringAspect from an ordinary `QString`.

See also value().

### `[override virtual]` void StringAspect::toMap(QVariantMap &map) const

Reimplements: BaseAspect::toMap(QVariantMap &map) const.

### QString StringAspect::value() const

Returns the value of this StringAspect as an ordinary `QString`.

See also setValue().