simplyfy setter
This commit is contained in:
parent
a7f874c665
commit
4ed5f7e431
|
@ -131,35 +131,10 @@ QVector3D QskLevelingSensor::subControlRotation( const QskAspect::Subcontrol sub
|
||||||
void QskLevelingSensor::setSubControlRotation(
|
void QskLevelingSensor::setSubControlRotation(
|
||||||
const QskAspect::Subcontrol subControl, const QVector3D& degrees )
|
const QskAspect::Subcontrol subControl, const QVector3D& degrees )
|
||||||
{
|
{
|
||||||
auto updateSubControlRotation = [ this ]( const QskAspect::Subcontrol subControl,
|
|
||||||
const QVector3D& degrees ) {
|
|
||||||
if ( compareExchange( m_data->m_subControlRotation[ subControl ], degrees ) )
|
if ( compareExchange( m_data->m_subControlRotation[ subControl ], degrees ) )
|
||||||
{
|
{
|
||||||
Q_EMIT subControlRotationChanged( subControl, degrees );
|
|
||||||
update();
|
update();
|
||||||
}
|
Q_EMIT subControlRotationChanged( subControl, degrees );
|
||||||
};
|
|
||||||
|
|
||||||
using Q = QskLevelingSensor;
|
|
||||||
|
|
||||||
if ( subControl == Q::TickmarksX || subControl == Q::TickmarksXLabels )
|
|
||||||
{
|
|
||||||
updateSubControlRotation( Q::TickmarksX, degrees );
|
|
||||||
updateSubControlRotation( Q::TickmarksXLabels, degrees );
|
|
||||||
}
|
|
||||||
else if ( subControl == Q::TickmarksY || subControl == Q::TickmarksYLabels )
|
|
||||||
{
|
|
||||||
updateSubControlRotation( Q::TickmarksY, degrees );
|
|
||||||
updateSubControlRotation( Q::TickmarksYLabels, degrees );
|
|
||||||
}
|
|
||||||
else if ( subControl == Q::TickmarksZ || subControl == TickmarksZLabels )
|
|
||||||
{
|
|
||||||
updateSubControlRotation( TickmarksZ, degrees );
|
|
||||||
updateSubControlRotation( TickmarksZLabels, degrees );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
updateSubControlRotation( subControl, degrees );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,96 +103,6 @@ class RadialTickmarksNode final : public QSGGeometryNode
|
||||||
QskHashValue m_tickmarksHash{ 0 };
|
QskHashValue m_tickmarksHash{ 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
class LinearTickmarksNode final : public QSGGeometryNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LinearTickmarksNode()
|
|
||||||
: m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
|
|
||||||
{
|
|
||||||
m_geometry.setDrawingMode( QSGGeometry::DrawLines );
|
|
||||||
m_geometry.setVertexDataPattern( QSGGeometry::StaticPattern );
|
|
||||||
|
|
||||||
setGeometry( &m_geometry );
|
|
||||||
setMaterial( &m_material );
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMaterialProperties( const QColor& color )
|
|
||||||
{
|
|
||||||
auto dirty = false;
|
|
||||||
|
|
||||||
if ( dirty |= ( m_material.color() != color ) )
|
|
||||||
{
|
|
||||||
m_material.setColor( color );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( dirty )
|
|
||||||
{
|
|
||||||
markDirty( QSGNode::DirtyMaterial );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setGeometryProperties( const QskScaleTickmarks& tickmarks, const QVector3D& tickmarkSize,
|
|
||||||
const QVector2D& scale = { 1.0, 0.0f }, const QVector2D& offset = {},
|
|
||||||
const float lineWidth = 1.0f, const bool forceDirty = false )
|
|
||||||
{
|
|
||||||
auto dirty = forceDirty;
|
|
||||||
|
|
||||||
if ( dirty |= !qFuzzyCompare( m_geometry.lineWidth(), lineWidth ) )
|
|
||||||
{
|
|
||||||
m_geometry.setLineWidth( lineWidth );
|
|
||||||
}
|
|
||||||
|
|
||||||
dirty |= m_geometry.vertexCount() != tickmarks.tickCount() * 2;
|
|
||||||
dirty |= compareExchange( m_tickmarkSize, tickmarkSize );
|
|
||||||
dirty |= compareExchange( m_scale, scale );
|
|
||||||
dirty |= compareExchange( m_offset, offset );
|
|
||||||
|
|
||||||
if ( dirty )
|
|
||||||
{
|
|
||||||
update( tickmarks );
|
|
||||||
markDirty( QSGNode::DirtyGeometry );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void update( const QskScaleTickmarks& tickmarks )
|
|
||||||
{
|
|
||||||
if ( m_geometry.vertexCount() != tickmarks.tickCount() * 2 )
|
|
||||||
{
|
|
||||||
m_geometry.allocate( tickmarks.tickCount() * 2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* vertexData = m_geometry.vertexDataAsPoint2D();
|
|
||||||
|
|
||||||
using T = QskScaleTickmarks::TickType;
|
|
||||||
for ( auto type : { T::MinorTick, T::MediumTick, T::MajorTick } )
|
|
||||||
{
|
|
||||||
for ( const auto tick : tickmarks.ticks( type ) )
|
|
||||||
{
|
|
||||||
const auto i = static_cast< int >( type );
|
|
||||||
|
|
||||||
const auto p = m_scale * tick;
|
|
||||||
const auto d = QVector2D( -m_scale.y(), m_scale.x() ).normalized();
|
|
||||||
|
|
||||||
const auto p1 = m_tickmarkSize[ i ] * +1 * d + p + m_offset;
|
|
||||||
const auto p2 = m_tickmarkSize[ i ] * -1 * d + p + m_offset;
|
|
||||||
|
|
||||||
vertexData[ 0 ].set( p1.x(), p1.y() );
|
|
||||||
vertexData[ 1 ].set( p2.x(), p2.y() );
|
|
||||||
vertexData += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_geometry.markVertexDataDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
QSGGeometry m_geometry;
|
|
||||||
QSGFlatColorMaterial m_material;
|
|
||||||
QVector2D m_scale = { 1.0f, 0.0f };
|
|
||||||
QVector2D m_offset = { 0.0f, 0.0f };
|
|
||||||
QVector3D m_tickmarkSize = { 1.0, 2.0, 4.0 };
|
|
||||||
};
|
|
||||||
|
|
||||||
class RadialClipNode final : public QSGClipNode
|
class RadialClipNode final : public QSGClipNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue