34 if ( mLineSymbols.empty() && mMarkerSymbols.empty() )
39 const QList<QgsAbstractPlotSeries *> seriesList = plotData.
series();
40 if ( seriesList.isEmpty() )
45 const QStringList categories = plotData.
categories();
49 if ( categories.isEmpty() )
63 context.
painter()->setClipRect( plotArea );
75 Qgs2DXyPlot::applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
77 const double xScale = plotArea.width() / ( maxX - minX );
78 const double yScale = plotArea.height() / ( maxY - minY );
79 const double categoriesWidth = plotArea.width() / categories.size();
85 if ( !lSymbol && !mSymbol )
102 const QList<std::pair<double, double>> data = xySeries->data();
103 QVector<QPointF> points;
106 for (
const std::pair<double, double> &pair : data )
108 if ( !std::isnan( pair.second ) )
114 if ( pair.first < 0 || pair.first >= categories.size() )
118 x = ( categoriesWidth * pair.first ) + ( categoriesWidth / 2 );
121 x = ( pair.first - minX ) * xScale;
124 double y = ( pair.second - minY ) * yScale;
126 const QPointF point( plotArea.x() + x, plotArea.y() + plotArea.height() - y );
135 QVector<QPointF> line;
136 for (
const QPointF &point : points )
138 if ( !point.isNull() )
144 if ( !line.isEmpty() )
151 if ( !line.isEmpty() )
159 for (
const QPointF &point : points )
161 if ( !point.isNull() )
167 value = data.at( pointIndex ).second;
172 for (
const std::pair<double, double> &pair : data )
174 if ( pair.first == pointIndex )
214 if ( index < 0 || index >=
static_cast<int>( mMarkerSymbols.size() ) )
219 return mMarkerSymbols[index].get();
229 if ( index + 1 >=
static_cast<int>( mMarkerSymbols.size() ) )
231 mMarkerSymbols.resize( index + 1 );
234 mMarkerSymbols[index].reset( symbol );
239 if ( index < 0 || index >=
static_cast<int>( mLineSymbols.size() ) )
244 return mLineSymbols[index].get();
254 if ( index + 1 >=
static_cast<int>( mLineSymbols.size() ) )
256 mLineSymbols.resize( index + 1 );
259 mLineSymbols[index].reset( symbol );
266 QDomElement markerSymbolsElement = document.createElement( QStringLiteral(
"markerSymbols" ) );
267 for (
int i = 0; i < static_cast<int>( mMarkerSymbols.size() ); i++ )
269 QDomElement markerSymbolElement = document.createElement( QStringLiteral(
"markerSymbol" ) );
270 markerSymbolElement.setAttribute( QStringLiteral(
"index" ), QString::number( i ) );
271 if ( mMarkerSymbols[i] )
275 markerSymbolsElement.appendChild( markerSymbolElement );
277 element.appendChild( markerSymbolsElement );
279 QDomElement lineSymbolsElement = document.createElement( QStringLiteral(
"lineSymbols" ) );
280 for (
int i = 0; i < static_cast<int>( mLineSymbols.size() ); i++ )
282 QDomElement lineSymbolElement = document.createElement( QStringLiteral(
"lineSymbol" ) );
283 lineSymbolElement.setAttribute( QStringLiteral(
"index" ), QString::number( i ) );
284 if ( mLineSymbols[i] )
288 lineSymbolsElement.appendChild( lineSymbolElement );
290 element.appendChild( lineSymbolsElement );
299 const QDomNodeList markerSymbolsList = element.firstChildElement( QStringLiteral(
"markerSymbols" ) ).childNodes();
300 for (
int i = 0; i < markerSymbolsList.count(); i++ )
302 const QDomElement markerSymbolElement = markerSymbolsList.at( i ).toElement();
303 const int index = markerSymbolElement.attribute( QStringLiteral(
"index" ), QStringLiteral(
"-1" ) ).toInt();
306 if ( markerSymbolElement.hasChildNodes() )
308 const QDomElement symbolElement = markerSymbolElement.firstChildElement( QStringLiteral(
"symbol" ) );
318 const QDomNodeList lineSymbolsList = element.firstChildElement( QStringLiteral(
"lineSymbols" ) ).childNodes();
319 for (
int i = 0; i < lineSymbolsList.count(); i++ )
321 const QDomElement lineSymbolElement = lineSymbolsList.at( i ).toElement();
322 const int index = lineSymbolElement.attribute( QStringLiteral(
"index" ), QStringLiteral(
"-1" ) ).toInt();
325 if ( lineSymbolElement.hasChildNodes() )
327 const QDomElement symbolElement = lineSymbolElement.firstChildElement( QStringLiteral(
"symbol" ) );
@ 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.