/**************************************************************************** ** ** 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. ** ****************************************************************************/ #include "aspects.h" #include "algorithm.h" #include "fancylineedit.h" #include "layoutbuilder.h" #include "pathchooser.h" #include "qtcassert.h" #include "qtcprocess.h" #include "utilsicons.h" #include "variablechooser.h" #include #include #include #include #include #include #include #include #include #include #include namespace Utils { /*! \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. 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. */ BaseAspect::BaseAspect() = default; /*! Destructs a BaseAspect. */ BaseAspect::~BaseAspect() = default; /*! \internal */ void BaseAspect::setConfigWidgetCreator(const ConfigWidgetCreator &configWidgetCreator) { m_configWidgetCreator = configWidgetCreator; } /*! 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; } /*! \internal */ QWidget *BaseAspect::createConfigWidget() const { return m_configWidgetCreator ? m_configWidgetCreator() : nullptr; } /*! Adds the visual representation of this aspect to a layout using a layout builder. */ void BaseAspect::addToLayout(LayoutBuilder &) { } void BaseAspect::saveToMap(QVariantMap &data, const QVariant &value, const QVariant &defaultValue, const QString &keyExtension) const { if (settingsKey().isEmpty()) return; const QString key = settingsKey() + keyExtension; if (value == defaultValue) data.remove(key); else data.insert(key, value); } /*! 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 &) {} // BaseAspects /*! \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. */ BaseAspects::BaseAspects() = default; /*! Destructs a BaseAspects object. */ BaseAspects::~BaseAspects() { qDeleteAll(m_aspects); } /*! Retrieves a BaseAspect with a given \a id, or nullptr if no such aspect is contained. \sa BaseAspect. */ BaseAspect *BaseAspects::aspect(Utils::Id id) const { return Utils::findOrDefault(m_aspects, Utils::equal(&BaseAspect::id, id)); } /*! \internal */ void BaseAspects::fromMap(const QVariantMap &map) const { for (BaseAspect *aspect : m_aspects) aspect->fromMap(map); } /*! \internal */ void BaseAspects::toMap(QVariantMap &map) const { for (BaseAspect *aspect : m_aspects) aspect->toMap(map); } namespace Internal { class BoolAspectPrivate { public: BoolAspect::LabelPlacement m_labelPlacement = BoolAspect::LabelPlacement::AtCheckBox; bool m_value = false; bool m_defaultValue = false; bool m_enabled = true; QString m_labelText; QString m_tooltip; QPointer m_checkBox; // Owned by configuration widget QPointer m_label; // Owned by configuration widget }; class SelectionAspectPrivate { public: int m_value = 0; int m_defaultValue = 0; SelectionAspect::DisplayStyle m_displayStyle = SelectionAspect::DisplayStyle::RadioButtons; struct Option { QString displayName; QString tooltip; }; QVector