[TechDraw] Simplify code getting default line weights

This commit is contained in:
Benjamin Bræstrup Sayoc
2022-08-02 14:11:13 +02:00
committed by WandererFan
parent 750fa24b2e
commit 86dfd0a862
12 changed files with 29 additions and 69 deletions

View File

@@ -104,12 +104,7 @@ std::string LineFormat::toString(void) const
//static preference getters.
double LineFormat::getDefEdgeWidth()
{
int lgNumber = Preferences::lineGroup();
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
double width = lg->getWeight("Graphic");
delete lg;
return width;
return TechDraw::LineGroup::getDefaultWidth("Graphic");
}
App::Color LineFormat::getDefEdgeColor()
@@ -136,7 +131,7 @@ CosmeticVertex::CosmeticVertex() : TechDraw::Vertex()
linkGeom = -1;
color = Preferences::vertexColor();
size = Preferences::vertexScale() *
LineGroup::getDefaultWidth("Thick", Preferences::lineGroup());
LineGroup::getDefaultWidth("Thick");
style = 1;
visible = true;
hlrVisible = true;
@@ -165,7 +160,7 @@ CosmeticVertex::CosmeticVertex(Base::Vector3d loc) : TechDraw::Vertex(loc)
linkGeom = -1;
color = Preferences::vertexColor();
size = Preferences::vertexScale() *
LineGroup::getDefaultWidth("Thick", Preferences::lineGroup());
LineGroup::getDefaultWidth("Thick");
style = 1; //TODO: implement styled vertexes
visible = true;
hlrVisible = true;

View File

@@ -522,12 +522,7 @@ double DrawUtil::sensibleScale(double working_scale)
double DrawUtil::getDefaultLineWeight(std::string lineType)
{
int lgNumber = Preferences::lineGroup();
auto lg = LineGroup::lineGroupFactory(lgNumber);
double weight = lg->getWeight(lineType);
delete lg; //Coverity CID 174671
return weight;
return TechDraw::LineGroup::getDefaultWidth(lineType);
}
bool DrawUtil::isBetween(const Base::Vector3d pt, const Base::Vector3d end1, const Base::Vector3d end2)

View File

@@ -178,15 +178,19 @@ LineGroup* LineGroup::lineGroupFactory(int groupNumber)
return lg;
}
//valid weight names: Thick, Thin, Graphic, Extra
double LineGroup::getDefaultWidth(std::string weightName, int groupNumber)
/**
* @brief Returns the default line width given a weight name and group number.
*
* @param weightName can be "Thick", "Thin", "Graphic" or "Extra"
* @param lineGroupNumber if -1 will then use groupNumber in preferences. Default value is -1.
* @return the default line width.
*/
double LineGroup::getDefaultWidth(std::string weightName, int lineGroupNumber)
{
//default line weights
int lgNumber = groupNumber;
if (lgNumber == -1) {
lgNumber = Preferences::lineGroup();
if (lineGroupNumber == -1) {
lineGroupNumber = Preferences::lineGroup();
}
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
auto lg = TechDraw::LineGroup::lineGroupFactory(lineGroupNumber);
double weight = lg->getWeight(weightName);
delete lg;

View File

@@ -426,17 +426,12 @@ void TaskCenterLine::enableTaskButtons(bool b)
double TaskCenterLine::getCenterWidth()
{
int lgNumber = Preferences::lineGroup();
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
double width = lg->getWeight("Graphic");
delete lg;
Gui::ViewProvider* vp = QGIView::getViewProvider(m_partFeat);
auto partVP = dynamic_cast<ViewProviderViewPart*>(vp);
if (partVP) {
width = partVP->IsoWidth.getValue();
if (!partVP) {
return TechDraw::LineGroup::getDefaultWidth("Graphic");
}
return width;
return partVP->IsoWidth.getValue();
}
Qt::PenStyle TaskCenterLine::getCenterStyle()

View File

@@ -778,11 +778,7 @@ int TaskLeaderLine::getPrefArrowStyle()
double TaskLeaderLine::prefWeight() const
{
int lgNumber = Preferences::lineGroup();
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
double weight = lg->getWeight("Thin");
delete lg; //Coverity CID 174670
return weight;
return TechDraw::LineGroup::getDefaultWidth("Thin");
}
App::Color TaskLeaderLine::prefLineColor(void)

View File

@@ -319,11 +319,7 @@ void TaskRichAnno::onEditorExit(void)
double TaskRichAnno::prefWeight() const
{
int lgNumber = Preferences::lineGroup();
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
double weight = lg->getWeight("Graphic");
delete lg; //Coverity CID 174670
return weight;
return TechDraw::LineGroup::getDefaultWidth("Graphic");
}
App::Color TaskRichAnno::prefLineColor(void)

View File

@@ -60,10 +60,7 @@ ViewProviderBalloon::ViewProviderBalloon()
ADD_PROPERTY_TYPE(Font, (Preferences::labelFont().c_str()), group, App::Prop_None, "The name of the font to use");
ADD_PROPERTY_TYPE(Fontsize, (Preferences::dimFontSizeMM()),
group, (App::PropertyType)(App::Prop_None), "Balloon text size in units");
int lgNumber = Preferences::lineGroup();
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
double weight = lg->getWeight("Thin");
delete lg; //Coverity CID 174670
double weight = TechDraw::LineGroup::getDefaultWidth("Thin");
ADD_PROPERTY_TYPE(LineWidth, (weight), group, (App::PropertyType)(App::Prop_None), "Leader line width");
ADD_PROPERTY_TYPE(LineVisible, (true), group, (App::PropertyType)(App::Prop_None), "Balloon line visible or hidden");
ADD_PROPERTY_TYPE(Color, (PreferencesGui::dimColor()), group, App::Prop_None, "Color of the balloon");

View File

@@ -240,11 +240,7 @@ double ViewProviderDimension::prefFontSize() const
double ViewProviderDimension::prefWeight() const
{
int lgNumber = Preferences::lineGroup();
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
double weight = lg->getWeight("Thin");
delete lg; //Coverity CID 174670
return weight;
return TechDraw::LineGroup::getDefaultWidth("Thin");
}
int ViewProviderDimension::prefStandardAndStyle() const

View File

@@ -178,10 +178,7 @@ void ViewProviderGeomHatch::updateGraphic(void)
void ViewProviderGeomHatch::getParameters(void)
{
int lgNumber = Preferences::lineGroup();
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
double weight = lg->getWeight("Graphic");
delete lg; //Coverity CID 174667
double weight = TechDraw::LineGroup::getDefaultWidth("Graphic");
WeightPattern.setValue(weight);
}

View File

@@ -181,11 +181,7 @@ TechDraw::DrawLeaderLine* ViewProviderLeader::getFeature() const
double ViewProviderLeader::getDefLineWeight(void)
{
int lgNumber = Preferences::lineGroup();
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
double result = lg->getWeight("Thin");
delete lg; //Coverity CID 174670
return result;
return TechDraw::LineGroup::getDefaultWidth("Thin");
}
App::Color ViewProviderLeader::getDefLineColor(void)

View File

@@ -168,11 +168,7 @@ double ViewProviderRichAnno::getDefFontSize()
double ViewProviderRichAnno::getDefLineWeight(void)
{
int lgNumber = Preferences::lineGroup();
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
double result = lg->getWeight("Graphics");
delete lg;
return result;
return TechDraw::LineGroup::getDefaultWidth("Graphics");
}
void ViewProviderRichAnno::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)

View File

@@ -78,21 +78,18 @@ ViewProviderViewPart::ViewProviderViewPart()
static const char *hgroup = "Highlight";
//default line weights
int lgNumber = Preferences::lineGroup();
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
double weight = lg->getWeight("Thick");
double weight = TechDraw::LineGroup::getDefaultWidth("Thick");
ADD_PROPERTY_TYPE(LineWidth,(weight),group,App::Prop_None,"The thickness of visible lines (line groups xx.2");
weight = lg->getWeight("Thin");
weight = TechDraw::LineGroup::getDefaultWidth("Thin");
ADD_PROPERTY_TYPE(HiddenWidth,(weight),group,App::Prop_None,"The thickness of hidden lines, if enabled (line groups xx.1)");
weight = lg->getWeight("Graphic");
weight = TechDraw::LineGroup::getDefaultWidth("Graphic");
ADD_PROPERTY_TYPE(IsoWidth,(weight),group,App::Prop_None,"The thickness of isoparameter lines, if enabled");
weight = lg->getWeight("Extra");
weight = TechDraw::LineGroup::getDefaultWidth("Extra");
ADD_PROPERTY_TYPE(ExtraWidth,(weight),group,App::Prop_None,"The thickness of LineGroup Extra lines, if enabled");
delete lg; //Coverity CID 174664
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");