diff --git a/python/gui/auto_generated/qgshighlight.sip.in b/python/gui/auto_generated/qgshighlight.sip.in index 6500ce660a5..ae02cad6f43 100644 --- a/python/gui/auto_generated/qgshighlight.sip.in +++ b/python/gui/auto_generated/qgshighlight.sip.in @@ -143,6 +143,13 @@ Returns the layer for which this highlight has been created. virtual void updatePosition(); + void applyDefaultStyle(); +%Docstring +Applies the default style from the user settings to the highlight. + +.. versionadded:: 3.30 +%End + protected: virtual void paint( QPainter *p ); diff --git a/python/gui/auto_generated/qgsidentifymenu.sip.in b/python/gui/auto_generated/qgsidentifymenu.sip.in index 73bcf051afa..941dcfd27de 100644 --- a/python/gui/auto_generated/qgsidentifymenu.sip.in +++ b/python/gui/auto_generated/qgsidentifymenu.sip.in @@ -161,11 +161,12 @@ exec :param pos: the position where the menu will be executed %End - static void styleHighlight( QgsHighlight *highlight ); + static void styleHighlight( QgsHighlight *highlight ) /Deprecated/; %Docstring Applies style from the settings to the highlight -.. versionadded:: 3.8 +.. deprecated:: + Use :py:func:`QgsHighlight.applyDefaultStyle()` instead. %End protected: diff --git a/src/app/qgsidentifyresultsdialog.cpp b/src/app/qgsidentifyresultsdialog.cpp index dfc2f28ba88..7a28ce9575e 100644 --- a/src/app/qgsidentifyresultsdialog.cpp +++ b/src/app/qgsidentifyresultsdialog.cpp @@ -2151,7 +2151,7 @@ void QgsIdentifyResultsDialog::highlightFeature( QTreeWidgetItem *item ) highlight->setWidth( 2 ); } - QgsIdentifyMenu::styleHighlight( highlight ); + highlight->applyDefaultStyle(); highlight->show(); mHighlights.insert( featItem, highlight ); } diff --git a/src/app/qgsmaptoolselectutils.cpp b/src/app/qgsmaptoolselectutils.cpp index ff4a80f0ac0..9df33ec3872 100644 --- a/src/app/qgsmaptoolselectutils.cpp +++ b/src/app/qgsmaptoolselectutils.cpp @@ -799,7 +799,7 @@ void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::highlightAllFeatures() if ( !geom.isEmpty() ) { QgsHighlight *hl = new QgsHighlight( mCanvas, geom, mVectorLayer ); - styleHighlight( hl ); + hl->applyDefaultStyle(); mHighlight.append( hl ); count++; } @@ -821,26 +821,11 @@ void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::highlightOneFeature( Qg if ( !geom.isEmpty() ) { QgsHighlight *hl = new QgsHighlight( mCanvas, geom, mVectorLayer ); - styleHighlight( hl ); + hl->applyDefaultStyle(); mHighlight.append( hl ); } } -void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::styleHighlight( QgsHighlight *highlight ) -{ - QgsSettings settings; - QColor color = QColor( settings.value( QStringLiteral( "Map/highlight/color" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() ); - int alpha = settings.value( QStringLiteral( "Map/highlight/colorAlpha" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.alpha() ).toInt(); - double buffer = settings.value( QStringLiteral( "Map/highlight/buffer" ), Qgis::DEFAULT_HIGHLIGHT_BUFFER_MM ).toDouble(); - double minWidth = settings.value( QStringLiteral( "Map/highlight/minWidth" ), Qgis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM ).toDouble(); - - highlight->setColor( color ); // sets also fill with default alpha - color.setAlpha( alpha ); - highlight->setFillColor( color ); // sets fill with alpha - highlight->setBuffer( buffer ); - highlight->setMinWidth( minWidth ); -} - QgsFeatureIds QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::filterIds( const QgsFeatureIds &ids, const QgsFeatureIds &existingSelection, Qgis::SelectBehavior behavior ) diff --git a/src/app/qgsmaptoolselectutils.h b/src/app/qgsmaptoolselectutils.h index 696d3340749..3bc48a8aced 100644 --- a/src/app/qgsmaptoolselectutils.h +++ b/src/app/qgsmaptoolselectutils.h @@ -171,8 +171,6 @@ namespace QgsMapToolSelectUtils void startFeatureSearch(); - void styleHighlight( QgsHighlight *highlight ); - QString textForChooseAll( qint64 featureCount = -1 ) const; QString textForChooseOneMenu() const; void populateChooseOneMenu( const QgsFeatureIds &ids ); diff --git a/src/gui/editorwidgets/qgsrelationreferencewidget.cpp b/src/gui/editorwidgets/qgsrelationreferencewidget.cpp index 3933259535d..6571a449054 100644 --- a/src/gui/editorwidgets/qgsrelationreferencewidget.cpp +++ b/src/gui/editorwidgets/qgsrelationreferencewidget.cpp @@ -43,7 +43,6 @@ #include "qgsfeaturelistcombobox.h" #include "qgsexpressioncontextutils.h" #include "qgsfeaturefiltermodel.h" -#include "qgsidentifymenu.h" #include "qgsvectorlayerutils.h" @@ -584,7 +583,7 @@ void QgsRelationReferenceWidget::highlightFeature( QgsFeature f, CanvasExtent ca // highlight deleteHighlight(); mHighlight = new QgsHighlight( mCanvas, f, mReferencedLayer ); - QgsIdentifyMenu::styleHighlight( mHighlight ); + mHighlight->applyDefaultStyle(); mHighlight->show(); QTimer *timer = new QTimer( this ); diff --git a/src/gui/qgshighlight.cpp b/src/gui/qgshighlight.cpp index 5c508e0352f..b64747c39b7 100644 --- a/src/gui/qgshighlight.cpp +++ b/src/gui/qgshighlight.cpp @@ -306,6 +306,21 @@ void QgsHighlight::updatePosition() updateRect(); } +void QgsHighlight::applyDefaultStyle() +{ + const QgsSettings settings; + QColor color = QColor( settings.value( QStringLiteral( "Map/highlight/color" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() ); + const int alpha = settings.value( QStringLiteral( "Map/highlight/colorAlpha" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.alpha() ).toInt(); + const double buffer = settings.value( QStringLiteral( "Map/highlight/buffer" ), Qgis::DEFAULT_HIGHLIGHT_BUFFER_MM ).toDouble(); + const double minWidth = settings.value( QStringLiteral( "Map/highlight/minWidth" ), Qgis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM ).toDouble(); + + setColor( color ); // sets also fill with default alpha + color.setAlpha( alpha ); + setFillColor( color ); // sets fill with alpha + setBuffer( buffer ); + setMinWidth( minWidth ); +} + void QgsHighlight::paint( QPainter *p ) { if ( mFeature.hasGeometry() ) diff --git a/src/gui/qgshighlight.h b/src/gui/qgshighlight.h index a14a5e7d9dc..ef5ad8f9842 100644 --- a/src/gui/qgshighlight.h +++ b/src/gui/qgshighlight.h @@ -172,6 +172,13 @@ class GUI_EXPORT QgsHighlight : public QgsMapCanvasItem void updatePosition() override; + /** + * Applies the default style from the user settings to the highlight. + * + * \since QGIS 3.30 + */ + void applyDefaultStyle(); + protected: void paint( QPainter *p ) override; diff --git a/src/gui/qgsidentifymenu.cpp b/src/gui/qgsidentifymenu.cpp index 30a0c71c3e8..cec083cb441 100644 --- a/src/gui/qgsidentifymenu.cpp +++ b/src/gui/qgsidentifymenu.cpp @@ -673,7 +673,7 @@ void QgsIdentifyMenu::handleMenuHover() continue; QgsHighlight *hl = new QgsHighlight( mCanvas, result.mFeature.geometry(), vl ); - styleHighlight( hl ); + hl->applyDefaultStyle(); mRubberBands.append( hl ); connect( vl, &QObject::destroyed, this, &QgsIdentifyMenu::layerDestroyed ); } @@ -681,17 +681,7 @@ void QgsIdentifyMenu::handleMenuHover() void QgsIdentifyMenu::styleHighlight( QgsHighlight *highlight ) { - const QgsSettings settings; - QColor color = QColor( settings.value( QStringLiteral( "Map/highlight/color" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() ); - const int alpha = settings.value( QStringLiteral( "Map/highlight/colorAlpha" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.alpha() ).toInt(); - const double buffer = settings.value( QStringLiteral( "Map/highlight/buffer" ), Qgis::DEFAULT_HIGHLIGHT_BUFFER_MM ).toDouble(); - const double minWidth = settings.value( QStringLiteral( "Map/highlight/minWidth" ), Qgis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM ).toDouble(); - - highlight->setColor( color ); // sets also fill with default alpha - color.setAlpha( alpha ); - highlight->setFillColor( color ); // sets fill with alpha - highlight->setBuffer( buffer ); - highlight->setMinWidth( minWidth ); + highlight->applyDefaultStyle(); } void QgsIdentifyMenu::deleteRubberBands() diff --git a/src/gui/qgsidentifymenu.h b/src/gui/qgsidentifymenu.h index 0e7cc269535..9c187fbf3ec 100644 --- a/src/gui/qgsidentifymenu.h +++ b/src/gui/qgsidentifymenu.h @@ -177,9 +177,9 @@ class GUI_EXPORT QgsIdentifyMenu : public QMenu /** * Applies style from the settings to the highlight * - * \since QGIS 3.8 + * \deprecated Use QgsHighlight::applyDefaultStyle() instead. */ - static void styleHighlight( QgsHighlight *highlight ); + Q_DECL_DEPRECATED static void styleHighlight( QgsHighlight *highlight ) SIP_DEPRECATED; protected: void closeEvent( QCloseEvent *e ) override;