Skip to content
Permalink
Browse files

[needs-docs] Reorganize save action for map layer

  • Loading branch information
slarosa committed Mar 18, 2018
1 parent 10044fb commit 11531c6fd7c8a8e49145521f635b6a42b95aa08c
Showing with 39 additions and 6 deletions.
  1. +22 −0 src/app/qgisapp.cpp
  2. +2 −0 src/app/qgisapp.h
  3. +15 −6 src/app/qgsapplayertreeviewmenuprovider.cpp
@@ -6985,6 +6985,28 @@ void QgisApp::saveAsLayerDefinition()
}
}

void QgisApp::saveStyleFile( QgsMapLayer *layer )
{
if ( !layer )
{
layer = qobject_cast<QgsMapLayer *>( activeLayer() );
}

QgsSettings settings;
QString lastUsedDir = settings.value( QStringLiteral( "style/lastStyleDir" ), QDir::homePath() ).toString();
QString filename = QFileDialog::getSaveFileName( this,
tr( "Save layer properties as style file" ),
lastUsedDir,
tr( "QGIS Layer Style File" ) + " (*.qml)" );
if ( filename.isEmpty() )
return;

bool defaultLoadedFlag;
layer->saveNamedStyle( filename, defaultLoadedFlag );

settings.setValue( QStringLiteral( "style/lastStyleDir" ), filename );
}

///@cond PRIVATE

/**
@@ -693,6 +693,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
public slots:
//! save current vector layer
void saveAsFile( QgsMapLayer *layer = nullptr );
//! save qml style for the current layer
void saveStyleFile( QgsMapLayer *layer = nullptr );

//! Process the list of URIs that have been dropped in QGIS
void handleDropUriList( const QgsMimeDataUtils::UriList &lst );
@@ -241,10 +241,6 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
if ( vlayer->storageType() == QLatin1String( "Memory storage" ) && mView->selectedLayerNodes().count() == 1 )
duplicateLayersAction->setEnabled( false );

// save as vector file
menu->addAction( tr( "Save as…" ), QgisApp::instance(), SLOT( saveAsFile() ) );
menu->addAction( tr( "Save as Layer Definition File…" ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) );

if ( vlayer->dataProvider()->supportsSubsetString() )
{
QAction *action = menu->addAction( tr( "&Filter…" ), QgisApp::instance(), SLOT( layerSubsetString() ) );
@@ -254,11 +250,24 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
menu->addAction( actions->actionShowFeatureCount( menu ) );

menu->addSeparator();

// save as vector file
QMenu *menuExportVector = new QMenu( tr( "Export" ), menu );
menuExportVector->addAction( tr( "Save as…" ), QgisApp::instance(), SLOT( saveAsFile() ) );
menuExportVector->addAction( tr( "Save as Layer Definition File…" ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) );
if ( vlayer->isSpatial() )
menuExportVector->addAction( tr( "QGIS Layer Style File…" ), QgisApp::instance(), SLOT( saveStyleFile() ) );
menu->addMenu( menuExportVector );
}
else if ( rlayer )
{
menu->addAction( tr( "Save As…" ), QgisApp::instance(), SLOT( saveAsRasterFile() ) );
menu->addAction( tr( "Save As Layer Definition File…" ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) );
QMenu *menuExportRaster = new QMenu( tr( "Export" ), menu );
menuExportRaster->addAction( tr( "Save As…" ), QgisApp::instance(), SLOT( saveAsRasterFile() ) );
menuExportRaster->addAction( tr( "Save As Layer Definition File…" ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) );
menuExportRaster->addAction( tr( "QGIS Layer Style File…" ), QgisApp::instance(), SLOT( saveStyleFile() ) );
menu->addMenu( menuExportRaster );

menu->addSeparator();
}
else if ( layer && layer->type() == QgsMapLayer::PluginLayer && mView->selectedLayerNodes().count() == 1 )
{

0 comments on commit 11531c6

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