From 9346dba3f72263212e1c3c8f5db1a0952a26ac14 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Tue, 5 Nov 2019 09:27:55 +0100 Subject: [PATCH] Fix Qt::UniqueConnection with lambda --- CMakeLists.txt | 2 +- src/gui/editorwidgets/qgshtmlwidgetwrapper.cpp | 17 +++++++++++------ src/gui/editorwidgets/qgshtmlwidgetwrapper.h | 3 +++ .../qgsvaluerelationwidgetwrapper.cpp | 16 +++++++++------- .../qgsvaluerelationwidgetwrapper.h | 3 +++ 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a9471ae684..c59db511c60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -761,7 +761,7 @@ IF (WITH_CORE) MARK_AS_ADVANCED (ADD_CLAZY_CHECKS) IF (ADD_CLAZY_CHECKS) SET(CMAKE_CXX_BASE_FLAGS "${CMAKE_CXX_FLAGS}") - SET(CLAZY_BASE_CHECKS "connect-3arg-lambda") + SET(CLAZY_BASE_CHECKS "connect-3arg-lambda,lambda-unique-connection") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_BASE_FLAGS} -Xclang -plugin-arg-clazy -Xclang ${CLAZY_BASE_CHECKS}") ENDIF (ADD_CLAZY_CHECKS) ENDIF (WITH_CORE) diff --git a/src/gui/editorwidgets/qgshtmlwidgetwrapper.cpp b/src/gui/editorwidgets/qgshtmlwidgetwrapper.cpp index 2e7a931fea8..3a6d7226251 100644 --- a/src/gui/editorwidgets/qgshtmlwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgshtmlwidgetwrapper.cpp @@ -49,12 +49,8 @@ void QgsHtmlWidgetWrapper::initWidget( QWidget *editor ) const int horizontalDpi = qApp->desktop()->screen()->logicalDpiX(); mWidget->setZoomFactor( horizontalDpi / 96.0 ); - auto page = mWidget->page(); - connect( page, &QWebPage::contentsChanged, this, [ = ] - { - auto docHeight { page->mainFrame()->contentsSize().height() }; - mWidget->setFixedHeight( docHeight ); - }, Qt::ConnectionType::UniqueConnection ); + QWebPage *page = mWidget->page(); + connect( page, &QWebPage::contentsChanged, this, &QgsHtmlWidgetWrapper::fixHeight, Qt::ConnectionType::UniqueConnection ); #endif } @@ -95,6 +91,15 @@ void QgsHtmlWidgetWrapper::setHtmlContext( ) mWidget->setHtml( mHtmlCode ); } +#ifdef WITH_QTWEBKIT +void QgsHtmlWidgetWrapper::fixHeight() +{ + QWebPage *page = mWidget->page(); + int docHeight { page->mainFrame()->contentsSize().height() }; + mWidget->setFixedHeight( docHeight ); +} +#endif + void QgsHtmlWidgetWrapper::setFeature( const QgsFeature &feature ) { if ( !mWidget ) diff --git a/src/gui/editorwidgets/qgshtmlwidgetwrapper.h b/src/gui/editorwidgets/qgshtmlwidgetwrapper.h index 18c039afa18..977424debe8 100644 --- a/src/gui/editorwidgets/qgshtmlwidgetwrapper.h +++ b/src/gui/editorwidgets/qgshtmlwidgetwrapper.h @@ -59,6 +59,9 @@ class GUI_EXPORT QgsHtmlWidgetWrapper : public QgsWidgetWrapper private slots: //! sets the html context with the current values void setHtmlContext( ); +#ifdef WITH_QTWEBKIT + void fixHeight(); +#endif private: QString mHtmlCode; diff --git a/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp b/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp index 0947d1eddbf..a3f3f444e5f 100644 --- a/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp @@ -172,13 +172,7 @@ void QgsValueRelationWidgetWrapper::initWidget( QWidget *editor ) } else if ( mLineEdit ) { - connect( mLineEdit, &QLineEdit::textChanged, this, [ = ]( const QString & value ) - { - Q_NOWARN_DEPRECATED_PUSH - emit valueChanged( value ); - Q_NOWARN_DEPRECATED_POP - emit valuesChanged( value ); - }, Qt::UniqueConnection ); + connect( mLineEdit, &QLineEdit::textChanged, this, &QgsValueRelationWidgetWrapper::emitValueChanged, Qt::UniqueConnection ); } } @@ -472,3 +466,11 @@ QList QgsValueRelationWidgetWrapper::layerDependencies() cons } return result; } + +void QgsValueRelationWidgetWrapper::emitValueChanged( const QString &value ) +{ + Q_NOWARN_DEPRECATED_PUSH + emit valueChanged( value ); + Q_NOWARN_DEPRECATED_POP + emit valuesChanged( value ); +} diff --git a/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.h b/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.h index 8e5544d2aaf..ddd4cfe0826 100644 --- a/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.h +++ b/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.h @@ -104,6 +104,9 @@ class GUI_EXPORT QgsValueRelationWidgetWrapper : public QgsEditorWidgetWrapper QList layerDependencies() const override; + private slots: + void emitValueChanged( const QString &value ); + private: void updateValues( const QVariant &value, const QVariantList & = QVariantList() ) override;