From b55ebe8f9134636b579a7aea35379a99137f424f Mon Sep 17 00:00:00 2001 From: Le Tan Date: Fri, 7 Oct 2016 11:07:43 +0800 Subject: [PATCH] use itemClicked signal instead of currentItemChanged to trigger opening a file This will handle the corner case: when user open file "f" and close it, this file is still current item, so if user want to re-open it by clicking on it, it won't work. Signed-off-by: Le Tan --- vfilelist.cpp | 10 +++++----- vfilelist.h | 4 ++-- vmainwindow.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/vfilelist.cpp b/vfilelist.cpp index 2afbfd2f..7a8e8ecd 100644 --- a/vfilelist.cpp +++ b/vfilelist.cpp @@ -12,8 +12,8 @@ VFileList::VFileList(QWidget *parent) connect(this, &VFileList::customContextMenuRequested, this, &VFileList::contextMenuRequested); - connect(this, &VFileList::currentItemChanged, - this, &VFileList::currentFileItemChanged); + connect(this, &VFileList::itemClicked, + this, &VFileList::handleItemClicked); } void VFileList::initActions() @@ -260,15 +260,15 @@ void VFileList::deleteFileAndUpdateList(QListWidgetItem *item) removeFileListItem(item); } -void VFileList::currentFileItemChanged(QListWidgetItem *currentItem) +void VFileList::handleItemClicked(QListWidgetItem *currentItem) { if (!currentItem) { - emit currentFileChanged(QJsonObject()); + emit fileClicked(QJsonObject()); return; } QJsonObject itemJson = currentItem->data(Qt::UserRole).toJsonObject(); Q_ASSERT(!itemJson.isEmpty()); itemJson["path"] = QDir::cleanPath(QDir(rootPath).filePath(relativePath)); qDebug() << "click file:" << itemJson; - emit currentFileChanged(itemJson); + emit fileClicked(itemJson); } diff --git a/vfilelist.h b/vfilelist.h index eb07599c..1bff3687 100644 --- a/vfilelist.h +++ b/vfilelist.h @@ -13,13 +13,13 @@ public: explicit VFileList(QWidget *parent = 0); signals: - void currentFileChanged(QJsonObject fileJson); + void fileClicked(QJsonObject fileJson); private slots: void newFile(); void deleteFile(); void contextMenuRequested(QPoint pos); - void currentFileItemChanged(QListWidgetItem *currentItem); + void handleItemClicked(QListWidgetItem *currentItem); public slots: void setDirectory(QJsonObject dirJson); diff --git a/vmainwindow.cpp b/vmainwindow.cpp index 1609b980..751f4f99 100644 --- a/vmainwindow.cpp +++ b/vmainwindow.cpp @@ -67,7 +67,7 @@ void VMainWindow::setupUI() SLOT(setTreePath(const QString&))); connect(directoryTree, &VDirectoryTree::currentDirectoryChanged, fileList, &VFileList::setDirectory); - connect(fileList, &VFileList::currentFileChanged, + connect(fileList, &VFileList::fileClicked, tabs, &VTabWidget::openFile); setCentralWidget(mainSplitter);