Change some int to qreal

Made this change to be more compliant with svg
This commit is contained in:
joshua
2025-06-08 21:40:32 +02:00
parent 95e401a266
commit d699faf501
7 changed files with 60 additions and 60 deletions

View File

@@ -44,38 +44,38 @@ class TerminalStripLayoutPattern
TerminalStripLayoutPattern();
//Header of terminal strip
QRect m_header_rect{0,30,50,130};
QRectF m_header_rect{0,30,50,130};
Qt::Orientation m_header_text_orientation{Qt::Horizontal};
void setHeaderTextAlignment(const Qt::Alignment &alignment);
Qt::Alignment headerTextAlignment() const;
QTextOption headerTextOption() const;
//Spacer between the header and the terminals
QRect m_spacer_rect{0, 50, 10, 90};
QRectF m_spacer_rect{0, 50, 10, 90};
//Font
QFont font() const;
void setFont (const QFont &font);
//Terminals
QVector<QRect> m_terminal_rect
QVector<QRectF> m_terminal_rect
{
QRect{0, 0, 20, 190},
QRect{0, 10, 20, 170},
QRect{0, 20, 20, 150},
QRect{0, 30, 20, 130}
QRectF{0, 0, 20, 190},
QRectF{0, 10, 20, 170},
QRectF{0, 20, 20, 150},
QRectF{0, 30, 20, 130}
};
//Terminal text
void setTerminalsTextAlignment(const Qt::Alignment &alignment);
Qt::Alignment terminalsTextAlignment() const;
QTextOption terminalsTextOption() const;
int m_terminals_text_height{50};
int m_terminals_text_y{35};
qreal m_terminals_text_height{50};
qreal m_terminals_text_y{35};
Qt::Orientation m_terminals_text_orientation {Qt::Vertical};
int m_bridge_point_d{5};
QVector<int> m_bridge_point_y_offset{50,70,90,110};
qreal m_bridge_point_d{5};
QVector<qreal> m_bridge_point_y_offset{50,70,90,110};
QUuid m_uuid{QUuid::createUuid()};
QString m_name;

View File

@@ -95,7 +95,7 @@ void TerminalStripDrawer::paint(QPainter *painter)
//Move painter pos to next drawing
painter->translate(m_pattern->m_header_rect.width(),0);
int x_offset{m_pattern->m_header_rect.width()};
qreal x_offset{m_pattern->m_header_rect.width()};
//Draw spacer
painter->drawRect(m_pattern->m_spacer_rect);
@@ -109,7 +109,7 @@ void TerminalStripDrawer::paint(QPainter *painter)
const auto terminals_text_option{m_pattern->terminalsTextOption()};
const auto terminals_text_height{m_pattern->m_terminals_text_height};
const auto terminals_text_y{m_pattern->m_terminals_text_y};
QRect terminal_rect;
QRectF terminal_rect;
QHash<QUuid, QVector<QPointF>> bridges_anchor_points;
@@ -145,7 +145,7 @@ void TerminalStripDrawer::paint(QPainter *painter)
//We can't use terminal_rect.bottomLeft for p2 because
//the returned value deviate from the true value
//(see Qt documentation about QRect)
const QPoint p2 { p1.x(), p1.y() + terminal_rect.height() };
const QPointF p2 { p1.x(), p1.y() + terminal_rect.height() };
painter->drawLine(p1, p2);
painter->restore();
}
@@ -154,8 +154,8 @@ void TerminalStripDrawer::paint(QPainter *painter)
{
painter->save();
painter->setPen(Qt::yellow);
painter->drawLine(QPoint{terminal_rect.x(), terminal_rect.y() + terminal_rect.height()/2},
QPoint{terminal_rect.width(), terminal_rect.y() + terminal_rect.height()/2});
painter->drawLine(QPointF{terminal_rect.x(), terminal_rect.y() + terminal_rect.height()/2},
QPointF{terminal_rect.width(), terminal_rect.y() + terminal_rect.height()/2});
painter->restore();
}
@@ -226,7 +226,7 @@ void TerminalStripDrawer::paint(QPainter *painter)
QRectF TerminalStripDrawer::boundingRect() const
{
return QRect{0, 0, width(), height()};;
return QRectF{0, 0, width(), height()};;
}
void TerminalStripDrawer::setLayout(QSharedPointer<TerminalStripLayoutPattern> layout)
@@ -243,7 +243,7 @@ void TerminalStripDrawer::setPreviewDraw(bool draw) {
m_preview_draw = draw;
}
int TerminalStripDrawer::height() const
qreal TerminalStripDrawer::height() const
{
if (m_pattern)
{
@@ -261,11 +261,11 @@ int TerminalStripDrawer::height() const
return 0;
}
int TerminalStripDrawer::width() const
qreal TerminalStripDrawer::width() const
{
if (m_pattern)
{
int width_{m_pattern->m_header_rect.width() + m_pattern->m_spacer_rect.width()};
qreal width_{m_pattern->m_header_rect.width() + m_pattern->m_spacer_rect.width()};
if (m_strip)
{

View File

@@ -80,8 +80,8 @@ namespace TerminalStripDrawer
void setPreviewDraw(bool draw = true);
private:
int height() const;
int width() const;
qreal height() const;
qreal width() const;
private:
QSharedPointer <AbstractTerminalStripInterface> m_strip;

View File

@@ -29,7 +29,7 @@
* @param parent_document
* @return
*/
QDomElement QETSVG::rectToElmt(const QRect &rect, QDomDocument &parent_document)
QDomElement QETSVG::rectToElmt(const QRectF &rect, QDomDocument &parent_document)
{
auto dom_element = parent_document.createElement(QStringLiteral("rect"));
if (!rect.isNull()) {
@@ -47,16 +47,16 @@ QDomElement QETSVG::rectToElmt(const QRect &rect, QDomDocument &parent_document)
* The tag name must be 'rect' if not, the returned QRect is null.
* @return a svg rect to QRect
*/
QRect QETSVG::rectFromElmt(const QDomElement &xml_element)
QRectF QETSVG::rectFromElmt(const QDomElement &xml_element)
{
QRect rect;
QRectF rect_;
if (xml_element.tagName() == QLatin1String("rect")) {
rect.setRect(xml_element.attribute(QStringLiteral("x"), QStringLiteral("0")).toInt(),
static_cast<int> (yFromAttribute(xml_element, 0)),
xml_element.attribute(QStringLiteral("width"), QStringLiteral("10")).toInt(),
static_cast<int> (heightFromAttribute(xml_element, 10)));
rect_.setRect(xml_element.attribute(QStringLiteral("x"), QStringLiteral("0")).toDouble(),
yFromAttribute(xml_element, 0),
xml_element.attribute(QStringLiteral("width"), QStringLiteral("10")).toDouble(),
heightFromAttribute(xml_element, 10));
}
return rect;
return rect_;
}
/**
@@ -75,9 +75,9 @@ void QETSVG::yToAttribute(const qreal &y, QDomElement &xml_element) {
* @return
*/
qreal QETSVG::yFromAttribute(const QDomElement &xml_element, const qreal &def_value) {
qreal value;
if (QET::attributeIsAReal(xml_element, QStringLiteral("y"), &value)) {
return value;
qreal value_;
if (QET::attributeIsAReal(xml_element, QStringLiteral("y"), &value_)) {
return value_;
}
return def_value;
}
@@ -92,9 +92,9 @@ void QETSVG::heightToAttribute(const qreal &height, QDomElement &xml_element) {
}
qreal QETSVG::heightFromAttribute(const QDomElement &xml_element, const qreal &def_value) {
qreal value;
if (QET::attributeIsAReal(xml_element, QStringLiteral("height"), &value)) {
return value;
qreal value_;
if (QET::attributeIsAReal(xml_element, QStringLiteral("height"), &value_)) {
return value_;
}
return def_value;
}
@@ -104,9 +104,9 @@ void QETSVG::rToAttribute(const qreal &r, QDomElement &xml_element) {
}
qreal QETSVG::rFromAttribute(const QDomElement &xml_element, const qreal &def_value) {
qreal value;
if (QET::attributeIsAReal(xml_element, QStringLiteral("r"), &value)) {
return value;
qreal value_;
if (QET::attributeIsAReal(xml_element, QStringLiteral("r"), &value_)) {
return value_;
}
return def_value;
@@ -114,14 +114,14 @@ qreal QETSVG::rFromAttribute(const QDomElement &xml_element, const qreal &def_va
void QETSVG::pointsToAttribute(const QVector<QPointF> &points, QDomElement &xml_element)
{
QStringList strl;
QStringList strl_;
for (const auto &point : points) {
strl.append(QString::number(point.x()) +
strl_.append(QString::number(point.x()) +
QString(",") +
QString::number(point.y()));
}
xml_element.setAttribute(QStringLiteral("points"), strl.join(" "));
xml_element.setAttribute(QStringLiteral("points"), strl_.join(" "));
}
/**
@@ -132,7 +132,7 @@ void QETSVG::pointsToAttribute(const QVector<QPointF> &points, QDomElement &xml_
*/
QVector<QPointF> QETSVG::pointsFromAttribute(const QDomElement &xml_element)
{
QVector<QPointF> vector;
QVector<QPointF> vector_;
if (const auto string_points = xml_element.attribute(QStringLiteral("points")).split(QStringLiteral(" ")) ;
!string_points.isEmpty()) {
bool x_ok, y_ok; for (const auto &point : string_points) {
@@ -141,11 +141,11 @@ QVector<QPointF> QETSVG::pointsFromAttribute(const QDomElement &xml_element)
const auto x = string_x_y[0].toDouble(&x_ok);
const auto y = string_x_y[1].toDouble(&y_ok);
if (x_ok && y_ok) {
vector.append(QPointF{x,y});
vector_.append(QPointF{x,y});
}
}
}
}
return vector;
return vector_;
}

View File

@@ -22,7 +22,7 @@
class QDomDocument;
class QPointF;
class QRect;
class QRectF;
/**
* @namespace QETSVG
@@ -32,8 +32,8 @@ class QRect;
*/
namespace QETSVG
{
QDomElement rectToElmt(const QRect &rect, QDomDocument &parent_document);
QRect rectFromElmt(const QDomElement &xml_element);
QDomElement rectToElmt(const QRectF &rect, QDomDocument &parent_document);
QRectF rectFromElmt(const QDomElement &xml_element);
void yToAttribute(const qreal &y, QDomElement &xml_element);
qreal yFromAttribute(const QDomElement &xml_element, const qreal &def_value=0);

View File

@@ -118,12 +118,12 @@ QDomElement TerminalStripLayoutPatternXml::toXml(const QSharedPointer<TerminalSt
terminals_xml.appendChild(terminals_text_xml);
auto bridge_xml = document.createElement(QStringLiteral("bridges"));
QETSVG::rToAttribute(static_cast<qreal>(pattern->m_bridge_point_d)/2, bridge_xml);
QETSVG::pointsToAttribute(QVector<QPointF>{QPointF{0, static_cast<qreal> (pattern->m_bridge_point_y_offset.at(0))},
QPointF{0, static_cast<qreal> (pattern->m_bridge_point_y_offset.at(1))},
QPointF{0, static_cast<qreal> (pattern->m_bridge_point_y_offset.at(2))},
QPointF{0, static_cast<qreal> (pattern->m_bridge_point_y_offset.at(3))}},
bridge_xml);
QETSVG::rToAttribute(pattern->m_bridge_point_d/2, bridge_xml);
QVector<QPointF> points_vector;
for (const auto &y : pattern->m_bridge_point_y_offset) {
points_vector.append(QPointF{0,y});
}
QETSVG::pointsToAttribute(points_vector, bridge_xml);
terminals_xml.appendChild(bridge_xml);
pattern_xml.appendChild(terminals_xml);
@@ -181,10 +181,10 @@ void TerminalStripLayoutPatternXml::fromXml(QSharedPointer<TerminalStripLayoutPa
layout->m_bridge_point_d = QETSVG::rFromAttribute(bridge_xml, 2.5)*2;
if (const auto points = QETSVG::pointsFromAttribute(bridge_xml);
points.size() == 4) {
layout->m_bridge_point_y_offset[0]= static_cast<int>(points[0].y());
layout->m_bridge_point_y_offset[1]= static_cast<int>(points[1].y());
layout->m_bridge_point_y_offset[2]= static_cast<int>(points[2].y());
layout->m_bridge_point_y_offset[3]= static_cast<int>(points[3].y());
layout->m_bridge_point_y_offset[0]= points[0].y();
layout->m_bridge_point_y_offset[1]= points[1].y();
layout->m_bridge_point_y_offset[2]= points[2].y();
layout->m_bridge_point_y_offset[3]= points[3].y();
}
}
}

View File

@@ -25,8 +25,8 @@ class TerminalStripLayoutPattern;
/**
* @brief The TerminalStripLayoutPatternXml class
* A class used to save/restor a @class TerminalStripLayoutPattern to
* xml
* A class with static function used to save/restor a
* @class TerminalStripLayoutPattern to xml
*/
class TerminalStripLayoutPatternXml
{