┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-12-11 20:23:21 +0100
committerPeter Penz <[email protected]>2011-12-11 20:24:38 +0100
commit42adf258b65f2785bd08d6dcbdabce92187c99cf (patch)
treeeac9bfab8ac1d5682444a2131ed19f049806b940 /src
parent85d08ac7edc53027e7d2e976e6479aceb0e0add4 (diff)
Remember sort settings
If the user has changed the sort-role or sort-order by clicking on the view-header of the details-view, the settings have been adjusted to the model but not remembered in the directory settings.
Diffstat (limited to 'src')
-rw-r--r--src/kitemviews/kitemlistheader.cpp12
-rw-r--r--src/kitemviews/kitemlistheader_p.h16
-rw-r--r--src/kitemviews/kitemlistview.cpp8
-rw-r--r--src/kitemviews/kitemlistview.h18
-rw-r--r--src/views/dolphinview.cpp29
-rw-r--r--src/views/dolphinview.h12
6 files changed, 89 insertions, 6 deletions
diff --git a/src/kitemviews/kitemlistheader.cpp b/src/kitemviews/kitemlistheader.cpp
index 96f868aad..7b5549c73 100644
--- a/src/kitemviews/kitemlistheader.cpp
+++ b/src/kitemviews/kitemlistheader.cpp
@@ -176,13 +176,17 @@ void KItemListHeader::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
const int sortRoleIndex = m_visibleRoles.indexOf(sortRole);
if (m_pressedRoleIndex == sortRoleIndex) {
// Toggle the sort order
- const Qt::SortOrder toggled = (m_model->sortOrder() == Qt::AscendingOrder) ?
+ const Qt::SortOrder previous = m_model->sortOrder();
+ const Qt::SortOrder current = (m_model->sortOrder() == Qt::AscendingOrder) ?
Qt::DescendingOrder : Qt::AscendingOrder;
- m_model->setSortOrder(toggled);
+ m_model->setSortOrder(current);
+ emit sortOrderChanged(current, previous);
} else {
// Change the sort role
- const QByteArray sortRole = m_visibleRoles.at(m_pressedRoleIndex);
- m_model->setSortRole(sortRole);
+ const QByteArray previous = m_model->sortRole();
+ const QByteArray current = m_visibleRoles.at(m_pressedRoleIndex);
+ m_model->setSortRole(current);
+ emit sortRoleChanged(current, previous);
}
}
diff --git a/src/kitemviews/kitemlistheader_p.h b/src/kitemviews/kitemlistheader_p.h
index a3f06f114..41505585e 100644
--- a/src/kitemviews/kitemlistheader_p.h
+++ b/src/kitemviews/kitemlistheader_p.h
@@ -60,6 +60,22 @@ signals:
qreal currentWidth,
qreal previousWidth);
+ /**
+ * Is emitted if the user has changed the sort order by clicking on a
+ * header item. The sort order of the model has already been adjusted to
+ * the current sort order. Note that no signal will be emitted if the
+ * sort order of the model has been changed without user interaction.
+ */
+ void sortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous);
+
+ /**
+ * Is emitted if the user has changed the sort role by clicking on a
+ * header item. The sort role of the model has already been adjusted to
+ * the current sort role. Note that no signal will be emitted if the
+ * sort role of the model has been changed without user interaction.
+ */
+ void sortRoleChanged(const QByteArray& current, const QByteArray& previous);
+
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp
index 5cf67034e..15e0340c0 100644
--- a/src/kitemviews/kitemlistview.cpp
+++ b/src/kitemviews/kitemlistview.cpp
@@ -527,10 +527,14 @@ void KItemListView::setHeaderShown(bool show)
m_header->setVisibleRolesWidths(headerRolesWidths());
m_header->setZValue(1);
- m_useHeaderWidths = false;
-
connect(m_header, SIGNAL(visibleRoleWidthChanged(QByteArray,qreal,qreal)),
this, SLOT(slotVisibleRoleWidthChanged(QByteArray,qreal,qreal)));
+ connect(m_header, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
+ this, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)));
+ connect(m_header, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
+ this, SIGNAL(sortRoleChanged(QByteArray,QByteArray)));
+
+ m_useHeaderWidths = false;
m_layouter->setHeaderHeight(m_header->size().height());
} else if (!show && m_header) {
diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h
index e44d557b9..a56a8db59 100644
--- a/src/kitemviews/kitemlistview.h
+++ b/src/kitemviews/kitemlistview.h
@@ -242,6 +242,24 @@ signals:
void maximumItemOffsetChanged(qreal current, qreal previous);
void scrollTo(qreal newOffset);
+ /**
+ * Is emitted if the user has changed the sort order by clicking on a
+ * header item (see KItemListView::setHeaderShown()). The sort order
+ * of the model has already been adjusted to
+ * the current sort order. Note that no signal will be emitted if the
+ * sort order of the model has been changed without user interaction.
+ */
+ void sortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous);
+
+ /**
+ * Is emitted if the user has changed the sort role by clicking on a
+ * header item (see KItemListView::setHeaderShown()). The sort role
+ * of the model has already been adjusted to
+ * the current sort role. Note that no signal will be emitted if the
+ * sort role of the model has been changed without user interaction.
+ */
+ void sortRoleChanged(const QByteArray& current, const QByteArray& previous);
+
protected:
virtual void initializeItemListWidget(KItemListWidget* item);
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 8ec7f335d..a94a41e15 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -154,6 +154,12 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) :
connect(model, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
}
+ KItemListView* view = controller->view();
+ connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
+ this, SLOT(slotSortOrderChangedByHeader(Qt::SortOrder,Qt::SortOrder)));
+ connect(view, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
+ this, SLOT(slotSortRoleChangedByHeader(QByteArray,QByteArray)));
+
KItemListSelectionManager* selectionManager = controller->selectionManager();
connect(selectionManager, SIGNAL(selectionChanged(QSet<int>,QSet<int>)),
this, SLOT(slotSelectionChanged(QSet<int>,QSet<int>)));
@@ -1096,6 +1102,29 @@ void DolphinView::slotRefreshItems()
}
}
+void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current, Qt::SortOrder previous)
+{
+ Q_UNUSED(previous);
+ Q_ASSERT(fileItemModel()->sortOrder() == current);
+
+ ViewProperties props(url());
+ props.setSortOrder(current);
+
+ emit sortOrderChanged(current);
+}
+
+void DolphinView::slotSortRoleChangedByHeader(const QByteArray& current, const QByteArray& previous)
+{
+ Q_UNUSED(previous);
+ Q_ASSERT(fileItemModel()->sortRole() == current);
+
+ ViewProperties props(url());
+ const Sorting sorting = sortingForSortRole(current);
+ props.setSorting(sorting);
+
+ emit sortingChanged(sorting);
+}
+
KFileItemModel* DolphinView::fileItemModel() const
{
return static_cast<KFileItemModel*>(m_container->controller()->model());
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index fa0baa61e..9a3a83fa3 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -647,6 +647,18 @@ private slots:
void slotRefreshItems();
/**
+ * Is invoked when the sort order has been changed by the user by clicking
+ * on a header item. The view properties of the directory will get updated.
+ */
+ void slotSortOrderChangedByHeader(Qt::SortOrder current, Qt::SortOrder previous);
+
+ /**
+ * Is invoked when the sort role has been changed by the user by clicking
+ * on a header item. The view properties of the directory will get updated.
+ */
+ void slotSortRoleChangedByHeader(const QByteArray& current, const QByteArray& previous);
+
+ /**
* Observes the item with the URL \a url. As soon as the directory
* model indicates that the item is available, the item will
* get selected and it is assured that the item stays visible.