23
23
#include < QTableWidget>
24
24
#include < QAction>
25
25
#include < QMenu>
26
- #include < QDebug>
27
26
28
27
QList< QgsStatisticalSummary::Statistic > QgsStatisticalSummaryDockWidget::sDisplayStats =
29
28
QList< QgsStatisticalSummary::Statistic > () << QgsStatisticalSummary::Count
@@ -96,7 +95,9 @@ QgsStatisticalSummaryDockWidget::QgsStatisticalSummaryDockWidget( QWidget *paren
96
95
97
96
mStatisticsMenu = new QMenu ( mOptionsToolButton );
98
97
mOptionsToolButton ->setMenu ( mStatisticsMenu );
99
- refreshStatisticsMenu ( QVariant::Int );
98
+
99
+ mFieldType = QVariant::Int;
100
+ refreshStatisticsMenu ();
100
101
}
101
102
102
103
QgsStatisticalSummaryDockWidget::~QgsStatisticalSummaryDockWidget ()
@@ -106,48 +107,42 @@ QgsStatisticalSummaryDockWidget::~QgsStatisticalSummaryDockWidget()
106
107
107
108
void QgsStatisticalSummaryDockWidget::refreshStatistics ()
108
109
{
109
- qDebug () << " refreshStatistics called..." ;
110
110
if ( !mLayer || ( mFieldExpressionWidget ->isExpression () && !mFieldExpressionWidget ->isValidExpression () ) )
111
111
{
112
112
mStatisticsTable ->setRowCount ( 0 );
113
113
return ;
114
114
}
115
115
116
- // non numeric field?
117
- bool isNumeric = true ;
118
- QVariant::Type fieldType = QVariant::Double;
116
+ // determine field type
117
+ mFieldType = QVariant::Double;
119
118
if ( !mFieldExpressionWidget ->isExpression () )
120
119
{
121
120
QString field = mFieldExpressionWidget ->currentField ();
122
- fieldType = mLayer ->fields ().field ( mLayer ->fields ().lookupField ( field ) ).type ();
123
- if ( fieldType == QVariant::String || fieldType == QVariant::Date || fieldType == QVariant::DateTime )
124
- {
125
- isNumeric = false ;
126
- }
121
+ mFieldType = mLayer ->fields ().field ( mLayer ->fields ().lookupField ( field ) ).type ();
127
122
}
128
123
124
+ refreshStatisticsMenu ();
125
+
129
126
bool selectedOnly = mSelectedOnlyCheckBox ->isChecked ();
130
127
131
- if ( isNumeric )
132
- {
133
- refreshStatisticsMenu ( QVariant::Int );
134
- updateNumericStatistics ( selectedOnly );
135
- }
136
- else
128
+ switch ( mFieldType )
137
129
{
138
- refreshStatisticsMenu ( fieldType );
139
- switch ( fieldType )
140
- {
141
- case QVariant::String:
142
- updateStringStatistics ( selectedOnly );
143
- break ;
144
- case QVariant::Date:
145
- case QVariant::DateTime:
146
- updateDateTimeStatistics ( selectedOnly );
147
- break ;
148
- default :
149
- break ;
150
- }
130
+ case QVariant::Int:
131
+ case QVariant::UInt:
132
+ case QVariant::Double:
133
+ case QVariant::LongLong:
134
+ case QVariant::ULongLong:
135
+ updateNumericStatistics ( selectedOnly );
136
+ break ;
137
+ case QVariant::String:
138
+ updateStringStatistics ( selectedOnly );
139
+ break ;
140
+ case QVariant::Date:
141
+ case QVariant::DateTime:
142
+ updateDateTimeStatistics ( selectedOnly );
143
+ break ;
144
+ default :
145
+ break ;
151
146
}
152
147
}
153
148
@@ -217,15 +212,26 @@ void QgsStatisticalSummaryDockWidget::updateStringStatistics( bool selectedOnly
217
212
return ;
218
213
}
219
214
215
+ QList< QgsStringStatisticalSummary::Statistic > statsToDisplay;
216
+ QgsStringStatisticalSummary::Statistics statsToCalc = 0 ;
217
+ Q_FOREACH ( QgsStringStatisticalSummary::Statistic stat, sDisplayStringStats )
218
+ {
219
+ if ( mStatsActions .value ( stat )->isChecked () )
220
+ {
221
+ statsToDisplay << stat;
222
+ statsToCalc |= stat;
223
+ }
224
+ }
225
+
220
226
QgsStringStatisticalSummary stats;
221
- stats.setStatistics ( QgsStringStatisticalSummary::All );
227
+ stats.setStatistics ( statsToCalc );
222
228
stats.calculateFromVariants ( values );
223
229
224
- mStatisticsTable ->setRowCount ( sDisplayStringStats .count () );
230
+ mStatisticsTable ->setRowCount ( statsToDisplay .count () );
225
231
mStatisticsTable ->setColumnCount ( 2 );
226
232
227
233
int row = 0 ;
228
- Q_FOREACH ( QgsStringStatisticalSummary::Statistic stat, sDisplayStringStats )
234
+ Q_FOREACH ( QgsStringStatisticalSummary::Statistic stat, statsToDisplay )
229
235
{
230
236
addRow ( row, QgsStringStatisticalSummary::displayName ( stat ),
231
237
stats.statistic ( stat ).toString (),
@@ -263,18 +269,38 @@ void QgsStatisticalSummaryDockWidget::layerChanged( QgsMapLayer *layer )
263
269
264
270
void QgsStatisticalSummaryDockWidget::statActionTriggered ( bool checked )
265
271
{
266
- qDebug () << " statActionTriggered called..." ;
267
272
QAction *action = dynamic_cast <QAction *>( sender () );
268
273
int stat = action->data ().toInt ();
269
274
275
+ QString settingsKey;
276
+ switch ( mFieldType )
277
+ {
278
+ case QVariant::Int:
279
+ case QVariant::UInt:
280
+ case QVariant::Double:
281
+ case QVariant::LongLong:
282
+ case QVariant::ULongLong:
283
+ settingsKey = QStringLiteral ( " numeric" );
284
+ break ;
285
+ case QVariant::String:
286
+ settingsKey = QStringLiteral ( " string" );
287
+ break ;
288
+ case QVariant::Date:
289
+ case QVariant::DateTime:
290
+ settingsKey = QStringLiteral ( " datetime" );
291
+ break ;
292
+ default :
293
+ break ;
294
+ }
295
+
270
296
QgsSettings settings;
271
297
if ( stat >= 0 )
272
298
{
273
- settings.setValue ( QStringLiteral ( " StatisticalSummaryDock/checked_%1 " ).arg ( stat ), checked );
299
+ settings.setValue ( QStringLiteral ( " StatisticalSummaryDock/%1_%2 " ). arg ( settingsKey ).arg ( stat ), checked );
274
300
}
275
301
else if ( stat == MISSING_VALUES )
276
302
{
277
- settings.setValue ( QStringLiteral ( " StatisticalSummaryDock/checked_missing_values " ). arg ( stat ), checked );
303
+ settings.setValue ( QStringLiteral ( " StatisticalSummaryDock/numeric_missing_values " ), checked );
278
304
}
279
305
280
306
refreshStatistics ();
@@ -307,15 +333,27 @@ void QgsStatisticalSummaryDockWidget::updateDateTimeStatistics( bool selectedOnl
307
333
return ;
308
334
}
309
335
336
+ QList< QgsDateTimeStatisticalSummary::Statistic > statsToDisplay;
337
+ QgsDateTimeStatisticalSummary::Statistics statsToCalc = 0 ;
338
+ Q_FOREACH ( QgsDateTimeStatisticalSummary::Statistic stat, sDisplayDateTimeStats )
339
+ {
340
+ if ( mStatsActions .value ( stat )->isChecked () )
341
+ {
342
+ statsToDisplay << stat;
343
+ statsToCalc |= stat;
344
+ }
345
+ }
346
+
347
+
310
348
QgsDateTimeStatisticalSummary stats;
311
- stats.setStatistics ( QgsDateTimeStatisticalSummary::All );
349
+ stats.setStatistics ( statsToCalc );
312
350
stats.calculate ( values );
313
351
314
- mStatisticsTable ->setRowCount ( sDisplayDateTimeStats .count () );
352
+ mStatisticsTable ->setRowCount ( statsToDisplay .count () );
315
353
mStatisticsTable ->setColumnCount ( 2 );
316
354
317
355
int row = 0 ;
318
- Q_FOREACH ( QgsDateTimeStatisticalSummary::Statistic stat, sDisplayDateTimeStats )
356
+ Q_FOREACH ( QgsDateTimeStatisticalSummary::Statistic stat, statsToDisplay )
319
357
{
320
358
QString value = ( stat == QgsDateTimeStatisticalSummary::Range
321
359
? tr ( " %1 seconds" ).arg ( stats.range ().seconds () )
@@ -346,21 +384,25 @@ void QgsStatisticalSummaryDockWidget::addRow( int row, const QString &name, cons
346
384
mStatisticsTable ->setItem ( row, 1 , valueItem );
347
385
}
348
386
349
- void QgsStatisticalSummaryDockWidget::refreshStatisticsMenu ( QVariant::Type fieldType )
387
+ void QgsStatisticalSummaryDockWidget::refreshStatisticsMenu ()
350
388
{
351
389
mStatisticsMenu ->clear ();
352
390
mStatsActions .clear ();
353
391
354
392
QgsSettings settings;
355
- switch ( fieldType )
393
+ switch ( mFieldType )
356
394
{
357
395
case QVariant::Int:
396
+ case QVariant::UInt:
397
+ case QVariant::Double:
398
+ case QVariant::LongLong:
399
+ case QVariant::ULongLong:
358
400
{
359
401
Q_FOREACH ( QgsStatisticalSummary::Statistic stat, sDisplayStats )
360
402
{
361
403
QAction *action = new QAction ( QgsStatisticalSummary::displayName ( stat ), mStatisticsMenu );
362
404
action->setCheckable ( true );
363
- bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/checked_ %1" ).arg ( stat ), true ).toBool ();
405
+ bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/numeric_ %1" ).arg ( stat ), true ).toBool ();
364
406
action->setChecked ( checked );
365
407
action->setData ( stat );
366
408
mStatsActions .insert ( stat, action );
@@ -371,7 +413,7 @@ void QgsStatisticalSummaryDockWidget::refreshStatisticsMenu( QVariant::Type fiel
371
413
// count of null values statistic
372
414
QAction *nullCountAction = new QAction ( tr ( " Missing (null) values" ), mStatisticsMenu );
373
415
nullCountAction->setCheckable ( true );
374
- bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/checked_missing_values " ), true ).toBool ();
416
+ bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/numeric_missing_values " ), true ).toBool ();
375
417
nullCountAction->setChecked ( checked );
376
418
nullCountAction->setData ( MISSING_VALUES );
377
419
mStatsActions .insert ( MISSING_VALUES, nullCountAction );
@@ -386,7 +428,7 @@ void QgsStatisticalSummaryDockWidget::refreshStatisticsMenu( QVariant::Type fiel
386
428
{
387
429
QAction *action = new QAction ( QgsStringStatisticalSummary::displayName ( stat ), mStatisticsMenu );
388
430
action->setCheckable ( true );
389
- bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/checked_ %1" ).arg ( stat ), true ).toBool ();
431
+ bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/string_ %1" ).arg ( stat ), true ).toBool ();
390
432
action->setChecked ( checked );
391
433
action->setData ( stat );
392
434
mStatsActions .insert ( stat, action );
@@ -402,7 +444,7 @@ void QgsStatisticalSummaryDockWidget::refreshStatisticsMenu( QVariant::Type fiel
402
444
{
403
445
QAction *action = new QAction ( QgsDateTimeStatisticalSummary::displayName ( stat ), mStatisticsMenu );
404
446
action->setCheckable ( true );
405
- bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/checked_ %1" ).arg ( stat ), true ).toBool ();
447
+ bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/datetime_ %1" ).arg ( stat ), true ).toBool ();
406
448
action->setChecked ( checked );
407
449
action->setData ( stat );
408
450
mStatsActions .insert ( stat, action );
0 commit comments