diff options
author | Arno <am@disconnect.de> | 2013-07-29 16:16:00 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2013-07-29 16:16:00 +0200 |
commit | f26f8c0a1a569a1397c3dde1f3fd7d0d7795f1f6 (patch) | |
tree | f742c42b3901a9bbc6427642019930cabfd48a72 | |
parent | 463b159343f04bbd220d8d409b45bd368841b90f (diff) | |
download | SheMov-f26f8c0a1a569a1397c3dde1f3fd7d0d7795f1f6.tar.gz SheMov-f26f8c0a1a569a1397c3dde1f3fd7d0d7795f1f6.tar.bz2 SheMov-f26f8c0a1a569a1397c3dde1f3fd7d0d7795f1f6.zip |
Another shot at the Filesystem View crashes
I think I found the bug. We need to stop the refresh timer when
operating on the view, because it can reset the model while we're still
holding QModelIndexes. When that happens we're working with invalid
indexes and BOOM.
-rw-r--r-- | filesystemwidget.cpp | 19 | ||||
-rw-r--r-- | smdirmodel.cpp | 11 | ||||
-rw-r--r-- | smdirmodel.h | 9 |
3 files changed, 35 insertions, 4 deletions
diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index 4c05640..317d9c2 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -163,13 +163,21 @@ void FilesystemWidget::directoryEdited(){ } void FilesystemWidget::fileViewActivated(const QModelIndex &idx){ - QModelIndex real = mFileProxy->mapToSource(idx); + /* we cannot use idx from the SIGNAL here, since the model + * may already have changed */ + Q_UNUSED(idx); + TimerHandler h(mFileModel->refresTimer()); + QModelIndexList selected = mFileView->selectionModel()->selectedRows(); + if(selected.isEmpty()){ + return; + } + QModelIndex real = mFileProxy->mapToSource(selected.first()); if(mFileModel->isDir(real)){ - if(idx.data().toString() == ".."){ + if(real.data().toString() == ".."){ parentDir(); return; } - fileView()->selectionModel()->select(idx, QItemSelectionModel::Deselect); + fileView()->selectionModel()->select(selected.first(), QItemSelectionModel::Deselect); QModelIndex curDir = mModel->index(real.data(SmDirModel::FullPathRole).toString()); mDirView->setCurrentIndex(mDirProxy->mapFromSource(curDir)); return; @@ -216,6 +224,7 @@ void FilesystemWidget::goBack(){ } void FilesystemWidget::deleteFiles(){ + TimerHandler h(mFileModel->refresTimer()); QSortFilterProxyModel *proxy = qobject_cast<QSortFilterProxyModel*>(mFileView->model()); QModelIndexList selected = mFileView->selectionModel()->selectedRows(); if(selected.isEmpty()){ @@ -233,6 +242,7 @@ void FilesystemWidget::deleteFiles(){ } void FilesystemWidget::toClipboard(int clipmode){ + TimerHandler h(mFileModel->refresTimer()); mClipboardMode = clipmode; QClipboard *clip = qApp->clipboard(); QModelIndexList selected = mFileView->selectionModel()->selectedRows(); @@ -279,7 +289,7 @@ void FilesystemWidget::fromClipboard(){ } void FilesystemWidget::renameFile(){ - mFileModel->refresTimer()->stop(); + TimerHandler h(mFileModel->refresTimer()); QModelIndex curIdx = mFileView->currentIndex(); if(curIdx.data().toString() == ".."){ return; @@ -288,6 +298,7 @@ void FilesystemWidget::renameFile(){ } void FilesystemWidget::playSelected(const QString &player){ + TimerHandler h(mFileModel->refresTimer()); QStringList files = selectedFiles(); if(files.isEmpty()){ statusbarMessage(tr("Nothing selected.")); diff --git a/smdirmodel.cpp b/smdirmodel.cpp index 480b6e1..6a7ac39 100644 --- a/smdirmodel.cpp +++ b/smdirmodel.cpp @@ -201,3 +201,14 @@ void SmDirModel::addFile(const QList<QVariant> &data){ return; } +TimerHandler::TimerHandler(QTimer *timer) : mTimer(timer) { + mTimer->stop(); +} + +TimerHandler::~TimerHandler(){ + QSettings s; + bool autoRefresh = s.value("ui/autorefresh", false).toBool(); + if(autoRefresh){ + mTimer->start(); + } +} diff --git a/smdirmodel.h b/smdirmodel.h index 21aab40..192992a 100644 --- a/smdirmodel.h +++ b/smdirmodel.h @@ -61,4 +61,13 @@ class SmDirModel : public SmTreeModel { SmDataColletor *mCollector; }; +class TimerHandler { + public: + TimerHandler(QTimer *timer); + ~TimerHandler(); + + private: + QTimer *mTimer; +}; + #endif // SMDIRMODEL_H |