Use Core::Id for IOptionPage::category

Change-Id: I63433edd9118a7aa4ecaef28f40bfc729d90f512
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
hjk
2012-12-29 03:37:27 +01:00
parent 1863bfebdb
commit 78beacd7b4
40 changed files with 62 additions and 63 deletions

View File

@@ -30,7 +30,7 @@
#ifndef IOPTIONSPAGE_H
#define IOPTIONSPAGE_H
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <QIcon>
#include <QObject>
@@ -46,7 +46,7 @@ public:
QString id() const { return m_id; }
QString displayName() const { return m_displayName; }
QString category() const { return m_category; }
Core::Id category() const { return m_category; }
QString displayCategory() const { return m_displayCategory; }
QIcon categoryIcon() const { return QIcon(m_categoryIcon); }
@@ -58,13 +58,13 @@ public:
protected:
void setId(const QString &id) { m_id = id; }
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
void setCategory(const QString &category) { m_category = category; }
void setCategory(Id category) { m_category = category; }
void setDisplayCategory(const QString &displayCategory) { m_displayCategory = displayCategory; }
void setCategoryIcon(const QString &categoryIcon) { m_categoryIcon = categoryIcon; }
QString m_id;
QString m_displayName;
QString m_category;
Core::Id m_category;
QString m_displayCategory;
QString m_categoryIcon;
};
@@ -84,18 +84,18 @@ class CORE_EXPORT IOptionsPageProvider : public QObject
public:
IOptionsPageProvider(QObject *parent = 0) : QObject(parent) {}
QString category() const { return m_category; }
Core::Id category() const { return m_category; }
QString displayCategory() const { return m_displayCategory; }
QIcon categoryIcon() const { return QIcon(m_categoryIcon); }
virtual QList<IOptionsPage *> pages() const = 0;
protected:
void setCategory(const QString &category) { m_category = category; }
void setCategory(Core::Id category) { m_category = category; }
void setDisplayCategory(const QString &displayCategory) { m_displayCategory = displayCategory; }
void setCategoryIcon(const QString &categoryIcon) { m_categoryIcon = categoryIcon; }
QString m_category;
Core::Id m_category;
QString m_displayCategory;
QString m_categoryIcon;
};

View File

@@ -69,9 +69,10 @@ static QPointer<SettingsDialog> m_instance = 0;
// ----------- Category model
class Category {
class Category
{
public:
QString id;
Id id;
QString displayName;
QIcon icon;
QList<IOptionsPage *> pages;
@@ -94,7 +95,7 @@ public:
const QList<Category*> &categories() const { return m_categories; }
private:
Category *findCategoryById(const QString &id);
Category *findCategoryById(Id id);
QList<Category*> m_categories;
QIcon m_emptyIcon;
@@ -145,7 +146,7 @@ void CategoryModel::setPages(const QList<IOptionsPage*> &pages,
// Put the pages in categories
foreach (IOptionsPage *page, pages) {
const QString &categoryId = page->category();
const Id categoryId = page->category();
Category *category = findCategoryById(categoryId);
if (!category) {
category = new Category;
@@ -162,7 +163,7 @@ void CategoryModel::setPages(const QList<IOptionsPage*> &pages,
}
foreach (IOptionsPageProvider *provider, providers) {
const QString &categoryId = provider->category();
const Id categoryId = provider->category();
Category *category = findCategoryById(categoryId);
if (!category) {
category = new Category;
@@ -181,7 +182,7 @@ void CategoryModel::setPages(const QList<IOptionsPage*> &pages,
endResetModel();
}
Category *CategoryModel::findCategoryById(const QString &id)
Category *CategoryModel::findCategoryById(Id id)
{
for (int i = 0; i < m_categories.size(); ++i) {
Category *category = m_categories.at(i);
@@ -269,7 +270,7 @@ public:
// Helpers to sort by category. id
bool optionsPageLessThan(const IOptionsPage *p1, const IOptionsPage *p2)
{
if (const int cc = p1->category().compare(p2->category()))
if (const int cc = p1->category().toString().compare(p2->category().toString()))
return cc < 0;
return p1->id().compare(p2->id()) < 0;
}
@@ -329,11 +330,11 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
void SettingsDialog::showPage(Id categoryId, Id pageId)
{
// handle the case of "show last page"
QString initialCategory = categoryId.toString();
Id initialCategory = categoryId;
QString initialPage = pageId.toString();
if (initialCategory.isEmpty() && initialPage.isEmpty()) {
if (!initialCategory.isValid() && initialPage.isEmpty()) {
QSettings *settings = ICore::settings();
initialCategory = settings->value(QLatin1String(categoryKeyC), QVariant(QString())).toString();
initialCategory = Id(settings->value(QLatin1String(categoryKeyC), QVariant(QString())).toString());
initialPage = settings->value(QLatin1String(pageKeyC), QVariant(QString())).toString();
}
@@ -462,7 +463,7 @@ void SettingsDialog::updateEnabledTabs(Category *category, const QString &search
for (int i = 0; i < category->pages.size(); ++i) {
const IOptionsPage *page = category->pages.at(i);
const bool enabled = searchText.isEmpty()
|| page->category().contains(searchText, Qt::CaseInsensitive)
|| page->category().toString().contains(searchText, Qt::CaseInsensitive)
|| page->displayName().contains(searchText, Qt::CaseInsensitive)
|| page->matches(searchText);
category->tabWidget->setTabEnabled(i, enabled);
@@ -541,7 +542,7 @@ void SettingsDialog::apply()
void SettingsDialog::done(int val)
{
QSettings *settings = ICore::settings();
settings->setValue(QLatin1String(categoryKeyC), m_currentCategory);
settings->setValue(QLatin1String(categoryKeyC), m_currentCategory.toString());
settings->setValue(QLatin1String(pageKeyC), m_currentPage);
ICore::saveSettings(); // save all settings

View File

@@ -35,7 +35,6 @@
#include <QList>
#include <QSet>
#include <QPointer>
#include <QEventLoop>
#include <QDialog>
@@ -99,7 +98,7 @@ private:
QSet<Core::IOptionsPage*> m_visitedPages;
QSortFilterProxyModel *m_proxyModel;
CategoryModel *m_model;
QString m_currentCategory;
Core::Id m_currentCategory;
QString m_currentPage;
QStackedLayout *m_stackedLayout;
Utils::FilterLineEdit *m_filterLineEdit;

View File

@@ -62,7 +62,7 @@ ShortcutSettings::ShortcutSettings(QObject *parent)
setId(QLatin1String(Core::Constants::SETTINGS_ID_SHORTCUTS));
setDisplayName(tr("Keyboard"));
setCategory(QLatin1String(Core::Constants::SETTINGS_CATEGORY_CORE));
setCategory(Core::Constants::SETTINGS_CATEGORY_CORE);
setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::SETTINGS_TR_CATEGORY_CORE));
setCategoryIcon(QLatin1String(Core::Constants::SETTINGS_CATEGORY_CORE_ICON));
}

View File

@@ -56,7 +56,7 @@ GeneralSettings::GeneralSettings():
{
setId(QLatin1String(Core::Constants::SETTINGS_ID_ENVIRONMENT));
setDisplayName(tr("General"));
setCategory(QLatin1String(Core::Constants::SETTINGS_CATEGORY_CORE));
setCategory(Core::Constants::SETTINGS_CATEGORY_CORE);
setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::SETTINGS_TR_CATEGORY_CORE));
setCategoryIcon(QLatin1String(Core::Constants::SETTINGS_CATEGORY_CORE_ICON));
}

View File

@@ -560,7 +560,7 @@ MimeTypeSettings::MimeTypeSettings(QObject *parent)
{
setId(QLatin1String(Core::Constants::SETTINGS_ID_MIMETYPES));
setDisplayName(tr("MIME Types"));
setCategory(QLatin1String(Core::Constants::SETTINGS_CATEGORY_CORE));
setCategory(Core::Constants::SETTINGS_CATEGORY_CORE);
setDisplayCategory(QCoreApplication::translate("Core",
Core::Constants::SETTINGS_TR_CATEGORY_CORE));
setCategoryIcon(QLatin1String(Core::Constants::SETTINGS_CATEGORY_CORE_ICON));

View File

@@ -52,7 +52,7 @@ ToolSettings::ToolSettings(QObject *parent) :
{
setId(QLatin1String(Core::Constants::SETTINGS_ID_TOOLS));
setDisplayName(tr("External Tools"));
setCategory(QLatin1String(Core::Constants::SETTINGS_CATEGORY_CORE));
setCategory(Core::Constants::SETTINGS_CATEGORY_CORE);
setDisplayCategory(QCoreApplication::translate("Core", Constants::SETTINGS_TR_CATEGORY_CORE));
setCategoryIcon(QLatin1String(Core::Constants::SETTINGS_CATEGORY_CORE_ICON));
}