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 );
81 const double xScale = plotArea.width() / ( maxX - minX );
82 const double yScale = plotArea.height() / ( maxY - minY );
83 const double categoriesWidth = plotArea.width() / categories.size();
89 if ( !lSymbol && !mSymbol )
106 const QList<std::pair<double, double>> data = xySeries->data();
107 QVector<QPointF> points;
110 for (
const std::pair<double, double> &pair : data )
112 if ( !std::isnan( pair.second ) )
118 if ( pair.first < 0 || pair.first >= categories.size() )
122 x = ( categoriesWidth * pair.first ) + ( categoriesWidth / 2 );
125 x = ( pair.first - minX ) * xScale;
128 double y = ( pair.second - minY ) * yScale;
130 const QPointF point( plotArea.x() + x, plotArea.y() + plotArea.height() - y );
139 QVector<QPointF> line;
140 for (
const QPointF &point : points )
142 if ( !point.isNull() )
148 if ( !line.isEmpty() )
155 if ( !line.isEmpty() )
163 for (
const QPointF &point : points )
165 if ( !point.isNull() )
171 value = data.at( pointIndex ).second;
176 for (
const std::pair<double, double> &pair : data )
178 if ( pair.first == pointIndex )
218 if ( index < 0 || index >=
static_cast<int>( mMarkerSymbols.size() ) )
223 return mMarkerSymbols[index].get();
233 if ( index + 1 >=
static_cast<int>( mMarkerSymbols.size() ) )
235 mMarkerSymbols.resize( index + 1 );
238 mMarkerSymbols[index].reset( symbol );
243 if ( index < 0 || index >=
static_cast<int>( mLineSymbols.size() ) )
248 return mLineSymbols[index].get();
258 if ( index + 1 >=
static_cast<int>( mLineSymbols.size() ) )
260 mLineSymbols.resize( index + 1 );
263 mLineSymbols[index].reset( symbol );
270 QDomElement markerSymbolsElement = document.createElement( u
"markerSymbols"_s );
271 for (
int i = 0; i < static_cast<int>( mMarkerSymbols.size() ); i++ )
273 QDomElement markerSymbolElement = document.createElement( u
"markerSymbol"_s );
274 markerSymbolElement.setAttribute( u
"index"_s, QString::number( i ) );
275 if ( mMarkerSymbols[i] )
279 markerSymbolsElement.appendChild( markerSymbolElement );
281 element.appendChild( markerSymbolsElement );
283 QDomElement lineSymbolsElement = document.createElement( u
"lineSymbols"_s );
284 for (
int i = 0; i < static_cast<int>( mLineSymbols.size() ); i++ )
286 QDomElement lineSymbolElement = document.createElement( u
"lineSymbol"_s );
287 lineSymbolElement.setAttribute( u
"index"_s, QString::number( i ) );
288 if ( mLineSymbols[i] )
292 lineSymbolsElement.appendChild( lineSymbolElement );
294 element.appendChild( lineSymbolsElement );
303 const QDomNodeList markerSymbolsList = element.firstChildElement( u
"markerSymbols"_s ).childNodes();
304 for (
int i = 0; i < markerSymbolsList.count(); i++ )
306 const QDomElement markerSymbolElement = markerSymbolsList.at( i ).toElement();
307 const int index = markerSymbolElement.attribute( u
"index"_s, u
"-1"_s ).toInt();
310 if ( markerSymbolElement.hasChildNodes() )
312 const QDomElement symbolElement = markerSymbolElement.firstChildElement( u
"symbol"_s );
322 const QDomNodeList lineSymbolsList = element.firstChildElement( u
"lineSymbols"_s ).childNodes();
323 for (
int i = 0; i < lineSymbolsList.count(); i++ )
325 const QDomElement lineSymbolElement = lineSymbolsList.at( i ).toElement();
326 const int index = lineSymbolElement.attribute( u
"index"_s, u
"-1"_s ).toInt();
329 if ( lineSymbolElement.hasChildNodes() )
331 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.
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.