ProjectExplorer: fix possible crashes

Change-Id: I0b06e31f07ddf9c052f360bb66ac2330cc21d7b6
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Tim Jenssen
2017-02-10 17:01:38 +01:00
parent a2c6e28478
commit 42061e8cdc
2 changed files with 7 additions and 5 deletions

View File

@@ -192,6 +192,7 @@ bool FlatModel::setData(const QModelIndex &index, const QVariant &value, int rol
return false;
Node *node = nodeForIndex(index);
QTC_ASSERT(node, return false);
Utils::FileName orgFilePath = node->filePath();
Utils::FileName newFilePath = orgFilePath.parentDir().appendPath(value.toString());
@@ -328,10 +329,11 @@ QMimeData *FlatModel::mimeData(const QModelIndexList &indexes) const
{
auto data = new Utils::DropMimeData;
foreach (const QModelIndex &index, indexes) {
Node *node = nodeForIndex(index);
if (node->asFileNode())
data->addFile(node->filePath().toString());
data->addValue(QVariant::fromValue(node));
if (Node *node = nodeForIndex(index)) {
if (node->asFileNode())
data->addFile(node->filePath().toString());
data->addValue(QVariant::fromValue(node));
}
}
return data;
}

View File

@@ -407,7 +407,7 @@ void ProjectTreeWidget::showContextMenu(const QPoint &pos)
void ProjectTreeWidget::openItem(const QModelIndex &mainIndex)
{
Node *node = m_model->nodeForIndex(mainIndex);
if (node->nodeType() != NodeType::File)
if (!node || node->nodeType() != NodeType::File)
return;
IEditor *editor = EditorManager::openEditor(node->filePath().toString());
if (editor && node->line() >= 0)