Commit 117ea8d2 authored by Laurent Montel's avatar Laurent Montel 😁

Patch from aleksejshilin

When no default aggregation or theme is selected by user, Core::Manager

picks the first one. The available ones were stored in QHash containers
which, per Qt documentation, are ordered randomly:

When iterating over a QMap, the items are always sorted by key. With
QHash, the items are arbitrarily ordered.

Given that keys are generated in a way that they differ each time, the
result of picking the first item was unpredictable.

This commit changes containers' type to QMap which guarantees order.

Differential Revision: https://phabricator.kde.org/D10417
parent 4ffe6f0f
......@@ -128,7 +128,7 @@ const Aggregation *Manager::defaultAggregation()
}
// try just the first one
QHash< QString, Aggregation * >::ConstIterator it = mAggregations.constBegin();
QMap< QString, Aggregation * >::ConstIterator it = mAggregations.constBegin();
if (it != mAggregations.constEnd()) {
return *it;
}
......@@ -379,8 +379,8 @@ void Manager::createDefaultAggregations()
void Manager::removeAllAggregations()
{
QHash< QString, Aggregation * >::ConstIterator end(mAggregations.constEnd());
for (QHash< QString, Aggregation * >::ConstIterator it = mAggregations.constBegin(); it != end; ++it) {
QMap< QString, Aggregation * >::ConstIterator end(mAggregations.constEnd());
for (QMap< QString, Aggregation * >::ConstIterator it = mAggregations.constBegin(); it != end; ++it) {
delete(*it);
}
......@@ -448,7 +448,7 @@ const Theme *Manager::defaultTheme()
}
// try just the first one
QHash< QString, Theme * >::ConstIterator it = mThemes.constBegin();
QMap< QString, Theme * >::ConstIterator it = mThemes.constBegin();
if (it != mThemes.constEnd()) {
return *it;
}
......@@ -807,8 +807,8 @@ void Manager::createDefaultThemes()
void Manager::removeAllThemes()
{
QHash< QString, Theme * >::ConstIterator end(mThemes.constEnd());
for (QHash< QString, Theme * >::ConstIterator it = mThemes.constBegin(); it != end; ++it) {
QMap< QString, Theme * >::ConstIterator end(mThemes.constEnd());
for (QMap< QString, Theme * >::ConstIterator it = mThemes.constBegin(); it != end; ++it) {
delete(*it);
}
......@@ -950,8 +950,8 @@ void Manager::saveConfiguration()
conf.writeEntry("Count", mAggregations.count());
int idx = 0;
QHash< QString, Aggregation * >::ConstIterator end(mAggregations.end());
for (QHash< QString, Aggregation * >::ConstIterator it = mAggregations.constBegin(); it != end; ++it) {
QMap< QString, Aggregation * >::ConstIterator end(mAggregations.end());
for (QMap< QString, Aggregation * >::ConstIterator it = mAggregations.constBegin(); it != end; ++it) {
conf.writeEntry(QStringLiteral("Set%1").arg(idx), (*it)->saveToString());
++idx;
}
......@@ -966,8 +966,8 @@ void Manager::saveConfiguration()
conf.writeEntry("Count", mThemes.count());
int idx = 0;
QHash< QString, Theme * >::ConstIterator end(mThemes.constEnd());
for (QHash< QString, Theme * >::ConstIterator it = mThemes.constBegin(); it != end; ++it) {
QMap< QString, Theme * >::ConstIterator end(mThemes.constEnd());
for (QMap< QString, Theme * >::ConstIterator it = mThemes.constBegin(); it != end; ++it) {
conf.writeEntry(QStringLiteral("Set%1").arg(idx), (*it)->saveToString());
++idx;
}
......
......@@ -23,7 +23,7 @@
#include <core/sortorder.h>
#include <QList>
#include <QHash>
#include <QMap>
#include <QObject>
#include <collection.h>
......@@ -61,8 +61,8 @@ protected:
private:
static Manager *mInstance;
QList< Widget * > mWidgetList;
QHash< QString, Aggregation * > mAggregations;
QHash< QString, Theme * > mThemes;
QMap< QString, Aggregation * > mAggregations;
QMap< QString, Theme * > mThemes;
KMime::DateFormatter *mDateFormatter = nullptr;
QString mCachedLocalizedUnknownText;
......@@ -102,7 +102,7 @@ public:
void addAggregation(Aggregation *set);
void removeAllAggregations();
const QHash< QString, Aggregation * > &aggregations() const
const QMap< QString, Aggregation * > &aggregations() const
{
return mAggregations;
}
......@@ -132,7 +132,7 @@ public:
void addTheme(Theme *set);
void removeAllThemes();
const QHash< QString, Theme * > &themes() const
const QMap< QString, Theme * > &themes() const
{
return mThemes;
}
......
......@@ -29,7 +29,7 @@
#include <QGridLayout>
#include <QPushButton>
#include <QFrame>
#include <QHash>
#include <QMap>
#include <KLocalizedString>
#include <KIconLoader>
......@@ -258,9 +258,9 @@ void ConfigureAggregationsDialog::Private::fillAggregationList()
if (!Manager::instance()) {
return;
}
const QHash< QString, Aggregation * > &sets = Manager::instance()->aggregations();
QHash< QString, Aggregation * >::ConstIterator end(sets.constEnd());
for (QHash< QString, Aggregation * >::ConstIterator it = sets.constBegin(); it != end; ++it) {
const QMap< QString, Aggregation * > &sets = Manager::instance()->aggregations();
QMap< QString, Aggregation * >::ConstIterator end(sets.constEnd());
for (QMap< QString, Aggregation * >::ConstIterator it = sets.constBegin(); it != end; ++it) {
(void)new AggregationListWidgetItem(mAggregationList, *(*it));
}
}
......
......@@ -29,7 +29,7 @@
#include <QGridLayout>
#include <QPushButton>
#include <QFrame>
#include <QHash>
#include <QMap>
#include <KMessageBox>
#include <KLocalizedString>
......@@ -256,10 +256,10 @@ void ConfigureThemesDialog::Private::editedThemeNameChanged()
void ConfigureThemesDialog::Private::fillThemeList()
{
const QHash< QString, Theme * > &sets = Manager::instance()->themes();
const QMap< QString, Theme * > &sets = Manager::instance()->themes();
QHash< QString, Theme * >::ConstIterator end(sets.constEnd());
for (QHash< QString, Theme * >::ConstIterator it = sets.constBegin(); it != end; ++it) {
QMap< QString, Theme * >::ConstIterator end(sets.constEnd());
for (QMap< QString, Theme * >::ConstIterator it = sets.constBegin(); it != end; ++it) {
(void)new ThemeListWidgetItem(mThemeList, *(*it));
}
}
......
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