Skip to content

Commit

Permalink
move definition to source
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Oct 8, 2018
1 parent 775d603 commit f404751
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
48 changes: 48 additions & 0 deletions src/app/qgsstatisticalsummarydockwidget.cpp
Expand Up @@ -21,6 +21,8 @@
#include "qgsstatisticalsummarydockwidget.h"
#include "qgsstatisticalsummary.h"
#include "qgsvectorlayer.h"
#include "qgsfeedback.h"
#include "qgsvectorlayerutils.h"

#include <QTableWidget>
#include <QAction>
Expand Down Expand Up @@ -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;
}
50 changes: 3 additions & 47 deletions src/app/qgsstatisticalsummarydockwidget.h
Expand Up @@ -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"
Expand All @@ -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; }

Expand Down

0 comments on commit f404751

Please sign in to comment.