From 929a4bc23baf083effd11ec685f912f8b51591ff Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 11 Nov 2016 05:29:47 +0100 Subject: Read and write settings / SelectionBehavior Fixing selection behavior should have been a separate commit, but well... Set it to ExtendedSelection and SelectRows. --- randomtab.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ randomtab.h | 3 +++ 2 files changed, 44 insertions(+) diff --git a/randomtab.cpp b/randomtab.cpp index 036e482..c704110 100644 --- a/randomtab.cpp +++ b/randomtab.cpp @@ -42,7 +42,13 @@ RandomTab::RandomTab(QWidget *parent) : QWidget(parent) { setupModels(); setupGui(); clearAll(); + readSettings(); mValidDvds = validDvdNos(); + select(); +} + +RandomTab::~RandomTab(){ + writeSettings(); } void RandomTab::setupGui(){ @@ -108,6 +114,8 @@ void RandomTab::setupGui(){ mFileView = new QTreeView; mFileView->setAlternatingRowColors(true); mFileView->setRootIsDecorated(false); + mFileView->setSelectionMode(QAbstractItemView::ExtendedSelection); + mFileView->setSelectionBehavior(QAbstractItemView::SelectRows); mFileModel = new QStandardItemModel; mFileProxy = new QSortFilterProxyModel; mFileProxy->setSourceModel(mFileModel); @@ -133,6 +141,34 @@ void RandomTab::setupGui(){ setLayout(mainLayout); } +void RandomTab::writeSettings(){ + QSettings s; + QStringList selGenres; + foreach(QComboBox *c, mGenreBoxes){ + selGenres << c->currentText(); + } + s.setValue("random/genres", selGenres); + QStringList selActors; + foreach(QComboBox *c,mActorBoxes){ + selActors << c->currentText(); + } + s.setValue("random/actors", selActors); + s.setValue("random/filecount", mNumber->text()); +} + +void RandomTab::readSettings(){ + QSettings s; + mNumber->setText(s.value("random/filecount", "10").toString()); + QStringList genres = s.value("random/genres").toStringList(); + for(int i = 0; i < genres.count(); ++i){ + mGenreBoxes.at(i)->setCurrentText(genres.at(i)); + } + QStringList actors = s.value("random/actors").toStringList(); + for(int i = 0; i < actors.count(); ++i){ + mActorBoxes.at(i)->setCurrentText(actors.at(i)); + } +} + QStringList RandomTab::validDvdNos(){ QStringList retval; QSettings s; @@ -200,8 +236,12 @@ void RandomTab::clearAll(){ } void RandomTab::refreshComboboxes(){ + logMessage(tr("Refreshing genres and actors...")); + writeSettings(); setupModels(); clearAll(); + readSettings(); + logMessage(tr("Refreshing genres and actors -> Done!")); } void RandomTab::select(){ @@ -293,6 +333,7 @@ void RandomTab::select(){ for(int i = 0; i < ColumnCount; ++i){ QStandardItem *item = new QStandardItem; item->setFont(QFont("courier new", -1, QFont::Bold)); + item->setEditable(false); fData << item; } fData[0]->setText(randomFilesQ.value(0).toString()); diff --git a/randomtab.h b/randomtab.h index 12d98c2..a4917a0 100644 --- a/randomtab.h +++ b/randomtab.h @@ -26,6 +26,7 @@ class RandomTab : public QWidget { enum CustomRoles { IdRole = Qt::UserRole + 1, SizeRole = Qt::UserRole + 2, DurationRole = Qt::UserRole + 3, DvdNoRole = Qt::UserRole + 4 }; enum { ColumnCount = 6 }; explicit RandomTab(QWidget *parent = 0); + virtual ~RandomTab(); public slots: void setupModels(); @@ -36,6 +37,8 @@ class RandomTab : public QWidget { private: void setupGui(); + void writeSettings(); + void readSettings(); QStringList validDvdNos(); QComboBox *mGenre1; QComboBox *mGenre2; -- cgit v1.2.3-70-g09d2