43 element.setAttribute( QStringLiteral(
"plotType" ),
type() );
45 QDomElement dataDefinedPropertiesElement = document.createElement( QStringLiteral(
"dataDefinedProperties" ) );
47 element.appendChild( dataDefinedPropertiesElement );
54 QDomElement dataDefinedPropertiesElement = element.firstChildElement( QStringLiteral(
"dataDefinedProperties" ) );
60void QgsPlot::initPropertyDefinitions()
62 if ( !sPropertyDefinitions.isEmpty() )
86 QgsPlot::initPropertyDefinitions();
87 return sPropertyDefinitions;
116 element.setAttribute( QStringLiteral(
"gridIntervalMinor" ),
qgsDoubleToString( mGridIntervalMinor ) );
117 element.setAttribute( QStringLiteral(
"gridIntervalMajor" ),
qgsDoubleToString( mGridIntervalMajor ) );
118 element.setAttribute( QStringLiteral(
"labelInterval" ),
qgsDoubleToString( mLabelInterval ) );
119 element.setAttribute( QStringLiteral(
"suffix" ), mLabelSuffix );
120 element.setAttribute( QStringLiteral(
"suffixPlacement" ),
qgsEnumValueToKey( mSuffixPlacement ) );
122 QDomElement numericFormatElement = document.createElement( QStringLiteral(
"numericFormat" ) );
123 mNumericFormat->writeXml( numericFormatElement, document, context );
124 element.appendChild( numericFormatElement );
126 QDomElement gridMajorElement = document.createElement( QStringLiteral(
"gridMajorSymbol" ) );
128 element.appendChild( gridMajorElement );
129 QDomElement gridMinorElement = document.createElement( QStringLiteral(
"gridMinorSymbol" ) );
131 element.appendChild( gridMinorElement );
133 QDomElement textFormatElement = document.createElement( QStringLiteral(
"textFormat" ) );
134 textFormatElement.appendChild( mLabelTextFormat.writeXml( document, context ) );
135 element.appendChild( textFormatElement );
143 mGridIntervalMinor = element.attribute( QStringLiteral(
"gridIntervalMinor" ) ).toDouble();
144 mGridIntervalMajor = element.attribute( QStringLiteral(
"gridIntervalMajor" ) ).toDouble();
145 mLabelInterval = element.attribute( QStringLiteral(
"labelInterval" ) ).toDouble();
147 mLabelSuffix = element.attribute( QStringLiteral(
"suffix" ) );
150 const QDomElement numericFormatElement = element.firstChildElement( QStringLiteral(
"numericFormat" ) );
153 const QDomElement gridMajorElement = element.firstChildElement( QStringLiteral(
"gridMajorSymbol" ) ).firstChildElement( QStringLiteral(
"symbol" ) );
155 const QDomElement gridMinorElement = element.firstChildElement( QStringLiteral(
"gridMinorSymbol" ) ).firstChildElement( QStringLiteral(
"symbol" ) );
158 const QDomElement textFormatElement = element.firstChildElement( QStringLiteral(
"textFormat" ) );
159 mLabelTextFormat.readXml( textFormatElement, context );
166 return mNumericFormat.get();
171 mNumericFormat.reset( format );
181 mLabelSuffix = suffix;
186 return mSuffixPlacement;
191 mSuffixPlacement = placement;
196 return mGridMajorSymbol.get();
201 mGridMajorSymbol.reset( symbol );
206 return mGridMinorSymbol.get();
211 mGridMinorSymbol.reset( symbol );
216 return mLabelTextFormat;
221 mLabelTextFormat = format;
230 : mMargins( 2, 2, 2, 2 )
238 element.setAttribute( QStringLiteral(
"margins" ), mMargins.toString() );
289 return QRectF( leftMargin, topMargin, mSize.width() - rightMargin - leftMargin, mSize.height() - bottomMargin - topMargin );
373 QDomElement xAxisElement = document.createElement( QStringLiteral(
"xAxis" ) );
374 mXAxis.writeXml( xAxisElement, document, context );
375 element.appendChild( xAxisElement );
376 QDomElement yAxisElement = document.createElement( QStringLiteral(
"yAxis" ) );
377 mYAxis.writeXml( yAxisElement, document, context );
378 element.appendChild( yAxisElement );
380 QDomElement backgroundElement = document.createElement( QStringLiteral(
"backgroundSymbol" ) );
382 element.appendChild( backgroundElement );
383 QDomElement borderElement = document.createElement( QStringLiteral(
"borderSymbol" ) );
385 element.appendChild( borderElement );
394 mMinX = element.attribute( QStringLiteral(
"minX" ) ).toDouble();
395 mMaxX = element.attribute( QStringLiteral(
"maxX" ) ).toDouble();
396 mMinY = element.attribute( QStringLiteral(
"minY" ) ).toDouble();
397 mMaxY = element.attribute( QStringLiteral(
"maxY" ) ).toDouble();
399 const QDomElement xAxisElement = element.firstChildElement( QStringLiteral(
"xAxis" ) );
400 mXAxis.readXml( xAxisElement, context );
401 const QDomElement yAxisElement = element.firstChildElement( QStringLiteral(
"yAxis" ) );
402 mYAxis.readXml( yAxisElement, context );
404 const QDomElement backgroundElement = element.firstChildElement( QStringLiteral(
"backgroundSymbol" ) ).firstChildElement( QStringLiteral(
"symbol" ) );
406 const QDomElement borderElement = element.firstChildElement( QStringLiteral(
"borderSymbol" ) ).firstChildElement( QStringLiteral(
"symbol" ) );
417 mChartBackgroundSymbol->startRender( context );
418 mChartBorderSymbol->startRender( context );
419 mXAxis.gridMinorSymbol()->startRender( context );
420 mYAxis.gridMinorSymbol()->startRender( context );
421 mXAxis.gridMajorSymbol()->startRender( context );
422 mYAxis.gridMajorSymbol()->startRender( context );
430 double majorIntervalX = mXAxis.gridIntervalMajor();
431 double minorIntervalX = mXAxis.gridIntervalMinor();
432 double labelIntervalX = mXAxis.labelInterval();
433 double majorIntervalY = mYAxis.gridIntervalMajor();
434 double minorIntervalY = mYAxis.gridIntervalMinor();
435 double labelIntervalY = mYAxis.labelInterval();
436 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
438 const double firstMinorXGrid = std::ceil( minX / minorIntervalX ) * minorIntervalX;
439 const double firstMajorXGrid = std::ceil( minX / majorIntervalX ) * majorIntervalX;
440 const double firstMinorYGrid = std::ceil( minY / minorIntervalY ) * minorIntervalY;
441 const double firstMajorYGrid = std::ceil( minY / majorIntervalY ) * majorIntervalY;
442 const double firstXLabel = labelIntervalX > 0 ? std::ceil( minX / labelIntervalX ) * labelIntervalX : 0;
443 const double firstYLabel = labelIntervalY > 0 ? std::ceil( minY / labelIntervalY ) * labelIntervalY : 0;
445 const QString xAxisSuffix = mXAxis.labelSuffix();
446 const QString yAxisSuffix = mYAxis.labelSuffix();
450 const double xTolerance = minorIntervalX / 100000;
451 const double yTolerance = minorIntervalY / 100000;
456 const QStringList categories = plotData.
categories();
459 double maxYAxisLabelWidth = 0;
461 switch ( mYAxis.type() )
464 if ( labelIntervalY > 0 )
466 for (
double currentY = firstYLabel; ; currentY += labelIntervalY )
468 const bool hasMoreLabels = currentY + labelIntervalY <= maxY && !
qgsDoubleNear( currentY + labelIntervalY, maxY, yTolerance );
470 QString text = mYAxis.numericFormat()->formatDouble( currentY, numericContext );
471 switch ( mYAxis.labelSuffixPlacement() )
481 if ( currentY == firstYLabel )
486 if ( !hasMoreLabels )
491 if ( currentY == firstYLabel || !hasMoreLabels )
497 if ( !hasMoreLabels )
504 for (
int i = 0; i < categories.size(); i++ )
506 maxYAxisLabelWidth = std::max( maxYAxisLabelWidth,
QgsTextRenderer::textWidth( context, mYAxis.textFormat(), { categories.at( i ) } ) );
511 const double chartAreaLeft = plotArea.left();
512 const double chartAreaRight = plotArea.right();
513 const double chartAreaTop = plotArea.top();
514 const double chartAreaBottom = plotArea.bottom();
517 mChartBackgroundSymbol->renderPolygon( QPolygonF(
519 QPointF( chartAreaLeft, chartAreaTop ),
520 QPointF( chartAreaRight, chartAreaTop ),
521 QPointF( chartAreaRight, chartAreaBottom ),
522 QPointF( chartAreaLeft, chartAreaBottom ),
523 QPointF( chartAreaLeft, chartAreaTop )
524 } ),
nullptr,
nullptr, context );
526 const double xScale = ( chartAreaRight - chartAreaLeft ) / ( maxX - minX );
527 const double yScale = ( chartAreaBottom - chartAreaTop ) / ( maxY - minY );
529 constexpr int MAX_OBJECTS = 1000;
534 switch ( mXAxis.type() )
539 double nextMajorXGrid = firstMajorXGrid;
540 int objectNumber = 0;
541 for (
double currentX = firstMinorXGrid; objectNumber < MAX_OBJECTS && ( currentX <= maxX && !
qgsDoubleNear( currentX, maxX, xTolerance ) ); currentX += minorIntervalX, ++objectNumber )
547 nextMajorXGrid += majorIntervalX;
552 QgsLineSymbol *currentGridSymbol = isMinor ? mXAxis.gridMinorSymbol() : mXAxis.gridMajorSymbol();
556 QPointF( ( currentX - minX ) * xScale + chartAreaLeft, chartAreaBottom ),
557 QPointF( ( currentX - minX ) * xScale + chartAreaLeft, chartAreaTop )
558 } ),
nullptr, context );
569 switch ( mYAxis.type() )
574 double nextMajorYGrid = firstMajorYGrid;
575 int objectNumber = 0;
576 for (
double currentY = firstMinorYGrid; objectNumber < MAX_OBJECTS && ( currentY <= maxY && !
qgsDoubleNear( currentY, maxY, yTolerance ) ); currentY += minorIntervalY, ++objectNumber )
582 nextMajorYGrid += majorIntervalY;
587 QgsLineSymbol *currentGridSymbol = isMinor ? mYAxis.gridMinorSymbol() : mYAxis.gridMajorSymbol();
591 QPointF( chartAreaLeft, chartAreaBottom - ( currentY - minY ) * yScale ),
592 QPointF( chartAreaRight, chartAreaBottom - ( currentY - minY ) * yScale )
593 } ),
nullptr, context );
606 switch ( mXAxis.type() )
611 int objectNumber = 0;
612 if ( labelIntervalX > 0 )
614 for (
double currentX = firstXLabel; ; currentX += labelIntervalX, ++objectNumber )
616 const bool hasMoreLabels = objectNumber + 1 < MAX_OBJECTS && ( currentX + labelIntervalX <= maxX ||
qgsDoubleNear( currentX + labelIntervalX, maxX, xTolerance ) );
618 QString text = mXAxis.numericFormat()->formatDouble( currentX, numericContext );
619 switch ( mXAxis.labelSuffixPlacement() )
629 if ( objectNumber == 0 )
634 if ( !hasMoreLabels )
639 if ( objectNumber == 0 || !hasMoreLabels )
646 if ( !hasMoreLabels )
656 const double categoryWidth = plotArea.width() / categories.size();
657 for (
int i = 0; i < categories.size(); i++ )
659 const double currentX = ( i * categoryWidth ) + categoryWidth / 2.0;
669 switch ( mYAxis.type() )
674 int objectNumber = 0;
675 if ( labelIntervalY > 0 )
677 for (
double currentY = firstYLabel; ; currentY += labelIntervalY, ++objectNumber )
679 const bool hasMoreLabels = objectNumber + 1 < MAX_OBJECTS && ( currentY + labelIntervalY <= maxY ||
qgsDoubleNear( currentY + labelIntervalY, maxY, yTolerance ) );
681 QString text = mYAxis.numericFormat()->formatDouble( currentY, numericContext );
682 switch ( mYAxis.labelSuffixPlacement() )
692 if ( objectNumber == 0 )
697 if ( !hasMoreLabels )
702 if ( objectNumber == 0 || !hasMoreLabels )
710 chartAreaBottom - ( currentY - minY ) * yScale + height / 2 ),
712 if ( !hasMoreLabels )
722 const double categoryHeight = plotArea.height() / categories.size();
723 for (
int i = 0; i < categories.size(); i++ )
725 const double currentY = ( i * categoryHeight ) + categoryHeight / 2.0;
730 chartAreaBottom - currentY + height / 2 ),
741 mChartBorderSymbol->renderPolygon( QPolygonF(
743 QPointF( chartAreaLeft, chartAreaTop ),
744 QPointF( chartAreaRight, chartAreaTop ),
745 QPointF( chartAreaRight, chartAreaBottom ),
746 QPointF( chartAreaLeft, chartAreaBottom ),
747 QPointF( chartAreaLeft, chartAreaTop )
748 } ),
nullptr,
nullptr, context );
750 mChartBackgroundSymbol->stopRender( context );
751 mChartBorderSymbol->stopRender( context );
752 mXAxis.gridMinorSymbol()->stopRender( context );
753 mYAxis.gridMinorSymbol()->stopRender( context );
754 mXAxis.gridMajorSymbol()->stopRender( context );
755 mYAxis.gridMajorSymbol()->stopRender( context );
766 double majorIntervalX = mXAxis.gridIntervalMajor();
767 double minorIntervalX = mXAxis.gridIntervalMinor();
768 double labelIntervalX = mXAxis.labelInterval();
769 double majorIntervalY = mYAxis.gridIntervalMajor();
770 double minorIntervalY = mYAxis.gridIntervalMinor();
771 double labelIntervalY = mYAxis.labelInterval();
772 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
777 const double firstMinorYGrid = std::ceil( minY / minorIntervalY ) * minorIntervalY;
778 const double firstXLabel = labelIntervalX > 0 ? std::ceil( minX / labelIntervalX ) * labelIntervalX : 0;
780 const QString xAxisSuffix = mXAxis.labelSuffix();
781 const QString yAxisSuffix = mYAxis.labelSuffix();
782 const double yAxisSuffixWidth = yAxisSuffix.isEmpty() ? 0 :
QgsTextRenderer::textWidth( context, mYAxis.textFormat(), { yAxisSuffix } );
786 const double xTolerance = minorIntervalX / 100000;
787 const double yTolerance = minorIntervalX / 100000;
789 constexpr int MAX_LABELS = 1000;
793 double maxXAxisLabelHeight = 0;
795 if ( labelIntervalX > 0 )
797 for (
double currentX = firstXLabel; ; currentX += labelIntervalX, labelNumber++ )
799 const bool hasMoreLabels = labelNumber + 1 < MAX_LABELS && ( currentX + labelIntervalX <= maxX ||
qgsDoubleNear( currentX + labelIntervalX, maxX, xTolerance ) );
802 QString text = mXAxis.numericFormat()->formatDouble( currentX, numericContext );
803 switch ( mXAxis.labelSuffixPlacement() )
813 if ( labelNumber == 0 )
818 if ( !hasMoreLabels )
823 if ( labelNumber == 0 || !hasMoreLabels )
828 if ( !hasMoreLabels )
833 double maxYAxisLabelWidth = 0;
836 for (
double currentY = firstMinorYGrid; ; currentY += minorIntervalY, labelNumber ++ )
838 const bool hasMoreLabels = labelNumber + 1 < MAX_LABELS && ( currentY + minorIntervalY <= maxY ||
qgsDoubleNear( currentY + minorIntervalY, maxY, yTolerance ) );
840 const QString text = mYAxis.numericFormat()->formatDouble( currentY, numericContext );
842 if ( yAxisSuffixWidth > 0 )
844 switch ( mYAxis.labelSuffixPlacement() )
850 thisLabelWidth += yAxisSuffixWidth;
854 if ( labelNumber == 0 )
855 thisLabelWidth += yAxisSuffixWidth;
859 if ( !hasMoreLabels )
860 thisLabelWidth += yAxisSuffixWidth;
864 if ( labelNumber == 0 || !hasMoreLabels )
865 thisLabelWidth += yAxisSuffixWidth;
869 maxYAxisLabelWidth = std::max( maxYAxisLabelWidth, thisLabelWidth );
870 if ( !hasMoreLabels )
875 const double rightTextSize = 0;
877 const double topTextSize = 0;
886 return QRectF( leftMargin, topMargin, mSize.width() - rightMargin - leftMargin, mSize.height() - bottomMargin - topMargin );
891 if ( !mSize.isValid() )
895 constexpr double IDEAL_WIDTH = 0.4;
896 constexpr double TOLERANCE = 0.04;
897 constexpr int MAX_LABELS = 1000;
906 const double availableWidth = mSize.width() - leftMargin - rightMargin;
907 const double availableHeight = mSize.height() - topMargin - bottomMargin;
911 auto refineIntervalForAxis = [&](
double axisMinimum,
double axisMaximum,
912 const std::function< double(
double ) > &sizeForLabel,
913 double availableSize,
double idealSizePercent,
double sizeTolerancePercent,
914 double & labelInterval,
double & majorInterval,
double & minorInterval )
916 auto roundBase10 = [](
double value )->
double
918 return std::pow( 10, std::floor( std::log10( value ) ) );
922 double totalSize = 0;
923 int initialLabelCount = 0;
925 const double firstLabelPos = std::ceil( axisMinimum / labelInterval ) * labelInterval;
927 for (
double currentPos = firstLabelPos; initialLabelCount <= MAX_LABELS && currentPos <= axisMaximum; currentPos += labelInterval, ++initialLabelCount )
929 totalSize += sizeForLabel( currentPos );
934 if ( initialLabelCount >= MAX_LABELS || ( totalSize / availableSize < ( idealSizePercent - sizeTolerancePercent ) ) || ( totalSize / availableSize > ( idealSizePercent + sizeTolerancePercent ) ) )
937 int numberLabelsInitial = std::floor( availableSize / 30 );
939 double labelIntervalTest = ( axisMaximum - axisMinimum ) / numberLabelsInitial;
940 double baseValue = roundBase10( labelIntervalTest );
941 double candidate = baseValue;
942 int currentMultiplier = 1;
944 int numberLabels = 0;
947 const double firstLabelPosition = std::ceil( axisMinimum / candidate ) * candidate;
948 double totalSize = 0;
950 for (
double currentPos = firstLabelPosition; currentPos <= axisMaximum; currentPos += candidate )
952 totalSize += sizeForLabel( currentPos );
955 if ( numberLabels > MAX_LABELS )
959 if ( numberLabels <= MAX_LABELS && totalSize <= availableSize * idealSizePercent )
962 if ( currentMultiplier == 1 )
963 currentMultiplier = 2;
964 else if ( currentMultiplier == 2 )
965 currentMultiplier = 5;
966 else if ( currentMultiplier == 5 )
969 currentMultiplier = 1;
972 candidate = baseValue * currentMultiplier;
974 labelInterval = candidate;
975 if ( numberLabels < 10 )
977 minorInterval = labelInterval / 2;
978 majorInterval = minorInterval * 4;
982 minorInterval = labelInterval;
983 majorInterval = minorInterval * 5;
992 double majorIntervalX = mXAxis.gridIntervalMajor();
993 double minorIntervalX = mXAxis.gridIntervalMinor();
994 double labelIntervalX = mXAxis.labelInterval();
995 double majorIntervalY = mYAxis.gridIntervalMajor();
996 double minorIntervalY = mYAxis.gridIntervalMinor();
997 double labelIntervalY = mYAxis.labelInterval();
998 applyDataDefinedProperties( context, minX, maxX, minY, maxY, majorIntervalX, minorIntervalX, labelIntervalX, majorIntervalY, minorIntervalY, labelIntervalY );
1001 const QString suffixX = mXAxis.labelSuffix();
1003 refineIntervalForAxis( minX, maxX, [
this, &context, suffixWidth, &numericContext](
double position ) ->
double
1005 const QString text = mXAxis.numericFormat()->formatDouble( position, numericContext );
1010 IDEAL_WIDTH, TOLERANCE, labelIntervalX, majorIntervalX, minorIntervalX );
1011 mXAxis.setLabelInterval( labelIntervalX );
1012 mXAxis.setGridIntervalMajor( majorIntervalX );
1013 mXAxis.setGridIntervalMinor( minorIntervalX );
1017 const QString suffixY = mYAxis.labelSuffix();
1018 refineIntervalForAxis( minY, maxY, [
this, &context, suffixY, &numericContext](
double position ) ->
double
1020 const QString text = mYAxis.numericFormat()->formatDouble( position, numericContext );
1025 IDEAL_WIDTH, TOLERANCE, labelIntervalY, majorIntervalY, minorIntervalY );
1026 mYAxis.setLabelInterval( labelIntervalY );
1027 mYAxis.setGridIntervalMajor( majorIntervalY );
1028 mYAxis.setGridIntervalMinor( minorIntervalY );
1034 return mChartBackgroundSymbol.get();
1039 mChartBackgroundSymbol.reset( symbol );
1044 return mChartBorderSymbol.get();
1049 mChartBorderSymbol.reset( symbol );
1052void 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
1106 majorIntervalX = value;
1116 minorIntervalX = value;
1126 labelIntervalX = value;
1136 majorIntervalY = value;
1146 minorIntervalY = value;
1156 labelIntervalY = value;
1172 auto gridMajor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 150 ), 0.1 );
1173 gridMajor->setPenCapStyle( Qt::FlatCap );
1179 auto gridMinor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 50 ), 0.1 );
1180 gridMinor->setPenCapStyle( Qt::FlatCap );
1186 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer >( QColor( 255, 255, 255 ) );
1192 auto chartBorder = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20 ), 0.1 );
1204 auto chartLine = std::make_unique< QgsSimpleLineSymbolLayer>( QColor( 89, 150, 50, 100 ), 0.6 );
1210 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer>( QColor( 89, 150, 50 ) );
1216 auto chartFill = std::make_unique< QgsSimpleFillSymbolLayer>( QColor( 150, 150, 150 ) );
1222 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 ) } );
1240 : mCategories( other.mCategories )
1244 addSeries( series->clone() );
1249 : mSeries( std::move( other.mSeries ) )
1250 , mCategories( std::move( other.mCategories ) )
1256 if (
this != &other )
1260 mCategories = other.mCategories;
1271 if (
this != &other )
1275 mCategories = std::move( other.mCategories );
1276 mSeries = std::move( other.mSeries );
1288 if ( !mSeries.contains(
series ) )
1296 qDeleteAll( mSeries );
1340 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.