41 QStringList gatheredCategories;
42 QList<QMap<QString, double>> gatheredSeriesCategoriesSum;
43 gatheredSeriesCategoriesSum.reserve( mSeriesDetails.size() );
44 std::vector<std::unique_ptr<QgsXyPlotSeries>> gatheredSeries;
45 gatheredSeries.reserve( mSeriesDetails.size() );
46 for (
int i = 0; i < mSeriesDetails.size(); i++ )
48 auto series = std::make_unique<QgsXyPlotSeries>();
49 gatheredSeries.emplace_back( std::move( series ) );
50 gatheredSeriesCategoriesSum << QMap<QString, double>();
53 QMap<QString, QgsExpression> preparedExpressions;
55 while (
mIterator.nextFeature( feature ) )
63 if ( !seriesDetails.filterExpression.isEmpty() )
65 auto filterExpressionIt = preparedExpressions.find( seriesDetails.filterExpression );
66 if ( filterExpressionIt == preparedExpressions.end() )
68 filterExpressionIt = preparedExpressions.insert( seriesDetails.filterExpression,
QgsExpression( seriesDetails.filterExpression ) );
78 auto xExpressionIt = preparedExpressions.find( seriesDetails.xExpression );
79 if ( xExpressionIt == preparedExpressions.end() )
81 xExpressionIt = preparedExpressions.insert( seriesDetails.xExpression,
QgsExpression( seriesDetails.xExpression ) );
85 auto yExpressionIt = preparedExpressions.find( seriesDetails.yExpression );
86 if ( yExpressionIt == preparedExpressions.end() )
88 yExpressionIt = preparedExpressions.insert( seriesDetails.yExpression,
QgsExpression( seriesDetails.yExpression ) );
108 gatheredSeries[seriesIndex]->append( x, y );
115 if ( category.isEmpty() )
121 if ( !mPredefinedCategories.isEmpty() )
123 x = mPredefinedCategories.indexOf( category );
127 if ( !gatheredCategories.contains( category ) )
129 gatheredCategories << category;
131 x = gatheredCategories.indexOf( category );
139 auto gatheredSeriesCategoriesSumIt = gatheredSeriesCategoriesSum[seriesIndex].find( category );
140 if ( gatheredSeriesCategoriesSumIt == gatheredSeriesCategoriesSum[seriesIndex].end() )
142 gatheredSeriesCategoriesSumIt = gatheredSeriesCategoriesSum[seriesIndex].insert( category, y );
143 *gatheredSeriesCategoriesSumIt = y;
147 *gatheredSeriesCategoriesSumIt += y;
157 switch ( mXAxisType )
161 int seriesIndex = -1;
162 for ( QMap<QString, double> &gatheredCategoriesSum : gatheredSeriesCategoriesSum )
165 if ( !mPredefinedCategories.isEmpty() )
167 for (
int i = 0; i < mPredefinedCategories.size(); i++ )
169 auto gatheredCategoriesSumIt = gatheredCategoriesSum.find( mPredefinedCategories[i] );
170 if ( gatheredCategoriesSumIt != gatheredCategoriesSum.end() )
172 gatheredSeries[seriesIndex]->append( i, *gatheredCategoriesSumIt );
176 else if ( !gatheredCategories.isEmpty() )
178 for (
int i = 0; i < gatheredCategories.size(); i++ )
180 auto gatheredCategoriesSumIt = gatheredCategoriesSum.find( gatheredCategories[i] );
181 if ( gatheredCategoriesSumIt != gatheredCategoriesSum.end() )
183 gatheredSeries[seriesIndex]->append( i, *gatheredCategoriesSumIt );
189 mData.setCategories( !mPredefinedCategories.isEmpty() ? mPredefinedCategories : gatheredCategories );
198 for ( std::unique_ptr<QgsXyPlotSeries> &series : gatheredSeries )
200 series->setName( mSeriesDetails[seriesIndex++].name );
201 mData.addSeries( series.release() );