Remove magic number and hard type enums in ArrowPropEnum.h
- Remove currently present magic numbers - Hard type enums, so magic numbers can no longer be introduced. We don't want people to introduce magic numbers.
This commit is contained in:
@@ -34,14 +34,16 @@ namespace TechDraw
|
||||
{
|
||||
|
||||
//common definitions for line ends / arrows
|
||||
enum ArrowType { FILLED_ARROW = 0,
|
||||
OPEN_ARROW,
|
||||
TICK,
|
||||
DOT,
|
||||
OPEN_CIRCLE,
|
||||
FORK,
|
||||
FILLED_TRIANGLE,
|
||||
NONE};
|
||||
enum class ArrowType : int {
|
||||
FILLED_ARROW = 0,
|
||||
OPEN_ARROW,
|
||||
TICK,
|
||||
DOT,
|
||||
OPEN_CIRCLE,
|
||||
FORK,
|
||||
FILLED_TRIANGLE,
|
||||
NONE
|
||||
};
|
||||
|
||||
class TechDrawExport ArrowPropEnum {
|
||||
Q_DECLARE_TR_FUNCTIONS(TechDraw::ArrowPropEnum)
|
||||
|
||||
@@ -70,7 +70,7 @@ DrawViewBalloon::DrawViewBalloon()
|
||||
ADD_PROPERTY_TYPE(OriginY, (0), "", (App::PropertyType)(App::Prop_None), "Balloon origin y");
|
||||
|
||||
EndType.setEnums(ArrowPropEnum::ArrowTypeEnums);
|
||||
ADD_PROPERTY_TYPE(EndType, (Preferences::balloonArrow()), "", (App::PropertyType)(App::Prop_None),
|
||||
ADD_PROPERTY_TYPE(EndType, (static_cast<int>(Preferences::balloonArrow())), "", (App::PropertyType)(App::Prop_None),
|
||||
"End symbol for the balloon line");
|
||||
|
||||
ADD_PROPERTY_TYPE(EndTypeScale, (1.0), "", (App::PropertyType)(App::Prop_None),
|
||||
|
||||
@@ -176,9 +176,10 @@ int Preferences::lineGroup()
|
||||
return getPreferenceGroup("Decorations")->GetInt("LineGroup", 3); // FC 0.70mm
|
||||
}
|
||||
|
||||
int Preferences::balloonArrow()
|
||||
ArrowType Preferences::balloonArrow()
|
||||
{
|
||||
return getPreferenceGroup("Decorations")->GetInt("BalloonArrow", 0);
|
||||
int temp = getPreferenceGroup("Decorations")->GetInt("BalloonArrow", 0);
|
||||
return static_cast<ArrowType>(temp);
|
||||
}
|
||||
|
||||
double Preferences::balloonKinkLength()
|
||||
|
||||
@@ -41,6 +41,7 @@ class Color;
|
||||
|
||||
namespace TechDraw
|
||||
{
|
||||
enum class ArrowType : int;
|
||||
|
||||
//getters for parameters used in multiple places.
|
||||
class TechDrawExport Preferences
|
||||
@@ -70,7 +71,7 @@ public:
|
||||
static double groupSpaceX();
|
||||
static double groupSpaceY();
|
||||
|
||||
static int balloonArrow();
|
||||
static ArrowType balloonArrow();
|
||||
static double balloonKinkLength();
|
||||
static int balloonShape();
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ void DlgPrefsTechDrawAnnotationImp::loadSettings()
|
||||
|
||||
ui->pcbBalloonArrow->onRestore();
|
||||
DrawGuiUtil::loadArrowBox(ui->pcbBalloonArrow);
|
||||
ui->pcbBalloonArrow->setCurrentIndex(prefBalloonArrow());
|
||||
ui->pcbBalloonArrow->setCurrentIndex(static_cast<int>(prefBalloonArrow()));
|
||||
|
||||
ui->cbEndCap->onRestore();
|
||||
|
||||
@@ -207,7 +207,7 @@ void DlgPrefsTechDrawAnnotationImp::changeEvent(QEvent *e)
|
||||
}
|
||||
}
|
||||
|
||||
int DlgPrefsTechDrawAnnotationImp::prefBalloonArrow() const
|
||||
TechDraw::ArrowType DlgPrefsTechDrawAnnotationImp::prefBalloonArrow() const
|
||||
{
|
||||
return Preferences::balloonArrow();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
namespace TechDraw {
|
||||
class LineGenerator;
|
||||
enum class ArrowType : int;
|
||||
}
|
||||
|
||||
namespace TechDrawGui {
|
||||
@@ -53,7 +54,7 @@ protected:
|
||||
void loadSettings() override;
|
||||
void changeEvent(QEvent *e) override;
|
||||
|
||||
int prefBalloonArrow() const;
|
||||
TechDraw::ArrowType prefBalloonArrow() const;
|
||||
int prefBalloonShape() const;
|
||||
int prefMattingStyle() const;
|
||||
void loadLineStyleBoxes();
|
||||
|
||||
@@ -147,7 +147,7 @@ void DlgPrefsTechDrawDimensionsImp::loadSettings()
|
||||
ui->plsb_ArrowSize->onRestore();
|
||||
|
||||
DrawGuiUtil::loadArrowBox(ui->pcbArrow);
|
||||
ui->pcbArrow->setCurrentIndex(prefArrowStyle());
|
||||
ui->pcbArrow->setCurrentIndex(static_cast<int>(prefArrowStyle()));
|
||||
|
||||
ui->leFormatSpec->setText(QString::fromStdString(Preferences::formatSpec()));
|
||||
ui->leFormatSpec->onRestore();
|
||||
@@ -225,7 +225,7 @@ void DlgPrefsTechDrawDimensionsImp::resetSettingsToDefaults()
|
||||
PreferencePage::resetSettingsToDefaults();
|
||||
}
|
||||
|
||||
int DlgPrefsTechDrawDimensionsImp::prefArrowStyle() const
|
||||
TechDraw::ArrowType DlgPrefsTechDrawDimensionsImp::prefArrowStyle() const
|
||||
{
|
||||
return PreferencesGui::dimArrowStyle();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
|
||||
namespace TechDraw {
|
||||
enum class ArrowType : int;
|
||||
}
|
||||
|
||||
namespace TechDrawGui {
|
||||
class Ui_DlgPrefsTechDrawDimensionsImp;
|
||||
|
||||
@@ -48,7 +52,7 @@ protected:
|
||||
void changeEvent(QEvent *e) override;
|
||||
void dimensioningModeChanged(int index);
|
||||
|
||||
int prefArrowStyle() const;
|
||||
TechDraw::ArrowType prefArrowStyle() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_DlgPrefsTechDrawDimensionsImp> ui;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Gui/Selection/Selection.h>
|
||||
#include <Mod/TechDraw/App/ArrowPropEnum.h>
|
||||
#include <Mod/TechDraw/App/Preferences.h>
|
||||
#include <Mod/TechDraw/App/LineGenerator.h>
|
||||
|
||||
@@ -156,9 +157,10 @@ QColor PreferencesGui::leaderQColor()
|
||||
return fcColor.asValue<QColor>();
|
||||
}
|
||||
|
||||
int PreferencesGui::dimArrowStyle()
|
||||
ArrowType PreferencesGui::dimArrowStyle()
|
||||
{
|
||||
return Preferences::getPreferenceGroup("Dimensions")->GetInt("ArrowStyle", 0);
|
||||
int temp = Preferences::getPreferenceGroup("Dimensions")->GetInt("ArrowStyle", 0);
|
||||
return static_cast<ArrowType>(temp);
|
||||
}
|
||||
|
||||
double PreferencesGui::dimArrowSize()
|
||||
|
||||
@@ -40,6 +40,10 @@ class QString;
|
||||
|
||||
#include <Mod/TechDraw/App/Preferences.h>
|
||||
|
||||
namespace TechDraw{
|
||||
enum class ArrowType : int;
|
||||
}
|
||||
|
||||
namespace TechDrawGui
|
||||
{
|
||||
|
||||
@@ -68,7 +72,7 @@ static QColor pageQColor();
|
||||
static App::Color breaklineColor();
|
||||
static QColor breaklineQColor();
|
||||
|
||||
static int dimArrowStyle();
|
||||
static TechDraw::ArrowType dimArrowStyle();
|
||||
static double dimArrowSize();
|
||||
|
||||
static double edgeFuzz();
|
||||
|
||||
@@ -39,7 +39,7 @@ using namespace TechDraw;
|
||||
QGIArrow::QGIArrow() :
|
||||
m_fill(Qt::SolidPattern),
|
||||
m_size(getPrefArrowSize()),
|
||||
m_style(0),
|
||||
m_style(ArrowType::FILLED_ARROW),
|
||||
m_dirMode(false),
|
||||
m_dir(Base::Vector3d(1.0, 0.0, 0.0))
|
||||
{
|
||||
@@ -300,7 +300,7 @@ QPainterPath QGIArrow::makePyramid(Base::Vector3d dir, double length)
|
||||
return path;
|
||||
}
|
||||
|
||||
int QGIArrow::getPrefArrowStyle()
|
||||
ArrowType QGIArrow::getPrefArrowStyle()
|
||||
{
|
||||
return PreferencesGui::dimArrowStyle();
|
||||
}
|
||||
@@ -310,7 +310,7 @@ double QGIArrow::getPrefArrowSize()
|
||||
return PreferencesGui::dimArrowSize();
|
||||
}
|
||||
|
||||
double QGIArrow::getOverlapAdjust(int style, double size)
|
||||
double QGIArrow::getOverlapAdjust(ArrowType style, double size)
|
||||
{
|
||||
// adjustment required depends on arrow size and type! :(
|
||||
// ex for fork and tick, adjustment sb zero. 0.25 is good for filled triangle, 0.1 for open arrow.
|
||||
@@ -318,22 +318,22 @@ double QGIArrow::getOverlapAdjust(int style, double size)
|
||||
// NOTE: this may need to be adjusted to account for line thickness too.
|
||||
// Base::Console().Message("QGIA::getOverlapAdjust(%d, %.3f) \n", style, size);
|
||||
switch(style) {
|
||||
case FILLED_ARROW:
|
||||
case ArrowType::FILLED_ARROW:
|
||||
return 0.50 * size;
|
||||
case OPEN_ARROW:
|
||||
case ArrowType::OPEN_ARROW:
|
||||
return 0.10 * size;
|
||||
case TICK:
|
||||
case ArrowType::TICK:
|
||||
return 0.0;
|
||||
case DOT:
|
||||
case ArrowType::DOT:
|
||||
return 0.0;
|
||||
case OPEN_CIRCLE:
|
||||
case ArrowType::OPEN_CIRCLE:
|
||||
//diameter is size/2 so radius is size/4
|
||||
return 0.25 * size;
|
||||
case FORK:
|
||||
case ArrowType::FORK:
|
||||
return 0.0;
|
||||
case FILLED_TRIANGLE:
|
||||
case ArrowType::FILLED_TRIANGLE:
|
||||
return size;
|
||||
case NONE:
|
||||
case ArrowType::NONE:
|
||||
return 0.0;
|
||||
}
|
||||
return 1.0; // Unknown
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#define DRAWINGGUI_QGRAPHICSITEMARROW_H
|
||||
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
#include <Mod/TechDraw/App/ArrowPropEnum.h>
|
||||
|
||||
#include <Base/Vector3D.h>
|
||||
|
||||
@@ -37,17 +38,6 @@ QT_END_NAMESPACE
|
||||
namespace TechDrawGui
|
||||
{
|
||||
|
||||
/*enum ArrowType {*/
|
||||
/* FILLED_TRIANGLE = 0, */
|
||||
/* OPEN_ARROW, */
|
||||
/* HASH_MARK, */
|
||||
/* DOT, */
|
||||
/* OPEN_CIRCLE, */
|
||||
/* FORK, */
|
||||
/* PYRAMID, */
|
||||
/* NONE*/
|
||||
/*};*/
|
||||
|
||||
class TechDrawGuiExport QGIArrow : public QGIPrimPath
|
||||
{
|
||||
public:
|
||||
@@ -64,16 +54,16 @@ public:
|
||||
void flip() { m_flipped = !m_flipped; }
|
||||
double getSize() { return m_size; }
|
||||
void setSize(double s);
|
||||
int getStyle() { return m_style; }
|
||||
void setStyle(int s) { m_style = s; }
|
||||
TechDraw::ArrowType getStyle() { return m_style; }
|
||||
void setStyle(TechDraw::ArrowType s) { m_style = s; }
|
||||
bool getDirMode() { return m_dirMode; }
|
||||
void setDirMode(bool b) { m_dirMode = b; }
|
||||
Base::Vector3d getDirection(void) { return m_flipped ? -m_dir : m_dir; }
|
||||
void setDirection(Base::Vector3d v) { m_dir = v; }
|
||||
void setDirection(double angle) { m_dir = Base::Vector3d(cos(angle), sin(angle), 0.0); }
|
||||
static int getPrefArrowStyle();
|
||||
static TechDraw::ArrowType getPrefArrowStyle();
|
||||
static double getPrefArrowSize();
|
||||
static double getOverlapAdjust(int style, double size);
|
||||
static double getOverlapAdjust(TechDraw::ArrowType style, double size);
|
||||
|
||||
protected:
|
||||
QPainterPath makeFilledTriangle(double length, double width, bool flipped);
|
||||
@@ -93,7 +83,7 @@ private:
|
||||
QBrush m_brush;
|
||||
Qt::BrushStyle m_fill;
|
||||
double m_size;
|
||||
int m_style;
|
||||
TechDraw::ArrowType m_style;
|
||||
bool m_flipped;
|
||||
bool m_dirMode;
|
||||
Base::Vector3d m_dir;
|
||||
|
||||
@@ -426,12 +426,14 @@ QPainterPath QGILeaderLine::makeLeaderPath(std::vector<QPointF> qPoints)
|
||||
double endAdjLength(0.0);
|
||||
if (qPoints.size() > 1) {
|
||||
//make path adjustment to hide leaderline ends behind arrowheads
|
||||
if (featLeader->StartSymbol.getValue() != ArrowType::NONE) {
|
||||
startAdjLength = QGIArrow::getOverlapAdjust(featLeader->StartSymbol.getValue(),
|
||||
ArrowType choice = static_cast<ArrowType>(featLeader->StartSymbol.getValue());
|
||||
if (choice != ArrowType::NONE) {
|
||||
startAdjLength = QGIArrow::getOverlapAdjust(choice,
|
||||
QGIArrow::getPrefArrowSize());
|
||||
}
|
||||
if (featLeader->EndSymbol.getValue() != ArrowType::NONE) {
|
||||
endAdjLength = QGIArrow::getOverlapAdjust(featLeader->EndSymbol.getValue(),
|
||||
choice = static_cast<ArrowType>(featLeader->EndSymbol.getValue());
|
||||
if (choice != ArrowType::NONE) {
|
||||
endAdjLength = QGIArrow::getOverlapAdjust(choice,
|
||||
QGIArrow::getPrefArrowSize());
|
||||
}
|
||||
|
||||
@@ -515,8 +517,9 @@ void QGILeaderLine::setArrows(std::vector<QPointF> pathPoints)
|
||||
|
||||
QPointF lastOffset = (pathPoints.back() - pathPoints.front());
|
||||
|
||||
if (featLeader->StartSymbol.getValue() != ArrowType::NONE) {
|
||||
m_arrow1->setStyle(featLeader->StartSymbol.getValue());
|
||||
ArrowType choice = static_cast<ArrowType>(featLeader->StartSymbol.getValue());
|
||||
if (choice != ArrowType::NONE) {
|
||||
m_arrow1->setStyle(choice);
|
||||
m_arrow1->setWidth(getLineWidth());
|
||||
m_arrow1->setSize(QGIArrow::getPrefArrowSize());
|
||||
m_arrow1->setDirMode(true);
|
||||
@@ -537,8 +540,9 @@ void QGILeaderLine::setArrows(std::vector<QPointF> pathPoints)
|
||||
m_arrow1->hide();
|
||||
}
|
||||
|
||||
if (featLeader->EndSymbol.getValue() != ArrowType::NONE) {
|
||||
m_arrow2->setStyle(featLeader->EndSymbol.getValue());
|
||||
choice = static_cast<ArrowType>(featLeader->EndSymbol.getValue());
|
||||
if (choice != ArrowType::NONE) {
|
||||
m_arrow2->setStyle(choice);
|
||||
m_arrow2->setWidth(getLineWidth());
|
||||
m_arrow2->setSize(QGIArrow::getPrefArrowSize());
|
||||
m_arrow2->setDirMode(true);
|
||||
|
||||
@@ -141,10 +141,10 @@ void QGISectionLine::makeArrows()
|
||||
//make Euro (ISO) Arrows
|
||||
void QGISectionLine::makeArrowsISO()
|
||||
{
|
||||
m_arrow1->setStyle(0);
|
||||
m_arrow1->setStyle(ArrowType::FILLED_ARROW);
|
||||
m_arrow1->setSize(QGIArrow::getPrefArrowSize());
|
||||
m_arrow1->setPos(m_start);
|
||||
m_arrow2->setStyle(0);
|
||||
m_arrow2->setStyle(ArrowType::FILLED_ARROW);
|
||||
m_arrow2->setSize(QGIArrow::getPrefArrowSize());
|
||||
m_arrow2->setPos(m_end);
|
||||
|
||||
@@ -165,9 +165,9 @@ void QGISectionLine::makeArrowsISO()
|
||||
//make traditional (ASME) section arrows
|
||||
void QGISectionLine::makeArrowsTrad()
|
||||
{
|
||||
m_arrow1->setStyle(0);
|
||||
m_arrow1->setStyle(ArrowType::FILLED_ARROW);
|
||||
m_arrow1->setSize(QGIArrow::getPrefArrowSize());
|
||||
m_arrow2->setStyle(0);
|
||||
m_arrow2->setStyle(ArrowType::FILLED_ARROW);
|
||||
m_arrow2->setSize(QGIArrow::getPrefArrowSize());
|
||||
|
||||
if (m_arrowMode == SINGLEDIRECTIONMODE) {
|
||||
|
||||
@@ -785,7 +785,7 @@ void QGIViewBalloon::drawBalloon(bool originDrag)
|
||||
|
||||
double xAdj = 0.0;
|
||||
double yAdj = 0.0;
|
||||
int endType = balloon->EndType.getValue();
|
||||
ArrowType endType = static_cast<ArrowType>(balloon->EndType.getValue());
|
||||
double arrowAdj = QGIArrow::getOverlapAdjust(
|
||||
endType, balloon->EndTypeScale.getValue() * QGIArrow::getPrefArrowSize());
|
||||
|
||||
@@ -955,8 +955,9 @@ QColor QGIViewBalloon::prefNormalColor()
|
||||
return getNormalColor();
|
||||
}
|
||||
|
||||
int QGIViewBalloon::prefDefaultArrow() const { return Preferences::balloonArrow(); }
|
||||
|
||||
ArrowType QGIViewBalloon::prefDefaultArrow() const {
|
||||
return Preferences::balloonArrow();
|
||||
}
|
||||
|
||||
//should this be an object property or global preference?
|
||||
//when would you want a crooked pyramid?
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace TechDraw
|
||||
{
|
||||
class DrawViewBalloon;
|
||||
class DrawView;
|
||||
enum class ArrowType : int;
|
||||
}// namespace TechDraw
|
||||
|
||||
namespace TechDraw
|
||||
@@ -203,7 +204,7 @@ public:
|
||||
|
||||
void setNormalColorAll();
|
||||
QColor prefNormalColor();
|
||||
int prefDefaultArrow() const;
|
||||
TechDraw::ArrowType prefDefaultArrow() const;
|
||||
bool prefOrthoPyramid() const;
|
||||
|
||||
TechDraw::DrawViewBalloon* getBalloonFeat()
|
||||
|
||||
@@ -927,7 +927,7 @@ void QGIViewDimension::drawArrows(int count, const Base::Vector2d positions[], d
|
||||
arrow->setSize(arrowSize);
|
||||
arrow->setFlipped(flipped);
|
||||
|
||||
if (vp->ArrowStyle.getValue() != ArrowType::NONE) {
|
||||
if (vp->ArrowStyle.getValue() != static_cast<int>(ArrowType::NONE)) {
|
||||
arrow->draw();
|
||||
arrow->show();
|
||||
}
|
||||
|
||||
@@ -233,11 +233,11 @@ void TaskLeaderLine::setUiPrimary()
|
||||
}
|
||||
|
||||
DrawGuiUtil::loadArrowBox(ui->cboxStartSym);
|
||||
int aStyle = PreferencesGui::dimArrowStyle();
|
||||
ui->cboxStartSym->setCurrentIndex(aStyle);
|
||||
ArrowType aStyle = PreferencesGui::dimArrowStyle();
|
||||
ui->cboxStartSym->setCurrentIndex(static_cast<int>(aStyle));
|
||||
|
||||
DrawGuiUtil::loadArrowBox(ui->cboxEndSym);
|
||||
ui->cboxEndSym->setCurrentIndex(TechDraw::ArrowType::NONE);
|
||||
ui->cboxEndSym->setCurrentIndex(static_cast<int>(TechDraw::ArrowType::NONE));
|
||||
|
||||
ui->dsbWeight->setUnit(Base::Unit::Length);
|
||||
ui->dsbWeight->setMinimum(0);
|
||||
|
||||
@@ -85,7 +85,7 @@ ViewProviderDimension::ViewProviderDimension()
|
||||
"Arrow size in units");
|
||||
|
||||
ArrowStyle.setEnums(ArrowPropEnum::ArrowTypeEnums); // NOLINT
|
||||
ADD_PROPERTY_TYPE(ArrowStyle, (PreferencesGui::dimArrowStyle()),
|
||||
ADD_PROPERTY_TYPE(ArrowStyle, (static_cast<int>(PreferencesGui::dimArrowStyle())),
|
||||
group, (App::PropertyType)(App::Prop_None),
|
||||
"Arrow end symbol - point, filled arrow, etc");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user