Skip to content
Permalink
Browse files

categories in paste style

  • Loading branch information
3nids authored and nyalldawson committed Sep 14, 2018
1 parent 2cabd48 commit e91a42def69472ed44690e1d108c7eb31ef97262
@@ -807,13 +807,15 @@ Retrieve a named style for this layer from a sqlite database.
:return: true if style was successfully loaded
%End

virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg /Out/ );
virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg /Out/,
QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories );
%Docstring
Import the properties of this layer from a QDomDocument

:param doc: source QDomDocument
:param errorMsg: this QString will be initialized on error
during the execution of readSymbology
:param categories: the style categories to import

:return: true on success

@@ -827,7 +829,8 @@ Export the properties of this layer as named style in a QDomDocument

:param doc: the target QDomDocument
:param errorMsg: this QString will be initialized on error
during the execution of writeSymbology
:param categories: the style categories to export
during the execution of writeSymbology
%End


@@ -8872,7 +8872,7 @@ void QgisApp::copyStyle( QgsMapLayer *sourceLayer, QgsMapLayer::StyleCategories
}
}

void QgisApp::pasteStyle( QgsMapLayer *destinationLayer )
void QgisApp::pasteStyle( QgsMapLayer *destinationLayer, QgsMapLayer::StyleCategories categories )
{
QgsMapLayer *selectionLayer = destinationLayer ? destinationLayer : activeLayer();
if ( selectionLayer )
@@ -8898,7 +8898,7 @@ void QgisApp::pasteStyle( QgsMapLayer *destinationLayer )
return;
}

if ( !selectionLayer->importNamedStyle( doc, errorMsg ) )
if ( !selectionLayer->importNamedStyle( doc, errorMsg, categories ) )
{
messageBar()->pushMessage( tr( "Cannot paste style" ),
errorMsg,
@@ -831,18 +831,18 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

/**
* Copy the style of a map layer
* \param sourceLayer The layer where the style will be taken from
(defaults to the active layer on the legend)
* \param sourceLayer The layer where the style will be taken from (defaults to the active layer on the legend)
* \param categories The style categories to copy
*/
void copyStyle( QgsMapLayer *sourceLayer = nullptr, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories );
//! pastes style on the clipboard to the active layer

/**
\param destinationLayer The layer that the clipboard will be pasted to
(defaults to the active layer on the legend)
* \param destinationLayer The layer that the clipboard will be pasted to (defaults to the active layer on the legend)
* \param categories The style categories to copy
*/
void pasteStyle( QgsMapLayer *destinationLayer = nullptr );
void pasteStyle( QgsMapLayer *destinationLayer = nullptr,
QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories );
//! copies group or layer on the clipboard
void copyLayer();
//! pastes group or layer from the clipboard to layer tree
@@ -318,7 +318,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
QgisApp *app = QgisApp::instance();
if ( layer->type() == QgsMapLayer::VectorLayer )
{
QMenu *copyStyleMenu = menuStyleManager->addMenu( tr( "Copy Style" ) );
QMenu *copyStyleMenu = menuStyleManager->addMenu( tr( "Copy Style" ) );
copyStyleMenu->setToolTipsVisible( true );
QList<QgsMapLayer::StyleCategory> categories = qgsEnumMap<QgsMapLayer::StyleCategory>().keys();
categories.move( categories.indexOf( QgsMapLayer::AllCategories ), 0 ); // move All categories to top
@@ -340,7 +340,27 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()

if ( app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
{
menuStyleManager->addAction( tr( "Paste Style" ), app, SLOT( pasteStyle() ) );
if ( layer->type() == QgsMapLayer::VectorLayer )
{
QMenu *copyStyleMenu = menuStyleManager->addMenu( tr( "Paste Style" ) );
copyStyleMenu->setToolTipsVisible( true );
QList<QgsMapLayer::StyleCategory> categories = qgsEnumMap<QgsMapLayer::StyleCategory>().keys();
categories.move( categories.indexOf( QgsMapLayer::AllCategories ), 0 ); // move All categories to top
for ( QgsMapLayer::StyleCategory category : categories )
{
QgsMapLayer::ReadableStyleCategory readableCategory = QgsMapLayer::readableStyleCategory( category );
QAction *copyAction = new QAction( readableCategory.icon(), readableCategory.name() );
copyAction->setToolTip( readableCategory.toolTip() );
connect( copyAction, &QAction::triggered, this, [ = ]() {app->pasteStyle( layer, category );} );
copyStyleMenu->addAction( copyAction );
if ( category == QgsMapLayer::AllCategories )
copyStyleMenu->addSeparator();
}
}
else
{
menuStyleManager->addAction( tr( "Paste Style" ), app, SLOT( pasteStyle() ) );
}
}

menuStyleManager->addSeparator();
@@ -1080,7 +1080,7 @@ bool QgsMapLayer::importNamedMetadata( QDomDocument &document, QString &errorMes
return mMetadata.readMetadataXml( myRoot );
}

bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMessage )
bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMessage, QgsMapLayer::StyleCategories categories )
{
QDomElement myRoot = myDocument.firstChildElement( QStringLiteral( "qgis" ) );
if ( myRoot.isNull() )
@@ -1111,22 +1111,8 @@ bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMe
}
}

// use scale dependent visibility flag
setScaleBasedVisibility( myRoot.attribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
if ( myRoot.hasAttribute( QStringLiteral( "minimumScale" ) ) )
{
//older scale element, when min/max were reversed
setMaximumScale( myRoot.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
setMinimumScale( myRoot.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
}
else
{
setMaximumScale( myRoot.attribute( QStringLiteral( "maxScale" ) ).toDouble() );
setMinimumScale( myRoot.attribute( QStringLiteral( "minScale" ) ).toDouble() );
}

QgsReadWriteContext context = QgsReadWriteContext();
return readSymbology( myRoot, myErrorMessage, context ); // TODO: support relative paths in QML?
return readSymbology( myRoot, myErrorMessage, context, categories ); // TODO: support relative paths in QML?
}

void QgsMapLayer::exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const
@@ -781,15 +781,18 @@ class CORE_EXPORT QgsMapLayer : public QObject
* \param doc source QDomDocument
* \param errorMsg this QString will be initialized on error
* during the execution of readSymbology
* \param categories the style categories to import
* \returns true on success
* \since QGIS 2.8
*/
virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT );
virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories );

/**
* Export the properties of this layer as named style in a QDomDocument
* \param doc the target QDomDocument
* \param errorMsg this QString will be initialized on error
* \param categories the style categories to export
* during the execution of writeSymbology
*/
virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, QgsReadWriteContext &context,

0 comments on commit e91a42d

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