TechDraw: remove unneeded state from QGIPrimPath

This commit is contained in:
Benjamin Bræstrup Sayoc
2025-02-23 00:05:30 +01:00
parent ba2a377e7e
commit aead9ac8c7
15 changed files with 79 additions and 145 deletions

View File

@@ -44,6 +44,7 @@ using namespace TechDraw;
PATPathMaker::PATPathMaker(QGraphicsItem* parent, double lineWidth, double fillScale) :
m_parent(parent),
m_pen(),
m_fillScale(fillScale),
m_lineWidth(lineWidth)
{

View File

@@ -46,8 +46,7 @@ QGIArrow::QGIArrow() :
setFlipped(false);
setFillStyle(Qt::SolidPattern);
m_brush.setStyle(m_fill);
m_colDefFill = getNormalColor();
m_colNormalFill = m_colDefFill;
m_colNormalFill = getNormalColor();
setCacheMode(QGraphicsItem::NoCache);
setAcceptHoverEvents(false);

View File

@@ -64,9 +64,7 @@ QGIBreakLine::QGIBreakLine()
setColor(PreferencesGui::sectionLineQColor());
// setFill(Qt::NoBrush);
setFill(Qt::SolidPattern);
m_brush.setStyle(Qt::SolidPattern);
}
void QGIBreakLine::draw()
@@ -253,9 +251,6 @@ void QGIBreakLine::paint ( QPainter * painter, const QStyleOptionGraphicsItem *
void QGIBreakLine::setTools()
{
m_pen.setWidthF(m_width);
m_pen.setColor(m_colCurrent);
m_brush.setStyle(m_brushCurrent);
m_brush.setColor(PreferencesGui::pageQColor());
m_line0->setPen(m_pen);

View File

@@ -42,7 +42,7 @@ using namespace TechDrawGui;
QGICMark::QGICMark(int index) : QGIVertex(index)
{
m_size = 3.0;
m_width = 0.75;
setThick(0.75);
draw();
}
void QGICMark::draw()
@@ -63,7 +63,7 @@ void QGICMark::setSize(float s)
void QGICMark::setThick(float t)
{
m_width = t;
m_pen.setWidthF(t);
draw();
}
@@ -73,7 +73,7 @@ QColor QGICMark::getCMarkColor()
}
void QGICMark::setPrettyNormal() {
m_colCurrent = getCMarkColor();
m_pen.setColor(getCMarkColor());
update();
}

View File

@@ -46,7 +46,7 @@ public:
void draw(void);
float getSize() { return m_size; }
void setSize(float s);
float getThick() { return m_width; }
float getThick() { return m_pen.widthF(); }
void setThick(float t);
void setPrettyNormal() override;

View File

@@ -104,7 +104,7 @@ void QGICenterLine::setIntersection(bool isIntersecting) {
void QGICenterLine::setTools()
{
if (m_styleCurrent == Qt::DashDotLine) {
if (m_pen.style() == Qt::DashDotLine) {
QVector<qreal> dashes;
qreal space = 4; // in unit width
qreal dash = 16;
@@ -116,7 +116,7 @@ void QGICenterLine::setTools()
qreal dashlen = dot + 2 * space + dash;
qreal l_len = sqrt(pow(m_start.x() - m_end.x(), 2) + pow(m_start.y() - m_end.y(), 2)) / 2.0;
// convert from pixelunits to width units
l_len = l_len / m_width;
l_len = l_len / m_pen.widthF();
// note that the additional length using RoundCap or SquareCap does not
// count here!
if (m_isintersection) {
@@ -127,12 +127,7 @@ void QGICenterLine::setTools()
m_pen.setDashPattern(dashes);
}
else {
m_pen.setStyle(m_styleCurrent);
}
m_pen.setCapStyle(Qt::RoundCap);
m_pen.setWidthF(m_width);
m_pen.setColor(m_colCurrent);
m_line->setPen(m_pen);
}

View File

@@ -42,7 +42,8 @@ QGIDimLines::QGIDimLines()
setFlag(QGraphicsItem::ItemIsSelectable, false);
setFlag(QGraphicsItem::ItemIsMovable, false);
m_width = 0.5;
setFill(QColor(100, 100, 0));
setWidth(0.5);
}
void QGIDimLines::draw()

View File

@@ -51,7 +51,7 @@ QGIEdge::QGIEdge(int index) :
setFlag(QGraphicsItem::ItemIsFocusable, true); // to get key press events
setFlag(QGraphicsItem::ItemIsSelectable, true);
m_width = 1.0;
setWidth(1.0);
setCosmetic(isCosmetic);
setFill(Qt::NoBrush);
}
@@ -70,18 +70,18 @@ void QGIEdge::setCosmetic(bool state)
void QGIEdge::setHiddenEdge(bool b) {
isHiddenEdge = b;
if (b) {
m_styleCurrent = getHiddenStyle();
m_pen.setStyle(getHiddenStyle());
} else {
m_styleCurrent = Qt::SolidLine;
m_pen.setStyle(Qt::SolidLine);
}
}
void QGIEdge::setPrettyNormal() {
// Base::Console().Message("QGIE::setPrettyNormal()\n");
if (isHiddenEdge) {
m_colCurrent = getHiddenColor();
m_pen.setColor(getHiddenColor());
} else {
m_colCurrent = getNormalColor();
m_pen.setColor(getNormalColor());
}
//should call QGIPP::setPrettyNormal()?
}
@@ -137,9 +137,3 @@ void QGIEdge::setLinePen(QPen linePen)
{
m_pen = linePen;
}
void QGIEdge::setCurrentPen()
{
m_pen.setWidthF(m_width);
m_pen.setColor(m_colCurrent);
}

View File

@@ -59,8 +59,6 @@ public:
void setSource(TechDraw::SourceType source) { m_source = source; }
TechDraw::SourceType getSource() const { return m_source;}
void setCurrentPen() override;
protected:
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;

View File

@@ -66,8 +66,6 @@ QGIFace::QGIFace(int index) :
setStyle(Qt::NoPen); //don't draw face lines, just fill for debugging
//setStyle(Qt::DashLine);
m_geomColor = PreferencesGui::getAccessibleQColor(QColor(Qt::black));
m_styleCurrent = Qt::NoPen;
m_pen.setStyle(m_styleCurrent);
setLineWeight(0.0); //0 = cosmetic
m_texture = QPixmap(); //empty texture
@@ -79,19 +77,11 @@ QGIFace::QGIFace(int index) :
getParameters();
// set up style & colour defaults
m_colDefFill = Base::Color(static_cast<uint32_t>(Preferences::getPreferenceGroup("Colors")->GetUnsigned("FaceColor", COLWHITE)))
.asValue<QColor>();
m_colDefFill.setAlpha(Preferences::getPreferenceGroup("Colors")->GetBool("ClearFace", false) ? ALPHALOW : ALPHAHIGH);
m_fillDef = Qt::SolidPattern;
m_fillSelect = Qt::SolidPattern;
setFillMode(FillMode::NoFill);
if (m_colDefFill.alpha() > 0) {
if (getDefaultFillColor().alpha() > 0) {
setFillMode(FillMode::PlainFill);
}
setFill(m_colDefFill, m_fillDef);
setFill(getDefaultFillColor(), getDefaultFillStyle());
m_sharedRender = new QSvgRenderer();
m_patMaker = new PATPathMaker(this, 1.0, 1.0);
@@ -103,6 +93,14 @@ QGIFace::~QGIFace()
delete m_patMaker;
}
QColor QGIFace::getDefaultFillColor()
{
QColor color = Base::Color(static_cast<uint32_t>(Preferences::getPreferenceGroup("Colors")->GetUnsigned("FaceColor", COLWHITE)))
.asValue<QColor>();
color.setAlpha(Preferences::getPreferenceGroup("Colors")->GetBool("ClearFace", false) ? ALPHALOW : ALPHAHIGH);
return color;
}
/// redraw this face
void QGIFace::draw()
{
@@ -118,16 +116,16 @@ void QGIFace::draw()
setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
if (!m_lineSets.empty()) {
m_brush.setTexture(QPixmap());
m_fillStyleCurrent = m_fillDef;
m_fillNormal = m_fillStyleCurrent;
m_fillNormal = getDefaultFillStyle();
m_brush.setStyle(m_fillNormal);
for (auto& ls: m_lineSets) {
lineSetToFillItems(ls);
}
}
} else if (m_mode == FillMode::SvgFill) {
m_brush.setTexture(QPixmap());
m_fillNormal = m_fillDef;
m_fillStyleCurrent = m_fillNormal;
m_fillNormal = getDefaultFillStyle();
m_brush.setStyle(m_fillNormal);
setFlag(QGraphicsItem::ItemClipsChildrenToShape,true);
loadSvgHatch(m_fileSpec);
if (exporting()) {
@@ -138,7 +136,7 @@ void QGIFace::draw()
m_svgHatchArea->show();
}
} else if (m_mode == FillMode::BitmapFill) {
m_fillStyleCurrent = Qt::TexturePattern;
m_brush.setStyle(Qt::TexturePattern);
m_texture = textureFromBitmap(m_fileSpec);
m_brush.setTexture(m_texture);
} else if (m_mode == FillMode::PlainFill) {
@@ -154,7 +152,7 @@ void QGIFace::setPrettyNormal() {
// Base::Console().Message("QGIF::setPrettyNormal() - hatched: %d\n", isHatched());
if (isHatched() &&
(m_mode == FillMode::BitmapFill) ) { //hatch with bitmap fill
m_fillStyleCurrent = Qt::TexturePattern;
m_brush.setStyle(Qt::TexturePattern);
m_brush.setTexture(m_texture);
} else {
m_brush.setTexture(QPixmap());
@@ -165,16 +163,14 @@ void QGIFace::setPrettyNormal() {
/// show the face style & colour in pre-select configuration
void QGIFace::setPrettyPre() {
// Base::Console().Message("QGIF::setPrettyPre()\n");
m_fillStyleCurrent = Qt::SolidPattern;
m_brush.setTexture(QPixmap());
m_brush.setStyle(Qt::SolidPattern);
QGIPrimPath::setPrettyPre();
}
/// show the face style & colour in selected configuration
void QGIFace::setPrettySel() {
// Base::Console().Message("QGIF::setPrettySel()\n");
m_fillStyleCurrent = Qt::SolidPattern;
m_brush.setTexture(QPixmap());
m_brush.setStyle(Qt::SolidPattern);
QGIPrimPath::setPrettySel();
}

View File

@@ -82,6 +82,11 @@ public:
void setDrawEdges(bool state);
virtual void setOutline(const QPainterPath& path);
QColor getDefaultFillColor() override;
Qt::BrushStyle getDefaultFillStyle() override {
return Qt::SolidPattern;
}
//shared fill parms
void isHatched(bool state) {m_isHatched = state; }
bool isHatched() {return m_isHatched;}
@@ -123,6 +128,10 @@ public:
void setHatchOffset(Base::Vector3d offset) { m_hatchOffset = offset; }
Base::Vector3d getHatchOffset() { return m_hatchOffset; }
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) override {
QGIPrimPath::paint(painter, option, widget);
}
protected:
void makeMark(double x, double y); // NOLINT readability-identifier-length
double getXForm();

View File

@@ -188,16 +188,10 @@ void QGIHighlight::paint ( QPainter * painter, const QStyleOptionGraphicsItem *
void QGIHighlight::setTools()
{
m_pen.setWidthF(m_width);
m_pen.setColor(m_colCurrent);
m_brush.setStyle(m_brushCurrent);
m_brush.setColor(m_colCurrent);
m_circle->setPen(m_pen);
m_rect->setPen(m_pen);
m_reference->setDefaultTextColor(m_colCurrent);
m_reference->setDefaultTextColor(m_pen.color());
}
void QGIHighlight::setLinePen(QPen isoPen)

View File

@@ -47,10 +47,7 @@ using namespace TechDraw;
using DGU = DrawGuiUtil;
QGIPrimPath::QGIPrimPath():
m_width(0),
m_capStyle(Qt::RoundCap),
m_fillStyleCurrent (Qt::NoBrush),
m_fillOverride(false)
m_brush(Qt::NoBrush)
{
setCacheMode(QGraphicsItem::NoCache);
setFlag(QGraphicsItem::ItemIsSelectable, true);
@@ -61,26 +58,19 @@ QGIPrimPath::QGIPrimPath():
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setAcceptHoverEvents(true);
isHighlighted = false;
multiselectActivated = false;
m_colOverride = false;
m_colNormal = getNormalColor();
m_colCurrent = m_colNormal;
m_pen.setColor(m_colNormal);
m_styleNormal = Qt::SolidLine;
m_styleCurrent = m_styleNormal;
m_pen.setStyle(m_styleCurrent);
m_capStyle = prefCapStyle();
m_pen.setCapStyle(m_capStyle);
m_pen.setWidthF(m_width);
m_pen.setStyle(m_styleNormal);
m_pen.setCapStyle(prefCapStyle());
m_pen.setWidthF(0);
m_fillDef = Qt::NoBrush;
m_fillSelect = Qt::SolidPattern;
m_fillNormal = m_fillDef;
m_fillStyleCurrent = m_fillNormal;
m_fillNormal = getDefaultFillStyle();
m_brush.setStyle(m_fillNormal);
m_colDefFill = Qt::white;
setFillColor(m_colDefFill);
setFillColor(getDefaultFillColor());
setPrettyNormal();
}
@@ -119,22 +109,18 @@ void QGIPrimPath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void QGIPrimPath::setPrettyNormal() {
m_colCurrent = m_colNormal;
m_fillColorCurrent = m_colNormalFill;
m_pen.setColor(m_colNormal);
m_brush.setColor(m_colNormalFill);
}
void QGIPrimPath::setPrettyPre() {
m_colCurrent = getPreColor();
if (!m_fillOverride) {
m_fillColorCurrent = getPreColor();
}
m_pen.setColor(getPreColor());
m_brush.setColor(getPreColor());
}
void QGIPrimPath::setPrettySel() {
m_colCurrent = getSelectColor();
if (!m_fillOverride) {
m_fillColorCurrent = getSelectColor();
}
m_pen.setColor(getSelectColor());
m_brush.setColor(getSelectColor());
}
//wf: why would a face use its parent's normal colour?
@@ -142,11 +128,6 @@ void QGIPrimPath::setPrettySel() {
QColor QGIPrimPath::getNormalColor()
{
QGIView *parent;
if (m_colOverride) {
return m_colNormal;
}
QGraphicsItem* qparent = parentItem();
if (!qparent) {
parent = nullptr;
@@ -195,8 +176,7 @@ QColor QGIPrimPath::getSelectColor()
void QGIPrimPath::setWidth(double w)
{
// Base::Console().Message("QGIPP::setWidth(%.3f)\n", w);
m_width = w;
m_pen.setWidthF(m_width);
m_pen.setWidthF(w);
}
void QGIPrimPath::setStyle(Qt::PenStyle s)
@@ -204,27 +184,25 @@ void QGIPrimPath::setStyle(Qt::PenStyle s)
// TODO: edge lines for faces are drawn with setStyle(Qt::NoPen) and trigger this message.
// Base::Console().Warning("QGIPP::setStyle(Qt: %d) is deprecated. Use setLinePen instead\n", s);
m_styleNormal = s;
m_styleCurrent = s;
m_pen.setStyle(s);
}
void QGIPrimPath::setStyle(int s)
{
// TODO: edge lines for faces are drawn with setStyle(Qt::NoPen) and trigger this message.
// Base::Console().Warning("QGIPP::setStyle(int: %d) is deprecated. Use setLinePen instead\n", s);
m_styleCurrent = static_cast<Qt::PenStyle>(s);
m_styleNormal = static_cast<Qt::PenStyle>(s);
m_pen.setStyle(m_styleNormal);
}
void QGIPrimPath::setNormalColor(QColor c)
{
m_colNormal = c;
m_colOverride = true;
m_colCurrent = m_colNormal;
m_pen.setColor(m_colNormal);
}
void QGIPrimPath::setCapStyle(Qt::PenCapStyle c)
{
m_capStyle = c;
m_pen.setCapStyle(c);
}
@@ -286,44 +264,32 @@ void QGIPrimPath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void QGIPrimPath::setFill(QColor c, Qt::BrushStyle s) {
setFillColor(c);
m_fillNormal = s;
m_fillStyleCurrent = s;
m_brush.setStyle(s);
}
void QGIPrimPath::setFill(QBrush b) {
setFillColor(b.color());
m_fillNormal = b.style();
m_fillStyleCurrent = b.style();
setFillColor(b.color());
m_brush.setStyle(b.style());
}
void QGIPrimPath::resetFill() {
m_colNormalFill = m_colDefFill;
m_fillNormal = m_fillDef;
m_fillStyleCurrent = m_fillDef;
m_colNormalFill = getDefaultFillColor();
m_fillNormal = getDefaultFillStyle();
m_brush.setStyle(m_fillNormal);
}
//set PlainFill
void QGIPrimPath::setFillColor(QColor c)
{
m_colNormalFill = c;
m_fillColorCurrent = m_colNormalFill;
}
void QGIPrimPath::setCurrentPen()
{
m_pen.setWidthF(m_width);
m_pen.setColor(m_colCurrent);
m_pen.setStyle(m_styleCurrent);
}
void QGIPrimPath::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
setCurrentPen();
setPen(m_pen);
m_brush.setColor(m_fillColorCurrent);
m_brush.setStyle(m_fillStyleCurrent);
setBrush(m_brush);
QGraphicsPathItem::paint (painter, &myOption, widget);

View File

@@ -55,25 +55,22 @@ public:
virtual void setPrettyPre();
virtual void setPrettySel();
virtual void setWidth(double w);
virtual double getWidth() { return m_width;}
Qt::PenStyle getStyle() { return m_styleCurrent; }
virtual double getWidth() { return m_pen.widthF();}
Qt::PenStyle getStyle() { return m_pen.style(); }
void setStyle(Qt::PenStyle s);
void setStyle(int s);
virtual void setNormalColor(QColor c);
virtual void setCapStyle(Qt::PenCapStyle c);
//plain color fill parms
void setFillStyle(Qt::BrushStyle f) { m_fillStyleCurrent = f; }
Qt::BrushStyle getFillStyle() { return m_fillStyleCurrent; }
void setFillStyle(Qt::BrushStyle f) { m_brush.setStyle(f); }
Qt::BrushStyle getFillStyle() { return m_brush.style(); }
void setFill(QColor c, Qt::BrushStyle s);
void setFill(QBrush b);
void resetFill();
void setFillColor(QColor c);
QColor getFillColor() { return m_colDefFill; }
void setFillOverride(bool b) { m_fillOverride = b; }
virtual void setCurrentPen();
QColor getFillColor() { return getDefaultFillColor(); }
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
@@ -88,32 +85,25 @@ protected:
virtual QColor getNormalColor();
virtual QColor getPreColor();
virtual QColor getSelectColor();
virtual QColor getDefaultFillColor() {
return Qt::white;
}
virtual Qt::BrushStyle getDefaultFillStyle() {
return Qt::NoBrush;
}
Base::Reference<ParameterGrp> getParmGroup();
virtual Qt::PenCapStyle prefCapStyle();
bool isHighlighted;
bool multiselectActivated;
QPen m_pen;
QColor m_colCurrent;
QColor m_colNormal;
bool m_colOverride;
Qt::PenStyle m_styleCurrent;
Qt::PenStyle m_styleNormal;
double m_width;
Qt::PenCapStyle m_capStyle;
QBrush m_brush;
Qt::BrushStyle m_fillStyleCurrent; //current fill style
QColor m_fillColorCurrent; //current fill color
QColor m_colDefFill; //"no color" default normal fill color
QColor m_colNormalFill; //current Normal fill color def or plain fill
Qt::BrushStyle m_fillDef; //default Normal fill style
Qt::BrushStyle m_fillNormal; //current Normal fill style
Qt::BrushStyle m_fillSelect; //Select/preSelect fill style
bool m_fillOverride;
private:

View File

@@ -267,7 +267,6 @@ QGIViewBalloon::QGIViewBalloon()
addToGroup(balloonShape);
balloonShape->setNormalColor(prefNormalColor());
balloonShape->setFill(Qt::transparent, Qt::SolidPattern);
balloonShape->setFillOverride(true);
balloonShape->setPrettyNormal();
arrow = new QGIArrow();
@@ -863,9 +862,6 @@ void QGIViewBalloon::drawBalloon(bool originDrag)
void QGIViewBalloon::setPrettyPre(void)
{
arrow->setPrettyPre();
//TODO: primPath needs override for fill
//balloonShape->setFillOverride(true); //don't fill with pre or select colours.
// balloonShape->setFill(Qt::white, Qt::NoBrush);
balloonShape->setPrettyPre();
balloonLines->setPrettyPre();
}