forked from qt-creator/qt-creator
Make "preferences" dialog remember last position.
Task: 234832
This commit is contained in:
@@ -30,18 +30,37 @@
|
|||||||
#include "settingsdialog.h"
|
#include "settingsdialog.h"
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
#include "icore.h"
|
||||||
|
|
||||||
|
#include <QtCore/QSettings>
|
||||||
#include <QtGui/QHeaderView>
|
#include <QtGui/QHeaderView>
|
||||||
#include <QtGui/QPushButton>
|
#include <QtGui/QPushButton>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct PageData {
|
||||||
|
int index;
|
||||||
|
QString category;
|
||||||
|
QString id;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(::PageData);
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Core::Internal;
|
using namespace Core::Internal;
|
||||||
|
|
||||||
SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
|
SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
||||||
const QString &initialPage)
|
const QString &pageId)
|
||||||
: QDialog(parent), m_applied(false)
|
: QDialog(parent), m_applied(false)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
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();
|
||||||
|
}
|
||||||
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
||||||
|
|
||||||
connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
|
connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
|
||||||
@@ -50,7 +69,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
|
|||||||
pageTree->header()->setVisible(false);
|
pageTree->header()->setVisible(false);
|
||||||
|
|
||||||
connect(pageTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
|
connect(pageTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
|
||||||
this, SLOT(pageSelected(QTreeWidgetItem *)));
|
this, SLOT(pageSelected()));
|
||||||
|
|
||||||
QMap<QString, QTreeWidgetItem *> categories;
|
QMap<QString, QTreeWidgetItem *> categories;
|
||||||
|
|
||||||
@@ -59,9 +78,14 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
|
|||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (IOptionsPage *page, pages) {
|
foreach (IOptionsPage *page, pages) {
|
||||||
|
PageData pageData;
|
||||||
|
pageData.index = index;
|
||||||
|
pageData.category = page->category();
|
||||||
|
pageData.id = page->id();
|
||||||
|
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem;
|
QTreeWidgetItem *item = new QTreeWidgetItem;
|
||||||
item->setText(0, page->trName());
|
item->setText(0, page->trName());
|
||||||
item->setData(0, Qt::UserRole, index);
|
item->setData(0, Qt::UserRole, qVariantFromValue(pageData));
|
||||||
|
|
||||||
QStringList categoriesId = page->category().split(QLatin1Char('|'));
|
QStringList categoriesId = page->category().split(QLatin1Char('|'));
|
||||||
QStringList trCategories = page->trCategory().split(QLatin1Char('|'));
|
QStringList trCategories = page->trCategory().split(QLatin1Char('|'));
|
||||||
@@ -71,7 +95,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
|
|||||||
if (!categories.contains(currentCategory)) {
|
if (!categories.contains(currentCategory)) {
|
||||||
treeitem = new QTreeWidgetItem(pageTree);
|
treeitem = new QTreeWidgetItem(pageTree);
|
||||||
treeitem->setText(0, trCategories.at(0));
|
treeitem->setText(0, trCategories.at(0));
|
||||||
treeitem->setData(0, Qt::UserRole, index);
|
treeitem->setData(0, Qt::UserRole, qVariantFromValue(pageData));
|
||||||
categories.insert(currentCategory, treeitem);
|
categories.insert(currentCategory, treeitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +105,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
|
|||||||
treeitem = new QTreeWidgetItem(categories.value(currentCategory));
|
treeitem = new QTreeWidgetItem(categories.value(currentCategory));
|
||||||
currentCategory += QLatin1Char('|') + categoriesId.at(catCount);
|
currentCategory += QLatin1Char('|') + categoriesId.at(catCount);
|
||||||
treeitem->setText(0, trCategories.at(catCount));
|
treeitem->setText(0, trCategories.at(catCount));
|
||||||
treeitem->setData(0, Qt::UserRole, index);
|
treeitem->setData(0, Qt::UserRole, qVariantFromValue(pageData));
|
||||||
categories.insert(currentCategory, treeitem);
|
categories.insert(currentCategory, treeitem);
|
||||||
} else {
|
} else {
|
||||||
currentCategory += QLatin1Char('|') + categoriesId.at(catCount);
|
currentCategory += QLatin1Char('|') + categoriesId.at(catCount);
|
||||||
@@ -114,10 +138,13 @@ SettingsDialog::~SettingsDialog()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::pageSelected(QTreeWidgetItem *)
|
void SettingsDialog::pageSelected()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *item = pageTree->currentItem();
|
QTreeWidgetItem *item = pageTree->currentItem();
|
||||||
int index = item->data(0, Qt::UserRole).toInt();
|
PageData data = item->data(0, Qt::UserRole).value<PageData>();
|
||||||
|
int index = data.index;
|
||||||
|
m_currentCategory = data.category;
|
||||||
|
m_currentPage = data.id;
|
||||||
stackedPages->setCurrentIndex(index);
|
stackedPages->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,3 +178,11 @@ bool SettingsDialog::execDialog()
|
|||||||
exec();
|
exec();
|
||||||
return m_applied;
|
return m_applied;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -53,8 +53,11 @@ public:
|
|||||||
// at least once
|
// at least once
|
||||||
bool execDialog();
|
bool execDialog();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void done(int);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void pageSelected(QTreeWidgetItem *cat);
|
void pageSelected();
|
||||||
void accept();
|
void accept();
|
||||||
void reject();
|
void reject();
|
||||||
void apply();
|
void apply();
|
||||||
@@ -62,6 +65,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QList<Core::IOptionsPage*> m_pages;
|
QList<Core::IOptionsPage*> m_pages;
|
||||||
bool m_applied;
|
bool m_applied;
|
||||||
|
QString m_currentCategory;
|
||||||
|
QString m_currentPage;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user