Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remember which project layers have been selected for display in eleva…
…tion

profiles and default to these next time an elevation profile is opened
  • Loading branch information
nyalldawson committed May 19, 2023
1 parent 53be37f commit c5f9dc5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/gui/elevation/qgselevationprofilelayertreeview.cpp
Expand Up @@ -235,6 +235,23 @@ QVariant QgsElevationProfileLayerTreeModel::data( const QModelIndex &index, int
return QgsLayerTreeModel::data( index, role );
}

bool QgsElevationProfileLayerTreeModel::setData( const QModelIndex &index, const QVariant &value, int role )
{
if ( QgsLayerTreeLayer *layerNode = qobject_cast< QgsLayerTreeLayer * >( index2node( index ) ) )
{
if ( role == Qt::CheckStateRole )
{
const bool checked = static_cast< Qt::CheckState >( value.toInt() ) == Qt::Checked;
if ( QgsMapLayer *layer = layerNode->layer() )
{
layer->setCustomProperty( QStringLiteral( "_include_in_elevation_profiles" ), checked );
}
}
}

return QgsLayerTreeModel::setData( index, value, role );
}

bool QgsElevationProfileLayerTreeModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
{
if ( action == Qt::IgnoreAction )
Expand Down Expand Up @@ -388,7 +405,15 @@ void QgsElevationProfileLayerTreeView::populateInitialLayers( QgsProject *projec
for ( QgsMapLayer *layer : std::as_const( sortedLayers ) )
{
QgsLayerTreeLayer *node = mLayerTree->addLayer( layer );
node->setItemVisibilityChecked( layer->elevationProperties() && layer->elevationProperties()->showByDefaultInElevationProfilePlots() );

if ( layer->customProperty( QStringLiteral( "_include_in_elevation_profiles" ) ).isValid() )
{
node->setItemVisibilityChecked( layer->customProperty( QStringLiteral( "_include_in_elevation_profiles" ) ).toBool() );
}
else
{
node->setItemVisibilityChecked( layer->elevationProperties() && layer->elevationProperties()->showByDefaultInElevationProfilePlots() );
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/elevation/qgselevationprofilelayertreeview.h
Expand Up @@ -56,6 +56,8 @@ class GUI_EXPORT QgsElevationProfileLayerTreeModel : public QgsLayerTreeModel
explicit QgsElevationProfileLayerTreeModel( QgsLayerTree *rootNode, QObject *parent = nullptr );

QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;

bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
QMimeData *mimeData( const QModelIndexList &indexes ) const override;

Expand Down

0 comments on commit c5f9dc5

Please sign in to comment.