Skip to content
Permalink
Browse files

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
  • Loading branch information
nyalldawson committed Apr 6, 2018
1 parent ebab649 commit fa051d5f2d3b13c53232f460fdbbf9fa7f47d07b
Showing with 26 additions and 4 deletions.
  1. +24 −2 src/core/qgis.h
  2. +2 −2 src/gui/symbology/qgssymbollayerwidget.cpp
@@ -299,9 +299,10 @@ inline double qgsRound( double number, double places )
///@cond PRIVATE

/**
* Contains "polyfills" for backporting c++ features from standards > c++11.
* Contains "polyfills" for backporting c++ features from standards > c++11 and Qt global methods
* added later than our minimum version.
*
* To be removed when minimum c++ build requirement includes the std implementation
* To be removed when minimum c++ or Qt build requirement includes the std implementation
* for these features.
*
* \note not available in Python bindings.
@@ -361,6 +362,27 @@ namespace qgis
template<class T, class... Args>
typename _Unique_if<T>::_Known_bound
make_unique( Args &&... ) = delete;

/**
* 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
*/
template<typename... Args> struct overload
{
template<typename C, typename R>
static constexpr auto of( R( C::*pmf )( Args... ) ) -> decltype( pmf )
{
return pmf;
}
};
}
///@endcond
#endif
@@ -1373,8 +1373,8 @@ QgsShapeburstFillSymbolLayerWidget::QgsShapeburstFillSymbolLayerWidget( QgsVecto
mLayer = nullptr;

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

0 comments on commit fa051d5

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