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
592ffe7377

Task-number: QTCREATORBUG-14742
Change-Id: I7be539127b76de90c19b0282565d845fa42010ab
Reviewed-by: Robert Loehning <robert.loehning@theqtcompany.com>
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
Eike Ziller
2015-08-05 15:20:14 +02:00
parent 64d8ac4880
commit 8261b98d7e
9 changed files with 54 additions and 35 deletions

View File

@@ -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);