diff --git a/autotests/coronatest.cpp b/autotests/coronatest.cpp index 2e468aea0..615c41937 100644 --- a/autotests/coronatest.cpp +++ b/autotests/coronatest.cpp @@ -169,7 +169,10 @@ void CoronaTest::checkOrder() QCOMPARE(m_corona->containments()[1]->id(), (uint)4); QCOMPARE(m_corona->containments()[2]->id(), (uint)5); - //TODO: Containment::applets() order check + //check applets order + QCOMPARE(m_corona->containments()[0]->applets().count(), 2); + QCOMPARE(m_corona->containments()[0]->applets()[0]->id(), (uint)2); + QCOMPARE(m_corona->containments()[0]->applets()[1]->id(), (uint)3); } void CoronaTest::startupCompletion() diff --git a/autotests/plasma-test-appletsrc b/autotests/plasma-test-appletsrc index a832e9a72..ef8497887 100644 --- a/autotests/plasma-test-appletsrc +++ b/autotests/plasma-test-appletsrc @@ -6,14 +6,16 @@ lastScreen=0 location=0 plugin=simplecontainment -[Containments][1][Applets][2] -immutability=1 -plugin=invalid - +#those two applets are not ordered by id +#but applets() should be ordered anyways [Containments][1][Applets][3] immutability=1 plugin=simpleapplet +[Containments][1][Applets][2] +immutability=1 +plugin=invalid + #empty panel: should emit complete even if empty [Containments][4] formfactor=2 diff --git a/src/plasma/containment.cpp b/src/plasma/containment.cpp index f078c84b1..e087072e7 100644 --- a/src/plasma/containment.cpp +++ b/src/plasma/containment.cpp @@ -260,10 +260,14 @@ void Containment::restoreContents(KConfigGroup &group) { KConfigGroup applets(&group, "Applets"); + //restore the applets ordered by id + QStringList groups = applets.groupList(); + qSort(groups.begin(), groups.end()); + // Sort the applet configs in order of geometry to ensure that applets // are added from left to right or top to bottom for a panel containment QList appletConfigs; - foreach (const QString &appletGroup, applets.groupList()) { + foreach (const QString &appletGroup, groups) { //qDebug() << "reading from applet group" << appletGroup; KConfigGroup appletConfig(&applets, appletGroup); appletConfigs.append(appletConfig); @@ -414,7 +418,11 @@ void Containment::addApplet(Applet *applet) applet->setParent(this); } - d->applets << applet; + //make sure the applets are sorted by id + auto position = std::lower_bound(d->applets.begin(), d->applets.end(), applet, [](Plasma::Applet *a1, Plasma::Applet *a2) { + return a1->id() < a2->id(); + }); + d->applets.insert(position, applet); if (!d->uiReady) { d->loadingApplets << applet;