From 6db25ff7bcb01e58715c52790155f63a197e9c55 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Mon, 30 Oct 2017 14:38:30 +0100 Subject: [PATCH] making clazy happier --- examples/automotive/SoundControl.cpp | 6 +++--- examples/colorswitch/Theme.cpp | 4 ++-- qskconfig.pri | 7 ++++--- src/common/QskGlobal.h | 16 ++++++++++++++++ src/common/QskObjectCounter.cpp | 4 ++-- src/controls/QskAnimator.cpp | 12 +++++++----- src/controls/QskControl.cpp | 7 ++++--- src/controls/QskSkinFactory.cpp | 8 ++++---- src/controls/QskSkinTransition.cpp | 6 ++++-- src/controls/QskWindow.cpp | 24 ++++++++++++++++-------- src/controls/QskWindow.h | 4 +++- src/dialogs/QskDialogButtonBox.cpp | 6 +++--- src/graphic/QskGraphic.cpp | 6 ++++-- src/layouts/QskGridBox.cpp | 4 ++-- src/layouts/QskLayoutEngine.h | 12 +++++++++++- src/layouts/QskLayoutItem.h | 10 +++++++++- src/nodes/QskBoxNode.cpp | 12 ++++++------ src/nodes/QskPlainTextRenderer.cpp | 4 +++- 18 files changed, 103 insertions(+), 49 deletions(-) diff --git a/examples/automotive/SoundControl.cpp b/examples/automotive/SoundControl.cpp index d075bd30..c79ffef1 100644 --- a/examples/automotive/SoundControl.cpp +++ b/examples/automotive/SoundControl.cpp @@ -298,10 +298,10 @@ public: // finally connect buttons/slider/labels connect( plusButton, &QskPushButton::pressed, - [ this ]() { increment( 1 ); } ); + this, [ this ]() { increment( 1 ); } ); connect( minusButton, &QskPushButton::pressed, - [ this ]() { increment( -1 ); } ); + this, [ this ]() { increment( -1 ); } ); connect( m_slider, &QskSlider::valueChanged, this, &SliderBox::setValue ); @@ -370,7 +370,7 @@ public: setAlignment( button, Qt::AlignCenter ); connect( button, &QskPushButton::pressed, - [ = ]() { shift( button->offset() ); } ); + this, [ = ]() { shift( button->offset() ); } ); } } diff --git a/examples/colorswitch/Theme.cpp b/examples/colorswitch/Theme.cpp index 695769d4..87616677 100644 --- a/examples/colorswitch/Theme.cpp +++ b/examples/colorswitch/Theme.cpp @@ -52,10 +52,10 @@ Theme::Theme( QObject* parent ): m_accent( qskSetup->skin()->color( QskAspect::Color ) ) { connect( qskSetup, &QskSetup::skinChanged, - [this]( QskSkin* ) { updateColors(); } ); + this, [this]( QskSkin* ) { updateColors(); } ); connect( qskSetup, &QskSetup::skinChanged, - [this]( QskSkin* ) { Q_EMIT skinChanged(); } ); + this, [this]( QskSkin* ) { Q_EMIT skinChanged(); } ); } void Theme::setAccent( QColor color ) diff --git a/qskconfig.pri b/qskconfig.pri index 789f2071..78a0e4d4 100644 --- a/qskconfig.pri +++ b/qskconfig.pri @@ -28,10 +28,11 @@ linux { -isystem $$[QT_INSTALL_HEADERS] \ -isystem $$[QT_INSTALL_HEADERS]/QtCore \ -isystem $$[QT_INSTALL_HEADERS]/QtGui \ - -isystem $$[QT_INSTALL_HEADERS]/QtGui/$$[QT_VERSION]/QtGui/private \ + -isystem $$[QT_INSTALL_HEADERS]/QtGui/$$[QT_VERSION]/QtGui \ -isystem $$[QT_INSTALL_HEADERS]/QtQuick \ - -isystem $$[QT_INSTALL_HEADERS]/QtQuick/$$[QT_VERSION]/QtQuick/private \ - -isystem $$[QT_INSTALL_HEADERS]/QtQml + -isystem $$[QT_INSTALL_HEADERS]/QtQuick/$$[QT_VERSION]/QtQuick \ + -isystem $$[QT_INSTALL_HEADERS]/QtQml \ + -isystem $$[QT_INSTALL_HEADERS]/QtQml/$$[QT_VERSION]/QtQml \ } } diff --git a/src/common/QskGlobal.h b/src/common/QskGlobal.h index de112b9d..46394806 100644 --- a/src/common/QskGlobal.h +++ b/src/common/QskGlobal.h @@ -39,4 +39,20 @@ #define QSK_QT_PRIVATE_END \ QT_WARNING_POP +#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) + +#define qskAsConst qAsConst + +#else + +template struct QskAddConst { typedef const T Type; }; + +template +constexpr typename QskAddConst::Type &qskAsConst( T &t ) noexcept { return t; } + +template +void qskAsConst( const T && ) = delete; + +#endif + #endif diff --git a/src/common/QskObjectCounter.cpp b/src/common/QskObjectCounter.cpp index 3e91eb75..68845e35 100644 --- a/src/common/QskObjectCounter.cpp +++ b/src/common/QskObjectCounter.cpp @@ -50,13 +50,13 @@ public: void addObject( QObject* object ) { - for ( auto counter : m_counterSet ) + for ( auto counter : qskAsConst( m_counterSet ) ) counter->addObject( object ); } void removeObject( QObject* object ) { - for ( auto counter : m_counterSet ) + for ( auto counter : qskAsConst( m_counterSet ) ) counter->removeObject( object ); } diff --git a/src/controls/QskAnimator.cpp b/src/controls/QskAnimator.cpp index 0c7f5fb0..6df6c39d 100644 --- a/src/controls/QskAnimator.cpp +++ b/src/controls/QskAnimator.cpp @@ -61,8 +61,6 @@ namespace int current; int maximum; }; - - static Statistics qskStatistics; } /* @@ -227,13 +225,15 @@ void QskAnimatorDriver::advanceAnimators( QQuickWindow* window ) } Q_GLOBAL_STATIC( QskAnimatorDriver, qskAnimatorDriver ) +Q_GLOBAL_STATIC( Statistics, qskStatistics ) QskAnimator::QskAnimator(): m_window( nullptr ), m_duration( 200 ), m_startTime( -1 ) { - qskStatistics.increment(); + if ( qskStatistics ) + qskStatistics->increment(); } QskAnimator::~QskAnimator() @@ -241,7 +241,8 @@ QskAnimator::~QskAnimator() if ( qskAnimatorDriver ) qskAnimatorDriver->unregisterAnimator( this ); - qskStatistics.decrement(); + if ( qskStatistics ) + qskStatistics->decrement(); } QQuickWindow* QskAnimator::window() const @@ -372,7 +373,8 @@ QMetaObject::Connection QskAnimator::addAdvanceHandler( QObject* receiver, void QskAnimator::debugStatistics( QDebug debug ) { - qskStatistics.debugStatistics( debug ); + if ( qskStatistics ) + qskStatistics->debugStatistics( debug ); } #endif diff --git a/src/controls/QskControl.cpp b/src/controls/QskControl.cpp index 0ed1a031..66cd2fb5 100644 --- a/src/controls/QskControl.cpp +++ b/src/controls/QskControl.cpp @@ -13,6 +13,7 @@ #include #include +#include QSK_QT_PRIVATE_BEGIN #include @@ -99,7 +100,7 @@ namespace }; } -static QskWindowStore qskReleasedWindowCounter; +Q_GLOBAL_STATIC( QskWindowStore, qskReleasedWindowCounter ) class QskControlPrivate : public QQuickItemPrivate { @@ -1045,7 +1046,7 @@ void QskControl::releaseResources() // sequences to be able to provide the correct "oldWindow" // in the WindowChange event. - qskReleasedWindowCounter.setWindow( window() ); + qskReleasedWindowCounter->setWindow( window() ); } const QSGNode* QskControl::itemNode( const QQuickItem* item ) @@ -1125,7 +1126,7 @@ void QskControl::itemChange( QQuickItem::ItemChange change, } QskWindowChangeEvent event( - qskReleasedWindowCounter.window(), value.window ); + qskReleasedWindowCounter->window(), value.window ); QCoreApplication::sendEvent( this, &event ); break; diff --git a/src/controls/QskSkinFactory.cpp b/src/controls/QskSkinFactory.cpp index 3d98793f..124daef9 100644 --- a/src/controls/QskSkinFactory.cpp +++ b/src/controls/QskSkinFactory.cpp @@ -9,9 +9,9 @@ namespace { - static const QString factoryId = "QSkinny"; - static const QString squiekSkinName = "Squiek"; - static const QString materialSkinName = "Material"; + static const char factoryId[] = "qskinny"; + static const char squiekSkinName[] = "Squiek"; + static const char materialSkinName[] = "Material"; class SkinFactory final : public QskSkinFactory { @@ -53,7 +53,7 @@ static FactoryTable& qskGetFactoryTable() if ( qskFactoryTable->isEmpty() ) { static SkinFactory dummySkinFactory ( nullptr ); - qskFactoryTable->insert( factoryId.toLower(), &dummySkinFactory ); + qskFactoryTable->insert( factoryId, &dummySkinFactory ); } return *qskFactoryTable; diff --git a/src/controls/QskSkinTransition.cpp b/src/controls/QskSkinTransition.cpp index 7565689e..4f3c1857 100644 --- a/src/controls/QskSkinTransition.cpp +++ b/src/controls/QskSkinTransition.cpp @@ -202,7 +202,8 @@ namespace addControlAnimators( control, animatorHint, candidates ); } - for ( auto child : item->childItems() ) + const auto children = item->childItems(); + for ( auto child : children ) addAnimators( child, animatorHint, candidates, skin ); } @@ -448,7 +449,8 @@ void QskSkinTransition::process() each object. */ - for ( const auto window : qGuiApp->topLevelWindows() ) + const auto windows = qGuiApp->topLevelWindows(); + for ( const auto window : windows ) { if ( auto quickWindow = qobject_cast< const QQuickWindow* >( window ) ) { diff --git a/src/controls/QskWindow.cpp b/src/controls/QskWindow.cpp index 57e0b1e5..8554a31a 100644 --- a/src/controls/QskWindow.cpp +++ b/src/controls/QskWindow.cpp @@ -126,17 +126,19 @@ QskWindow::~QskWindow() { // When being used from Qml the item destruction would run in the most // unefficient way, leading to lots of QQuickItem::ItemChildRemovedChange - // depending operations. We change this. + // depending operations. So let's remove the toplevel children manually. - QList children; - for ( auto child : contentItem()->childItems() ) + QList items; + + const auto children = contentItem()->childItems(); + for ( auto child : children ) { if ( child->parent() == contentItem() ) - children += child; + items += child; } - for ( auto child : children ) - delete child; + for ( auto item : qskAsConst( items ) ) + delete item; } void QskWindow::resizeF( const QSizeF& size ) @@ -156,7 +158,12 @@ bool QskWindow::deleteOnClose() const void QskWindow::setDeleteOnClose( bool on ) { Q_D( QskWindow ); - d->deleteOnClose = on; + + if ( on != d->deleteOnClose ) + { + d->deleteOnClose = on; + Q_EMIT deleteOnCloseChanged(); + } } void QskWindow::setAutoLayoutChildren( bool on ) @@ -377,7 +384,8 @@ void QskWindow::layoutItems() const QSizeF sz( contentItem()->width(), contentItem()->height() ); - for ( auto child : contentItem()->childItems() ) + const auto children = contentItem()->childItems(); + for ( auto child : children ) { if ( !QskControl::isTransparentForPositioner( child ) ) { diff --git a/src/controls/QskWindow.h b/src/controls/QskWindow.h index 7a697ca5..89429dfd 100644 --- a/src/controls/QskWindow.h +++ b/src/controls/QskWindow.h @@ -16,7 +16,8 @@ class QSK_EXPORT QskWindow : public QQuickWindow { Q_OBJECT - Q_PROPERTY( bool deleteOnClose READ deleteOnClose WRITE setDeleteOnClose FINAL ) + Q_PROPERTY( bool deleteOnClose READ deleteOnClose + WRITE setDeleteOnClose NOTIFY deleteOnCloseChanged FINAL ) Q_PROPERTY( bool autoLayoutChildren READ autoLayoutChildren WRITE setAutoLayoutChildren NOTIFY autoLayoutChildrenChanged FINAL ) @@ -72,6 +73,7 @@ Q_SIGNALS: void localeChanged( const QLocale& ); void framebufferModeChanged( FramebufferMode ); void autoLayoutChildrenChanged(); + void deleteOnCloseChanged(); public Q_SLOTS: void setLocale( const QLocale& ); diff --git a/src/dialogs/QskDialogButtonBox.cpp b/src/dialogs/QskDialogButtonBox.cpp index 7be99c29..8ca78f6a 100644 --- a/src/dialogs/QskDialogButtonBox.cpp +++ b/src/dialogs/QskDialogButtonBox.cpp @@ -92,7 +92,7 @@ void QskDialogButtonBox::setOrientation( Qt::Orientation orientation ) for ( int i = 0; i < QskDialog::NButtonRoles; i++ ) { - for ( QskPushButton* button : m_data->buttonLists[i] ) + for ( QskPushButton* button : qskAsConst( m_data->buttonLists[i] ) ) { // avoid that buttons get deleted // together with the layout @@ -307,7 +307,7 @@ void QskDialogButtonBox::clear() { for ( int i = 0; i < QskDialog::NButtonRoles; i++ ) { - for ( QQuickItem* button : m_data->buttonLists[i] ) + for ( const QQuickItem* button : qskAsConst( m_data->buttonLists[i] ) ) delete button; } @@ -319,7 +319,7 @@ void QskDialogButtonBox::setStandardButtons( { for ( int i = 0; i < QskDialog::NButtonRoles; i++ ) { - for ( QQuickItem* button : m_data->buttonLists[i] ) + for ( const QQuickItem* button : qskAsConst( m_data->buttonLists[i] ) ) delete button; } diff --git a/src/graphic/QskGraphic.cpp b/src/graphic/QskGraphic.cpp index c43254f1..b71be4d2 100644 --- a/src/graphic/QskGraphic.cpp +++ b/src/graphic/QskGraphic.cpp @@ -910,7 +910,8 @@ void QskGraphic::updateState( const QPaintEngineState& state ) } else if ( auto gradient = pen.brush().gradient() ) { - for ( const auto& stop : gradient->stops() ) + const auto stops = gradient->stops(); + for ( const auto& stop : stops ) qskInsertColor( stop.second, m_data->colorTable ); } } @@ -925,7 +926,8 @@ void QskGraphic::updateState( const QPaintEngineState& state ) } else if ( auto gradient = brush.gradient() ) { - for ( const auto& stop : gradient->stops() ) + const auto stops = gradient->stops(); + for ( const auto& stop : stops ) qskInsertColor( stop.second, m_data->colorTable ); } } diff --git a/src/layouts/QskGridBox.cpp b/src/layouts/QskGridBox.cpp index 6a8f58e7..d6603f4c 100644 --- a/src/layouts/QskGridBox.cpp +++ b/src/layouts/QskGridBox.cpp @@ -6,8 +6,8 @@ #include "QskGridBox.h" #include "QskLayoutItem.h" #include "QskLayoutEngine.h" -#include -#include +#include +#include class QskGridBox::PrivateData { diff --git a/src/layouts/QskLayoutEngine.h b/src/layouts/QskLayoutEngine.h index 7e9aa269..218608cf 100644 --- a/src/layouts/QskLayoutEngine.h +++ b/src/layouts/QskLayoutEngine.h @@ -6,7 +6,17 @@ #ifndef QSK_LAYOUT_ENGINE_H #define QSK_LAYOUT_ENGINE_H -#include +#include "QskGlobal.h" + +QSK_QT_PRIVATE_BEGIN +/* + QskLayoutEngine.h should be hidden into some cpp file + as it needs private headers. TODO + */ + +#include +QSK_QT_PRIVATE_END + class QskLayoutItem; class QQuickItem; diff --git a/src/layouts/QskLayoutItem.h b/src/layouts/QskLayoutItem.h index a828f7dd..e828bbea 100644 --- a/src/layouts/QskLayoutItem.h +++ b/src/layouts/QskLayoutItem.h @@ -8,7 +8,15 @@ #include "QskGlobal.h" #include "QskSizePolicy.h" -#include + +QSK_QT_PRIVATE_BEGIN +/* + QskLayoutItem.h should be hidden into some cpp file + as it needs private headers. TODO + */ + +#include +QSK_QT_PRIVATE_END class QQuickItem; diff --git a/src/nodes/QskBoxNode.cpp b/src/nodes/QskBoxNode.cpp index a2d6958e..f083f5ff 100644 --- a/src/nodes/QskBoxNode.cpp +++ b/src/nodes/QskBoxNode.cpp @@ -10,11 +10,11 @@ #include "QskBoxBorderColors.h" #include "QskGradient.h" - #include #include +#include -static QSGVertexColorMaterial qskMaterialVertex; +Q_GLOBAL_STATIC( QSGVertexColorMaterial, qskMaterialVertex ) static inline uint qskMetricsHash( const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& borderMetrics ) @@ -38,13 +38,13 @@ QskBoxNode::QskBoxNode(): m_colorsHash( 0 ), m_geometry( QSGGeometry::defaultAttributes_ColoredPoint2D(), 0 ) { - setMaterial( &qskMaterialVertex ); + setMaterial( qskMaterialVertex ); setGeometry( &m_geometry ); } QskBoxNode::~QskBoxNode() { - if ( material() != &qskMaterialVertex ) + if ( material() != qskMaterialVertex ) delete material(); } @@ -167,7 +167,7 @@ void QskBoxNode::setMonochrome( bool on ) { const auto material = this->material(); - if ( on == ( material != &qskMaterialVertex ) ) + if ( on == ( material != qskMaterialVertex ) ) return; m_geometry.allocate( 0 ); @@ -181,7 +181,7 @@ void QskBoxNode::setMonochrome( bool on ) } else { - setMaterial( &qskMaterialVertex ); + setMaterial( qskMaterialVertex ); delete material; const QSGGeometry g( QSGGeometry::defaultAttributes_ColoredPoint2D(), 0 ); diff --git a/src/nodes/QskPlainTextRenderer.cpp b/src/nodes/QskPlainTextRenderer.cpp index 431e7ea7..a2e124b8 100644 --- a/src/nodes/QskPlainTextRenderer.cpp +++ b/src/nodes/QskPlainTextRenderer.cpp @@ -116,7 +116,9 @@ static void qskRenderText( for ( int i = 0; i < layout->lineCount(); ++i ) { auto line = layout->lineAt( i ); - for ( const auto& glyphRun : line.glyphRuns() ) + + const auto glyphRuns = line.glyphRuns(); + for ( const auto& glyphRun : glyphRuns ) { const bool doCreate = !glyphNode; if ( doCreate )