[TD]use weak_ptr as deletion guard
- prevent crash if dimension deleted by Python while dialog is open
This commit is contained in:
@@ -47,11 +47,10 @@ using namespace TechDraw;
|
||||
using namespace TechDrawGui;
|
||||
|
||||
TaskDimension::TaskDimension(QGIViewDimension *parent, ViewProviderDimension *dimensionVP) :
|
||||
ui(new Ui_TaskDimension)
|
||||
ui(new Ui_TaskDimension),
|
||||
m_parent(parent),
|
||||
m_dimensionVP(dimensionVP)
|
||||
{
|
||||
m_parent = parent;
|
||||
m_dimensionVP = dimensionVP;
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
// Tolerancing
|
||||
@@ -143,6 +142,11 @@ TaskDimension::~TaskDimension()
|
||||
|
||||
bool TaskDimension::accept()
|
||||
{
|
||||
if (m_dimensionVP.expired()) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Missing Dimension"),
|
||||
QObject::tr("Dimension not found. Was it deleted? Can not continue."));
|
||||
return true;
|
||||
}
|
||||
Gui::Document* doc = m_dimensionVP->getDocument();
|
||||
m_dimensionVP->getObject()->purgeTouched();
|
||||
doc->commitCommand();
|
||||
@@ -153,6 +157,11 @@ bool TaskDimension::accept()
|
||||
|
||||
bool TaskDimension::reject()
|
||||
{
|
||||
if (m_dimensionVP.expired()) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Missing Dimension"),
|
||||
QObject::tr("Dimension not found. Was it deleted? Can not continue."));
|
||||
return true;
|
||||
}
|
||||
Gui::Document* doc = m_dimensionVP->getDocument();
|
||||
doc->abortCommand();
|
||||
recomputeFeature();
|
||||
@@ -165,6 +174,10 @@ bool TaskDimension::reject()
|
||||
|
||||
void TaskDimension::recomputeFeature()
|
||||
{
|
||||
if (m_dimensionVP.expired()) {
|
||||
// guard against deletion while this dialog is running
|
||||
return;
|
||||
}
|
||||
App::DocumentObject* objVP = m_dimensionVP->getObject();
|
||||
assert(objVP);
|
||||
objVP->getDocument()->recomputeFeature(objVP);
|
||||
@@ -297,12 +310,18 @@ void TaskDimension::onArbitraryTolerancesChanged()
|
||||
|
||||
void TaskDimension::onFlipArrowheadsChanged()
|
||||
{
|
||||
if (m_dimensionVP.expired()) {
|
||||
return;
|
||||
}
|
||||
m_dimensionVP->FlipArrowheads.setValue(ui->cbArrowheads->isChecked());
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
void TaskDimension::onColorChanged()
|
||||
{
|
||||
if (m_dimensionVP.expired()) {
|
||||
return;
|
||||
}
|
||||
App::Color ac;
|
||||
ac.setValue<QColor>(ui->dimensionColor->color());
|
||||
m_dimensionVP->Color.setValue(ac);
|
||||
@@ -311,12 +330,18 @@ void TaskDimension::onColorChanged()
|
||||
|
||||
void TaskDimension::onFontsizeChanged()
|
||||
{
|
||||
if (m_dimensionVP.expired()) {
|
||||
return;
|
||||
}
|
||||
m_dimensionVP->Fontsize.setValue(ui->qsbFontSize->value().getValue());
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
void TaskDimension::onDrawingStyleChanged()
|
||||
{
|
||||
if (m_dimensionVP.expired()) {
|
||||
return;
|
||||
}
|
||||
m_dimensionVP->StandardAndStyle.setValue(ui->comboDrawingStyle->currentIndex());
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#ifndef GUI_TASKVIEW_TASKDIMENSION_H
|
||||
#define GUI_TASKVIEW_TASKDIMENSION_H
|
||||
|
||||
#include <Gui/DocumentObserver.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
@@ -72,7 +73,7 @@ private Q_SLOTS:
|
||||
private:
|
||||
std::unique_ptr<Ui_TaskDimension> ui;
|
||||
QGIViewDimension *m_parent;
|
||||
ViewProviderDimension *m_dimensionVP;
|
||||
Gui::WeakPtrT<ViewProviderDimension> m_dimensionVP;
|
||||
std::pair<double, bool> getAngleFromSelection();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user