┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-12-16 22:01:04 +0100
committerPeter Penz <[email protected]>2011-12-16 22:06:12 +0100
commitea2ed61cd12eec48b66811df0e43dd40e546374a (patch)
treea40d74a472967dc92fa8d2f8e12d3b4c143281a0
parentf640e48bbe3504e4ae3e16349cf98ba9fae90428 (diff)
Update the roles if items have been changed
The code "// TODO..." in slotItemsChanged() obviously was not sufficient ;-) BUG: 288691 BUG: 288824 BUG: 288921 FIXED-IN: 4.8.0
-rw-r--r--src/kitemviews/kfileitemmodelrolesupdater.cpp80
-rw-r--r--src/kitemviews/kfileitemmodelrolesupdater.h23
2 files changed, 65 insertions, 38 deletions
diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp
index 65c11e0f5..5175b371c 100644
--- a/src/kitemviews/kfileitemmodelrolesupdater.cpp
+++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp
@@ -243,42 +243,7 @@ QStringList KFileItemModelRolesUpdater::enabledPlugins() const
void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList& itemRanges)
{
- // If no valid index range is given assume that all items are visible.
- // A cleanup will be done later as soon as the index range has been set.
- const bool hasValidIndexRange = (m_lastVisibleIndex >= 0);
-
- if (hasValidIndexRange) {
- // Move all current pending visible items that are not visible anymore
- // to the pending invisible items.
- QSetIterator<KFileItem> it(m_pendingVisibleItems);
- while (it.hasNext()) {
- const KFileItem item = it.next();
- const int index = m_model->index(item);
- if (index < m_firstVisibleIndex || index > m_lastVisibleIndex) {
- m_pendingVisibleItems.remove(item);
- m_pendingInvisibleItems.insert(item);
- }
- }
- }
-
- int rangesCount = 0;
-
- foreach (const KItemRange& range, itemRanges) {
- rangesCount += range.count;
-
- // Add the inserted items to the pending visible and invisible items
- const int lastIndex = range.index + range.count - 1;
- for (int i = range.index; i <= lastIndex; ++i) {
- const KFileItem item = m_model->fileItem(i);
- if (!hasValidIndexRange || (i >= m_firstVisibleIndex && i <= m_lastVisibleIndex)) {
- m_pendingVisibleItems.insert(item);
- } else {
- m_pendingInvisibleItems.insert(item);
- }
- }
- }
-
- triggerPendingRolesResolving(rangesCount);
+ startUpdating(itemRanges);
}
void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList& itemRanges)
@@ -313,9 +278,8 @@ void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList& itemRang
void KFileItemModelRolesUpdater::slotItemsChanged(const KItemRangeList& itemRanges,
const QSet<QByteArray>& roles)
{
- Q_UNUSED(itemRanges);
Q_UNUSED(roles);
- // TODO
+ startUpdating(itemRanges);
}
void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPixmap& pixmap)
@@ -494,6 +458,46 @@ void KFileItemModelRolesUpdater::resolveNextPendingRoles()
#endif
}
+void KFileItemModelRolesUpdater::startUpdating(const KItemRangeList& itemRanges)
+{
+ // If no valid index range is given assume that all items are visible.
+ // A cleanup will be done later as soon as the index range has been set.
+ const bool hasValidIndexRange = (m_lastVisibleIndex >= 0);
+
+ if (hasValidIndexRange) {
+ // Move all current pending visible items that are not visible anymore
+ // to the pending invisible items.
+ QSetIterator<KFileItem> it(m_pendingVisibleItems);
+ while (it.hasNext()) {
+ const KFileItem item = it.next();
+ const int index = m_model->index(item);
+ if (index < m_firstVisibleIndex || index > m_lastVisibleIndex) {
+ m_pendingVisibleItems.remove(item);
+ m_pendingInvisibleItems.insert(item);
+ }
+ }
+ }
+
+ int rangesCount = 0;
+
+ foreach (const KItemRange& range, itemRanges) {
+ rangesCount += range.count;
+
+ // Add the inserted items to the pending visible and invisible items
+ const int lastIndex = range.index + range.count - 1;
+ for (int i = range.index; i <= lastIndex; ++i) {
+ const KFileItem item = m_model->fileItem(i);
+ if (!hasValidIndexRange || (i >= m_firstVisibleIndex && i <= m_lastVisibleIndex)) {
+ m_pendingVisibleItems.insert(item);
+ } else {
+ m_pendingInvisibleItems.insert(item);
+ }
+ }
+ }
+
+ triggerPendingRolesResolving(rangesCount);
+}
+
void KFileItemModelRolesUpdater::startPreviewJob(const KFileItemList& items)
{
if (items.isEmpty() || m_paused) {
diff --git a/src/kitemviews/kfileitemmodelrolesupdater.h b/src/kitemviews/kfileitemmodelrolesupdater.h
index 85f9c293c..993cc5244 100644
--- a/src/kitemviews/kfileitemmodelrolesupdater.h
+++ b/src/kitemviews/kfileitemmodelrolesupdater.h
@@ -107,12 +107,22 @@ private slots:
void slotItemsChanged(const KItemRangeList& itemRanges,
const QSet<QByteArray>& roles);
+ /**
+ * Is invoked after a preview has been received successfully.
+ * @see startPreviewJob()
+ */
void slotGotPreview(const KFileItem& item, const QPixmap& pixmap);
+
+ /**
+ * Is invoked after generating a preview has failed.
+ * @see startPreviewJob()
+ */
void slotPreviewFailed(const KFileItem& item);
/**
* Is invoked when the preview job has been finished and
* removes the job from the m_previewJobs list.
+ * @see startPreviewJob()
*/
void slotPreviewJobFinished(KJob* job);
@@ -120,6 +130,19 @@ private slots:
void resolveNextPendingRoles();
private:
+ /**
+ * Updates the roles for the given item ranges. The roles for the currently
+ * visible items will get updated first.
+ */
+ void startUpdating(const KItemRangeList& itemRanges);
+
+ /**
+ * Creates previews for the items starting from the first item of the
+ * given list.
+ * @see slotGotPreview()
+ * @see slotPreviewFailed()
+ * @see slotPreviewJobFinished()
+ */
void startPreviewJob(const KFileItemList& items);
bool hasPendingRoles() const;