TechDraw: remove unneeded state from QGIFace

This commit is contained in:
Benjamin Bræstrup Sayoc
2025-02-23 00:09:56 +01:00
parent 6cb6757908
commit 32da822741
4 changed files with 31 additions and 67 deletions

View File

@@ -56,7 +56,6 @@ using namespace TechDraw;
using DU = DrawUtil;
QGIFace::QGIFace(int index) :
m_hideSvgTiles(false),
projIndex(index),
m_hatchRotation(0.0)
{
@@ -65,8 +64,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));
setLineWeight(0.0); //0 = cosmetic
m_texture = QPixmap(); //empty texture
@@ -85,6 +82,9 @@ QGIFace::QGIFace(int index) :
m_sharedRender = new QSvgRenderer();
m_patMaker = new PATPathMaker(this, 1.0, 1.0);
setHatchColor(PreferencesGui::getAccessibleQColor(QColor(Qt::black)));
m_patMaker->setLineWidth(0.5);
setLineWeight(0.0); //0 = cosmetic
}
QGIFace::~QGIFace()
@@ -105,7 +105,6 @@ QColor QGIFace::getDefaultFillColor()
void QGIFace::draw()
{
// Base::Console().Message("QGIF::draw - pen style: %d\n", m_pen.style());
setPath(m_outline); //Face boundary
m_svgHatchArea->hide();
m_imageSvgHatchArea->hide();
@@ -226,14 +225,13 @@ void QGIFace::setFillMode(FillMode mode)
/// update the outline of this face
void QGIFace::setOutline(const QPainterPath & path)
{
m_outline = path;
setPath(path);
}
/// remove the PAT hatch lines
void QGIFace::clearLineSets()
{
m_dashSpecs.clear();
clearFillItems();
return;
}
/// add PAT hatch line set
@@ -245,7 +243,6 @@ void QGIFace::addLineSet(LineSet& ls)
/// convert the PAT line set to QGraphicsPathItems
void QGIFace::lineSetToFillItems(LineSet& ls)
{
m_patMaker->setLineWidth(Rez::guiX(m_geomWeight));
m_patMaker->setScale(m_fillScale);
m_patMaker->setPen(setGeomPen());
m_patMaker->lineSetToFillItems(ls);
@@ -254,8 +251,6 @@ void QGIFace::lineSetToFillItems(LineSet& ls)
QPen QGIFace::setGeomPen()
{
QPen result;
result.setWidthF(Rez::guiX(m_geomWeight));
result.setColor(m_geomColor);
result.setStyle(Qt::SolidLine);
return result;
}
@@ -278,16 +273,6 @@ double QGIFace::getXForm()
return 1.0;
}
/// remove the children that make up a PAT fill
void QGIFace::clearFillItems()
{
for (auto& fill: m_fillItems) {
fill->setParentItem(nullptr);
this->scene()->removeItem(fill);
delete fill;
}
}
/// debugging tool draws a mark at a position on this face
void QGIFace::makeMark(double x, double y) // NOLINT readability-identifier-length
{
@@ -305,10 +290,10 @@ void QGIFace::buildSvgHatch()
// Base::Console().Message("QGIF::buildSvgHatch() - offset: %s\n", DrawUtil::formatVector(getHatchOffset()).c_str());
double wTile = SVGSIZEW * m_fillScale;
double hTile = SVGSIZEH * m_fillScale;
double faceWidth = m_outline.boundingRect().width();
double faceHeight = m_outline.boundingRect().height();
double faceWidth = path().boundingRect().width();
double faceHeight = path().boundingRect().height();
double faceOverlaySize = Preferences::svgHatchFactor() * std::max(faceWidth, faceHeight);
QPointF faceCenter = m_outline.boundingRect().center();
QPointF faceCenter = path().boundingRect().center();
double tilesWide = ceil(faceOverlaySize / wTile);
double tilesHigh = ceil(faceOverlaySize / hTile);
@@ -348,21 +333,16 @@ void QGIFace::buildSvgHatch()
m_svgHatchArea->setRotation(m_hatchRotation);
}
void QGIFace::clearSvg()
{
hideSvg(true);
}
//! similar to svg hatch, but using pixmaps. we do this because QGraphicsSvgItems are not clipped
//! when we export the scene to svg, but pixmaps are clipped.
void QGIFace::buildPixHatch()
{
double wTile = SVGSIZEW * m_fillScale;
double hTile = SVGSIZEH * m_fillScale;
double faceWidth = m_outline.boundingRect().width();
double faceHeight = m_outline.boundingRect().height();
double faceWidth = path().boundingRect().width();
double faceHeight = path().boundingRect().height();
double faceOverlaySize = Preferences::svgHatchFactor() * std::max(faceWidth, faceHeight);
QPointF faceCenter = m_outline.boundingRect().center();
QPointF faceCenter = path().boundingRect().center();
double tilesWide = ceil(faceOverlaySize / wTile);
double tilesHigh = ceil(faceOverlaySize / hTile);
@@ -452,7 +432,15 @@ void QGIFace::buildPixHatch()
void QGIFace::setHatchColor(Base::Color color)
{
m_svgCol = color.asHexString();
m_geomColor = color.asValue<QColor>();
QPen p = m_patMaker->getPen();
p.setColor(color.asValue<QColor>());
m_patMaker->setPen(p);
}
void QGIFace::setHatchColor(QColor color)
{
setHatchColor(Base::Color::fromValue(color));
}
void QGIFace::setHatchScale(double scale)
@@ -460,16 +448,6 @@ void QGIFace::setHatchScale(double scale)
m_fillScale = scale;
}
/// turn svg tiles on or off. QtSvg does not handle clipping,
/// so we must be able to turn the hatching on/off when exporting a face with an
/// svg hatch. Otherwise the full tile pattern is shown in the export.
/// NOTE: there appears to have been a change in Qt that it now clips svg items
void QGIFace::hideSvg(bool state)
{
m_hideSvgTiles = state;
}
/// create a QPixmap from a bitmap file. The QPixmap will be used as a QBrush
/// texture.
QPixmap QGIFace::textureFromBitmap(std::string fileSpec) const
@@ -492,13 +470,13 @@ QPixmap QGIFace::textureFromBitmap(std::string fileSpec) const
return pix;
}
void QGIFace::setLineWeight(double weight) {
m_geomWeight = weight;
void QGIFace::setLineWeight(double weight)
{
m_patMaker->setLineWidth(Rez::guiX(weight));
}
void QGIFace::getParameters()
{
m_maxSeg = Preferences::getPreferenceGroup("PAT")->GetInt("MaxSeg", MAXSEGMENT);
m_maxTile = Preferences::getPreferenceGroup("Decorations")->GetInt("MaxSVGTile", MAXTILES);
}