minor refactorings

This commit is contained in:
Vogel, Rick 2023-07-25 14:56:22 +02:00
parent 0a70efc7f3
commit 969de1bee4
2 changed files with 39 additions and 39 deletions

View File

@ -23,21 +23,18 @@ class QSK_EXPORT QskLevelingSensor : public QskControl
public Q_SLOTS: public Q_SLOTS:
void setTickmarks( Qt::Axis axis, Tickmarks tickmarks ); void setTickmarks( Qt::Axis axis, Tickmarks tickmarks );
void setTickmarksLabels( Qt::Axis axis, TickmarksLabels labels ); void setTickmarksLabels( Qt::Axis axis, TickmarksLabels labels );
void setAngle( const QVector3D& degree ); void setAngle( const QVector3D& degrees );
void setAngle( Qt::Axis axis, float degree ); void setSubControlRotation( QskAspect::Subcontrol subControl, const QVector3D& degrees );
void setSubControlRotation( QskAspect::Subcontrol subControl, const QVector3D& degree );
Q_SIGNALS: Q_SIGNALS:
void anglesChanged( const QVector3D& degree ); void anglesChanged( const QVector3D& degree );
void subControlRotationChanged( QskAspect::Subcontrol subControl, const QVector3D& degree ); void subControlRotationChanged( QskAspect::Subcontrol subControl, const QVector3D& degrees );
public: public:
Q_REQUIRED_RESULT const Tickmarks& tickmarks( Qt::Axis axis ) const; Q_REQUIRED_RESULT const Tickmarks& tickmarks( Qt::Axis axis ) const;
Q_REQUIRED_RESULT const TickmarksLabels& tickmarkLabels( 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& angle() const;
Q_REQUIRED_RESULT const QVector3D& subControlRotation( Q_REQUIRED_RESULT const QVector3D& subControlRotation( QskAspect::Subcontrol subControl ) const;
QskAspect::Subcontrol subControl ) const noexcept;
private: private:
class PrivateData; class PrivateData;

View File

@ -1,6 +1,8 @@
#include <QskLevelingSensor.h>
#include <QskFunctions.h> #include <QskFunctions.h>
#include <QskLevelingSensor.h>
#include <QskScaleTickmarks.h> #include <QskScaleTickmarks.h>
#include <type_traits>
#include <unordered_map> #include <unordered_map>
#include <QVector2D> #include <QVector2D>
@ -30,6 +32,17 @@ namespace
return false; 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 ) inline bool isAxis( const Qt::Axis axis )
{ {
return axis == Qt::XAxis || axis == Qt::YAxis || axis == Qt::ZAxis; return axis == Qt::XAxis || axis == Qt::YAxis || axis == Qt::ZAxis;
@ -49,8 +62,6 @@ QSK_SUBCONTROL( QskLevelingSensor, TickmarksZLabels )
if ( !( expr ) ) \ if ( !( expr ) ) \
return; return;
using Q = QskLevelingSensor;
class QskLevelingSensor::PrivateData class QskLevelingSensor::PrivateData
{ {
public: public:
@ -82,27 +93,16 @@ void QskLevelingSensor::setTickmarksLabels( const Qt::Axis axis, TickmarksLabels
update(); 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(); update();
Q_EMIT anglesChanged( m_data->m_angle ); Q_EMIT anglesChanged( m_data->m_angle );
} }
} }
void QskLevelingSensor::setAngle( const Qt::Axis axis, const float degree ) const QskScaleTickmarks& QskLevelingSensor::tickmarks( const Qt::Axis axis ) const
{
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
{ {
if ( isAxis( axis ) ) if ( isAxis( axis ) )
{ {
@ -112,7 +112,8 @@ const QskScaleTickmarks& QskLevelingSensor::tickmarks( Qt::Axis axis ) const
return invalid; return invalid;
} }
const QskLevelingSensor::TickmarksLabels& QskLevelingSensor::tickmarkLabels( Qt::Axis axis ) const const QskLevelingSensor::TickmarksLabels& QskLevelingSensor::tickmarkLabels(
const Qt::Axis axis ) const
{ {
if ( isAxis( axis ) ) if ( isAxis( axis ) )
{ {
@ -122,13 +123,13 @@ const QskLevelingSensor::TickmarksLabels& QskLevelingSensor::tickmarkLabels( Qt:
return invalid; return invalid;
} }
const QVector3D& QskLevelingSensor::angle() const noexcept const QVector3D& QskLevelingSensor::angle() const
{ {
return m_data->m_angle; return m_data->m_angle;
} }
const QVector3D& QskLevelingSensor::subControlRotation( const QVector3D& QskLevelingSensor::subControlRotation(
const QskAspect::Subcontrol subControl ) const noexcept const QskAspect::Subcontrol subControl ) const
{ {
static const QVector3D notFound; static const QVector3D notFound;
const auto found = m_data->m_subControlRotation.find( subControl ); const auto found = m_data->m_subControlRotation.find( subControl );
@ -140,35 +141,37 @@ const QVector3D& QskLevelingSensor::subControlRotation(
} }
void QskLevelingSensor::setSubControlRotation( void QskLevelingSensor::setSubControlRotation(
const QskAspect::Subcontrol subControl, const QVector3D& degree ) const QskAspect::Subcontrol subControl, const QVector3D& degrees )
{ {
auto updateSubControlRotation = [ this ]( const QskAspect::Subcontrol subControl, auto updateSubControlRotation = [ this ]( const QskAspect::Subcontrol subControl,
const QVector3D& degree ) { const QVector3D& degrees ) {
if ( compareExchange( m_data->m_subControlRotation[ subControl ], degree ) ) if ( compareExchange( m_data->m_subControlRotation[ subControl ], degrees ) )
{ {
Q_EMIT subControlRotationChanged( subControl, degree ); Q_EMIT subControlRotationChanged( subControl, degrees );
update(); update();
} }
}; };
using Q = QskLevelingSensor;
if ( subControl == Q::TickmarksX || subControl == Q::TickmarksXLabels ) if ( subControl == Q::TickmarksX || subControl == Q::TickmarksXLabels )
{ {
updateSubControlRotation( Q::TickmarksX, degree ); updateSubControlRotation( Q::TickmarksX, degrees );
updateSubControlRotation( Q::TickmarksXLabels, degree ); updateSubControlRotation( Q::TickmarksXLabels, degrees );
} }
else if ( subControl == Q::TickmarksY || subControl == Q::TickmarksYLabels ) else if ( subControl == Q::TickmarksY || subControl == Q::TickmarksYLabels )
{ {
updateSubControlRotation( Q::TickmarksY, degree ); updateSubControlRotation( Q::TickmarksY, degrees );
updateSubControlRotation( Q::TickmarksYLabels, degree ); updateSubControlRotation( Q::TickmarksYLabels, degrees );
} }
else if ( subControl == Q::TickmarksZ || subControl == TickmarksZLabels ) else if ( subControl == Q::TickmarksZ || subControl == TickmarksZLabels )
{ {
updateSubControlRotation( TickmarksZ, degree ); updateSubControlRotation( TickmarksZ, degrees );
updateSubControlRotation( TickmarksZLabels, degree ); updateSubControlRotation( TickmarksZLabels, degrees );
} }
else else
{ {
updateSubControlRotation( subControl, degree ); updateSubControlRotation( subControl, degrees );
} }
} }