Fix segfault on bad input

This commit is contained in:
WandererFan 2016-11-14 09:42:54 -05:00 committed by wmayer
parent 657264ad49
commit 3797f7ebc3
2 changed files with 37 additions and 17 deletions

View File

@ -70,6 +70,7 @@ TaskSectionView::TaskSectionView(TechDraw::DrawViewPart* base, TechDraw::DrawVie
connect(ui->pbReset, SIGNAL(clicked(bool)),
this, SLOT(onResetClicked(bool)));
sectionDir = "unset";
saveInitialValues();
resetValues();
}
@ -97,6 +98,7 @@ void TaskSectionView::resetValues()
checkAll(false);
enableAll(true);
sectionDir = "unset";
sectionProjDir = saveSectionProjDir;
sectionNormal = saveSectionNormal;
@ -114,8 +116,9 @@ void TaskSectionView::resetValues()
}
//calculate good starting points from base view and push buttons
void TaskSectionView::calcValues()
bool TaskSectionView::calcValues()
{
bool result = true;
Base::Vector3d stdX(1.0,0.0,0.0);
Base::Vector3d stdY(0.0,1.0,0.0);
Base::Vector3d stdZ(0.0,0.0,1.0);
@ -165,25 +168,32 @@ void TaskSectionView::calcValues()
sectionProjDir = -1.0 * stdX;
sectionNormal = -1.0 * stdX;
}
} else {
Base::Console().Message("Select a direction\n");
result = false;
}
ui->leNormal->setText(formatVector(sectionNormal));
ui->leProjDir->setText(formatVector(sectionProjDir));
if (result) {
ui->leNormal->setText(formatVector(sectionNormal));
ui->leProjDir->setText(formatVector(sectionProjDir));
Base::Console().Message("Press Reset, OK or Cancel to continue\n");
Base::Console().Message("Press Reset, OK or Cancel to continue\n");
}
return result;
}
//move values from screen to DocObjs
void TaskSectionView::updateValues()
{
m_section->SectionDirection.setValue(sectionDir);
if (strcmp(sectionDir,"unset") != 0) {
m_section->SectionDirection.setValue(sectionDir);
}
m_section->Direction.setValue(sectionProjDir);
m_section->SectionNormal.setValue(sectionNormal);
Base::Vector3d origin(ui->sb_OrgX->value().getValue(),
ui->sb_OrgY->value().getValue(),
ui->sb_OrgZ->value().getValue());
m_section->SectionOrigin.setValue(origin);
m_section->SectionDirection.setValue(sectionDir);
m_section->SectionSymbol.setValue(ui->leSymbol->text().toUtf8().constData());
m_base->touch();
@ -206,8 +216,9 @@ void TaskSectionView::turnOnUp()
ui->pb_Up->setChecked(true);
ui->pb_Up->setEnabled(true);
blockButtons(false);
calcValues();
updateValues();
if (calcValues()) {
updateValues();
}
}
void TaskSectionView::turnOnDown()
@ -218,8 +229,9 @@ void TaskSectionView::turnOnDown()
ui->pb_Down->setChecked(true);
ui->pb_Down->setEnabled(true);
blockButtons(false);
calcValues();
updateValues();
if (calcValues()) {
updateValues();
}
}
void TaskSectionView::turnOnLeft()
@ -230,8 +242,9 @@ void TaskSectionView::turnOnLeft()
ui->pb_Left->setChecked(true);
ui->pb_Left->setEnabled(true);
blockButtons(false);
calcValues();
updateValues();
if (calcValues()) {
updateValues();
}
}
void TaskSectionView::turnOnRight()
@ -242,8 +255,9 @@ void TaskSectionView::turnOnRight()
ui->pb_Right->setChecked(true);
ui->pb_Right->setEnabled(true);
blockButtons(false);
calcValues();
updateValues();
if (calcValues()) {
updateValues();
}
}
void TaskSectionView::checkAll(bool b)
@ -302,8 +316,14 @@ void TaskSectionView::onResetClicked(bool b)
bool TaskSectionView::accept()
{
updateValues();
return true;
if (strcmp(sectionDir,"unset") != 0) {
updateValues();
return true;
} else {
Base::Console().Message("No direction selected!\n");
reject();
return false;
}
}
bool TaskSectionView::reject()

View File

@ -66,7 +66,7 @@ protected:
void blockButtons(bool b);
void changeEvent(QEvent *e);
void resetValues();
void calcValues();
bool calcValues();
void saveInitialValues();
void updateValues();
QString formatVector(Base::Vector3d v);