summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2016-10-03 04:26:43 +0200
committerArno <arno@disconnect.de>2016-10-03 04:26:43 +0200
commiteb65464ccdfae3458dd91be3bd6c0b7ee2ada7fa (patch)
tree6e246d0a05bab83e568cd3dc01e124eeb296d87d
parent7a75a5dc83cf0899958a24cb28d3b32f6f42933e (diff)
downloadShemovCleaner-eb65464ccdfae3458dd91be3bd6c0b7ee2ada7fa.tar.gz
ShemovCleaner-eb65464ccdfae3458dd91be3bd6c0b7ee2ada7fa.tar.bz2
ShemovCleaner-eb65464ccdfae3458dd91be3bd6c0b7ee2ada7fa.zip
Selections, selections...
Remember selected items after refreshing the torrent view. Also correctly! select the first torrent on startup.
-rw-r--r--torrentwidget.cpp26
-rw-r--r--torrentwidget.h3
2 files changed, 27 insertions, 2 deletions
diff --git a/torrentwidget.cpp b/torrentwidget.cpp
index e86b3e9..b101598 100644
--- a/torrentwidget.cpp
+++ b/torrentwidget.cpp
@@ -153,6 +153,7 @@ void TorrentWidget::createActions(){
}
void TorrentWidget::gatherData(){
+ rememberSelection();
QSqlDatabase db = QSqlDatabase::database("shemovdb");
if(!db.isOpen()){
db.open();
@@ -213,6 +214,7 @@ void TorrentWidget::gatherData(){
qApp->processEvents();
mFileView->setSortingEnabled(true);
readHeaderData();
+ restoreSelection();
}
void TorrentWidget::deleteFiles(){
@@ -379,8 +381,8 @@ void TorrentWidget::fileSelectionChanged(const QItemSelection &selected, const Q
void TorrentWidget::selectFirst(){
if(mModel->rowCount() > 0){
- QModelIndex idx = mModel->index(0, 0);
- mFileView->selectionModel()->select(idx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
+ QModelIndex idx = mProxy->index(0, NameColumn);
+ mFileView->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::Rows);
}
}
@@ -419,6 +421,26 @@ void TorrentWidget::writeSettings(){
s.setValue("searchdir", mDir->text());
}
+void TorrentWidget::rememberSelection(){
+ QModelIndexList sel = mFileView->selectionModel()->selectedRows(NameColumn);
+ mSelection.clear();
+ foreach(QModelIndex idx, sel){
+ mSelection << idx.data().toString();
+ }
+}
+
+void TorrentWidget::restoreSelection(){
+ QList<QStandardItem*> modelItems;
+ foreach(QString sel, mSelection){
+ modelItems << mModel->findItems(sel, Qt::MatchExactly, NameColumn);
+ }
+ foreach(QStandardItem *i, modelItems){
+ QModelIndex srcIdx = mModel->indexFromItem(i);
+ QModelIndex idx = mProxy->mapFromSource(srcIdx);
+ mFileView->selectionModel()->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
+ }
+}
+
QAction *TorrentWidget::createSeparator(){
QAction *retval = new QAction(this);
retval->setSeparator(true);
diff --git a/torrentwidget.h b/torrentwidget.h
index d672398..2288e60 100644
--- a/torrentwidget.h
+++ b/torrentwidget.h
@@ -60,12 +60,15 @@ class TorrentWidget : public QWidget {
void writeHeaderData();
void readSettings();
void writeSettings();
+ void rememberSelection();
+ void restoreSelection();
QAction *createSeparator();
QLineEdit *mDir;
QPushButton *mSelDir;
QLineEdit *mSearchTorrents;
QPushButton *mDoSearchTorrents;
QString mExt;
+ QStringList mSelection;
QStandardItemModel *mModel;
QTreeView *mFileView;
QToolBar *mToolBar;