mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
bug-fix: currentItemChanged() may have NULL pointer
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
9dd22760fc
commit
b47c9f3368
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -33,6 +33,7 @@ private:
|
||||
QListWidgetItem *createFileAndUpdateList(const QString &name,
|
||||
const QString &description);
|
||||
void deleteFileAndUpdateList(QListWidgetItem *item);
|
||||
void clearDirectoryInfo();
|
||||
|
||||
QString rootPath;
|
||||
QString relativePath;
|
||||
|
Loading…
x
Reference in New Issue
Block a user