make sure applets are sorted by id

As with containment, make sure Containment::applets()
is always sorted by id, to have the least sursprises possible

it adds a test

Change-Id: Ib1aeeff7c70bb6969b32b2fef8557889a43edf09
This commit is contained in:
Marco Martin 2014-09-15 17:55:36 +02:00
parent a159208d54
commit 37b34711d8
3 changed files with 20 additions and 7 deletions

View File

@ -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()

View File

@ -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

View File

@ -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<KConfigGroup> 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;