Skip to content

Commit

Permalink
[qtcontacts-sqlite] Improve DLG plugin interface. Contributes to JB#4…
Browse files Browse the repository at this point in the history
…4742

This commit improves the display label group plugin interface by
allowing plugins to report whether the specified locale is a
preferred locale for them, rather than merely valid, as some
plugins may work in multiple locales but should be preferentially
used (e.g. to determine the default display label groups) for
a subset of those locales.

For example, a pinyin grouping plugin might be valid in all locales
but preferred in locales which use Simplified Han writing script.

The database now populates the "default" supported display label
groups from the highest priority preferred plugin rather than
the highest priority valid plugin (falling back to highest priority
valid plugin if no preferred plugins exist for the current locale).
  • Loading branch information
Chris Adams committed Apr 17, 2019
1 parent 7b785aa commit 367e4b5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
16 changes: 14 additions & 2 deletions src/engine/contactsdatabase.cpp
Expand Up @@ -3553,9 +3553,21 @@ QStringList ContactsDatabase::displayLabelGroups() const
QStringList groups;
const QLocale locale;
for (int i = 0; i < m_dlgGenerators.size(); ++i) {
if (m_dlgGenerators.at(i)->validForLocale(locale)) {
if (m_dlgGenerators.at(i)->preferredForLocale(locale)) {
groups = m_dlgGenerators.at(i)->displayLabelGroups();
break;
if (!groups.isEmpty()) {
break;
}
}
}
if (groups.isEmpty()) {
for (int i = 0; i < m_dlgGenerators.size(); ++i) {
if (m_dlgGenerators.at(i)->validForLocale(locale)) {
groups = m_dlgGenerators.at(i)->displayLabelGroups();
if (!groups.isEmpty()) {
break;
}
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/engine/defaultdlggenerator.cpp
Expand Up @@ -75,9 +75,14 @@ int DefaultDlgGenerator::priority() const
return 0;
}

bool DefaultDlgGenerator::preferredForLocale(const QLocale &) const
{
return false; // this default plugin is the fallback, never preferred but always valid.
}

bool DefaultDlgGenerator::validForLocale(const QLocale &) const
{
return true; // this default plugin is the fallback, and always valid.
return true; // this default plugin is the fallback, always valid.
}

QStringList DefaultDlgGenerator::displayLabelGroups() const
Expand Down
1 change: 1 addition & 0 deletions src/engine/defaultdlggenerator.h
Expand Up @@ -45,6 +45,7 @@ class DefaultDlgGenerator : public QObject, public QtContactsSqliteExtensions::D
QString name() const Q_DECL_OVERRIDE;
int priority() const Q_DECL_OVERRIDE;
bool validForLocale(const QLocale &locale) const Q_DECL_OVERRIDE;
bool preferredForLocale(const QLocale &locale) const Q_DECL_OVERRIDE;
QString displayLabelGroup(const QString &data) const Q_DECL_OVERRIDE;
QStringList displayLabelGroups() const Q_DECL_OVERRIDE;
};
Expand Down
1 change: 1 addition & 0 deletions src/extensions/displaylabelgroupgenerator.h
Expand Up @@ -56,6 +56,7 @@ class DisplayLabelGroupGenerator
virtual ~DisplayLabelGroupGenerator() {}
virtual QString name() const = 0;
virtual int priority() const = 0; // higher priority will be used before lower priority when generating label groups.
virtual bool preferredForLocale(const QLocale &locale) const = 0;
virtual bool validForLocale(const QLocale &locale) const = 0;
virtual QString displayLabelGroup(const QString &data) const = 0;
virtual QStringList displayLabelGroups() const = 0;
Expand Down
8 changes: 6 additions & 2 deletions tests/auto/displaylabelgroups/testplugin/testdlggplugin.cpp
Expand Up @@ -63,9 +63,13 @@ int TestDlgg::priority() const
return 1; // test plugin has slightly higher than the default/fallback.
}

bool TestDlgg::validForLocale(const QLocale &locale) const
bool TestDlgg::preferredForLocale(const QLocale &) const
{
return true; // this test plugin is always "preferred".
}

bool TestDlgg::validForLocale(const QLocale &) const
{
Q_UNUSED(locale)
return true; // this test plugin is always "valid".
}

Expand Down
1 change: 1 addition & 0 deletions tests/auto/displaylabelgroups/testplugin/testdlggplugin.h
Expand Up @@ -45,6 +45,7 @@ class TestDlgg : public QObject, QtContactsSqliteExtensions::DisplayLabelGroupGe
TestDlgg(QObject *parent = Q_NULLPTR);
QString name() const Q_DECL_OVERRIDE;
int priority() const Q_DECL_OVERRIDE;
bool preferredForLocale(const QLocale &locale) const Q_DECL_OVERRIDE;
bool validForLocale(const QLocale &locale) const Q_DECL_OVERRIDE;
QString displayLabelGroup(const QString &data) const Q_DECL_OVERRIDE;
QStringList displayLabelGroups() const Q_DECL_OVERRIDE;
Expand Down

0 comments on commit 367e4b5

Please sign in to comment.