diff options
author | Arno <am@disconnect.de> | 2010-07-30 19:59:52 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-07-30 19:59:52 +0200 |
commit | 066cc53c2506fb7f7cb7b3b0d888243df611cacd (patch) | |
tree | 73af8e7b7ea17255d95a84b3ee9dcd5d6946c171 | |
parent | a493d6500c33a0956e0165ad53136fa6110a7a64 (diff) | |
download | SheMov-066cc53c2506fb7f7cb7b3b0d888243df611cacd.tar.gz SheMov-066cc53c2506fb7f7cb7b3b0d888243df611cacd.tar.bz2 SheMov-066cc53c2506fb7f7cb7b3b0d888243df611cacd.zip |
Bugfix commit
The journey through the internals of SheMov started by fixing
SeriesTreeWidget::readSettings(). The selected index didn't really get
selected on startup because only QItemSelectionModel::setCurrendt() was
called. Replace it with QItemSelectionModel::select() and
QTreeView::setCurrent(). Also fix SeriesTreeWidget::writeSettings() to
only write selected items to QSettings() when something is selected.
While working on selections I realized that there is a serious bug in
Helper::moveToArchive. The destination directory in the archive must be
created if it doesn't exist. For a testcase I needed an easy way to move
files back from the archive to incoming directory, so I added
FilesTreeWiget::moveToDirectory(). This lets you move files from the
FilesTreeWidget to any directory. During testing I realized that
SeriesTreeWidget::deleteFromSeries() QMessageBox() doesn't show files
when deleting a series part. Fixed that by adding SeriesParts to file
list.
Finally a newly added SeriesPart gets selected and selected by expanding
it first and then calling QItemSelectionModel::select()
To make a long story short:
1. fix SeriesTreeWidget::{read,write}Settings
2. add FilesTreeWidget::moveToDirectory()
3. fix SeriesTreeWidget::deleteFromSeries() QMessageBox
4. fix selecting newly added SeriesParts
-rw-r--r-- | filestreewidget.cpp | 19 | ||||
-rw-r--r-- | filestreewidget.h | 1 | ||||
-rw-r--r-- | helper.cpp | 5 | ||||
-rw-r--r-- | seriestreewidget.cpp | 21 | ||||
-rw-r--r-- | shemov.cpp | 3 | ||||
-rw-r--r-- | shemov.h | 1 |
6 files changed, 43 insertions, 7 deletions
diff --git a/filestreewidget.cpp b/filestreewidget.cpp index d27a22e..a348ac4 100644 --- a/filestreewidget.cpp +++ b/filestreewidget.cpp @@ -17,6 +17,8 @@ #include <QSpinBox> #include <QPushButton> #include <QProcess> +#include <QFileDialog> +#include <QSettings> #include <QDebug> @@ -139,6 +141,23 @@ void FilesTreeWidget::removeFiles(){ } } +void FilesTreeWidget::moveToDirectory(){ + QModelIndexList selected = mView->selectionModel()->selectedRows(); + if(selected.isEmpty()){ + return; + } + QSettings s; + QString startDir = s.value("paths/selecteddir", QDir::homePath()).toString(); + QString dir = QFileDialog::getExistingDirectory(this, tr("Select directory"), startDir); + if(!dir.isEmpty()){ + foreach(QModelIndex i, selected){ + QString source = i.data(FilesTreeModel::FullPathRole).toString(); + QString destination = QString("%1/%2").arg(dir).arg(i.data(FilesTreeModel::FileNameRole).toString()); + QFile::rename(source, destination); + } + } +} + void FilesTreeWidget::fileSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous){ Q_UNUSED(previous); int seriesPartId = current.data(FilesTreeModel::SeriesPartIdRole).toInt(); diff --git a/filestreewidget.h b/filestreewidget.h index ae723e3..c11431b 100644 --- a/filestreewidget.h +++ b/filestreewidget.h @@ -33,6 +33,7 @@ class FilesTreeWidget : public QWidget { void moveToBurn(); void setDvdNo(); void removeFiles(); + void moveToDirectory(); private slots: void fileSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous); @@ -13,6 +13,7 @@ #include <QCryptographicHash> #include <QHash> #include <QSettings> +#include <QDir> #include "helper.h" @@ -90,6 +91,10 @@ namespace Helper { return QString(); } } + QFileInfo destDir = QFileInfo(destFile.absolutePath()); + if(!destDir.exists()){ + QDir::root().mkpath(destFile.absolutePath()); + } bool success = QFile::rename(path, destFile.absoluteFilePath()); if(success){ return destFile.absoluteFilePath(); diff --git a/seriestreewidget.cpp b/seriestreewidget.cpp index 35276a1..3452931 100644 --- a/seriestreewidget.cpp +++ b/seriestreewidget.cpp @@ -93,6 +93,9 @@ void SeriesTreeWidget::seriesAdded(QString seriesName, int seriesPart, bool reso } QModelIndex destIdx = mModel->findValue(seriesName); if(destIdx.isValid()){ + QModelIndex proxySeries = mProxy->mapFromSource(destIdx); + mView->expand(proxySeries); + mView->scrollTo(proxySeries, QAbstractItemView::PositionAtCenter); QModelIndex seriesPartIdx = mModel->findValue(seriesPart, destIdx, SeriesTreeModel::SeriesPart); if(seriesPartIdx.isValid()){ destIdx = seriesPartIdx; @@ -100,10 +103,7 @@ void SeriesTreeWidget::seriesAdded(QString seriesName, int seriesPart, bool reso } if(destIdx.isValid()){ QModelIndex proxyIndex = mProxy->mapFromSource(destIdx); - if(destIdx.parent().isValid()){ - mView->expand(destIdx); - } - mView->selectionModel()->select(proxyIndex, QItemSelectionModel::ClearAndSelect); + mView->selectionModel()->select(proxyIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current | QItemSelectionModel::Rows); } } @@ -136,6 +136,9 @@ void SeriesTreeWidget::deleteFromSeries(){ foreach(QPersistentModelIndex s, series){ files.append(mModel->findFiles(s)); } + foreach(QPersistentModelIndex p, parts){ + files.append(mModel->findFiles(p)); + } QString message; if(!files.isEmpty()){ @@ -181,7 +184,9 @@ void SeriesTreeWidget::readSettings(){ QModelIndex seriesIdx = mModel->findValue(selectedSeries); if(seriesIdx.isValid()){ QModelIndex real = mProxy->mapFromSource(seriesIdx); - mView->selectionModel()->setCurrentIndex(real, QItemSelectionModel::SelectCurrent); + mView->scrollTo(real, QAbstractItemView::PositionAtCenter); + mView->selectionModel()->select(real, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current | QItemSelectionModel::Rows); + mView->setCurrentIndex(real); } } @@ -189,8 +194,10 @@ void SeriesTreeWidget::writeSettings(){ QSettings s; s.setValue("archive/expanded", mExpandedItems); s.setValue("archive/sortorder", mProxy->sortOrder()); - QString selected = mView->selectionModel()->currentIndex().data(SeriesTreeModel::NameRole).toString(); - s.setValue("archive/selectedseries", selected); + QModelIndexList selected = mView->selectionModel()->selectedRows(); + if(!selected.isEmpty()){ + s.setValue("archive/selectedseries", selected.at(0).data(SeriesTreeModel::NameRole).toString()); + } } void SeriesTreeWidget::expandCurrent(){ @@ -357,6 +357,8 @@ void SheMov::createActions(){ //Tree FileWidget actions mMoveToBurnA = new QAction(tr("Move to burn directory"), this); connect(mMoveToBurnA, SIGNAL(triggered()), mATree->filesWidget(), SLOT(moveToBurn())); + mMoveFilesA = new QAction(tr("Move to directory..."), this); + connect(mMoveFilesA, SIGNAL(triggered()), mATree->filesWidget(), SLOT(moveToDirectory())); mSetDvdNoA = new QAction(tr("Set dvd number"), this); connect(mSetDvdNoA, SIGNAL(triggered()), mATree->filesWidget(), SLOT(setDvdNo())); mDeleteFilesFromTreeA = new QAction(tr("Delete file(s)..."), this); @@ -471,6 +473,7 @@ void SheMov::createMenus(){ //ArchiveTreeView fileWidget context menu mATree->filesWidget()->filesTree()->addAction(mMoveToBurnA); + mATree->filesWidget()->filesTree()->addAction(mMoveFilesA); QAction *sep7 = new QAction(this); sep7->setSeparator(true); mATree->filesWidget()->filesTree()->addAction(sep7); @@ -101,6 +101,7 @@ class SheMov : public QMainWindow { //TreeView FileWidget Actions QAction *mMoveToBurnA; + QAction *mMoveFilesA; QAction *mSetDvdNoA; QAction *mDeleteFilesFromTreeA; |