29using namespace Qt::StringLiterals;
39 if ( mLineSymbols.empty() && mMarkerSymbols.empty() )
44 const QList<QgsAbstractPlotSeries *> seriesList = plotData.
series();
45 if ( seriesList.isEmpty() )
50 const QStringList categories = plotData.
categories();
54 if ( categories.isEmpty() )
68 context.
painter()->setClipRect( plotArea );
80 Qgs2DXyPlot::applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
84 double categoriesWidth = 0.0;
87 xScale = plotArea.height() / ( maxX - minX );
88 yScale = plotArea.width() / ( maxY - minY );
89 categoriesWidth = plotArea.height() /
static_cast<double>( categories.size() );
93 xScale = plotArea.width() / ( maxX - minX );
94 yScale = plotArea.height() / ( maxY - minY );
95 categoriesWidth = plotArea.width() /
static_cast<double>( categories.size() );
103 if ( !lSymbol && !mSymbol )
122 const QList<std::pair<double, double>> data = xySeries->data();
123 QVector<QPointF> points;
126 for (
const std::pair<double, double> &pair : data )
128 if ( !std::isnan( pair.second ) )
134 if ( pair.first < 0 || pair.first >= categories.size() )
138 x = ( categoriesWidth * pair.first ) + ( categoriesWidth / 2 );
141 x = ( pair.first - minX ) * xScale;
144 double y = ( pair.second - minY ) * yScale;
149 point = QPointF( plotArea.x() + y, plotArea.bottom() - x );
153 point = QPointF( plotArea.x() + x, plotArea.y() + plotArea.height() - y );
163 QVector<QPointF> line;
164 for (
const QPointF &point : points )
166 if ( !point.isNull() )
172 if ( !line.isEmpty() )
179 if ( !line.isEmpty() )
187 for (
const QPointF &point : points )
189 if ( !point.isNull() )
195 value = data.at( pointIndex ).second;
200 for (
const std::pair<double, double> &pair : data )
202 if ( pair.first == pointIndex )
240 if ( index < 0 || index >=
static_cast<int>( mMarkerSymbols.size() ) )
245 return mMarkerSymbols[index].get();
255 if ( index + 1 >=
static_cast<int>( mMarkerSymbols.size() ) )
257 mMarkerSymbols.resize( index + 1 );
260 mMarkerSymbols[index].reset( symbol );
265 if ( index < 0 || index >=
static_cast<int>( mLineSymbols.size() ) )
270 return mLineSymbols[index].get();
280 if ( index + 1 >=
static_cast<int>( mLineSymbols.size() ) )
282 mLineSymbols.resize( index + 1 );
285 mLineSymbols[index].reset( symbol );
292 QDomElement markerSymbolsElement = document.createElement( u
"markerSymbols"_s );
293 for (
int i = 0; i < static_cast<int>( mMarkerSymbols.size() ); i++ )
295 QDomElement markerSymbolElement = document.createElement( u
"markerSymbol"_s );
296 markerSymbolElement.setAttribute( u
"index"_s, QString::number( i ) );
297 if ( mMarkerSymbols[i] )
301 markerSymbolsElement.appendChild( markerSymbolElement );
303 element.appendChild( markerSymbolsElement );
305 QDomElement lineSymbolsElement = document.createElement( u
"lineSymbols"_s );
306 for (
int i = 0; i < static_cast<int>( mLineSymbols.size() ); i++ )
308 QDomElement lineSymbolElement = document.createElement( u
"lineSymbol"_s );
309 lineSymbolElement.setAttribute( u
"index"_s, QString::number( i ) );
310 if ( mLineSymbols[i] )
314 lineSymbolsElement.appendChild( lineSymbolElement );
316 element.appendChild( lineSymbolsElement );
325 const QDomNodeList markerSymbolsList = element.firstChildElement( u
"markerSymbols"_s ).childNodes();
326 for (
int i = 0; i < markerSymbolsList.count(); i++ )
328 const QDomElement markerSymbolElement = markerSymbolsList.at( i ).toElement();
329 const int index = markerSymbolElement.attribute( u
"index"_s, u
"-1"_s ).toInt();
332 if ( markerSymbolElement.hasChildNodes() )
334 const QDomElement symbolElement = markerSymbolElement.firstChildElement( u
"symbol"_s );
344 const QDomNodeList lineSymbolsList = element.firstChildElement( u
"lineSymbols"_s ).childNodes();
345 for (
int i = 0; i < lineSymbolsList.count(); i++ )
347 const QDomElement lineSymbolElement = lineSymbolsList.at( i ).toElement();
348 const int index = lineSymbolElement.attribute( u
"index"_s, u
"-1"_s ).toInt();
351 if ( lineSymbolElement.hasChildNodes() )
353 const QDomElement symbolElement = lineSymbolElement.firstChildElement( u
"symbol"_s );
400 for (
int idx = 0; idx < lineChartPlot->lineSymbolCount(); idx++ )
404 for (
int idx = 0; idx < lineChartPlot->markerSymbolCount(); idx++ )
@ Categorical
The axis represents categories.
@ Interval
The axis represents a range of values.
void copyCommonProperties(const Qgs2DPlot *other)
Copies all Qgs2DPlot-level properties (size, margins, data-defined properties) from other to this plo...
Qgs2DPlot()
Constructor for Qgs2DPlot.
void copyCommonProperties(const Qgs2DXyPlot *other)
Copies all Qgs2DXyPlot-level properties (axis ranges, axes, flip state, background and border symbols...
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.
Qgs2DXyPlot()
Constructor for Qgs2DXyPlot.
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 initFromPlot(const QgsPlot *plot) override
Initializes properties of this plot from an existing plot, transferring all applicable settings.
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.
Scoped object for saving and restoring a QPainter object's state.
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.