Skip to content
Permalink
Browse files

Merge pull request #6629 from slarosa/reorganize_cm

[needs-docs] Reorganize save action for map layer
  • Loading branch information
slarosa committed Mar 20, 2018
2 parents 9a25d67 + ee5dc8d commit 94e3d1c282c8bfe73dd47f7a9f3eb2162a6b7445
Showing with 57 additions and 12 deletions.
  1. +22 −0 src/app/qgisapp.cpp
  2. +6 −6 src/app/qgisapp.h
  3. +29 −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 as QGIS Layer 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,7 +693,12 @@ 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 );
//! save qrl definition for the current layer
void saveAsLayerDefinition();
//! save current raster layer
void saveAsRasterFile( QgsRasterLayer *layer = nullptr );
//! Process the list of URIs that have been dropped in QGIS
void handleDropUriList( const QgsMimeDataUtils::UriList &lst );
//! Convenience function to open either a project or a layer file.
@@ -1503,11 +1508,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! set the CAD dock widget visible
void setCadDockVisible( bool visible );

void saveAsLayerDefinition();

//! save current raster layer
void saveAsRasterFile( QgsRasterLayer *layer = nullptr );

//! show Python console
void showPythonDialog();

@@ -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,38 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
menu->addAction( actions->actionShowFeatureCount( menu ) );

menu->addSeparator();

// save as vector file
QMenu *menuExportVector = new QMenu( tr( "Export" ), menu );
QAction *actionSaveAs = new QAction( tr( "Save as…" ), menuExportVector );
QAction *actionSaveAsDefinitionLayer = new QAction( tr( "Save as Layer Definition File…" ), menuExportVector );
connect( actionSaveAs, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->saveAsFile(); } );
menuExportVector->addAction( actionSaveAs );
connect( actionSaveAsDefinitionLayer, &QAction::triggered, QgisApp::instance(), &QgisApp::saveAsLayerDefinition );
menuExportVector->addAction( actionSaveAsDefinitionLayer );
if ( vlayer->isSpatial() )
{
QAction *actionSaveStyle = new QAction( tr( "Save as QGIS Layer Style File…" ), menuExportVector );
connect( actionSaveStyle, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->saveStyleFile(); } );
menuExportVector->addAction( actionSaveStyle );
}
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 );
QAction *actionSaveAs = new QAction( tr( "Save as…" ), menuExportRaster );
QAction *actionSaveAsDefinitionLayer = new QAction( tr( "Save as Layer Definition File…" ), menuExportRaster );
QAction *actionSaveStyle = new QAction( tr( "Save as QGIS Layer Style File…" ), menuExportRaster );
connect( actionSaveAs, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->saveAsFile(); } );
menuExportRaster->addAction( actionSaveAs );
connect( actionSaveAsDefinitionLayer, &QAction::triggered, QgisApp::instance(), &QgisApp::saveAsLayerDefinition );
menuExportRaster->addAction( actionSaveAsDefinitionLayer );
connect( actionSaveStyle, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->saveStyleFile(); } );
menuExportRaster->addAction( actionSaveStyle );
menu->addMenu( menuExportRaster );

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

0 comments on commit 94e3d1c

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