[TechDraw] Improve readability of DrawPage.cpp

This commit is contained in:
Benjamin Bræstrup Sayoc
2023-04-05 14:41:01 +02:00
committed by WandererFan
parent e34874b591
commit 2e12a8fad2

View File

@@ -99,7 +99,7 @@ void DrawPage::onBeforeChange(const App::Property* prop)
void DrawPage::onChanged(const App::Property* prop)
{
if ((prop == &KeepUpdated) && KeepUpdated.getValue()) {
if (prop == &KeepUpdated && KeepUpdated.getValue()) {
if (!isRestoring() && !isUnsetting()) {
//would be nice if this message was displayed immediately instead of after the recomputeFeature
Base::Console().Message("Rebuilding Views for: %s/%s\n", getNameInDocument(),
@@ -152,12 +152,14 @@ App::DocumentObjectExecReturn* DrawPage::execute(void) { return App::DocumentObj
// this is now irrelevant, b/c DP::execute doesn't do anything.
short DrawPage::mustExecute() const
{
short result = 0;
if (!isRestoring()) {
result = (Views.isTouched() || Scale.isTouched() || ProjectionType.isTouched()
|| Template.isTouched());
if (result) {
return result;
if (
Views.isTouched() ||
Scale.isTouched() ||
ProjectionType.isTouched() ||
Template.isTouched()
) {
return true;
}
}
return App::DocumentObject::mustExecute();
@@ -190,8 +192,7 @@ bool DrawPage::hasValidTemplate() const
double DrawPage::getPageWidth() const
{
App::DocumentObject* obj = nullptr;
obj = Template.getValue();
App::DocumentObject* obj = Template.getValue();
if (obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
@@ -203,14 +204,11 @@ double DrawPage::getPageWidth() const
double DrawPage::getPageHeight() const
{
App::DocumentObject* obj = nullptr;
obj = Template.getValue();
App::DocumentObject* obj = Template.getValue();
if (obj) {
if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
return templ->getHeight();
}
if (obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
return templ->getHeight();
}
throw Base::RuntimeError("Template not set for Page");
@@ -222,12 +220,9 @@ const char* DrawPage::getPageOrientation() const
App::DocumentObject* obj;
obj = Template.getValue();
if (obj) {
if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
return templ->Orientation.getValueAsString();
}
if (obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
return templ->Orientation.getValueAsString();
}
throw Base::RuntimeError("Template not set for Page");
}
@@ -235,15 +230,11 @@ const char* DrawPage::getPageOrientation() const
//orientation as 0(Portrait) or 1(Landscape)
int DrawPage::getOrientation() const
{
App::DocumentObject* obj;
obj = Template.getValue();
App::DocumentObject* obj = Template.getValue();
if (obj) {
if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
return templ->Orientation.getValue();
}
if (obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
return templ->Orientation.getValue();
}
throw Base::RuntimeError("Template not set for Page");
}
@@ -448,14 +439,13 @@ void DrawPage::handleChangedPropertyType(Base::XMLReader& reader, const char* Ty
bool DrawPage::canUpdate() const
{
bool result = false;
if (GlobalUpdateDrawings() && KeepUpdated.getValue()) {
result = true;
return true;
}
else if (!GlobalUpdateDrawings() && AllowPageOverride() && KeepUpdated.getValue()) {
result = true;
return true;
}
return result;
return false;
}
//true if object belongs to this page
@@ -479,8 +469,7 @@ bool DrawPage::GlobalUpdateDrawings(void)
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
bool result = hGrp->GetBool("GlobalUpdateDrawings", true);
return result;
return hGrp->GetBool("GlobalUpdateDrawings", true);
}
//allow/prevent a single page to update despite GlobalUpdateDrawings setting
@@ -491,8 +480,7 @@ bool DrawPage::AllowPageOverride(void)
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
bool result = hGrp->GetBool("AllowPageOverride", true);
return result;
return hGrp->GetBool("AllowPageOverride", true);
}