Commit 9b9d339c authored by Eike Ziller's avatar Eike Ziller

Hardcode search terms for designer options page

By taking the translated text from designer.
This way we don't freeze directly when filtering the options page. We
still have to initialize designer (and therefore freeze) the moment that
category gets selected though (which can also happen during filtering).

Task-number: QTCREATORBUG-9584
Change-Id: I88275db97f87a5da8c565bccc8ae41de3b51a135
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@digia.com>
parent 8178f709
......@@ -94,6 +94,7 @@ public:
QIcon categoryIcon() const { return QIcon(m_categoryIcon); }
virtual QList<IOptionsPage *> pages() const = 0;
virtual bool matches(const QString & /* searchKeyWord*/) const = 0;
protected:
void setCategory(Core::Id category) { m_category = category; }
......
......@@ -66,12 +66,15 @@ static QPointer<SettingsDialog> m_instance = 0;
class Category
{
public:
Category() : index(-1), providerPagesCreated(false) { }
Id id;
int index;
QString displayName;
QIcon icon;
QList<IOptionsPage *> pages;
QList<IOptionsPageProvider *> providers;
bool providerPagesCreated;
QTabWidget *tabWidget;
};
......@@ -210,15 +213,23 @@ bool CategoryFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou
if (QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent))
return true;
const QString pattern = filterRegExp().pattern();
const CategoryModel *cm = static_cast<CategoryModel*>(sourceModel());
foreach (const IOptionsPage *page, cm->categories().at(sourceRow)->pages) {
const QString pattern = filterRegExp().pattern();
const Category *category = cm->categories().at(sourceRow);
foreach (const IOptionsPage *page, category->pages) {
if (page->displayCategory().contains(pattern, Qt::CaseInsensitive)
|| page->displayName().contains(pattern, Qt::CaseInsensitive)
|| page->matches(pattern))
|| page->displayName().contains(pattern, Qt::CaseInsensitive)
|| page->matches(pattern))
return true;
}
if (!category->providerPagesCreated) {
foreach (const IOptionsPageProvider *provider, category->providers) {
if (provider->matches(pattern))
return true;
}
}
return false;
}
......@@ -324,8 +335,6 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
// The order of the slot connection matters here, the filter slot
// opens the matching page after the model has filtered.
connect(m_filterLineEdit, SIGNAL(filterChanged(QString)),
this, SLOT(ensureAllCategoryWidgets()));
connect(m_filterLineEdit, SIGNAL(filterChanged(QString)),
m_proxyModel, SLOT(setFilterFixedString(QString)));
connect(m_filterLineEdit, SIGNAL(filterChanged(QString)), this, SLOT(filter(QString)));
......@@ -432,9 +441,12 @@ void SettingsDialog::ensureCategoryWidget(Category *category)
{
if (category->tabWidget != 0)
return;
foreach (const IOptionsPageProvider *provider, category->providers) {
category->pages += provider->pages();
if (!category->providerPagesCreated) {
foreach (const IOptionsPageProvider *provider, category->providers)
category->pages += provider->pages();
category->providerPagesCreated = true;
}
qStableSort(category->pages.begin(), category->pages.end(), optionsPageLessThan);
QTabWidget *tabWidget = new QTabWidget;
......@@ -451,12 +463,6 @@ void SettingsDialog::ensureCategoryWidget(Category *category)
category->index = m_stackedLayout->addWidget(tabWidget);
}
void SettingsDialog::ensureAllCategoryWidgets()
{
foreach (Category *category, m_model->categories())
ensureCategoryWidget(category);
}
void SettingsDialog::disconnectTabWidgets()
{
foreach (Category *category, m_model->categories()) {
......@@ -514,7 +520,6 @@ void SettingsDialog::currentTabChanged(int index)
void SettingsDialog::filter(const QString &text)
{
ensureAllCategoryWidgets();
// When there is no current index, select the first one when possible
if (!m_categoryList->currentIndex().isValid() && m_model->rowCount() > 0)
m_categoryList->setCurrentIndex(m_proxyModel->index(0, 0));
......
......@@ -79,7 +79,6 @@ private slots:
void currentChanged(const QModelIndex &current);
void currentTabChanged(int);
void filter(const QString &text);
void ensureAllCategoryWidgets();
private:
SettingsDialog(QWidget *parent);
......
......@@ -91,3 +91,43 @@ QList<Core::IOptionsPage *> SettingsPageProvider::pages() const
}
return FormEditorW::instance()->optionsPages();
}
bool SettingsPageProvider::matches(const QString &searchKeyWord) const
{
// to avoid fully initializing designer when typing something in the options' filter edit
// we hardcode matching of UI text from the designer pages, which are taken if the designer pages
// were not yet loaded
// luckily linguist cannot resolve the translated texts, so we do not end up with duplicate
// translatable strings for Qt Creator
static const struct { const char *context; const char *value; } uitext[] = {
{"EmbeddedOptionsPage", "Embedded Design"},
{"EmbeddedOptionsPage", "Device Profiles"},
{"FormEditorOptionsPage", "Forms"},
{"FormEditorOptionsPage", "Preview Zoom"},
{"FormEditorOptionsPage", "Default Zoom"},
{"FormEditorOptionsPage", "Default Grid"},
{"qdesigner_internal::GridPanel", "Visible"},
{"qdesigner_internal::GridPanel", "Snap"},
{"qdesigner_internal::GridPanel", "Reset"},
{"qdesigner_internal::GridPanel", "Grid"},
{"qdesigner_internal::GridPanel", "Grid &X"},
{"qdesigner_internal::GridPanel", "Grid &Y"},
{"PreviewConfigurationWidget", "Print/Preview Configuration"},
{"PreviewConfigurationWidget", "Style"},
{"PreviewConfigurationWidget", "Style sheet"},
{"PreviewConfigurationWidget", "Device skin"},
{"TemplateOptionsPage", "Template Paths"},
{"qdesigner_internal::TemplateOptionsWidget", "Additional Template Paths"}
};
static const size_t itemCount = sizeof(uitext)/sizeof(uitext[0]);
if (m_keywords.isEmpty()) {
m_keywords.reserve(itemCount);
for (size_t i = 0; i < itemCount; ++i)
m_keywords << QCoreApplication::translate(uitext[i].context, uitext[i].value).remove(QLatin1Char('&'));
}
foreach (const QString &key, m_keywords) {
if (key.contains(searchKeyWord, Qt::CaseInsensitive))
return true;
}
return false;
}
......@@ -68,9 +68,11 @@ public:
SettingsPageProvider(QObject *parent = 0);
QList<Core::IOptionsPage *> pages() const;
bool matches(const QString &searchKeyWord) const;
private:
mutable bool m_initialized;
mutable QStringList m_keywords;
};
} // namespace Internal
......
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