Git commit 168c4be89fa96bb3dbb08f71a5f14b696fbfe364 by Ivan =C4=8Cuki=C4=87. Committed on 28/02/2017 at 22:35. Pushed by ivan into branch 'master'. Allow to plan ahead and set the order for an item not yet in the list M +26 -13 src/resultmodel.cpp https://commits.kde.org/kactivities-stats/168c4be89fa96bb3dbb08f71a5f14b696= fbfe364 diff --git a/src/resultmodel.cpp b/src/resultmodel.cpp index e9e440c..a44c5f6 100644 --- a/src/resultmodel.cpp +++ b/src/resultmodel.cpp @@ -130,15 +130,11 @@ public: = qDebug() << "Searching for " << resource; auto resourcePosition =3D find(resource); + qDebug() << "Was resource found? " << (bool)resourcePosition; if (resourcePosition) { qDebug() << "What is the status? " << resourcePosition.ite= rator->linkStatus(); } - if (!resourcePosition - || resourcePosition.iterator->linkStatus() =3D=3D ResultSe= t::Result::NotLinked) { - qWarning("Trying to reposition a resource that we do not h= ave, or is not linked"); - return; - } = // Lets make a list of linked items - we can only reorder them, // not others @@ -155,20 +151,37 @@ public: position =3D linkedItems.size(); } = - auto oldPosition =3D linkedItems.indexOf(resource); + // We have two options: + // - we are planning to add an item to the desired position, + // but the item is not yet in the model + // - we want to move an existing item + if (!resourcePosition + || resourcePosition.iterator->linkStatus() =3D=3D Resu= ltSet::Result::NotLinked) { + + qDebug() << "Trying to reposition a resource that we do no= t have, or is not linked"; + + linkedItems.insert(position, resource); = - kamd::utils::slide_one( - linkedItems.begin() + oldPosition, - linkedItems.begin() + position); + m_fixedItems =3D linkedItems; = - m_fixedItems =3D linkedItems; + } else { + + auto oldPosition =3D linkedItems.indexOf(resource); + + kamd::utils::slide_one( + linkedItems.begin() + oldPosition, + linkedItems.begin() + position); + + m_fixedItems =3D linkedItems; + + // We are prepared to reorder the cache + d->repositionResult(resourcePosition, + d->destinationFor(*resourcePosition)); + } = m_config.writeEntry("kactivitiesLinkedItemsOrder", m_fixedItem= s); m_config.sync(); = - // We are prepared to reorder the cache - d->repositionResult(resourcePosition, - d->destinationFor(*resourcePosition)); } = inline void debug() const