2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2009-03-19 18:14:54 +01:00
|
|
|
#include "icore.h"
|
2009-01-19 12:39:20 +01:00
|
|
|
|
2009-11-19 17:47:13 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2009-11-27 13:54:27 +01:00
|
|
|
#include <utils/filterlineedit.h>
|
2009-11-19 17:47:13 +01:00
|
|
|
|
2009-03-19 18:14:54 +01:00
|
|
|
#include <QtCore/QSettings>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QHeaderView>
|
2009-11-19 17:47:13 +01:00
|
|
|
#include <QtGui/QStandardItemModel>
|
|
|
|
|
#include <QtGui/QStandardItem>
|
|
|
|
|
#include <QtGui/QSortFilterProxyModel>
|
|
|
|
|
#include <QtGui/QItemSelectionModel>
|
2009-11-27 13:54:27 +01:00
|
|
|
#include <QtGui/QHBoxLayout>
|
2009-11-19 17:47:13 +01:00
|
|
|
#include <QtGui/QIcon>
|
2009-11-24 15:05:02 +01:00
|
|
|
#include <QtGui/QLabel>
|
2009-11-27 13:54:27 +01:00
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
#include <QtGui/QToolButton>
|
|
|
|
|
#include <QtGui/QToolBar>
|
2009-11-24 15:05:02 +01:00
|
|
|
#include <QtGui/QSpacerItem>
|
|
|
|
|
#include <QtGui/QStyle>
|
2009-11-27 13:54:27 +01:00
|
|
|
#include <QtGui/QStackedLayout>
|
|
|
|
|
#include <QtGui/QGridLayout>
|
|
|
|
|
#include <QtGui/QLineEdit>
|
|
|
|
|
#include <QtGui/QFrame>
|
|
|
|
|
#include <QtGui/QDialogButtonBox>
|
|
|
|
|
#include <QtGui/QTreeView>
|
|
|
|
|
#include <QtGui/QApplication>
|
2009-11-19 17:47:13 +01:00
|
|
|
|
|
|
|
|
enum ItemType { CategoryItem, PageItem };
|
|
|
|
|
|
|
|
|
|
enum { TypeRole = Qt::UserRole + 1,
|
|
|
|
|
IndexRole = Qt::UserRole + 2,
|
|
|
|
|
PageRole = Qt::UserRole + 3 };
|
|
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Core::IOptionsPage*)
|
|
|
|
|
|
|
|
|
|
static const char categoryKeyC[] = "General/LastPreferenceCategory";
|
|
|
|
|
static const char pageKeyC[] = "General/LastPreferencePage";
|
|
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-19 17:47:13 +01:00
|
|
|
// Create item on either model or parent item
|
|
|
|
|
template<class Parent>
|
|
|
|
|
inline QStandardItem *createStandardItem(Parent *parent,
|
|
|
|
|
const QString &text,
|
|
|
|
|
ItemType type = CategoryItem,
|
|
|
|
|
int index = -1,
|
|
|
|
|
IOptionsPage *page = 0)
|
|
|
|
|
{
|
|
|
|
|
QStandardItem *rc = new QStandardItem(text);
|
2009-11-20 12:56:49 +01:00
|
|
|
rc->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
|
2009-11-19 17:47:13 +01:00
|
|
|
rc->setData(QVariant(int(type)), TypeRole);
|
|
|
|
|
rc->setData(QVariant(index), IndexRole);
|
|
|
|
|
rc->setData(qVariantFromValue(page), PageRole);
|
|
|
|
|
parent->appendRow(rc);
|
|
|
|
|
return rc;
|
2009-03-19 18:14:54 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-19 17:47:13 +01:00
|
|
|
static inline ItemType itemTypeOfItem(const QStandardItem *item)
|
|
|
|
|
{
|
|
|
|
|
return static_cast<ItemType>(item->data(TypeRole).toInt());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline ItemType itemTypeOfItem(const QAbstractItemModel *model, const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
return static_cast<ItemType>(model->data(index, TypeRole).toInt());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int indexOfItem(const QStandardItem *item)
|
|
|
|
|
{
|
|
|
|
|
return item->data(IndexRole).toInt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline IOptionsPage *pageOfItem(const QStandardItem *item)
|
|
|
|
|
{
|
|
|
|
|
return qvariant_cast<IOptionsPage *>(item->data(PageRole));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline IOptionsPage *pageOfItem(const QAbstractItemModel *model, const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
return qvariant_cast<IOptionsPage *>(model->data(index, PageRole));
|
|
|
|
|
}
|
2009-03-19 18:14:54 +01:00
|
|
|
|
2009-11-19 17:47:13 +01:00
|
|
|
// A filter model that returns true for the parent (category) nodes
|
|
|
|
|
// (which by default do not match the search string and are thus collapsed)
|
|
|
|
|
// and additionally checks IOptionsPage::matches().
|
|
|
|
|
class PageFilterModel : public QSortFilterProxyModel {
|
|
|
|
|
public:
|
|
|
|
|
explicit PageFilterModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {}
|
|
|
|
|
protected:
|
|
|
|
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool PageFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
|
|
|
|
{
|
|
|
|
|
if (!source_parent.isValid())
|
|
|
|
|
return true; // Always true for parents/categories.
|
|
|
|
|
// Regular contents check, then check page-filter.
|
|
|
|
|
if (QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent))
|
|
|
|
|
return true;
|
2009-11-20 12:56:49 +01:00
|
|
|
if (const IOptionsPage *page = pageOfItem(sourceModel(), source_parent.child(source_row, 0))) {
|
|
|
|
|
const QString pattern = filterRegExp().pattern();
|
2010-01-07 18:17:24 +01:00
|
|
|
return page->displayCategory().contains(pattern, Qt::CaseInsensitive) ||
|
2009-11-20 12:56:49 +01:00
|
|
|
page->matches(pattern);
|
|
|
|
|
}
|
2009-11-19 17:47:13 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Populate a model with pages.
|
|
|
|
|
static QStandardItemModel *pageModel(const QList<IOptionsPage*> &pages,
|
|
|
|
|
QObject *parent,
|
|
|
|
|
const QString &initialCategory,
|
|
|
|
|
const QString &initialPageId,
|
|
|
|
|
QModelIndex *initialIndex)
|
|
|
|
|
{
|
|
|
|
|
QStandardItemModel *model = new QStandardItemModel(0, 1, parent);
|
|
|
|
|
const QChar hierarchySeparator = QLatin1Char('|');
|
|
|
|
|
int index = 0;
|
|
|
|
|
QMap<QString, QStandardItem *> categories;
|
|
|
|
|
foreach (IOptionsPage *page, pages) {
|
|
|
|
|
const QStringList categoriesId = page->category().split(hierarchySeparator);
|
2010-01-07 18:17:24 +01:00
|
|
|
const QStringList displayCategories = page->displayCategory().split(hierarchySeparator);
|
2009-11-19 17:47:13 +01:00
|
|
|
const int categoryDepth = categoriesId.size();
|
2010-01-07 18:17:24 +01:00
|
|
|
if (categoryDepth != displayCategories.size()) {
|
2009-11-19 17:47:13 +01:00
|
|
|
qWarning("Internal error: Hierarchy mismatch in settings page %s.", qPrintable(page->id()));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retrieve/Create parent items for nested categories "Cat1|Cat2|Cat3"
|
|
|
|
|
QString currentCategory = categoriesId.at(0);
|
|
|
|
|
QStandardItem *treeItem = categories.value(currentCategory, 0);
|
|
|
|
|
if (!treeItem) {
|
2010-01-07 18:17:24 +01:00
|
|
|
treeItem = createStandardItem(model, displayCategories.at(0), CategoryItem);
|
2009-11-19 17:47:13 +01:00
|
|
|
categories.insert(currentCategory, treeItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int cat = 1; cat < categoryDepth; cat++) {
|
|
|
|
|
const QString fullCategory = currentCategory + hierarchySeparator + categoriesId.at(cat);
|
|
|
|
|
treeItem = categories.value(fullCategory, 0);
|
|
|
|
|
if (!treeItem) {
|
|
|
|
|
QStandardItem *parentItem = categories.value(currentCategory);
|
|
|
|
|
QTC_ASSERT(parentItem, return model)
|
2010-01-07 18:17:24 +01:00
|
|
|
treeItem = createStandardItem(parentItem, displayCategories.at(cat), CategoryItem);
|
2009-11-19 17:47:13 +01:00
|
|
|
categories.insert(fullCategory, treeItem);
|
|
|
|
|
}
|
|
|
|
|
currentCategory = fullCategory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Append page item
|
|
|
|
|
QTC_ASSERT(treeItem, return model)
|
2010-01-07 18:17:24 +01:00
|
|
|
QStandardItem *item = createStandardItem(treeItem, page->displayName(), PageItem, index, page);
|
2009-11-19 17:47:13 +01:00
|
|
|
if (currentCategory == initialCategory && page->id() == initialPageId) {
|
|
|
|
|
*initialIndex = model->indexFromItem(item);
|
|
|
|
|
}
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
return model;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-12-10 14:01:37 +01:00
|
|
|
// ----------- Pages tree view
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Special version of a QTreeView that has the width of the first column as
|
|
|
|
|
* minimum size.
|
|
|
|
|
*/
|
|
|
|
|
class PageTree : public QTreeView
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
PageTree(QWidget *parent = 0) : QTreeView(parent)
|
|
|
|
|
{
|
|
|
|
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual QSize sizeHint() const
|
|
|
|
|
{
|
|
|
|
|
return QSize(sizeHintForColumn(0) + frameWidth() * 2, 100);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2009-11-27 16:12:12 +01:00
|
|
|
// ----------- SettingsDialog
|
|
|
|
|
|
|
|
|
|
// Helpers to sort by category. id
|
|
|
|
|
bool optionsPageLessThan(const IOptionsPage *p1, const IOptionsPage *p2)
|
|
|
|
|
{
|
|
|
|
|
if (const int cc = p1->category().compare(p2->category()))
|
|
|
|
|
return cc < 0;
|
|
|
|
|
return p1->id().compare(p2->id()) < 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QList<Core::IOptionsPage*> sortedOptionsPages()
|
|
|
|
|
{
|
|
|
|
|
QList<Core::IOptionsPage*> rc = ExtensionSystem::PluginManager::instance()->getObjects<IOptionsPage>();
|
|
|
|
|
qStableSort(rc.begin(), rc.end(), optionsPageLessThan);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-19 18:14:54 +01:00
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
2009-11-19 17:47:13 +01:00
|
|
|
const QString &pageId) :
|
|
|
|
|
QDialog(parent),
|
2009-11-27 16:12:12 +01:00
|
|
|
m_pages(sortedOptionsPages()),
|
2009-11-19 17:47:13 +01:00
|
|
|
m_proxyModel(new PageFilterModel),
|
|
|
|
|
m_model(0),
|
2009-11-27 13:54:27 +01:00
|
|
|
m_applied(false),
|
|
|
|
|
m_stackedLayout(new QStackedLayout),
|
|
|
|
|
m_filterLineEdit(new Utils::FilterLineEdit),
|
2009-12-10 14:01:37 +01:00
|
|
|
m_pageTree(new PageTree),
|
2009-11-27 13:54:27 +01:00
|
|
|
m_headerLabel(new QLabel)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-27 13:54:27 +01:00
|
|
|
createGui();
|
2009-11-20 16:55:23 +01:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2009-09-17 10:38:53 +02:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
|
setWindowTitle(tr("Preferences"));
|
|
|
|
|
#else
|
|
|
|
|
setWindowTitle(tr("Options"));
|
|
|
|
|
#endif
|
2009-03-19 18:14:54 +01:00
|
|
|
QString initialCategory = categoryId;
|
|
|
|
|
QString initialPage = pageId;
|
|
|
|
|
if (initialCategory.isEmpty() && initialPage.isEmpty()) {
|
|
|
|
|
QSettings *settings = ICore::instance()->settings();
|
2009-11-19 17:47:13 +01:00
|
|
|
initialCategory = settings->value(QLatin1String(categoryKeyC), QVariant(QString())).toString();
|
|
|
|
|
initialPage = settings->value(QLatin1String(pageKeyC), QVariant(QString())).toString();
|
2009-03-19 18:14:54 +01:00
|
|
|
}
|
2009-01-05 13:45:30 +01:00
|
|
|
|
2009-11-24 15:05:02 +01:00
|
|
|
// Create pages with title labels with a larger, bold font, left-aligned
|
|
|
|
|
// with the group boxes of the page.
|
2009-12-10 14:01:37 +01:00
|
|
|
foreach (IOptionsPage *page, m_pages)
|
2009-11-27 13:54:27 +01:00
|
|
|
m_stackedLayout->addWidget(page->createPage(0));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-19 17:47:13 +01:00
|
|
|
QModelIndex initialIndex;
|
|
|
|
|
m_model = pageModel(m_pages, 0, initialCategory, initialPage, &initialIndex);
|
|
|
|
|
m_proxyModel->setFilterKeyColumn(0);
|
|
|
|
|
m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
|
m_proxyModel->setSourceModel(m_model);
|
2009-11-27 13:54:27 +01:00
|
|
|
m_pageTree->setModel(m_proxyModel);
|
|
|
|
|
m_pageTree->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
connect(m_pageTree->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
|
2009-11-19 17:47:13 +01:00
|
|
|
this, SLOT(currentChanged(QModelIndex,QModelIndex)));
|
|
|
|
|
if (initialIndex.isValid()) {
|
|
|
|
|
const QModelIndex proxyIndex = m_proxyModel->mapFromSource(initialIndex);
|
2009-11-27 13:54:27 +01:00
|
|
|
m_pageTree->selectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-19 17:47:13 +01:00
|
|
|
// The order of the slot connection matters here, the filter slot
|
|
|
|
|
// opens the matching page after the model has filtered.
|
2009-11-27 13:54:27 +01:00
|
|
|
connect(m_filterLineEdit, SIGNAL(filterChanged(QString)),
|
2009-11-19 17:47:13 +01:00
|
|
|
m_proxyModel, SLOT(setFilterFixedString(QString)));
|
2009-11-27 13:54:27 +01:00
|
|
|
connect(m_filterLineEdit, SIGNAL(filterChanged(QString)), this, SLOT(filter(QString)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::createGui()
|
|
|
|
|
{
|
|
|
|
|
// Header label with large font and a bit of spacing (align with group boxes)
|
|
|
|
|
QFont headerLabelFont = m_headerLabel->font();
|
|
|
|
|
headerLabelFont.setBold(true);
|
|
|
|
|
// Paranoia: Should a font be set in pixels...
|
|
|
|
|
const int pointSize = headerLabelFont.pointSize();
|
|
|
|
|
if (pointSize > 0)
|
|
|
|
|
headerLabelFont.setPointSize(pointSize + 2);
|
|
|
|
|
m_headerLabel->setFont(headerLabelFont);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *headerHLayout = new QHBoxLayout;
|
|
|
|
|
const int leftMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) +
|
|
|
|
|
qApp->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
|
|
|
|
headerHLayout->addSpacerItem(new QSpacerItem(leftMargin, 0, QSizePolicy::Fixed, QSizePolicy::Ignored));
|
|
|
|
|
headerHLayout->addWidget(m_headerLabel);
|
|
|
|
|
|
|
|
|
|
// Tree
|
|
|
|
|
m_pageTree->header()->setVisible(false);
|
|
|
|
|
m_stackedLayout->setMargin(0);
|
|
|
|
|
|
|
|
|
|
// Separator Line
|
|
|
|
|
QFrame *bottomLine = new QFrame;
|
|
|
|
|
bottomLine->setFrameShape(QFrame::HLine);
|
|
|
|
|
bottomLine->setFrameShadow(QFrame::Sunken);
|
|
|
|
|
|
|
|
|
|
// Button box
|
|
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Apply|QDialogButtonBox::Cancel);
|
|
|
|
|
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
|
|
|
|
connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
|
|
|
|
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
|
|
|
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
|
|
|
|
|
|
|
|
|
QGridLayout *mainGridLayout = new QGridLayout;
|
|
|
|
|
mainGridLayout->addWidget(m_filterLineEdit, 0, 0, 1, 1);
|
|
|
|
|
mainGridLayout->addLayout(headerHLayout, 0, 1, 1, 1);
|
|
|
|
|
mainGridLayout->addWidget(m_pageTree, 1, 0, 2, 1);
|
|
|
|
|
mainGridLayout->addLayout(m_stackedLayout, 1, 1, 1, 1);
|
|
|
|
|
mainGridLayout->addWidget(bottomLine, 2, 1, 1, 1);
|
|
|
|
|
mainGridLayout->addWidget(buttonBox, 3, 0, 1, 2);
|
|
|
|
|
mainGridLayout->setColumnStretch(0, 1);
|
|
|
|
|
mainGridLayout->setColumnStretch(1, 4);
|
|
|
|
|
setLayout(mainGridLayout);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-19 17:47:13 +01:00
|
|
|
void SettingsDialog::showPage(const QStandardItem *item)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-19 17:47:13 +01:00
|
|
|
// Show a page item or recurse to the first page of a category
|
|
|
|
|
// if a category was hit.
|
|
|
|
|
switch (itemTypeOfItem(item)) {
|
|
|
|
|
case PageItem: {
|
2009-11-24 15:05:02 +01:00
|
|
|
IOptionsPage *page = pageOfItem(item);
|
2009-11-19 17:47:13 +01:00
|
|
|
m_currentCategory = page->category();
|
|
|
|
|
m_currentPage = page->id();
|
2009-11-27 13:54:27 +01:00
|
|
|
m_stackedLayout->setCurrentIndex(indexOfItem(item));
|
2009-11-24 15:05:02 +01:00
|
|
|
m_visitedPages.insert(page);
|
2010-01-07 18:17:24 +01:00
|
|
|
m_headerLabel->setText(page->displayName());
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case CategoryItem:
|
|
|
|
|
if (const QStandardItem *child = item->child(0, 0))
|
|
|
|
|
showPage(child);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::currentChanged(const QModelIndex & current, const QModelIndex & /*previous */)
|
|
|
|
|
{
|
|
|
|
|
if (current.isValid())
|
|
|
|
|
if (const QStandardItem *item = m_model->itemFromIndex(m_proxyModel->mapToSource(current)))
|
|
|
|
|
showPage(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helpers that recurse down the model to find a page.
|
|
|
|
|
static QModelIndex findPage(const QModelIndex &root)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(root.isValid(), return root)
|
|
|
|
|
const QAbstractItemModel *model = root.model();
|
|
|
|
|
// Found a page!
|
|
|
|
|
if (itemTypeOfItem(model, root) == PageItem)
|
|
|
|
|
return root;
|
|
|
|
|
// Recurse down category.
|
|
|
|
|
const int childCount = model->rowCount(root);
|
|
|
|
|
for (int c = 0; c < childCount; c++) {
|
|
|
|
|
const QModelIndex page = findPage(root.child(c, 0));
|
|
|
|
|
if (page.isValid())
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QModelIndex findPage(const QAbstractItemModel *model)
|
|
|
|
|
{
|
|
|
|
|
const QModelIndex invalid;
|
|
|
|
|
// Traverse top categories
|
|
|
|
|
const int rootItemCount = model->rowCount(invalid);
|
|
|
|
|
for (int c = 0; c < rootItemCount; c++) {
|
|
|
|
|
const QModelIndex page = findPage(model->index(c, 0, invalid));
|
|
|
|
|
if (page.isValid())
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
return invalid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::filter(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
// Filter cleared, collapse all.
|
|
|
|
|
if (text.isEmpty()) {
|
2009-11-27 13:54:27 +01:00
|
|
|
m_pageTree->collapseAll();
|
2009-11-19 17:47:13 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Expand match and select the first page. Note: This depends
|
|
|
|
|
// on the order of slot invocation, needs to be done after filtering
|
|
|
|
|
if (!m_proxyModel->rowCount(QModelIndex()))
|
|
|
|
|
return;
|
2009-11-27 13:54:27 +01:00
|
|
|
m_pageTree->expandAll();
|
2009-11-19 17:47:13 +01:00
|
|
|
const QModelIndex firstVisiblePage = findPage(m_proxyModel);
|
|
|
|
|
if (firstVisiblePage.isValid())
|
2009-11-27 13:54:27 +01:00
|
|
|
m_pageTree->selectionModel()->setCurrentIndex(firstVisiblePage, QItemSelectionModel::ClearAndSelect);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::accept()
|
|
|
|
|
{
|
2009-03-18 16:43:01 +01:00
|
|
|
m_applied = true;
|
2009-11-24 15:05:02 +01:00
|
|
|
foreach (IOptionsPage *page, m_visitedPages)
|
2009-01-13 15:41:33 +01:00
|
|
|
page->apply();
|
2009-11-24 15:05:02 +01:00
|
|
|
foreach (IOptionsPage *page, m_pages)
|
2009-01-13 15:41:33 +01:00
|
|
|
page->finish();
|
2008-12-02 12:01:29 +01:00
|
|
|
done(QDialog::Accepted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::reject()
|
|
|
|
|
{
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (IOptionsPage *page, m_pages)
|
2009-01-13 15:41:33 +01:00
|
|
|
page->finish();
|
2008-12-02 12:01:29 +01:00
|
|
|
done(QDialog::Rejected);
|
|
|
|
|
}
|
2009-01-05 13:45:30 +01:00
|
|
|
|
|
|
|
|
void SettingsDialog::apply()
|
|
|
|
|
{
|
2009-11-24 15:05:02 +01:00
|
|
|
foreach (IOptionsPage *page, m_visitedPages)
|
2009-01-13 15:41:33 +01:00
|
|
|
page->apply();
|
2009-03-18 16:43:01 +01:00
|
|
|
m_applied = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SettingsDialog::execDialog()
|
|
|
|
|
{
|
2009-11-27 13:54:27 +01:00
|
|
|
m_pageTree->setFocus();
|
2009-03-18 16:43:01 +01:00
|
|
|
m_applied = false;
|
|
|
|
|
exec();
|
|
|
|
|
return m_applied;
|
2009-01-05 13:45:30 +01:00
|
|
|
}
|
2009-03-19 18:14:54 +01:00
|
|
|
|
|
|
|
|
void SettingsDialog::done(int val)
|
|
|
|
|
{
|
|
|
|
|
QSettings *settings = ICore::instance()->settings();
|
2009-11-19 17:47:13 +01:00
|
|
|
settings->setValue(QLatin1String(categoryKeyC), m_currentCategory);
|
|
|
|
|
settings->setValue(QLatin1String(pageKeyC), m_currentPage);
|
2009-03-19 18:14:54 +01:00
|
|
|
QDialog::done(val);
|
|
|
|
|
}
|
2009-11-19 17:47:13 +01:00
|
|
|
|
2009-12-10 14:01:37 +01:00
|
|
|
/**
|
|
|
|
|
* Override to make sure the settings dialog starts up as small as possible.
|
|
|
|
|
*/
|
|
|
|
|
QSize SettingsDialog::sizeHint() const
|
|
|
|
|
{
|
|
|
|
|
return minimumSize();
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
|
|
|
|
}
|