2018-09-17 15:56:14 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
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"
|
|
|
|
|
#include "fancylineedit.h"
|
|
|
|
|
#include "layoutbuilder.h"
|
|
|
|
|
#include "pathchooser.h"
|
|
|
|
|
#include "qtcassert.h"
|
|
|
|
|
#include "qtcprocess.h"
|
|
|
|
|
#include "utilsicons.h"
|
|
|
|
|
#include "variablechooser.h"
|
2018-09-17 15:56:14 +02:00
|
|
|
|
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>
|
2020-09-18 12:11:40 +02:00
|
|
|
#include <QFormLayout>
|
2018-09-17 15:56:14 +02:00
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QLineEdit>
|
2020-09-18 12:11:40 +02:00
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QRadioButton>
|
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
|
|
|
#include <QToolButton>
|
|
|
|
|
|
|
|
|
|
namespace Utils {
|
|
|
|
|
|
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-09-18 12:11:40 +02:00
|
|
|
BaseAspect::BaseAspect() = default;
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Destructs a BaseAspect.
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
BaseAspect::~BaseAspect() = default;
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
void BaseAspect::setConfigWidgetCreator(const ConfigWidgetCreator &configWidgetCreator)
|
|
|
|
|
{
|
|
|
|
|
m_configWidgetCreator = configWidgetCreator;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 06:05:18 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the key to be used when accessing the settings.
|
|
|
|
|
|
|
|
|
|
\sa setSettingsKey()
|
|
|
|
|
*/
|
|
|
|
|
QString BaseAspect::settingsKey() const
|
|
|
|
|
{
|
|
|
|
|
return m_settingsKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Sets the key to be used when accessing the settings.
|
|
|
|
|
|
|
|
|
|
\sa settingsKey()
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::setSettingsKey(const QString &key)
|
|
|
|
|
{
|
|
|
|
|
m_settingsKey = key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Sets the key and group to be used when accessing the settings.
|
|
|
|
|
|
|
|
|
|
\sa settingsKey()
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::setSettingsKey(const QString &group, const QString &key)
|
|
|
|
|
{
|
|
|
|
|
m_settingsKey = group + "/" + key;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
QWidget *BaseAspect::createConfigWidget() const
|
|
|
|
|
{
|
|
|
|
|
return m_configWidgetCreator ? m_configWidgetCreator() : nullptr;
|
|
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
|
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 &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Retrieves the internal value of this BaseAspect from a \c QVariantMap.
|
|
|
|
|
|
|
|
|
|
This base implementation does nothing.
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::fromMap(const QVariantMap &)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Stores the internal value of this BaseAspect into a \c QVariantMap.
|
|
|
|
|
|
|
|
|
|
This base implementation does nothing.
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::toMap(QVariantMap &) const
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
void BaseAspect::acquaintSiblings(const BaseAspects &)
|
|
|
|
|
{}
|
|
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
// BaseAspects
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\class BaseAspects
|
|
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief This class represent a collection of one or more aspects.
|
|
|
|
|
|
|
|
|
|
A BaseAspects object assumes ownership on its aspects.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Constructs a BaseAspects object.
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
BaseAspects::BaseAspects() = default;
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Destructs a BaseAspects object.
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
BaseAspects::~BaseAspects()
|
|
|
|
|
{
|
2020-11-02 19:05:24 +01:00
|
|
|
qDeleteAll(m_aspects);
|
2020-09-18 12:11:40 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Retrieves a BaseAspect with a given \a id, or nullptr if no such aspect is contained.
|
|
|
|
|
|
|
|
|
|
\sa BaseAspect.
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
BaseAspect *BaseAspects::aspect(Utils::Id id) const
|
|
|
|
|
{
|
2020-11-02 19:05:24 +01:00
|
|
|
return Utils::findOrDefault(m_aspects, Utils::equal(&BaseAspect::id, id));
|
2020-09-18 12:11:40 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
void BaseAspects::fromMap(const QVariantMap &map) const
|
|
|
|
|
{
|
2020-11-02 19:05:24 +01:00
|
|
|
for (BaseAspect *aspect : m_aspects)
|
2020-09-18 12:11:40 +02:00
|
|
|
aspect->fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
void BaseAspects::toMap(QVariantMap &map) const
|
|
|
|
|
{
|
2020-11-02 19:05:24 +01:00
|
|
|
for (BaseAspect *aspect : m_aspects)
|
2020-09-18 12:11:40 +02:00
|
|
|
aspect->toMap(map);
|
|
|
|
|
}
|
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
|
|
|
bool m_value = false;
|
|
|
|
|
bool m_defaultValue = false;
|
2020-07-21 08:51:38 +02:00
|
|
|
bool m_enabled = true;
|
2020-07-30 08:25:25 +02:00
|
|
|
QString m_labelText;
|
2018-10-22 18:34:55 +02:00
|
|
|
QString m_tooltip;
|
2018-09-17 15:56:14 +02:00
|
|
|
QPointer<QCheckBox> m_checkBox; // Owned by configuration widget
|
2020-07-30 08:25:25 +02:00
|
|
|
QPointer<QLabel> m_label; // Owned by configuration widget
|
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:
|
|
|
|
|
int m_value = 0;
|
|
|
|
|
int m_defaultValue = 0;
|
2020-08-13 09:16:00 +02:00
|
|
|
SelectionAspect::DisplayStyle m_displayStyle
|
|
|
|
|
= SelectionAspect::DisplayStyle::RadioButtons;
|
2019-06-13 18:25:17 +02:00
|
|
|
struct Option { QString displayName; QString tooltip; };
|
|
|
|
|
QVector<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-11-25 13:31:27 +01:00
|
|
|
QPointer<QLabel> m_label;
|
2019-06-13 18:25:17 +02:00
|
|
|
QPointer<QButtonGroup> m_buttonGroup;
|
2020-07-29 07:00:50 +02:00
|
|
|
QString m_tooltip;
|
2019-06-13 18:25:17 +02:00
|
|
|
};
|
|
|
|
|
|
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
|
|
|
QString m_labelText;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
QString m_value;
|
|
|
|
|
QString m_placeHolderText;
|
|
|
|
|
QString m_historyCompleterKey;
|
2020-07-30 05:42:33 +02:00
|
|
|
QString m_tooltip;
|
2018-09-17 15:56:14 +02:00
|
|
|
PathChooser::Kind m_expectedKind = PathChooser::File;
|
|
|
|
|
Environment m_environment;
|
|
|
|
|
QPointer<QLabel> m_label;
|
|
|
|
|
QPointer<QLabel> m_labelDisplay;
|
|
|
|
|
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;
|
2018-09-17 15:56:14 +02:00
|
|
|
QPixmap m_labelPixmap;
|
2020-09-18 12:11:40 +02:00
|
|
|
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;
|
|
|
|
|
|
2019-06-25 12:40:06 +02:00
|
|
|
bool m_readOnly = false;
|
2020-10-05 09:03:13 +02:00
|
|
|
bool m_undoRedoEnabled = false;
|
|
|
|
|
bool m_enabled = true;
|
2019-07-23 13:44:11 +02:00
|
|
|
bool m_showToolTipOnLabel = false;
|
2020-03-16 10:24:35 +01:00
|
|
|
bool m_fileDialogOnly = false;
|
2019-11-25 17:55:39 +01:00
|
|
|
|
|
|
|
|
template<class Widget> void updateWidgetFromCheckStatus(Widget *w)
|
|
|
|
|
{
|
|
|
|
|
const bool enabled = !m_checker || m_checker->value();
|
2020-08-13 09:16:00 +02:00
|
|
|
if (m_uncheckedSemantics == StringAspect::UncheckedSemantics::Disabled)
|
2019-11-25 17:55:39 +01:00
|
|
|
w->setEnabled(enabled);
|
|
|
|
|
else
|
|
|
|
|
w->setReadOnly(!enabled);
|
|
|
|
|
}
|
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:
|
2019-04-24 12:15:31 +02:00
|
|
|
qint64 m_value = 0;
|
2020-07-21 08:54:39 +02:00
|
|
|
qint64 m_defaultValue = 0;
|
2018-09-25 08:24:10 +02:00
|
|
|
QVariant m_minimumValue;
|
|
|
|
|
QVariant m_maximumValue;
|
|
|
|
|
int m_displayIntegerBase = 10;
|
2019-04-24 12:15:31 +02:00
|
|
|
qint64 m_displayScaleFactor = 1;
|
2020-07-21 08:51:38 +02:00
|
|
|
QString m_labelText;
|
2018-09-25 08:24:10 +02:00
|
|
|
QString m_prefix;
|
|
|
|
|
QString m_suffix;
|
2020-07-28 22:36:16 +02:00
|
|
|
QString m_tooltip;
|
2020-07-21 08:51:38 +02:00
|
|
|
QPointer<QLabel> m_label;
|
2018-09-25 08:24:10 +02:00
|
|
|
QPointer<QSpinBox> m_spinBox; // Owned by configuration widget
|
2020-07-21 08:51:38 +02:00
|
|
|
bool m_enabled = true;
|
2018-09-25 08:24:10 +02:00
|
|
|
};
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
class StringListAspectPrivate
|
2020-07-21 08:48:06 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QStringList m_value;
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-14 07:22:37 +02:00
|
|
|
class AspectContainerPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-09-18 12:11:40 +02:00
|
|
|
QList<BaseAspect *> m_items;
|
2020-08-14 07:22:37 +02:00
|
|
|
};
|
|
|
|
|
|
2020-08-14 08:55:22 +02:00
|
|
|
class TextDisplayPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QString m_message;
|
|
|
|
|
QString m_tooltip;
|
2020-08-20 15:54:21 +02:00
|
|
|
Utils::InfoLabel::InfoType m_type;
|
|
|
|
|
QPointer<InfoLabel> m_label;
|
2020-08-14 08:55:22 +02:00
|
|
|
};
|
|
|
|
|
|
2018-09-17 15:56:14 +02:00
|
|
|
} // Internal
|
|
|
|
|
|
|
|
|
|
/*!
|
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)
|
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
|
|
|
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
|
|
|
{
|
|
|
|
|
return d->m_value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Sets the value of this StringAspect from an ordinary \c QString.
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setValue(const QString &value)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
const bool isSame = value == d->m_value;
|
2020-03-24 10:14:47 +01:00
|
|
|
if (isSame)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QString processedValue = value;
|
|
|
|
|
if (d->m_valueAcceptor) {
|
|
|
|
|
const Utils::optional<QString> tmp = d->m_valueAcceptor(d->m_value, value);
|
|
|
|
|
if (!tmp) {
|
|
|
|
|
update(); // Make sure the original value is retained in the UI
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
processedValue = tmp.value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d->m_value = processedValue;
|
2018-09-17 15:56:14 +02:00
|
|
|
update();
|
2020-03-24 10:14:47 +01:00
|
|
|
emit changed();
|
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 StringAspect::fromMap(const QVariantMap &map)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
if (!settingsKey().isEmpty())
|
|
|
|
|
d->m_value = map.value(settingsKey()).toString();
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
if (!settingsKey().isEmpty())
|
|
|
|
|
map.insert(settingsKey(), d->m_value);
|
|
|
|
|
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
|
|
|
{
|
2020-04-24 13:01:20 +02:00
|
|
|
return FilePath::fromUserInput(d->m_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
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Sets \a labelText as text for the separate label in the visual
|
|
|
|
|
representation of this string aspect.
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setLabelText(const QString &labelText)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
d->m_labelText = labelText;
|
|
|
|
|
if (d->m_label)
|
|
|
|
|
d->m_label->setText(labelText);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Sets \a labelPixmap as pixmap for the separate label in the visual
|
|
|
|
|
representation of this aspect.
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setLabelPixmap(const QPixmap &labelPixmap)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
d->m_labelPixmap = labelPixmap;
|
|
|
|
|
if (d->m_label)
|
|
|
|
|
d->m_label->setPixmap(labelPixmap);
|
|
|
|
|
}
|
|
|
|
|
|
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-05 09:03:13 +02:00
|
|
|
void StringAspect::setEnabled(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
d->m_enabled = enabled;
|
|
|
|
|
if (d->m_labelDisplay)
|
|
|
|
|
d->m_labelDisplay->setEnabled(enabled);
|
|
|
|
|
if (d->m_lineEditDisplay)
|
|
|
|
|
d->m_lineEditDisplay->setEnabled(enabled);
|
|
|
|
|
if (d->m_pathChooserDisplay)
|
|
|
|
|
d->m_pathChooserDisplay->setEnabled(enabled);
|
|
|
|
|
if (d->m_textEditDisplay)
|
|
|
|
|
d->m_textEditDisplay->setEnabled(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the current text for the separate label in the visual
|
|
|
|
|
representation of this string aspect.
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
QString StringAspect::labelText() const
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
return d->m_labelText;
|
|
|
|
|
}
|
|
|
|
|
|
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-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-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-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-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
|
|
|
}
|
|
|
|
|
|
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-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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setFileDialogOnly(bool requireFileDialog)
|
2020-03-16 10:24:35 +01:00
|
|
|
{
|
|
|
|
|
d->m_fileDialogOnly = requireFileDialog;
|
|
|
|
|
if (d->m_pathChooserDisplay)
|
|
|
|
|
d->m_pathChooserDisplay->setFileDialogOnly(requireFileDialog);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setEnvironment(const Environment &env)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
d->m_environment = env;
|
|
|
|
|
if (d->m_pathChooserDisplay)
|
|
|
|
|
d->m_pathChooserDisplay->setEnvironment(env);
|
|
|
|
|
}
|
|
|
|
|
|
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-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setToolTip(const QString &tooltip)
|
2020-07-30 05:42:33 +02:00
|
|
|
{
|
|
|
|
|
d->m_tooltip = tooltip;
|
|
|
|
|
if (d->m_pathChooserDisplay)
|
|
|
|
|
d->m_pathChooserDisplay->setToolTip(tooltip);
|
|
|
|
|
if (d->m_lineEditDisplay)
|
|
|
|
|
d->m_lineEditDisplay->setToolTip(tooltip);
|
|
|
|
|
if (d->m_textEditDisplay)
|
|
|
|
|
d->m_textEditDisplay->setToolTip(tooltip);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::setReadOnly(bool readOnly)
|
2019-06-25 12:40:06 +02:00
|
|
|
{
|
|
|
|
|
d->m_readOnly = readOnly;
|
|
|
|
|
if (d->m_pathChooserDisplay)
|
|
|
|
|
d->m_pathChooserDisplay->setReadOnly(readOnly);
|
|
|
|
|
if (d->m_lineEditDisplay)
|
|
|
|
|
d->m_lineEditDisplay->setReadOnly(readOnly);
|
|
|
|
|
if (d->m_textEditDisplay)
|
|
|
|
|
d->m_textEditDisplay->setReadOnly(readOnly);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
QTC_CHECK(!d->m_label);
|
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
|
|
|
}
|
|
|
|
|
|
2019-10-15 17:20:51 +02:00
|
|
|
d->m_label = new QLabel;
|
2018-09-17 15:56:14 +02:00
|
|
|
d->m_label->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
|
|
|
d->m_label->setText(d->m_labelText);
|
|
|
|
|
if (!d->m_labelPixmap.isNull())
|
|
|
|
|
d->m_label->setPixmap(d->m_labelPixmap);
|
2019-10-15 17:20:51 +02:00
|
|
|
builder.addItem(d->m_label.data());
|
2018-09-17 15:56:14 +02:00
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
QWidget *parentWidget = builder.layout()->parentWidget();
|
|
|
|
|
|
2019-11-25 17:55:39 +01:00
|
|
|
const auto useMacroExpander = [this, &builder](QWidget *w) {
|
|
|
|
|
if (!d->m_expanderProvider)
|
|
|
|
|
return;
|
2020-09-18 12:11:40 +02:00
|
|
|
const auto chooser = new VariableChooser(builder.layout()->parentWidget());
|
2019-11-25 17:55:39 +01:00
|
|
|
chooser->addSupportedWidget(w);
|
|
|
|
|
chooser->addMacroExpanderProvider(d->m_expanderProvider);
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-17 15:56:14 +02:00
|
|
|
switch (d->m_displayStyle) {
|
|
|
|
|
case PathChooserDisplay:
|
2020-09-18 12:11:40 +02:00
|
|
|
d->m_pathChooserDisplay = new PathChooser(parentWidget);
|
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);
|
2018-09-17 15:56:14 +02:00
|
|
|
d->m_pathChooserDisplay->setEnvironment(d->m_environment);
|
2019-12-17 11:53:58 +01:00
|
|
|
d->m_pathChooserDisplay->setBaseDirectory(d->m_baseFileName);
|
2020-10-05 09:03:13 +02:00
|
|
|
d->m_pathChooserDisplay->setEnabled(d->m_enabled);
|
2019-06-25 12:40:06 +02:00
|
|
|
d->m_pathChooserDisplay->setReadOnly(d->m_readOnly);
|
2019-11-25 17:55:39 +01:00
|
|
|
useMacroExpander(d->m_pathChooserDisplay->lineEdit());
|
2018-09-17 15:56:14 +02:00
|
|
|
connect(d->m_pathChooserDisplay, &PathChooser::pathChanged,
|
2020-08-13 09:16:00 +02:00
|
|
|
this, &StringAspect::setValue);
|
2019-10-15 17:20:51 +02:00
|
|
|
builder.addItem(d->m_pathChooserDisplay.data());
|
2020-03-16 10:24:35 +01:00
|
|
|
d->m_pathChooserDisplay->setFileDialogOnly(d->m_fileDialogOnly);
|
2018-09-17 15:56:14 +02:00
|
|
|
break;
|
|
|
|
|
case LineEditDisplay:
|
2019-10-15 17:20:51 +02:00
|
|
|
d->m_lineEditDisplay = new 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
|
|
|
d->m_lineEditDisplay->setEnabled(d->m_enabled);
|
2019-06-25 12:40:06 +02:00
|
|
|
d->m_lineEditDisplay->setReadOnly(d->m_readOnly);
|
2020-10-05 09:03:13 +02:00
|
|
|
if (d->m_validator)
|
|
|
|
|
d->m_lineEditDisplay->setValidationFunction(d->m_validator);
|
2019-11-25 17:55:39 +01:00
|
|
|
useMacroExpander(d->m_lineEditDisplay);
|
2018-09-17 15:56:14 +02:00
|
|
|
connect(d->m_lineEditDisplay, &FancyLineEdit::textEdited,
|
2020-08-13 09:16:00 +02:00
|
|
|
this, &StringAspect::setValue);
|
2019-10-15 17:20:51 +02:00
|
|
|
builder.addItem(d->m_lineEditDisplay.data());
|
2018-09-17 15:56:14 +02:00
|
|
|
break;
|
2018-10-16 07:59:52 +02:00
|
|
|
case TextEditDisplay:
|
2019-10-15 17:20:51 +02:00
|
|
|
d->m_textEditDisplay = new 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->setEnabled(d->m_enabled);
|
2019-06-25 12:40:06 +02:00
|
|
|
d->m_textEditDisplay->setReadOnly(d->m_readOnly);
|
2020-10-05 09:03:13 +02:00
|
|
|
d->m_textEditDisplay->setUndoRedoEnabled(d->m_undoRedoEnabled);
|
|
|
|
|
d->m_textEditDisplay->setTextInteractionFlags
|
|
|
|
|
(Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse);
|
2019-11-25 17:55:39 +01:00
|
|
|
useMacroExpander(d->m_textEditDisplay);
|
2018-10-16 07:59:52 +02:00
|
|
|
connect(d->m_textEditDisplay, &QTextEdit::textChanged, this, [this] {
|
|
|
|
|
const QString value = d->m_textEditDisplay->document()->toPlainText();
|
|
|
|
|
if (value != d->m_value) {
|
|
|
|
|
d->m_value = value;
|
|
|
|
|
emit changed();
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-10-15 17:20:51 +02:00
|
|
|
builder.addItem(d->m_textEditDisplay.data());
|
2018-10-16 07:59:52 +02:00
|
|
|
break;
|
2018-09-17 15:56:14 +02:00
|
|
|
case LabelDisplay:
|
2019-10-15 17:20:51 +02:00
|
|
|
d->m_labelDisplay = new QLabel;
|
2020-10-05 09:03:13 +02:00
|
|
|
d->m_labelDisplay->setEnabled(d->m_enabled);
|
2018-09-17 15:56:14 +02:00
|
|
|
d->m_labelDisplay->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
2019-10-15 17:20:51 +02:00
|
|
|
builder.addItem(d->m_labelDisplay.data());
|
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);
|
2018-09-17 15:56:14 +02:00
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringAspect::update()
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
const QString displayedString = d->m_displayFilter ? d->m_displayFilter(d->m_value)
|
|
|
|
|
: d->m_value;
|
|
|
|
|
|
|
|
|
|
if (d->m_pathChooserDisplay) {
|
2020-04-09 11:05:50 +02:00
|
|
|
d->m_pathChooserDisplay->setFilePath(FilePath::fromString(displayedString));
|
2020-07-30 05:42:33 +02:00
|
|
|
d->m_pathChooserDisplay->setToolTip(d->m_tooltip);
|
2019-11-25 17:55:39 +01:00
|
|
|
d->updateWidgetFromCheckStatus(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);
|
2020-07-30 05:42:33 +02:00
|
|
|
d->m_lineEditDisplay->setToolTip(d->m_tooltip);
|
2019-11-25 17:55:39 +01:00
|
|
|
d->updateWidgetFromCheckStatus(d->m_lineEditDisplay.data());
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-16 07:59:52 +02:00
|
|
|
if (d->m_textEditDisplay) {
|
|
|
|
|
d->m_textEditDisplay->setText(displayedString);
|
2020-07-30 05:42:33 +02:00
|
|
|
d->m_textEditDisplay->setToolTip(d->m_tooltip);
|
2019-11-25 17:55:39 +01:00
|
|
|
d->updateWidgetFromCheckStatus(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-07-30 05:42:33 +02:00
|
|
|
d->m_labelDisplay->setToolTip(d->m_showToolTipOnLabel ? displayedString : d->m_tooltip);
|
2019-07-23 13:44:11 +02:00
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
|
|
|
|
|
if (d->m_label) {
|
|
|
|
|
d->m_label->setText(d->m_labelText);
|
|
|
|
|
if (!d->m_labelPixmap.isNull())
|
|
|
|
|
d->m_label->setPixmap(d->m_labelPixmap);
|
|
|
|
|
}
|
2020-03-19 15:31:27 +01:00
|
|
|
|
|
|
|
|
validateInput();
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
setSettingsKey(settingsKey);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2019-11-26 17:11:01 +01:00
|
|
|
d->m_checkBox = new QCheckBox();
|
2020-08-17 10:30:36 +02:00
|
|
|
switch (d->m_labelPlacement) {
|
|
|
|
|
case LabelPlacement::AtCheckBoxWithoutDummyLabel:
|
|
|
|
|
d->m_checkBox->setText(d->m_labelText);
|
|
|
|
|
break;
|
|
|
|
|
case LabelPlacement::AtCheckBox:
|
2020-07-30 08:25:25 +02:00
|
|
|
d->m_checkBox->setText(d->m_labelText);
|
2019-12-17 18:02:11 +01:00
|
|
|
builder.addItem(new QLabel);
|
2020-08-17 10:30:36 +02:00
|
|
|
break;
|
|
|
|
|
case LabelPlacement::InExtraLabel:
|
2020-07-30 08:25:25 +02:00
|
|
|
d->m_label = new QLabel(d->m_labelText);
|
|
|
|
|
d->m_label->setToolTip(d->m_tooltip);
|
|
|
|
|
builder.addItem(d->m_label.data());
|
2020-08-17 10:30:36 +02:00
|
|
|
break;
|
2019-11-26 17:11:01 +01:00
|
|
|
}
|
2018-09-17 15:56:14 +02:00
|
|
|
d->m_checkBox->setChecked(d->m_value);
|
2018-10-22 18:34:55 +02:00
|
|
|
d->m_checkBox->setToolTip(d->m_tooltip);
|
2020-07-21 08:51:38 +02:00
|
|
|
d->m_checkBox->setEnabled(d->m_enabled);
|
2019-11-26 17:11:01 +01:00
|
|
|
builder.addItem(d->m_checkBox.data());
|
2018-09-17 15:56:14 +02:00
|
|
|
connect(d->m_checkBox.data(), &QAbstractButton::clicked, this, [this] {
|
|
|
|
|
d->m_value = d->m_checkBox->isChecked();
|
|
|
|
|
emit changed();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void BoolAspect::fromMap(const QVariantMap &map)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
d->m_value = map.value(settingsKey(), d->m_defaultValue).toBool();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void BoolAspect::toMap(QVariantMap &data) const
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2020-11-09 13:42:10 +02:00
|
|
|
if (!settingsKey().isEmpty())
|
|
|
|
|
data.insert(settingsKey(), d->m_value);
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
bool BoolAspect::defaultValue() const
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
return d->m_defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void BoolAspect::setDefaultValue(bool defaultValue)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
d->m_defaultValue = defaultValue;
|
2019-06-18 14:57:47 +02:00
|
|
|
d->m_value = defaultValue;
|
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
|
|
|
{
|
|
|
|
|
return d->m_value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void BoolAspect::setValue(bool value)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
|
|
|
|
d->m_value = value;
|
|
|
|
|
if (d->m_checkBox)
|
|
|
|
|
d->m_checkBox->setChecked(d->m_value);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void BoolAspect::setLabel(const QString &labelText, LabelPlacement labelPlacement)
|
2018-09-17 15:56:14 +02:00
|
|
|
{
|
2020-07-30 08:25:25 +02:00
|
|
|
d->m_labelText = labelText;
|
2019-11-26 17:11:01 +01:00
|
|
|
d->m_labelPlacement = labelPlacement;
|
2018-09-17 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void BoolAspect::setToolTip(const QString &tooltip)
|
2018-10-22 18:34:55 +02:00
|
|
|
{
|
|
|
|
|
d->m_tooltip = tooltip;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void BoolAspect::setEnabled(bool enabled)
|
2020-07-21 08:51:38 +02:00
|
|
|
{
|
|
|
|
|
d->m_enabled = enabled;
|
|
|
|
|
if (d->m_checkBox)
|
|
|
|
|
d->m_checkBox->setEnabled(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
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:
|
|
|
|
|
d->m_buttonGroup = new QButtonGroup;
|
|
|
|
|
d->m_buttonGroup->setExclusive(true);
|
|
|
|
|
for (int i = 0, n = d->m_options.size(); i < n; ++i) {
|
2020-08-13 09:16:00 +02:00
|
|
|
const Internal::SelectionAspectPrivate::Option &option = d->m_options.at(i);
|
2019-11-25 12:46:08 +01:00
|
|
|
auto button = new QRadioButton(option.displayName);
|
|
|
|
|
button->setChecked(i == d->m_value);
|
|
|
|
|
button->setToolTip(option.tooltip);
|
2020-09-18 04:54:41 +02:00
|
|
|
builder.addItems({{}, button});
|
2019-11-25 12:46:08 +01:00
|
|
|
d->m_buttons.append(button);
|
|
|
|
|
d->m_buttonGroup->addButton(button);
|
|
|
|
|
connect(button, &QAbstractButton::clicked, this, [this, i] {
|
2020-10-05 18:23:17 +02:00
|
|
|
if (d->m_value != i) {
|
|
|
|
|
d->m_value = i;
|
|
|
|
|
emit changed();
|
|
|
|
|
}
|
2019-11-25 12:46:08 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DisplayStyle::ComboBox:
|
2019-11-25 13:31:27 +01:00
|
|
|
d->m_label = new QLabel(displayName());
|
2020-07-29 07:00:50 +02:00
|
|
|
d->m_label->setToolTip(d->m_tooltip);
|
2019-11-25 12:46:08 +01:00
|
|
|
d->m_comboBox = new QComboBox;
|
2020-07-29 07:00:50 +02:00
|
|
|
d->m_comboBox->setToolTip(d->m_tooltip);
|
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);
|
|
|
|
|
connect(d->m_comboBox.data(), QOverload<int>::of(&QComboBox::activated), this,
|
2020-10-05 18:23:17 +02:00
|
|
|
[this](int index) {
|
|
|
|
|
if (d->m_value != index) {
|
|
|
|
|
d->m_value = index;
|
|
|
|
|
emit changed();
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-11-25 12:46:08 +01:00
|
|
|
d->m_comboBox->setCurrentIndex(d->m_value);
|
2020-09-18 04:54:41 +02:00
|
|
|
builder.addItems({d->m_label.data(), d->m_comboBox.data()});
|
2019-11-25 12:46:08 +01:00
|
|
|
break;
|
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::fromMap(const QVariantMap &map)
|
2019-06-13 18:25:17 +02:00
|
|
|
{
|
|
|
|
|
d->m_value = map.value(settingsKey(), d->m_defaultValue).toInt();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void SelectionAspect::toMap(QVariantMap &data) const
|
2019-06-13 18:25:17 +02:00
|
|
|
{
|
2020-11-09 13:42:10 +02:00
|
|
|
if (!settingsKey().isEmpty())
|
|
|
|
|
data.insert(settingsKey(), d->m_value);
|
2019-06-13 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void SelectionAspect::setVisibleDynamic(bool visible)
|
2019-11-25 13:31:27 +01:00
|
|
|
{
|
|
|
|
|
if (d->m_label)
|
|
|
|
|
d->m_label->setVisible(visible);
|
|
|
|
|
if (d->m_comboBox)
|
|
|
|
|
d->m_comboBox->setVisible(visible);
|
|
|
|
|
for (QRadioButton * const button : qAsConst(d->m_buttons))
|
|
|
|
|
button->setVisible(visible);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
int SelectionAspect::defaultValue() const
|
2019-06-13 18:25:17 +02:00
|
|
|
{
|
|
|
|
|
return d->m_defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void SelectionAspect::setDefaultValue(int defaultValue)
|
2019-06-13 18:25:17 +02:00
|
|
|
{
|
|
|
|
|
d->m_defaultValue = defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
void SelectionAspect::setToolTip(const QString &tooltip)
|
2020-07-29 07:00:50 +02:00
|
|
|
{
|
|
|
|
|
d->m_tooltip = tooltip;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
int SelectionAspect::value() const
|
2019-06-13 18:25:17 +02:00
|
|
|
{
|
|
|
|
|
return d->m_value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void SelectionAspect::setValue(int value)
|
2019-06-13 18:25:17 +02:00
|
|
|
{
|
|
|
|
|
d->m_value = value;
|
|
|
|
|
if (d->m_buttonGroup && 0 <= value && value < d->m_buttons.size())
|
|
|
|
|
d->m_buttons.at(value)->setChecked(true);
|
2019-11-25 12:46:08 +01:00
|
|
|
else if (d->m_comboBox) {
|
|
|
|
|
d->m_comboBox->setCurrentIndex(value);
|
|
|
|
|
}
|
2019-06-13 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
QString SelectionAspect::stringValue() const
|
2020-07-29 07:00:50 +02:00
|
|
|
{
|
|
|
|
|
return d->m_options.at(d->m_value).displayName;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
d->m_options.append({displayName, toolTip});
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
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
|
|
|
{
|
2020-07-21 08:51:38 +02:00
|
|
|
QTC_CHECK(!d->m_label);
|
|
|
|
|
d->m_label = new QLabel(d->m_labelText);
|
|
|
|
|
d->m_label->setEnabled(d->m_enabled);
|
|
|
|
|
|
2018-09-25 08:24:10 +02:00
|
|
|
QTC_CHECK(!d->m_spinBox);
|
2019-10-15 17:20:51 +02:00
|
|
|
d->m_spinBox = new QSpinBox;
|
2019-04-24 12:15:31 +02:00
|
|
|
d->m_spinBox->setValue(int(d->m_value / d->m_displayScaleFactor));
|
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);
|
2020-07-21 08:51:38 +02:00
|
|
|
d->m_spinBox->setEnabled(d->m_enabled);
|
2020-07-28 22:36:16 +02:00
|
|
|
d->m_spinBox->setToolTip(d->m_tooltip);
|
2018-09-25 08:24:10 +02:00
|
|
|
if (d->m_maximumValue.isValid() && d->m_maximumValue.isValid())
|
2019-04-24 12:15:31 +02:00
|
|
|
d->m_spinBox->setRange(int(d->m_minimumValue.toLongLong() / d->m_displayScaleFactor),
|
|
|
|
|
int(d->m_maximumValue.toLongLong() / d->m_displayScaleFactor));
|
2020-07-21 08:51:38 +02:00
|
|
|
|
2020-09-18 04:54:41 +02:00
|
|
|
builder.addItems({d->m_label.data(), d->m_spinBox.data()});
|
2019-02-26 09:40:49 +01:00
|
|
|
connect(d->m_spinBox.data(), QOverload<int>::of(&QSpinBox::valueChanged),
|
2018-09-25 08:24:10 +02:00
|
|
|
this, [this](int value) {
|
2019-04-24 12:15:31 +02:00
|
|
|
d->m_value = value * d->m_displayScaleFactor;
|
2018-09-25 08:24:10 +02:00
|
|
|
emit changed();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::fromMap(const QVariantMap &map)
|
2018-09-25 08:24:10 +02:00
|
|
|
{
|
2020-07-21 08:54:39 +02:00
|
|
|
d->m_value = map.value(settingsKey(), d->m_defaultValue).toLongLong();
|
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::toMap(QVariantMap &data) const
|
2018-09-25 08:24:10 +02:00
|
|
|
{
|
2020-07-21 08:54:39 +02:00
|
|
|
if (d->m_value != d->m_defaultValue)
|
|
|
|
|
data.insert(settingsKey(), d->m_value);
|
|
|
|
|
else
|
|
|
|
|
data.remove(settingsKey());
|
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
|
|
|
{
|
2019-04-24 12:15:31 +02:00
|
|
|
return d->m_value;
|
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
|
|
|
{
|
|
|
|
|
d->m_value = value;
|
|
|
|
|
if (d->m_spinBox)
|
2019-04-24 12:15:31 +02:00
|
|
|
d->m_spinBox->setValue(int(d->m_value / d->m_displayScaleFactor));
|
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
|
|
|
{
|
2020-07-21 08:51:38 +02:00
|
|
|
d->m_labelText = label;
|
|
|
|
|
if (d->m_label)
|
|
|
|
|
d->m_label->setText(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::setEnabled(bool enabled)
|
2020-07-21 08:51:38 +02:00
|
|
|
{
|
|
|
|
|
d->m_enabled = enabled;
|
|
|
|
|
if (d->m_label)
|
|
|
|
|
d->m_label->setEnabled(enabled);
|
|
|
|
|
if (d->m_spinBox)
|
|
|
|
|
d->m_spinBox->setEnabled(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::setDefaultValue(qint64 defaultValue)
|
2020-07-21 08:54:39 +02:00
|
|
|
{
|
|
|
|
|
d->m_defaultValue = defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void IntegerAspect::setToolTip(const QString &tooltip)
|
2020-07-28 22:36:16 +02:00
|
|
|
{
|
|
|
|
|
d->m_tooltip = tooltip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
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);
|
|
|
|
|
setDefaultValue(2);
|
2020-10-15 17:07:00 +02:00
|
|
|
addOption(onString);
|
|
|
|
|
addOption(offString);
|
|
|
|
|
addOption(defaultString);
|
2019-11-25 13:31:27 +01:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
TriState TriStateAspect::setting() const
|
2019-11-25 13:31:27 +01:00
|
|
|
{
|
2019-11-15 16:20:33 +01:00
|
|
|
return TriState::fromVariant(value());
|
2019-11-25 13:31:27 +01:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void TriStateAspect::setSetting(TriState setting)
|
2019-11-25 13:31:27 +01:00
|
|
|
{
|
2019-11-15 16:20:33 +01:00
|
|
|
setValue(setting.toVariant().toInt());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
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-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringListAspect::fromMap(const QVariantMap &map)
|
2020-07-21 08:48:06 +02:00
|
|
|
{
|
|
|
|
|
d->m_value = map.value(settingsKey()).toStringList();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringListAspect::toMap(QVariantMap &data) const
|
2020-07-21 08:48:06 +02:00
|
|
|
{
|
2020-11-09 13:42:10 +02:00
|
|
|
if (!settingsKey().isEmpty())
|
|
|
|
|
data.insert(settingsKey(), d->m_value);
|
2020-07-21 08:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
QStringList StringListAspect::value() const
|
2020-07-21 08:48:06 +02:00
|
|
|
{
|
|
|
|
|
return d->m_value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
void StringListAspect::setValue(const QStringList &value)
|
2020-07-21 08:48:06 +02:00
|
|
|
{
|
|
|
|
|
d->m_value = value;
|
|
|
|
|
}
|
|
|
|
|
|
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-08-20 15:54:21 +02:00
|
|
|
d->m_label = new InfoLabel(d->m_message, d->m_type);
|
2020-08-14 08:55:22 +02:00
|
|
|
d->m_label->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
|
|
|
d->m_label->setToolTip(d->m_tooltip);
|
2020-08-20 15:54:21 +02:00
|
|
|
d->m_label->setElideMode(Qt::ElideNone);
|
|
|
|
|
d->m_label->setWordWrap(true);
|
2020-08-14 08:55:22 +02:00
|
|
|
}
|
|
|
|
|
builder.addItem(d->m_label.data());
|
2020-08-19 10:29:14 +02:00
|
|
|
d->m_label->setVisible(isVisible());
|
2020-08-14 08:55:22 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Shows or hides this text display depending on the value of \a visible.
|
|
|
|
|
By default, the text display is visible.
|
|
|
|
|
*/
|
2020-08-14 08:55:22 +02:00
|
|
|
void TextDisplay::setVisible(bool visible)
|
|
|
|
|
{
|
2020-09-18 12:11:40 +02:00
|
|
|
BaseAspect::setVisible(visible);
|
2020-08-14 08:55:22 +02:00
|
|
|
if (d->m_label)
|
|
|
|
|
d->m_label->setVisible(visible);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Sets \a tooltip as tool tip for the visual representation of this aspect.
|
|
|
|
|
*/
|
2020-08-14 08:55:22 +02:00
|
|
|
void TextDisplay::setToolTip(const QString &tooltip)
|
|
|
|
|
{
|
|
|
|
|
d->m_tooltip = tooltip;
|
|
|
|
|
if (d->m_label)
|
|
|
|
|
d->m_label->setToolTip(tooltip);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
2020-08-14 07:22:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
AspectContainer::AspectContainer()
|
|
|
|
|
: d(new Internal::AspectContainerPrivate)
|
|
|
|
|
{}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-14 07:22:37 +02:00
|
|
|
AspectContainer::~AspectContainer() = default;
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2020-09-18 12:11:40 +02:00
|
|
|
void AspectContainer::addAspectHelper(BaseAspect *aspect)
|
2020-08-14 07:22:37 +02:00
|
|
|
{
|
|
|
|
|
d->m_items.append(aspect);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
Adds all visible sub-aspects to \a builder.
|
|
|
|
|
*/
|
2020-08-14 07:22:37 +02:00
|
|
|
void AspectContainer::addToLayout(LayoutBuilder &builder)
|
|
|
|
|
{
|
2020-09-18 12:11:40 +02:00
|
|
|
for (BaseAspect *aspect : d->m_items) {
|
2020-08-14 07:22:37 +02:00
|
|
|
if (aspect->isVisible())
|
|
|
|
|
aspect->addToLayout(builder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-14 07:22:37 +02:00
|
|
|
void AspectContainer::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
2020-09-18 12:11:40 +02:00
|
|
|
for (BaseAspect *aspect : d->m_items)
|
2020-08-14 07:22:37 +02:00
|
|
|
aspect->fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 09:39:54 +02:00
|
|
|
/*!
|
|
|
|
|
\reimp
|
|
|
|
|
*/
|
2020-08-14 07:22:37 +02:00
|
|
|
void AspectContainer::toMap(QVariantMap &map) const
|
|
|
|
|
{
|
2020-09-18 12:11:40 +02:00
|
|
|
for (BaseAspect *aspect : d->m_items)
|
2020-08-14 07:22:37 +02:00
|
|
|
aspect->toMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
} // namespace Utils
|