Skip to content

Commit

Permalink
[needs-docs] Reorganize save action for map layer
Browse files Browse the repository at this point in the history
  • Loading branch information
slarosa committed Mar 18, 2018
1 parent 10044fb commit 11531c6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
21 changes: 15 additions & 6 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand All @@ -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 )
{
Expand Down

0 comments on commit 11531c6

Please sign in to comment.