diff --git a/autotests/coronatest.cpp b/autotests/coronatest.cpp index 3e9b51bda..2e468aea0 100644 --- a/autotests/coronatest.cpp +++ b/autotests/coronatest.cpp @@ -144,9 +144,7 @@ void CoronaTest::restore() { m_corona->loadLayout("plasma-test-appletsrc"); QCOMPARE(m_corona->containments().count(), 3); - //TODO: check the order of m_corona->containments() is stable: - //at the moment the ordering seems pretty random - //same thing for the order of containment->applets() + for (auto cont : m_corona->containments()) { switch (cont->id()) { case 1: @@ -157,6 +155,21 @@ void CoronaTest::restore() break; } } + + +} + + +void CoronaTest::checkOrder() +{ + QCOMPARE(m_corona->containments().count(), 3); + + //check containments order + QCOMPARE(m_corona->containments()[0]->id(), (uint)1); + QCOMPARE(m_corona->containments()[1]->id(), (uint)4); + QCOMPARE(m_corona->containments()[2]->id(), (uint)5); + + //TODO: Containment::applets() order check } void CoronaTest::startupCompletion() diff --git a/autotests/coronatest.h b/autotests/coronatest.h index 4f6d37f84..d20217ff1 100644 --- a/autotests/coronatest.h +++ b/autotests/coronatest.h @@ -84,6 +84,7 @@ public Q_SLOTS: private Q_SLOTS: void restore(); + void checkOrder(); void startupCompletion(); void addRemoveApplets(); void immutability(); diff --git a/src/plasma/corona.cpp b/src/plasma/corona.cpp index 81a327d73..038be7b2e 100644 --- a/src/plasma/corona.cpp +++ b/src/plasma/corona.cpp @@ -477,7 +477,11 @@ Containment *CoronaPrivate::addContainment(const QString &name, const QVariantLi conf.deleteGroup(); } - containments.append(containment); + //make sure the containments are sorted by id + auto position = std::lower_bound(containments.begin(), containments.end(), containment, [](Plasma::Containment *c1, Plasma::Containment *c2) { + return c1->id() < c2->id(); + }); + containments.insert(position, containment); QObject::connect(containment, SIGNAL(destroyed(QObject*)), q, SLOT(containmentDestroyed(QObject*))); @@ -514,8 +518,10 @@ QList CoronaPrivate::importLayout(const KConfigGroup &con } KConfigGroup containmentsGroup(&conf, "Containments"); + QStringList groups = containmentsGroup.groupList(); + qSort(groups.begin(), groups.end()); - foreach (const QString &group, containmentsGroup.groupList()) { + foreach (const QString &group, groups) { KConfigGroup containmentConfig(&containmentsGroup, group); if (containmentConfig.entryMap().isEmpty()) {