@@ -155,30 +155,34 @@ void QgsStatisticalSummaryDockWidget::refreshStatistics()
155155 if ( ok )
156156 {
157157 int featureCount = selectedOnly ? mLayer ->selectedFeatureCount () : mLayer ->featureCount ();
158- mGatherer = new QgsStatisticsValueGatherer ( mLayer , fit, featureCount, sourceFieldExp );
158+ std::unique_ptr< QgsStatisticsValueGatherer > gatherer = qgis::make_unique< QgsStatisticsValueGatherer > ( mLayer , fit, featureCount, sourceFieldExp );
159159 switch ( mFieldType )
160160 {
161161 case DataType::Numeric:
162- connect ( mGatherer , &QgsStatisticsValueGatherer::taskCompleted, this , &QgsStatisticalSummaryDockWidget::updateNumericStatistics );
162+ connect ( gatherer. get () , &QgsStatisticsValueGatherer::taskCompleted, this , &QgsStatisticalSummaryDockWidget::updateNumericStatistics );
163163 break ;
164164 case DataType::String:
165- connect ( mGatherer , &QgsStatisticsValueGatherer::taskCompleted, this , &QgsStatisticalSummaryDockWidget::updateStringStatistics );
165+ connect ( gatherer. get () , &QgsStatisticsValueGatherer::taskCompleted, this , &QgsStatisticalSummaryDockWidget::updateStringStatistics );
166166 break ;
167167 case DataType::DateTime:
168- connect ( mGatherer , &QgsStatisticsValueGatherer::taskCompleted, this , &QgsStatisticalSummaryDockWidget::updateDateTimeStatistics );
168+ connect ( gatherer. get () , &QgsStatisticsValueGatherer::taskCompleted, this , &QgsStatisticalSummaryDockWidget::updateDateTimeStatistics );
169169 break ;
170170 default :
171- break ;
171+ // don't know how to handle stats for this field!
172+ mStatisticsTable ->setRowCount ( 0 );
173+ return ;
172174 }
173- connect ( mGatherer , &QgsStatisticsValueGatherer::progressChanged, mCalculatingProgressBar , &QProgressBar::setValue );
174- connect ( mCancelButton , &QPushButton::clicked, mGatherer , &QgsStatisticsValueGatherer::cancel );
175+ connect ( gatherer.get (), &QgsStatisticsValueGatherer::progressChanged, mCalculatingProgressBar , &QProgressBar::setValue );
176+ connect ( gatherer.get (), &QgsStatisticsValueGatherer::taskTerminated, this , &QgsStatisticalSummaryDockWidget::gathererFinished );
177+ connect ( mCancelButton , &QPushButton::clicked, gatherer.get (), &QgsStatisticsValueGatherer::cancel );
175178 mCalculatingProgressBar ->setMinimum ( 0 );
176179 mCalculatingProgressBar ->setMaximum ( featureCount > 0 ? 100 : 0 );
177180 mCalculatingProgressBar ->setValue ( 0 );
178181 mCancelButton ->show ();
179182 mCalculatingProgressBar ->show ();
180183
181- QgsApplication::taskManager ()->addTask ( mGatherer );
184+ mGatherer = gatherer.get ();
185+ QgsApplication::taskManager ()->addTask ( gatherer.release () );
182186 }
183187}
184188
0 commit comments