2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-04-24 16:47:39 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Copyright (C) 2016 Falko Arps
|
|
|
|
|
** Copyright (C) 2016 Sven Klein
|
|
|
|
|
** Copyright (C) 2016 Giuliano Schneider
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-04-24 16:47:39 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-04-24 16:47:39 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2009-04-24 16:47:39 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-04-24 16:47:39 +02:00
|
|
|
|
|
|
|
|
#include "ioptionspage.h"
|
|
|
|
|
|
2017-07-07 14:05:06 +03:00
|
|
|
#include <utils/stringutils.h>
|
2017-01-17 18:47:58 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2017-07-07 14:05:06 +03:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QGroupBox>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <QIcon>
|
2013-12-03 14:17:03 +01:00
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPushButton>
|
2020-03-27 11:56:25 +01:00
|
|
|
#include <QRegularExpression>
|
2013-12-03 14:17:03 +01:00
|
|
|
|
2020-01-10 09:33:24 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2020-02-14 16:55:29 +01:00
|
|
|
/*!
|
|
|
|
|
\class Core::IOptionsPageProvider
|
|
|
|
|
\inmodule QtCreator
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
/*!
|
|
|
|
|
\class Core::IOptionsPageWidget
|
|
|
|
|
\inmodule QtCreator
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
|
2009-04-24 16:47:39 +02:00
|
|
|
/*!
|
2013-12-11 15:37:48 +01:00
|
|
|
\class Core::IOptionsPage
|
2020-02-14 16:55:29 +01:00
|
|
|
\ingroup mainclasses
|
|
|
|
|
\inmodule QtCreator
|
2013-12-11 15:37:48 +01:00
|
|
|
\brief The IOptionsPage class is an interface for providing pages for the
|
2020-02-14 16:55:29 +01:00
|
|
|
\uicontrol Options dialog (called \uicontrol Preferences on \macos).
|
|
|
|
|
|
|
|
|
|
\image qtcreator-options-dialog.png
|
2009-04-24 16:47:39 +02:00
|
|
|
*/
|
2013-12-03 14:17:03 +01:00
|
|
|
|
2013-12-11 15:37:48 +01:00
|
|
|
/*!
|
|
|
|
|
|
2020-02-21 14:47:59 +01:00
|
|
|
\fn Core::Id Core::IOptionsPage::id() const
|
2013-12-11 15:37:48 +01:00
|
|
|
|
|
|
|
|
Returns a unique identifier for referencing the options page.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-02-21 14:47:59 +01:00
|
|
|
\fn QString Core::IOptionsPage::displayName() const
|
2013-12-11 15:37:48 +01:00
|
|
|
|
|
|
|
|
Returns the translated display name of the options page.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-02-21 14:47:59 +01:00
|
|
|
\fn Core::Id Core::IOptionsPage::category() const
|
2013-12-11 15:37:48 +01:00
|
|
|
|
|
|
|
|
Returns the unique id for the category that the options page should be displayed in. This id is
|
2020-02-14 16:55:29 +01:00
|
|
|
used for sorting the list on the left side of the \uicontrol Options dialog.
|
2013-12-11 15:37:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-02-21 14:47:59 +01:00
|
|
|
\fn QString Core::IOptionsPage::displayCategory() const
|
2013-12-11 15:37:48 +01:00
|
|
|
|
|
|
|
|
Returns the translated category name of the options page. This name is displayed in the list on
|
2020-02-14 16:55:29 +01:00
|
|
|
the left side of the \uicontrol Options dialog.
|
2013-12-11 15:37:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Returns the category icon of the options page. This icon is displayed in the list on the left
|
2020-02-14 16:55:29 +01:00
|
|
|
side of the \uicontrol Options dialog.
|
2013-12-11 15:37:48 +01:00
|
|
|
*/
|
2015-02-26 13:38:54 +01:00
|
|
|
QIcon Core::IOptionsPage::categoryIcon() const
|
|
|
|
|
{
|
2016-09-20 10:47:09 +02:00
|
|
|
return m_categoryIcon.icon();
|
2015-02-26 13:38:54 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-17 18:47:58 +01:00
|
|
|
/*!
|
2020-02-14 16:55:29 +01:00
|
|
|
Sets the \a widgetCreator callback to create page widgets on demand. The
|
|
|
|
|
widget will be destroyed on finish().
|
2017-01-17 18:47:58 +01:00
|
|
|
*/
|
|
|
|
|
void Core::IOptionsPage::setWidgetCreator(const WidgetCreator &widgetCreator)
|
|
|
|
|
{
|
|
|
|
|
m_widgetCreator = widgetCreator;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-11 15:37:48 +01:00
|
|
|
/*!
|
2020-02-14 16:55:29 +01:00
|
|
|
Returns the widget to show in the \uicontrol Options dialog. You should create a widget lazily here,
|
2013-12-11 15:37:48 +01:00
|
|
|
and delete it again in the finish() method. This method can be called multiple times, so you
|
|
|
|
|
should only create a new widget if the old one was deleted.
|
2017-01-17 18:47:58 +01:00
|
|
|
|
2020-02-14 16:55:29 +01:00
|
|
|
Alternatively, use setWidgetCreator() to set a callback function that is used to
|
2017-01-17 18:47:58 +01:00
|
|
|
lazily create a widget in time.
|
|
|
|
|
|
2020-02-14 16:55:29 +01:00
|
|
|
Either override this function in a derived class, or set a widget creator.
|
2013-12-11 15:37:48 +01:00
|
|
|
*/
|
|
|
|
|
|
2017-01-17 18:47:58 +01:00
|
|
|
QWidget *Core::IOptionsPage::widget()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_widgetCreator, return nullptr);
|
|
|
|
|
if (!m_widget)
|
|
|
|
|
m_widget = m_widgetCreator();
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
2013-12-11 15:37:48 +01:00
|
|
|
|
2017-01-17 18:47:58 +01:00
|
|
|
/*!
|
2020-02-14 16:55:29 +01:00
|
|
|
Called when selecting the \uicontrol Apply button on the options page dialog.
|
|
|
|
|
Should detect whether any changes were made and store those.
|
|
|
|
|
|
|
|
|
|
Either override this function in a derived class, or set a widget creator.
|
2017-01-17 18:47:58 +01:00
|
|
|
|
2020-02-14 16:55:29 +01:00
|
|
|
\sa setWidgetCreator()
|
2013-12-11 15:37:48 +01:00
|
|
|
*/
|
|
|
|
|
|
2017-01-17 18:47:58 +01:00
|
|
|
void Core::IOptionsPage::apply()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_widgetCreator, return);
|
|
|
|
|
if (m_widget)
|
|
|
|
|
m_widget->apply();
|
|
|
|
|
}
|
2013-12-11 15:37:48 +01:00
|
|
|
|
2017-01-17 18:47:58 +01:00
|
|
|
/*!
|
2020-02-14 16:55:29 +01:00
|
|
|
Called directly before the \uicontrol Options dialog closes. Here you should
|
|
|
|
|
delete the widget that was created in widget() to free resources.
|
2017-01-17 18:47:58 +01:00
|
|
|
|
2020-02-14 16:55:29 +01:00
|
|
|
Either override this function in a derived class, or set a widget creator.
|
|
|
|
|
|
|
|
|
|
\sa setWidgetCreator()
|
2013-12-11 15:37:48 +01:00
|
|
|
*/
|
|
|
|
|
|
2017-01-17 18:47:58 +01:00
|
|
|
void Core::IOptionsPage::finish()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_widgetCreator, return);
|
|
|
|
|
if (m_widget) {
|
|
|
|
|
m_widget->finish();
|
|
|
|
|
delete m_widget;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-14 16:55:29 +01:00
|
|
|
/*!
|
|
|
|
|
Sets \a categoryIconPath as the path to the category icon of the options
|
|
|
|
|
page.
|
|
|
|
|
*/
|
2020-01-10 09:33:24 +01:00
|
|
|
void Core::IOptionsPage::setCategoryIconPath(const QString &categoryIconPath)
|
|
|
|
|
{
|
|
|
|
|
m_categoryIcon = Icon({{categoryIconPath, Theme::PanelTextColorDark}}, Icon::Tint);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-11 15:37:48 +01:00
|
|
|
/*!
|
2020-02-21 14:47:59 +01:00
|
|
|
\fn void Core::IOptionsPage::setId(Core::Id id)
|
2013-12-11 15:37:48 +01:00
|
|
|
|
|
|
|
|
Sets the \a id of the options page.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-02-21 14:47:59 +01:00
|
|
|
\fn void Core::IOptionsPage::setDisplayName(const QString &displayName)
|
2013-12-11 15:37:48 +01:00
|
|
|
|
|
|
|
|
Sets \a displayName as the display name of the options page.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-02-21 14:47:59 +01:00
|
|
|
\fn void Core::IOptionsPage::setCategory(Core::Id category)
|
2013-12-11 15:37:48 +01:00
|
|
|
|
|
|
|
|
Uses \a category to sort the options pages.
|
|
|
|
|
*/
|
2013-12-03 14:17:03 +01:00
|
|
|
|
2013-12-11 15:37:48 +01:00
|
|
|
/*!
|
2020-02-21 14:47:59 +01:00
|
|
|
\fn void Core::IOptionsPage::setDisplayCategory(const QString &displayCategory)
|
2013-12-11 15:37:48 +01:00
|
|
|
|
|
|
|
|
Sets \a displayCategory as the display category of the options page.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-02-21 14:47:59 +01:00
|
|
|
\fn void Core::IOptionsPage::setCategoryIcon(const Utils::Icon &categoryIcon)
|
2013-12-11 15:37:48 +01:00
|
|
|
|
|
|
|
|
Sets \a categoryIcon as the category icon of the options page.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-12-08 17:20:48 +01:00
|
|
|
static QList<Core::IOptionsPage *> g_optionsPages;
|
2013-12-11 15:37:48 +01:00
|
|
|
|
|
|
|
|
/*!
|
2018-04-10 12:28:18 +02:00
|
|
|
Constructs an options page with the given \a parent and registers it
|
2020-02-14 16:55:29 +01:00
|
|
|
at the global options page pool if \a registerGlobally is \c true.
|
2013-12-11 15:37:48 +01:00
|
|
|
*/
|
2018-04-10 12:28:18 +02:00
|
|
|
Core::IOptionsPage::IOptionsPage(QObject *parent, bool registerGlobally)
|
|
|
|
|
: QObject(parent)
|
2013-12-03 14:17:03 +01:00
|
|
|
{
|
2018-04-10 12:28:18 +02:00
|
|
|
if (registerGlobally)
|
|
|
|
|
g_optionsPages.append(this);
|
2013-12-03 14:17:03 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-11 15:37:48 +01:00
|
|
|
/*!
|
2020-02-14 16:55:29 +01:00
|
|
|
\internal
|
2013-12-11 15:37:48 +01:00
|
|
|
*/
|
2013-12-03 14:17:03 +01:00
|
|
|
Core::IOptionsPage::~IOptionsPage()
|
|
|
|
|
{
|
2017-12-08 17:20:48 +01:00
|
|
|
g_optionsPages.removeOne(this);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-14 16:55:29 +01:00
|
|
|
/*!
|
|
|
|
|
Returns a list of all options pages.
|
|
|
|
|
*/
|
2017-12-08 17:20:48 +01:00
|
|
|
const QList<Core::IOptionsPage *> Core::IOptionsPage::allOptionsPages()
|
|
|
|
|
{
|
|
|
|
|
return g_optionsPages;
|
2013-12-03 14:17:03 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-11 15:37:48 +01:00
|
|
|
/*!
|
2020-03-27 11:56:25 +01:00
|
|
|
Is used by the \uicontrol Options dialog search filter to match \a regexp to this options
|
2013-12-11 15:37:48 +01:00
|
|
|
page. This defaults to take the widget and then looks for all child labels, check boxes, push
|
|
|
|
|
buttons, and group boxes. Should return \c true when a match is found.
|
|
|
|
|
*/
|
2020-03-27 11:56:25 +01:00
|
|
|
bool Core::IOptionsPage::matches(const QRegularExpression ®exp) const
|
2013-12-03 14:17:03 +01:00
|
|
|
{
|
|
|
|
|
if (!m_keywordsInitialized) {
|
2018-07-21 21:11:46 +02:00
|
|
|
auto that = const_cast<IOptionsPage *>(this);
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *widget = that->widget();
|
|
|
|
|
if (!widget)
|
|
|
|
|
return false;
|
|
|
|
|
// find common subwidgets
|
|
|
|
|
foreach (const QLabel *label, widget->findChildren<QLabel *>())
|
2017-07-07 14:05:06 +03:00
|
|
|
m_keywords << Utils::stripAccelerator(label->text());
|
2013-12-03 14:17:03 +01:00
|
|
|
foreach (const QCheckBox *checkbox, widget->findChildren<QCheckBox *>())
|
2017-07-07 14:05:06 +03:00
|
|
|
m_keywords << Utils::stripAccelerator(checkbox->text());
|
2013-12-03 14:17:03 +01:00
|
|
|
foreach (const QPushButton *pushButton, widget->findChildren<QPushButton *>())
|
2017-07-07 14:05:06 +03:00
|
|
|
m_keywords << Utils::stripAccelerator(pushButton->text());
|
2013-12-03 14:17:03 +01:00
|
|
|
foreach (const QGroupBox *groupBox, widget->findChildren<QGroupBox *>())
|
2017-07-07 14:05:06 +03:00
|
|
|
m_keywords << Utils::stripAccelerator(groupBox->title());
|
2013-12-03 14:17:03 +01:00
|
|
|
|
|
|
|
|
m_keywordsInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
foreach (const QString &keyword, m_keywords)
|
2020-03-27 11:56:25 +01:00
|
|
|
if (keyword.contains(regexp))
|
2013-12-03 14:17:03 +01:00
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-02-26 13:38:54 +01:00
|
|
|
|
2017-12-08 17:20:48 +01:00
|
|
|
static QList<Core::IOptionsPageProvider *> g_optionsPagesProviders;
|
|
|
|
|
|
|
|
|
|
Core::IOptionsPageProvider::IOptionsPageProvider(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
g_optionsPagesProviders.append(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::IOptionsPageProvider::~IOptionsPageProvider()
|
|
|
|
|
{
|
|
|
|
|
g_optionsPagesProviders.removeOne(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QList<Core::IOptionsPageProvider *> Core::IOptionsPageProvider::allOptionsPagesProviders()
|
|
|
|
|
{
|
|
|
|
|
return g_optionsPagesProviders;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 13:38:54 +01:00
|
|
|
QIcon Core::IOptionsPageProvider::categoryIcon() const
|
|
|
|
|
{
|
2018-04-23 18:02:55 +02:00
|
|
|
return m_categoryIcon.icon();
|
2015-02-26 13:38:54 +01:00
|
|
|
}
|