Skip to content

Commit

Permalink
Add qgis::overload method for new-style Qt connects
Browse files Browse the repository at this point in the history
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 fa051d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 24 additions & 2 deletions src/core/qgis.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/gui/symbology/qgssymbollayerwidget.cpp
Expand Up @@ -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 );
Expand Down

0 comments on commit fa051d5

Please sign in to comment.