From 96baf1b64ce5475ffd0948ac8db9efaffba10968 Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Wed, 28 Aug 2019 08:01:01 +0200 Subject: [PATCH 01/11] [feature] Allow renaming of the current map theme --- .../qgsmapthemecollection.sip.in | 18 ++++++++++-- src/app/qgsmapthemes.cpp | 28 +++++++++++++++++++ src/app/qgsmapthemes.h | 4 +++ src/core/qgsmapthemecollection.cpp | 13 +++++++++ src/core/qgsmapthemecollection.h | 16 +++++++++-- 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/python/core/auto_generated/qgsmapthemecollection.sip.in b/python/core/auto_generated/qgsmapthemecollection.sip.in index 70f35fe7419..9e1b0fce790 100644 --- a/python/core/auto_generated/qgsmapthemecollection.sip.in +++ b/python/core/auto_generated/qgsmapthemecollection.sip.in @@ -186,14 +186,21 @@ Updates a map theme within the collection. void removeMapTheme( const QString &name ); %Docstring -Remove an existing map theme from collection. +Removes an existing map theme from collection. .. versionadded:: 3.0 +%End + + void renameMapTheme( const QString &name, const QString &newName ); +%Docstring +Renames an existing map theme in the collection. + +.. versionadded:: 3.12 %End void clear(); %Docstring -Remove all map themes from the collection. +Removes all map themes from the collection. %End QStringList mapThemes() const; @@ -324,6 +331,13 @@ Emitted when map themes within the collection are changed. Emitted when a map theme changes definition. .. versionadded:: 3.0 +%End + + void mapThemeRenamed( const QString &name, const QString &newName ); +%Docstring +Emitted when a map theme within the collection is renamed. + +.. versionadded:: 3.12 %End void projectChanged(); diff --git a/src/app/qgsmapthemes.cpp b/src/app/qgsmapthemes.cpp index 687cb3bd97e..461eba4fe62 100644 --- a/src/app/qgsmapthemes.cpp +++ b/src/app/qgsmapthemes.cpp @@ -47,6 +47,7 @@ QgsMapThemes::QgsMapThemes() mReplaceMenu = new QMenu( tr( "Replace Theme" ) ); mMenu->addMenu( mReplaceMenu ); + mActionRenameCurrentPreset = mMenu->addAction( tr( "Rename Current Theme…" ), this, &QgsMapThemes::renameCurrentPreset ); mActionAddPreset = mMenu->addAction( tr( "Add Theme…" ), this, [ = ] { addPreset(); } ); mMenuSeparator = mMenu->addSeparator(); @@ -138,6 +139,32 @@ void QgsMapThemes::applyState( const QString &presetName ) QgsProject::instance()->mapThemeCollection()->applyTheme( presetName, root, model ); } +void QgsMapThemes::renameCurrentPreset() +{ + QgsMapThemeCollection::MapThemeRecord mapTheme = currentState(); + QStringList existingNames = QgsProject::instance()->mapThemeCollection()->mapThemes(); + + for ( QAction *actionPreset : qgis::as_const( mMenuPresetActions ) ) + { + if ( actionPreset->isChecked() ) + { + QgsNewNameDialog dlg( + tr( "theme" ), + tr( "%1" ).arg( actionPreset->text() ), + QStringList(), existingNames, QRegExp(), Qt::CaseInsensitive, mMenu ); + + dlg.setWindowTitle( tr( "Rename Map Theme" ) ); + dlg.setHintString( tr( "Enter the new name of the map theme" ) ); + dlg.setOverwriteEnabled( false ); + dlg.setConflictingNameWarning( tr( "A theme with this name already exists." ) ); + if ( dlg.exec() != QDialog::Accepted || dlg.name().isEmpty() ) + return; + + QgsProject::instance()->mapThemeCollection()->renameMapTheme( actionPreset->text(), dlg.name() ); + } + } +} + void QgsMapThemes::removeCurrentPreset() { for ( QAction *actionPreset : qgis::as_const( mMenuPresetActions ) ) @@ -187,4 +214,5 @@ void QgsMapThemes::menuAboutToShow() mActionAddPreset->setEnabled( !hasCurrent ); mActionRemoveCurrentPreset->setEnabled( hasCurrent ); + mActionRenameCurrentPreset->setEnabled( hasCurrent ); } diff --git a/src/app/qgsmapthemes.h b/src/app/qgsmapthemes.h index 1a1f09e4331..84a36adae59 100644 --- a/src/app/qgsmapthemes.h +++ b/src/app/qgsmapthemes.h @@ -65,6 +65,9 @@ class APP_EXPORT QgsMapThemes : public QObject //! Handles removal of current preset from the project's collection void removeCurrentPreset(); + //! Handles renaming of the current map theme + void renameCurrentPreset(); + //! Handles creation of preset menu void menuAboutToShow(); @@ -91,6 +94,7 @@ class APP_EXPORT QgsMapThemes : public QObject QAction *mMenuSeparator = nullptr; QAction *mActionAddPreset = nullptr; QAction *mActionRemoveCurrentPreset = nullptr; + QAction *mActionRenameCurrentPreset = nullptr; QList mMenuPresetActions; QList mMenuReplaceActions; }; diff --git a/src/core/qgsmapthemecollection.cpp b/src/core/qgsmapthemecollection.cpp index c6da0af31ac..f6b62c9d755 100644 --- a/src/core/qgsmapthemecollection.cpp +++ b/src/core/qgsmapthemecollection.cpp @@ -281,6 +281,19 @@ void QgsMapThemeCollection::update( const QString &name, const MapThemeRecord &s emit mapThemesChanged(); } + +void QgsMapThemeCollection::renameMapTheme( const QString &name, const QString &newName ) //, const MapThemeRecord &state ) +{ + if ( !mMapThemes.contains( name ) || mMapThemes.contains( newName ) ) + return; + + const MapThemeRecord state = mMapThemes[name]; + const MapThemeRecord newState = state; + insert( newName, newState ); + emit mapThemeRenamed( name, newName ); + removeMapTheme( name ); +} + void QgsMapThemeCollection::removeMapTheme( const QString &name ) { if ( !mMapThemes.contains( name ) ) diff --git a/src/core/qgsmapthemecollection.h b/src/core/qgsmapthemecollection.h index 12389afeee3..0e5fe35fce0 100644 --- a/src/core/qgsmapthemecollection.h +++ b/src/core/qgsmapthemecollection.h @@ -257,12 +257,18 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject void update( const QString &name, const QgsMapThemeCollection::MapThemeRecord &state ); /** - * Remove an existing map theme from collection. + * Removes an existing map theme from collection. * \since QGIS 3.0 */ void removeMapTheme( const QString &name ); - //! Remove all map themes from the collection. + /** + * Renames an existing map theme in the collection. + * \since QGIS 3.12 + */ + void renameMapTheme( const QString &name, const QString &newName ); + + //! Removes all map themes from the collection. void clear(); /** @@ -373,6 +379,12 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject */ void mapThemeChanged( const QString &theme ); + /** + * Emitted when a map theme within the collection is renamed. + * \since QGIS 3.12 + */ + void mapThemeRenamed( const QString &name, const QString &newName ); + /** * Emitted when the project changes * From ad43567e1f0dd90e890192fec62127d3bf872ada Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Thu, 21 Nov 2019 09:06:58 +0100 Subject: [PATCH 02/11] Keep in sync new map theme name with layout map item visibility If the applied map theme is being renamed, ensure we do not lose that. --- src/core/layout/qgslayoutitemmap.cpp | 12 ++++++++++++ src/core/layout/qgslayoutitemmap.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/core/layout/qgslayoutitemmap.cpp b/src/core/layout/qgslayoutitemmap.cpp index 166f91792a0..65e2dc0d58a 100644 --- a/src/core/layout/qgslayoutitemmap.cpp +++ b/src/core/layout/qgslayoutitemmap.cpp @@ -1778,6 +1778,17 @@ void QgsLayoutItemMap::mapThemeChanged( const QString &theme ) mCachedLayerStyleOverridesPresetName.clear(); // force cache regeneration at next redraw } +void QgsLayoutItemMap::currentMapThemeRenamed( const QString &theme, const QString &newTheme ) +{ + if ( mFollowVisibilityPreset ) + { + if ( theme == mFollowVisibilityPresetName ) + { + mFollowVisibilityPresetName = newTheme; + } + } +} + void QgsLayoutItemMap::connectUpdateSlot() { //connect signal from layer registry to update in case of new or deleted layers @@ -1820,6 +1831,7 @@ void QgsLayoutItemMap::connectUpdateSlot() } ); connect( project->mapThemeCollection(), &QgsMapThemeCollection::mapThemeChanged, this, &QgsLayoutItemMap::mapThemeChanged ); + connect( project->mapThemeCollection(), &QgsMapThemeCollection::mapThemeRenamed, this, &QgsLayoutItemMap::currentMapThemeRenamed ); } QTransform QgsLayoutItemMap::layoutToMapCoordsTransform() const diff --git a/src/core/layout/qgslayoutitemmap.h b/src/core/layout/qgslayoutitemmap.h index 8ccdcebb180..d278f63e41c 100644 --- a/src/core/layout/qgslayoutitemmap.h +++ b/src/core/layout/qgslayoutitemmap.h @@ -622,6 +622,9 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem void mapThemeChanged( const QString &theme ); + //! Applies current visibility presets to the renamed map theme + void currentMapThemeRenamed( const QString &theme, const QString &newTheme ); + //! Create cache image void recreateCachedImageInBackground(); From be60ea5eeca430bdad43b136311ba812460a3a6a Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Thu, 16 Jan 2020 08:03:39 +0100 Subject: [PATCH 03/11] Update additional map view canvas when it uses the renamed map theme --- src/app/qgsmapcanvasdockwidget.cpp | 10 ++++++++++ src/app/qgsmapcanvasdockwidget.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/app/qgsmapcanvasdockwidget.cpp b/src/app/qgsmapcanvasdockwidget.cpp index 3b5165cb29b..e521ed7792f 100644 --- a/src/app/qgsmapcanvasdockwidget.cpp +++ b/src/app/qgsmapcanvasdockwidget.cpp @@ -227,6 +227,8 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa if ( mSyncExtentRadio->isChecked() ) syncViewCenter( mMainCanvas ); } ); + + connect( QgsProject::instance()->mapThemeCollection(), &QgsMapThemeCollection::mapThemeRenamed, this, &QgsMapCanvasDockWidget::currentMapThemeRenamed ); } void QgsMapCanvasDockWidget::setMainCanvas( QgsMapCanvas *canvas ) @@ -441,6 +443,14 @@ void QgsMapCanvasDockWidget::menuAboutToShow() mMenu->addActions( mMenuPresetActions ); } +void QgsMapCanvasDockWidget::currentMapThemeRenamed( const QString &theme, const QString &newTheme ) +{ + if ( theme == mMapCanvas->theme() ) + { + mMapCanvas->setTheme( newTheme ); + } +} + void QgsMapCanvasDockWidget::settingsMenuAboutToShow() { whileBlocking( mActionShowAnnotations )->setChecked( mMapCanvas->annotationsVisible() ); diff --git a/src/app/qgsmapcanvasdockwidget.h b/src/app/qgsmapcanvasdockwidget.h index 398a0e68abf..d4fdd8f788c 100644 --- a/src/app/qgsmapcanvasdockwidget.h +++ b/src/app/qgsmapcanvasdockwidget.h @@ -157,6 +157,7 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM void mapExtentChanged(); void mapCrsChanged(); void menuAboutToShow(); + void currentMapThemeRenamed( const QString &theme, const QString &newTheme ); void settingsMenuAboutToShow(); void syncMarker( const QgsPointXY &p ); void mapScaleChanged(); From 27ce90d82882066b37585a459adfb61194c169ca Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Tue, 21 Jan 2020 07:21:47 +0100 Subject: [PATCH 04/11] Update target version --- python/core/auto_generated/qgsmapthemecollection.sip.in | 4 ++-- src/core/qgsmapthemecollection.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/core/auto_generated/qgsmapthemecollection.sip.in b/python/core/auto_generated/qgsmapthemecollection.sip.in index 9e1b0fce790..42f8c0799c5 100644 --- a/python/core/auto_generated/qgsmapthemecollection.sip.in +++ b/python/core/auto_generated/qgsmapthemecollection.sip.in @@ -195,7 +195,7 @@ Removes an existing map theme from collection. %Docstring Renames an existing map theme in the collection. -.. versionadded:: 3.12 +.. versionadded:: 3.14 %End void clear(); @@ -337,7 +337,7 @@ Emitted when a map theme changes definition. %Docstring Emitted when a map theme within the collection is renamed. -.. versionadded:: 3.12 +.. versionadded:: 3.14 %End void projectChanged(); diff --git a/src/core/qgsmapthemecollection.h b/src/core/qgsmapthemecollection.h index 0e5fe35fce0..cd0705ad95c 100644 --- a/src/core/qgsmapthemecollection.h +++ b/src/core/qgsmapthemecollection.h @@ -264,7 +264,7 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject /** * Renames an existing map theme in the collection. - * \since QGIS 3.12 + * \since QGIS 3.14 */ void renameMapTheme( const QString &name, const QString &newName ); @@ -381,7 +381,7 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject /** * Emitted when a map theme within the collection is renamed. - * \since QGIS 3.12 + * \since QGIS 3.14 */ void mapThemeRenamed( const QString &name, const QString &newName ); From a7ca951dda8637360ad12a83717b238ee2fbe99c Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Tue, 21 Jan 2020 07:59:49 +0100 Subject: [PATCH 05/11] Make map canvas follow active theme renaming and add test --- src/gui/qgsmapcanvas.cpp | 12 ++++++++++++ src/gui/qgsmapcanvas.h | 1 + tests/src/python/test_qgsmapcanvas.py | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index 8cd1fde0b36..d7af3a09f1c 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -138,6 +138,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent ) this, &QgsMapCanvas::writeProject ); connect( QgsProject::instance()->mapThemeCollection(), &QgsMapThemeCollection::mapThemeChanged, this, &QgsMapCanvas::mapThemeChanged ); + connect( QgsProject::instance()->mapThemeCollection(), &QgsMapThemeCollection::mapThemeRenamed, this, &QgsMapCanvas::mapThemeRenamed ); connect( QgsProject::instance()->mapThemeCollection(), &QgsMapThemeCollection::mapThemesChanged, this, &QgsMapCanvas::projectThemesChanged ); mSettings.setFlag( QgsMapSettings::DrawEditingInfo ); @@ -610,6 +611,17 @@ void QgsMapCanvas::mapThemeChanged( const QString &theme ) } } +void QgsMapCanvas::mapThemeRenamed( const QString &theme, const QString &newTheme ) +{ + if ( mTheme.isEmpty() || theme != mTheme ) + { + return; + } + + setTheme( newTheme ); + refresh(); +} + void QgsMapCanvas::rendererJobFinished() { QgsDebugMsgLevel( QStringLiteral( "CANVAS finish! %1" ).arg( !mJobCanceled ), 2 ); diff --git a/src/gui/qgsmapcanvas.h b/src/gui/qgsmapcanvas.h index 4430be7764f..426504dee1b 100644 --- a/src/gui/qgsmapcanvas.h +++ b/src/gui/qgsmapcanvas.h @@ -827,6 +827,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView void refreshMap(); void mapThemeChanged( const QString &theme ); + void mapThemeRenamed( const QString &theme, const QString &newTheme ); signals: diff --git a/tests/src/python/test_qgsmapcanvas.py b/tests/src/python/test_qgsmapcanvas.py index 2fc79bef243..3a46e5992f3 100644 --- a/tests/src/python/test_qgsmapcanvas.py +++ b/tests/src/python/test_qgsmapcanvas.py @@ -331,6 +331,24 @@ class TestQgsMapCanvas(unittest.TestCase): # should be different - we should now render project layers self.assertFalse(self.canvasImageCheck('theme4', 'theme4', canvas)) + # set canvas to theme1 + canvas.setTheme('theme1') + canvas.refresh() + canvas.waitWhileRendering() + self.assertEqual(canvas.theme(), 'theme1') + themeLayers = theme1.layerRecords() + # rename the active theme + QgsProject.instance().mapThemeCollection().renameMapTheme('theme1', 'theme5') + # canvas theme should now be set to theme5 + canvas.refresh() + canvas.waitWhileRendering() + self.assertEqual(canvas.theme(), 'theme5') + # theme5 should render as theme1 + theme5 = QgsProject.instance().mapThemeCollection().mapThemeState('theme5') + theme5Layers = theme5.layerRecords() + self.assertEqual(themeLayers, theme5Layers, 'themes are different') + #self.assertTrue(self.canvasImageCheck('theme5', 'theme5', canvas)) + def canvasImageCheck(self, name, reference_image, canvas): self.report += "

Render {}

\n".format(name) temp_dir = QDir.tempPath() + '/' From e7550818b11c42db8a9a402430d22c2480b680ac Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Thu, 6 Feb 2020 07:02:42 +0100 Subject: [PATCH 06/11] Apply suggestions from review --- python/core/auto_generated/qgsmapthemecollection.sip.in | 8 ++++---- src/core/layout/qgslayoutitemmap.cpp | 7 ++----- src/core/qgsmapthemecollection.cpp | 6 +++--- src/core/qgsmapthemecollection.h | 8 ++++---- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/python/core/auto_generated/qgsmapthemecollection.sip.in b/python/core/auto_generated/qgsmapthemecollection.sip.in index 42f8c0799c5..ef9a6ca6871 100644 --- a/python/core/auto_generated/qgsmapthemecollection.sip.in +++ b/python/core/auto_generated/qgsmapthemecollection.sip.in @@ -191,11 +191,11 @@ Removes an existing map theme from collection. .. versionadded:: 3.0 %End - void renameMapTheme( const QString &name, const QString &newName ); + bool renameMapTheme( const QString &name, const QString &newName ); %Docstring -Renames an existing map theme in the collection. +Retuns whether a map theme is renamed. -.. versionadded:: 3.14 +.. versionadded:: 3.12 %End void clear(); @@ -337,7 +337,7 @@ Emitted when a map theme changes definition. %Docstring Emitted when a map theme within the collection is renamed. -.. versionadded:: 3.14 +.. versionadded:: 3.12 %End void projectChanged(); diff --git a/src/core/layout/qgslayoutitemmap.cpp b/src/core/layout/qgslayoutitemmap.cpp index 65e2dc0d58a..bf559d0edcc 100644 --- a/src/core/layout/qgslayoutitemmap.cpp +++ b/src/core/layout/qgslayoutitemmap.cpp @@ -1780,12 +1780,9 @@ void QgsLayoutItemMap::mapThemeChanged( const QString &theme ) void QgsLayoutItemMap::currentMapThemeRenamed( const QString &theme, const QString &newTheme ) { - if ( mFollowVisibilityPreset ) + if ( theme == mFollowVisibilityPresetName ) { - if ( theme == mFollowVisibilityPresetName ) - { - mFollowVisibilityPresetName = newTheme; - } + mFollowVisibilityPresetName = newTheme; } } diff --git a/src/core/qgsmapthemecollection.cpp b/src/core/qgsmapthemecollection.cpp index f6b62c9d755..09e7d013721 100644 --- a/src/core/qgsmapthemecollection.cpp +++ b/src/core/qgsmapthemecollection.cpp @@ -281,17 +281,17 @@ void QgsMapThemeCollection::update( const QString &name, const MapThemeRecord &s emit mapThemesChanged(); } - -void QgsMapThemeCollection::renameMapTheme( const QString &name, const QString &newName ) //, const MapThemeRecord &state ) +bool QgsMapThemeCollection::renameMapTheme( const QString &name, const QString &newName ) { if ( !mMapThemes.contains( name ) || mMapThemes.contains( newName ) ) - return; + return false; const MapThemeRecord state = mMapThemes[name]; const MapThemeRecord newState = state; insert( newName, newState ); emit mapThemeRenamed( name, newName ); removeMapTheme( name ); + return true; } void QgsMapThemeCollection::removeMapTheme( const QString &name ) diff --git a/src/core/qgsmapthemecollection.h b/src/core/qgsmapthemecollection.h index cd0705ad95c..56bd250fcfb 100644 --- a/src/core/qgsmapthemecollection.h +++ b/src/core/qgsmapthemecollection.h @@ -263,10 +263,10 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject void removeMapTheme( const QString &name ); /** - * Renames an existing map theme in the collection. - * \since QGIS 3.14 + * Retuns whether a map theme is renamed. + * \since QGIS 3.12 */ - void renameMapTheme( const QString &name, const QString &newName ); + bool renameMapTheme( const QString &name, const QString &newName ); //! Removes all map themes from the collection. void clear(); @@ -381,7 +381,7 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject /** * Emitted when a map theme within the collection is renamed. - * \since QGIS 3.14 + * \since QGIS 3.12 */ void mapThemeRenamed( const QString &name, const QString &newName ); From ee58be521a75d9e43cc6462cb62c9ba1cfe0a2b7 Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Thu, 6 Feb 2020 07:14:26 +0100 Subject: [PATCH 07/11] Fix renameMapTheme dox Co-Authored-By: Nyall Dawson --- src/core/qgsmapthemecollection.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/qgsmapthemecollection.h b/src/core/qgsmapthemecollection.h index 56bd250fcfb..b4c3b4d7090 100644 --- a/src/core/qgsmapthemecollection.h +++ b/src/core/qgsmapthemecollection.h @@ -263,7 +263,8 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject void removeMapTheme( const QString &name ); /** - * Retuns whether a map theme is renamed. + * Renames the existing map theme called \a name to \a newName. + * Returns TRUE if the rename was successful, or FALSE if it failed (e.g. due to a duplicate name for \a newName). * \since QGIS 3.12 */ bool renameMapTheme( const QString &name, const QString &newName ); From 1ad5c43c4e149825380dfcda1562536ce7d21cda Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Thu, 6 Feb 2020 10:13:06 +0100 Subject: [PATCH 08/11] Update sip file --- python/core/auto_generated/qgsmapthemecollection.sip.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/core/auto_generated/qgsmapthemecollection.sip.in b/python/core/auto_generated/qgsmapthemecollection.sip.in index ef9a6ca6871..25f90ade3a8 100644 --- a/python/core/auto_generated/qgsmapthemecollection.sip.in +++ b/python/core/auto_generated/qgsmapthemecollection.sip.in @@ -193,7 +193,8 @@ Removes an existing map theme from collection. bool renameMapTheme( const QString &name, const QString &newName ); %Docstring -Retuns whether a map theme is renamed. +Renames the existing map theme called ``name`` to ``newName``. +Returns ``True`` if the rename was successful, or ``False`` if it failed (e.g. due to a duplicate name for ``newName``). .. versionadded:: 3.12 %End From 23585d4142fb11fef8c40b131b6deb3960d68e4b Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Tue, 24 Mar 2020 02:43:50 +0100 Subject: [PATCH 09/11] Update 3D canvas active map theme name --- src/app/3d/qgs3dmapcanvasdockwidget.cpp | 9 +++++++++ src/app/3d/qgs3dmapcanvasdockwidget.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/app/3d/qgs3dmapcanvasdockwidget.cpp b/src/app/3d/qgs3dmapcanvasdockwidget.cpp index 8eec53dd266..4ac4d6794a2 100644 --- a/src/app/3d/qgs3dmapcanvasdockwidget.cpp +++ b/src/app/3d/qgs3dmapcanvasdockwidget.cpp @@ -103,6 +103,7 @@ Qgs3DMapCanvasDockWidget::Qgs3DMapCanvasDockWidget( QWidget *parent ) // Map Theme Menu mMapThemeMenu = new QMenu(); connect( mMapThemeMenu, &QMenu::aboutToShow, this, &Qgs3DMapCanvasDockWidget::mapThemeMenuAboutToShow ); + connect( QgsProject::instance()->mapThemeCollection(), &QgsMapThemeCollection::mapThemeRenamed, this, &Qgs3DMapCanvasDockWidget::currentMapThemeRenamed ); mBtnMapThemes = new QToolButton(); mBtnMapThemes->setAutoRaise( true ); @@ -344,3 +345,11 @@ void Qgs3DMapCanvasDockWidget::mapThemeMenuAboutToShow() } mMapThemeMenu->addActions( mMapThemeMenuPresetActions ); } + +void Qgs3DMapCanvasDockWidget::currentMapThemeRenamed( const QString &theme, const QString &newTheme ) +{ + if ( theme == mCanvas->map()->terrainMapTheme() ) + { + mCanvas->map()->setTerrainMapTheme( newTheme ); + } +} diff --git a/src/app/3d/qgs3dmapcanvasdockwidget.h b/src/app/3d/qgs3dmapcanvasdockwidget.h index 457f010dee4..64e43abac40 100644 --- a/src/app/3d/qgs3dmapcanvasdockwidget.h +++ b/src/app/3d/qgs3dmapcanvasdockwidget.h @@ -65,6 +65,7 @@ class APP_EXPORT Qgs3DMapCanvasDockWidget : public QgsDockWidget void onMainCanvasColorChanged(); void onTotalPendingJobsCountChanged(); void mapThemeMenuAboutToShow(); + void currentMapThemeRenamed( const QString &theme, const QString &newTheme ); private: Qgs3DMapCanvas *mCanvas = nullptr; From 5329f0548544cbcdcd4f600be48a56ad014782b8 Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Sat, 28 Mar 2020 15:59:18 +0100 Subject: [PATCH 10/11] Fix target version --- python/core/auto_generated/qgsmapthemecollection.sip.in | 4 ++-- src/core/qgsmapthemecollection.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/core/auto_generated/qgsmapthemecollection.sip.in b/python/core/auto_generated/qgsmapthemecollection.sip.in index 25f90ade3a8..1891581f008 100644 --- a/python/core/auto_generated/qgsmapthemecollection.sip.in +++ b/python/core/auto_generated/qgsmapthemecollection.sip.in @@ -196,7 +196,7 @@ Removes an existing map theme from collection. Renames the existing map theme called ``name`` to ``newName``. Returns ``True`` if the rename was successful, or ``False`` if it failed (e.g. due to a duplicate name for ``newName``). -.. versionadded:: 3.12 +.. versionadded:: 3.14 %End void clear(); @@ -338,7 +338,7 @@ Emitted when a map theme changes definition. %Docstring Emitted when a map theme within the collection is renamed. -.. versionadded:: 3.12 +.. versionadded:: 3.14 %End void projectChanged(); diff --git a/src/core/qgsmapthemecollection.h b/src/core/qgsmapthemecollection.h index b4c3b4d7090..741ca0e3dfb 100644 --- a/src/core/qgsmapthemecollection.h +++ b/src/core/qgsmapthemecollection.h @@ -265,7 +265,7 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject /** * Renames the existing map theme called \a name to \a newName. * Returns TRUE if the rename was successful, or FALSE if it failed (e.g. due to a duplicate name for \a newName). - * \since QGIS 3.12 + * \since QGIS 3.14 */ bool renameMapTheme( const QString &name, const QString &newName ); @@ -382,7 +382,7 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject /** * Emitted when a map theme within the collection is renamed. - * \since QGIS 3.12 + * \since QGIS 3.14 */ void mapThemeRenamed( const QString &name, const QString &newName ); From 9fc5985c7491b9fddf78a3fc3398cebb7be5ce05 Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Thu, 23 Apr 2020 08:37:28 +0200 Subject: [PATCH 11/11] More doc strings --- src/app/3d/qgs3dmapcanvasdockwidget.h | 1 + src/app/qgsmapcanvasdockwidget.h | 1 + src/core/layout/qgslayoutitemmap.h | 2 +- src/gui/qgsmapcanvas.h | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/3d/qgs3dmapcanvasdockwidget.h b/src/app/3d/qgs3dmapcanvasdockwidget.h index 64e43abac40..ac0b26d59bd 100644 --- a/src/app/3d/qgs3dmapcanvasdockwidget.h +++ b/src/app/3d/qgs3dmapcanvasdockwidget.h @@ -65,6 +65,7 @@ class APP_EXPORT Qgs3DMapCanvasDockWidget : public QgsDockWidget void onMainCanvasColorChanged(); void onTotalPendingJobsCountChanged(); void mapThemeMenuAboutToShow(); + //! Renames the active map theme called \a theme to \a newTheme void currentMapThemeRenamed( const QString &theme, const QString &newTheme ); private: diff --git a/src/app/qgsmapcanvasdockwidget.h b/src/app/qgsmapcanvasdockwidget.h index d4fdd8f788c..a912ccd9c38 100644 --- a/src/app/qgsmapcanvasdockwidget.h +++ b/src/app/qgsmapcanvasdockwidget.h @@ -157,6 +157,7 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM void mapExtentChanged(); void mapCrsChanged(); void menuAboutToShow(); + //! Renames the active map theme called \a theme to \a newTheme void currentMapThemeRenamed( const QString &theme, const QString &newTheme ); void settingsMenuAboutToShow(); void syncMarker( const QgsPointXY &p ); diff --git a/src/core/layout/qgslayoutitemmap.h b/src/core/layout/qgslayoutitemmap.h index d278f63e41c..52d0b0f0401 100644 --- a/src/core/layout/qgslayoutitemmap.h +++ b/src/core/layout/qgslayoutitemmap.h @@ -622,7 +622,7 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem void mapThemeChanged( const QString &theme ); - //! Applies current visibility presets to the renamed map theme + //! Renames the active map theme called \a theme to \a newTheme void currentMapThemeRenamed( const QString &theme, const QString &newTheme ); //! Create cache image diff --git a/src/gui/qgsmapcanvas.h b/src/gui/qgsmapcanvas.h index 426504dee1b..837f64eddc3 100644 --- a/src/gui/qgsmapcanvas.h +++ b/src/gui/qgsmapcanvas.h @@ -827,6 +827,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView void refreshMap(); void mapThemeChanged( const QString &theme ); + //! Renames the active map theme called \a theme to \a newTheme void mapThemeRenamed( const QString &theme, const QString &newTheme ); signals: