minor refactorings
This commit is contained in:
parent
0a70efc7f3
commit
969de1bee4
|
@ -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;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <QskLevelingSensor.h>
|
||||
#include <QskFunctions.h>
|
||||
#include <QskLevelingSensor.h>
|
||||
#include <QskScaleTickmarks.h>
|
||||
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <QVector2D>
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue