From eda0213389bd2534b481b7d02e717a4ef3a4f529 Mon Sep 17 00:00:00 2001 From: Frank Bergkemper Date: Wed, 21 Aug 2013 09:12:59 +0200 Subject: [PATCH] Sortable tables in bRestore Quick as is fix. Enable sorting in bRestore by setting the sorting attribute using setSortingEnabled() on the bRestoreTable objects. For FileList and FileRevisions we disable the sorting during the filling of the table (to not make it to slow) and explicitly sort the FileList on the filenames in them ascending and the FileRevisions on the revision date descending (so you get the newest revision first in the list.) Some sorting doesn't work or doesn't work right as we need to write new sorting operators which are not there. That is something we won't solve any time soon. The restore list also has the sorting attribute enabled so you can use sorting in that view too. Fixes #215: Sortable tables in bRestore Signed-off-by: Marco van Wieringen --- src/qt-console/restore/brestore.cpp | 27 +++++++++++++++++++++++++-- src/qt-console/restore/brestore.ui | 8 +++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/qt-console/restore/brestore.cpp b/src/qt-console/restore/brestore.cpp index 8ca41e28616..5978cc79c38 100644 --- a/src/qt-console/restore/brestore.cpp +++ b/src/qt-console/restore/brestore.cpp @@ -155,6 +155,9 @@ void bRestore::displayFiles(int64_t pathid, QString path) bool foundFilter = false; QString FileFilter, FileName; + // Disable sorting while filling the table + FileList->setSortingEnabled(false); + // If we provide pathid, use it (path can be altered by encoding conversion) if (pathid > 0) { arg = " pathid=" + QString().setNum(pathid); @@ -256,6 +259,14 @@ void bRestore::displayFiles(int64_t pathid, QString path) item.widget(1)->setData(Qt::UserRole, fieldlist.join("\t")); // keep info } } + + // Enable sorting after filling the table + FileList->setSortingEnabled(true); + + // Default sort by the Filename column ascending + FileList->sortByColumn(1, Qt::AscendingOrder); + + // Resize all columns to the data in them FileList->verticalHeader()->hide(); FileList->resizeColumnsToContents(); FileList->resizeRowsToContents(); @@ -294,6 +305,10 @@ void bRestore::displayFileVersion(QString pathid, QString fnid, QStringList results; QStringList fieldlist; QString tmp; + + // Disable sorting while filling the table + FileRevisions->setSortingEnabled(false); + if (m_console->dir_cmd(q, results)) { FileRevisions->setRowCount(results.size()); foreach (QString resultline, results) { @@ -321,6 +336,14 @@ void bRestore::displayFileVersion(QString pathid, QString fnid, item.widget(1)->setData(Qt::UserRole, fieldlist.join("\t")); } } + + // Enable sorting after filling the table + FileRevisions->setSortingEnabled(true); + + // Default sort by the Date column ascending + FileRevisions->sortByColumn(4, Qt::DescendingOrder); + + // Resize all columns to the data in them FileRevisions->verticalHeader()->hide(); FileRevisions->resizeColumnsToContents(); FileRevisions->resizeRowsToContents(); @@ -571,8 +594,8 @@ void bRestore::get_info_from_selection(QStringList &fileids, int32_t LinkFI; for (int i=0; i < RestoreList->rowCount(); i++) { QTableWidgetItem *item = RestoreList->item(i, 1); - QString data = item->data(Qt::UserRole).toString(); - QStringList lst = data.split("\t"); + QString filedata = item->data(Qt::UserRole).toString(); + QStringList lst = filedata.split("\t"); if (lst.at(1) != "0") { // skip path fileids << lst.at(2); jobids << lst.at(3); diff --git a/src/qt-console/restore/brestore.ui b/src/qt-console/restore/brestore.ui index a1b89d087a9..56caa881fa3 100644 --- a/src/qt-console/restore/brestore.ui +++ b/src/qt-console/restore/brestore.ui @@ -133,7 +133,7 @@ false - false + true false @@ -357,6 +357,9 @@ QAbstractItemView::DragOnly + + true + true @@ -469,6 +472,9 @@ p, li { white-space: pre-wrap; } QAbstractItemView::DropOnly + + true + Qt::MoveAction