From 969de1bee4d5b17c7df8edcfc51b556795d43d4d Mon Sep 17 00:00:00 2001 From: "Vogel, Rick" Date: Tue, 25 Jul 2023 14:56:22 +0200 Subject: [PATCH] minor refactorings --- src/controls/QskLevelingSensor.h | 13 ++--- src/controls/private/QskLevelingSensor.cpp | 65 +++++++++++----------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/controls/QskLevelingSensor.h b/src/controls/QskLevelingSensor.h index 2949c8a3..84b15fc6 100644 --- a/src/controls/QskLevelingSensor.h +++ b/src/controls/QskLevelingSensor.h @@ -23,21 +23,18 @@ class QSK_EXPORT QskLevelingSensor : public QskControl public Q_SLOTS: void setTickmarks( Qt::Axis axis, Tickmarks tickmarks ); void setTickmarksLabels( Qt::Axis axis, TickmarksLabels labels ); - void setAngle( const QVector3D& degree ); - void setAngle( Qt::Axis axis, float degree ); - - void setSubControlRotation( QskAspect::Subcontrol subControl, const QVector3D& degree ); + void setAngle( const QVector3D& degrees ); + void setSubControlRotation( QskAspect::Subcontrol subControl, const QVector3D& degrees ); Q_SIGNALS: void anglesChanged( const QVector3D& degree ); - void subControlRotationChanged( QskAspect::Subcontrol subControl, const QVector3D& degree ); + void subControlRotationChanged( QskAspect::Subcontrol subControl, const QVector3D& degrees ); public: Q_REQUIRED_RESULT const Tickmarks& tickmarks( Qt::Axis axis ) const; Q_REQUIRED_RESULT const TickmarksLabels& tickmarkLabels( Qt::Axis axis ) const; - Q_REQUIRED_RESULT const QVector3D& angle() const noexcept; - Q_REQUIRED_RESULT const QVector3D& subControlRotation( - QskAspect::Subcontrol subControl ) const noexcept; + Q_REQUIRED_RESULT const QVector3D& angle() const; + Q_REQUIRED_RESULT const QVector3D& subControlRotation( QskAspect::Subcontrol subControl ) const; private: class PrivateData; diff --git a/src/controls/private/QskLevelingSensor.cpp b/src/controls/private/QskLevelingSensor.cpp index fd4f7bd9..7788e838 100644 --- a/src/controls/private/QskLevelingSensor.cpp +++ b/src/controls/private/QskLevelingSensor.cpp @@ -1,6 +1,8 @@ -#include #include +#include #include + +#include #include #include @@ -30,6 +32,17 @@ namespace return false; } + template<> + bool compareExchange< double >( double& dst, const double& src ) + { + if ( !qskFuzzyCompare( dst, src ) ) + { + dst = src; + return true; + } + return false; + } + inline bool isAxis( const Qt::Axis axis ) { return axis == Qt::XAxis || axis == Qt::YAxis || axis == Qt::ZAxis; @@ -49,8 +62,6 @@ QSK_SUBCONTROL( QskLevelingSensor, TickmarksZLabels ) if ( !( expr ) ) \ return; -using Q = QskLevelingSensor; - class QskLevelingSensor::PrivateData { public: @@ -82,27 +93,16 @@ void QskLevelingSensor::setTickmarksLabels( const Qt::Axis axis, TickmarksLabels update(); } -void QskLevelingSensor::setAngle( const QVector3D& degree ) +void QskLevelingSensor::setAngle( const QVector3D& degrees ) { - if ( compareExchange( m_data->m_angle, degree ) ) + if ( compareExchange( m_data->m_angle, degrees ) ) { update(); Q_EMIT anglesChanged( m_data->m_angle ); } } -void QskLevelingSensor::setAngle( const Qt::Axis axis, const float degree ) -{ - RETURN_IF_FALSE( isAxis( axis ) ); - - if ( compareExchange( m_data->m_angle[ axis ], degree ) ) - { - update(); - Q_EMIT anglesChanged( m_data->m_angle ); - } -} - -const QskScaleTickmarks& QskLevelingSensor::tickmarks( Qt::Axis axis ) const +const QskScaleTickmarks& QskLevelingSensor::tickmarks( const Qt::Axis axis ) const { if ( isAxis( axis ) ) { @@ -112,7 +112,8 @@ const QskScaleTickmarks& QskLevelingSensor::tickmarks( Qt::Axis axis ) const return invalid; } -const QskLevelingSensor::TickmarksLabels& QskLevelingSensor::tickmarkLabels( Qt::Axis axis ) const +const QskLevelingSensor::TickmarksLabels& QskLevelingSensor::tickmarkLabels( + const Qt::Axis axis ) const { if ( isAxis( axis ) ) { @@ -122,13 +123,13 @@ const QskLevelingSensor::TickmarksLabels& QskLevelingSensor::tickmarkLabels( Qt: return invalid; } -const QVector3D& QskLevelingSensor::angle() const noexcept +const QVector3D& QskLevelingSensor::angle() const { return m_data->m_angle; } const QVector3D& QskLevelingSensor::subControlRotation( - const QskAspect::Subcontrol subControl ) const noexcept + const QskAspect::Subcontrol subControl ) const { static const QVector3D notFound; const auto found = m_data->m_subControlRotation.find( subControl ); @@ -140,35 +141,37 @@ const QVector3D& QskLevelingSensor::subControlRotation( } void QskLevelingSensor::setSubControlRotation( - const QskAspect::Subcontrol subControl, const QVector3D& degree ) + const QskAspect::Subcontrol subControl, const QVector3D& degrees ) { auto updateSubControlRotation = [ this ]( const QskAspect::Subcontrol subControl, - const QVector3D& degree ) { - if ( compareExchange( m_data->m_subControlRotation[ subControl ], degree ) ) + const QVector3D& degrees ) { + if ( compareExchange( m_data->m_subControlRotation[ subControl ], degrees ) ) { - Q_EMIT subControlRotationChanged( subControl, degree ); + Q_EMIT subControlRotationChanged( subControl, degrees ); update(); } }; + using Q = QskLevelingSensor; + if ( subControl == Q::TickmarksX || subControl == Q::TickmarksXLabels ) { - updateSubControlRotation( Q::TickmarksX, degree ); - updateSubControlRotation( Q::TickmarksXLabels, degree ); + updateSubControlRotation( Q::TickmarksX, degrees ); + updateSubControlRotation( Q::TickmarksXLabels, degrees ); } else if ( subControl == Q::TickmarksY || subControl == Q::TickmarksYLabels ) { - updateSubControlRotation( Q::TickmarksY, degree ); - updateSubControlRotation( Q::TickmarksYLabels, degree ); + updateSubControlRotation( Q::TickmarksY, degrees ); + updateSubControlRotation( Q::TickmarksYLabels, degrees ); } else if ( subControl == Q::TickmarksZ || subControl == TickmarksZLabels ) { - updateSubControlRotation( TickmarksZ, degree ); - updateSubControlRotation( TickmarksZLabels, degree ); + updateSubControlRotation( TickmarksZ, degrees ); + updateSubControlRotation( TickmarksZLabels, degrees ); } else { - updateSubControlRotation( subControl, degree ); + updateSubControlRotation( subControl, degrees ); } }