Commit 8261b98d authored by Eike Ziller's avatar Eike Ziller

Preferences: Options pages need unique IDs

Since we are referring to them by ID without specifying the category in
addition.
This requirement was implicitly added by
592ffe73

Task-number: QTCREATORBUG-14742
Change-Id: I7be539127b76de90c19b0282565d845fa42010ab
Reviewed-by: default avatarRobert Loehning <robert.loehning@theqtcompany.com>
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent 64d8ac48
......@@ -64,6 +64,21 @@ namespace Internal {
static QPointer<SettingsDialog> m_instance = 0;
// Helpers to sort by category. id
bool optionsPageLessThan(const IOptionsPage *p1, const IOptionsPage *p2)
{
if (p1->category() != p2->category())
return p1->category().alphabeticallyBefore(p2->category());
return p1->id().alphabeticallyBefore(p2->id());
}
static inline QList<IOptionsPage*> sortedOptionsPages()
{
QList<IOptionsPage*> rc = ExtensionSystem::PluginManager::getObjects<IOptionsPage>();
qStableSort(rc.begin(), rc.end(), optionsPageLessThan);
return rc;
}
// ----------- Category model
class Category
......@@ -104,12 +119,14 @@ public:
void setPages(const QList<IOptionsPage*> &pages,
const QList<IOptionsPageProvider *> &providers);
void ensurePages(Category *category);
const QList<Category*> &categories() const { return m_categories; }
private:
Category *findCategoryById(Id id);
QList<Category*> m_categories;
QSet<Id> m_pageIds;
QIcon m_emptyIcon;
};
......@@ -155,9 +172,13 @@ void CategoryModel::setPages(const QList<IOptionsPage*> &pages,
// Clear any previous categories
qDeleteAll(m_categories);
m_categories.clear();
m_pageIds.clear();
// Put the pages in categories
foreach (IOptionsPage *page, pages) {
QTC_ASSERT(!m_pageIds.contains(page->id()),
qWarning("duplicate options page id '%s'", qPrintable(page->id().toString())));
m_pageIds.insert(page->id());
const Id categoryId = page->category();
Category *category = findCategoryById(categoryId);
if (!category) {
......@@ -194,6 +215,25 @@ void CategoryModel::setPages(const QList<IOptionsPage*> &pages,
endResetModel();
}
void CategoryModel::ensurePages(Category *category)
{
if (!category->providerPagesCreated) {
QList<IOptionsPage *> createdPages;
foreach (const IOptionsPageProvider *provider, category->providers)
createdPages += provider->pages();
// check for duplicate ids
foreach (IOptionsPage *page, createdPages) {
QTC_ASSERT(!m_pageIds.contains(page->id()),
qWarning("duplicate options page id '%s'", qPrintable(page->id().toString())));
}
category->pages += createdPages;
category->providerPagesCreated = true;
qStableSort(category->pages.begin(), category->pages.end(), optionsPageLessThan);
}
}
Category *CategoryModel::findCategoryById(Id id)
{
for (int i = 0; i < m_categories.size(); ++i) {
......@@ -359,21 +399,6 @@ private:
// ----------- SettingsDialog
// Helpers to sort by category. id
bool optionsPageLessThan(const IOptionsPage *p1, const IOptionsPage *p2)
{
if (p1->category() != p2->category())
return p1->category().alphabeticallyBefore(p2->category());
return p1->id().alphabeticallyBefore(p2->id());
}
static inline QList<IOptionsPage*> sortedOptionsPages()
{
QList<IOptionsPage*> rc = ExtensionSystem::PluginManager::getObjects<IOptionsPage>();
qStableSort(rc.begin(), rc.end(), optionsPageLessThan);
return rc;
}
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
m_pages(sortedOptionsPages()),
......@@ -540,14 +565,8 @@ void SettingsDialog::ensureCategoryWidget(Category *category)
{
if (category->tabWidget != 0)
return;
if (!category->providerPagesCreated) {
foreach (const IOptionsPageProvider *provider, category->providers)
category->pages += provider->pages();
category->providerPagesCreated = true;
}
qStableSort(category->pages.begin(), category->pages.end(), optionsPageLessThan);
m_model->ensurePages(category);
QTabWidget *tabWidget = new QTabWidget;
for (int j = 0; j < category->pages.size(); ++j) {
IOptionsPage *page = category->pages.at(j);
......
......@@ -99,7 +99,7 @@ FileShareProtocolSettingsPage::FileShareProtocolSettingsPage(const QSharedPointe
QObject *parent) :
Core::IOptionsPage(parent), m_settings(s), m_widget(0)
{
setId("X.FileSharePaster");
setId("X.CodePaster.FileSharePaster");
setDisplayName(tr("Fileshare"));
setCategory(Constants::CPASTER_SETTINGS_CATEGORY);
setDisplayCategory(QCoreApplication::translate("CodePaster", Constants::CPASTER_SETTINGS_TR_CATEGORY));
......
......@@ -70,7 +70,7 @@ Settings SettingsWidget::settings()
SettingsPage::SettingsPage(const QSharedPointer<Settings> &settings) :
m_settings(settings), m_widget(0)
{
setId("A.General");
setId("A.CodePaster.General");
setDisplayName(tr("General"));
setCategory(Constants::CPASTER_SETTINGS_CATEGORY);
setDisplayCategory(QCoreApplication::translate("CodePaster",
......
......@@ -56,11 +56,11 @@ const char CPPTOOLS_SORT_EDITOR_DOCUMENT_OUTLINE[] = "SortedMethodOverview";
const char CPPTOOLS_MODEL_MANAGER_SUPPORTERS_KEY[] = "ModelManagerSupporters";
const char CPPTOOLS_MODEL_MANAGER_PCH_USAGE[] = "PCHUsage";
const char CPP_CODE_STYLE_SETTINGS_ID[] = "A.Code Style";
const char CPP_CODE_STYLE_SETTINGS_ID[] = "A.Cpp.Code Style";
const char CPP_CODE_STYLE_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "Code Style");
const char CPP_FILE_SETTINGS_ID[] = "B.File Naming";
const char CPP_FILE_SETTINGS_ID[] = "B.Cpp.File Naming";
const char CPP_FILE_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "File Naming");
const char CPP_CODE_MODEL_SETTINGS_ID[] = "C.Code Model";
const char CPP_CODE_MODEL_SETTINGS_ID[] = "C.Cpp.Code Model";
const char CPP_CODE_MODEL_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "Code Model");
const char CPP_SETTINGS_CATEGORY[] = "I.C++";
const char CPP_SETTINGS_TR_CATEGORY[] = QT_TRANSLATE_NOOP("CppTools", "C++");
......
......@@ -202,7 +202,7 @@ QStringList CdbOptionsPageWidget::breakEvents() const
CdbOptionsPage::CdbOptionsPage()
{
setId("F.Cda");
setId("F.Debugger.Cda");
setDisplayName(tr("CDB"));
setCategory(Debugger::Constants::DEBUGGER_SETTINGS_CATEGORY);
setDisplayCategory(QCoreApplication::translate("Debugger",
......@@ -281,7 +281,7 @@ CdbPathsPageWidget::CdbPathsPageWidget(QWidget *parent) :
CdbPathsPage::CdbPathsPage()
: m_widget(0)
{
setId("F.Cdb");
setId("F.Debugger.Cdb");
setDisplayName(tr("CDB Paths"));
setCategory(Debugger::Constants::DEBUGGER_SETTINGS_CATEGORY);
setDisplayCategory(QCoreApplication::translate("Debugger",
......
......@@ -339,7 +339,7 @@ QString CommonOptionsPage::msgSetBreakpointAtFunctionToolTip(const char *functio
LocalsAndExpressionsOptionsPage::LocalsAndExpressionsOptionsPage()
{
setId("Z.LocalsAndExpressions");
setId("Z.Debugger.LocalsAndExpressions");
//: '&&' will appear as one (one is marking keyboard shortcut)
setDisplayName(QCoreApplication::translate("Debugger", "Locals && Expressions"));
setCategory(DEBUGGER_SETTINGS_CATEGORY);
......
......@@ -36,7 +36,7 @@
namespace Debugger {
namespace Constants {
const char DEBUGGER_COMMON_SETTINGS_ID[] = "A.Common";
const char DEBUGGER_COMMON_SETTINGS_ID[] = "A.Debugger.General";
const char DEBUGGER_SETTINGS_CATEGORY[] = "O.Debugger";
const char DEBUGGER_SETTINGS_TR_CATEGORY[] = QT_TRANSLATE_NOOP("Debugger", "Debugger");
const char DEBUGGER_COMMON_SETTINGS_CATEGORY_ICON[] = ":/debugger/images/category_debug.png";
......
......@@ -111,9 +111,9 @@ namespace Internal {
const char INSTALL_HANDLER[] = "TextEditor.FakeVimHandler";
const char SETTINGS_CATEGORY[] = "D.FakeVim";
const char SETTINGS_CATEGORY_FAKEVIM_ICON[] = ":/fakevim/images/category_fakevim.png";
const char SETTINGS_ID[] = "A.General";
const char SETTINGS_EX_CMDS_ID[] = "B.ExCommands";
const char SETTINGS_USER_CMDS_ID[] = "C.UserCommands";
const char SETTINGS_ID[] = "A.FakeVim.General";
const char SETTINGS_EX_CMDS_ID[] = "B.FakeVim.ExCommands";
const char SETTINGS_USER_CMDS_ID[] = "C.FakeVim.UserCommands";
typedef QLatin1String _;
class MiniBuffer : public QStackedWidget
......
......@@ -39,7 +39,7 @@ namespace Constants {
const char VCS_SETTINGS_CATEGORY[] = "V.Version Control";
const char VCS_SETTINGS_TR_CATEGORY[] = QT_TRANSLATE_NOOP("VcsBase", "Version Control");
const char SETTINGS_CATEGORY_VCS_ICON[] = ":/vcsbase/images/category_vcs.png";
const char VCS_COMMON_SETTINGS_ID[] = "A.Common";
const char VCS_COMMON_SETTINGS_ID[] = "A.VCS.General";
const char VCS_COMMON_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("VcsBase", "General");
// Ids for sort order (wizards and preferences)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment