2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
#include "aspects.h"
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
#include "algorithm.h"
|
2022-05-06 12:42:03 +02:00
|
|
|
#include "environment.h"
|
2020-09-18 12:11:40 +02:00
|
|
|
#include "fancylineedit.h"
|
|
|
|
|
#include "layoutbuilder.h"
|
|
|
|
|
#include "pathchooser.h"
|
|
|
|
|
#include "qtcassert.h"
|
2021-02-18 14:18:34 +01:00
|
|
|
#include "qtcsettings.h"
|
2020-09-18 12:11:40 +02:00
|
|
|
#include "variablechooser.h"
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
#include <QAction>
|
2020-09-18 12:11:40 +02:00
|
|
|
#include <QButtonGroup>
|
2018-09-17 15:56:14 +02:00
|
|
|
#include <QCheckBox>
|
2019-11-25 12:46:08 +01:00
|
|
|
#include <QComboBox>
|
2021-02-18 14:18:34 +01:00
|
|
|
#include <QDebug>
|
2021-04-06 11:51:14 +02:00
|
|
|
#include <QGroupBox>
|
2018-09-17 15:56:14 +02:00
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QLineEdit>
|
2020-12-17 13:28:48 +01:00
|
|
|
#include <QListWidget>
|
2020-09-18 12:11:40 +02:00
|
|
|
#include <QPointer>
|
2021-03-25 14:59:01 +01:00
|
|
|
#include <QPushButton>
|
2020-09-18 12:11:40 +02:00
|
|
|
#include <QRadioButton>
|
2021-02-18 14:18:34 +01:00
|
|
|
#include <QSettings>
|
2018-09-25 08:24:10 +02:00
|
|
|
#include <QSpinBox>
|
2018-10-16 07:59:52 +02:00
|
|
|
#include <QTextEdit>
|
2020-09-18 12:11:40 +02:00
|
|
|
|
|
|
|
|
namespace Utils {
|
2020-12-17 15:43:10 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class BaseAspectPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2022-05-25 05:44:45 +02:00
|
|
|
Id m_id;
|
2021-02-17 14:11:58 +01:00
|
|
|
QVariant m_value;
|
|
|
|
|
QVariant m_defaultValue;
|
2021-03-22 17:40:44 +01:00
|
|
|
std::function<QVariant(const QVariant &)> m_toSettings;
|
|
|
|
|
std::function<QVariant(const QVariant &)> m_fromSettings;
|
2021-02-17 14:11:58 +01:00
|
|
|
|
2020-12-17 15:43:10 +01:00
|
|
|
QString m_displayName;
|
|
|
|
|
QString m_settingsKey; // Name of data in settings.
|
2020-12-17 16:29:46 +01:00
|
|
|
QString m_tooltip;
|
2021-02-17 16:48:10 +01:00
|
|
|
QString m_labelText;
|
|
|
|
|
QPixmap m_labelPixmap;
|
2021-03-01 08:41:49 +01:00
|
|
|
QIcon m_icon;
|
2021-02-17 16:48:10 +01:00
|
|
|
QPointer<QLabel> m_label; // Owned by configuration widget
|
2021-02-18 14:18:34 +01:00
|
|
|
QPointer<QAction> m_action; // Owned by us.
|
2021-02-17 16:48:10 +01:00
|
|
|
|
2020-12-17 15:43:10 +01:00
|
|
|
bool m_visible = true;
|
2020-12-17 16:29:46 +01:00
|
|
|
bool m_enabled = true;
|
|
|
|
|
bool m_readOnly = true;
|
2021-02-18 14:18:34 +01:00
|
|
|
bool m_autoApply = true;
|
2021-04-08 15:44:45 +02:00
|
|
|
int m_spanX = 1;
|
|
|
|
|
int m_spanY = 1;
|
2020-12-17 15:43:10 +01:00
|
|
|
BaseAspect::ConfigWidgetCreator m_configWidgetCreator;
|
2021-02-15 09:15:49 +01:00
|
|
|
QList<QPointer<QWidget>> m_subWidgets;
|
2022-04-08 11:35:54 +02:00
|
|
|
|
|
|
|
|
BaseAspect::DataCreator m_dataCreator;
|
2022-04-08 15:12:24 +02:00
|
|
|
BaseAspect::DataCloner m_dataCloner;
|
2022-04-08 11:35:54 +02:00
|
|
|
QList<BaseAspect::DataExtractor> m_dataExtractors;
|
2020-12-17 15:43:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // Internal
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\class Utils::BaseAspect
|
|
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief The \c BaseAspect class provides a common base for classes implementing
|
|
|
|
|
aspects.
|
|
|
|
|
|
|
|
|
|
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.
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
Simple aspects are for example a boolean property represented by a QCheckBox
|
|
|
|
|
in the user interface, or a string property represented by a PathChooser,
|
|
|
|
|
selecting directories in the filesystem.
|
|
|
|
|
|
|
|
|
|
While aspects implementations usually have the ability to visualize and to persist
|
|
|
|
|
their data, or use an ID, neither of these is mandatory.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Constructs a BaseAspect.
|
|
|
|
|
*/
|
2020-12-17 15:43:10 +01:00
|
|
|
BaseAspect::BaseAspect()
|
|
|
|
|
: d(new Internal::BaseAspectPrivate)
|
2022-04-08 11:35:54 +02:00
|
|
|
{
|
|
|
|
|
addDataExtractor(this, &BaseAspect::value, &Data::value);
|
|
|
|
|
}
|
2020-12-17 15:43:10 +01:00
|
|
|
|
2020-12-17 16:29:46 +01:00
|
|
|
/*!
|
|
|
|
|
Destructs a BaseAspect.
|
|
|
|
|
*/
|
2021-02-18 14:18:34 +01:00
|
|
|
BaseAspect::~BaseAspect()
|
|
|
|
|
{
|
|
|
|
|
delete d->m_action;
|
|
|
|
|
}
|
2020-12-17 16:29:46 +01:00
|
|
|
|
2020-12-17 15:43:10 +01:00
|
|
|
Id BaseAspect::id() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseAspect::setId(Id id)
|
|
|
|
|
{
|
|
|
|
|
d->m_id = id;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-17 14:11:58 +01:00
|
|
|
QVariant BaseAspect::value() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Sets value.
|
|
|
|
|
|
|
|
|
|
Emits changed() if the value changed.
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::setValue(const QVariant &value)
|
|
|
|
|
{
|
2021-03-01 06:35:08 +01:00
|
|
|
if (setValueQuietly(value)) {
|
2021-02-17 14:11:58 +01:00
|
|
|
emit changed();
|
2021-03-01 06:35:08 +01:00
|
|
|
emitChangedValue();
|
|
|
|
|
}
|
2021-02-17 14:11:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Sets value without emitting changed()
|
|
|
|
|
|
|
|
|
|
Returns whether the value changed.
|
|
|
|
|
*/
|
|
|
|
|
bool BaseAspect::setValueQuietly(const QVariant &value)
|
|
|
|
|
{
|
|
|
|
|
if (d->m_value == value)
|
|
|
|
|
return false;
|
|
|
|
|
d->m_value = value;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant BaseAspect::defaultValue() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2021-02-18 14:18:34 +01:00
|
|
|
Sets a default value and the current value for this aspect.
|
|
|
|
|
|
|
|
|
|
\note The current value will be set silently to the same value.
|
|
|
|
|
It is reasonable to only set default values in the setup phase
|
|
|
|
|
of the aspect.
|
2021-02-17 14:11:58 +01:00
|
|
|
|
|
|
|
|
Default values will not be stored in settings.
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::setDefaultValue(const QVariant &value)
|
|
|
|
|
{
|
|
|
|
|
d->m_defaultValue = value;
|
2021-02-18 14:18:34 +01:00
|
|
|
d->m_value = value;
|
2021-02-17 14:11:58 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-17 15:43:10 +01:00
|
|
|
void BaseAspect::setDisplayName(const QString &displayName)
|
|
|
|
|
{
|
|
|
|
|
d->m_displayName = displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BaseAspect::isVisible() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_visible;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 16:29:46 +01:00
|
|
|
/*!
|
|
|
|
|
Shows or hides the visual representation of this aspect depending
|
|
|
|
|
on the value of \a visible.
|
|
|
|
|
By default, it is visible.
|
|
|
|
|
*/
|
2020-12-17 15:43:10 +01:00
|
|
|
void BaseAspect::setVisible(bool visible)
|
|
|
|
|
{
|
|
|
|
|
d->m_visible = visible;
|
2021-02-15 09:15:49 +01:00
|
|
|
for (QWidget *w : qAsConst(d->m_subWidgets)) {
|
|
|
|
|
QTC_ASSERT(w, continue);
|
2021-03-11 19:02:42 +01:00
|
|
|
// This may happen during layout building. Explicit setting visibility here
|
|
|
|
|
// may create a show a toplevel widget for a moment until it is parented
|
|
|
|
|
// to some non-shown widget.
|
2021-12-28 21:42:29 +01:00
|
|
|
if (w->parentWidget())
|
2021-03-11 19:02:42 +01:00
|
|
|
w->setVisible(visible);
|
2021-02-15 09:15:49 +01:00
|
|
|
}
|
2020-12-17 16:29:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-17 16:48:10 +01:00
|
|
|
void BaseAspect::setupLabel()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!d->m_label, delete d->m_label);
|
2021-02-18 14:18:34 +01:00
|
|
|
if (d->m_labelText.isEmpty() && d->m_labelPixmap.isNull())
|
|
|
|
|
return;
|
2021-02-17 16:48:10 +01:00
|
|
|
d->m_label = new QLabel(d->m_labelText);
|
2022-02-03 16:12:41 +01:00
|
|
|
d->m_label->setTextInteractionFlags(d->m_label->textInteractionFlags()
|
|
|
|
|
| Qt::TextSelectableByMouse);
|
|
|
|
|
connect(d->m_label, &QLabel::linkActivated, this, [this](const QString &link) {
|
|
|
|
|
emit labelLinkActivated(link);
|
|
|
|
|
});
|
2021-02-17 16:48:10 +01:00
|
|
|
if (!d->m_labelPixmap.isNull())
|
|
|
|
|
d->m_label->setPixmap(d->m_labelPixmap);
|
|
|
|
|
registerSubWidget(d->m_label);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
void BaseAspect::addLabeledItem(LayoutBuilder &builder, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
setupLabel();
|
2021-03-23 10:19:41 +01:00
|
|
|
if (QLabel *l = label()) {
|
|
|
|
|
l->setBuddy(widget);
|
2021-04-08 15:44:45 +02:00
|
|
|
builder.addItem(l);
|
|
|
|
|
LayoutBuilder::LayoutItem item(widget);
|
|
|
|
|
item.span = std::max(d->m_spanX - 1, 1);
|
|
|
|
|
builder.addItem(item);
|
2021-03-23 10:19:41 +01:00
|
|
|
} else {
|
2021-04-08 15:44:45 +02:00
|
|
|
builder.addItem(LayoutBuilder::LayoutItem(widget));
|
2021-03-23 10:19:41 +01:00
|
|
|
}
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-17 16:48:10 +01:00
|
|
|
/*!
|
|
|
|
|
Sets \a labelText as text for the separate label in the visual
|
|
|
|
|
representation of this aspect.
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::setLabelText(const QString &labelText)
|
|
|
|
|
{
|
|
|
|
|
d->m_labelText = labelText;
|
|
|
|
|
if (d->m_label)
|
|
|
|
|
d->m_label->setText(labelText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Sets \a labelPixmap as pixmap for the separate label in the visual
|
|
|
|
|
representation of this aspect.
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::setLabelPixmap(const QPixmap &labelPixmap)
|
|
|
|
|
{
|
|
|
|
|
d->m_labelPixmap = labelPixmap;
|
|
|
|
|
if (d->m_label)
|
|
|
|
|
d->m_label->setPixmap(labelPixmap);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 08:41:49 +01:00
|
|
|
void BaseAspect::setIcon(const QIcon &icon)
|
|
|
|
|
{
|
|
|
|
|
d->m_icon = icon;
|
|
|
|
|
if (d->m_action)
|
|
|
|
|
d->m_action->setIcon(icon);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-17 16:48:10 +01:00
|
|
|
/*!
|
|
|
|
|
Returns the current text for the separate label in the visual
|
|
|
|
|
representation of this aspect.
|
|
|
|
|
*/
|
|
|
|
|
QString BaseAspect::labelText() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_labelText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLabel *BaseAspect::label() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_label.data();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 16:29:46 +01:00
|
|
|
QString BaseAspect::toolTip() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_tooltip;
|
2020-12-17 15:43:10 +01:00
|
|
|
}
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
2020-12-17 16:29:46 +01:00
|
|
|
Sets \a tooltip as tool tip for the visual representation of this aspect.
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::setToolTip(const QString &tooltip)
|
|
|
|
|
{
|
|
|
|
|
d->m_tooltip = tooltip;
|
2021-02-15 09:15:49 +01:00
|
|
|
for (QWidget *w : qAsConst(d->m_subWidgets)) {
|
|
|
|
|
QTC_ASSERT(w, continue);
|
2020-12-17 16:29:46 +01:00
|
|
|
w->setToolTip(tooltip);
|
2021-02-15 09:15:49 +01:00
|
|
|
}
|
2020-12-17 16:29:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-01 09:25:52 +02:00
|
|
|
bool BaseAspect::isEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_enabled;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 16:29:46 +01:00
|
|
|
void BaseAspect::setEnabled(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
d->m_enabled = enabled;
|
2021-02-15 09:15:49 +01:00
|
|
|
for (QWidget *w : qAsConst(d->m_subWidgets)) {
|
|
|
|
|
QTC_ASSERT(w, continue);
|
2020-12-17 16:29:46 +01:00
|
|
|
w->setEnabled(enabled);
|
2021-02-15 09:15:49 +01:00
|
|
|
}
|
2020-12-17 16:29:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-12 13:43:24 +02:00
|
|
|
/*!
|
|
|
|
|
Makes the enabled state of this aspect depend on the checked state of \a checker.
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::setEnabler(BoolAspect *checker)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(checker, return);
|
|
|
|
|
setEnabled(checker->value());
|
|
|
|
|
connect(checker, &BoolAspect::volatileValueChanged, this, &BaseAspect::setEnabled);
|
|
|
|
|
connect(checker, &BoolAspect::valueChanged, this, &BaseAspect::setEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-29 09:11:36 +02:00
|
|
|
bool BaseAspect::isReadOnly() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_readOnly;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 16:29:46 +01:00
|
|
|
void BaseAspect::setReadOnly(bool readOnly)
|
|
|
|
|
{
|
|
|
|
|
d->m_readOnly = readOnly;
|
|
|
|
|
for (QWidget *w : qAsConst(d->m_subWidgets)) {
|
2021-02-15 09:15:49 +01:00
|
|
|
QTC_ASSERT(w, continue);
|
2020-12-17 16:29:46 +01:00
|
|
|
if (auto lineEdit = qobject_cast<QLineEdit *>(w))
|
|
|
|
|
lineEdit->setReadOnly(readOnly);
|
|
|
|
|
else if (auto textEdit = qobject_cast<QTextEdit *>(w))
|
|
|
|
|
textEdit->setReadOnly(readOnly);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2021-04-08 15:44:45 +02:00
|
|
|
void BaseAspect::setSpan(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
d->m_spanX = x;
|
|
|
|
|
d->m_spanY = y;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
bool BaseAspect::isAutoApply() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_autoApply;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Sets auto-apply mode. When auto-apply mode is on, user interaction to this
|
|
|
|
|
aspect's widget will not modify the \c value of the aspect until \c apply()
|
|
|
|
|
is called programmatically.
|
|
|
|
|
|
|
|
|
|
\sa setSettingsKey()
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void BaseAspect::setAutoApply(bool on)
|
|
|
|
|
{
|
|
|
|
|
d->m_autoApply = on;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
void BaseAspect::setConfigWidgetCreator(const ConfigWidgetCreator &configWidgetCreator)
|
|
|
|
|
{
|
2020-12-17 15:43:10 +01:00
|
|
|
d->m_configWidgetCreator = configWidgetCreator;
|
2020-09-18 12:11:40 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-05 06:05:18 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the key to be used when accessing the settings.
|
|
|
|
|
|
|
|
|
|
\sa setSettingsKey()
|
|
|
|
|
*/
|
|
|
|
|
QString BaseAspect::settingsKey() const
|
|
|
|
|
{
|
2020-12-17 15:43:10 +01:00
|
|
|
return d->m_settingsKey;
|
2020-10-05 06:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Sets the key to be used when accessing the settings.
|
|
|
|
|
|
|
|
|
|
\sa settingsKey()
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::setSettingsKey(const QString &key)
|
|
|
|
|
{
|
2020-12-17 15:43:10 +01:00
|
|
|
d->m_settingsKey = key;
|
2020-10-05 06:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Sets the key and group to be used when accessing the settings.
|
|
|
|
|
|
|
|
|
|
\sa settingsKey()
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::setSettingsKey(const QString &group, const QString &key)
|
|
|
|
|
{
|
2020-12-17 15:43:10 +01:00
|
|
|
d->m_settingsKey = group + "/" + key;
|
2020-10-05 06:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
/*!
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
QString BaseAspect::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_displayName.isEmpty() ? d->m_labelText : d->m_displayName;
|
|
|
|
|
}
|
2020-12-17 15:43:10 +01:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
QWidget *BaseAspect::createConfigWidget() const
|
|
|
|
|
{
|
2020-12-17 15:43:10 +01:00
|
|
|
return d->m_configWidgetCreator ? d->m_configWidgetCreator() : nullptr;
|
2020-09-18 12:11:40 +02:00
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
QAction *BaseAspect::action()
|
|
|
|
|
{
|
|
|
|
|
if (!d->m_action) {
|
|
|
|
|
d->m_action = new QAction(labelText());
|
2021-03-01 08:41:49 +01:00
|
|
|
d->m_action->setIcon(d->m_icon);
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
return d->m_action;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Adds the visual representation of this aspect to a layout using
|
|
|
|
|
a layout builder.
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
void BaseAspect::addToLayout(LayoutBuilder &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
/*!
|
|
|
|
|
Updates this aspect's value from user-initiated changes in the widget.
|
|
|
|
|
|
|
|
|
|
This has only an effect if \c isAutoApply is false.
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::apply()
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!d->m_autoApply);
|
2021-03-17 07:42:50 +01:00
|
|
|
if (isDirty())
|
|
|
|
|
setValue(volatileValue());
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Discard user changes in the widget and restore widget contents from
|
|
|
|
|
aspect's value.
|
|
|
|
|
|
|
|
|
|
This has only an effect if \c isAutoApply is false.
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::cancel()
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!d->m_autoApply);
|
2021-03-17 07:42:50 +01:00
|
|
|
if (!d->m_subWidgets.isEmpty())
|
|
|
|
|
setVolatileValue(d->m_value);
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseAspect::finish()
|
|
|
|
|
{
|
2021-03-29 14:20:50 +02:00
|
|
|
// No qDeleteAll() possible as long as the connect in registerSubWidget() exist.
|
|
|
|
|
while (d->m_subWidgets.size())
|
|
|
|
|
delete d->m_subWidgets.takeLast();
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BaseAspect::hasAction() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_action != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BaseAspect::isDirty() const
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!isAutoApply());
|
2021-03-17 07:42:50 +01:00
|
|
|
// Aspects that were never shown cannot contain unsaved user changes.
|
|
|
|
|
if (d->m_subWidgets.isEmpty())
|
|
|
|
|
return false;
|
2021-02-18 14:18:34 +01:00
|
|
|
return volatileValue() != d->m_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant BaseAspect::volatileValue() const
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!isAutoApply());
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseAspect::setVolatileValue(const QVariant &val)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(val);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 16:29:46 +01:00
|
|
|
void BaseAspect::registerSubWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
d->m_subWidgets.append(widget);
|
|
|
|
|
|
2021-03-29 14:20:50 +02:00
|
|
|
// FIXME: This interferes with qDeleteAll() in finish() and destructor,
|
|
|
|
|
// it would not be needed when all users actually deleted their subwidgets,
|
|
|
|
|
// e.g. the SettingsPage::finish() base implementation, but this still
|
|
|
|
|
// leaves the cases where no such base functionality is available, e.g.
|
|
|
|
|
// in the run/build config aspects.
|
2021-02-15 11:25:26 +01:00
|
|
|
connect(widget, &QObject::destroyed, this, [this, widget] {
|
|
|
|
|
d->m_subWidgets.removeAll(widget);
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-17 16:29:46 +01:00
|
|
|
widget->setEnabled(d->m_enabled);
|
|
|
|
|
widget->setToolTip(d->m_tooltip);
|
|
|
|
|
|
|
|
|
|
// Visible is on by default. Not setting it explicitly avoid popping
|
|
|
|
|
// it up when the parent is not set yet, the normal case.
|
|
|
|
|
if (!d->m_visible)
|
|
|
|
|
widget->setVisible(d->m_visible);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 15:44:44 +02:00
|
|
|
void BaseAspect::saveToMap(QVariantMap &data, const QVariant &value,
|
2021-03-11 16:52:22 +01:00
|
|
|
const QVariant &defaultValue, const QString &key)
|
2020-11-09 15:04:37 +02:00
|
|
|
{
|
2021-03-11 16:52:22 +01:00
|
|
|
if (key.isEmpty())
|
2020-11-09 15:04:37 +02:00
|
|
|
return;
|
|
|
|
|
if (value == defaultValue)
|
2020-11-09 15:44:44 +02:00
|
|
|
data.remove(key);
|
2020-11-09 15:04:37 +02:00
|
|
|
else
|
2020-11-09 15:44:44 +02:00
|
|
|
data.insert(key, value);
|
2020-11-09 15:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Retrieves the internal value of this BaseAspect from a \c QVariantMap.
|
|
|
|
|
*/
|
2021-02-17 14:11:58 +01:00
|
|
|
void BaseAspect::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
2021-03-22 17:40:44 +01:00
|
|
|
const QVariant val = map.value(settingsKey(), toSettingsValue(defaultValue()));
|
|
|
|
|
setValue(fromSettingsValue(val));
|
2021-02-17 14:11:58 +01:00
|
|
|
}
|
2020-09-21 09:39:54 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Stores the internal value of this BaseAspect into a \c QVariantMap.
|
|
|
|
|
*/
|
2021-02-17 14:11:58 +01:00
|
|
|
void BaseAspect::toMap(QVariantMap &map) const
|
|
|
|
|
{
|
2021-03-22 17:40:44 +01:00
|
|
|
saveToMap(map, toSettingsValue(d->m_value), toSettingsValue(d->m_defaultValue), settingsKey());
|
2021-02-17 14:11:58 +01:00
|
|
|
}
|
2020-09-21 09:39:54 +02:00
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
void BaseAspect::readSettings(const QSettings *settings)
|
|
|
|
|
{
|
|
|
|
|
if (settingsKey().isEmpty())
|
|
|
|
|
return;
|
2021-03-24 14:44:09 +01:00
|
|
|
const QVariant &val = settings->value(settingsKey());
|
|
|
|
|
setValue(val.isValid() ? fromSettingsValue(val) : defaultValue());
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseAspect::writeSettings(QSettings *settings) const
|
|
|
|
|
{
|
|
|
|
|
if (settingsKey().isEmpty())
|
|
|
|
|
return;
|
2021-03-22 17:40:44 +01:00
|
|
|
QtcSettings::setValueWithDefault(settings,
|
|
|
|
|
settingsKey(),
|
|
|
|
|
toSettingsValue(value()),
|
|
|
|
|
toSettingsValue(defaultValue()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseAspect::setFromSettingsTransformation(const SavedValueTransformation &transform)
|
|
|
|
|
{
|
|
|
|
|
d->m_fromSettings = transform;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseAspect::setToSettingsTransformation(const SavedValueTransformation &transform)
|
|
|
|
|
{
|
|
|
|
|
d->m_toSettings = transform;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant BaseAspect::toSettingsValue(const QVariant &val) const
|
|
|
|
|
{
|
|
|
|
|
return d->m_toSettings ? d->m_toSettings(val) : val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant BaseAspect::fromSettingsValue(const QVariant &val) const
|
|
|
|
|
{
|
|
|
|
|
return d->m_fromSettings ? d->m_fromSettings(val) : val;
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
2018-09-17 15:56:14 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
class BoolAspectPrivate
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2020-08-13 09:16:00 +02:00
|
|
|
BoolAspect::LabelPlacement m_labelPlacement = BoolAspect::LabelPlacement::AtCheckBox;
|
2018-09-17 15:56:14 +02:00
|
|
|
QPointer<QCheckBox> m_checkBox; // Owned by configuration widget
|
2021-04-06 11:51:14 +02:00
|
|
|
QPointer<QGroupBox> m_groupBox; // For BoolAspects handling GroupBox check boxes
|
2018-09-17 15:56:14 +02:00
|
|
|
};
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
class SelectionAspectPrivate
|
2019-06-13 18:25:17 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2021-03-23 16:10:56 +01:00
|
|
|
~SelectionAspectPrivate() { delete m_buttonGroup; }
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
SelectionAspect::DisplayStyle m_displayStyle
|
|
|
|
|
= SelectionAspect::DisplayStyle::RadioButtons;
|
2021-03-26 18:16:08 +01:00
|
|
|
QVector<SelectionAspect::Option> m_options;
|
2019-11-25 12:46:08 +01:00
|
|
|
|
|
|
|
|
// These are all owned by the configuration widget.
|
|
|
|
|
QList<QPointer<QRadioButton>> m_buttons;
|
|
|
|
|
QPointer<QComboBox> m_comboBox;
|
2019-06-13 18:25:17 +02:00
|
|
|
QPointer<QButtonGroup> m_buttonGroup;
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-17 13:28:48 +01:00
|
|
|
class MultiSelectionAspectPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-02-17 14:11:58 +01:00
|
|
|
explicit MultiSelectionAspectPrivate(MultiSelectionAspect *q) : q(q) {}
|
|
|
|
|
|
|
|
|
|
bool setValueSelectedHelper(const QString &value, bool on);
|
|
|
|
|
|
|
|
|
|
MultiSelectionAspect *q;
|
2020-12-17 13:28:48 +01:00
|
|
|
QStringList m_allValues;
|
|
|
|
|
MultiSelectionAspect::DisplayStyle m_displayStyle
|
|
|
|
|
= MultiSelectionAspect::DisplayStyle::ListView;
|
|
|
|
|
|
|
|
|
|
// These are all owned by the configuration widget.
|
|
|
|
|
QPointer<QListWidget> m_listView;
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
class StringAspectPrivate
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2020-08-13 09:16:00 +02:00
|
|
|
StringAspect::DisplayStyle m_displayStyle = StringAspect::LabelDisplay;
|
|
|
|
|
StringAspect::CheckBoxPlacement m_checkBoxPlacement
|
|
|
|
|
= StringAspect::CheckBoxPlacement::Right;
|
|
|
|
|
StringAspect::UncheckedSemantics m_uncheckedSemantics
|
|
|
|
|
= StringAspect::UncheckedSemantics::Disabled;
|
2018-09-17 15:56:14 +02:00
|
|
|
std::function<QString(const QString &)> m_displayFilter;
|
2020-08-13 09:16:00 +02:00
|
|
|
std::unique_ptr<BoolAspect> m_checker;
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2021-12-01 17:18:03 +03:00
|
|
|
Qt::TextElideMode m_elideMode = Qt::ElideNone;
|
2018-09-17 15:56:14 +02:00
|
|
|
QString m_placeHolderText;
|
|
|
|
|
QString m_historyCompleterKey;
|
|
|
|
|
PathChooser::Kind m_expectedKind = PathChooser::File;
|
2021-08-03 15:12:24 +02:00
|
|
|
EnvironmentChange m_environmentChange;
|
2021-12-01 17:18:03 +03:00
|
|
|
QPointer<ElidingLabel> m_labelDisplay;
|
2018-09-17 15:56:14 +02:00
|
|
|
QPointer<FancyLineEdit> m_lineEditDisplay;
|
|
|
|
|
QPointer<PathChooser> m_pathChooserDisplay;
|
2018-10-16 07:59:52 +02:00
|
|
|
QPointer<QTextEdit> m_textEditDisplay;
|
2020-09-18 12:11:40 +02:00
|
|
|
MacroExpanderProvider m_expanderProvider;
|
|
|
|
|
FilePath m_baseFileName;
|
2020-08-13 09:16:00 +02:00
|
|
|
StringAspect::ValueAcceptor m_valueAcceptor;
|
2020-10-05 09:03:13 +02:00
|
|
|
FancyLineEdit::ValidationFunction m_validator;
|
2020-11-09 15:57:47 +01:00
|
|
|
std::function<void()> m_openTerminal;
|
2020-10-05 09:03:13 +02:00
|
|
|
|
2020-11-19 23:12:28 +01:00
|
|
|
bool m_undoRedoEnabled = true;
|
2021-02-18 14:18:34 +01:00
|
|
|
bool m_acceptRichText = false;
|
2019-07-23 13:44:11 +02:00
|
|
|
bool m_showToolTipOnLabel = false;
|
2020-03-16 10:24:35 +01:00
|
|
|
bool m_fileDialogOnly = false;
|
2021-03-25 14:59:01 +01:00
|
|
|
bool m_useResetButton = false;
|
2021-06-22 13:54:16 +02:00
|
|
|
bool m_autoApplyOnEditingFinished = false;
|
|
|
|
|
// Used to block recursive editingFinished signals for example when return is pressed, and
|
|
|
|
|
// the validation changes focus by opening a dialog
|
|
|
|
|
bool m_blockAutoApply = false;
|
2019-11-25 17:55:39 +01:00
|
|
|
|
2021-04-01 09:25:52 +02:00
|
|
|
template<class Widget> void updateWidgetFromCheckStatus(StringAspect *aspect, Widget *w)
|
2019-11-25 17:55:39 +01:00
|
|
|
{
|
|
|
|
|
const bool enabled = !m_checker || m_checker->value();
|
2020-08-13 09:16:00 +02:00
|
|
|
if (m_uncheckedSemantics == StringAspect::UncheckedSemantics::Disabled)
|
2021-04-01 09:25:52 +02:00
|
|
|
w->setEnabled(enabled && aspect->isEnabled());
|
2019-11-25 17:55:39 +01:00
|
|
|
else
|
2021-03-29 09:11:36 +02:00
|
|
|
w->setReadOnly(!enabled || aspect->isReadOnly());
|
2019-11-25 17:55:39 +01:00
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
};
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
class IntegerAspectPrivate
|
2018-09-25 08:24:10 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2021-03-02 07:03:57 +01:00
|
|
|
Utils::optional<qint64> m_minimumValue;
|
|
|
|
|
Utils::optional<qint64> m_maximumValue;
|
2018-09-25 08:24:10 +02:00
|
|
|
int m_displayIntegerBase = 10;
|
2019-04-24 12:15:31 +02:00
|
|
|
qint64 m_displayScaleFactor = 1;
|
2018-09-25 08:24:10 +02:00
|
|
|
QString m_prefix;
|
|
|
|
|
QString m_suffix;
|
2021-02-18 14:18:34 +01:00
|
|
|
QString m_specialValueText;
|
|
|
|
|
int m_singleStep = 1;
|
2018-09-25 08:24:10 +02:00
|
|
|
QPointer<QSpinBox> m_spinBox; // Owned by configuration widget
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-01 08:45:29 +01:00
|
|
|
class DoubleAspectPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Utils::optional<double> m_minimumValue;
|
|
|
|
|
Utils::optional<double> m_maximumValue;
|
|
|
|
|
QString m_prefix;
|
|
|
|
|
QString m_suffix;
|
|
|
|
|
QString m_specialValueText;
|
|
|
|
|
double m_singleStep = 1;
|
|
|
|
|
QPointer<QDoubleSpinBox> m_spinBox; // Owned by configuration widget
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
class StringListAspectPrivate
|
2020-07-21 08:48:06 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-14 08:55:22 +02:00
|
|
|
class TextDisplayPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QString m_message;
|
2022-05-25 05:44:45 +02:00
|
|
|
InfoLabel::InfoType m_type;
|
2020-08-20 15:54:21 +02:00
|
|
|
QPointer<InfoLabel> m_label;
|
2020-08-14 08:55:22 +02:00
|
|
|
};
|
|
|
|
|
|
2018-09-17 15:56:14 +02:00
|
|
|
} // Internal
|
|
|
|
|
|
2020-10-01 09:25:13 +02:00
|
|
|
/*!
|
|
|
|
|
\enum Utils::StringAspect::DisplayStyle
|
|
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
The DisplayStyle enum describes the main visual characteristics of a
|
|
|
|
|
string aspect.
|
|
|
|
|
|
|
|
|
|
\value LabelDisplay
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
\value LineEditDisplay
|
|
|
|
|
Based on QLineEdit, used for user-editable strings that usually
|
|
|
|
|
fit on a line.
|
|
|
|
|
|
|
|
|
|
\value TextEditDisplay
|
|
|
|
|
Based on QTextEdit, used for user-editable strings that often
|
|
|
|
|
do not fit on a line.
|
|
|
|
|
|
|
|
|
|
\value PathChooserDisplay
|
|
|
|
|
Based on Utils::PathChooser.
|
|
|
|
|
|
|
|
|
|
\sa Utils::PathChooser
|
|
|
|
|
*/
|
|
|
|
|
|
2018-09-17 15:56:14 +02:00
|
|
|
/*!
|
2020-09-18 12:11:40 +02:00
|
|
|
\class Utils::StringAspect
|
2020-09-21 09:39:54 +02:00
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief 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.
|
|
|
|
|
|
|
|
|
|
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.
|
2018-09-17 15:56:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Constructs a StringAspect.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
StringAspect::StringAspect()
|
|
|
|
|
: d(new Internal::StringAspectPrivate)
|
2021-02-18 14:18:34 +01:00
|
|
|
{
|
|
|
|
|
setDefaultValue(QString());
|
2021-04-08 15:44:45 +02:00
|
|
|
setSpan(2, 1); // Default: Label + something
|
2022-04-08 11:35:54 +02:00
|
|
|
|
|
|
|
|
addDataExtractor(this, &StringAspect::value, &Data::value);
|
|
|
|
|
addDataExtractor(this, &StringAspect::filePath, &Data::filePath);
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
2020-10-01 09:25:13 +02:00
|
|
|
\internal
|
2020-09-21 09:39:54 +02:00
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
StringAspect::~StringAspect() = default;
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setValueAcceptor(StringAspect::ValueAcceptor &&acceptor)
|
2020-03-24 10:14:47 +01:00
|
|
|
{
|
|
|
|
|
d->m_valueAcceptor = std::move(acceptor);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the value of this StringAspect as an ordinary \c QString.
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
QString StringAspect::value() const
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
return BaseAspect::value().toString();
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
2020-10-01 09:25:13 +02:00
|
|
|
Sets the \a value of this StringAspect from an ordinary \c QString.
|
2020-09-21 09:39:54 +02:00
|
|
|
*/
|
2021-02-17 14:11:58 +01:00
|
|
|
void StringAspect::setValue(const QString &val)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
const bool isSame = val == value();
|
2020-03-24 10:14:47 +01:00
|
|
|
if (isSame)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-02-17 14:11:58 +01:00
|
|
|
QString processedValue = val;
|
2020-03-24 10:14:47 +01:00
|
|
|
if (d->m_valueAcceptor) {
|
2021-02-17 14:11:58 +01:00
|
|
|
const Utils::optional<QString> tmp = d->m_valueAcceptor(value(), val);
|
2020-03-24 10:14:47 +01:00
|
|
|
if (!tmp) {
|
|
|
|
|
update(); // Make sure the original value is retained in the UI
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
processedValue = tmp.value();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-17 14:11:58 +01:00
|
|
|
if (BaseAspect::setValueQuietly(QVariant(processedValue))) {
|
|
|
|
|
update();
|
|
|
|
|
emit changed();
|
2021-03-25 18:25:27 +01:00
|
|
|
emit valueChanged(processedValue);
|
2021-02-17 14:11:58 +01:00
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
void StringAspect::setDefaultValue(const QString &val)
|
|
|
|
|
{
|
|
|
|
|
BaseAspect::setDefaultValue(val);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::fromMap(const QVariantMap &map)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
if (!settingsKey().isEmpty())
|
2021-03-18 14:20:02 +01:00
|
|
|
BaseAspect::setValueQuietly(map.value(settingsKey(), defaultValue()));
|
2018-09-17 15:56:14 +02:00
|
|
|
if (d->m_checker)
|
|
|
|
|
d->m_checker->fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::toMap(QVariantMap &map) const
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2021-03-11 16:52:22 +01:00
|
|
|
saveToMap(map, value(), defaultValue(), settingsKey());
|
2018-09-17 15:56:14 +02:00
|
|
|
if (d->m_checker)
|
|
|
|
|
d->m_checker->toMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the value of this string aspect as \c Utils::FilePath.
|
|
|
|
|
|
|
|
|
|
\note This simply uses \c FilePath::fromUserInput() for the
|
|
|
|
|
conversion. It does not use any check that the value is actually
|
|
|
|
|
a valid file path.
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
FilePath StringAspect::filePath() const
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
return FilePath::fromUserInput(value());
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Sets the value of this string aspect to \a value.
|
|
|
|
|
|
|
|
|
|
\note This simply uses \c FilePath::toUserOutput() for the
|
|
|
|
|
conversion. It does not use any check that the value is actually
|
|
|
|
|
a file path.
|
|
|
|
|
*/
|
|
|
|
|
void StringAspect::setFilePath(const FilePath &value)
|
2019-04-17 15:20:24 +02:00
|
|
|
{
|
2020-09-21 09:39:54 +02:00
|
|
|
setValue(value.toUserOutput());
|
2019-04-17 15:20:24 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-05 10:21:13 +02:00
|
|
|
void StringAspect::setDefaultFilePath(const FilePath &value)
|
|
|
|
|
{
|
|
|
|
|
setDefaultValue(value.toUserOutput());
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-19 09:46:26 +01:00
|
|
|
PathChooser *StringAspect::pathChooser() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_pathChooserDisplay.data();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setShowToolTipOnLabel(bool show)
|
2019-07-23 13:44:11 +02:00
|
|
|
{
|
|
|
|
|
d->m_showToolTipOnLabel = show;
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 09:25:13 +02:00
|
|
|
/*!
|
|
|
|
|
Sets a \a displayFilter for fine-tuning the visual appearance
|
|
|
|
|
of the value of this string aspect.
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setDisplayFilter(const std::function<QString(const QString &)> &displayFilter)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
d->m_displayFilter = displayFilter;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 09:25:13 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the check box value.
|
|
|
|
|
|
|
|
|
|
\sa makeCheckable(), setChecked()
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
bool StringAspect::isChecked() const
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
return !d->m_checker || d->m_checker->value();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 09:25:13 +02:00
|
|
|
/*!
|
|
|
|
|
Sets the check box of this aspect to \a checked.
|
|
|
|
|
|
|
|
|
|
\sa makeCheckable(), isChecked()
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setChecked(bool checked)
|
2019-11-25 17:55:39 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d->m_checker, return);
|
|
|
|
|
d->m_checker->setValue(checked);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 09:25:13 +02:00
|
|
|
/*!
|
|
|
|
|
Selects the main display characteristics of the aspect according to
|
|
|
|
|
\a displayStyle.
|
|
|
|
|
|
|
|
|
|
\note Not all StringAspect features are available with all display styles.
|
|
|
|
|
|
|
|
|
|
\sa Utils::StringAspect::DisplayStyle
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setDisplayStyle(DisplayStyle displayStyle)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
d->m_displayStyle = displayStyle;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 09:25:13 +02:00
|
|
|
/*!
|
|
|
|
|
Sets \a placeHolderText as place holder for line and text displays.
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setPlaceHolderText(const QString &placeHolderText)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
d->m_placeHolderText = placeHolderText;
|
|
|
|
|
if (d->m_lineEditDisplay)
|
|
|
|
|
d->m_lineEditDisplay->setPlaceholderText(placeHolderText);
|
2018-10-16 07:59:52 +02:00
|
|
|
if (d->m_textEditDisplay)
|
|
|
|
|
d->m_textEditDisplay->setPlaceholderText(placeHolderText);
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-01 17:18:03 +03:00
|
|
|
/*!
|
|
|
|
|
Sets \a elideMode as label elide mode.
|
|
|
|
|
*/
|
|
|
|
|
void StringAspect::setElideMode(Qt::TextElideMode elideMode)
|
|
|
|
|
{
|
|
|
|
|
d->m_elideMode = elideMode;
|
|
|
|
|
if (d->m_labelDisplay)
|
|
|
|
|
d->m_labelDisplay->setElideMode(elideMode);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 09:25:13 +02:00
|
|
|
/*!
|
|
|
|
|
Sets \a historyCompleterKey as key for the history completer settings for
|
|
|
|
|
line edits and path chooser displays.
|
|
|
|
|
|
|
|
|
|
\sa Utils::PathChooser::setExpectedKind()
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setHistoryCompleter(const QString &historyCompleterKey)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
d->m_historyCompleterKey = historyCompleterKey;
|
|
|
|
|
if (d->m_lineEditDisplay)
|
|
|
|
|
d->m_lineEditDisplay->setHistoryCompleter(historyCompleterKey);
|
|
|
|
|
if (d->m_pathChooserDisplay)
|
|
|
|
|
d->m_pathChooserDisplay->setHistoryCompleter(historyCompleterKey);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 09:25:13 +02:00
|
|
|
/*!
|
|
|
|
|
Sets \a expectedKind as expected kind for path chooser displays.
|
|
|
|
|
|
|
|
|
|
\sa Utils::PathChooser::setExpectedKind()
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setExpectedKind(const PathChooser::Kind expectedKind)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
d->m_expectedKind = expectedKind;
|
|
|
|
|
if (d->m_pathChooserDisplay)
|
|
|
|
|
d->m_pathChooserDisplay->setExpectedKind(expectedKind);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-03 15:12:24 +02:00
|
|
|
void StringAspect::setEnvironmentChange(const EnvironmentChange &change)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2021-08-03 15:12:24 +02:00
|
|
|
d->m_environmentChange = change;
|
2018-09-17 15:56:14 +02:00
|
|
|
if (d->m_pathChooserDisplay)
|
2021-08-03 15:12:24 +02:00
|
|
|
d->m_pathChooserDisplay->setEnvironmentChange(change);
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setBaseFileName(const FilePath &baseFileName)
|
2019-04-26 17:06:23 +02:00
|
|
|
{
|
|
|
|
|
d->m_baseFileName = baseFileName;
|
|
|
|
|
if (d->m_pathChooserDisplay)
|
2019-12-17 11:53:58 +01:00
|
|
|
d->m_pathChooserDisplay->setBaseDirectory(baseFileName);
|
2019-04-26 17:06:23 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-05 09:03:13 +02:00
|
|
|
void StringAspect::setUndoRedoEnabled(bool undoRedoEnabled)
|
|
|
|
|
{
|
|
|
|
|
d->m_undoRedoEnabled = undoRedoEnabled;
|
|
|
|
|
if (d->m_textEditDisplay)
|
|
|
|
|
d->m_textEditDisplay->setUndoRedoEnabled(undoRedoEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
void StringAspect::setAcceptRichText(bool acceptRichText)
|
|
|
|
|
{
|
|
|
|
|
d->m_acceptRichText = acceptRichText;
|
|
|
|
|
if (d->m_textEditDisplay)
|
|
|
|
|
d->m_textEditDisplay->setAcceptRichText(acceptRichText);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setMacroExpanderProvider(const MacroExpanderProvider &expanderProvider)
|
2019-11-25 17:55:39 +01:00
|
|
|
{
|
|
|
|
|
d->m_expanderProvider = expanderProvider;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
void StringAspect::setUseGlobalMacroExpander()
|
|
|
|
|
{
|
|
|
|
|
d->m_expanderProvider = &globalMacroExpander;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 14:59:01 +01:00
|
|
|
void StringAspect::setUseResetButton()
|
|
|
|
|
{
|
|
|
|
|
d->m_useResetButton = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 09:03:13 +02:00
|
|
|
void StringAspect::setValidationFunction(const FancyLineEdit::ValidationFunction &validator)
|
|
|
|
|
{
|
|
|
|
|
d->m_validator = validator;
|
|
|
|
|
if (d->m_lineEditDisplay)
|
|
|
|
|
d->m_lineEditDisplay->setValidationFunction(d->m_validator);
|
2021-07-22 15:11:41 +02:00
|
|
|
else if (d->m_pathChooserDisplay)
|
|
|
|
|
d->m_pathChooserDisplay->setValidationFunction(d->m_validator);
|
2020-10-05 09:03:13 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-09 15:57:47 +01:00
|
|
|
void StringAspect::setOpenTerminalHandler(const std::function<void ()> &openTerminal)
|
|
|
|
|
{
|
|
|
|
|
d->m_openTerminal = openTerminal;
|
|
|
|
|
if (d->m_pathChooserDisplay)
|
|
|
|
|
d->m_pathChooserDisplay->setOpenTerminalHandler(openTerminal);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 13:54:16 +02:00
|
|
|
void StringAspect::setAutoApplyOnEditingFinished(bool applyOnEditingFinished)
|
|
|
|
|
{
|
|
|
|
|
d->m_autoApplyOnEditingFinished = applyOnEditingFinished;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::validateInput()
|
2020-03-19 15:31:27 +01:00
|
|
|
{
|
|
|
|
|
if (d->m_pathChooserDisplay)
|
|
|
|
|
d->m_pathChooserDisplay->triggerChanged();
|
|
|
|
|
if (d->m_lineEditDisplay)
|
|
|
|
|
d->m_lineEditDisplay->validate();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setUncheckedSemantics(StringAspect::UncheckedSemantics semantics)
|
2019-11-25 17:55:39 +01:00
|
|
|
{
|
|
|
|
|
d->m_uncheckedSemantics = semantics;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::addToLayout(LayoutBuilder &builder)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2019-11-26 17:11:01 +01:00
|
|
|
if (d->m_checker && d->m_checkBoxPlacement == CheckBoxPlacement::Top) {
|
|
|
|
|
d->m_checker->addToLayout(builder);
|
2020-09-18 04:54:41 +02:00
|
|
|
builder.finishRow();
|
2019-11-26 17:11:01 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
const auto useMacroExpander = [this](QWidget *w) {
|
2019-11-25 17:55:39 +01:00
|
|
|
if (!d->m_expanderProvider)
|
|
|
|
|
return;
|
2021-03-11 19:02:42 +01:00
|
|
|
const auto chooser = new VariableChooser(w);
|
2019-11-25 17:55:39 +01:00
|
|
|
chooser->addSupportedWidget(w);
|
|
|
|
|
chooser->addMacroExpanderProvider(d->m_expanderProvider);
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
const QString displayedString = d->m_displayFilter ? d->m_displayFilter(value()) : value();
|
|
|
|
|
|
2018-09-17 15:56:14 +02:00
|
|
|
switch (d->m_displayStyle) {
|
|
|
|
|
case PathChooserDisplay:
|
2020-12-17 16:29:46 +01:00
|
|
|
d->m_pathChooserDisplay = createSubWidget<PathChooser>();
|
2018-09-17 15:56:14 +02:00
|
|
|
d->m_pathChooserDisplay->setExpectedKind(d->m_expectedKind);
|
2018-10-22 12:22:01 +02:00
|
|
|
if (!d->m_historyCompleterKey.isEmpty())
|
|
|
|
|
d->m_pathChooserDisplay->setHistoryCompleter(d->m_historyCompleterKey);
|
2021-07-22 15:11:41 +02:00
|
|
|
if (d->m_validator)
|
|
|
|
|
d->m_pathChooserDisplay->setValidationFunction(d->m_validator);
|
2021-08-03 15:12:24 +02:00
|
|
|
d->m_pathChooserDisplay->setEnvironmentChange(d->m_environmentChange);
|
2019-12-17 11:53:58 +01:00
|
|
|
d->m_pathChooserDisplay->setBaseDirectory(d->m_baseFileName);
|
2020-11-09 15:57:47 +01:00
|
|
|
d->m_pathChooserDisplay->setOpenTerminalHandler(d->m_openTerminal);
|
2022-05-05 10:21:13 +02:00
|
|
|
if (defaultValue() == value())
|
|
|
|
|
d->m_pathChooserDisplay->setDefaultValue(defaultValue().toString());
|
|
|
|
|
else
|
|
|
|
|
d->m_pathChooserDisplay->setFilePath(FilePath::fromUserInput(displayedString));
|
2022-07-04 12:54:26 +02:00
|
|
|
// do not override default value with placeholder, but use placeholder if default is empty
|
|
|
|
|
if (d->m_pathChooserDisplay->lineEdit()->placeholderText().isEmpty())
|
|
|
|
|
d->m_pathChooserDisplay->lineEdit()->setPlaceholderText(d->m_placeHolderText);
|
2021-04-01 09:25:52 +02:00
|
|
|
d->updateWidgetFromCheckStatus(this, d->m_pathChooserDisplay.data());
|
2021-02-18 14:18:34 +01:00
|
|
|
addLabeledItem(builder, d->m_pathChooserDisplay);
|
|
|
|
|
useMacroExpander(d->m_pathChooserDisplay->lineEdit());
|
|
|
|
|
if (isAutoApply()) {
|
2021-06-22 13:54:16 +02:00
|
|
|
if (d->m_autoApplyOnEditingFinished) {
|
2022-04-22 16:18:54 +02:00
|
|
|
const auto setPathChooserValue = [this] {
|
2021-06-22 13:54:16 +02:00
|
|
|
if (d->m_blockAutoApply)
|
|
|
|
|
return;
|
|
|
|
|
d->m_blockAutoApply = true;
|
2021-09-27 10:38:51 +02:00
|
|
|
setValue(d->m_pathChooserDisplay->filePath().toString());
|
2021-06-22 13:54:16 +02:00
|
|
|
d->m_blockAutoApply = false;
|
2022-04-22 16:18:54 +02:00
|
|
|
};
|
|
|
|
|
connect(d->m_pathChooserDisplay, &PathChooser::editingFinished, this, setPathChooserValue);
|
|
|
|
|
connect(d->m_pathChooserDisplay, &PathChooser::browsingFinished, this, setPathChooserValue);
|
2021-06-22 13:54:16 +02:00
|
|
|
} else {
|
2021-10-29 09:16:13 +02:00
|
|
|
connect(d->m_pathChooserDisplay, &PathChooser::pathChanged,
|
|
|
|
|
this, [this](const QString &path) {
|
|
|
|
|
setValue(path);
|
2021-06-22 13:54:16 +02:00
|
|
|
});
|
|
|
|
|
}
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
break;
|
|
|
|
|
case LineEditDisplay:
|
2020-12-17 16:29:46 +01:00
|
|
|
d->m_lineEditDisplay = createSubWidget<FancyLineEdit>();
|
2018-09-17 15:56:14 +02:00
|
|
|
d->m_lineEditDisplay->setPlaceholderText(d->m_placeHolderText);
|
2018-10-22 12:22:01 +02:00
|
|
|
if (!d->m_historyCompleterKey.isEmpty())
|
|
|
|
|
d->m_lineEditDisplay->setHistoryCompleter(d->m_historyCompleterKey);
|
2020-10-05 09:03:13 +02:00
|
|
|
if (d->m_validator)
|
|
|
|
|
d->m_lineEditDisplay->setValidationFunction(d->m_validator);
|
2021-02-18 14:18:34 +01:00
|
|
|
d->m_lineEditDisplay->setTextKeepingActiveCursor(displayedString);
|
2021-04-01 09:25:52 +02:00
|
|
|
d->updateWidgetFromCheckStatus(this, d->m_lineEditDisplay.data());
|
2021-02-18 14:18:34 +01:00
|
|
|
addLabeledItem(builder, d->m_lineEditDisplay);
|
2019-11-25 17:55:39 +01:00
|
|
|
useMacroExpander(d->m_lineEditDisplay);
|
2021-02-18 14:18:34 +01:00
|
|
|
if (isAutoApply()) {
|
2021-06-22 13:54:16 +02:00
|
|
|
if (d->m_autoApplyOnEditingFinished) {
|
|
|
|
|
connect(d->m_lineEditDisplay, &FancyLineEdit::editingFinished, this, [this] {
|
|
|
|
|
if (d->m_blockAutoApply)
|
|
|
|
|
return;
|
|
|
|
|
d->m_blockAutoApply = true;
|
|
|
|
|
setValue(d->m_lineEditDisplay->text());
|
|
|
|
|
d->m_blockAutoApply = false;
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
connect(d->m_lineEditDisplay,
|
|
|
|
|
&FancyLineEdit::textEdited,
|
|
|
|
|
this,
|
|
|
|
|
&StringAspect::setValue);
|
2022-06-23 10:27:26 +02:00
|
|
|
connect(d->m_lineEditDisplay, &FancyLineEdit::editingFinished, this, [this] {
|
|
|
|
|
setValue(d->m_lineEditDisplay->text());
|
|
|
|
|
});
|
2021-06-22 13:54:16 +02:00
|
|
|
}
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
2021-03-25 14:59:01 +01:00
|
|
|
if (d->m_useResetButton) {
|
|
|
|
|
auto resetButton = createSubWidget<QPushButton>(tr("Reset"));
|
|
|
|
|
resetButton->setEnabled(d->m_lineEditDisplay->text() != defaultValue());
|
|
|
|
|
connect(resetButton, &QPushButton::clicked, this, [this] {
|
|
|
|
|
d->m_lineEditDisplay->setText(defaultValue().toString());
|
|
|
|
|
});
|
|
|
|
|
connect(d->m_lineEditDisplay, &QLineEdit::textChanged, this, [this, resetButton] {
|
|
|
|
|
resetButton->setEnabled(d->m_lineEditDisplay->text() != defaultValue());
|
|
|
|
|
});
|
|
|
|
|
builder.addItem(resetButton);
|
|
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
break;
|
2018-10-16 07:59:52 +02:00
|
|
|
case TextEditDisplay:
|
2020-12-17 16:29:46 +01:00
|
|
|
d->m_textEditDisplay = createSubWidget<QTextEdit>();
|
2018-10-16 07:59:52 +02:00
|
|
|
d->m_textEditDisplay->setPlaceholderText(d->m_placeHolderText);
|
2020-10-05 09:03:13 +02:00
|
|
|
d->m_textEditDisplay->setUndoRedoEnabled(d->m_undoRedoEnabled);
|
2021-02-18 14:18:34 +01:00
|
|
|
d->m_textEditDisplay->setAcceptRichText(d->m_acceptRichText);
|
2020-11-19 23:12:28 +01:00
|
|
|
d->m_textEditDisplay->setTextInteractionFlags(Qt::TextEditorInteraction);
|
2021-02-18 14:18:34 +01:00
|
|
|
d->m_textEditDisplay->setText(displayedString);
|
2021-04-01 09:25:52 +02:00
|
|
|
d->updateWidgetFromCheckStatus(this, d->m_textEditDisplay.data());
|
2021-02-18 14:18:34 +01:00
|
|
|
addLabeledItem(builder, d->m_textEditDisplay);
|
2019-11-25 17:55:39 +01:00
|
|
|
useMacroExpander(d->m_textEditDisplay);
|
2021-02-18 14:18:34 +01:00
|
|
|
if (isAutoApply()) {
|
|
|
|
|
connect(d->m_textEditDisplay, &QTextEdit::textChanged, this, [this] {
|
|
|
|
|
setValue(d->m_textEditDisplay->document()->toPlainText());
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-10-16 07:59:52 +02:00
|
|
|
break;
|
2018-09-17 15:56:14 +02:00
|
|
|
case LabelDisplay:
|
2021-12-01 17:18:03 +03:00
|
|
|
d->m_labelDisplay = createSubWidget<ElidingLabel>();
|
|
|
|
|
d->m_labelDisplay->setElideMode(d->m_elideMode);
|
2018-09-17 15:56:14 +02:00
|
|
|
d->m_labelDisplay->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
2021-02-18 14:18:34 +01:00
|
|
|
d->m_labelDisplay->setText(displayedString);
|
|
|
|
|
d->m_labelDisplay->setToolTip(d->m_showToolTipOnLabel ? displayedString : toolTip());
|
|
|
|
|
addLabeledItem(builder, d->m_labelDisplay);
|
2018-09-17 15:56:14 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-19 15:31:27 +01:00
|
|
|
validateInput();
|
|
|
|
|
|
2019-11-26 17:11:01 +01:00
|
|
|
if (d->m_checker && d->m_checkBoxPlacement == CheckBoxPlacement::Right)
|
2019-10-15 17:20:51 +02:00
|
|
|
d->m_checker->addToLayout(builder);
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
QVariant StringAspect::volatileValue() const
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!isAutoApply());
|
|
|
|
|
switch (d->m_displayStyle) {
|
|
|
|
|
case PathChooserDisplay:
|
|
|
|
|
QTC_ASSERT(d->m_pathChooserDisplay, return {});
|
2022-07-07 08:25:03 +02:00
|
|
|
if (d->m_pathChooserDisplay->filePath().isEmpty())
|
|
|
|
|
return defaultValue().toString();
|
2021-09-27 10:38:51 +02:00
|
|
|
return d->m_pathChooserDisplay->filePath().toString();
|
2021-02-18 14:18:34 +01:00
|
|
|
case LineEditDisplay:
|
|
|
|
|
QTC_ASSERT(d->m_lineEditDisplay, return {});
|
2022-07-07 08:25:03 +02:00
|
|
|
if (d->m_lineEditDisplay->text().isEmpty())
|
|
|
|
|
return defaultValue().toString();
|
2021-02-18 14:18:34 +01:00
|
|
|
return d->m_lineEditDisplay->text();
|
|
|
|
|
case TextEditDisplay:
|
|
|
|
|
QTC_ASSERT(d->m_textEditDisplay, return {});
|
2022-07-07 08:25:03 +02:00
|
|
|
if (d->m_textEditDisplay->document()->isEmpty())
|
|
|
|
|
return defaultValue().toString();
|
2021-02-18 14:18:34 +01:00
|
|
|
return d->m_textEditDisplay->document()->toPlainText();
|
|
|
|
|
case LabelDisplay:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StringAspect::setVolatileValue(const QVariant &val)
|
|
|
|
|
{
|
|
|
|
|
switch (d->m_displayStyle) {
|
|
|
|
|
case PathChooserDisplay:
|
|
|
|
|
if (d->m_pathChooserDisplay)
|
2021-09-30 16:46:42 +02:00
|
|
|
d->m_pathChooserDisplay->setFilePath(FilePath::fromVariant(val));
|
2021-02-18 14:18:34 +01:00
|
|
|
break;
|
|
|
|
|
case LineEditDisplay:
|
|
|
|
|
if (d->m_lineEditDisplay)
|
|
|
|
|
d->m_lineEditDisplay->setText(val.toString());
|
|
|
|
|
break;
|
|
|
|
|
case TextEditDisplay:
|
|
|
|
|
if (d->m_textEditDisplay)
|
|
|
|
|
d->m_textEditDisplay->document()->setPlainText(val.toString());
|
|
|
|
|
break;
|
|
|
|
|
case LabelDisplay:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-25 18:25:27 +01:00
|
|
|
void StringAspect::emitChangedValue()
|
|
|
|
|
{
|
|
|
|
|
emit valueChanged(value());
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::update()
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
const QString displayedString = d->m_displayFilter ? d->m_displayFilter(value()) : value();
|
2018-09-17 15:56:14 +02:00
|
|
|
|
|
|
|
|
if (d->m_pathChooserDisplay) {
|
2020-04-09 11:05:50 +02:00
|
|
|
d->m_pathChooserDisplay->setFilePath(FilePath::fromString(displayedString));
|
2021-04-01 09:25:52 +02:00
|
|
|
d->updateWidgetFromCheckStatus(this, d->m_pathChooserDisplay.data());
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d->m_lineEditDisplay) {
|
2019-02-07 14:12:49 +01:00
|
|
|
d->m_lineEditDisplay->setTextKeepingActiveCursor(displayedString);
|
2021-04-01 09:25:52 +02:00
|
|
|
d->updateWidgetFromCheckStatus(this, d->m_lineEditDisplay.data());
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-16 07:59:52 +02:00
|
|
|
if (d->m_textEditDisplay) {
|
2021-03-03 11:50:37 +01:00
|
|
|
const QString old = d->m_textEditDisplay->document()->toPlainText();
|
|
|
|
|
if (displayedString != old)
|
|
|
|
|
d->m_textEditDisplay->setText(displayedString);
|
2021-04-01 09:25:52 +02:00
|
|
|
d->updateWidgetFromCheckStatus(this, d->m_textEditDisplay.data());
|
2018-10-16 07:59:52 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-23 13:44:11 +02:00
|
|
|
if (d->m_labelDisplay) {
|
2018-09-17 15:56:14 +02:00
|
|
|
d->m_labelDisplay->setText(displayedString);
|
2020-12-17 16:29:46 +01:00
|
|
|
d->m_labelDisplay->setToolTip(d->m_showToolTipOnLabel ? displayedString : toolTip());
|
2019-07-23 13:44:11 +02:00
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2020-03-19 15:31:27 +01:00
|
|
|
validateInput();
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-01 09:25:13 +02:00
|
|
|
/*!
|
|
|
|
|
Adds a check box with a \a checkerLabel according to \a checkBoxPlacement
|
|
|
|
|
to the line edit.
|
|
|
|
|
|
|
|
|
|
The state of the check box is made persistent when using a non-emtpy
|
|
|
|
|
\a checkerKey.
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::makeCheckable(CheckBoxPlacement checkBoxPlacement,
|
2019-11-26 17:11:01 +01:00
|
|
|
const QString &checkerLabel, const QString &checkerKey)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!d->m_checker, return);
|
2019-11-26 17:11:01 +01:00
|
|
|
d->m_checkBoxPlacement = checkBoxPlacement;
|
2020-08-13 09:16:00 +02:00
|
|
|
d->m_checker.reset(new BoolAspect);
|
2019-11-26 17:11:01 +01:00
|
|
|
d->m_checker->setLabel(checkerLabel, checkBoxPlacement == CheckBoxPlacement::Top
|
2020-08-13 09:16:00 +02:00
|
|
|
? BoolAspect::LabelPlacement::InExtraLabel
|
|
|
|
|
: BoolAspect::LabelPlacement::AtCheckBox);
|
2018-09-17 15:56:14 +02:00
|
|
|
d->m_checker->setSettingsKey(checkerKey);
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
connect(d->m_checker.get(), &BoolAspect::changed, this, &StringAspect::update);
|
|
|
|
|
connect(d->m_checker.get(), &BoolAspect::changed, this, &StringAspect::changed);
|
|
|
|
|
connect(d->m_checker.get(), &BoolAspect::changed, this, &StringAspect::checkedChanged);
|
2018-09-17 15:56:14 +02:00
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-09-18 12:11:40 +02:00
|
|
|
\class Utils::BoolAspect
|
2020-09-21 09:39:54 +02:00
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief A boolean aspect is a boolean property of some object, together with
|
|
|
|
|
a description of its behavior for common operations like visualizing or
|
|
|
|
|
persisting.
|
|
|
|
|
|
|
|
|
|
The boolean aspect is displayed using a QCheckBox.
|
|
|
|
|
|
|
|
|
|
The visual representation often contains a label in front or after
|
|
|
|
|
the display of the actual checkmark.
|
2018-09-17 15:56:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
BoolAspect::BoolAspect(const QString &settingsKey)
|
|
|
|
|
: d(new Internal::BoolAspectPrivate)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
setDefaultValue(false);
|
2018-09-17 15:56:14 +02:00
|
|
|
setSettingsKey(settingsKey);
|
2021-04-08 15:44:45 +02:00
|
|
|
setSpan(2, 1);
|
2022-04-08 11:35:54 +02:00
|
|
|
|
|
|
|
|
addDataExtractor(this, &BoolAspect::value, &Data::value);
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
BoolAspect::~BoolAspect() = default;
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void BoolAspect::addToLayout(LayoutBuilder &builder)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
QTC_CHECK(!d->m_checkBox);
|
2020-12-17 16:29:46 +01:00
|
|
|
d->m_checkBox = createSubWidget<QCheckBox>();
|
2020-08-17 10:30:36 +02:00
|
|
|
switch (d->m_labelPlacement) {
|
|
|
|
|
case LabelPlacement::AtCheckBoxWithoutDummyLabel:
|
2021-02-17 16:48:10 +01:00
|
|
|
d->m_checkBox->setText(labelText());
|
2021-02-18 14:18:34 +01:00
|
|
|
builder.addItem(d->m_checkBox.data());
|
2020-08-17 10:30:36 +02:00
|
|
|
break;
|
2021-03-11 19:02:42 +01:00
|
|
|
case LabelPlacement::AtCheckBox: {
|
2021-02-17 16:48:10 +01:00
|
|
|
d->m_checkBox->setText(labelText());
|
2021-03-11 19:02:42 +01:00
|
|
|
LayoutBuilder::LayoutType type = builder.layoutType();
|
|
|
|
|
if (type == LayoutBuilder::FormLayout)
|
|
|
|
|
builder.addItem(createSubWidget<QLabel>());
|
2021-02-18 14:18:34 +01:00
|
|
|
builder.addItem(d->m_checkBox.data());
|
2020-08-17 10:30:36 +02:00
|
|
|
break;
|
2021-03-11 19:02:42 +01:00
|
|
|
}
|
2020-08-17 10:30:36 +02:00
|
|
|
case LabelPlacement::InExtraLabel:
|
2021-02-18 14:18:34 +01:00
|
|
|
addLabeledItem(builder, d->m_checkBox);
|
2020-08-17 10:30:36 +02:00
|
|
|
break;
|
2019-11-26 17:11:01 +01:00
|
|
|
}
|
2021-02-17 14:11:58 +01:00
|
|
|
d->m_checkBox->setChecked(value());
|
2021-02-18 14:18:34 +01:00
|
|
|
if (isAutoApply()) {
|
|
|
|
|
connect(d->m_checkBox.data(), &QAbstractButton::clicked,
|
|
|
|
|
this, [this](bool val) { setValue(val); });
|
|
|
|
|
}
|
2021-03-31 10:36:25 +02:00
|
|
|
connect(d->m_checkBox.data(), &QAbstractButton::clicked,
|
|
|
|
|
this, &BoolAspect::volatileValueChanged);
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *BoolAspect::action()
|
|
|
|
|
{
|
|
|
|
|
if (hasAction())
|
|
|
|
|
return BaseAspect::action();
|
|
|
|
|
auto act = BaseAspect::action(); // Creates it.
|
|
|
|
|
act->setCheckable(true);
|
|
|
|
|
act->setChecked(value());
|
2021-11-16 16:32:28 +01:00
|
|
|
act->setToolTip(toolTip());
|
2021-02-18 14:18:34 +01:00
|
|
|
connect(act, &QAction::triggered, this, [this](bool newValue) {
|
2021-03-02 17:07:58 +01:00
|
|
|
// The check would be nice to have in simple conditions, but if we
|
|
|
|
|
// have an action that's used both on a settings page and as action
|
|
|
|
|
// in a menu like "Use FakeVim", isAutoApply() is false, and yet this
|
|
|
|
|
// here can trigger.
|
|
|
|
|
//QTC_CHECK(isAutoApply());
|
2021-02-18 14:18:34 +01:00
|
|
|
setValue(newValue);
|
2018-09-17 15:56:14 +02:00
|
|
|
});
|
2021-02-18 14:18:34 +01:00
|
|
|
return act;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant BoolAspect::volatileValue() const
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!isAutoApply());
|
2021-04-06 11:51:14 +02:00
|
|
|
if (d->m_checkBox)
|
|
|
|
|
return d->m_checkBox->isChecked();
|
|
|
|
|
if (d->m_groupBox)
|
|
|
|
|
return d->m_groupBox->isChecked();
|
|
|
|
|
QTC_CHECK(false);
|
|
|
|
|
return {};
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BoolAspect::setVolatileValue(const QVariant &val)
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!isAutoApply());
|
|
|
|
|
if (d->m_checkBox)
|
|
|
|
|
d->m_checkBox->setChecked(val.toBool());
|
2021-04-06 11:51:14 +02:00
|
|
|
else if (d->m_groupBox)
|
|
|
|
|
d->m_groupBox->setChecked(val.toBool());
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-01 06:35:08 +01:00
|
|
|
void BoolAspect::emitChangedValue()
|
|
|
|
|
{
|
|
|
|
|
emit valueChanged(value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
bool BoolAspect::value() const
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
return BaseAspect::value().toBool();
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void BoolAspect::setValue(bool value)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
if (BaseAspect::setValueQuietly(value)) {
|
|
|
|
|
if (d->m_checkBox)
|
|
|
|
|
d->m_checkBox->setChecked(value);
|
2021-02-18 14:18:34 +01:00
|
|
|
//qDebug() << "SetValue: Changing" << labelText() << " to " << value;
|
2021-02-17 14:11:58 +01:00
|
|
|
emit changed();
|
2021-02-18 14:18:34 +01:00
|
|
|
//QTC_CHECK(!labelText().isEmpty());
|
|
|
|
|
emit valueChanged(value);
|
|
|
|
|
//qDebug() << "SetValue: Changed" << labelText() << " to " << value;
|
|
|
|
|
if (hasAction()) {
|
|
|
|
|
//qDebug() << "SetValue: Triggering " << labelText() << "with" << value;
|
|
|
|
|
emit action()->triggered(value);
|
|
|
|
|
}
|
2021-02-17 14:11:58 +01:00
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
void BoolAspect::setDefaultValue(bool val)
|
|
|
|
|
{
|
|
|
|
|
BaseAspect::setDefaultValue(val);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void BoolAspect::setLabel(const QString &labelText, LabelPlacement labelPlacement)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2021-02-17 16:48:10 +01:00
|
|
|
BaseAspect::setLabelText(labelText);
|
2019-11-26 17:11:01 +01:00
|
|
|
d->m_labelPlacement = labelPlacement;
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
void BoolAspect::setLabelPlacement(BoolAspect::LabelPlacement labelPlacement)
|
|
|
|
|
{
|
|
|
|
|
d->m_labelPlacement = labelPlacement;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 11:51:14 +02:00
|
|
|
void BoolAspect::setHandlesGroup(QGroupBox *box)
|
|
|
|
|
{
|
|
|
|
|
registerSubWidget(box);
|
|
|
|
|
d->m_groupBox = box;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 18:25:17 +02:00
|
|
|
/*!
|
2020-09-18 12:11:40 +02:00
|
|
|
\class Utils::SelectionAspect
|
2020-09-21 09:39:54 +02:00
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief A selection aspect represents a specific choice out of
|
|
|
|
|
several.
|
|
|
|
|
|
|
|
|
|
The selection aspect is displayed using a QComboBox or
|
|
|
|
|
QRadioButtons in a QButtonGroup.
|
2019-06-13 18:25:17 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
SelectionAspect::SelectionAspect()
|
|
|
|
|
: d(new Internal::SelectionAspectPrivate)
|
2021-04-08 15:44:45 +02:00
|
|
|
{
|
|
|
|
|
setSpan(2, 1);
|
|
|
|
|
}
|
2019-06-13 18:25:17 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
SelectionAspect::~SelectionAspect() = default;
|
2019-06-13 18:25:17 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void SelectionAspect::addToLayout(LayoutBuilder &builder)
|
2019-06-13 18:25:17 +02:00
|
|
|
{
|
|
|
|
|
QTC_CHECK(d->m_buttonGroup == nullptr);
|
2019-11-25 12:46:08 +01:00
|
|
|
QTC_CHECK(!d->m_comboBox);
|
2019-06-13 18:25:17 +02:00
|
|
|
QTC_ASSERT(d->m_buttons.isEmpty(), d->m_buttons.clear());
|
2019-11-25 12:46:08 +01:00
|
|
|
|
|
|
|
|
switch (d->m_displayStyle) {
|
|
|
|
|
case DisplayStyle::RadioButtons:
|
2020-12-17 16:29:46 +01:00
|
|
|
d->m_buttonGroup = new QButtonGroup();
|
2019-11-25 12:46:08 +01:00
|
|
|
d->m_buttonGroup->setExclusive(true);
|
|
|
|
|
for (int i = 0, n = d->m_options.size(); i < n; ++i) {
|
2021-03-26 18:16:08 +01:00
|
|
|
const Option &option = d->m_options.at(i);
|
2021-03-23 16:10:56 +01:00
|
|
|
auto button = createSubWidget<QRadioButton>(option.displayName);
|
2021-02-17 14:11:58 +01:00
|
|
|
button->setChecked(i == value());
|
2021-03-26 18:16:08 +01:00
|
|
|
button->setEnabled(option.enabled);
|
2019-11-25 12:46:08 +01:00
|
|
|
button->setToolTip(option.tooltip);
|
2022-07-25 17:56:47 +02:00
|
|
|
builder.addItems({Layouting::empty, button});
|
2019-11-25 12:46:08 +01:00
|
|
|
d->m_buttons.append(button);
|
2021-03-04 13:13:49 +01:00
|
|
|
d->m_buttonGroup->addButton(button, i);
|
2021-03-22 17:59:39 +01:00
|
|
|
if (isAutoApply()) {
|
|
|
|
|
connect(button, &QAbstractButton::clicked, this, [this, i] {
|
|
|
|
|
setValue(i);
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-11-25 12:46:08 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DisplayStyle::ComboBox:
|
2021-02-17 16:48:10 +01:00
|
|
|
setLabelText(displayName());
|
2020-12-17 16:29:46 +01:00
|
|
|
d->m_comboBox = createSubWidget<QComboBox>();
|
2019-11-25 12:46:08 +01:00
|
|
|
for (int i = 0, n = d->m_options.size(); i < n; ++i)
|
|
|
|
|
d->m_comboBox->addItem(d->m_options.at(i).displayName);
|
2021-03-22 17:59:39 +01:00
|
|
|
if (isAutoApply()) {
|
2022-07-19 22:32:39 +02:00
|
|
|
connect(d->m_comboBox.data(), &QComboBox::activated,
|
2021-03-22 17:59:39 +01:00
|
|
|
this, &SelectionAspect::setValue);
|
|
|
|
|
}
|
2022-07-19 22:32:39 +02:00
|
|
|
connect(d->m_comboBox.data(), &QComboBox::currentIndexChanged,
|
2021-04-01 09:20:49 +02:00
|
|
|
this, &SelectionAspect::volatileValueChanged);
|
2021-02-17 14:11:58 +01:00
|
|
|
d->m_comboBox->setCurrentIndex(value());
|
2021-02-18 14:18:34 +01:00
|
|
|
addLabeledItem(builder, d->m_comboBox);
|
2019-11-25 12:46:08 +01:00
|
|
|
break;
|
2019-06-13 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 13:13:49 +01:00
|
|
|
QVariant SelectionAspect::volatileValue() const
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!isAutoApply());
|
|
|
|
|
switch (d->m_displayStyle) {
|
|
|
|
|
case DisplayStyle::RadioButtons:
|
|
|
|
|
QTC_ASSERT(d->m_buttonGroup, return {});
|
|
|
|
|
return d->m_buttonGroup->checkedId();
|
|
|
|
|
case DisplayStyle::ComboBox:
|
|
|
|
|
QTC_ASSERT(d->m_comboBox, return {});
|
|
|
|
|
return d->m_comboBox->currentIndex();
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SelectionAspect::setVolatileValue(const QVariant &val)
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!isAutoApply());
|
|
|
|
|
switch (d->m_displayStyle) {
|
|
|
|
|
case DisplayStyle::RadioButtons: {
|
|
|
|
|
if (d->m_buttonGroup) {
|
|
|
|
|
QAbstractButton *button = d->m_buttonGroup->button(val.toInt());
|
|
|
|
|
QTC_ASSERT(button, return);
|
|
|
|
|
button->setChecked(true);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DisplayStyle::ComboBox:
|
|
|
|
|
if (d->m_comboBox)
|
|
|
|
|
d->m_comboBox->setCurrentIndex(val.toInt());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-24 05:41:03 +01:00
|
|
|
void SelectionAspect::finish()
|
|
|
|
|
{
|
|
|
|
|
delete d->m_buttonGroup;
|
2021-03-29 14:20:50 +02:00
|
|
|
d->m_buttonGroup = nullptr;
|
|
|
|
|
BaseAspect::finish();
|
2021-04-01 11:02:32 +02:00
|
|
|
d->m_buttons.clear();
|
2021-03-24 05:41:03 +01:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void SelectionAspect::setDisplayStyle(SelectionAspect::DisplayStyle style)
|
2019-11-25 12:46:08 +01:00
|
|
|
{
|
|
|
|
|
d->m_displayStyle = style;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
int SelectionAspect::value() const
|
2019-06-13 18:25:17 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
return BaseAspect::value().toInt();
|
2019-06-13 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void SelectionAspect::setValue(int value)
|
2019-06-13 18:25:17 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
if (BaseAspect::setValueQuietly(value)) {
|
|
|
|
|
if (d->m_buttonGroup && 0 <= value && value < d->m_buttons.size())
|
|
|
|
|
d->m_buttons.at(value)->setChecked(true);
|
|
|
|
|
else if (d->m_comboBox)
|
|
|
|
|
d->m_comboBox->setCurrentIndex(value);
|
|
|
|
|
emit changed();
|
2019-11-25 12:46:08 +01:00
|
|
|
}
|
2019-06-13 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-22 17:40:44 +01:00
|
|
|
void SelectionAspect::setStringValue(const QString &val)
|
|
|
|
|
{
|
|
|
|
|
const int index = indexForDisplay(val);
|
|
|
|
|
QTC_ASSERT(index >= 0, return);
|
|
|
|
|
setValue(index);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
void SelectionAspect::setDefaultValue(int val)
|
|
|
|
|
{
|
|
|
|
|
BaseAspect::setDefaultValue(val);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 17:40:44 +01:00
|
|
|
// Note: This needs to be set after all options are added.
|
|
|
|
|
void SelectionAspect::setDefaultValue(const QString &val)
|
|
|
|
|
{
|
|
|
|
|
BaseAspect::setDefaultValue(indexForDisplay(val));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
QString SelectionAspect::stringValue() const
|
2020-07-29 07:00:50 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
return d->m_options.at(value()).displayName;
|
2020-07-29 07:00:50 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-06 16:07:32 +02:00
|
|
|
QVariant SelectionAspect::itemValue() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_options.at(value()).itemData;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void SelectionAspect::addOption(const QString &displayName, const QString &toolTip)
|
2019-06-13 18:25:17 +02:00
|
|
|
{
|
2021-04-06 16:07:32 +02:00
|
|
|
d->m_options.append(Option(displayName, toolTip, {}));
|
2019-06-13 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-26 18:16:08 +01:00
|
|
|
void SelectionAspect::addOption(const Option &option)
|
|
|
|
|
{
|
|
|
|
|
d->m_options.append(option);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 17:40:44 +01:00
|
|
|
int SelectionAspect::indexForDisplay(const QString &displayName) const
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0, n = d->m_options.size(); i < n; ++i) {
|
|
|
|
|
if (d->m_options.at(i).displayName == displayName)
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SelectionAspect::displayForIndex(int index) const
|
|
|
|
|
{
|
2021-03-24 14:47:32 +01:00
|
|
|
QTC_ASSERT(index >= 0 && index < d->m_options.size(), return {});
|
2021-03-22 17:40:44 +01:00
|
|
|
return d->m_options.at(index).displayName;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-16 10:18:58 +02:00
|
|
|
int SelectionAspect::indexForItemValue(const QVariant &value) const
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0, n = d->m_options.size(); i < n; ++i) {
|
|
|
|
|
if (d->m_options.at(i).itemData == value)
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant SelectionAspect::itemValueForIndex(int index) const
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(index >= 0 && index < d->m_options.size(), return {});
|
|
|
|
|
return d->m_options.at(index).itemData;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 13:28:48 +01:00
|
|
|
/*!
|
|
|
|
|
\class Utils::MultiSelectionAspect
|
|
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief A multi-selection aspect represents one or more choices out of
|
|
|
|
|
several.
|
|
|
|
|
|
|
|
|
|
The multi-selection aspect is displayed using a QListWidget with
|
|
|
|
|
checkable items.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
MultiSelectionAspect::MultiSelectionAspect()
|
2021-02-17 14:11:58 +01:00
|
|
|
: d(new Internal::MultiSelectionAspectPrivate(this))
|
|
|
|
|
{
|
|
|
|
|
setDefaultValue(QStringList());
|
2021-04-08 15:44:45 +02:00
|
|
|
setSpan(2, 1);
|
2021-02-17 14:11:58 +01:00
|
|
|
}
|
2020-12-17 13:28:48 +01:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
|
|
|
|
MultiSelectionAspect::~MultiSelectionAspect() = default;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
|
|
|
|
void MultiSelectionAspect::addToLayout(LayoutBuilder &builder)
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(d->m_listView == nullptr);
|
|
|
|
|
if (d->m_allValues.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (d->m_displayStyle) {
|
|
|
|
|
case DisplayStyle::ListView:
|
2020-12-17 16:29:46 +01:00
|
|
|
d->m_listView = createSubWidget<QListWidget>();
|
2021-02-17 14:11:58 +01:00
|
|
|
for (const QString &val : qAsConst(d->m_allValues)) {
|
|
|
|
|
auto item = new QListWidgetItem(val, d->m_listView);
|
2020-12-17 13:28:48 +01:00
|
|
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
2021-02-17 14:11:58 +01:00
|
|
|
item->setCheckState(value().contains(item->text()) ? Qt::Checked : Qt::Unchecked);
|
2020-12-17 13:28:48 +01:00
|
|
|
}
|
|
|
|
|
connect(d->m_listView, &QListWidget::itemChanged, this,
|
|
|
|
|
[this](QListWidgetItem *item) {
|
|
|
|
|
if (d->setValueSelectedHelper(item->text(), item->checkState() & Qt::Checked))
|
|
|
|
|
emit changed();
|
|
|
|
|
});
|
2021-02-18 14:18:34 +01:00
|
|
|
addLabeledItem(builder, d->m_listView);
|
2020-12-17 13:28:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-17 14:11:58 +01:00
|
|
|
bool Internal::MultiSelectionAspectPrivate::setValueSelectedHelper(const QString &val, bool on)
|
2020-12-17 13:28:48 +01:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
QStringList list = q->value();
|
|
|
|
|
if (on && !list.contains(val)) {
|
|
|
|
|
list.append(val);
|
|
|
|
|
q->setValue(list);
|
2020-12-17 13:28:48 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2021-02-17 14:11:58 +01:00
|
|
|
if (!on && list.contains(val)) {
|
|
|
|
|
list.removeOne(val);
|
|
|
|
|
q->setValue(list);
|
2020-12-17 13:28:48 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList MultiSelectionAspect::allValues() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_allValues;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MultiSelectionAspect::setAllValues(const QStringList &val)
|
|
|
|
|
{
|
|
|
|
|
d->m_allValues = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MultiSelectionAspect::setDisplayStyle(MultiSelectionAspect::DisplayStyle style)
|
|
|
|
|
{
|
|
|
|
|
d->m_displayStyle = style;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList MultiSelectionAspect::value() const
|
|
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
return BaseAspect::value().toStringList();
|
2020-12-17 13:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MultiSelectionAspect::setValue(const QStringList &value)
|
|
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
if (BaseAspect::setValueQuietly(value)) {
|
|
|
|
|
if (d->m_listView) {
|
|
|
|
|
const int n = d->m_listView->count();
|
|
|
|
|
QTC_CHECK(n == d->m_allValues.size());
|
|
|
|
|
for (int i = 0; i != n; ++i) {
|
|
|
|
|
auto item = d->m_listView->item(i);
|
|
|
|
|
item->setCheckState(value.contains(item->text()) ? Qt::Checked : Qt::Unchecked);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
emit changed();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-17 13:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-09-25 08:24:10 +02:00
|
|
|
/*!
|
2020-09-18 12:11:40 +02:00
|
|
|
\class Utils::IntegerAspect
|
2020-09-21 09:39:54 +02:00
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief An integer aspect is a integral property of some object, together with
|
|
|
|
|
a description of its behavior for common operations like visualizing or
|
|
|
|
|
persisting.
|
|
|
|
|
|
|
|
|
|
The integer aspect is displayed using a \c QSpinBox.
|
|
|
|
|
|
|
|
|
|
The visual representation often contains a label in front
|
|
|
|
|
the display of the spin box.
|
2018-09-25 08:24:10 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
// IntegerAspect
|
2018-09-25 08:24:10 +02:00
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
IntegerAspect::IntegerAspect()
|
|
|
|
|
: d(new Internal::IntegerAspectPrivate)
|
2021-02-17 14:11:58 +01:00
|
|
|
{
|
|
|
|
|
setDefaultValue(qint64(0));
|
2021-04-08 15:44:45 +02:00
|
|
|
setSpan(2, 1);
|
2022-04-08 11:35:54 +02:00
|
|
|
|
|
|
|
|
addDataExtractor(this, &IntegerAspect::value, &Data::value);
|
2021-02-17 14:11:58 +01:00
|
|
|
}
|
2018-09-25 08:24:10 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
IntegerAspect::~IntegerAspect() = default;
|
2018-09-25 08:24:10 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::addToLayout(LayoutBuilder &builder)
|
2018-09-25 08:24:10 +02:00
|
|
|
{
|
|
|
|
|
QTC_CHECK(!d->m_spinBox);
|
2020-12-17 16:29:46 +01:00
|
|
|
d->m_spinBox = createSubWidget<QSpinBox>();
|
2018-09-25 08:24:10 +02:00
|
|
|
d->m_spinBox->setDisplayIntegerBase(d->m_displayIntegerBase);
|
|
|
|
|
d->m_spinBox->setPrefix(d->m_prefix);
|
|
|
|
|
d->m_spinBox->setSuffix(d->m_suffix);
|
2021-02-18 14:18:34 +01:00
|
|
|
d->m_spinBox->setSingleStep(d->m_singleStep);
|
|
|
|
|
d->m_spinBox->setSpecialValueText(d->m_specialValueText);
|
2021-03-02 07:03:57 +01:00
|
|
|
if (d->m_maximumValue && d->m_maximumValue)
|
|
|
|
|
d->m_spinBox->setRange(int(d->m_minimumValue.value() / d->m_displayScaleFactor),
|
|
|
|
|
int(d->m_maximumValue.value() / d->m_displayScaleFactor));
|
|
|
|
|
d->m_spinBox->setValue(int(value() / d->m_displayScaleFactor)); // Must happen after setRange()
|
2021-02-18 14:18:34 +01:00
|
|
|
addLabeledItem(builder, d->m_spinBox);
|
2020-07-21 08:51:38 +02:00
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
if (isAutoApply()) {
|
2022-07-19 22:32:39 +02:00
|
|
|
connect(d->m_spinBox.data(), &QSpinBox::valueChanged,
|
2021-03-04 12:32:49 +01:00
|
|
|
this, [this] { setValue(d->m_spinBox->value()); });
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant IntegerAspect::volatileValue() const
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!isAutoApply());
|
|
|
|
|
QTC_ASSERT(d->m_spinBox, return {});
|
|
|
|
|
return d->m_spinBox->value() * d->m_displayScaleFactor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IntegerAspect::setVolatileValue(const QVariant &val)
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!isAutoApply());
|
|
|
|
|
if (d->m_spinBox)
|
|
|
|
|
d->m_spinBox->setValue(int(val.toLongLong() / d->m_displayScaleFactor));
|
2018-09-25 08:24:10 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
qint64 IntegerAspect::value() const
|
2018-09-25 08:24:10 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
return BaseAspect::value().toLongLong();
|
2018-09-25 08:24:10 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::setValue(qint64 value)
|
2018-09-25 08:24:10 +02:00
|
|
|
{
|
2022-07-06 21:41:21 +02:00
|
|
|
if (BaseAspect::setValueQuietly(value)) {
|
|
|
|
|
if (d->m_spinBox)
|
|
|
|
|
d->m_spinBox->setValue(value);
|
|
|
|
|
//qDebug() << "SetValue: Changing" << labelText() << " to " << value;
|
|
|
|
|
emit changed();
|
|
|
|
|
//QTC_CHECK(!labelText().isEmpty());
|
|
|
|
|
emit valueChanged(value);
|
|
|
|
|
//qDebug() << "SetValue: Changed" << labelText() << " to " << value;
|
|
|
|
|
}
|
2018-09-25 08:24:10 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::setRange(qint64 min, qint64 max)
|
2018-09-25 08:24:10 +02:00
|
|
|
{
|
|
|
|
|
d->m_minimumValue = min;
|
|
|
|
|
d->m_maximumValue = max;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::setLabel(const QString &label)
|
2018-09-25 08:24:10 +02:00
|
|
|
{
|
2021-02-17 16:48:10 +01:00
|
|
|
setLabelText(label);
|
2018-09-25 08:24:10 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::setPrefix(const QString &prefix)
|
2018-09-25 08:24:10 +02:00
|
|
|
{
|
|
|
|
|
d->m_prefix = prefix;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::setSuffix(const QString &suffix)
|
2018-09-25 08:24:10 +02:00
|
|
|
{
|
|
|
|
|
d->m_suffix = suffix;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::setDisplayIntegerBase(int base)
|
2018-09-25 08:24:10 +02:00
|
|
|
{
|
|
|
|
|
d->m_displayIntegerBase = base;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::setDisplayScaleFactor(qint64 factor)
|
2019-04-24 12:15:31 +02:00
|
|
|
{
|
|
|
|
|
d->m_displayScaleFactor = factor;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::setDefaultValue(qint64 defaultValue)
|
2020-07-21 08:54:39 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
BaseAspect::setDefaultValue(defaultValue);
|
2020-07-21 08:54:39 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
void IntegerAspect::setSpecialValueText(const QString &specialText)
|
|
|
|
|
{
|
|
|
|
|
d->m_specialValueText = specialText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IntegerAspect::setSingleStep(qint64 step)
|
|
|
|
|
{
|
|
|
|
|
d->m_singleStep = step;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-03-01 08:45:29 +01:00
|
|
|
/*!
|
|
|
|
|
\class Utils::DoubleAspect
|
|
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief An double aspect is a numerical property of some object, together with
|
|
|
|
|
a description of its behavior for common operations like visualizing or
|
|
|
|
|
persisting.
|
|
|
|
|
|
|
|
|
|
The double aspect is displayed using a \c QDoubleSpinBox.
|
|
|
|
|
|
|
|
|
|
The visual representation often contains a label in front
|
|
|
|
|
the display of the spin box.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
DoubleAspect::DoubleAspect()
|
|
|
|
|
: d(new Internal::DoubleAspectPrivate)
|
|
|
|
|
{
|
|
|
|
|
setDefaultValue(double(0));
|
2021-04-08 15:44:45 +02:00
|
|
|
setSpan(2, 1);
|
2021-03-01 08:45:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
|
|
|
|
DoubleAspect::~DoubleAspect() = default;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
|
|
|
|
void DoubleAspect::addToLayout(LayoutBuilder &builder)
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!d->m_spinBox);
|
|
|
|
|
d->m_spinBox = createSubWidget<QDoubleSpinBox>();
|
|
|
|
|
d->m_spinBox->setPrefix(d->m_prefix);
|
|
|
|
|
d->m_spinBox->setSuffix(d->m_suffix);
|
|
|
|
|
d->m_spinBox->setSingleStep(d->m_singleStep);
|
|
|
|
|
d->m_spinBox->setSpecialValueText(d->m_specialValueText);
|
|
|
|
|
if (d->m_maximumValue && d->m_maximumValue)
|
|
|
|
|
d->m_spinBox->setRange(d->m_minimumValue.value(), d->m_maximumValue.value());
|
2021-03-02 07:03:57 +01:00
|
|
|
d->m_spinBox->setValue(value()); // Must happen after setRange()!
|
2021-03-01 08:45:29 +01:00
|
|
|
addLabeledItem(builder, d->m_spinBox);
|
|
|
|
|
|
|
|
|
|
if (isAutoApply()) {
|
2022-07-19 22:32:39 +02:00
|
|
|
connect(d->m_spinBox.data(), &QDoubleSpinBox::valueChanged,
|
2021-03-01 08:45:29 +01:00
|
|
|
this, [this] { setValue(d->m_spinBox->value()); });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant DoubleAspect::volatileValue() const
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!isAutoApply());
|
|
|
|
|
QTC_ASSERT(d->m_spinBox, return {});
|
|
|
|
|
return d->m_spinBox->value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DoubleAspect::setVolatileValue(const QVariant &val)
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!isAutoApply());
|
|
|
|
|
if (d->m_spinBox)
|
|
|
|
|
d->m_spinBox->setValue(val.toDouble());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double DoubleAspect::value() const
|
|
|
|
|
{
|
|
|
|
|
return BaseAspect::value().toDouble();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DoubleAspect::setValue(double value)
|
|
|
|
|
{
|
|
|
|
|
BaseAspect::setValue(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DoubleAspect::setRange(double min, double max)
|
|
|
|
|
{
|
|
|
|
|
d->m_minimumValue = min;
|
|
|
|
|
d->m_maximumValue = max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DoubleAspect::setPrefix(const QString &prefix)
|
|
|
|
|
{
|
|
|
|
|
d->m_prefix = prefix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DoubleAspect::setSuffix(const QString &suffix)
|
|
|
|
|
{
|
|
|
|
|
d->m_suffix = suffix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DoubleAspect::setDefaultValue(double defaultValue)
|
|
|
|
|
{
|
|
|
|
|
BaseAspect::setDefaultValue(defaultValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DoubleAspect::setSpecialValueText(const QString &specialText)
|
|
|
|
|
{
|
|
|
|
|
d->m_specialValueText = specialText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DoubleAspect::setSingleStep(double step)
|
|
|
|
|
{
|
|
|
|
|
d->m_singleStep = step;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 22:36:16 +02:00
|
|
|
/*!
|
2020-09-18 12:11:40 +02:00
|
|
|
\class Utils::BaseTristateAspect
|
2020-09-21 09:39:54 +02:00
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief A tristate aspect is a property of some object that can have
|
|
|
|
|
three values: enabled, disabled, and unspecified.
|
|
|
|
|
|
|
|
|
|
Its visual representation is a QComboBox with three items.
|
2020-07-28 22:36:16 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-10-15 17:07:00 +02:00
|
|
|
TriStateAspect::TriStateAspect(const QString onString, const QString &offString,
|
|
|
|
|
const QString &defaultString)
|
2019-11-25 13:31:27 +01:00
|
|
|
{
|
|
|
|
|
setDisplayStyle(DisplayStyle::ComboBox);
|
2021-02-22 07:41:51 +01:00
|
|
|
setDefaultValue(TriState::Default);
|
2020-10-15 17:07:00 +02:00
|
|
|
addOption(onString);
|
|
|
|
|
addOption(offString);
|
|
|
|
|
addOption(defaultString);
|
2019-11-25 13:31:27 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-22 07:41:51 +01:00
|
|
|
TriState TriStateAspect::value() const
|
2019-11-25 13:31:27 +01:00
|
|
|
{
|
2021-02-22 07:41:51 +01:00
|
|
|
return TriState::fromVariant(BaseAspect::value());
|
2019-11-25 13:31:27 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-22 07:41:51 +01:00
|
|
|
void TriStateAspect::setValue(TriState value)
|
2019-11-25 13:31:27 +01:00
|
|
|
{
|
2022-06-07 10:06:39 +02:00
|
|
|
SelectionAspect::setValue(value.toInt());
|
2021-02-22 07:41:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TriStateAspect::setDefaultValue(TriState value)
|
|
|
|
|
{
|
|
|
|
|
BaseAspect::setDefaultValue(value.toVariant());
|
2019-11-15 16:20:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TriState TriState::Enabled{TriState::EnabledValue};
|
|
|
|
|
const TriState TriState::Disabled{TriState::DisabledValue};
|
|
|
|
|
const TriState TriState::Default{TriState::DefaultValue};
|
|
|
|
|
|
|
|
|
|
TriState TriState::fromVariant(const QVariant &variant)
|
|
|
|
|
{
|
|
|
|
|
int v = variant.toInt();
|
|
|
|
|
QTC_ASSERT(v == EnabledValue || v == DisabledValue || v == DefaultValue, v = DefaultValue);
|
|
|
|
|
return TriState(Value(v));
|
2019-11-25 13:31:27 +01:00
|
|
|
}
|
|
|
|
|
|
2020-07-21 08:48:06 +02:00
|
|
|
|
|
|
|
|
/*!
|
2020-09-18 12:11:40 +02:00
|
|
|
\class Utils::StringListAspect
|
2020-09-21 09:39:54 +02:00
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief A string list aspect represents a property of some object
|
|
|
|
|
that is a list of strings.
|
2020-07-21 08:48:06 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
StringListAspect::StringListAspect()
|
|
|
|
|
: d(new Internal::StringListAspectPrivate)
|
2021-02-17 14:11:58 +01:00
|
|
|
{
|
|
|
|
|
setDefaultValue(QStringList());
|
|
|
|
|
}
|
2020-07-21 08:48:06 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
StringListAspect::~StringListAspect() = default;
|
2020-07-21 08:48:06 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringListAspect::addToLayout(LayoutBuilder &builder)
|
2020-07-21 08:48:06 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(builder)
|
|
|
|
|
// TODO - when needed.
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
QStringList StringListAspect::value() const
|
2020-07-21 08:48:06 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
return BaseAspect::value().toStringList();
|
2020-07-21 08:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringListAspect::setValue(const QStringList &value)
|
2020-07-21 08:48:06 +02:00
|
|
|
{
|
2021-02-17 14:11:58 +01:00
|
|
|
BaseAspect::setValue(value);
|
2020-07-21 08:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-01 08:48:25 +01:00
|
|
|
void StringListAspect::appendValue(const QString &s, bool allowDuplicates)
|
|
|
|
|
{
|
|
|
|
|
QStringList val = value();
|
|
|
|
|
if (allowDuplicates || !val.contains(s))
|
|
|
|
|
val.append(s);
|
|
|
|
|
setValue(val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StringListAspect::removeValue(const QString &s)
|
|
|
|
|
{
|
|
|
|
|
QStringList val = value();
|
|
|
|
|
val.removeAll(s);
|
|
|
|
|
setValue(val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StringListAspect::appendValues(const QStringList &values, bool allowDuplicates)
|
|
|
|
|
{
|
|
|
|
|
QStringList val = value();
|
|
|
|
|
for (const QString &s : values) {
|
|
|
|
|
if (allowDuplicates || !val.contains(s))
|
|
|
|
|
val.append(s);
|
|
|
|
|
}
|
|
|
|
|
setValue(val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StringListAspect::removeValues(const QStringList &values)
|
|
|
|
|
{
|
|
|
|
|
QStringList val = value();
|
|
|
|
|
for (const QString &s : values)
|
|
|
|
|
val.removeAll(s);
|
|
|
|
|
setValue(val);
|
|
|
|
|
}
|
2021-03-01 08:49:15 +01:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class Utils::IntegerListAspect
|
|
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief A string list aspect represents a property of some object
|
|
|
|
|
that is a list of strings.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
IntegersAspect::IntegersAspect()
|
|
|
|
|
{
|
|
|
|
|
setDefaultValue({});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
|
|
|
|
IntegersAspect::~IntegersAspect() = default;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
|
|
|
|
void IntegersAspect::addToLayout(LayoutBuilder &builder)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(builder)
|
|
|
|
|
// TODO - when needed.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IntegersAspect::emitChangedValue()
|
|
|
|
|
{
|
|
|
|
|
emit valueChanged(value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<int> IntegersAspect::value() const
|
|
|
|
|
{
|
2022-05-25 05:44:45 +02:00
|
|
|
return transform(BaseAspect::value().toList(),
|
2021-03-01 08:49:15 +01:00
|
|
|
[](QVariant v) { return v.toInt(); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IntegersAspect::setValue(const QList<int> &value)
|
|
|
|
|
{
|
2022-05-25 05:44:45 +02:00
|
|
|
BaseAspect::setValue(transform(value, &QVariant::fromValue<int>));
|
2021-03-01 08:49:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IntegersAspect::setDefaultValue(const QList<int> &value)
|
|
|
|
|
{
|
2022-05-25 05:44:45 +02:00
|
|
|
BaseAspect::setDefaultValue(transform(value, &QVariant::fromValue<int>));
|
2021-03-01 08:49:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-08-14 08:55:22 +02:00
|
|
|
/*!
|
2020-09-18 12:11:40 +02:00
|
|
|
\class Utils::TextDisplay
|
2020-09-21 09:39:54 +02:00
|
|
|
|
|
|
|
|
\brief A text display is a phony aspect with the sole purpose of providing
|
|
|
|
|
some text display using an Utils::InfoLabel in places where otherwise
|
|
|
|
|
more expensive Utils::StringAspect items would be used.
|
|
|
|
|
|
|
|
|
|
A text display does not have a real value.
|
2020-08-14 08:55:22 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Constructs a text display showing the \a message with an icon representing
|
|
|
|
|
type \a type.
|
|
|
|
|
*/
|
2020-08-20 15:54:21 +02:00
|
|
|
TextDisplay::TextDisplay(const QString &message, InfoLabel::InfoType type)
|
2020-08-14 08:55:22 +02:00
|
|
|
: d(new Internal::TextDisplayPrivate)
|
|
|
|
|
{
|
|
|
|
|
d->m_message = message;
|
2020-08-20 15:54:21 +02:00
|
|
|
d->m_type = type;
|
2020-08-14 08:55:22 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-14 08:55:22 +02:00
|
|
|
TextDisplay::~TextDisplay() = default;
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-14 08:55:22 +02:00
|
|
|
void TextDisplay::addToLayout(LayoutBuilder &builder)
|
|
|
|
|
{
|
|
|
|
|
if (!d->m_label) {
|
2020-12-17 16:29:46 +01:00
|
|
|
d->m_label = createSubWidget<InfoLabel>(d->m_message, d->m_type);
|
2020-08-14 08:55:22 +02:00
|
|
|
d->m_label->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
2020-08-20 15:54:21 +02:00
|
|
|
d->m_label->setElideMode(Qt::ElideNone);
|
|
|
|
|
d->m_label->setWordWrap(true);
|
2021-03-11 19:02:42 +01:00
|
|
|
// Do not use m_label->setVisible(isVisible()) unconditionally, it does not
|
|
|
|
|
// have a QWidget parent yet when used in a LayoutBuilder.
|
|
|
|
|
if (!isVisible())
|
|
|
|
|
d->m_label->setVisible(false);
|
2020-08-14 08:55:22 +02:00
|
|
|
}
|
|
|
|
|
builder.addItem(d->m_label.data());
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Sets \a t as the information label type for the visual representation
|
|
|
|
|
of this aspect.
|
|
|
|
|
*/
|
2020-08-20 15:54:21 +02:00
|
|
|
void TextDisplay::setIconType(InfoLabel::InfoType t)
|
|
|
|
|
{
|
|
|
|
|
d->m_type = t;
|
|
|
|
|
if (d->m_label)
|
|
|
|
|
d->m_label->setType(t);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
void TextDisplay::setText(const QString &message)
|
|
|
|
|
{
|
|
|
|
|
d->m_message = message;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-14 07:22:37 +02:00
|
|
|
/*!
|
2020-09-18 12:11:40 +02:00
|
|
|
\class Utils::AspectContainer
|
2020-09-21 09:39:54 +02:00
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief The AspectContainer class wraps one or more aspects while providing
|
|
|
|
|
the interface of a single aspect.
|
2021-03-31 08:57:26 +02:00
|
|
|
|
|
|
|
|
Sub-aspects ownership can be declared using \a setOwnsSubAspects.
|
2020-08-14 07:22:37 +02:00
|
|
|
*/
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class AspectContainerPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QList<BaseAspect *> m_items; // Not owned
|
2021-03-17 06:59:57 +01:00
|
|
|
bool m_autoApply = true;
|
2021-03-31 08:57:26 +02:00
|
|
|
bool m_ownsSubAspects = false;
|
2021-03-24 16:34:05 +01:00
|
|
|
QStringList m_settingsGroup;
|
2021-02-18 14:18:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
|
2021-03-31 12:37:34 +02:00
|
|
|
AspectContainer::AspectContainer(QObject *parent)
|
|
|
|
|
: QObject(parent), d(new Internal::AspectContainerPrivate)
|
2020-08-14 07:22:37 +02:00
|
|
|
{}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2021-03-31 08:57:26 +02:00
|
|
|
AspectContainer::~AspectContainer()
|
|
|
|
|
{
|
|
|
|
|
if (d->m_ownsSubAspects)
|
|
|
|
|
qDeleteAll(d->m_items);
|
|
|
|
|
}
|
2020-08-14 07:22:37 +02:00
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2021-02-18 14:18:34 +01:00
|
|
|
void AspectContainer::registerAspect(BaseAspect *aspect)
|
2020-08-14 07:22:37 +02:00
|
|
|
{
|
2021-03-17 06:59:57 +01:00
|
|
|
aspect->setAutoApply(d->m_autoApply);
|
2020-08-14 07:22:37 +02:00
|
|
|
d->m_items.append(aspect);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 08:03:49 +01:00
|
|
|
void AspectContainer::registerAspects(const AspectContainer &aspects)
|
2020-08-14 07:22:37 +02:00
|
|
|
{
|
2021-03-04 08:03:49 +01:00
|
|
|
for (BaseAspect *aspect : qAsConst(aspects.d->m_items))
|
2021-03-17 06:59:57 +01:00
|
|
|
registerAspect(aspect);
|
2020-08-14 07:22:37 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-31 08:57:26 +02:00
|
|
|
/*!
|
|
|
|
|
Retrieves a BaseAspect with a given \a id, or nullptr if no such aspect is contained.
|
|
|
|
|
|
|
|
|
|
\sa BaseAspect.
|
|
|
|
|
*/
|
|
|
|
|
BaseAspect *AspectContainer::aspect(Id id) const
|
|
|
|
|
{
|
2022-05-25 05:44:45 +02:00
|
|
|
return findOrDefault(d->m_items, equal(&BaseAspect::id, id));
|
2021-03-31 08:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AspectContainer::const_iterator AspectContainer::begin() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_items.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AspectContainer::const_iterator AspectContainer::end() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_items.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QList<BaseAspect *> &AspectContainer::aspects() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_items;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-14 07:22:37 +02:00
|
|
|
void AspectContainer::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
2021-02-16 15:01:44 +01:00
|
|
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
2020-08-14 07:22:37 +02:00
|
|
|
aspect->fromMap(map);
|
2021-04-06 18:35:27 +02:00
|
|
|
|
|
|
|
|
emit fromMapFinished();
|
|
|
|
|
|
2020-08-14 07:22:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AspectContainer::toMap(QVariantMap &map) const
|
|
|
|
|
{
|
2021-02-16 15:01:44 +01:00
|
|
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
2020-08-14 07:22:37 +02:00
|
|
|
aspect->toMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-24 11:16:18 +01:00
|
|
|
void AspectContainer::readSettings(QSettings *settings)
|
2021-02-18 14:18:34 +01:00
|
|
|
{
|
2021-03-24 16:34:05 +01:00
|
|
|
for (const QString &group : d->m_settingsGroup)
|
|
|
|
|
settings->beginGroup(group);
|
|
|
|
|
|
2021-03-24 11:16:18 +01:00
|
|
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
|
|
|
|
aspect->readSettings(settings);
|
2021-03-24 16:34:05 +01:00
|
|
|
|
|
|
|
|
for (int i = 0; i != d->m_settingsGroup.size(); ++i)
|
2021-03-24 11:16:18 +01:00
|
|
|
settings->endGroup();
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AspectContainer::writeSettings(QSettings *settings) const
|
|
|
|
|
{
|
2021-03-24 16:34:05 +01:00
|
|
|
for (const QString &group : d->m_settingsGroup)
|
|
|
|
|
settings->beginGroup(group);
|
|
|
|
|
|
2021-03-24 11:16:18 +01:00
|
|
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
|
|
|
|
aspect->writeSettings(settings);
|
2021-03-24 16:34:05 +01:00
|
|
|
|
|
|
|
|
for (int i = 0; i != d->m_settingsGroup.size(); ++i)
|
2021-03-22 15:11:30 +01:00
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-24 16:34:05 +01:00
|
|
|
void AspectContainer::setSettingsGroup(const QString &groupKey)
|
|
|
|
|
{
|
|
|
|
|
d->m_settingsGroup = QStringList{groupKey};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AspectContainer::setSettingsGroups(const QString &groupKey, const QString &subGroupKey)
|
2021-03-22 15:11:30 +01:00
|
|
|
{
|
2021-03-24 16:34:05 +01:00
|
|
|
d->m_settingsGroup = QStringList{groupKey, subGroupKey};
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AspectContainer::apply()
|
|
|
|
|
{
|
|
|
|
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
|
|
|
|
aspect->apply();
|
2021-03-31 12:37:34 +02:00
|
|
|
|
|
|
|
|
emit applied();
|
2021-02-18 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AspectContainer::cancel()
|
|
|
|
|
{
|
|
|
|
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
|
|
|
|
aspect->cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AspectContainer::finish()
|
|
|
|
|
{
|
|
|
|
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
|
|
|
|
aspect->finish();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 16:33:57 +01:00
|
|
|
void AspectContainer::reset()
|
|
|
|
|
{
|
|
|
|
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
|
|
|
|
aspect->setValueQuietly(aspect->defaultValue());
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
void AspectContainer::setAutoApply(bool on)
|
|
|
|
|
{
|
2021-03-17 06:59:57 +01:00
|
|
|
d->m_autoApply = on;
|
2021-02-18 14:18:34 +01:00
|
|
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
|
|
|
|
aspect->setAutoApply(on);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-31 08:57:26 +02:00
|
|
|
void AspectContainer::setOwnsSubAspects(bool on)
|
|
|
|
|
{
|
|
|
|
|
d->m_ownsSubAspects = on;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-16 06:01:09 +01:00
|
|
|
bool AspectContainer::isDirty() const
|
|
|
|
|
{
|
|
|
|
|
for (BaseAspect *aspect : qAsConst(d->m_items)) {
|
|
|
|
|
if (aspect->isDirty())
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 16:33:57 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 08:53:36 +01:00
|
|
|
void AspectContainer::forEachAspect(const std::function<void(BaseAspect *)> &run) const
|
2021-02-18 14:18:34 +01:00
|
|
|
{
|
|
|
|
|
for (BaseAspect *aspect : qAsConst(d->m_items)) {
|
|
|
|
|
if (auto container = dynamic_cast<AspectContainer *>(aspect))
|
|
|
|
|
container->forEachAspect(run);
|
|
|
|
|
else
|
|
|
|
|
run(aspect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 16:51:46 +02:00
|
|
|
BaseAspect::Data::Ptr BaseAspect::extractData() const
|
2022-04-08 11:35:54 +02:00
|
|
|
{
|
2022-04-08 15:12:24 +02:00
|
|
|
QTC_ASSERT(d->m_dataCreator, return {});
|
2022-04-08 11:35:54 +02:00
|
|
|
Data *data = d->m_dataCreator();
|
|
|
|
|
data->m_classId = metaObject();
|
|
|
|
|
data->m_id = id();
|
2022-04-08 15:12:24 +02:00
|
|
|
data->m_cloner = d->m_dataCloner;
|
2022-04-08 11:35:54 +02:00
|
|
|
for (const DataExtractor &extractor : d->m_dataExtractors)
|
2022-05-11 16:51:46 +02:00
|
|
|
extractor(data);
|
2022-04-08 15:12:24 +02:00
|
|
|
return Data::Ptr(data);
|
2022-04-08 11:35:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseAspect::addDataExtractorHelper(const DataExtractor &extractor) const
|
|
|
|
|
{
|
|
|
|
|
d->m_dataExtractors.append(extractor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseAspect::setDataCreatorHelper(const DataCreator &creator) const
|
|
|
|
|
{
|
|
|
|
|
d->m_dataCreator = creator;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 15:12:24 +02:00
|
|
|
void BaseAspect::setDataClonerHelper(const DataCloner &cloner) const
|
|
|
|
|
{
|
|
|
|
|
d->m_dataCloner = cloner;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 11:35:54 +02:00
|
|
|
const BaseAspect::Data *AspectContainerData::aspect(Id instanceId) const
|
|
|
|
|
{
|
2022-04-08 15:12:24 +02:00
|
|
|
for (const BaseAspect::Data::Ptr &data : m_data) {
|
|
|
|
|
if (data.get()->id() == instanceId)
|
|
|
|
|
return data.get();
|
2022-04-08 11:35:54 +02:00
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BaseAspect::Data *AspectContainerData::aspect(BaseAspect::Data::ClassId classId) const
|
|
|
|
|
{
|
2022-04-08 15:12:24 +02:00
|
|
|
for (const BaseAspect::Data::Ptr &data : m_data) {
|
|
|
|
|
if (data.get()->classId() == classId)
|
|
|
|
|
return data.get();
|
2022-04-08 11:35:54 +02:00
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 15:12:24 +02:00
|
|
|
void AspectContainerData::append(const BaseAspect::Data::Ptr &data)
|
|
|
|
|
{
|
|
|
|
|
m_data.append(data);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-22 13:05:45 +02:00
|
|
|
// BaseAspect::Data
|
|
|
|
|
|
|
|
|
|
BaseAspect::Data::~Data() = default;
|
|
|
|
|
|
2022-04-08 15:12:24 +02:00
|
|
|
void BaseAspect::Data::Ptr::operator=(const Ptr &other)
|
|
|
|
|
{
|
|
|
|
|
if (this == &other)
|
|
|
|
|
return;
|
|
|
|
|
delete m_data;
|
|
|
|
|
m_data = other.m_data->clone();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
} // namespace Utils
|