2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-04-24 16:47:39 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2009-04-24 16:47:39 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-04-24 16:47:39 +02:00
|
|
|
|
|
|
|
|
#include "ioptionspage.h"
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QGroupBox>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
2009-04-24 16:47:39 +02:00
|
|
|
/*!
|
|
|
|
|
\class Core::IOptionsPage
|
|
|
|
|
\mainclass
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The IOptionsPage class is an interface for providing pages for the
|
|
|
|
|
\gui Options dialog (called \gui Preferences on Mac OS).
|
2009-04-24 16:47:39 +02:00
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
You need to subclass this interface and put an instance of your subclass
|
|
|
|
|
into the plugin manager object pool (e.g. ExtensionSystem::PluginManager::addObject).
|
2009-04-24 16:47:39 +02:00
|
|
|
Guidelines for implementing:
|
|
|
|
|
\list
|
2013-09-06 16:38:53 +02:00
|
|
|
\li \c id() is a unique identifier for referencing this page
|
|
|
|
|
\li \c displayName() is the (translated) name for display
|
|
|
|
|
\li \c category() is the unique id for the category that the page should be displayed in
|
|
|
|
|
\li \c displayCategory() is the translated name of the category
|
2013-12-03 14:17:03 +01:00
|
|
|
\li \c widget() is called to retrieve the widget to show in the
|
|
|
|
|
\gui Options dialog. You should create a widget lazily here, 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.
|
2013-09-06 16:38:53 +02:00
|
|
|
\li \c apply() is called to store the settings. It should detect if any changes have been
|
2010-12-02 18:28:16 +01:00
|
|
|
made and store those
|
2013-12-03 14:17:03 +01:00
|
|
|
\li \c finish() is called directly before the \gui Options dialog closes. Here you should delete
|
|
|
|
|
the widget that was created in widget() to free resources.
|
|
|
|
|
\li \c matches() is used for the \gui Options dialog search filter. The default implementation
|
|
|
|
|
takes the widget() and searches for all labels, buttons, checkboxes and group boxes,
|
|
|
|
|
and matches on their texts/titles. You can implement your own matching algorithm, but
|
|
|
|
|
usually the default implementation will work fine.
|
2009-04-24 16:47:39 +02:00
|
|
|
\endlist
|
|
|
|
|
*/
|
2013-12-03 14:17:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
Core::IOptionsPage::IOptionsPage(QObject *parent)
|
|
|
|
|
: QObject(parent),
|
|
|
|
|
m_keywordsInitialized(false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::IOptionsPage::~IOptionsPage()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Core::IOptionsPage::matches(const QString &searchKeyWord) const
|
|
|
|
|
{
|
|
|
|
|
if (!m_keywordsInitialized) {
|
|
|
|
|
IOptionsPage *that = const_cast<IOptionsPage *>(this);
|
|
|
|
|
QWidget *widget = that->widget();
|
|
|
|
|
if (!widget)
|
|
|
|
|
return false;
|
|
|
|
|
// find common subwidgets
|
|
|
|
|
foreach (const QLabel *label, widget->findChildren<QLabel *>())
|
|
|
|
|
m_keywords << label->text();
|
|
|
|
|
foreach (const QCheckBox *checkbox, widget->findChildren<QCheckBox *>())
|
|
|
|
|
m_keywords << checkbox->text();
|
|
|
|
|
foreach (const QPushButton *pushButton, widget->findChildren<QPushButton *>())
|
|
|
|
|
m_keywords << pushButton->text();
|
|
|
|
|
foreach (const QGroupBox *groupBox, widget->findChildren<QGroupBox *>())
|
|
|
|
|
m_keywords << groupBox->title();
|
|
|
|
|
|
|
|
|
|
// clean up accelerators
|
|
|
|
|
QMutableStringListIterator it(m_keywords);
|
|
|
|
|
while (it.hasNext())
|
|
|
|
|
it.next().remove(QLatin1Char('&'));
|
|
|
|
|
m_keywordsInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
foreach (const QString &keyword, m_keywords)
|
|
|
|
|
if (keyword.contains(searchKeyWord, Qt::CaseInsensitive))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|