Skip to content

Commit

Permalink
[needs-docs] Clicking the memory layer indicator triggers a 'make per…
Browse files Browse the repository at this point in the history
…menant' action
  • Loading branch information
nyalldawson committed Aug 6, 2018
1 parent 01876d1 commit 317b310
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/app/qgslayertreeviewmemoryindicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "qgslayertreemodel.h"
#include "qgslayertreeview.h"
#include "qgsvectorlayer.h"
#include "qgisapp.h"

QgsLayerTreeViewMemoryIndicatorProvider::QgsLayerTreeViewMemoryIndicatorProvider( QgsLayerTreeView *view )
: QObject( view )
Expand Down Expand Up @@ -122,11 +123,25 @@ void QgsLayerTreeViewMemoryIndicatorProvider::onDataSourceChanged()
}
}

void QgsLayerTreeViewMemoryIndicatorProvider::onIndicatorClicked( const QModelIndex &index )
{
QgsLayerTreeNode *node = mLayerTreeView->layerTreeModel()->index2node( index );
if ( !QgsLayerTree::isLayer( node ) )
return;

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( QgsLayerTree::toLayer( node )->layer() );
if ( !vlayer )
return;

QgisApp::instance()->makeMemoryLayerPermanent( vlayer );
}

std::unique_ptr< QgsLayerTreeViewIndicator > QgsLayerTreeViewMemoryIndicatorProvider::newIndicator()
{
std::unique_ptr< QgsLayerTreeViewIndicator > indicator = qgis::make_unique< QgsLayerTreeViewIndicator >( this );
indicator->setIcon( mIcon );
indicator->setToolTip( tr( "<b>Temporary scratch layer only!</b><br>Contents will be discarded after closing this project" ) );
connect( indicator.get(), &QgsLayerTreeViewIndicator::clicked, this, &QgsLayerTreeViewMemoryIndicatorProvider::onIndicatorClicked );
mIndicators.insert( indicator.get() );
return indicator;
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgslayertreeviewmemoryindicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class QgsLayerTreeViewMemoryIndicatorProvider : public QObject
//! Adds/removes indicator of a layer
void onDataSourceChanged();

void onIndicatorClicked( const QModelIndex &index );

private:
std::unique_ptr< QgsLayerTreeViewIndicator > newIndicator();
void addOrRemoveIndicator( QgsLayerTreeNode *node, QgsVectorLayer *vlayer );
Expand Down

0 comments on commit 317b310

Please sign in to comment.