diff options
author | Arno <am@disconnect.de> | 2010-05-12 17:20:09 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-05-12 17:20:09 +0200 |
commit | 11187b64f4473cf8b7993e323e0f6d0294f6609e (patch) | |
tree | eaebbf826253b910e75caf6e9479782c9b6e2b2e | |
parent | ce5cb5bc57ae95ca920b0a8b4715a201a491d897 (diff) | |
download | SheMov-11187b64f4473cf8b7993e323e0f6d0294f6609e.tar.gz SheMov-11187b64f4473cf8b7993e323e0f6d0294f6609e.tar.bz2 SheMov-11187b64f4473cf8b7993e323e0f6d0294f6609e.zip |
Solved issue with mRefreshA in FilesystemWidget
FilesystemWidget needs a pointer to the QAction triggering a refresh to
disable it under certain circumstances. The current solution was to
search the actions() of a child widget for a specific string in
QAction::data(). Don't like it.
Now SheMov sets the refresh action via a member function of
FilesystemWidget.
-rw-r--r-- | filesystemwidget.cpp | 39 | ||||
-rw-r--r-- | filesystemwidget.h | 5 | ||||
-rw-r--r-- | shemov.cpp | 2 |
3 files changed, 11 insertions, 35 deletions
diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index d857407..63bef46 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -177,11 +177,7 @@ void FilesystemWidget::deleteFiles(){ int count(0); if(!selected.isEmpty()){ count = selected.count(); - QAction *refresh = action(mFileView, "RE"); - if(refresh){ - // a refresh would invalidate selection - refresh->setEnabled(false); - } + mRefreshAction->setEnabled(false); QString message = QString(tr("Really delete %1 files?")).arg(QString::number(selected.count())); int retval = QMessageBox::question(this, tr("Question"), message, QMessageBox::Yes | QMessageBox::No); if(retval == QMessageBox::Yes){ @@ -192,9 +188,7 @@ void FilesystemWidget::deleteFiles(){ } mFileView->selectionModel()->clearSelection(); mModel->refresh(QModelIndex()); - if(refresh){ - refresh->setEnabled(true); - } + mRefreshAction->setEnabled(true); }else{ count = 1; QModelIndex cur = mFileView->currentIndex(); @@ -222,10 +216,7 @@ void FilesystemWidget::copyFiles(){ QString message = QString(tr("Really copy %1 files to %2?")).arg(selected.count()).arg(root.absoluteFilePath()); int retval = QMessageBox::question(this, tr("Question"), message, QMessageBox::Yes | QMessageBox::No); if(retval == QMessageBox::Yes){ - QAction *refresh = action(mFileView, "RE"); - if(refresh){ - refresh->setEnabled(false); - } + mRefreshAction->setEnabled(false); int files(0), dirs(0), failed(0); foreach(QModelIndex idx, selected){ QModelIndex real = proxy->mapToSource(idx); @@ -246,9 +237,7 @@ void FilesystemWidget::copyFiles(){ statusbarMessage(message); mFileView->selectionModel()->clearSelection(); mModel->refresh(rootIndex); - if(refresh){ - refresh->setEnabled(true); - } + mRefreshAction->setEnabled(true); } } @@ -264,10 +253,7 @@ void FilesystemWidget::moveFiles(){ QString message = QString(tr("Really move %1 file(s) to %2?")).arg(selected.count()).arg(root.absoluteFilePath()); int retval = QMessageBox::question(this, tr("Question"), message, QMessageBox::Yes | QMessageBox::No); if(retval == QMessageBox::Yes){ - QAction *refresh = action(mFileView, "RE"); - if(refresh){ - refresh->setEnabled(false); - } + mRefreshAction->setEnabled(false); int success(0), failed(0); foreach(QModelIndex cur, selected){ QModelIndex real = proxy->mapToSource(cur); @@ -281,9 +267,7 @@ void FilesystemWidget::moveFiles(){ } QString message = QString(tr("Successfully moved %1 file(s), %2 errors")).arg(success).arg(failed); emit statusbarMessage(message); - if(refresh){ - refresh->setEnabled(true); - } + mRefreshAction->setEnabled(true); mFileView->selectionModel()->clearSelection(); mModel->refresh(QModelIndex()); } @@ -557,14 +541,3 @@ QStringList FilesystemWidget::selectedFiles(){ } return retval; } - -QAction * FilesystemWidget::action(QWidget *widget, const QVariant &data) const{ - QAction *retval = 0; - foreach(QAction *a, widget->actions()){ - if(a->data() == data){ - retval = a; - break; - } - } - return retval; -} diff --git a/filesystemwidget.h b/filesystemwidget.h index 6ee60f6..8baae88 100644 --- a/filesystemwidget.h +++ b/filesystemwidget.h @@ -34,6 +34,8 @@ class FilesystemWidget : public QWidget { QDirModel *dirModel() { return mModel; }; const QString windowTitle() const { return mWindowTitle; }; void setArchiveDialog(ArchiveEditDialog *dlg); + void setRefreshAction(QAction *refreshAction) { mRefreshAction = refreshAction; } + QAction *refreshAction() { return mRefreshAction; } signals: void windowTitle(const QString &); @@ -70,7 +72,7 @@ class FilesystemWidget : public QWidget { QPair<QString, QStringList> programData(const QString &prefix, const QString &preferred); QStringList selectedFiles(); QStringList mExpandedDirs; - QAction *action(QWidget *widget, const QVariant &data) const; + //QAction *action(QWidget *widget, const QVariant &data) const; QDirModel *mModel; QTreeView *mDirView; FileView *mFileView; @@ -82,6 +84,7 @@ class FilesystemWidget : public QWidget { QString mTemplate; ArchiveEditDialog *mAEDialog; qint64 mSize; + QAction *mRefreshAction; }; #endif @@ -280,7 +280,7 @@ void SheMov::createActions(){ connect(mDeleteFilesA, SIGNAL(triggered()), mFSWidget, SLOT(deleteFiles())); mRefreshA = new QAction(tr("Refresh"), this); mRefreshA->setShortcut(Qt::Key_F4); - mRefreshA->setData("RE"); + mFSWidget->setRefreshAction(mRefreshA); connect(mRefreshA, SIGNAL(triggered()), mFSWidget->fileView(), SLOT(refresh())); connect(mRefreshA, SIGNAL(triggered()), this, SLOT(setFsFree())); mCopyA = new QAction(tr("Copy file(s)..."), this); |