Sync file browser after change via Drag & Drop

This commit is contained in:
Martchus 2016-08-07 19:59:33 +02:00
parent 5010d3621d
commit c525a6acd9
5 changed files with 39 additions and 41 deletions

View File

@ -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);
}

View File

@ -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<void(MainWindow::*)(void)>(&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 &currentPath)
/*!
* \brief Handles that the current path has changed by the tag editor widget itself.
*/
void MainWindow::handleCurrentPathChanged(const QString &currentPath)
{
// 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();
}

View File

@ -60,7 +60,7 @@ private slots:
void showSaveAsDlg();
void saveFileInformation();
void handleFileStatusChange(bool opened, bool hasTag);
void handleFileSaved(const QString &currentPath);
void handleCurrentPathChanged(const QString &currentPath);
// 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;

View File

@ -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();

View File

@ -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<Media::Tag *> 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;