28using namespace Qt::StringLiterals;
38 if ( mLineSymbols.empty() && mMarkerSymbols.empty() )
43 const QList<QgsAbstractPlotSeries *> seriesList = plotData.
series();
44 if ( seriesList.isEmpty() )
49 const QStringList categories = plotData.
categories();
53 if ( categories.isEmpty() )
67 context.
painter()->setClipRect( plotArea );
79 Qgs2DXyPlot::applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
83 double categoriesWidth = 0.0;
86 xScale = plotArea.height() / ( maxX - minX );
87 yScale = plotArea.width() / ( maxY - minY );
88 categoriesWidth = plotArea.height() /
static_cast<double>( categories.size() );
92 xScale = plotArea.width() / ( maxX - minX );
93 yScale = plotArea.height() / ( maxY - minY );
94 categoriesWidth = plotArea.width() /
static_cast<double>( categories.size() );
102 if ( !lSymbol && !mSymbol )
121 const QList<std::pair<double, double>> data = xySeries->data();
122 QVector<QPointF> points;
125 for (
const std::pair<double, double> &pair : data )
127 if ( !std::isnan( pair.second ) )
133 if ( pair.first < 0 || pair.first >= categories.size() )
137 x = ( categoriesWidth * pair.first ) + ( categoriesWidth / 2 );
140 x = ( pair.first - minX ) * xScale;
143 double y = ( pair.second - minY ) * yScale;
148 point = QPointF( plotArea.x() + y, plotArea.bottom() - x );
152 point = QPointF( plotArea.x() + x, plotArea.y() + plotArea.height() - y );
162 QVector<QPointF> line;
163 for (
const QPointF &point : points )
165 if ( !point.isNull() )
171 if ( !line.isEmpty() )
178 if ( !line.isEmpty() )
186 for (
const QPointF &point : points )
188 if ( !point.isNull() )
194 value = data.at( pointIndex ).second;
199 for (
const std::pair<double, double> &pair : data )
201 if ( pair.first == pointIndex )
241 if ( index < 0 || index >=
static_cast<int>( mMarkerSymbols.size() ) )
246 return mMarkerSymbols[index].get();
256 if ( index + 1 >=
static_cast<int>( mMarkerSymbols.size() ) )
258 mMarkerSymbols.resize( index + 1 );
261 mMarkerSymbols[index].reset( symbol );
266 if ( index < 0 || index >=
static_cast<int>( mLineSymbols.size() ) )
271 return mLineSymbols[index].get();
281 if ( index + 1 >=
static_cast<int>( mLineSymbols.size() ) )
283 mLineSymbols.resize( index + 1 );
286 mLineSymbols[index].reset( symbol );
293 QDomElement markerSymbolsElement = document.createElement( u
"markerSymbols"_s );
294 for (
int i = 0; i < static_cast<int>( mMarkerSymbols.size() ); i++ )
296 QDomElement markerSymbolElement = document.createElement( u
"markerSymbol"_s );
297 markerSymbolElement.setAttribute( u
"index"_s, QString::number( i ) );
298 if ( mMarkerSymbols[i] )
302 markerSymbolsElement.appendChild( markerSymbolElement );
304 element.appendChild( markerSymbolsElement );
306 QDomElement lineSymbolsElement = document.createElement( u
"lineSymbols"_s );
307 for (
int i = 0; i < static_cast<int>( mLineSymbols.size() ); i++ )
309 QDomElement lineSymbolElement = document.createElement( u
"lineSymbol"_s );
310 lineSymbolElement.setAttribute( u
"index"_s, QString::number( i ) );
311 if ( mLineSymbols[i] )
315 lineSymbolsElement.appendChild( lineSymbolElement );
317 element.appendChild( lineSymbolsElement );
326 const QDomNodeList markerSymbolsList = element.firstChildElement( u
"markerSymbols"_s ).childNodes();
327 for (
int i = 0; i < markerSymbolsList.count(); i++ )
329 const QDomElement markerSymbolElement = markerSymbolsList.at( i ).toElement();
330 const int index = markerSymbolElement.attribute( u
"index"_s, u
"-1"_s ).toInt();
333 if ( markerSymbolElement.hasChildNodes() )
335 const QDomElement symbolElement = markerSymbolElement.firstChildElement( u
"symbol"_s );
345 const QDomNodeList lineSymbolsList = element.firstChildElement( u
"lineSymbols"_s ).childNodes();
346 for (
int i = 0; i < lineSymbolsList.count(); i++ )
348 const QDomElement lineSymbolElement = lineSymbolsList.at( i ).toElement();
349 const int index = lineSymbolElement.attribute( u
"index"_s, u
"-1"_s ).toInt();
352 if ( lineSymbolElement.hasChildNodes() )
354 const QDomElement symbolElement = lineSymbolElement.firstChildElement( u
"symbol"_s );
@ Categorical
The axis represents categories.
@ Interval
The axis represents a range of values.
double yMaximum() const
Returns the maximum value of the y axis.
double xMinimum() const
Returns the minimum value of the x axis.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the plot's properties from an XML element.
void applyDataDefinedProperties(QgsRenderContext &context, double &minX, double &maxX, double &minY, double &maxY, double &majorIntervalX, double &minorIntervalX, double &labelIntervalX, double &majorIntervalY, double &minorIntervalY, double &labelIntervalY) const
Applies 2D XY plot data-defined properties.
QgsPlotAxis & yAxis()
Returns a reference to the plot's y axis.
bool flipAxes() const
Returns whether the X and Y axes are flipped.
QgsPlotAxis & xAxis()
Returns a reference to the plot's x axis.
double yMinimum() const
Returns the minimum value of the y axis.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes the plot's properties into an XML element.
double xMaximum() const
Returns the maximum value of the x axis.
An abstract class used to encapsulate the data for a plot series.
RAII class to pop scope from an expression context on destruction.
Single scope for storing variables and functions for use within a QgsExpressionContext.
bool removeVariable(const QString &name)
Removes a variable from the context scope, if found.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
QgsMarkerSymbol * markerSymbolAt(int index) const
Returns the marker symbol for the series with matching index.
QgsLineSymbol * lineSymbolAt(int index) const
Returns the line symbol for the series with matching index.
static QgsVectorLayerAbstractPlotDataGatherer * createDataGatherer(QgsPlot *plot)
Returns a new data gatherer for a given line chart plot.
void setLineSymbolAt(int index, QgsLineSymbol *symbol)
Sets the line symbol to use for the series with matching index.
void setMarkerSymbolAt(int index, QgsMarkerSymbol *symbol)
Sets the fill symbol to use for the series with matching index.
QString type() const override
Returns the plot's type.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes the plot's properties into an XML element.
void renderContent(QgsRenderContext &context, QgsPlotRenderContext &plotContext, const QRectF &plotArea, const QgsPlotData &plotData=QgsPlotData()) override
Renders the plot content.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the plot's properties from an XML element.
static QgsLineChartPlot * create()
Returns a new line chart.
A line symbol type, for rendering LineString and MultiLineString geometries.
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol along the line joining points, using the given render context.
A marker symbol type, for rendering Point and MultiPoint geometries.
void renderPoint(QPointF point, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol at the specified point, using the given render context.
double gridIntervalMinor() const
Returns the interval of minor grid lines for the axis.
double gridIntervalMajor() const
Returns the interval of major grid lines for the axis.
Qgis::PlotAxisType type() const
Returns the axis type.
double labelInterval() const
Returns the interval of labels for the axis.
Encapsulates one or more plot series.
QStringList categories() const
Returns the name of the series' categories.
QList< QgsAbstractPlotSeries * > series() const
Returns the list of series forming the plot data.
static QgsLineSymbol * lineChartLineSymbol()
Returns the default line symbol to use for line charts.
static QgsMarkerSymbol * lineChartMarkerSymbol()
Returns the default marker symbol to use for line charts.
Contains information about the context of a plot rendering operation.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
static std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
An abstract vector layer plot data gatherer base class.
An vector layer plot data gatherer class for XY series.
Encapsulates the data for an XY plot series.
Single variable definition for use within a QgsExpressionContextScope.