39using namespace Qt::StringLiterals;
47 element.setAttribute( u
"plotType"_s,
type() );
49 QDomElement dataDefinedPropertiesElement = document.createElement( u
"dataDefinedProperties"_s );
51 element.appendChild( dataDefinedPropertiesElement );
58 QDomElement dataDefinedPropertiesElement = element.firstChildElement( u
"dataDefinedProperties"_s );
64void QgsPlot::initPropertyDefinitions()
66 if ( !sPropertyDefinitions.isEmpty() )
90 QgsPlot::initPropertyDefinitions();
91 return sPropertyDefinitions;
120 element.setAttribute( u
"gridIntervalMinor"_s,
qgsDoubleToString( mGridIntervalMinor ) );
121 element.setAttribute( u
"gridIntervalMajor"_s,
qgsDoubleToString( mGridIntervalMajor ) );
123 element.setAttribute( u
"suffix"_s, mLabelSuffix );
124 element.setAttribute( u
"suffixPlacement"_s,
qgsEnumValueToKey( mSuffixPlacement ) );
126 QDomElement numericFormatElement = document.createElement( u
"numericFormat"_s );
127 mNumericFormat->writeXml( numericFormatElement, document, context );
128 element.appendChild( numericFormatElement );
130 QDomElement gridMajorElement = document.createElement( u
"gridMajorSymbol"_s );
132 element.appendChild( gridMajorElement );
133 QDomElement gridMinorElement = document.createElement( u
"gridMinorSymbol"_s );
135 element.appendChild( gridMinorElement );
137 QDomElement textFormatElement = document.createElement( u
"textFormat"_s );
138 textFormatElement.appendChild( mLabelTextFormat.writeXml( document, context ) );
139 element.appendChild( textFormatElement );
147 mGridIntervalMinor = element.attribute( u
"gridIntervalMinor"_s ).toDouble();
148 mGridIntervalMajor = element.attribute( u
"gridIntervalMajor"_s ).toDouble();
149 mLabelInterval = element.attribute( u
"labelInterval"_s ).toDouble();
151 mLabelSuffix = element.attribute( u
"suffix"_s );
154 const QDomElement numericFormatElement = element.firstChildElement( u
"numericFormat"_s );
157 const QDomElement gridMajorElement = element.firstChildElement( u
"gridMajorSymbol"_s ).firstChildElement( u
"symbol"_s );
159 const QDomElement gridMinorElement = element.firstChildElement( u
"gridMinorSymbol"_s ).firstChildElement( u
"symbol"_s );
162 const QDomElement textFormatElement = element.firstChildElement( u
"textFormat"_s );
163 mLabelTextFormat.readXml( textFormatElement, context );
170 return mNumericFormat.get();
175 mNumericFormat.reset( format );
185 mLabelSuffix = suffix;
190 return mSuffixPlacement;
195 mSuffixPlacement = placement;
200 return mGridMajorSymbol.get();
205 mGridMajorSymbol.reset( symbol );
210 return mGridMinorSymbol.get();
215 mGridMinorSymbol.reset( symbol );
220 return mLabelTextFormat;
225 mLabelTextFormat = format;
234 : mMargins( 2, 2, 2, 2 )
242 element.setAttribute( u
"margins"_s, mMargins.toString() );
293 return QRectF( leftMargin, topMargin, mSize.width() - rightMargin - leftMargin, mSize.height() - bottomMargin - topMargin );
377 QDomElement xAxisElement = document.createElement( u
"xAxis"_s );
378 mXAxis.writeXml( xAxisElement, document, context );
379 element.appendChild( xAxisElement );
380 QDomElement yAxisElement = document.createElement( u
"yAxis"_s );
381 mYAxis.writeXml( yAxisElement, document, context );
382 element.appendChild( yAxisElement );
384 QDomElement backgroundElement = document.createElement( u
"backgroundSymbol"_s );
386 element.appendChild( backgroundElement );
387 QDomElement borderElement = document.createElement( u
"borderSymbol"_s );
389 element.appendChild( borderElement );
398 mMinX = element.attribute( u
"minX"_s ).toDouble();
399 mMaxX = element.attribute( u
"maxX"_s ).toDouble();
400 mMinY = element.attribute( u
"minY"_s ).toDouble();
401 mMaxY = element.attribute( u
"maxY"_s ).toDouble();
403 const QDomElement xAxisElement = element.firstChildElement( u
"xAxis"_s );
404 mXAxis.readXml( xAxisElement, context );
405 const QDomElement yAxisElement = element.firstChildElement( u
"yAxis"_s );
406 mYAxis.readXml( yAxisElement, context );
408 const QDomElement backgroundElement = element.firstChildElement( u
"backgroundSymbol"_s ).firstChildElement( u
"symbol"_s );
410 const QDomElement borderElement = element.firstChildElement( u
"borderSymbol"_s ).firstChildElement( u
"symbol"_s );
421 mChartBackgroundSymbol->startRender( context );
422 mChartBorderSymbol->startRender( context );
423 mXAxis.gridMinorSymbol()->startRender( context );
424 mYAxis.gridMinorSymbol()->startRender( context );
425 mXAxis.gridMajorSymbol()->startRender( context );
426 mYAxis.gridMajorSymbol()->startRender( context );
434 double majorIntervalX = mXAxis.gridIntervalMajor();
435 double minorIntervalX = mXAxis.gridIntervalMinor();
436 double labelIntervalX = mXAxis.labelInterval();
437 double majorIntervalY = mYAxis.gridIntervalMajor();
438 double minorIntervalY = mYAxis.gridIntervalMinor();
439 double labelIntervalY = mYAxis.labelInterval();
440 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
442 const double firstMinorXGrid = std::ceil( minX / minorIntervalX ) * minorIntervalX;
443 const double firstMajorXGrid = std::ceil( minX / majorIntervalX ) * majorIntervalX;
444 const double firstMinorYGrid = std::ceil( minY / minorIntervalY ) * minorIntervalY;
445 const double firstMajorYGrid = std::ceil( minY / majorIntervalY ) * majorIntervalY;
446 const double firstXLabel = labelIntervalX > 0 ? std::ceil( minX / labelIntervalX ) * labelIntervalX : 0;
447 const double firstYLabel = labelIntervalY > 0 ? std::ceil( minY / labelIntervalY ) * labelIntervalY : 0;
449 const QString xAxisSuffix = mXAxis.labelSuffix();
450 const QString yAxisSuffix = mYAxis.labelSuffix();
454 const double xTolerance = minorIntervalX / 100000;
455 const double yTolerance = minorIntervalY / 100000;
460 const QStringList categories = plotData.
categories();
463 double maxYAxisLabelWidth = 0;
465 switch ( mYAxis.type() )
468 if ( labelIntervalY > 0 )
470 for (
double currentY = firstYLabel; ; currentY += labelIntervalY )
472 const bool hasMoreLabels = currentY + labelIntervalY <= maxY && !
qgsDoubleNear( currentY + labelIntervalY, maxY, yTolerance );
474 QString text = mYAxis.numericFormat()->formatDouble( currentY, numericContext );
475 switch ( mYAxis.labelSuffixPlacement() )
485 if ( currentY == firstYLabel )
490 if ( !hasMoreLabels )
495 if ( currentY == firstYLabel || !hasMoreLabels )
501 if ( !hasMoreLabels )
508 for (
int i = 0; i < categories.size(); i++ )
510 maxYAxisLabelWidth = std::max( maxYAxisLabelWidth,
QgsTextRenderer::textWidth( context, mYAxis.textFormat(), { categories.at( i ) } ) );
515 const double chartAreaLeft = plotArea.left();
516 const double chartAreaRight = plotArea.right();
517 const double chartAreaTop = plotArea.top();
518 const double chartAreaBottom = plotArea.bottom();
521 mChartBackgroundSymbol->renderPolygon( QPolygonF(
523 QPointF( chartAreaLeft, chartAreaTop ),
524 QPointF( chartAreaRight, chartAreaTop ),
525 QPointF( chartAreaRight, chartAreaBottom ),
526 QPointF( chartAreaLeft, chartAreaBottom ),
527 QPointF( chartAreaLeft, chartAreaTop )
528 } ),
nullptr,
nullptr, context );
530 const double xScale = ( chartAreaRight - chartAreaLeft ) / ( maxX - minX );
531 const double yScale = ( chartAreaBottom - chartAreaTop ) / ( maxY - minY );
533 constexpr int MAX_OBJECTS = 1000;
538 switch ( mXAxis.type() )
543 double nextMajorXGrid = firstMajorXGrid;
544 int objectNumber = 0;
545 for (
double currentX = firstMinorXGrid; objectNumber < MAX_OBJECTS && ( currentX <= maxX && !
qgsDoubleNear( currentX, maxX, xTolerance ) ); currentX += minorIntervalX, ++objectNumber )
551 nextMajorXGrid += majorIntervalX;
556 QgsLineSymbol *currentGridSymbol = isMinor ? mXAxis.gridMinorSymbol() : mXAxis.gridMajorSymbol();
560 QPointF( ( currentX - minX ) * xScale + chartAreaLeft, chartAreaBottom ),
561 QPointF( ( currentX - minX ) * xScale + chartAreaLeft, chartAreaTop )
562 } ),
nullptr, context );
573 switch ( mYAxis.type() )
578 double nextMajorYGrid = firstMajorYGrid;
579 int objectNumber = 0;
580 for (
double currentY = firstMinorYGrid; objectNumber < MAX_OBJECTS && ( currentY <= maxY && !
qgsDoubleNear( currentY, maxY, yTolerance ) ); currentY += minorIntervalY, ++objectNumber )
586 nextMajorYGrid += majorIntervalY;
591 QgsLineSymbol *currentGridSymbol = isMinor ? mYAxis.gridMinorSymbol() : mYAxis.gridMajorSymbol();
595 QPointF( chartAreaLeft, chartAreaBottom - ( currentY - minY ) * yScale ),
596 QPointF( chartAreaRight, chartAreaBottom - ( currentY - minY ) * yScale )
597 } ),
nullptr, context );
610 switch ( mXAxis.type() )
615 int objectNumber = 0;
616 if ( labelIntervalX > 0 )
618 for (
double currentX = firstXLabel; ; currentX += labelIntervalX, ++objectNumber )
620 const bool hasMoreLabels = objectNumber + 1 < MAX_OBJECTS && ( currentX + labelIntervalX <= maxX ||
qgsDoubleNear( currentX + labelIntervalX, maxX, xTolerance ) );
622 QString text = mXAxis.numericFormat()->formatDouble( currentX, numericContext );
623 switch ( mXAxis.labelSuffixPlacement() )
633 if ( objectNumber == 0 )
638 if ( !hasMoreLabels )
643 if ( objectNumber == 0 || !hasMoreLabels )
650 if ( !hasMoreLabels )
660 const double categoryWidth = plotArea.width() / categories.size();
661 for (
int i = 0; i < categories.size(); i++ )
663 const double currentX = ( i * categoryWidth ) + categoryWidth / 2.0;
673 switch ( mYAxis.type() )
678 int objectNumber = 0;
679 if ( labelIntervalY > 0 )
681 for (
double currentY = firstYLabel; ; currentY += labelIntervalY, ++objectNumber )
683 const bool hasMoreLabels = objectNumber + 1 < MAX_OBJECTS && ( currentY + labelIntervalY <= maxY ||
qgsDoubleNear( currentY + labelIntervalY, maxY, yTolerance ) );
685 QString text = mYAxis.numericFormat()->formatDouble( currentY, numericContext );
686 switch ( mYAxis.labelSuffixPlacement() )
696 if ( objectNumber == 0 )
701 if ( !hasMoreLabels )
706 if ( objectNumber == 0 || !hasMoreLabels )
714 chartAreaBottom - ( currentY - minY ) * yScale + height / 2 ),
716 if ( !hasMoreLabels )
726 const double categoryHeight = plotArea.height() / categories.size();
727 for (
int i = 0; i < categories.size(); i++ )
729 const double currentY = ( i * categoryHeight ) + categoryHeight / 2.0;
734 chartAreaBottom - currentY + height / 2 ),
745 mChartBorderSymbol->renderPolygon( QPolygonF(
747 QPointF( chartAreaLeft, chartAreaTop ),
748 QPointF( chartAreaRight, chartAreaTop ),
749 QPointF( chartAreaRight, chartAreaBottom ),
750 QPointF( chartAreaLeft, chartAreaBottom ),
751 QPointF( chartAreaLeft, chartAreaTop )
752 } ),
nullptr,
nullptr, context );
754 mChartBackgroundSymbol->stopRender( context );
755 mChartBorderSymbol->stopRender( context );
756 mXAxis.gridMinorSymbol()->stopRender( context );
757 mYAxis.gridMinorSymbol()->stopRender( context );
758 mXAxis.gridMajorSymbol()->stopRender( context );
759 mYAxis.gridMajorSymbol()->stopRender( context );
770 double majorIntervalX = mXAxis.gridIntervalMajor();
771 double minorIntervalX = mXAxis.gridIntervalMinor();
772 double labelIntervalX = mXAxis.labelInterval();
773 double majorIntervalY = mYAxis.gridIntervalMajor();
774 double minorIntervalY = mYAxis.gridIntervalMinor();
775 double labelIntervalY = mYAxis.labelInterval();
776 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
781 const double firstMinorYGrid = std::ceil( minY / minorIntervalY ) * minorIntervalY;
782 const double firstXLabel = labelIntervalX > 0 ? std::ceil( minX / labelIntervalX ) * labelIntervalX : 0;
784 const QString xAxisSuffix = mXAxis.labelSuffix();
785 const QString yAxisSuffix = mYAxis.labelSuffix();
786 const double yAxisSuffixWidth = yAxisSuffix.isEmpty() ? 0 :
QgsTextRenderer::textWidth( context, mYAxis.textFormat(), { yAxisSuffix } );
790 const double xTolerance = minorIntervalX / 100000;
791 const double yTolerance = minorIntervalX / 100000;
793 constexpr int MAX_LABELS = 1000;
797 double maxXAxisLabelHeight = 0;
799 if ( labelIntervalX > 0 )
801 for (
double currentX = firstXLabel; ; currentX += labelIntervalX, labelNumber++ )
803 const bool hasMoreLabels = labelNumber + 1 < MAX_LABELS && ( currentX + labelIntervalX <= maxX ||
qgsDoubleNear( currentX + labelIntervalX, maxX, xTolerance ) );
806 QString text = mXAxis.numericFormat()->formatDouble( currentX, numericContext );
807 switch ( mXAxis.labelSuffixPlacement() )
817 if ( labelNumber == 0 )
822 if ( !hasMoreLabels )
827 if ( labelNumber == 0 || !hasMoreLabels )
832 if ( !hasMoreLabels )
837 double maxYAxisLabelWidth = 0;
840 for (
double currentY = firstMinorYGrid; ; currentY += minorIntervalY, labelNumber ++ )
842 const bool hasMoreLabels = labelNumber + 1 < MAX_LABELS && ( currentY + minorIntervalY <= maxY ||
qgsDoubleNear( currentY + minorIntervalY, maxY, yTolerance ) );
844 const QString text = mYAxis.numericFormat()->formatDouble( currentY, numericContext );
846 if ( yAxisSuffixWidth > 0 )
848 switch ( mYAxis.labelSuffixPlacement() )
854 thisLabelWidth += yAxisSuffixWidth;
858 if ( labelNumber == 0 )
859 thisLabelWidth += yAxisSuffixWidth;
863 if ( !hasMoreLabels )
864 thisLabelWidth += yAxisSuffixWidth;
868 if ( labelNumber == 0 || !hasMoreLabels )
869 thisLabelWidth += yAxisSuffixWidth;
873 maxYAxisLabelWidth = std::max( maxYAxisLabelWidth, thisLabelWidth );
874 if ( !hasMoreLabels )
879 const double rightTextSize = 0;
881 const double topTextSize = 0;
890 return QRectF( leftMargin, topMargin, mSize.width() - rightMargin - leftMargin, mSize.height() - bottomMargin - topMargin );
895 if ( !mSize.isValid() )
899 constexpr double IDEAL_WIDTH = 0.4;
901 constexpr int MAX_LABELS = 1000;
910 const double availableWidth = mSize.width() - leftMargin - rightMargin;
911 const double availableHeight = mSize.height() - topMargin - bottomMargin;
915 auto refineIntervalForAxis = [&](
double axisMinimum,
double axisMaximum,
916 const std::function< double(
double ) > &sizeForLabel,
917 double availableSize,
double idealSizePercent,
double sizeTolerancePercent,
918 double & labelInterval,
double & majorInterval,
double & minorInterval )
920 auto roundBase10 = [](
double value )->
double
922 return std::pow( 10, std::floor( std::log10( value ) ) );
926 double totalSize = 0;
927 int initialLabelCount = 0;
929 const double firstLabelPos = std::ceil( axisMinimum / labelInterval ) * labelInterval;
931 for (
double currentPos = firstLabelPos; initialLabelCount <= MAX_LABELS && currentPos <= axisMaximum; currentPos += labelInterval, ++initialLabelCount )
933 totalSize += sizeForLabel( currentPos );
938 if ( initialLabelCount >= MAX_LABELS || ( totalSize / availableSize < ( idealSizePercent - sizeTolerancePercent ) ) || ( totalSize / availableSize > ( idealSizePercent + sizeTolerancePercent ) ) )
941 int numberLabelsInitial = std::floor( availableSize / 30 );
943 double labelIntervalTest = ( axisMaximum - axisMinimum ) / numberLabelsInitial;
944 double baseValue = roundBase10( labelIntervalTest );
945 double candidate = baseValue;
946 int currentMultiplier = 1;
948 int numberLabels = 0;
951 const double firstLabelPosition = std::ceil( axisMinimum / candidate ) * candidate;
952 double totalSize = 0;
954 for (
double currentPos = firstLabelPosition; currentPos <= axisMaximum; currentPos += candidate )
956 totalSize += sizeForLabel( currentPos );
959 if ( numberLabels > MAX_LABELS )
963 if ( numberLabels <= MAX_LABELS && totalSize <= availableSize * idealSizePercent )
966 if ( currentMultiplier == 1 )
967 currentMultiplier = 2;
968 else if ( currentMultiplier == 2 )
969 currentMultiplier = 5;
970 else if ( currentMultiplier == 5 )
973 currentMultiplier = 1;
976 candidate = baseValue * currentMultiplier;
978 labelInterval = candidate;
979 if ( numberLabels < 10 )
981 minorInterval = labelInterval / 2;
982 majorInterval = minorInterval * 4;
986 minorInterval = labelInterval;
987 majorInterval = minorInterval * 5;
996 double majorIntervalX = mXAxis.gridIntervalMajor();
997 double minorIntervalX = mXAxis.gridIntervalMinor();
998 double labelIntervalX = mXAxis.labelInterval();
999 double majorIntervalY = mYAxis.gridIntervalMajor();
1000 double minorIntervalY = mYAxis.gridIntervalMinor();
1001 double labelIntervalY = mYAxis.labelInterval();
1002 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
1005 const QString suffixX = mXAxis.labelSuffix();
1007 refineIntervalForAxis( minX, maxX, [
this, &context, suffixWidth, &numericContext](
double position ) ->
double
1009 const QString text = mXAxis.numericFormat()->formatDouble( position, numericContext );
1014 IDEAL_WIDTH,
TOLERANCE, labelIntervalX, majorIntervalX, minorIntervalX );
1015 mXAxis.setLabelInterval( labelIntervalX );
1016 mXAxis.setGridIntervalMajor( majorIntervalX );
1017 mXAxis.setGridIntervalMinor( minorIntervalX );
1021 const QString suffixY = mYAxis.labelSuffix();
1022 refineIntervalForAxis( minY, maxY, [
this, &context, suffixY, &numericContext](
double position ) ->
double
1024 const QString text = mYAxis.numericFormat()->formatDouble( position, numericContext );
1029 IDEAL_WIDTH,
TOLERANCE, labelIntervalY, majorIntervalY, minorIntervalY );
1030 mYAxis.setLabelInterval( labelIntervalY );
1031 mYAxis.setGridIntervalMajor( majorIntervalY );
1032 mYAxis.setGridIntervalMinor( minorIntervalY );
1038 return mChartBackgroundSymbol.get();
1043 mChartBackgroundSymbol.reset( symbol );
1048 return mChartBorderSymbol.get();
1053 mChartBorderSymbol.reset( symbol );
1056void Qgs2DXyPlot::applyDataDefinedProperties(
QgsRenderContext &context,
double &minX,
double &maxX,
double &minY,
double &maxY,
double &majorIntervalX,
double &minorIntervalX,
double &labelIntervalX,
double &majorIntervalY,
double &minorIntervalY,
double &labelIntervalY )
const
1110 majorIntervalX = value;
1120 minorIntervalX = value;
1130 labelIntervalX = value;
1140 majorIntervalY = value;
1150 minorIntervalY = value;
1160 labelIntervalY = value;
1176 auto gridMajor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 150 ), 0.1 );
1177 gridMajor->setPenCapStyle( Qt::FlatCap );
1183 auto gridMinor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 50 ), 0.1 );
1184 gridMinor->setPenCapStyle( Qt::FlatCap );
1190 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer >( QColor( 255, 255, 255 ) );
1196 auto chartBorder = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20 ), 0.1 );
1208 auto chartLine = std::make_unique< QgsSimpleLineSymbolLayer>( QColor( 89, 150, 50, 100 ), 0.6 );
1214 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer>( QColor( 89, 150, 50 ) );
1220 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer>( QColor( 150, 150, 150 ) );
1226 return new QgsPresetSchemeColorRamp( { QColor( 89, 150, 50 ), QColor( 228, 26, 28 ), QColor( 55, 126, 184 ), QColor( 152, 78, 163 ), QColor( 255, 127, 0 ), QColor( 166, 86, 40 ), QColor( 247, 129, 191 ), QColor( 153, 153, 153 ) } );
1244 : mCategories( other.mCategories )
1248 addSeries( series->clone() );
1253 : mSeries( std::move( other.mSeries ) )
1254 , mCategories( std::move( other.mCategories ) )
1260 if (
this != &other )
1264 mCategories = other.mCategories;
1275 if (
this != &other )
1279 mCategories = std::move( other.mCategories );
1280 mSeries = std::move( other.mSeries );
1292 if ( !mSeries.contains(
series ) )
1300 qDeleteAll( mSeries );
1344 mData << std::make_pair( x, y );
PlotAxisSuffixPlacement
Placement options for suffixes in the labels for axis of plots.
@ FirstAndLastLabels
Place suffix after the first and last label values only.
@ EveryLabel
Place suffix after every value label.
@ FirstLabel
Place suffix after the first label value only.
@ LastLabel
Place suffix after the last label value only.
@ NoLabels
Do not place suffixes.
PlotAxisType
Plots axis types.
@ Categorical
The axis represents categories.
@ Interval
The axis represents a range of values.
@ Millimeters
Millimeters.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes the plot's properties into an XML element.
void applyDataDefinedProperties(QgsRenderContext &context, QgsMargins &margins) const
Applies 2D plot data-defined properties.
virtual void renderContent(QgsRenderContext &context, QgsPlotRenderContext &plotContext, const QRectF &plotArea, const QgsPlotData &plotData=QgsPlotData())
Renders the plot content.
void setSize(QSizeF size)
Sets the overall size of the plot (including titles and over components which sit outside the plot ar...
const QgsMargins & margins() const
Returns the margins of the plot area (in millimeters).
virtual QRectF interiorPlotArea(QgsRenderContext &context, QgsPlotRenderContext &plotContext) const
Returns the area of the plot which corresponds to the actual plot content (excluding all titles and o...
Qgs2DPlot()
Constructor for Qgs2DPlot.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the plot's properties from an XML element.
virtual void render(QgsRenderContext &context, QgsPlotRenderContext &plotContext, const QgsPlotData &plotData=QgsPlotData())
Renders the plot.
QSizeF size() const
Returns the overall size of the plot (in millimeters) (including titles and other components which si...
void setMargins(const QgsMargins &margins)
Sets the margins of the plot area (in millimeters).
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the plot's properties from an XML element.
void setChartBackgroundSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to render the background of the chart.
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.
void setChartBorderSymbol(QgsFillSymbol *symbol)
Sets the symbol used to render the border of the chart.
void render(QgsRenderContext &context, QgsPlotRenderContext &plotContext, const QgsPlotData &plotData=QgsPlotData()) override
Renders the plot.
QgsFillSymbol * chartBackgroundSymbol()
Returns the fill symbol used to render the background of the chart.
void calculateOptimisedIntervals(QgsRenderContext &context, QgsPlotRenderContext &plotContext)
Automatically sets the grid and label intervals to optimal values for display in the given render con...
Qgs2DXyPlot()
Constructor for Qgs2DXyPlot.
QgsFillSymbol * chartBorderSymbol()
Returns the symbol used to render the border of the chart.
QRectF interiorPlotArea(QgsRenderContext &context, QgsPlotRenderContext &plotContext) const override
Returns the area of the plot which corresponds to the actual plot content (excluding all titles and o...
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes the plot's properties into an XML element.
An abstract class used to encapsulate the data for a plot series.
void setName(const QString &name)
Sets the series' name.
QString name() const
Returns the series' name.
QgsAbstractPlotSeries()=default
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
Abstract base class for color ramps.
RAII class to pop scope from an expression context on destruction.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
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.
Defines the four margins of a rectangle.
double top() const
Returns the top margin.
static QgsMargins fromString(const QString &string)
Returns a QgsMargins object decoded from a string, or a null QgsMargins if the string could not be in...
double right() const
Returns the right margin.
double bottom() const
Returns the bottom margin.
double left() const
Returns the left margin.
A marker symbol type, for rendering Point and MultiPoint geometries.
A context for numeric formats.
QgsLineSymbol * gridMinorSymbol()
Returns the line symbol used to render the minor lines in the axis grid.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the axis' properties from an XML element.
void setGridMajorSymbol(QgsLineSymbol *symbol)
Sets the symbol used to render the major lines in the axis grid.
void setType(Qgis::PlotAxisType type)
Sets the axis type.
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for the axis labels.
QgsTextFormat textFormat() const
Returns the text format used for the axis labels.
void setLabelSuffixPlacement(Qgis::PlotAxisSuffixPlacement placement)
Sets the placement for the axis label suffixes.
Qgis::PlotAxisType type() const
Returns the axis type.
QgsLineSymbol * gridMajorSymbol()
Returns the line symbol used to render the major lines in the axis grid.
void setLabelSuffix(const QString &suffix)
Sets the axis label suffix.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for the axis labels.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes the axis' properties into an XML element.
void setGridMinorSymbol(QgsLineSymbol *symbol)
Sets the symbol used to render the minor lines in the axis grid.
QgsNumericFormat * numericFormat() const
Returns the numeric format used for the axis labels.
Qgis::PlotAxisSuffixPlacement labelSuffixPlacement() const
Returns the placement for the axis label suffixes.
QString labelSuffix() const
Returns the axis label suffix, or an empty string if no label suffix is to be used.
Encapsulates one or more plot series.
QStringList categories() const
Returns the name of the series' categories.
QgsPlotData & operator=(const QgsPlotData &other)
void clearSeries()
Clears all series from the plot data.
QList< QgsAbstractPlotSeries * > series() const
Returns the list of series forming the plot data.
void setCategories(const QStringList &categories)
Sets the name of the series' categories.
void addSeries(QgsAbstractPlotSeries *series)
Adds a series to the plot data.
static QgsFillSymbol * chartBorderSymbol()
Returns the default fill symbol to use for the chart area border.
static QgsNumericFormat * pieChartNumericFormat()
Returns the default color ramp to use for pie charts.
static QgsNumericFormat * axisLabelNumericFormat()
Returns the default numeric format to use for plot axis labels.
static QgsColorRamp * pieChartColorRamp()
Returns the default color ramp to use for pie charts.
static QgsFillSymbol * barChartFillSymbol()
Returns the default fill symbol to use for bar charts.
static QgsLineSymbol * lineChartLineSymbol()
Returns the default line symbol to use for line charts.
static QgsLineSymbol * axisGridMinorSymbol()
Returns the default line symbol to use for axis minor grid lines.
static QgsFillSymbol * pieChartFillSymbol()
Returns the default fill symbol to use for pie charts.
static QgsMarkerSymbol * lineChartMarkerSymbol()
Returns the default marker symbol to use for line charts.
static QgsFillSymbol * chartBackgroundSymbol()
Returns the default fill symbol to use for the chart area background fill.
static QgsLineSymbol * axisGridMajorSymbol()
Returns the default line symbol to use for axis major grid lines.
Contains information about the context of a plot rendering operation.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the plot property definitions.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the plot's property collection, used for data defined overrides.
virtual QString type() const
Returns the plot's type.
QgsPropertyCollection mDataDefinedProperties
@ YAxisMinorInterval
Minor grid line interval for Y axis.
@ YAxisLabelInterval
Label interval for Y axis.
@ XAxisMajorInterval
Major grid line interval for X axis.
@ XAxisMaximum
Maximum X axis value.
@ XAxisMinimum
Minimum X axis value.
@ XAxisLabelInterval
Label interval for X axis.
@ MarginBottom
Bottom margin.
@ XAxisMinorInterval
Minor grid line interval for X axis.
@ YAxisMajorInterval
Major grid line interval for Y axis.
@ YAxisMaximum
Maximum Y axis value.
@ MarginRight
Right margin.
@ YAxisMinimum
Minimum Y axis value.
virtual bool readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the plot's properties from an XML element.
virtual bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes the plot's properties into an XML element.
A scheme based color ramp consisting of a list of predefined colors.
Definition for a property.
@ Double
Double value (including negative values).
@ DoublePositive
Positive double value (including 0).
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
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.
Container for all settings relating to text rendering.
static double textWidth(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, QFontMetricsF *fontMetrics=nullptr)
Returns the width of a text based on a given format.
static void drawText(const QRectF &rect, double rotation, Qgis::TextHorizontalAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, Qgis::TextVerticalAlignment vAlignment=Qgis::TextVerticalAlignment::Top, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Rectangle)
Draws text within a rectangle using the specified settings.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Point, QFontMetricsF *fontMetrics=nullptr, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), double maxLineWidth=0)
Returns the height of a text based on a given format.
void setData(const QList< std::pair< double, double > > &data)
Sets the series' list of XY pairs of double.
QgsAbstractPlotSeries * clone() const override
Clones the series.
QgsXyPlotSeries()=default
void append(double x, double y)
Appends a pair of X/Y double values to the series.
void clear()
Clears the series' data.
QList< std::pair< double, double > > data() const
Returns the series' list of XY pairs of double.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QList< QgsSymbolLayer * > QgsSymbolLayerList
#define DEFAULT_SCALE_METHOD
Single variable definition for use within a QgsExpressionContextScope.