inverted as bool instead of Qsk::Position

This commit is contained in:
Uwe Rathmann 2022-04-17 12:25:51 +02:00
parent e514b659e8
commit 15e04de169
5 changed files with 13 additions and 31 deletions

View File

@ -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"

View File

@ -6,7 +6,6 @@
#pragma once
#include <QskControl.h>
#include <QskNamespace.h>
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;

View File

@ -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++;
}
}

View File

@ -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;

View File

@ -5,8 +5,6 @@
#pragma once
#include <QskNamespace.h>
#include <QPolygonF>
#include <QSGFlatColorMaterial>
#include <QSGGeometryNode>
@ -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;
};