45 QStringList gatheredCategories;
46 QList<QMap<QString, double>> gatheredSeriesCategoriesSum;
47 gatheredSeriesCategoriesSum.reserve( mSeriesDetails.size() );
48 std::vector<std::unique_ptr<QgsXyPlotSeries>> gatheredSeries;
49 gatheredSeries.reserve( mSeriesDetails.size() );
50 for (
int i = 0; i < mSeriesDetails.size(); i++ )
52 auto series = std::make_unique<QgsXyPlotSeries>();
53 gatheredSeries.emplace_back( std::move( series ) );
54 gatheredSeriesCategoriesSum << QMap<QString, double>();
57 QMap<QString, QgsExpression> preparedExpressions;
59 while (
mIterator.nextFeature( feature ) )
67 if ( !seriesDetails.filterExpression.isEmpty() )
69 auto filterExpressionIt = preparedExpressions.find( seriesDetails.filterExpression );
70 if ( filterExpressionIt == preparedExpressions.end() )
72 filterExpressionIt = preparedExpressions.insert( seriesDetails.filterExpression,
QgsExpression( seriesDetails.filterExpression ) );
82 auto xExpressionIt = preparedExpressions.find( seriesDetails.xExpression );
83 if ( xExpressionIt == preparedExpressions.end() )
85 xExpressionIt = preparedExpressions.insert( seriesDetails.xExpression,
QgsExpression( seriesDetails.xExpression ) );
89 auto yExpressionIt = preparedExpressions.find( seriesDetails.yExpression );
90 if ( yExpressionIt == preparedExpressions.end() )
92 yExpressionIt = preparedExpressions.insert( seriesDetails.yExpression,
QgsExpression( seriesDetails.yExpression ) );
102 switch ( mXAxisType )
112 gatheredSeries[seriesIndex]->append( x, y );
119 if ( category.isEmpty() )
125 if ( !mPredefinedCategories.isEmpty() )
127 x = mPredefinedCategories.indexOf( category );
131 if ( !gatheredCategories.contains( category ) )
133 gatheredCategories << category;
135 x = gatheredCategories.indexOf( category );
143 auto gatheredSeriesCategoriesSumIt = gatheredSeriesCategoriesSum[seriesIndex].find( category );
144 if ( gatheredSeriesCategoriesSumIt == gatheredSeriesCategoriesSum[seriesIndex].end() )
146 gatheredSeriesCategoriesSumIt = gatheredSeriesCategoriesSum[seriesIndex].insert( category, y );
147 *gatheredSeriesCategoriesSumIt = y;
151 *gatheredSeriesCategoriesSumIt += y;
161 switch ( mXAxisType )
165 int seriesIndex = -1;
166 for ( QMap<QString, double> &gatheredCategoriesSum : gatheredSeriesCategoriesSum )
169 if ( !mPredefinedCategories.isEmpty() )
171 for (
int i = 0; i < mPredefinedCategories.size(); i++ )
173 auto gatheredCategoriesSumIt = gatheredCategoriesSum.find( mPredefinedCategories[i] );
174 if ( gatheredCategoriesSumIt != gatheredCategoriesSum.end() )
176 gatheredSeries[seriesIndex]->append( i, *gatheredCategoriesSumIt );
180 else if ( !gatheredCategories.isEmpty() )
182 for (
int i = 0; i < gatheredCategories.size(); i++ )
184 auto gatheredCategoriesSumIt = gatheredCategoriesSum.find( gatheredCategories[i] );
185 if ( gatheredCategoriesSumIt != gatheredCategoriesSum.end() )
187 gatheredSeries[seriesIndex]->append( i, *gatheredCategoriesSumIt );
193 mData.setCategories( !mPredefinedCategories.isEmpty() ? mPredefinedCategories : gatheredCategories );
202 for ( std::unique_ptr<QgsXyPlotSeries> &series : gatheredSeries )
204 series->setName( mSeriesDetails[seriesIndex++].name );
205 mData.addSeries( series.release() );