Skip to content

Commit

Permalink
[TD]trap potential crash on app close
Browse files Browse the repository at this point in the history
- avoid possible crash in TD dialogs if app closed
  while dialog in progress.
  • Loading branch information
WandererFan committed Apr 24, 2020
1 parent 0a3f7ae commit 0c57730
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 46 deletions.
50 changes: 28 additions & 22 deletions src/Mod/TechDraw/Gui/TaskDetail.cpp
Expand Up @@ -125,7 +125,7 @@ TaskDetail::TaskDetail(TechDraw::DrawViewPart* baseFeat):
this, SLOT(onYEdit()));
connect(ui->qsbRadius, SIGNAL(editingFinished()),
this, SLOT(onRadiusEdit()));
connect(ui->aeReference, SIGNAL(editingFinished()),
connect(ui->leReference, SIGNAL(editingFinished()),
this, SLOT(onReferenceEdit()));

m_ghost = new QGIGhostHighlight();
Expand Down Expand Up @@ -198,7 +198,7 @@ TaskDetail::TaskDetail(TechDraw::DrawViewDetail* detailFeat):
this, SLOT(onYEdit()));
connect(ui->qsbRadius, SIGNAL(editingFinished()),
this, SLOT(onRadiusEdit()));
connect(ui->aeReference, SIGNAL(editingFinished()),
connect(ui->leReference, SIGNAL(editingFinished()),
this, SLOT(onReferenceEdit()));

m_ghost = new QGIGhostHighlight();
Expand Down Expand Up @@ -280,7 +280,7 @@ void TaskDetail::setUiFromFeat()
ui->qsbX->setValue(anchor.x);
ui->qsbY->setValue(anchor.y);
ui->qsbRadius->setValue(radius);
ui->aeReference->setText(ref);
ui->leReference->setText(ref);
}

//update ui point fields after tracker finishes
Expand All @@ -295,7 +295,7 @@ void TaskDetail::enableInputFields(bool b)
ui->qsbX->setEnabled(b);
ui->qsbY->setEnabled(b);
ui->qsbRadius->setEnabled(b);
ui->aeReference->setEnabled(b);
ui->leReference->setEnabled(b);
}

void TaskDetail::onXEdit()
Expand All @@ -315,7 +315,7 @@ void TaskDetail::onRadiusEdit()

void TaskDetail::onReferenceEdit()
{
updateDetail();
updateDetail(); //<<<<<
}

void TaskDetail::onDraggerClicked(bool b)
Expand Down Expand Up @@ -430,23 +430,29 @@ void TaskDetail::createDetail()
void TaskDetail::updateDetail()
{
// Base::Console().Message("TD::updateDetail()\n");
Gui::Command::openCommand("Update Detail");
double x = ui->qsbX->rawValue();
double y = ui->qsbY->rawValue();
Base::Vector3d temp(x, y, 0.0);
TechDraw::DrawViewDetail* detailFeat = getDetailFeat();
detailFeat->AnchorPoint.setValue(temp);

double radius = ui->qsbRadius->rawValue();
detailFeat->Radius.setValue(radius);
QString qRef = ui->aeReference->text();
std::string ref = Base::Tools::toStdString(qRef);
detailFeat->Reference.setValue(ref);

detailFeat->recomputeFeature();
getBaseFeat()->requestPaint();
Gui::Command::updateActive();
Gui::Command::commitCommand();
try {
Gui::Command::openCommand("Update Detail");
double x = ui->qsbX->rawValue();
double y = ui->qsbY->rawValue();
Base::Vector3d temp(x, y, 0.0);
TechDraw::DrawViewDetail* detailFeat = getDetailFeat();
detailFeat->AnchorPoint.setValue(temp);

double radius = ui->qsbRadius->rawValue();
detailFeat->Radius.setValue(radius);
QString qRef = ui->leReference->text();
std::string ref = Base::Tools::toStdString(qRef);
detailFeat->Reference.setValue(ref);

detailFeat->recomputeFeature();
getBaseFeat()->requestPaint();
Gui::Command::updateActive();
Gui::Command::commitCommand();
}
catch (...) {
//this is probably due to appl closing while dialog is still open
Base::Console().Error("Task Detail - detail feature update failed.\n");
}
}

//***** Getters ****************************************************************
Expand Down
15 changes: 2 additions & 13 deletions src/Mod/TechDraw/Gui/TaskDetail.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>304</width>
<height>244</height>
<height>253</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -214,13 +214,7 @@
</widget>
</item>
<item row="3" column="2">
<widget class="Gui::AccelLineEdit" name="aeReference">
<property name="toolTip">
<string>Detail identifier</string>
</property>
<property name="text">
<string>1</string>
</property>
<widget class="QLineEdit" name="leReference">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
Expand All @@ -231,11 +225,6 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::AccelLineEdit</class>
<extends>QLineEdit</extends>
<header>Gui/Widgets.h</header>
</customwidget>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
Expand Down
26 changes: 15 additions & 11 deletions src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp
Expand Up @@ -184,13 +184,15 @@ QGIView* ViewProviderDrawingView::getQView(void)
TechDraw::DrawView* dv = getViewObject();
if (dv) {
Gui::Document* guiDoc = Gui::Application::Instance->getDocument(getViewObject()->getDocument());
Gui::ViewProvider* vp = guiDoc->getViewProvider(getViewObject()->findParentPage());
ViewProviderPage* dvp = dynamic_cast<ViewProviderPage*>(vp);
if (dvp) {
if (dvp->getMDIViewPage()) {
if (dvp->getMDIViewPage()->getQGVPage()) {
qView = dynamic_cast<QGIView *>(dvp->getMDIViewPage()->
getQGVPage()->findQViewForDocObj(getViewObject()));
if (guiDoc != nullptr) {
Gui::ViewProvider* vp = guiDoc->getViewProvider(getViewObject()->findParentPage());
ViewProviderPage* dvp = dynamic_cast<ViewProviderPage*>(vp);
if (dvp) {
if (dvp->getMDIViewPage()) {
if (dvp->getMDIViewPage()->getQGVPage()) {
qView = dynamic_cast<QGIView *>(dvp->getMDIViewPage()->
getQGVPage()->findQViewForDocObj(getViewObject()));
}
}
}
}
Expand Down Expand Up @@ -249,10 +251,12 @@ MDIViewPage* ViewProviderDrawingView::getMDIViewPage() const
{
MDIViewPage* result = nullptr;
Gui::Document* guiDoc = Gui::Application::Instance->getDocument(getViewObject()->getDocument());
Gui::ViewProvider* vp = guiDoc->getViewProvider(getViewObject()->findParentPage()); //if not in page.views, !@#$%
ViewProviderPage* dvp = dynamic_cast<ViewProviderPage*>(vp);
if (dvp) {
result = dvp->getMDIViewPage();
if (guiDoc != nullptr) {
Gui::ViewProvider* vp = guiDoc->getViewProvider(getViewObject()->findParentPage());
ViewProviderPage* dvp = dynamic_cast<ViewProviderPage*>(vp);
if (dvp) {
result = dvp->getMDIViewPage();
}
}
return result;
}
Expand Down

0 comments on commit 0c57730

Please sign in to comment.