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 ) )
62 if ( !seriesDetails.filterExpression.isEmpty() )
64 auto filterExpressionIt = preparedExpressions.find( seriesDetails.filterExpression );
65 if ( filterExpressionIt == preparedExpressions.end() )
67 filterExpressionIt = preparedExpressions.insert( seriesDetails.filterExpression,
QgsExpression( seriesDetails.filterExpression ) );
77 auto xExpressionIt = preparedExpressions.find( seriesDetails.xExpression );
78 if ( xExpressionIt == preparedExpressions.end() )
80 xExpressionIt = preparedExpressions.insert( seriesDetails.xExpression,
QgsExpression( seriesDetails.xExpression ) );
84 auto yExpressionIt = preparedExpressions.find( seriesDetails.yExpression );
85 if ( yExpressionIt == preparedExpressions.end() )
87 yExpressionIt = preparedExpressions.insert( seriesDetails.yExpression,
QgsExpression( seriesDetails.yExpression ) );
107 gatheredSeries[seriesIndex]->append( x, y );
114 if ( category.isEmpty() )
120 if ( !mPredefinedCategories.isEmpty() )
122 x = mPredefinedCategories.indexOf( category );
126 if ( !gatheredCategories.contains( category ) )
128 gatheredCategories << category;
130 x = gatheredCategories.indexOf( category );
138 auto gatheredSeriesCategoriesSumIt = gatheredSeriesCategoriesSum[seriesIndex].find( category );
139 if ( gatheredSeriesCategoriesSumIt == gatheredSeriesCategoriesSum[seriesIndex].end() )
141 gatheredSeriesCategoriesSumIt = gatheredSeriesCategoriesSum[seriesIndex].insert( category, y );
142 *gatheredSeriesCategoriesSumIt = y;
146 *gatheredSeriesCategoriesSumIt += y;
157 switch ( mXAxisType )
162 for ( QMap<QString, double> &gatheredCategoriesSum : gatheredSeriesCategoriesSum )
164 if ( !mPredefinedCategories.isEmpty() )
166 for (
int i = 0; i < mPredefinedCategories.size(); i++ )
168 auto gatheredCategoriesSumIt = gatheredCategoriesSum.find( mPredefinedCategories[i] );
169 if ( gatheredCategoriesSumIt != gatheredCategoriesSum.end() )
171 gatheredSeries[seriesIndex]->append( i, *gatheredCategoriesSumIt );
175 else if ( !gatheredCategories.isEmpty() )
177 for (
int i = 0; i < gatheredCategories.size(); i++ )
179 auto gatheredCategoriesSumIt = gatheredCategoriesSum.find( gatheredCategories[i] );
180 if ( gatheredCategoriesSumIt != gatheredCategoriesSum.end() )
182 gatheredSeries[seriesIndex]->append( i, *gatheredCategoriesSumIt );
189 mData.setCategories( !mPredefinedCategories.isEmpty() ? mPredefinedCategories : gatheredCategories );
197 for ( std::unique_ptr<QgsXyPlotSeries> &series : gatheredSeries )
199 mData.addSeries( series.release() );