[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kactivities-stats] src: Allow to plan ahead and set the order for an item not yet in the list
From: Ivan Čukić <null () kde ! org>
Date: 2017-02-28 22:36:08
Message-ID: E1ciqNM-0000WL-6n () code ! kde ! org
[Download RAW message or body]
Git commit 168c4be89fa96bb3dbb08f71a5f14b696fbfe364 by Ivan Čukić.
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/168c4be89fa96bb3dbb08f71a5f14b696fbfe364
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 = find(resource);
+
qDebug() << "Was resource found? " << (bool)resourcePosition;
if (resourcePosition) {
qDebug() << "What is the status? " << resourcePosition.iterator->linkStatus();
}
- if (!resourcePosition
- || resourcePosition.iterator->linkStatus() == ResultSet::Result::NotLinked) {
- qWarning("Trying to reposition a resource that we do not have, 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 = linkedItems.size();
}
- auto oldPosition = 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() == ResultSet::Result::NotLinked) {
+
+ qDebug() << "Trying to reposition a resource that we do not have, or is not linked";
+
+ linkedItems.insert(position, resource);
- kamd::utils::slide_one(
- linkedItems.begin() + oldPosition,
- linkedItems.begin() + position);
+ m_fixedItems = linkedItems;
- m_fixedItems = linkedItems;
+ } else {
+
+ auto oldPosition = linkedItems.indexOf(resource);
+
+ kamd::utils::slide_one(
+ linkedItems.begin() + oldPosition,
+ linkedItems.begin() + position);
+
+ m_fixedItems = linkedItems;
+
+ // We are prepared to reorder the cache
+ d->repositionResult(resourcePosition,
+ d->destinationFor(*resourcePosition));
+ }
m_config.writeEntry("kactivitiesLinkedItemsOrder", m_fixedItems);
m_config.sync();
- // We are prepared to reorder the cache
- d->repositionResult(resourcePosition,
- d->destinationFor(*resourcePosition));
}
inline void debug() const
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic