Skip to content

Commit fa051d5

Browse files
committedApr 6, 2018
Add qgis::overload method for new-style Qt connects
Used for new-style Qt connects to overloaded signals, avoiding the usual horrible connect syntax required in these circumstances. Example usage: connect( mSpinBox, qgis::overload< int >::of( &QSpinBox::valueChanged ), this, &MyClass::mySlot ); This is an alternative to qOverload, which was implemented in Qt 5.7. See https://stackoverflow.com/a/16795664/1861260
1 parent ebab649 commit fa051d5

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed
 

‎src/core/qgis.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,10 @@ inline double qgsRound( double number, double places )
299299
///@cond PRIVATE
300300

301301
/**
302-
* Contains "polyfills" for backporting c++ features from standards > c++11.
302+
* Contains "polyfills" for backporting c++ features from standards > c++11 and Qt global methods
303+
* added later than our minimum version.
303304
*
304-
* To be removed when minimum c++ build requirement includes the std implementation
305+
* To be removed when minimum c++ or Qt build requirement includes the std implementation
305306
* for these features.
306307
*
307308
* \note not available in Python bindings.
@@ -361,6 +362,27 @@ namespace qgis
361362
template<class T, class... Args>
362363
typename _Unique_if<T>::_Known_bound
363364
make_unique( Args &&... ) = delete;
365+
366+
/**
367+
* Used for new-style Qt connects to overloaded signals, avoiding the usual horrible connect syntax required
368+
* in these circumstances.
369+
*
370+
* Example usage:
371+
*
372+
* connect( mSpinBox, qgis::overload< int >::of( &QSpinBox::valueChanged ), this, &MyClass::mySlot );
373+
*
374+
* This is an alternative to qOverload, which was implemented in Qt 5.7.
375+
*
376+
* See https://stackoverflow.com/a/16795664/1861260
377+
*/
378+
template<typename... Args> struct overload
379+
{
380+
template<typename C, typename R>
381+
static constexpr auto of( R( C::*pmf )( Args... ) ) -> decltype( pmf )
382+
{
383+
return pmf;
384+
}
385+
};
364386
}
365387
///@endcond
366388
#endif

‎src/gui/symbology/qgssymbollayerwidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,8 +1373,8 @@ QgsShapeburstFillSymbolLayerWidget::QgsShapeburstFillSymbolLayerWidget( QgsVecto
13731373
mLayer = nullptr;
13741374

13751375
setupUi( this );
1376-
connect( mSpinBlurRadius, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsShapeburstFillSymbolLayerWidget::mSpinBlurRadius_valueChanged );
1377-
connect( mSpinMaxDistance, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsShapeburstFillSymbolLayerWidget::mSpinMaxDistance_valueChanged );
1376+
connect( mSpinBlurRadius, qgis::overload< int >::of( &QSpinBox::valueChanged ), this, &QgsShapeburstFillSymbolLayerWidget::mSpinBlurRadius_valueChanged );
1377+
connect( mSpinMaxDistance, qgis::overload< double >::of( &QDoubleSpinBox::valueChanged ), this, &QgsShapeburstFillSymbolLayerWidget::mSpinMaxDistance_valueChanged );
13781378
connect( mDistanceUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsShapeburstFillSymbolLayerWidget::mDistanceUnitWidget_changed );
13791379
connect( mRadioUseWholeShape, &QRadioButton::toggled, this, &QgsShapeburstFillSymbolLayerWidget::mRadioUseWholeShape_toggled );
13801380
connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsShapeburstFillSymbolLayerWidget::mOffsetUnitWidget_changed );

0 commit comments

Comments
 (0)
Please sign in to comment.