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() )
97 QgsPlot::initPropertyDefinitions();
98 return sPropertyDefinitions;
137 element.setAttribute( u
"gridIntervalMinor"_s,
qgsDoubleToString( mGridIntervalMinor ) );
138 element.setAttribute( u
"gridIntervalMajor"_s,
qgsDoubleToString( mGridIntervalMajor ) );
140 element.setAttribute( u
"suffix"_s, mLabelSuffix );
141 element.setAttribute( u
"suffixPlacement"_s,
qgsEnumValueToKey( mSuffixPlacement ) );
143 QDomElement numericFormatElement = document.createElement( u
"numericFormat"_s );
144 mNumericFormat->writeXml( numericFormatElement, document, context );
145 element.appendChild( numericFormatElement );
147 QDomElement gridMajorElement = document.createElement( u
"gridMajorSymbol"_s );
149 element.appendChild( gridMajorElement );
150 QDomElement gridMinorElement = document.createElement( u
"gridMinorSymbol"_s );
152 element.appendChild( gridMinorElement );
154 QDomElement textFormatElement = document.createElement( u
"textFormat"_s );
155 textFormatElement.appendChild( mLabelTextFormat.writeXml( document, context ) );
156 element.appendChild( textFormatElement );
164 mGridIntervalMinor = element.attribute( u
"gridIntervalMinor"_s ).toDouble();
165 mGridIntervalMajor = element.attribute( u
"gridIntervalMajor"_s ).toDouble();
166 mLabelInterval = element.attribute( u
"labelInterval"_s ).toDouble();
168 mLabelSuffix = element.attribute( u
"suffix"_s );
171 const QDomElement numericFormatElement = element.firstChildElement( u
"numericFormat"_s );
174 const QDomElement gridMajorElement = element.firstChildElement( u
"gridMajorSymbol"_s ).firstChildElement( u
"symbol"_s );
176 const QDomElement gridMinorElement = element.firstChildElement( u
"gridMinorSymbol"_s ).firstChildElement( u
"symbol"_s );
179 const QDomElement textFormatElement = element.firstChildElement( u
"textFormat"_s );
180 mLabelTextFormat.readXml( textFormatElement, context );
187 return mNumericFormat.get();
192 mNumericFormat.reset( format );
202 mLabelSuffix = suffix;
207 return mSuffixPlacement;
212 mSuffixPlacement = placement;
217 return mGridMajorSymbol.get();
222 return mGridMajorSymbol.get();
227 mGridMajorSymbol.reset( symbol );
232 return mGridMinorSymbol.get();
237 return mGridMinorSymbol.get();
242 mGridMinorSymbol.reset( symbol );
247 return mLabelTextFormat;
252 mLabelTextFormat = format;
278 : mMargins( 2, 2, 2, 2 )
285 element.setAttribute( u
"margins"_s, mMargins.toString() );
335 return QRectF( leftMargin, topMargin, mSize.width() - rightMargin - leftMargin, mSize.height() - bottomMargin - topMargin );
431 element.setAttribute( u
"flipAxes"_s, mFlipAxes ?
"1"_L1 :
"0"_L1 );
433 QDomElement xAxisElement = document.createElement( u
"xAxis"_s );
434 mXAxis.writeXml( xAxisElement, document, context );
435 element.appendChild( xAxisElement );
436 QDomElement yAxisElement = document.createElement( u
"yAxis"_s );
437 mYAxis.writeXml( yAxisElement, document, context );
438 element.appendChild( yAxisElement );
440 QDomElement backgroundElement = document.createElement( u
"backgroundSymbol"_s );
442 element.appendChild( backgroundElement );
443 QDomElement borderElement = document.createElement( u
"borderSymbol"_s );
445 element.appendChild( borderElement );
454 mFlipAxes = element.attribute( u
"flipAxes"_s ).toInt() == 1;
456 mMinX = element.attribute( u
"minX"_s ).toDouble();
457 mMaxX = element.attribute( u
"maxX"_s ).toDouble();
458 mMinY = element.attribute( u
"minY"_s ).toDouble();
459 mMaxY = element.attribute( u
"maxY"_s ).toDouble();
461 const QDomElement xAxisElement = element.firstChildElement( u
"xAxis"_s );
462 mXAxis.readXml( xAxisElement, context );
463 const QDomElement yAxisElement = element.firstChildElement( u
"yAxis"_s );
464 mYAxis.readXml( yAxisElement, context );
466 const QDomElement backgroundElement = element.firstChildElement( u
"backgroundSymbol"_s ).firstChildElement( u
"symbol"_s );
468 const QDomElement borderElement = element.firstChildElement( u
"borderSymbol"_s ).firstChildElement( u
"symbol"_s );
479 mChartBackgroundSymbol->startRender( context );
480 mChartBorderSymbol->startRender( context );
482 mXAxis.gridMinorSymbol()->startRender( context );
483 mYAxis.gridMinorSymbol()->startRender( context );
484 mXAxis.gridMajorSymbol()->startRender( context );
485 mYAxis.gridMajorSymbol()->startRender( context );
493 double majorIntervalX = mXAxis.gridIntervalMajor();
494 double minorIntervalX = mXAxis.gridIntervalMinor();
495 double labelIntervalX = mXAxis.labelInterval();
496 double majorIntervalY = mYAxis.gridIntervalMajor();
497 double minorIntervalY = mYAxis.gridIntervalMinor();
498 double labelIntervalY = mYAxis.labelInterval();
499 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
507 std::swap( minX, minY );
508 std::swap( maxX, maxY );
509 std::swap( majorIntervalX, majorIntervalY );
510 std::swap( minorIntervalX, minorIntervalY );
511 std::swap( labelIntervalX, labelIntervalY );
519 const double firstMinorXGrid = std::ceil( minX / minorIntervalX ) * minorIntervalX;
520 const double firstMajorXGrid = std::ceil( minX / majorIntervalX ) * majorIntervalX;
521 const double firstMinorYGrid = std::ceil( minY / minorIntervalY ) * minorIntervalY;
522 const double firstMajorYGrid = std::ceil( minY / majorIntervalY ) * majorIntervalY;
523 const double firstXLabel = labelIntervalX > 0 ? std::ceil( minX / labelIntervalX ) * labelIntervalX : 0;
524 const double firstYLabel = labelIntervalY > 0 ? std::ceil( minY / labelIntervalY ) * labelIntervalY : 0;
526 const QString xAxisSuffix =
xAxis->labelSuffix();
527 const QString yAxisSuffix =
yAxis->labelSuffix();
531 const double xTolerance = minorIntervalX / 100000;
532 const double yTolerance = minorIntervalY / 100000;
536 constexpr int MAX_OBJECTS = 1000;
539 const QStringList categories = plotData.
categories();
542 double maxYAxisLabelWidth = 0;
544 switch (
yAxis->type() )
547 if ( labelIntervalY > 0 )
549 int objectNumber = 0;
550 for (
double currentY = firstYLabel;; currentY += labelIntervalY, ++objectNumber )
552 const bool hasMoreLabels = objectNumber + 1 < MAX_OBJECTS && ( currentY + labelIntervalY <= maxY && !
qgsDoubleNear( currentY + labelIntervalY, maxY, yTolerance ) );
554 QString text =
yAxis->numericFormat()->formatDouble( currentY, numericContext );
555 switch (
yAxis->labelSuffixPlacement() )
565 if ( currentY == firstYLabel )
570 if ( !hasMoreLabels )
575 if ( currentY == firstYLabel || !hasMoreLabels )
581 if ( !hasMoreLabels )
588 for (
int i = 0; i < categories.size(); i++ )
591 if ( i + 1 >= MAX_OBJECTS )
597 const double chartAreaLeft = plotArea.left();
598 const double chartAreaRight = plotArea.right();
599 const double chartAreaTop = plotArea.top();
600 const double chartAreaBottom = plotArea.bottom();
603 mChartBackgroundSymbol->renderPolygon(
605 { QPointF( chartAreaLeft, chartAreaTop ),
606 QPointF( chartAreaRight, chartAreaTop ),
607 QPointF( chartAreaRight, chartAreaBottom ),
608 QPointF( chartAreaLeft, chartAreaBottom ),
609 QPointF( chartAreaLeft, chartAreaTop ) }
616 const double xScale = ( chartAreaRight - chartAreaLeft ) / ( maxX - minX );
617 const double yScale = ( chartAreaBottom - chartAreaTop ) / ( maxY - minY );
622 switch (
xAxis->type() )
627 double nextMajorXGrid = firstMajorXGrid;
628 int objectNumber = 0;
629 for (
double currentX = firstMinorXGrid; objectNumber < MAX_OBJECTS && ( currentX <= maxX && !
qgsDoubleNear( currentX, maxX, xTolerance ) ); currentX += minorIntervalX, ++objectNumber )
635 nextMajorXGrid += majorIntervalX;
642 ->
renderPolyline( QPolygonF( QVector<QPointF> { QPointF( ( currentX - minX ) * xScale + chartAreaLeft, chartAreaBottom ), QPointF( ( currentX - minX ) * xScale + chartAreaLeft, chartAreaTop ) } ),
nullptr, context );
653 switch (
yAxis->type() )
658 double nextMajorYGrid = firstMajorYGrid;
659 int objectNumber = 0;
660 for (
double currentY = firstMinorYGrid; objectNumber < MAX_OBJECTS && ( currentY <= maxY && !
qgsDoubleNear( currentY, maxY, yTolerance ) ); currentY += minorIntervalY, ++objectNumber )
666 nextMajorYGrid += majorIntervalY;
673 ->
renderPolyline( QPolygonF( QVector<QPointF> { QPointF( chartAreaLeft, chartAreaBottom - ( currentY - minY ) * yScale ), QPointF( chartAreaRight, chartAreaBottom - ( currentY - minY ) * yScale ) } ),
nullptr, context );
686 switch (
xAxis->type() )
691 if ( labelIntervalX > 0 )
693 int objectNumber = 0;
694 for (
double currentX = firstXLabel;; currentX += labelIntervalX, ++objectNumber )
696 const bool hasMoreLabels = objectNumber + 1 < MAX_OBJECTS && ( currentX + labelIntervalX <= maxX ||
qgsDoubleNear( currentX + labelIntervalX, maxX, xTolerance ) );
698 QString text =
xAxis->numericFormat()->formatDouble( currentX, numericContext );
699 switch (
xAxis->labelSuffixPlacement() )
709 if ( objectNumber == 0 )
714 if ( !hasMoreLabels )
719 if ( objectNumber == 0 || !hasMoreLabels )
732 if ( !hasMoreLabels )
742 const double categoryWidth = plotArea.width() / categories.size();
743 for (
int i = 0; i < categories.size(); i++ )
745 const double currentX = ( i * categoryWidth ) + categoryWidth / 2.0;
751 { categories.at( i ) },
755 if ( i + 1 >= MAX_OBJECTS )
763 switch (
yAxis->type() )
768 if ( labelIntervalY > 0 )
770 int objectNumber = 0;
771 for (
double currentY = firstYLabel;; currentY += labelIntervalY, ++objectNumber )
773 const bool hasMoreLabels = objectNumber + 1 < MAX_OBJECTS && ( currentY + labelIntervalY <= maxY ||
qgsDoubleNear( currentY + labelIntervalY, maxY, yTolerance ) );
775 QString text =
yAxis->numericFormat()->formatDouble( currentY, numericContext );
776 switch (
yAxis->labelSuffixPlacement() )
786 if ( objectNumber == 0 )
791 if ( !hasMoreLabels )
796 if ( objectNumber == 0 || !hasMoreLabels )
811 if ( !hasMoreLabels )
821 const double categoryHeight = plotArea.height() / categories.size();
822 for (
int i = 0; i < categories.size(); i++ )
824 const double currentY = ( i * categoryHeight ) + categoryHeight / 2.0;
831 { categories.at( i ) },
837 if ( i + 1 >= MAX_OBJECTS )
848 mChartBorderSymbol->renderPolygon(
850 { QPointF( chartAreaLeft, chartAreaTop ),
851 QPointF( chartAreaRight, chartAreaTop ),
852 QPointF( chartAreaRight, chartAreaBottom ),
853 QPointF( chartAreaLeft, chartAreaBottom ),
854 QPointF( chartAreaLeft, chartAreaTop ) }
861 mChartBackgroundSymbol->stopRender( context );
862 mChartBorderSymbol->stopRender( context );
863 xAxis->gridMinorSymbol()->stopRender( context );
864 yAxis->gridMinorSymbol()->stopRender( context );
865 xAxis->gridMajorSymbol()->stopRender( context );
866 yAxis->gridMajorSymbol()->stopRender( context );
874 const QStringList categories = plotData.
categories();
880 double majorIntervalX = mXAxis.gridIntervalMajor();
881 double minorIntervalX = mXAxis.gridIntervalMinor();
882 double labelIntervalX = mXAxis.labelInterval();
883 double majorIntervalY = mYAxis.gridIntervalMajor();
884 double minorIntervalY = mYAxis.gridIntervalMinor();
885 double labelIntervalY = mYAxis.labelInterval();
886 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
892 std::swap( minX, minY );
893 std::swap( maxX, maxY );
894 std::swap( majorIntervalX, majorIntervalY );
895 std::swap( minorIntervalX, minorIntervalY );
896 std::swap( labelIntervalX, labelIntervalY );
902 const double firstMinorYGrid = std::ceil( minY / minorIntervalY ) * minorIntervalY;
903 const double firstXLabel = labelIntervalX > 0 ? std::ceil( minX / labelIntervalX ) * labelIntervalX : 0;
905 const QString xAxisSuffix =
xAxis->labelSuffix();
906 const QString yAxisSuffix =
yAxis->labelSuffix();
911 const double xTolerance = minorIntervalX / 100000;
912 const double yTolerance = minorIntervalX / 100000;
914 constexpr int MAX_LABELS = 1000;
918 double maxXAxisLabelHeight = 0;
920 switch (
xAxis->type() )
923 if ( labelIntervalX > 0 )
925 for (
double currentX = firstXLabel;; currentX += labelIntervalX, labelNumber++ )
927 const bool hasMoreLabels = labelNumber + 1 < MAX_LABELS && ( currentX + labelIntervalX <= maxX ||
qgsDoubleNear( currentX + labelIntervalX, maxX, xTolerance ) );
930 QString text =
xAxis->numericFormat()->formatDouble( currentX, numericContext );
931 switch (
xAxis->labelSuffixPlacement() )
941 if ( labelNumber == 0 )
946 if ( !hasMoreLabels )
951 if ( labelNumber == 0 || !hasMoreLabels )
956 if ( !hasMoreLabels )
963 for (
int i = 0; i < categories.size(); i++ )
966 if ( i + 1 >= MAX_LABELS )
972 double maxYAxisLabelWidth = 0;
975 switch (
yAxis->type() )
978 for (
double currentY = firstMinorYGrid;; currentY += minorIntervalY, labelNumber++ )
980 const bool hasMoreLabels = labelNumber + 1 < MAX_LABELS && ( currentY + minorIntervalY <= maxY ||
qgsDoubleNear( currentY + minorIntervalY, maxY, yTolerance ) );
982 const QString text =
yAxis->numericFormat()->formatDouble( currentY, numericContext );
984 if ( yAxisSuffixWidth > 0 )
986 switch (
yAxis->labelSuffixPlacement() )
992 thisLabelWidth += yAxisSuffixWidth;
996 if ( labelNumber == 0 )
997 thisLabelWidth += yAxisSuffixWidth;
1001 if ( !hasMoreLabels )
1002 thisLabelWidth += yAxisSuffixWidth;
1006 if ( labelNumber == 0 || !hasMoreLabels )
1007 thisLabelWidth += yAxisSuffixWidth;
1011 maxYAxisLabelWidth = std::max( maxYAxisLabelWidth, thisLabelWidth );
1012 if ( !hasMoreLabels )
1018 for (
int i = 0; i < categories.size(); i++ )
1021 if ( i + 1 >= MAX_LABELS )
1028 const double rightTextSize = 0;
1030 const double topTextSize = 0;
1039 return QRectF( leftMargin, topMargin, mSize.width() - rightMargin - leftMargin, mSize.height() - bottomMargin - topMargin );
1044 if ( !mSize.isValid() )
1048 constexpr double IDEAL_WIDTH = 0.4;
1050 constexpr int MAX_LABELS = 1000;
1061 auto refineIntervalForAxis =
1062 [&](
double axisMinimum,
double axisMaximum,
const std::function< double(
double ) > &sizeForLabel,
double availableSize,
double idealSizePercent,
double sizeTolerancePercent,
double &labelInterval,
double &majorInterval,
double &minorInterval ) {
1063 auto roundBase10 = [](
double value ) ->
double {
return std::pow( 10, std::floor( std::log10( value ) ) ); };
1066 double totalSize = 0;
1067 int initialLabelCount = 0;
1069 const double firstLabelPos = std::ceil( axisMinimum / labelInterval ) * labelInterval;
1071 for (
double currentPos = firstLabelPos; initialLabelCount <= MAX_LABELS && currentPos <= axisMaximum; currentPos += labelInterval, ++initialLabelCount )
1073 totalSize += sizeForLabel( currentPos );
1078 if ( initialLabelCount >= MAX_LABELS || ( totalSize / availableSize < ( idealSizePercent - sizeTolerancePercent ) ) || ( totalSize / availableSize > ( idealSizePercent + sizeTolerancePercent ) ) )
1081 int numberLabelsInitial = std::floor( availableSize / 30 );
1083 double labelIntervalTest = ( axisMaximum - axisMinimum ) / numberLabelsInitial;
1084 double baseValue = roundBase10( labelIntervalTest );
1085 double candidate = baseValue;
1086 int currentMultiplier = 1;
1088 int numberLabels = 0;
1091 const double firstLabelPosition = std::ceil( axisMinimum / candidate ) * candidate;
1092 double totalSize = 0;
1094 for (
double currentPos = firstLabelPosition; currentPos <= axisMaximum; currentPos += candidate )
1096 totalSize += sizeForLabel( currentPos );
1099 if ( numberLabels > MAX_LABELS )
1103 if ( numberLabels <= MAX_LABELS && totalSize <= availableSize * idealSizePercent )
1106 if ( currentMultiplier == 1 )
1107 currentMultiplier = 2;
1108 else if ( currentMultiplier == 2 )
1109 currentMultiplier = 5;
1110 else if ( currentMultiplier == 5 )
1113 currentMultiplier = 1;
1116 candidate = baseValue * currentMultiplier;
1118 labelInterval = candidate;
1119 if ( numberLabels < 10 )
1121 minorInterval = labelInterval / 2;
1122 majorInterval = minorInterval * 4;
1126 minorInterval = labelInterval;
1127 majorInterval = minorInterval * 5;
1132 double minX = mMinX;
1133 double maxX = mMaxX;
1134 double minY = mMinY;
1135 double maxY = mMaxY;
1136 double majorIntervalX = mXAxis.gridIntervalMajor();
1137 double minorIntervalX = mXAxis.gridIntervalMinor();
1138 double labelIntervalX = mXAxis.labelInterval();
1139 double majorIntervalY = mYAxis.gridIntervalMajor();
1140 double minorIntervalY = mYAxis.gridIntervalMinor();
1141 double labelIntervalY = mYAxis.labelInterval();
1142 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
1145 const double availableSize = mFlipAxes ? mSize.height() - topMargin - bottomMargin : mSize.width() - leftMargin - rightMargin;
1146 const QString suffixX = mXAxis.labelSuffix();
1148 refineIntervalForAxis(
1151 [
this, &context, suffixWidth, &numericContext](
double position ) ->
double {
1152 const QString text = mXAxis.numericFormat()->formatDouble( position, numericContext );
1164 mXAxis.setLabelInterval( labelIntervalX );
1165 mXAxis.setGridIntervalMajor( majorIntervalX );
1166 mXAxis.setGridIntervalMinor( minorIntervalX );
1170 const double availableSize = mFlipAxes ? mSize.width() - leftMargin - rightMargin : mSize.height() - topMargin - bottomMargin;
1171 const QString suffixY = mYAxis.labelSuffix();
1172 refineIntervalForAxis(
1175 [
this, &context, suffixY, &numericContext](
double position ) ->
double {
1176 const QString text = mYAxis.numericFormat()->formatDouble( position, numericContext );
1188 mYAxis.setLabelInterval( labelIntervalY );
1189 mYAxis.setGridIntervalMajor( majorIntervalY );
1190 mYAxis.setGridIntervalMinor( minorIntervalY );
1196 return mChartBackgroundSymbol.get();
1201 return mChartBackgroundSymbol.get();
1206 mChartBackgroundSymbol.reset( symbol );
1211 return mChartBorderSymbol.get();
1216 return mChartBorderSymbol.get();
1221 mChartBorderSymbol.reset( symbol );
1235 double &majorIntervalX,
1236 double &minorIntervalX,
1237 double &labelIntervalX,
1238 double &majorIntervalY,
1239 double &minorIntervalY,
1240 double &labelIntervalY
1295 majorIntervalX = value;
1305 minorIntervalX = value;
1315 labelIntervalX = value;
1325 majorIntervalY = value;
1335 minorIntervalY = value;
1345 labelIntervalY = value;
1389 auto gridMajor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 150 ), 0.1 );
1390 gridMajor->setPenCapStyle( Qt::FlatCap );
1396 auto gridMinor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 50 ), 0.1 );
1397 gridMinor->setPenCapStyle( Qt::FlatCap );
1403 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer >( QColor( 255, 255, 255 ) );
1409 auto chartBorder = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20 ), 0.1 );
1421 auto chartLine = std::make_unique< QgsSimpleLineSymbolLayer>( QColor( 89, 150, 50, 100 ), 0.6 );
1427 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer>( QColor( 89, 150, 50 ) );
1433 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer>( QColor( 150, 150, 150 ) );
1440 { 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 ) }
1459 : mCategories( other.mCategories )
1463 addSeries( series->clone() );
1468 : mSeries( std::move( other.mSeries ) )
1469 , mCategories( std::move( other.mCategories ) )
1474 if (
this != &other )
1478 mCategories = other.mCategories;
1489 if (
this != &other )
1493 mCategories = std::move( other.mCategories );
1494 mSeries = std::move( other.mSeries );
1506 if ( !mSeries.contains(
series ) )
1514 qDeleteAll( mSeries );
1558 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.
virtual QRectF interiorPlotArea(QgsRenderContext &context, QgsPlotRenderContext &plotContext, const QgsPlotData &plotData=QgsPlotData()) const
Returns the area of the plot which corresponds to the actual plot content (excluding all titles and o...
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).
void copyCommonProperties(const Qgs2DPlot *other)
Copies all Qgs2DPlot-level properties (size, margins, data-defined properties) from other to this plo...
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).
void copyCommonProperties(const Qgs2DXyPlot *other)
Copies all Qgs2DXyPlot-level properties (axis ranges, axes, flip state, background and border symbols...
void setXMaximum(double maximum)
Sets the maximum value of the x axis.
double yMaximum() const
Returns the maximum value of the y axis.
void setYMinimum(double minimum)
Sets the minimum 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 setChartBackgroundSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to render the background of the chart.
void setFlipAxes(bool flipAxes)
Sets whether the X and Y axes are flipped.
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.
void setChartBorderSymbol(QgsFillSymbol *symbol)
Sets the symbol used to render the border of the chart.
bool flipAxes() const
Returns whether the X and Y axes are flipped.
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 setXMinimum(double minimum)
Sets the minimum value of the x axis.
void calculateOptimisedIntervals(QgsRenderContext &context, QgsPlotRenderContext &plotContext)
Automatically sets the grid and label intervals to optimal values for display in the given render con...
QgsPlotAxis & xAxis()
Returns a reference to the plot's x axis.
Qgs2DXyPlot()
Constructor for Qgs2DXyPlot.
QgsFillSymbol * chartBorderSymbol()
Returns the symbol used to render the border of the chart.
double yMinimum() const
Returns the minimum value of the y axis.
QRectF interiorPlotArea(QgsRenderContext &context, QgsPlotRenderContext &plotContext, const QgsPlotData &plotData=QgsPlotData()) const override
Returns the area of the plot which corresponds to the actual plot content (excluding all titles and o...
void setYMaximum(double maximum)
Sets the maximum 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.
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.
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
A line symbol type, for rendering LineString and MultiLineString geometries.
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
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.
Encapsulates the properties of a plot axis.
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.
static void copyProperties(const QgsPlotAxis &source, QgsPlotAxis &destination)
Copies all properties from source axis to destination axis.
void setGridMajorSymbol(QgsLineSymbol *symbol)
Sets the symbol used to render the major lines in the axis grid.
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.
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 setGridIntervalMajor(double interval)
Sets the interval of major grid lines for the axis.
void setLabelSuffixPlacement(Qgis::PlotAxisSuffixPlacement placement)
Sets the placement for the axis label suffixes.
void setGridIntervalMinor(double interval)
Sets the interval of minor grid lines for the axis.
void setLabelInterval(double interval)
Sets the interval of labels for the axis.
Qgis::PlotAxisType type() const
Returns the axis type.
double labelInterval() const
Returns the interval of labels for the axis.
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.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the plot's property collection, used for data defined overrides.
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
virtual void initFromPlot(const QgsPlot *plot)
Initializes properties of this plot from an existing plot, transferring all applicable settings.
@ 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.