22
22
23
23
#include < QTableWidget>
24
24
#include < QAction>
25
+ #include < QMenu>
26
+ #include < QDebug>
25
27
26
28
QList< QgsStatisticalSummary::Statistic > QgsStatisticalSummaryDockWidget::sDisplayStats =
27
29
QList< QgsStatisticalSummary::Statistic > () << QgsStatisticalSummary::Count
@@ -92,28 +94,9 @@ QgsStatisticalSummaryDockWidget::QgsStatisticalSummaryDockWidget( QWidget *paren
92
94
connect ( mButtonRefresh , &QAbstractButton::clicked, this , &QgsStatisticalSummaryDockWidget::refreshStatistics );
93
95
connect ( QgsProject::instance (), static_cast <void ( QgsProject::* )( const QStringList & )>( &QgsProject::layersWillBeRemoved ), this , &QgsStatisticalSummaryDockWidget::layersRemoved );
94
96
95
- QgsSettings settings;
96
- Q_FOREACH ( QgsStatisticalSummary::Statistic stat, sDisplayStats )
97
- {
98
- QAction *action = new QAction ( QgsStatisticalSummary::displayName ( stat ), mOptionsToolButton );
99
- action->setCheckable ( true );
100
- bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/checked_%1" ).arg ( stat ), true ).toBool ();
101
- action->setChecked ( checked );
102
- action->setData ( stat );
103
- mStatsActions .insert ( stat, action );
104
- connect ( action, &QAction::triggered, this , &QgsStatisticalSummaryDockWidget::statActionTriggered );
105
- mOptionsToolButton ->addAction ( action );
106
- }
107
-
108
- // count of null values statistic:
109
- QAction *nullCountAction = new QAction ( tr ( " Missing (null) values" ), mOptionsToolButton );
110
- nullCountAction->setCheckable ( true );
111
- bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/checked_missing_values" ), true ).toBool ();
112
- nullCountAction->setChecked ( checked );
113
- nullCountAction->setData ( MISSING_VALUES );
114
- mStatsActions .insert ( MISSING_VALUES, nullCountAction );
115
- connect ( nullCountAction, &QAction::triggered, this , &QgsStatisticalSummaryDockWidget::statActionTriggered );
116
- mOptionsToolButton ->addAction ( nullCountAction );
97
+ mStatisticsMenu = new QMenu ( mOptionsToolButton );
98
+ mOptionsToolButton ->setMenu ( mStatisticsMenu );
99
+ refreshStatisticsMenu ( QVariant::Int );
117
100
}
118
101
119
102
QgsStatisticalSummaryDockWidget::~QgsStatisticalSummaryDockWidget ()
@@ -123,6 +106,7 @@ QgsStatisticalSummaryDockWidget::~QgsStatisticalSummaryDockWidget()
123
106
124
107
void QgsStatisticalSummaryDockWidget::refreshStatistics ()
125
108
{
109
+ qDebug () << " refreshStatistics called..." ;
126
110
if ( !mLayer || ( mFieldExpressionWidget ->isExpression () && !mFieldExpressionWidget ->isValidExpression () ) )
127
111
{
128
112
mStatisticsTable ->setRowCount ( 0 );
@@ -146,10 +130,12 @@ void QgsStatisticalSummaryDockWidget::refreshStatistics()
146
130
147
131
if ( isNumeric )
148
132
{
133
+ refreshStatisticsMenu ( QVariant::Int );
149
134
updateNumericStatistics ( selectedOnly );
150
135
}
151
136
else
152
137
{
138
+ refreshStatisticsMenu ( fieldType );
153
139
switch ( fieldType )
154
140
{
155
141
case QVariant::String:
@@ -277,7 +263,7 @@ void QgsStatisticalSummaryDockWidget::layerChanged( QgsMapLayer *layer )
277
263
278
264
void QgsStatisticalSummaryDockWidget::statActionTriggered ( bool checked )
279
265
{
280
- refreshStatistics () ;
266
+ qDebug () << " statActionTriggered called... " ;
281
267
QAction *action = dynamic_cast <QAction *>( sender () );
282
268
int stat = action->data ().toInt ();
283
269
@@ -290,6 +276,8 @@ void QgsStatisticalSummaryDockWidget::statActionTriggered( bool checked )
290
276
{
291
277
settings.setValue ( QStringLiteral ( " StatisticalSummaryDock/checked_missing_values" ).arg ( stat ), checked );
292
278
}
279
+
280
+ refreshStatistics ();
293
281
}
294
282
295
283
void QgsStatisticalSummaryDockWidget::layersRemoved ( const QStringList &layers )
@@ -358,3 +346,72 @@ void QgsStatisticalSummaryDockWidget::addRow( int row, const QString &name, cons
358
346
mStatisticsTable ->setItem ( row, 1 , valueItem );
359
347
}
360
348
349
+ void QgsStatisticalSummaryDockWidget::refreshStatisticsMenu ( QVariant::Type fieldType )
350
+ {
351
+ mStatisticsMenu ->clear ();
352
+ mStatsActions .clear ();
353
+
354
+ QgsSettings settings;
355
+ switch ( fieldType )
356
+ {
357
+ case QVariant::Int:
358
+ {
359
+ Q_FOREACH ( QgsStatisticalSummary::Statistic stat, sDisplayStats )
360
+ {
361
+ QAction *action = new QAction ( QgsStatisticalSummary::displayName ( stat ), mStatisticsMenu );
362
+ action->setCheckable ( true );
363
+ bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/checked_%1" ).arg ( stat ), true ).toBool ();
364
+ action->setChecked ( checked );
365
+ action->setData ( stat );
366
+ mStatsActions .insert ( stat, action );
367
+ connect ( action, &QAction::toggled, this , &QgsStatisticalSummaryDockWidget::statActionTriggered );
368
+ mStatisticsMenu ->addAction ( action );
369
+ }
370
+
371
+ // count of null values statistic
372
+ QAction *nullCountAction = new QAction ( tr ( " Missing (null) values" ), mStatisticsMenu );
373
+ nullCountAction->setCheckable ( true );
374
+ bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/checked_missing_values" ), true ).toBool ();
375
+ nullCountAction->setChecked ( checked );
376
+ nullCountAction->setData ( MISSING_VALUES );
377
+ mStatsActions .insert ( MISSING_VALUES, nullCountAction );
378
+ connect ( nullCountAction, &QAction::toggled, this , &QgsStatisticalSummaryDockWidget::statActionTriggered );
379
+ mStatisticsMenu ->addAction ( nullCountAction );
380
+
381
+ break ;
382
+ }
383
+ case QVariant::String:
384
+ {
385
+ Q_FOREACH ( QgsStringStatisticalSummary::Statistic stat, sDisplayStringStats )
386
+ {
387
+ QAction *action = new QAction ( QgsStringStatisticalSummary::displayName ( stat ), mStatisticsMenu );
388
+ action->setCheckable ( true );
389
+ bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/checked_%1" ).arg ( stat ), true ).toBool ();
390
+ action->setChecked ( checked );
391
+ action->setData ( stat );
392
+ mStatsActions .insert ( stat, action );
393
+ connect ( action, &QAction::toggled, this , &QgsStatisticalSummaryDockWidget::statActionTriggered );
394
+ mStatisticsMenu ->addAction ( action );
395
+ }
396
+ break ;
397
+ }
398
+ case QVariant::Date:
399
+ case QVariant::DateTime:
400
+ {
401
+ Q_FOREACH ( QgsDateTimeStatisticalSummary::Statistic stat, sDisplayDateTimeStats )
402
+ {
403
+ QAction *action = new QAction ( QgsDateTimeStatisticalSummary::displayName ( stat ), mStatisticsMenu );
404
+ action->setCheckable ( true );
405
+ bool checked = settings.value ( QStringLiteral ( " StatisticalSummaryDock/checked_%1" ).arg ( stat ), true ).toBool ();
406
+ action->setChecked ( checked );
407
+ action->setData ( stat );
408
+ mStatsActions .insert ( stat, action );
409
+ connect ( action, &QAction::toggled, this , &QgsStatisticalSummaryDockWidget::statActionTriggered );
410
+ mStatisticsMenu ->addAction ( action );
411
+ }
412
+ break ;
413
+ }
414
+ default :
415
+ break ;
416
+ }
417
+ }
0 commit comments