From 9957652d15f4858ad985590a0366c77ff818b405 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 15 Sep 2014 15:40:15 +0200 Subject: [PATCH] Ensure corona::containments() is ordered the order in which containments were restored used to be quite random: ensure that's ordered by id this makes the shell startups be more reproduceable from one to another, if a new containment arrives, ensure it's inserted maintaining id order containment::appelts() will need the same treatment adds a test as well that checks the order is right Change-Id: Ie1b278e5b83d7e3645f7293bf6d030aa7f43a221 --- autotests/coronatest.cpp | 19 ++++++++++++++++--- autotests/coronatest.h | 1 + src/plasma/corona.cpp | 10 ++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) 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()) {