Skip to content

Commit 5f36f66

Browse files
rduivenvoordenyalldawson
andcommittedOct 23, 2020
Adding a Identify Result setting to hide the Derived attributes
Not 100% sure about what to hide for Mesh layers. For now hiding the so called 'Geometry' feature Co-authored-by: Nyall Dawson <nyall.dawson@gmail.com>
1 parent 7257456 commit 5f36f66

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed
 

‎src/app/qgsidentifyresultsdialog.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
334334
connect( mCollapseAction, &QAction::triggered, this, &QgsIdentifyResultsDialog::mCollapseAction_triggered );
335335
connect( mActionCopy, &QAction::triggered, this, &QgsIdentifyResultsDialog::mActionCopy_triggered );
336336
connect( mActionAutoFeatureForm, &QAction::toggled, this, &QgsIdentifyResultsDialog::mActionAutoFeatureForm_toggled );
337+
connect( mActionHideDerivedAttributes, &QAction::toggled, this, &QgsIdentifyResultsDialog::mActionHideDerivedAttributes_toggled );
337338

338339
mOpenFormAction->setDisabled( true );
339340

@@ -433,6 +434,9 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
433434

434435
settingsMenu->addAction( mActionAutoFeatureForm );
435436
mActionAutoFeatureForm->setChecked( mySettings.value( QStringLiteral( "Map/identifyAutoFeatureForm" ), false ).toBool() );
437+
settingsMenu->addAction( mActionHideDerivedAttributes );
438+
mActionHideDerivedAttributes->setChecked( mySettings.value( QStringLiteral( "Map/hideDerivedAttributes" ), false ).toBool() );
439+
436440
}
437441

438442
QgsIdentifyResultsDialog::~QgsIdentifyResultsDialog()
@@ -609,7 +613,7 @@ QgsIdentifyResultsFeatureItem *QgsIdentifyResultsDialog::createFeatureItem( QgsV
609613
featItem->setData( 0, FeatureRole, f );
610614
parentItem->addChild( featItem );
611615

612-
if ( !derivedAttributes.empty() )
616+
if ( !derivedAttributes.empty() && !QgsSettings().value( QStringLiteral( "/Map/hideDerivedAttributes" ), false ).toBool() )
613617
{
614618
QgsTreeWidgetItem *derivedItem = new QgsTreeWidgetItem( QStringList() << tr( "(Derived)" ) );
615619
derivedItem->setData( 0, Qt::UserRole, "derived" );
@@ -626,7 +630,7 @@ QgsIdentifyResultsFeatureItem *QgsIdentifyResultsDialog::createFeatureItem( QgsV
626630
QList< QgsMapLayerAction * > registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer );
627631
QList<QgsAction> actions = vlayer->actions()->actions( QStringLiteral( "Feature" ) );
628632

629-
if ( !vlayer->fields().isEmpty() || !actions.isEmpty() || !registeredActions.isEmpty() )
633+
if ( ( !vlayer->fields().isEmpty() || !actions.isEmpty() || !registeredActions.isEmpty() ) && !QgsSettings().value( QStringLiteral( "/Map/hideDerivedAttributes" ), false ).toBool() )
630634
{
631635
QgsTreeWidgetItem *actionItem = new QgsTreeWidgetItem( QStringList() << tr( "(Actions)" ) );
632636
actionItem->setData( 0, Qt::UserRole, "actions" );
@@ -1063,7 +1067,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
10631067
}
10641068
}
10651069

1066-
if ( derivedAttributes.size() >= 0 )
1070+
if ( derivedAttributes.size() >= 0 && !QgsSettings().value( QStringLiteral( "/Map/hideDerivedAttributes" ), false ).toBool() )
10671071
{
10681072
QgsTreeWidgetItem *derivedItem = new QgsTreeWidgetItem( QStringList() << tr( "(Derived)" ) );
10691073
derivedItem->setData( 0, Qt::UserRole, "derived" );
@@ -1135,6 +1139,12 @@ void QgsIdentifyResultsDialog::addFeature( QgsMeshLayer *layer,
11351139
connect( layer, &QgsMapLayer::crsChanged, this, &QgsIdentifyResultsDialog::layerDestroyed );
11361140
}
11371141

1142+
// for Mesh layers it looks like it is best to hide the 'Geometry' feature, but keep the actual 'derived' attributes
1143+
if ( label == tr( "Geometry" ) && QgsSettings().value( QStringLiteral( "/Map/hideDerivedAttributes" ), false ).toBool() )
1144+
{
1145+
return;
1146+
}
1147+
11381148
QgsIdentifyResultsFeatureItem *featItem = new QgsIdentifyResultsFeatureItem( QgsFields(),
11391149
QgsFeature(),
11401150
layer->crs(),
@@ -1197,7 +1207,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorTileLayer *layer,
11971207
: QString();
11981208
layItem->setText( 0, QStringLiteral( "%1 %2" ).arg( layer->name(), countSuffix ) );
11991209

1200-
if ( derivedAttributes.size() >= 0 )
1210+
if ( derivedAttributes.size() >= 0 && !QgsSettings().value( QStringLiteral( "/Map/hideDerivedAttributes" ), false ).toBool() )
12011211
{
12021212
QgsTreeWidgetItem *derivedItem = new QgsTreeWidgetItem( QStringList() << tr( "(Derived)" ) );
12031213
derivedItem->setData( 0, Qt::UserRole, "derived" );
@@ -2270,6 +2280,12 @@ void QgsIdentifyResultsDialog::mActionAutoFeatureForm_toggled( bool checked )
22702280
settings.setValue( QStringLiteral( "Map/identifyAutoFeatureForm" ), checked );
22712281
}
22722282

2283+
void QgsIdentifyResultsDialog::mActionHideDerivedAttributes_toggled( bool checked )
2284+
{
2285+
QgsSettings settings;
2286+
settings.setValue( QStringLiteral( "Map/hideDerivedAttributes" ), checked );
2287+
}
2288+
22732289
void QgsIdentifyResultsDialog::mExpandNewAction_triggered( bool checked )
22742290
{
22752291
QgsSettings settings;

‎src/app/qgsidentifyresultsdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
256256

257257
void mActionAutoFeatureForm_toggled( bool checked );
258258

259+
void mActionHideDerivedAttributes_toggled( bool checked );
260+
259261
void mExpandAction_triggered( bool checked ) { Q_UNUSED( checked ) expandAll(); }
260262
void mCollapseAction_triggered( bool checked ) { Q_UNUSED( checked ) collapseAll(); }
261263

‎src/ui/qgsidentifyresultsbase.ui

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,23 @@
366366
</property>
367367
</action>
368368
<action name="mActionAutoFeatureForm">
369+
<property name="checkable">
370+
<bool>true</bool>
371+
</property>
369372
<property name="text">
370373
<string>Auto open form for single feature results</string>
371374
</property>
375+
</action>
376+
<action name="mActionHideDerivedAttributes">
372377
<property name="checkable">
373378
<bool>true</bool>
374379
</property>
380+
<property name="text">
381+
<string>Hide Derived Attributes from Results</string>
382+
</property>
383+
<property name="toolTip">
384+
<string>Hide derived attributes from results</string>
385+
</property>
375386
</action>
376387
</widget>
377388
<layoutdefault spacing="6" margin="11"/>

0 commit comments

Comments
 (0)
Please sign in to comment.