diff --git a/vdirectorytree.cpp b/vdirectorytree.cpp index 1502d8f2..a362693c 100644 --- a/vdirectorytree.cpp +++ b/vdirectorytree.cpp @@ -465,6 +465,10 @@ bool VDirectoryTree::isConflictNameWithChildren(const QTreeWidgetItem *parent, c void VDirectoryTree::currentDirectoryItemChanged(QTreeWidgetItem *currentItem) { + if (!currentItem) { + emit currentDirectoryChanged(QJsonObject()); + return; + } QJsonObject itemJson = currentItem->data(0, Qt::UserRole).toJsonObject(); Q_ASSERT(!itemJson.isEmpty()); itemJson["root_path"] = treePath; diff --git a/vfilelist.cpp b/vfilelist.cpp index 5a38f656..2afbfd2f 100644 --- a/vfilelist.cpp +++ b/vfilelist.cpp @@ -31,7 +31,11 @@ void VFileList::initActions() void VFileList::setDirectory(QJsonObject dirJson) { - Q_ASSERT(!dirJson.isEmpty()); + if (dirJson.isEmpty()) { + clearDirectoryInfo(); + return; + } + directoryName = dirJson["name"].toString(); rootPath = dirJson["root_path"].toString(); relativePath = QDir(dirJson["relative_path"].toString()).filePath(directoryName); @@ -40,6 +44,11 @@ void VFileList::setDirectory(QJsonObject dirJson) updateFileList(); } +void VFileList::clearDirectoryInfo() +{ + directoryName = rootPath = relativePath = ""; + clear(); +} void VFileList::updateFileList() { @@ -253,6 +262,10 @@ void VFileList::deleteFileAndUpdateList(QListWidgetItem *item) void VFileList::currentFileItemChanged(QListWidgetItem *currentItem) { + if (!currentItem) { + emit currentFileChanged(QJsonObject()); + return; + } QJsonObject itemJson = currentItem->data(Qt::UserRole).toJsonObject(); Q_ASSERT(!itemJson.isEmpty()); itemJson["path"] = QDir::cleanPath(QDir(rootPath).filePath(relativePath)); diff --git a/vfilelist.h b/vfilelist.h index 71091bdf..eb07599c 100644 --- a/vfilelist.h +++ b/vfilelist.h @@ -33,6 +33,7 @@ private: QListWidgetItem *createFileAndUpdateList(const QString &name, const QString &description); void deleteFileAndUpdateList(QListWidgetItem *item); + void clearDirectoryInfo(); QString rootPath; QString relativePath;