From 15e04de169ba7adfb7590a5917b7a70319378084 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Sun, 17 Apr 2022 12:25:51 +0200 Subject: [PATCH] inverted as bool instead of Qsk::Position --- examples/iotdashboard/Diagram.cpp | 11 ----------- examples/iotdashboard/Diagram.h | 4 ---- examples/iotdashboard/DiagramSkinlet.cpp | 7 ++++--- examples/iotdashboard/nodes/DiagramDataNode.cpp | 16 +++++++--------- examples/iotdashboard/nodes/DiagramDataNode.h | 6 ++---- 5 files changed, 13 insertions(+), 31 deletions(-) diff --git a/examples/iotdashboard/Diagram.cpp b/examples/iotdashboard/Diagram.cpp index edb18a62..e05bd9aa 100644 --- a/examples/iotdashboard/Diagram.cpp +++ b/examples/iotdashboard/Diagram.cpp @@ -20,7 +20,6 @@ class Diagram::PrivateData QVector< QVector< QPointF > > dataPoints; int xGridLines = -1; qreal yMax = -1; - Qsk::Position position = Qsk::Bottom; QVector< Types > types; }; @@ -70,14 +69,4 @@ void Diagram::setXGridLines( int lines ) m_data->xGridLines = lines; } -Qsk::Position Diagram::chartPosition() const -{ - return m_data->position; -} - -void Diagram::setChartPosition( Qsk::Position position ) -{ - m_data->position = position; -} - #include "moc_Diagram.cpp" diff --git a/examples/iotdashboard/Diagram.h b/examples/iotdashboard/Diagram.h index a996bc20..978dd31d 100644 --- a/examples/iotdashboard/Diagram.h +++ b/examples/iotdashboard/Diagram.h @@ -6,7 +6,6 @@ #pragma once #include -#include class Diagram : public QskControl { @@ -40,9 +39,6 @@ class Diagram : public QskControl int xGridLines() const; void setXGridLines( int lines ); - Qsk::Position chartPosition() const; - void setChartPosition( Qsk::Position ); - private: class PrivateData; std::unique_ptr< PrivateData > m_data; diff --git a/examples/iotdashboard/DiagramSkinlet.cpp b/examples/iotdashboard/DiagramSkinlet.cpp index 715e8cee..0f50e4b6 100644 --- a/examples/iotdashboard/DiagramSkinlet.cpp +++ b/examples/iotdashboard/DiagramSkinlet.cpp @@ -92,10 +92,11 @@ QSGNode* DiagramSkinlet::updateChartNode( const Diagram* diagram, QSGNode* node } using Q = Diagram; + const QRectF rect = diagram->subControlRect( Q::Chart ); const qreal yMax = diagram->yMax(); - const Qsk::Position position = diagram->chartPosition(); - QVector< Diagram::Type > types = { Diagram::Line, Diagram::Area }; + + const QVector< Diagram::Type > types = { Diagram::Line, Diagram::Area }; for( int i = 0; i < diagram->dataPoints().size(); ++i ) { @@ -137,7 +138,7 @@ QSGNode* DiagramSkinlet::updateChartNode( const Diagram* diagram, QSGNode* node const QColor color = ( types.at( j ) == Diagram::Line ) ? diagram->color( lineSubcontrol ) : diagram->color( areaSubcontrol ); - dataPointNode->update( rect, nodeType, color, dataPoints, yMax, position, lineWidth ); + dataPointNode->update( rect, nodeType, color, dataPoints, yMax, false, lineWidth ); nodeIndex++; } } diff --git a/examples/iotdashboard/nodes/DiagramDataNode.cpp b/examples/iotdashboard/nodes/DiagramDataNode.cpp index a5fa2006..2229fa50 100644 --- a/examples/iotdashboard/nodes/DiagramDataNode.cpp +++ b/examples/iotdashboard/nodes/DiagramDataNode.cpp @@ -16,10 +16,8 @@ DiagramDataNode::DiagramDataNode() void DiagramDataNode::update( const QRectF& rect, Type type, const QColor& color, const QVector< QPointF >& dataPoints, - const qreal yMax, Qsk::Position position, int lineWidth ) + const qreal yMax, bool inverted, int lineWidth ) { - Q_UNUSED( rect ); - if( color != m_color ) { m_material.setColor( color ); @@ -27,8 +25,8 @@ void DiagramDataNode::update( const QRectF& rect, Type type, markDirty( QSGNode::DirtyMaterial ); } - if( m_rect == rect && m_dataPoints == dataPoints && m_yMax == yMax && m_position == position - && m_type == type && m_lineWidth == lineWidth ) + if( m_rect == rect && m_dataPoints == dataPoints && m_yMax == yMax + && m_inverted == inverted && m_type == type && m_lineWidth == lineWidth ) { return; } @@ -44,7 +42,7 @@ void DiagramDataNode::update( const QRectF& rect, Type type, m_rect = rect; m_dataPoints = dataPoints; m_yMax = yMax; - m_position = position; + m_inverted = inverted; m_type = type; const auto drawingMode = @@ -76,13 +74,13 @@ void DiagramDataNode::update( const QRectF& rect, Type type, { const qreal x = ( ( m_dataPoints.at( i ).x() - xMin ) / ( xMax - xMin ) ) * rect.width(); const qreal fraction = ( m_dataPoints.at( i ).y() / yMax ) * rect.height(); - const qreal y = ( position == Qsk::Top ) ? fraction : rect.height() - fraction; + const qreal y = inverted ? fraction : rect.height() - fraction; if( m_type == Line && i < m_dataPoints.size() - 1 ) { const qreal x2 = ( ( m_dataPoints.at( i + 1 ).x() - xMin ) / ( xMax - xMin ) ) * rect.width(); const qreal fraction2 = ( m_dataPoints.at( i + 1 ).y() / yMax ) * rect.height(); - const qreal y2 = ( position == Qsk::Top ) ? fraction2 : rect.height() - fraction2; + const qreal y2 = inverted ? fraction2 : rect.height() - fraction2; vertexData[2 * i].x = x; vertexData[2 * i].y = y; @@ -91,7 +89,7 @@ void DiagramDataNode::update( const QRectF& rect, Type type, } else if( m_type == Area ) { - const qreal y0 = ( position == Qsk::Top ) ? 0 : rect.height(); + const qreal y0 = inverted ? 0 : rect.height(); vertexData[2 * i].x = x; vertexData[2 * i].y = y; diff --git a/examples/iotdashboard/nodes/DiagramDataNode.h b/examples/iotdashboard/nodes/DiagramDataNode.h index 65bb6c0b..584fb75f 100644 --- a/examples/iotdashboard/nodes/DiagramDataNode.h +++ b/examples/iotdashboard/nodes/DiagramDataNode.h @@ -5,8 +5,6 @@ #pragma once -#include - #include #include #include @@ -23,7 +21,7 @@ class DiagramDataNode : public QSGGeometryNode DiagramDataNode(); void update( const QRectF&, Type, const QColor&, - const QVector< QPointF >&, const qreal yMax, Qsk::Position, int lineWidth ); + const QVector< QPointF >&, const qreal yMax, bool inverted, int lineWidth ); private: QSGFlatColorMaterial m_material; @@ -34,6 +32,6 @@ class DiagramDataNode : public QSGGeometryNode QColor m_color; QVector< QPointF > m_dataPoints; qreal m_yMax; - Qsk::Position m_position; + bool m_inverted; int m_lineWidth; };