inverted as bool instead of Qsk::Position
This commit is contained in:
parent
e514b659e8
commit
15e04de169
@ -20,7 +20,6 @@ class Diagram::PrivateData
|
|||||||
QVector< QVector< QPointF > > dataPoints;
|
QVector< QVector< QPointF > > dataPoints;
|
||||||
int xGridLines = -1;
|
int xGridLines = -1;
|
||||||
qreal yMax = -1;
|
qreal yMax = -1;
|
||||||
Qsk::Position position = Qsk::Bottom;
|
|
||||||
QVector< Types > types;
|
QVector< Types > types;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,14 +69,4 @@ void Diagram::setXGridLines( int lines )
|
|||||||
m_data->xGridLines = 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"
|
#include "moc_Diagram.cpp"
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QskControl.h>
|
#include <QskControl.h>
|
||||||
#include <QskNamespace.h>
|
|
||||||
|
|
||||||
class Diagram : public QskControl
|
class Diagram : public QskControl
|
||||||
{
|
{
|
||||||
@ -40,9 +39,6 @@ class Diagram : public QskControl
|
|||||||
int xGridLines() const;
|
int xGridLines() const;
|
||||||
void setXGridLines( int lines );
|
void setXGridLines( int lines );
|
||||||
|
|
||||||
Qsk::Position chartPosition() const;
|
|
||||||
void setChartPosition( Qsk::Position );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class PrivateData;
|
class PrivateData;
|
||||||
std::unique_ptr< PrivateData > m_data;
|
std::unique_ptr< PrivateData > m_data;
|
||||||
|
@ -92,10 +92,11 @@ QSGNode* DiagramSkinlet::updateChartNode( const Diagram* diagram, QSGNode* node
|
|||||||
}
|
}
|
||||||
|
|
||||||
using Q = Diagram;
|
using Q = Diagram;
|
||||||
|
|
||||||
const QRectF rect = diagram->subControlRect( Q::Chart );
|
const QRectF rect = diagram->subControlRect( Q::Chart );
|
||||||
const qreal yMax = diagram->yMax();
|
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 )
|
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 )
|
const QColor color = ( types.at( j ) == Diagram::Line ) ? diagram->color( lineSubcontrol )
|
||||||
: diagram->color( areaSubcontrol );
|
: diagram->color( areaSubcontrol );
|
||||||
|
|
||||||
dataPointNode->update( rect, nodeType, color, dataPoints, yMax, position, lineWidth );
|
dataPointNode->update( rect, nodeType, color, dataPoints, yMax, false, lineWidth );
|
||||||
nodeIndex++;
|
nodeIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,8 @@ DiagramDataNode::DiagramDataNode()
|
|||||||
|
|
||||||
void DiagramDataNode::update( const QRectF& rect, Type type,
|
void DiagramDataNode::update( const QRectF& rect, Type type,
|
||||||
const QColor& color, const QVector< QPointF >& dataPoints,
|
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 )
|
if( color != m_color )
|
||||||
{
|
{
|
||||||
m_material.setColor( color );
|
m_material.setColor( color );
|
||||||
@ -27,8 +25,8 @@ void DiagramDataNode::update( const QRectF& rect, Type type,
|
|||||||
markDirty( QSGNode::DirtyMaterial );
|
markDirty( QSGNode::DirtyMaterial );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_rect == rect && m_dataPoints == dataPoints && m_yMax == yMax && m_position == position
|
if( m_rect == rect && m_dataPoints == dataPoints && m_yMax == yMax
|
||||||
&& m_type == type && m_lineWidth == lineWidth )
|
&& m_inverted == inverted && m_type == type && m_lineWidth == lineWidth )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -44,7 +42,7 @@ void DiagramDataNode::update( const QRectF& rect, Type type,
|
|||||||
m_rect = rect;
|
m_rect = rect;
|
||||||
m_dataPoints = dataPoints;
|
m_dataPoints = dataPoints;
|
||||||
m_yMax = yMax;
|
m_yMax = yMax;
|
||||||
m_position = position;
|
m_inverted = inverted;
|
||||||
m_type = type;
|
m_type = type;
|
||||||
|
|
||||||
const auto drawingMode =
|
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 x = ( ( m_dataPoints.at( i ).x() - xMin ) / ( xMax - xMin ) ) * rect.width();
|
||||||
const qreal fraction = ( m_dataPoints.at( i ).y() / yMax ) * rect.height();
|
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 )
|
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 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 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].x = x;
|
||||||
vertexData[2 * i].y = y;
|
vertexData[2 * i].y = y;
|
||||||
|
|
||||||
@ -91,7 +89,7 @@ void DiagramDataNode::update( const QRectF& rect, Type type,
|
|||||||
}
|
}
|
||||||
else if( m_type == Area )
|
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].x = x;
|
||||||
vertexData[2 * i].y = y;
|
vertexData[2 * i].y = y;
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QskNamespace.h>
|
|
||||||
|
|
||||||
#include <QPolygonF>
|
#include <QPolygonF>
|
||||||
#include <QSGFlatColorMaterial>
|
#include <QSGFlatColorMaterial>
|
||||||
#include <QSGGeometryNode>
|
#include <QSGGeometryNode>
|
||||||
@ -23,7 +21,7 @@ class DiagramDataNode : public QSGGeometryNode
|
|||||||
DiagramDataNode();
|
DiagramDataNode();
|
||||||
|
|
||||||
void update( const QRectF&, Type, const QColor&,
|
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:
|
private:
|
||||||
QSGFlatColorMaterial m_material;
|
QSGFlatColorMaterial m_material;
|
||||||
@ -34,6 +32,6 @@ class DiagramDataNode : public QSGGeometryNode
|
|||||||
QColor m_color;
|
QColor m_color;
|
||||||
QVector< QPointF > m_dataPoints;
|
QVector< QPointF > m_dataPoints;
|
||||||
qreal m_yMax;
|
qreal m_yMax;
|
||||||
Qsk::Position m_position;
|
bool m_inverted;
|
||||||
int m_lineWidth;
|
int m_lineWidth;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user