2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 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-06-17 00:01:27 +10:00
|
|
|
** contact the sales department at http://www.qtsoftware.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-03-19 18:14:54 +01:00
|
|
|
#include <QtCore/QSettings>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QHeaderView>
|
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
|
2009-03-19 18:14:54 +01:00
|
|
|
namespace {
|
|
|
|
|
struct PageData {
|
|
|
|
|
int index;
|
|
|
|
|
QString category;
|
|
|
|
|
QString id;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(::PageData);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
2009-03-19 18:14:54 +01:00
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
|
|
|
|
const QString &pageId)
|
2009-03-18 16:43:01 +01:00
|
|
|
: QDialog(parent), m_applied(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setupUi(this);
|
2009-03-19 18:14:54 +01:00
|
|
|
QString initialCategory = categoryId;
|
|
|
|
|
QString initialPage = pageId;
|
|
|
|
|
if (initialCategory.isEmpty() && initialPage.isEmpty()) {
|
|
|
|
|
QSettings *settings = ICore::instance()->settings();
|
|
|
|
|
initialCategory = settings->value("General/LastPreferenceCategory", QVariant(QString())).toString();
|
|
|
|
|
initialPage = settings->value("General/LastPreferencePage", QVariant(QString())).toString();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
|
|
|
|
|
2009-01-05 13:45:30 +01:00
|
|
|
connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
|
|
|
|
|
|
2008-12-10 12:33:14 +01:00
|
|
|
splitter->setCollapsible(1, false);
|
2008-12-02 12:01:29 +01:00
|
|
|
pageTree->header()->setVisible(false);
|
|
|
|
|
|
|
|
|
|
connect(pageTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
|
2009-03-19 18:14:54 +01:00
|
|
|
this, SLOT(pageSelected()));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QMap<QString, QTreeWidgetItem *> categories;
|
|
|
|
|
|
|
|
|
|
QList<IOptionsPage*> pages =
|
2009-01-20 15:31:33 +01:00
|
|
|
ExtensionSystem::PluginManager::instance()->getObjects<IOptionsPage>();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
int index = 0;
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (IOptionsPage *page, pages) {
|
2009-03-19 18:14:54 +01:00
|
|
|
PageData pageData;
|
|
|
|
|
pageData.index = index;
|
|
|
|
|
pageData.category = page->category();
|
|
|
|
|
pageData.id = page->id();
|
|
|
|
|
|
2008-12-10 12:33:14 +01:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem;
|
2009-03-18 16:43:01 +01:00
|
|
|
item->setText(0, page->trName());
|
2009-03-19 18:14:54 +01:00
|
|
|
item->setData(0, Qt::UserRole, qVariantFromValue(pageData));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QStringList categoriesId = page->category().split(QLatin1Char('|'));
|
|
|
|
|
QStringList trCategories = page->trCategory().split(QLatin1Char('|'));
|
|
|
|
|
QString currentCategory = categoriesId.at(0);
|
|
|
|
|
|
|
|
|
|
QTreeWidgetItem *treeitem;
|
|
|
|
|
if (!categories.contains(currentCategory)) {
|
|
|
|
|
treeitem = new QTreeWidgetItem(pageTree);
|
|
|
|
|
treeitem->setText(0, trCategories.at(0));
|
2009-03-19 18:14:54 +01:00
|
|
|
treeitem->setData(0, Qt::UserRole, qVariantFromValue(pageData));
|
2008-12-02 12:01:29 +01:00
|
|
|
categories.insert(currentCategory, treeitem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int catCount = 1;
|
|
|
|
|
while (catCount < categoriesId.count()) {
|
2008-12-09 11:07:24 +01:00
|
|
|
if (!categories.contains(currentCategory + QLatin1Char('|') + categoriesId.at(catCount))) {
|
2008-12-02 12:01:29 +01:00
|
|
|
treeitem = new QTreeWidgetItem(categories.value(currentCategory));
|
|
|
|
|
currentCategory += QLatin1Char('|') + categoriesId.at(catCount);
|
|
|
|
|
treeitem->setText(0, trCategories.at(catCount));
|
2009-03-19 18:14:54 +01:00
|
|
|
treeitem->setData(0, Qt::UserRole, qVariantFromValue(pageData));
|
2008-12-02 12:01:29 +01:00
|
|
|
categories.insert(currentCategory, treeitem);
|
|
|
|
|
} else {
|
|
|
|
|
currentCategory += QLatin1Char('|') + categoriesId.at(catCount);
|
|
|
|
|
}
|
|
|
|
|
++catCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
categories.value(currentCategory)->addChild(item);
|
|
|
|
|
|
|
|
|
|
m_pages.append(page);
|
|
|
|
|
stackedPages->addWidget(page->createPage(stackedPages));
|
|
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
if (page->id() == initialPage && currentCategory == initialCategory) {
|
2008-12-02 12:01:29 +01:00
|
|
|
stackedPages->setCurrentIndex(stackedPages->count());
|
|
|
|
|
pageTree->setCurrentItem(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<int> sizes;
|
|
|
|
|
sizes << 150 << 300;
|
|
|
|
|
splitter->setSizes(sizes);
|
|
|
|
|
|
|
|
|
|
splitter->setStretchFactor(splitter->indexOf(pageTree), 0);
|
|
|
|
|
splitter->setStretchFactor(splitter->indexOf(layoutWidget), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-19 18:14:54 +01:00
|
|
|
void SettingsDialog::pageSelected()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
QTreeWidgetItem *item = pageTree->currentItem();
|
2009-03-19 18:14:54 +01:00
|
|
|
PageData data = item->data(0, Qt::UserRole).value<PageData>();
|
|
|
|
|
int index = data.index;
|
|
|
|
|
m_currentCategory = data.category;
|
|
|
|
|
m_currentPage = data.id;
|
2008-12-02 12:01:29 +01:00
|
|
|
stackedPages->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::accept()
|
|
|
|
|
{
|
2009-03-18 16:43:01 +01:00
|
|
|
m_applied = true;
|
2009-01-13 15:41:33 +01:00
|
|
|
foreach (IOptionsPage *page, m_pages) {
|
|
|
|
|
page->apply();
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
foreach (IOptionsPage *page, m_pages)
|
2009-01-13 15:41:33 +01:00
|
|
|
page->apply();
|
2009-03-18 16:43:01 +01:00
|
|
|
m_applied = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SettingsDialog::execDialog()
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
settings->setValue("General/LastPreferenceCategory", m_currentCategory);
|
|
|
|
|
settings->setValue("General/LastPreferencePage", m_currentPage);
|
|
|
|
|
QDialog::done(val);
|
|
|
|
|
}
|