Skip to content

Commit

Permalink
Adding a Identify Result setting to hide the Derived attributes
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rduivenvoorde and nyalldawson committed Oct 23, 2020
1 parent 7257456 commit 5f36f66
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -334,6 +334,7 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
connect( mCollapseAction, &QAction::triggered, this, &QgsIdentifyResultsDialog::mCollapseAction_triggered );
connect( mActionCopy, &QAction::triggered, this, &QgsIdentifyResultsDialog::mActionCopy_triggered );
connect( mActionAutoFeatureForm, &QAction::toggled, this, &QgsIdentifyResultsDialog::mActionAutoFeatureForm_toggled );
connect( mActionHideDerivedAttributes, &QAction::toggled, this, &QgsIdentifyResultsDialog::mActionHideDerivedAttributes_toggled );

mOpenFormAction->setDisabled( true );

Expand Down Expand Up @@ -433,6 +434,9 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge

settingsMenu->addAction( mActionAutoFeatureForm );
mActionAutoFeatureForm->setChecked( mySettings.value( QStringLiteral( "Map/identifyAutoFeatureForm" ), false ).toBool() );
settingsMenu->addAction( mActionHideDerivedAttributes );
mActionHideDerivedAttributes->setChecked( mySettings.value( QStringLiteral( "Map/hideDerivedAttributes" ), false ).toBool() );

}

QgsIdentifyResultsDialog::~QgsIdentifyResultsDialog()
Expand Down Expand Up @@ -609,7 +613,7 @@ QgsIdentifyResultsFeatureItem *QgsIdentifyResultsDialog::createFeatureItem( QgsV
featItem->setData( 0, FeatureRole, f );
parentItem->addChild( featItem );

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

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

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

// for Mesh layers it looks like it is best to hide the 'Geometry' feature, but keep the actual 'derived' attributes
if ( label == tr( "Geometry" ) && QgsSettings().value( QStringLiteral( "/Map/hideDerivedAttributes" ), false ).toBool() )
{
return;
}

QgsIdentifyResultsFeatureItem *featItem = new QgsIdentifyResultsFeatureItem( QgsFields(),
QgsFeature(),
layer->crs(),
Expand Down Expand Up @@ -1197,7 +1207,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorTileLayer *layer,
: QString();
layItem->setText( 0, QStringLiteral( "%1 %2" ).arg( layer->name(), countSuffix ) );

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

void QgsIdentifyResultsDialog::mActionHideDerivedAttributes_toggled( bool checked )
{
QgsSettings settings;
settings.setValue( QStringLiteral( "Map/hideDerivedAttributes" ), checked );
}

void QgsIdentifyResultsDialog::mExpandNewAction_triggered( bool checked )
{
QgsSettings settings;
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsidentifyresultsdialog.h
Expand Up @@ -256,6 +256,8 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti

void mActionAutoFeatureForm_toggled( bool checked );

void mActionHideDerivedAttributes_toggled( bool checked );

void mExpandAction_triggered( bool checked ) { Q_UNUSED( checked ) expandAll(); }
void mCollapseAction_triggered( bool checked ) { Q_UNUSED( checked ) collapseAll(); }

Expand Down
11 changes: 11 additions & 0 deletions src/ui/qgsidentifyresultsbase.ui
Expand Up @@ -366,12 +366,23 @@
</property>
</action>
<action name="mActionAutoFeatureForm">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Auto open form for single feature results</string>
</property>
</action>
<action name="mActionHideDerivedAttributes">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Hide Derived Attributes from Results</string>
</property>
<property name="toolTip">
<string>Hide derived attributes from results</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
Expand Down

0 comments on commit 5f36f66

Please sign in to comment.