Fix crash.

Valentina crashes when a user uses a tool and select button Cancel to close a
tool dialog.

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2017-04-17 19:24:41 +03:00
parent 720366657f
commit d354b99149

View File

@ -660,32 +660,18 @@ void MainWindow::ClosedDialogWithApply(int result, VMainGraphicsScene *scene)
SCASSERT(not dialogTool.isNull()) SCASSERT(not dialogTool.isNull())
if (result == QDialog::Accepted) if (result == QDialog::Accepted)
{ {
// Only create tool if not already created with apply ApplyDialog<DrawTool>(scene);
if (dialogTool->GetAssociatedTool() == nullptr)
{
SCASSERT(scene != nullptr)
dialogTool->SetAssociatedTool(DrawTool::Create(dialogTool, scene, doc, pattern));
} }
else // If before Cancel was used Apply we have an item
{ // Or update associated tool with data DrawTool *vtool = qobject_cast<DrawTool *>(dialogTool->GetAssociatedTool());// Don't check for nullptr here
DrawTool * vtool= qobject_cast<DrawTool *>(dialogTool->GetAssociatedTool());
SCASSERT(vtool != nullptr)
vtool->FullUpdateFromGuiApply();
}
}
SCASSERT(not dialogTool.isNull())
QGraphicsItem *tool = dynamic_cast<QGraphicsItem *>(dialogTool->GetAssociatedTool());
SCASSERT(tool != nullptr)
ui->view->itemClicked(tool);
if (dialogTool->GetAssociatedTool() != nullptr) if (dialogTool->GetAssociatedTool() != nullptr)
{ {
DrawTool *vtool= qobject_cast<DrawTool *>(dialogTool->GetAssociatedTool());
SCASSERT(vtool != nullptr) SCASSERT(vtool != nullptr)
vtool->DialogLinkDestroy(); vtool->DialogLinkDestroy();
connect(vtool, &DrawTool::ToolTip, this, &MainWindow::ShowToolTip); connect(vtool, &DrawTool::ToolTip, this, &MainWindow::ShowToolTip);
} }
ArrowTool(); ArrowTool();
ui->view->itemClicked(vtool);// Don't check for nullptr here
// If insert not to the end of file call lite parse // If insert not to the end of file call lite parse
if (doc->getCursor() > 0) if (doc->getCursor() > 0)
{ {
@ -715,7 +701,7 @@ void MainWindow::ApplyDialog(VMainGraphicsScene *scene)
} }
else else
{ // Or update associated tool with data { // Or update associated tool with data
DrawTool * vtool= qobject_cast<DrawTool *>(dialogTool->GetAssociatedTool()); DrawTool * vtool = qobject_cast<DrawTool *>(dialogTool->GetAssociatedTool());
SCASSERT(vtool != nullptr) SCASSERT(vtool != nullptr)
vtool->FullUpdateFromGuiApply(); vtool->FullUpdateFromGuiApply();
} }