From: Peter Penz Date: Thu, 14 Dec 2006 19:12:05 +0000 (+0000) Subject: Support changing the sorting type and sort order (TODO: does not work yet as the... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/70782d6bb4d3b02c4c48c38ee2867561a706ed84 Support changing the sorting type and sort order (TODO: does not work yet as the implementation in KDirModel is empty yet). svn path=/trunk/playground/utils/dolphin/; revision=613696 --- diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 7f0481eec..2f287f353 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -392,61 +392,43 @@ bool DolphinView::isZoomOutPossible() const void DolphinView::setSorting(Sorting sorting) { if (sorting != this->sorting()) { - /*KFileView* view = fileView(); - int spec = view->sorting() & ~QDir::Name & ~QDir::Size & ~QDir::Time & ~QDir::Unsorted; - - switch (sorting) { - case SortByName: spec = spec | QDir::Name; break; - case SortBySize: spec = spec | QDir::Size; break; - case SortByDate: spec = spec | QDir::Time; break; - default: break; - } - ViewProperties props(url()); props.setSorting(sorting); - view->setSorting(static_cast(spec)); + KDirModel* dirModel = static_cast(m_iconsView->model()); + dirModel->sort(columnIndex(sorting), props.sortOrder()); - emit signalSortingChanged(sorting);*/ + emit sortingChanged(sorting); } } DolphinView::Sorting DolphinView::sorting() const { - /*const QDir::SortFlags spec = fileView()->sorting(); - - if (spec & QDir::Time) { - return SortByDate; - } - - if (spec & QDir::Size) { - return SortBySize; - }*/ - - return SortByName; + // TODO: instead of getting the sorting from the properties just fetch + // them from KDirModel, if such an interface will be offered (David?) + ViewProperties props(url()); + return props.sorting(); } void DolphinView::setSortOrder(Qt::SortOrder order) { if (sortOrder() != order) { - /*KFileView* view = fileView(); - int sorting = view->sorting(); - sorting = (order == Qt::Ascending) ? (sorting & ~QDir::Reversed) : - (sorting | QDir::Reversed); - ViewProperties props(url()); props.setSortOrder(order); - view->setSorting(static_cast(sorting)); + KDirModel* dirModel = static_cast(m_iconsView->model()); + dirModel->sort(columnIndex(props.sorting()), order); - emit signalSortOrderChanged(order);*/ + emit sortOrderChanged(order); } } Qt::SortOrder DolphinView::sortOrder() const { - //return fileView()->isReversed() ? Qt::Descending : Qt::Ascending; - return Qt::Descending; + // TODO: instead of getting the order from the properties just fetch + // them from KDirModel, if such an interface will be offered (David?) + ViewProperties props(url()); + return props.sortOrder(); } void DolphinView::goBack() @@ -1054,4 +1036,16 @@ void DolphinView::applyModeToView() } } +int DolphinView::columnIndex(Sorting sorting) const +{ + int index = 0; + switch (sorting) { + case SortByName: index = KDirModel::Name; break; + case SortBySize: index = KDirModel::Size; break; + case SortByDate: index = KDirModel::ModifiedTime; break; + default: assert(false); + } + return index; +} + #include "dolphinview.moc" diff --git a/src/dolphinview.h b/src/dolphinview.h index 2f1d7c605..e5af61f3f 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -442,6 +442,12 @@ private: */ void applyModeToView(); + /** + * Returns the column index used in the KDirModel depending on \a sorting. + */ + int columnIndex(Sorting sorting) const; + +private: bool m_refreshing; bool m_showProgress; Mode m_mode;