Skip to content
Permalink
Browse files

[needs-docs] Clicking the memory layer indicator triggers a 'make per…

…menant' action
  • Loading branch information
nyalldawson committed Aug 6, 2018
1 parent 01876d1 commit 317b31052520eb0a0642cb8561cc954c4d8ddec6
Showing with 17 additions and 0 deletions.
  1. +15 −0 src/app/qgslayertreeviewmemoryindicator.cpp
  2. +2 −0 src/app/qgslayertreeviewmemoryindicator.h
@@ -18,6 +18,7 @@
#include "qgslayertreemodel.h"
#include "qgslayertreeview.h"
#include "qgsvectorlayer.h"
#include "qgisapp.h"

QgsLayerTreeViewMemoryIndicatorProvider::QgsLayerTreeViewMemoryIndicatorProvider( QgsLayerTreeView *view )
: QObject( view )
@@ -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;
}
@@ -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 );

0 comments on commit 317b310

Please sign in to comment.
You can’t perform that action at this time.