From c525a6acd987dce1a8636c7ba4e9e17b41e36953 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 7 Aug 2016 19:59:33 +0200 Subject: [PATCH] Sync file browser after change via Drag & Drop --- gui/dbquerywidget.cpp | 2 +- gui/mainwindow.cpp | 41 +++++++++++++++++++++++++---------------- gui/mainwindow.h | 3 ++- gui/tageditorwidget.cpp | 5 +++-- gui/tageditorwidget.h | 29 ++++++++--------------------- 5 files changed, 39 insertions(+), 41 deletions(-) diff --git a/gui/dbquerywidget.cpp b/gui/dbquerywidget.cpp index 1d4e661..8222c9c 100644 --- a/gui/dbquerywidget.cpp +++ b/gui/dbquerywidget.cpp @@ -76,7 +76,7 @@ DbQueryWidget::DbQueryWidget(TagEditorWidget *tagEditorWidget, QWidget *parent) connect(m_ui->abortPushButton, &QPushButton::clicked, this, &DbQueryWidget::abortSearch); connect(m_ui->startPushButton, &QPushButton::clicked, this, &DbQueryWidget::startSearch); connect(m_ui->applyPushButton, &QPushButton::clicked, this, &DbQueryWidget::applyResults); - connect(m_tagEditorWidget, &TagEditorWidget::fileStatusChange, this, &DbQueryWidget::fileStatusChanged); + connect(m_tagEditorWidget, &TagEditorWidget::fileStatusChanged, this, &DbQueryWidget::fileStatusChanged); connect(m_ui->resultsTreeView, &QTreeView::customContextMenuRequested, this, &DbQueryWidget::showResultsContextMenu); } diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index d8a6807..5b72359 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -74,6 +74,7 @@ MediaFileInfo &MainWindow::fileInfo() MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent, Qt::Window), m_ui(new Ui::MainWindow()), + m_internalFileSelection(false), m_aboutDlg(nullptr), m_settingsDlg(nullptr), m_dbQueryWidget(nullptr) @@ -137,9 +138,9 @@ MainWindow::MainWindow(QWidget *parent) : connect(m_ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutDlg); // tag editor widget connect(m_ui->tagEditorWidget, &TagEditorWidget::nextFileSelected, this, static_cast(&MainWindow::selectNextFile)); - connect(m_ui->tagEditorWidget, &TagEditorWidget::fileStatusChange, this, &MainWindow::handleFileStatusChange); + connect(m_ui->tagEditorWidget, &TagEditorWidget::fileStatusChanged, this, &MainWindow::handleFileStatusChange); connect(m_ui->tagEditorWidget, &TagEditorWidget::statusMessage, m_ui->statusBar, &QStatusBar::showMessage); - connect(m_ui->tagEditorWidget, &TagEditorWidget::fileSaved, this, &MainWindow::handleFileSaved); + connect(m_ui->tagEditorWidget, &TagEditorWidget::currentPathChanged, this, &MainWindow::handleCurrentPathChanged); // misc connect(m_ui->pathLineEdit, &QLineEdit::textEdited, this, &MainWindow::pathEntered); connect(m_ui->filesTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MainWindow::fileSelected); @@ -209,9 +210,9 @@ bool MainWindow::event(QEvent *event) */ void MainWindow::pathEntered() { - QString path = m_ui->pathLineEdit->text(); + const QString path = m_ui->pathLineEdit->text(); if(!path.isEmpty()) { - QModelIndex index = m_fileFilterModel->mapFromSource(m_fileModel->index(path)); + const QModelIndex index = m_fileFilterModel->mapFromSource(m_fileModel->index(path)); if(index.isValid()) { m_ui->filesTreeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); m_ui->pathLineEdit->setProperty("classNames", QStringList()); @@ -224,23 +225,26 @@ void MainWindow::pathEntered() /*! * \brief This private slot is called when the selected file or directory changes. + * * If a directory is selected the m_ui->pathLineEdit will be updated. * If a file is selected it will be opened. */ void MainWindow::fileSelected() { - QModelIndexList selectedIndexes = m_ui->filesTreeView->selectionModel()->selectedRows(); - if(selectedIndexes.count() == 1) { - QString path(m_fileModel->filePath(m_fileFilterModel->mapToSource(selectedIndexes.at(0)))); - QFileInfo fileInfo(path); - if(fileInfo.isFile()) { - startParsing(path); - m_ui->pathLineEdit->setText(fileInfo.dir().path()); - } else if(fileInfo.isDir()) { - m_ui->pathLineEdit->setText(path); + if(!m_internalFileSelection) { + const QModelIndexList selectedIndexes = m_ui->filesTreeView->selectionModel()->selectedRows(); + if(selectedIndexes.count() == 1) { + QString path(m_fileModel->filePath(m_fileFilterModel->mapToSource(selectedIndexes.at(0)))); + QFileInfo fileInfo(path); + if(fileInfo.isFile()) { + startParsing(path); + m_ui->pathLineEdit->setText(fileInfo.dir().path()); + } else if(fileInfo.isDir()) { + m_ui->pathLineEdit->setText(path); + } + m_ui->pathLineEdit->setProperty("classNames", QStringList()); + updateStyle(m_ui->pathLineEdit); } - m_ui->pathLineEdit->setProperty("classNames", QStringList()); - updateStyle(m_ui->pathLineEdit); } } @@ -262,13 +266,18 @@ void MainWindow::handleFileStatusChange(bool opened, bool hasTag) setWindowTitle(Dialogs::generateWindowTitle(opened ? DocumentStatus::Saved : DocumentStatus::NoDocument, m_ui->tagEditorWidget->currentPath())); } -void MainWindow::handleFileSaved(const QString ¤tPath) +/*! + * \brief Handles that the current path has changed by the tag editor widget itself. + */ +void MainWindow::handleCurrentPathChanged(const QString ¤tPath) { // ensure the current file is still selected + m_internalFileSelection = true; const QModelIndex index = m_fileFilterModel->mapFromSource(m_fileModel->index(currentPath)); if(index.isValid()) { m_ui->filesTreeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); } + m_internalFileSelection = false; // ensure this is the active window activateWindow(); } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index ec7f8af..08e983e 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -60,7 +60,7 @@ private slots: void showSaveAsDlg(); void saveFileInformation(); void handleFileStatusChange(bool opened, bool hasTag); - void handleFileSaved(const QString ¤tPath); + void handleCurrentPathChanged(const QString ¤tPath); // settings void showSettingsDlg(); @@ -81,6 +81,7 @@ private: // models QFileSystemModel *m_fileModel; FileFilterProxyModel *m_fileFilterModel; + bool m_internalFileSelection; // dialogs Dialogs::AboutDialog *m_aboutDlg; Dialogs::SettingsDialog *m_settingsDlg; diff --git a/gui/tageditorwidget.cpp b/gui/tageditorwidget.cpp index 55d4c2c..69b2f00 100644 --- a/gui/tageditorwidget.cpp +++ b/gui/tageditorwidget.cpp @@ -221,6 +221,7 @@ bool TagEditorWidget::event(QEvent *event) } startParsing(path, true); #else + emit currentPathChanged(url.path()); startParsing(url.path(), true); #endif } @@ -457,7 +458,7 @@ void TagEditorWidget::updateFileStatusStatus() m_infoTreeView->setEnabled(opened); } // inform the main window about the file status change as well - emit fileStatusChange(opened, hasTag); + emit fileStatusChanged(opened, hasTag); } /*! @@ -1150,7 +1151,7 @@ void TagEditorWidget::showSavingResult(bool processingError, bool ioError) m_fileOperationMutex.unlock(); // let the main window know that the current file has been saved // -> the main window will ensure the current file is still selected - emit fileSaved(m_currentPath); + emit currentPathChanged(m_currentPath); // show next file (only if there are critical notifications) if(!critical && m_nextFileAfterSaving) { emit nextFileSelected(); diff --git a/gui/tageditorwidget.h b/gui/tageditorwidget.h index f95f0d9..b1513b2 100644 --- a/gui/tageditorwidget.h +++ b/gui/tageditorwidget.h @@ -43,7 +43,7 @@ class FileInfoModel; class TagEditorWidget : public QWidget { Q_OBJECT - Q_PROPERTY(QString currentPath READ currentPath) + Q_PROPERTY(QString currentPath READ currentPath NOTIFY currentPathChanged) Q_PROPERTY(QByteArray fileInfoHtml READ fileInfoHtml) Q_PROPERTY(bool fileNameVisible READ isFileNameVisible WRITE setFileNameVisible) Q_PROPERTY(bool buttonsVisible READ areButtonsVisible WRITE setButtonVisible) @@ -79,25 +79,14 @@ public slots: void applySettingsFromDialog(); signals: - /*! - * \brief Emitted when loading the next file has been triggered. - */ + /// \brief Emitted when loading the next file has been triggered. void nextFileSelected(); - - /*! - * \brief Emitted to show a status message. - */ + /// \brief Emitted to show a status message. void statusMessage(const QString &message, int timeout = 0); - - /*! - * \brief Emmited when the file status (opened/closed) has changed. - */ - void fileStatusChange(bool opened, bool hasTag); - - /*! - * \brief Emitted when the current path changed. - */ - void fileSaved(const QString &newPath); + /// \brief Emmited when the file status (opened/closed) has changed. + void fileStatusChanged(bool opened, bool hasTag); + /// \brief Emitted when the current path has changed; always emitted a saving. + void currentPathChanged(const QString &newPath); protected: bool event(QEvent *event); @@ -151,9 +140,7 @@ private: Media::MediaFileInfo m_fileInfo; std::vector m_tags; QByteArray m_fileInfoHtml; - /*! - * \brief This is the actual direcotry of the opened file which may differ from the directory selected in the tree view of the main window. - */ + /// \brief This is the actual direcotry of the opened file which may differ from the directory selected in the tree view of the main window. QString m_currentDir; QString m_lastDir; QString m_saveFilePath;