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 element.setAttribute( u
"flipAxes"_s, mFlipAxes ?
"1"_L1 :
"0"_L1 );
379 QDomElement xAxisElement = document.createElement( u
"xAxis"_s );
380 mXAxis.writeXml( xAxisElement, document, context );
381 element.appendChild( xAxisElement );
382 QDomElement yAxisElement = document.createElement( u
"yAxis"_s );
383 mYAxis.writeXml( yAxisElement, document, context );
384 element.appendChild( yAxisElement );
386 QDomElement backgroundElement = document.createElement( u
"backgroundSymbol"_s );
388 element.appendChild( backgroundElement );
389 QDomElement borderElement = document.createElement( u
"borderSymbol"_s );
391 element.appendChild( borderElement );
400 mFlipAxes = element.attribute( u
"flipAxes"_s ).toInt() == 1;
402 mMinX = element.attribute( u
"minX"_s ).toDouble();
403 mMaxX = element.attribute( u
"maxX"_s ).toDouble();
404 mMinY = element.attribute( u
"minY"_s ).toDouble();
405 mMaxY = element.attribute( u
"maxY"_s ).toDouble();
407 const QDomElement xAxisElement = element.firstChildElement( u
"xAxis"_s );
408 mXAxis.readXml( xAxisElement, context );
409 const QDomElement yAxisElement = element.firstChildElement( u
"yAxis"_s );
410 mYAxis.readXml( yAxisElement, context );
412 const QDomElement backgroundElement = element.firstChildElement( u
"backgroundSymbol"_s ).firstChildElement( u
"symbol"_s );
414 const QDomElement borderElement = element.firstChildElement( u
"borderSymbol"_s ).firstChildElement( u
"symbol"_s );
425 mChartBackgroundSymbol->startRender( context );
426 mChartBorderSymbol->startRender( context );
428 mXAxis.gridMinorSymbol()->startRender( context );
429 mYAxis.gridMinorSymbol()->startRender( context );
430 mXAxis.gridMajorSymbol()->startRender( context );
431 mYAxis.gridMajorSymbol()->startRender( context );
439 double majorIntervalX = mXAxis.gridIntervalMajor();
440 double minorIntervalX = mXAxis.gridIntervalMinor();
441 double labelIntervalX = mXAxis.labelInterval();
442 double majorIntervalY = mYAxis.gridIntervalMajor();
443 double minorIntervalY = mYAxis.gridIntervalMinor();
444 double labelIntervalY = mYAxis.labelInterval();
445 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
453 std::swap( minX, minY );
454 std::swap( maxX, maxY );
455 std::swap( majorIntervalX, majorIntervalY );
456 std::swap( minorIntervalX, minorIntervalY );
457 std::swap( labelIntervalX, labelIntervalY );
465 const double firstMinorXGrid = std::ceil( minX / minorIntervalX ) * minorIntervalX;
466 const double firstMajorXGrid = std::ceil( minX / majorIntervalX ) * majorIntervalX;
467 const double firstMinorYGrid = std::ceil( minY / minorIntervalY ) * minorIntervalY;
468 const double firstMajorYGrid = std::ceil( minY / majorIntervalY ) * majorIntervalY;
469 const double firstXLabel = labelIntervalX > 0 ? std::ceil( minX / labelIntervalX ) * labelIntervalX : 0;
470 const double firstYLabel = labelIntervalY > 0 ? std::ceil( minY / labelIntervalY ) * labelIntervalY : 0;
472 const QString xAxisSuffix =
xAxis->labelSuffix();
473 const QString yAxisSuffix =
yAxis->labelSuffix();
477 const double xTolerance = minorIntervalX / 100000;
478 const double yTolerance = minorIntervalY / 100000;
482 constexpr int MAX_OBJECTS = 1000;
485 const QStringList categories = plotData.
categories();
488 double maxYAxisLabelWidth = 0;
490 switch (
yAxis->type() )
493 if ( labelIntervalY > 0 )
495 int objectNumber = 0;
496 for (
double currentY = firstYLabel; ; currentY += labelIntervalY, ++objectNumber )
498 const bool hasMoreLabels = objectNumber + 1 < MAX_OBJECTS && ( currentY + labelIntervalY <= maxY && !
qgsDoubleNear( currentY + labelIntervalY, maxY, yTolerance ) );
500 QString text =
yAxis->numericFormat()->formatDouble( currentY, numericContext );
501 switch (
yAxis->labelSuffixPlacement() )
511 if ( currentY == firstYLabel )
516 if ( !hasMoreLabels )
521 if ( currentY == firstYLabel || !hasMoreLabels )
527 if ( !hasMoreLabels )
534 for (
int i = 0; i < categories.size(); i++ )
537 if ( i + 1 >= MAX_OBJECTS )
543 const double chartAreaLeft = plotArea.left();
544 const double chartAreaRight = plotArea.right();
545 const double chartAreaTop = plotArea.top();
546 const double chartAreaBottom = plotArea.bottom();
549 mChartBackgroundSymbol->renderPolygon( QPolygonF(
551 QPointF( chartAreaLeft, chartAreaTop ),
552 QPointF( chartAreaRight, chartAreaTop ),
553 QPointF( chartAreaRight, chartAreaBottom ),
554 QPointF( chartAreaLeft, chartAreaBottom ),
555 QPointF( chartAreaLeft, chartAreaTop )
556 } ),
nullptr,
nullptr, context );
558 const double xScale = ( chartAreaRight - chartAreaLeft ) / ( maxX - minX );
559 const double yScale = ( chartAreaBottom - chartAreaTop ) / ( maxY - minY );
564 switch (
xAxis->type() )
569 double nextMajorXGrid = firstMajorXGrid;
570 int objectNumber = 0;
571 for (
double currentX = firstMinorXGrid; objectNumber < MAX_OBJECTS && ( currentX <= maxX && !
qgsDoubleNear( currentX, maxX, xTolerance ) ); currentX += minorIntervalX, ++objectNumber )
577 nextMajorXGrid += majorIntervalX;
586 QPointF( ( currentX - minX ) * xScale + chartAreaLeft, chartAreaBottom ),
587 QPointF( ( currentX - minX ) * xScale + chartAreaLeft, chartAreaTop )
588 } ),
nullptr, context );
599 switch (
yAxis->type() )
604 double nextMajorYGrid = firstMajorYGrid;
605 int objectNumber = 0;
606 for (
double currentY = firstMinorYGrid; objectNumber < MAX_OBJECTS && ( currentY <= maxY && !
qgsDoubleNear( currentY, maxY, yTolerance ) ); currentY += minorIntervalY, ++objectNumber )
612 nextMajorYGrid += majorIntervalY;
621 QPointF( chartAreaLeft, chartAreaBottom - ( currentY - minY ) * yScale ),
622 QPointF( chartAreaRight, chartAreaBottom - ( currentY - minY ) * yScale )
623 } ),
nullptr, context );
636 switch (
xAxis->type() )
641 if ( labelIntervalX > 0 )
643 int objectNumber = 0;
644 for (
double currentX = firstXLabel; ; currentX += labelIntervalX, ++objectNumber )
646 const bool hasMoreLabels = objectNumber + 1 < MAX_OBJECTS && ( currentX + labelIntervalX <= maxX ||
qgsDoubleNear( currentX + labelIntervalX, maxX, xTolerance ) );
648 QString text =
xAxis->numericFormat()->formatDouble( currentX, numericContext );
649 switch (
xAxis->labelSuffixPlacement() )
659 if ( objectNumber == 0 )
664 if ( !hasMoreLabels )
669 if ( objectNumber == 0 || !hasMoreLabels )
676 if ( !hasMoreLabels )
686 const double categoryWidth = plotArea.width() / categories.size();
687 for (
int i = 0; i < categories.size(); i++ )
689 const double currentX = ( i * categoryWidth ) + categoryWidth / 2.0;
693 if ( i + 1 >= MAX_OBJECTS )
701 switch (
yAxis->type() )
706 if ( labelIntervalY > 0 )
708 int objectNumber = 0;
709 for (
double currentY = firstYLabel; ; currentY += labelIntervalY, ++objectNumber )
711 const bool hasMoreLabels = objectNumber + 1 < MAX_OBJECTS && ( currentY + labelIntervalY <= maxY ||
qgsDoubleNear( currentY + labelIntervalY, maxY, yTolerance ) );
713 QString text =
yAxis->numericFormat()->formatDouble( currentY, numericContext );
714 switch (
yAxis->labelSuffixPlacement() )
724 if ( objectNumber == 0 )
729 if ( !hasMoreLabels )
734 if ( objectNumber == 0 || !hasMoreLabels )
742 chartAreaBottom - ( currentY - minY ) * yScale + height / 2 ),
744 if ( !hasMoreLabels )
754 const double categoryHeight = plotArea.height() / categories.size();
755 for (
int i = 0; i < categories.size(); i++ )
757 const double currentY = ( i * categoryHeight ) + categoryHeight / 2.0;
762 chartAreaBottom - currentY + height / 2 ),
765 if ( i + 1 >= MAX_OBJECTS )
776 mChartBorderSymbol->renderPolygon( QPolygonF(
778 QPointF( chartAreaLeft, chartAreaTop ),
779 QPointF( chartAreaRight, chartAreaTop ),
780 QPointF( chartAreaRight, chartAreaBottom ),
781 QPointF( chartAreaLeft, chartAreaBottom ),
782 QPointF( chartAreaLeft, chartAreaTop )
783 } ),
nullptr,
nullptr, context );
785 mChartBackgroundSymbol->stopRender( context );
786 mChartBorderSymbol->stopRender( context );
787 xAxis->gridMinorSymbol()->stopRender( context );
788 yAxis->gridMinorSymbol()->stopRender( context );
789 xAxis->gridMajorSymbol()->stopRender( context );
790 yAxis->gridMajorSymbol()->stopRender( context );
798 const QStringList categories = plotData.
categories();
804 double majorIntervalX = mXAxis.gridIntervalMajor();
805 double minorIntervalX = mXAxis.gridIntervalMinor();
806 double labelIntervalX = mXAxis.labelInterval();
807 double majorIntervalY = mYAxis.gridIntervalMajor();
808 double minorIntervalY = mYAxis.gridIntervalMinor();
809 double labelIntervalY = mYAxis.labelInterval();
810 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
816 std::swap( minX, minY );
817 std::swap( maxX, maxY );
818 std::swap( majorIntervalX, majorIntervalY );
819 std::swap( minorIntervalX, minorIntervalY );
820 std::swap( labelIntervalX, labelIntervalY );
826 const double firstMinorYGrid = std::ceil( minY / minorIntervalY ) * minorIntervalY;
827 const double firstXLabel = labelIntervalX > 0 ? std::ceil( minX / labelIntervalX ) * labelIntervalX : 0;
829 const QString xAxisSuffix =
xAxis->labelSuffix();
830 const QString yAxisSuffix =
yAxis->labelSuffix();
835 const double xTolerance = minorIntervalX / 100000;
836 const double yTolerance = minorIntervalX / 100000;
838 constexpr int MAX_LABELS = 1000;
842 double maxXAxisLabelHeight = 0;
844 switch (
xAxis->type() )
847 if ( labelIntervalX > 0 )
849 for (
double currentX = firstXLabel; ; currentX += labelIntervalX, labelNumber++ )
851 const bool hasMoreLabels = labelNumber + 1 < MAX_LABELS && ( currentX + labelIntervalX <= maxX ||
qgsDoubleNear( currentX + labelIntervalX, maxX, xTolerance ) );
854 QString text =
xAxis->numericFormat()->formatDouble( currentX, numericContext );
855 switch (
xAxis->labelSuffixPlacement() )
865 if ( labelNumber == 0 )
870 if ( !hasMoreLabels )
875 if ( labelNumber == 0 || !hasMoreLabels )
880 if ( !hasMoreLabels )
887 for (
int i = 0; i < categories.size(); i++ )
890 if ( i + 1 >= MAX_LABELS )
896 double maxYAxisLabelWidth = 0;
899 switch (
yAxis->type() )
902 for (
double currentY = firstMinorYGrid; ; currentY += minorIntervalY, labelNumber ++ )
904 const bool hasMoreLabels = labelNumber + 1 < MAX_LABELS && ( currentY + minorIntervalY <= maxY ||
qgsDoubleNear( currentY + minorIntervalY, maxY, yTolerance ) );
906 const QString text =
yAxis->numericFormat()->formatDouble( currentY, numericContext );
908 if ( yAxisSuffixWidth > 0 )
910 switch (
yAxis->labelSuffixPlacement() )
916 thisLabelWidth += yAxisSuffixWidth;
920 if ( labelNumber == 0 )
921 thisLabelWidth += yAxisSuffixWidth;
925 if ( !hasMoreLabels )
926 thisLabelWidth += yAxisSuffixWidth;
930 if ( labelNumber == 0 || !hasMoreLabels )
931 thisLabelWidth += yAxisSuffixWidth;
935 maxYAxisLabelWidth = std::max( maxYAxisLabelWidth, thisLabelWidth );
936 if ( !hasMoreLabels )
942 for (
int i = 0; i < categories.size(); i++ )
945 if ( i + 1 >= MAX_LABELS )
952 const double rightTextSize = 0;
954 const double topTextSize = 0;
963 return QRectF( leftMargin, topMargin, mSize.width() - rightMargin - leftMargin, mSize.height() - bottomMargin - topMargin );
968 if ( !mSize.isValid() )
972 constexpr double IDEAL_WIDTH = 0.4;
974 constexpr int MAX_LABELS = 1000;
985 auto refineIntervalForAxis = [&](
double axisMinimum,
double axisMaximum,
986 const std::function< double(
double ) > &sizeForLabel,
987 double availableSize,
double idealSizePercent,
double sizeTolerancePercent,
988 double & labelInterval,
double & majorInterval,
double & minorInterval )
990 auto roundBase10 = [](
double value )->
double
992 return std::pow( 10, std::floor( std::log10( value ) ) );
996 double totalSize = 0;
997 int initialLabelCount = 0;
999 const double firstLabelPos = std::ceil( axisMinimum / labelInterval ) * labelInterval;
1001 for (
double currentPos = firstLabelPos; initialLabelCount <= MAX_LABELS && currentPos <= axisMaximum; currentPos += labelInterval, ++initialLabelCount )
1003 totalSize += sizeForLabel( currentPos );
1008 if ( initialLabelCount >= MAX_LABELS || ( totalSize / availableSize < ( idealSizePercent - sizeTolerancePercent ) ) || ( totalSize / availableSize > ( idealSizePercent + sizeTolerancePercent ) ) )
1011 int numberLabelsInitial = std::floor( availableSize / 30 );
1013 double labelIntervalTest = ( axisMaximum - axisMinimum ) / numberLabelsInitial;
1014 double baseValue = roundBase10( labelIntervalTest );
1015 double candidate = baseValue;
1016 int currentMultiplier = 1;
1018 int numberLabels = 0;
1021 const double firstLabelPosition = std::ceil( axisMinimum / candidate ) * candidate;
1022 double totalSize = 0;
1024 for (
double currentPos = firstLabelPosition; currentPos <= axisMaximum; currentPos += candidate )
1026 totalSize += sizeForLabel( currentPos );
1029 if ( numberLabels > MAX_LABELS )
1033 if ( numberLabels <= MAX_LABELS && totalSize <= availableSize * idealSizePercent )
1036 if ( currentMultiplier == 1 )
1037 currentMultiplier = 2;
1038 else if ( currentMultiplier == 2 )
1039 currentMultiplier = 5;
1040 else if ( currentMultiplier == 5 )
1043 currentMultiplier = 1;
1046 candidate = baseValue * currentMultiplier;
1048 labelInterval = candidate;
1049 if ( numberLabels < 10 )
1051 minorInterval = labelInterval / 2;
1052 majorInterval = minorInterval * 4;
1056 minorInterval = labelInterval;
1057 majorInterval = minorInterval * 5;
1062 double minX = mMinX;
1063 double maxX = mMaxX;
1064 double minY = mMinY;
1065 double maxY = mMaxY;
1066 double majorIntervalX = mXAxis.gridIntervalMajor();
1067 double minorIntervalX = mXAxis.gridIntervalMinor();
1068 double labelIntervalX = mXAxis.labelInterval();
1069 double majorIntervalY = mYAxis.gridIntervalMajor();
1070 double minorIntervalY = mYAxis.gridIntervalMinor();
1071 double labelIntervalY = mYAxis.labelInterval();
1072 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
1075 const double availableSize = mFlipAxes ? mSize.height() - topMargin - bottomMargin : mSize.width() - leftMargin - rightMargin;
1076 const QString suffixX = mXAxis.labelSuffix();
1078 refineIntervalForAxis( minX, maxX, [
this, &context, suffixWidth, &numericContext](
double position ) ->
double
1080 const QString text = mXAxis.numericFormat()->formatDouble( position, numericContext );
1085 IDEAL_WIDTH,
TOLERANCE, labelIntervalX, majorIntervalX, minorIntervalX );
1086 mXAxis.setLabelInterval( labelIntervalX );
1087 mXAxis.setGridIntervalMajor( majorIntervalX );
1088 mXAxis.setGridIntervalMinor( minorIntervalX );
1092 const double availableSize = mFlipAxes ? mSize.width() - leftMargin - rightMargin : mSize.height() - topMargin - bottomMargin;
1093 const QString suffixY = mYAxis.labelSuffix();
1094 refineIntervalForAxis( minY, maxY, [
this, &context, suffixY, &numericContext](
double position ) ->
double
1096 const QString text = mYAxis.numericFormat()->formatDouble( position, numericContext );
1101 IDEAL_WIDTH,
TOLERANCE, labelIntervalY, majorIntervalY, minorIntervalY );
1102 mYAxis.setLabelInterval( labelIntervalY );
1103 mYAxis.setGridIntervalMajor( majorIntervalY );
1104 mYAxis.setGridIntervalMinor( minorIntervalY );
1110 return mChartBackgroundSymbol.get();
1115 mChartBackgroundSymbol.reset( symbol );
1120 return mChartBorderSymbol.get();
1125 mChartBorderSymbol.reset( symbol );
1133void 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
1187 majorIntervalX = value;
1197 minorIntervalX = value;
1207 labelIntervalX = value;
1217 majorIntervalY = value;
1227 minorIntervalY = value;
1237 labelIntervalY = value;
1253 auto gridMajor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 150 ), 0.1 );
1254 gridMajor->setPenCapStyle( Qt::FlatCap );
1260 auto gridMinor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 50 ), 0.1 );
1261 gridMinor->setPenCapStyle( Qt::FlatCap );
1267 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer >( QColor( 255, 255, 255 ) );
1273 auto chartBorder = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20 ), 0.1 );
1285 auto chartLine = std::make_unique< QgsSimpleLineSymbolLayer>( QColor( 89, 150, 50, 100 ), 0.6 );
1291 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer>( QColor( 89, 150, 50 ) );
1297 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer>( QColor( 150, 150, 150 ) );
1303 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 ) } );
1321 : mCategories( other.mCategories )
1325 addSeries( series->clone() );
1330 : mSeries( std::move( other.mSeries ) )
1331 , mCategories( std::move( other.mCategories ) )
1337 if (
this != &other )
1341 mCategories = other.mCategories;
1352 if (
this != &other )
1356 mCategories = std::move( other.mCategories );
1357 mSeries = std::move( other.mSeries );
1369 if ( !mSeries.contains(
series ) )
1377 qDeleteAll( mSeries );
1421 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).
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 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 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.
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...
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.
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.
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.