Skip to content
Permalink
Browse files

move definition to source

  • Loading branch information
3nids committed Oct 5, 2018
1 parent 775d603 commit f404751e5bcb2e188ed7d4d8dd5308cf6fa67bfd
Showing with 51 additions and 47 deletions.
  1. +48 −0 src/app/qgsstatisticalsummarydockwidget.cpp
  2. +3 −47 src/app/qgsstatisticalsummarydockwidget.h
@@ -21,6 +21,8 @@
#include "qgsstatisticalsummarydockwidget.h"
#include "qgsstatisticalsummary.h"
#include "qgsvectorlayer.h"
#include "qgsfeedback.h"
#include "qgsvectorlayerutils.h"

#include <QTableWidget>
#include <QAction>
@@ -578,3 +580,49 @@ QgsStatisticalSummaryDockWidget::DataType QgsStatisticalSummaryDockWidget::field

return DataType::Numeric;
}

QgsStatisticsValueGatherer::QgsStatisticsValueGatherer( QgsVectorLayer *layer, const QgsFeatureIterator &fit, long featureCount, const QString &sourceFieldExp )
: QgsTask( tr( "Fetching statistic values" ) )
, mFeatureIterator( fit )
, mFeatureCount( featureCount )
, mFieldExpression( sourceFieldExp )
{
mFieldIndex = layer->fields().lookupField( mFieldExpression );
if ( mFieldIndex == -1 )
{
// use expression, already validated
mExpression.reset( new QgsExpression( mFieldExpression ) );
mContext.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( layer ) );
}
}

bool QgsStatisticsValueGatherer::run()
{
QgsFeature f;
int current = 0;
while ( mFeatureIterator.nextFeature( f ) )
{
if ( mExpression )
{
mContext.setFeature( f );
QVariant v = mExpression->evaluate( &mContext );
mValues << v;
}
else
{
mValues << f.attribute( mFieldIndex );
}

if ( isCanceled() )
{
return false;
}

current++;
if ( mFeatureCount > 0 )
{
setProgress( 100.0 * static_cast< double >( current ) / mFeatureCount );
}
}
return true;
}
@@ -23,8 +23,6 @@
#include "qgsdatetimestatisticalsummary.h"
#include "qgsdockwidget.h"
#include "qgsfeatureiterator.h"
#include "qgsfeedback.h"
#include "qgsvectorlayerutils.h"
#include "qgstaskmanager.h"

#include "qgis_app.h"
@@ -47,51 +45,9 @@ class QgsStatisticsValueGatherer : public QgsTask
Q_OBJECT

public:
QgsStatisticsValueGatherer( QgsVectorLayer *layer, const QgsFeatureIterator &fit, long featureCount, const QString &sourceFieldExp )
: QgsTask( tr( "Fetching statistic values" ) )
, mFeatureIterator( fit )
, mFeatureCount( featureCount )
, mFieldExpression( sourceFieldExp )
{
mFieldIndex = layer->fields().lookupField( mFieldExpression );
if ( mFieldIndex == -1 )
{
// use expression, already validated
mExpression.reset( new QgsExpression( mFieldExpression ) );
mContext.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( layer ) );
}
}

bool run() override
{
QgsFeature f;
int current = 0;
while ( mFeatureIterator.nextFeature( f ) )
{
if ( mExpression )
{
mContext.setFeature( f );
QVariant v = mExpression->evaluate( &mContext );
mValues << v;
}
else
{
mValues << f.attribute( mFieldIndex );
}

if ( isCanceled() )
{
return false;
}

current++;
if ( mFeatureCount > 0 )
{
setProgress( 100.0 * static_cast< double >( current ) / mFeatureCount );
}
}
return true;
}
QgsStatisticsValueGatherer( QgsVectorLayer *layer, const QgsFeatureIterator &fit, long featureCount, const QString &sourceFieldExp );

bool run() override;

QList<QVariant> values() const { return mValues; }

0 comments on commit f404751

Please sign in to comment.
You can’t perform that action at this time.