clang-format

This commit is contained in:
Vogel, Rick 2023-07-25 15:08:00 +02:00
parent f3727a79e1
commit 7a74014257
7 changed files with 218 additions and 215 deletions

View File

@ -31,11 +31,11 @@ namespace
void style( QskSkinHintTableEditor& editor );
template< typename Skinnable, typename Skinlet >
void declareSkinlet( )
void declareSkinlet()
{
QskSkin::declareSkinlet< Skinnable, Skinlet >();
}
template< typename Skinnable, typename Skinlet >
void declareSkinlet( QskSkinHintTableEditor& editor )
{
@ -122,7 +122,7 @@ namespace
editor.setColor( Q::TickmarksX, Qt::black );
editor.setStrutSize( Q::TickmarksX, { r1, 0.2 } ); // w %, h %
editor.setHint( Q::TickmarksX, QVector3D{ 0.50, 0.75, 1.0 } ); // %
editor.setAlignment(Q::TickmarksX, Qt::AlignCenter);
editor.setAlignment( Q::TickmarksX, Qt::AlignCenter );
editor.setStrutSize( Q::TickmarksXLabels, { r1, 0.15 } ); // w %, h %
editor.setAlignment( Q::TickmarksXLabels, Qt::AlignTop | Qt::AlignHCenter );
@ -130,7 +130,7 @@ namespace
editor.setColor( Q::TickmarksY, Qt::black );
editor.setStrutSize( Q::TickmarksY, { 0.1, r1 } ); // w %, h %
editor.setHint( Q::TickmarksY, QVector3D{ 0.50, 0.75, 1.00 } ); // %
editor.setAlignment(Q::TickmarksY, Qt::AlignCenter);
editor.setAlignment( Q::TickmarksY, Qt::AlignCenter );
editor.setStrutSize( Q::TickmarksYLabels, { 0.15, r1 } ); // w %, h %
editor.setAlignment( Q::TickmarksYLabels, Qt::AlignCenter );

View File

@ -11,12 +11,12 @@
#include <QskSkinManager.h>
#include <QskWindow.h>
#include <QskLevelingSensor.h>
#include <QskIntervalF.h>
#include <QskLevelingSensor.h>
#include <QskLinearBox.h>
#include <QskScaleTickmarks.h>
#include <QskSlider.h>
#include <QskTextLabel.h>
#include <QskScaleTickmarks.h>
#include <QGuiApplication>
#include <QQuickWindow>

View File

@ -1,7 +1,7 @@
#pragma once
#include <QskSkinlet.h>
#include <QSGNode>
#include <QskSkinlet.h>
class QskLevelingSensor;
@ -9,9 +9,9 @@ class QSK_EXPORT QskLevelingSensorSkinlet : public QskSkinlet
{
Q_GADGET
using Inherited = QskSkinlet;
using Inherited = QskSkinlet;
public:
public:
enum NodeRole
{
OuterDisk,
@ -28,26 +28,25 @@ public:
RoleCount
};
Q_INVOKABLE QskLevelingSensorSkinlet(QskSkin* skin = nullptr);
Q_INVOKABLE QskLevelingSensorSkinlet( QskSkin* skin = nullptr );
~QskLevelingSensorSkinlet() override = default;
static Q_REQUIRED_RESULT float outerRadius(const QskSkinnable* const skinnable);
static Q_REQUIRED_RESULT float innerRadius(const QskSkinnable* const skinnable);
static Q_REQUIRED_RESULT QPointF center(const QskSkinnable* const skinnable);
static Q_REQUIRED_RESULT float outerRadius( const QskSkinnable* const skinnable );
static Q_REQUIRED_RESULT float innerRadius( const QskSkinnable* const skinnable );
static Q_REQUIRED_RESULT QPointF center( const QskSkinnable* const skinnable );
protected:
protected:
Q_REQUIRED_RESULT QRectF subControlRect( const QskSkinnable* skinnable,
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const override;
Q_REQUIRED_RESULT QRectF subControlRect(const QskSkinnable* skinnable,
const QRectF& contentsRect, QskAspect::Subcontrol subControl) const override;
Q_REQUIRED_RESULT QSGNode* updateSubNode(
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const override;
Q_REQUIRED_RESULT QSGNode* updateSubNode(const QskSkinnable* skinnable,
quint8 nodeRole, QSGNode* node) const override;
template< NodeRole >
Q_REQUIRED_RESULT QRectF subControlRect(
const QskLevelingSensor* sensor, const QRectF& contentsRect ) const;
template<NodeRole>
Q_REQUIRED_RESULT QRectF subControlRect(const QskLevelingSensor* sensor,
const QRectF& contentsRect) const;
template<NodeRole>
Q_REQUIRED_RESULT QSGNode* updateSubNode(const QskLevelingSensor* sensor,
quint8 nodeRole, QSGNode* node) const;
template< NodeRole >
Q_REQUIRED_RESULT QSGNode* updateSubNode(
const QskLevelingSensor* sensor, quint8 nodeRole, QSGNode* node ) const;
};

View File

@ -2,83 +2,85 @@
#include "QskLevelingSensorUtility.h"
#include <QSGFlatColorMaterial>
#include <QSGGeometry>
#include <QSGGeometryNode>
#include <QSGFlatColorMaterial>
#include <QFontMetricsF>
#include <qmath.h>
class RadialTickmarksNode final : public QSGGeometryNode
{
public:
RadialTickmarksNode() : m_geometry(QSGGeometry::defaultAttributes_Point2D(), 0)
public:
RadialTickmarksNode()
: m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
{
m_geometry.setDrawingMode(QSGGeometry::DrawLines);
m_geometry.setVertexDataPattern(QSGGeometry::StaticPattern);
m_geometry.setDrawingMode( QSGGeometry::DrawLines );
m_geometry.setVertexDataPattern( QSGGeometry::StaticPattern );
setGeometry(&m_geometry);
setMaterial(&m_material);
setGeometry( &m_geometry );
setMaterial( &m_material );
}
void setMaterialProperties(const QColor& color)
void setMaterialProperties( const QColor& color )
{
if (m_material.color() != color)
if ( m_material.color() != color )
{
m_material.setColor(color);
markDirty(QSGNode::DirtyMaterial);
m_material.setColor( color );
markDirty( QSGNode::DirtyMaterial );
}
}
void setGeometryProperties(const QskScaleTickmarks& tickmarks, const qreal r1 = 0.0, const QVector3D& r2 = { 0.5, 0.75, 1.0 }, float lineWidth = 1.0)
void setGeometryProperties( const QskScaleTickmarks& tickmarks, const qreal r1 = 0.0,
const QVector3D& r2 = { 0.5, 0.75, 1.0 }, float lineWidth = 1.0 )
{
auto dirty = false;
if (dirty |= (m_geometry.lineWidth() != lineWidth))
if ( dirty |= ( m_geometry.lineWidth() != lineWidth ) )
{
m_geometry.setLineWidth(lineWidth);
m_geometry.setLineWidth( lineWidth );
}
dirty |= compareExchange(m_r1, r1);
dirty |= compareExchange(m_r2, r2);
dirty |= compareExchange(m_tickmarksHash, tickmarks.hash());
dirty |= compareExchange( m_r1, r1 );
dirty |= compareExchange( m_r2, r2 );
dirty |= compareExchange( m_tickmarksHash, tickmarks.hash() );
if (dirty)
if ( dirty )
{
update(tickmarks);
update( tickmarks );
}
}
private:
void update(const QskScaleTickmarks& tickmarks)
private:
void update( const QskScaleTickmarks& tickmarks )
{
if (m_geometry.vertexCount() != tickmarks.tickCount())
if ( m_geometry.vertexCount() != tickmarks.tickCount() )
{
m_geometry.allocate(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 ( auto type : { T::MinorTick, T::MediumTick, T::MajorTick } )
{
for (const auto tick : tickmarks.ticks(type))
for ( const auto tick : tickmarks.ticks( type ) )
{
const auto i = static_cast<int>(type);
const auto angleRad = qDegreesToRadians(tick);
const auto x1 = qFastCos(angleRad) * m_r1;
const auto y1 = qFastSin(angleRad) * m_r1;
const auto x2 = qFastCos(angleRad) * m_r2[i];
const auto y2 = qFastSin(angleRad) * m_r2[i];
const auto i = static_cast< int >( type );
const auto angleRad = qDegreesToRadians( tick );
const auto x1 = qFastCos( angleRad ) * m_r1;
const auto y1 = qFastSin( angleRad ) * m_r1;
const auto x2 = qFastCos( angleRad ) * m_r2[ i ];
const auto y2 = qFastSin( angleRad ) * m_r2[ i ];
vertexData[0].set(x1, y1);
vertexData[1].set(x2, y2);
vertexData[ 0 ].set( x1, y1 );
vertexData[ 1 ].set( x2, y2 );
vertexData += 2;
}
}
m_geometry.markVertexDataDirty();
markDirty(QSGNode::DirtyGeometry);
markDirty( QSGNode::DirtyGeometry );
}
QSGGeometry m_geometry;
@ -90,77 +92,80 @@ private:
class LinearTickmarksNode final : public QSGGeometryNode
{
public:
LinearTickmarksNode() : m_geometry(QSGGeometry::defaultAttributes_Point2D(), 0)
public:
LinearTickmarksNode()
: m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
{
m_geometry.setDrawingMode(QSGGeometry::DrawLines);
m_geometry.setVertexDataPattern(QSGGeometry::StaticPattern);
m_geometry.setDrawingMode( QSGGeometry::DrawLines );
m_geometry.setVertexDataPattern( QSGGeometry::StaticPattern );
setGeometry(&m_geometry);
setMaterial(&m_material);
setGeometry( &m_geometry );
setMaterial( &m_material );
}
void setMaterialProperties(const QColor& color)
void setMaterialProperties( const QColor& color )
{
auto dirty = false;
if (dirty |= (m_material.color() != color))
if ( dirty |= ( m_material.color() != color ) )
{
m_material.setColor(color);
m_material.setColor( color );
}
if (dirty)
if ( dirty )
{
markDirty(QSGNode::DirtyMaterial);
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)
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))
if ( dirty |= !qFuzzyCompare( m_geometry.lineWidth(), lineWidth ) )
{
m_geometry.setLineWidth(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);
dirty |= compareExchange( m_tickmarkSize, tickmarkSize );
dirty |= compareExchange( m_scale, scale );
dirty |= compareExchange( m_offset, offset );
if (dirty)
if ( dirty )
{
update(tickmarks);
markDirty(QSGNode::DirtyGeometry);
update( tickmarks );
markDirty( QSGNode::DirtyGeometry );
}
}
private:
void update(const QskScaleTickmarks& tickmarks)
private:
void update( const QskScaleTickmarks& tickmarks )
{
if (m_geometry.vertexCount() != tickmarks.tickCount() * 2)
if ( m_geometry.vertexCount() != tickmarks.tickCount() * 2 )
{
m_geometry.allocate(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 ( auto type : { T::MinorTick, T::MediumTick, T::MajorTick } )
{
for (const auto tick : tickmarks.ticks(type))
for ( const auto tick : tickmarks.ticks( type ) )
{
const auto i = static_cast<int>(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 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;
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[ 0 ].set( p1.x(), p1.y() );
vertexData[ 1 ].set( p2.x(), p2.y() );
vertexData += 2;
}
}
@ -177,53 +182,55 @@ private:
class RadialClipNode final : public QSGClipNode
{
public:
RadialClipNode() : m_geometry(QSGGeometry::defaultAttributes_Point2D(), 0)
public:
RadialClipNode()
: m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
{
m_geometry.setVertexDataPattern(QSGGeometry::DynamicPattern);
m_geometry.setDrawingMode(QSGGeometry::DrawTriangleFan);
setGeometry(&m_geometry);
setIsRectangular(false);
m_geometry.setVertexDataPattern( QSGGeometry::DynamicPattern );
m_geometry.setDrawingMode( QSGGeometry::DrawTriangleFan );
setGeometry( &m_geometry );
setIsRectangular( false );
}
void setGeometryProperties(const qreal radius = 1.0, const qreal cx = 0.0, const qreal cy = 0.0, const int count = 360)
void setGeometryProperties( const qreal radius = 1.0, const qreal cx = 0.0,
const qreal cy = 0.0, const int count = 360 )
{
auto dirty = false;
dirty |= compareExchange(m_radius, radius);
dirty |= compareExchange(m_cx, cx);
dirty |= compareExchange(m_cy, cy);
dirty |= compareExchange(m_count, count);
dirty |= compareExchange( m_radius, radius );
dirty |= compareExchange( m_cx, cx );
dirty |= compareExchange( m_cy, cy );
dirty |= compareExchange( m_count, count );
if (dirty)
if ( dirty )
{
update();
}
}
private:
private:
void update()
{
const auto step = 2.0 * M_PI / m_count;
if (m_geometry.vertexCount() != m_count)
if ( m_geometry.vertexCount() != m_count )
{
m_geometry.allocate(m_count);
m_geometry.allocate( m_count );
}
auto* vertices = m_geometry.vertexDataAsPoint2D();
for (int i = 0; i < m_count; ++i)
for ( int i = 0; i < m_count; ++i )
{
vertices[i].x = qFastCos(i * step) * m_radius + m_cx;
vertices[i].y = qFastSin(i * step) * m_radius + m_cy;
vertices[ i ].x = qFastCos( i * step ) * m_radius + m_cx;
vertices[ i ].y = qFastSin( i * step ) * m_radius + m_cy;
}
m_geometry.markVertexDataDirty();
markDirty(QSGNode::DirtyGeometry);
markDirty( QSGNode::DirtyGeometry );
}
using QSGClipNode::setIsRectangular;
using QSGClipNode::setClipRect;
using QSGClipNode::setIsRectangular;
QSGGeometry m_geometry;
qreal m_radius = 1.0;
@ -232,72 +239,75 @@ private:
int m_count = 360;
};
template<typename CRTP>
template< typename CRTP >
struct TickmarksLabelsNode : public QSGNode
{
public:
QVector2D value(const QVector2D& v, const QVector2D& s, const QVector2D& o) const
public:
QVector2D value( const QVector2D& v, const QVector2D& s, const QVector2D& o ) const
{
return static_cast<const CRTP*>(this)->value(v, s, o);
return static_cast< const CRTP* >( this )->value( v, s, o );
}
void update(const QskSkinnable* const skinnable, const QskAspect::Subcontrol subControl, const QVector<QPair<double, QString>>& labels, const QVector2D& scale = { 1.0, 0.0 }, const QVector2D& offset = {})
void update( const QskSkinnable* const skinnable, const QskAspect::Subcontrol subControl,
const QVector< QPair< double, QString > >& labels, const QVector2D& scale = { 1.0, 0.0 },
const QVector2D& offset = {} )
{
const auto count = labels.count();
for ( int i = childCount(); i > count; --i )
for ( int i = childCount(); i > count; --i )
{
removeChildNode(lastChild());
removeChildNode( lastChild() );
}
for ( int i = childCount(); i < count; ++i )
for ( int i = childCount(); i < count; ++i )
{
appendChildNode(new QskTextNode);
}
appendChildNode( new QskTextNode );
}
const QFontMetricsF metrics(skinnable->effectiveFont(subControl));
const auto h = skinnable->effectiveFontHeight(subControl);
const auto a = skinnable->alignmentHint(subControl);
const QFontMetricsF metrics( skinnable->effectiveFont( subControl ) );
const auto h = skinnable->effectiveFontHeight( subControl );
const auto a = skinnable->alignmentHint( subControl );
auto* textNode = static_cast<QskTextNode*>(firstChild());
for (const auto& label : qAsConst(labels))
auto* textNode = static_cast< QskTextNode* >( firstChild() );
for ( const auto& label : qAsConst( labels ) )
{
const auto v = value({ (float)label.first, (float)label.first }, scale, offset);
const auto v = value( { ( float ) label.first, ( float ) label.first }, scale, offset );
auto x = v.x();
auto y = v.y();
const auto w = metrics.horizontalAdvance(label.second);
const auto w = metrics.horizontalAdvance( label.second );
x -= a.testFlag(Qt::AlignRight) ? w : 0;
x -= a.testFlag(Qt::AlignHCenter) ? w / 2 : 0;
x -= a.testFlag( Qt::AlignRight ) ? w : 0;
x -= a.testFlag( Qt::AlignHCenter ) ? w / 2 : 0;
y -= a.testFlag(Qt::AlignBottom) ? h : 0;
y -= a.testFlag(Qt::AlignVCenter) ? h / 2 : 0;
y -= a.testFlag( Qt::AlignBottom ) ? h : 0;
y -= a.testFlag( Qt::AlignVCenter ) ? h / 2 : 0;
QskSkinlet::updateTextNode(skinnable, textNode, { x,y,w,h }, a, label.second, subControl);
QskSkinlet::updateTextNode(
skinnable, textNode, { x, y, w, h }, a, label.second, subControl );
textNode = static_cast<QskTextNode*>(textNode->nextSibling());
textNode = static_cast< QskTextNode* >( textNode->nextSibling() );
}
}
};
struct LinearTickmarksLabelsNode final : public TickmarksLabelsNode<LinearTickmarksLabelsNode>
struct LinearTickmarksLabelsNode final : public TickmarksLabelsNode< LinearTickmarksLabelsNode >
{
public:
QVector2D value(const QVector2D& v, const QVector2D& s, const QVector2D& o) const
public:
QVector2D value( const QVector2D& v, const QVector2D& s, const QVector2D& o ) const
{
return v * s + o;
}
};
struct RadialTickmarksLabelsNode final : public TickmarksLabelsNode<RadialTickmarksLabelsNode>
struct RadialTickmarksLabelsNode final : public TickmarksLabelsNode< RadialTickmarksLabelsNode >
{
public:
QVector2D value(const QVector2D& v, const QVector2D& s, const QVector2D& o) const
public:
QVector2D value( const QVector2D& v, const QVector2D& s, const QVector2D& o ) const
{
return QVector2D{
(float)qFastCos(qDegreesToRadians(v.x())),
(float)qFastSin(qDegreesToRadians(v.y()))
} *s + o;
( float ) qFastCos( qDegreesToRadians( v.x() ) ),
( float ) qFastSin( qDegreesToRadians( v.y() ) )
} * s + o;
}
};

View File

@ -1,8 +1,8 @@
#include <QskLevelingSensorSkinlet.h>
#include <QskLevelingSensor.h>
#include "QskLevelingSensorUtility.h"
#include "QskLevelingSensorNodes.h"
#include "QskLevelingSensorUtility.h"
#include "QskSGNodeUtility.h"
#include <QskLevelingSensor.h>
#include <QskLevelingSensorSkinlet.h>
#include <QskArcMetrics.h>
#include <QskBoxBorderColors.h>
@ -51,9 +51,9 @@ namespace
{
}
Q_REQUIRED_RESULT QVector3D scale() const noexcept
Q_REQUIRED_RESULT QVector3D scale() const noexcept
{
return {(float)sX, (float)sY, (float)sZ};
return { ( float ) sX, ( float ) sY, ( float ) sZ };
}
};
@ -78,9 +78,9 @@ namespace
{
}
Q_REQUIRED_RESULT QVector3D translation() const noexcept
Q_REQUIRED_RESULT QVector3D translation() const noexcept
{
return {(float)tX, (float)tY, (float)tZ};
return { ( float ) tX, ( float ) tY, ( float ) tZ };
}
Q_REQUIRED_RESULT QMatrix4x4 matrix() const noexcept
@ -99,7 +99,7 @@ using namespace QskSGNode;
template< typename Root, typename... Children >
inline Q_REQUIRED_RESULT Root* ensureNodes( QSGNode* root = nullptr )
{
return ensureNodes<AppendMode::Recursive, Root, Children...>(root);
return ensureNodes< AppendMode::Recursive, Root, Children... >( root );
}
float QskLevelingSensorSkinlet::outerRadius( const QskSkinnable* const skinnable )
@ -189,7 +189,7 @@ template<>
QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::OuterDisk >(
const QskLevelingSensor* const sensor, const quint8 nodeRole, QSGNode* const node ) const
{
const auto subControl = Q::OuterDisk;
const auto subControl = Q::OuterDisk;
const auto contentsRect = sensor->contentsRect();
const auto boxRect = subControlRect< OuterDisk >( sensor, contentsRect );
const auto boxShapeMetrics = QskBoxShapeMetrics{ boxRect.width() / 2 };
@ -197,7 +197,7 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::OuterDisk >(
const auto boxBorderColors = sensor->boxBorderColorsHint( subControl );
const auto boxGradient = sensor->gradientHint( subControl );
auto* const root = ensureNodes<QSGTransformNode, QskBoxNode >( node );
auto* const root = ensureNodes< QSGTransformNode, QskBoxNode >( node );
auto* const bNode = static_cast< QskBoxNode* >( root->firstChild() );
const auto size = outerRadius( sensor ) * sensor->strutSizeHint( Q::OuterDisk ).width();
@ -221,8 +221,8 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::Horizon >(
const QskLevelingSensor* const sensor, const quint8 nodeRole, QSGNode* const node ) const
{
const auto subControl = Q::Horizon;
const State<QskAspect::Subcontrol> state(sensor, subControl);
const State< QskAspect::Subcontrol > state( sensor, subControl );
const auto dY = 2 * sensor->angle().y();
const auto pY = qBound( 0.0, 0.5 + ( -state.rX / dY ), 1.0 );
@ -238,7 +238,8 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::Horizon >(
auto* const tNode = ensureNodes< QSGTransformNode, QskBoxNode >( node );
auto* const boxNode = static_cast< QskBoxNode* >( tNode->firstChild() );
updateBoxNode( sensor, boxNode, { 0, 0, 2 * state.r1, 2 * state.r1 }, shape, metrics, colors, gradient );
updateBoxNode(
sensor, boxNode, { 0, 0, 2 * state.r1, 2 * state.r1 }, shape, metrics, colors, gradient );
const auto matrix = matrix_deg( 0, 0, 0, state.cX, state.cY, 0 ) *
matrix_deg( 0, 0, 0, -state.r1, -state.r1, 0 );
@ -252,14 +253,13 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksX >(
const QskLevelingSensor* const sensor, const quint8 nodeRole, QSGNode* const node ) const
{
const auto subControl = Q::TickmarksX;
State<QskAspect::Subcontrol> state(sensor, subControl);
State< QskAspect::Subcontrol > state( sensor, subControl );
const auto color = sensor->color( subControl );
const auto scale = sensor->strutSizeHint( subControl );
const auto r3 = state.r1 * scale.height();
auto* const clipping =
ensureNodes< RadialClipNode, QSGTransformNode, LinearTickmarksNode >(
node );
ensureNodes< RadialClipNode, QSGTransformNode, LinearTickmarksNode >( node );
auto* const transform = static_cast< QSGTransformNode* >( clipping->firstChild() );
auto* const tickmarks = static_cast< LinearTickmarksNode* >( transform->firstChild() );
@ -291,8 +291,7 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksY >(
const auto rotation = sensor->subControlRotation( subControl );
auto* const cNode =
ensureNodes< RadialClipNode,QSGTransformNode, LinearTickmarksNode>(
node );
ensureNodes< RadialClipNode, QSGTransformNode, LinearTickmarksNode >( node );
auto* const tNode = static_cast< QSGTransformNode* >( cNode->firstChild() );
auto* const lNode = static_cast< LinearTickmarksNode* >( tNode->firstChild() );
@ -318,9 +317,9 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksZ >(
const auto color = sensor->color( subControl );
const auto scale = sensor->strutSizeHint( subControl );
const auto r3 =
qvariant_cast< QVector3D >( sensor->effectiveSkinHint( subControl ) ) * ( state.r2 - state.r1 ) +
QVector3D{ (float)state.r1, (float)state.r1, (float)state.r1 };
const auto r3 = qvariant_cast< QVector3D >( sensor->effectiveSkinHint( subControl ) ) *
( state.r2 - state.r1 ) +
QVector3D{ ( float ) state.r1, ( float ) state.r1, ( float ) state.r1 };
auto* const transform = ensureNodes< QSGTransformNode, RadialTickmarksNode >( node );
auto* const tickmarksNode = static_cast< RadialTickmarksNode* >( transform->firstChild() );
@ -338,8 +337,9 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksXLabels >(
{
const auto subControl = Q::TickmarksXLabels;
const State< QskAspect::Subcontrol > state( sensor, subControl );
const auto r3 = static_cast< float >( state.r1 * sensor->strutSizeHint( Q::TickmarksX ).height() );
const auto translation = state.translation().toVector2D() + QVector2D{0, r3};
const auto r3 =
static_cast< float >( state.r1 * sensor->strutSizeHint( Q::TickmarksX ).height() );
const auto translation = state.translation().toVector2D() + QVector2D{ 0, r3 };
auto* const cNode =
ensureNodes< RadialClipNode, QSGTransformNode, LinearTickmarksLabelsNode >( node );
@ -347,8 +347,8 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksXLabels >(
auto* const lNode = static_cast< LinearTickmarksLabelsNode* >( tNode->firstChild() );
cNode->setGeometryProperties( state.r1, state.cX, state.cY );
tNode->setMatrix( state.matrix() );
lNode->update(
sensor, subControl, sensor->tickmarkLabels( Qt::XAxis ), { state.scale().x(), 0.0 }, translation );
lNode->update( sensor, subControl, sensor->tickmarkLabels( Qt::XAxis ),
{ state.scale().x(), 0.0 }, translation );
return cNode;
}
@ -358,14 +358,16 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksYLabels >(
{
const auto subControl = Q::TickmarksYLabels;
const State< QskAspect::Subcontrol > state( sensor, subControl );
const auto r3 = static_cast< float >( state.r1 * sensor->strutSizeHint( Q::TickmarksY ).width() );
const auto r3 =
static_cast< float >( state.r1 * sensor->strutSizeHint( Q::TickmarksY ).width() );
const auto scale = sensor->strutSizeHint( subControl );
const auto angles = sensor->angle();
const auto rotation = sensor->subControlRotation( subControl );
const auto translation = state.translation().toVector2D() + QVector2D( r3, 0 );
auto* const cNode = ensureNodes< RadialClipNode, QSGTransformNode, LinearTickmarksLabelsNode >( node );
auto* const cNode =
ensureNodes< RadialClipNode, QSGTransformNode, LinearTickmarksLabelsNode >( node );
auto* const tNode = static_cast< QSGTransformNode* >( cNode->firstChild() );
auto* const lNode = static_cast< LinearTickmarksLabelsNode* >( tNode->firstChild() );
cNode->setGeometryProperties( state.r1, state.cX, state.cY );
@ -380,9 +382,9 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksZLabels >(
const QskLevelingSensor* const sensor, const quint8 nodeRole, QSGNode* const node ) const
{
const auto subControl = Q::TickmarksZLabels;
const State< QskAspect::Subcontrol > state( sensor, subControl );
auto* const tNode = ensureNodes< QSGTransformNode, RadialTickmarksLabelsNode>( node );
auto* const lNode = static_cast< RadialTickmarksLabelsNode* >( tNode->firstChild() );
const State< QskAspect::Subcontrol > state( sensor, subControl );
auto* const tNode = ensureNodes< QSGTransformNode, RadialTickmarksLabelsNode >( node );
auto* const lNode = static_cast< RadialTickmarksLabelsNode* >( tNode->firstChild() );
const auto r3 = static_cast< float >( state.r1 * sensor->strutSizeHint( subControl ).width() );
lNode->update( sensor, subControl, sensor->tickmarkLabels( Qt::ZAxis ), { r3, r3 } );
tNode->setMatrix( state.matrix() );
@ -406,7 +408,7 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode(
const QskSkinnable* const skinnable, const quint8 nodeRole, QSGNode* const node ) const
{
const auto* const sensor = static_cast< const Q* >( skinnable );
switch ( static_cast< R >( nodeRole ) )
{
case OuterDisk:

View File

@ -3,45 +3,36 @@
#include <qmath.h>
#include <qmatrix4x4.h>
#include <QskScaleTickmarks.h>
#include <QskFunctions.h>
#include <QskScaleTickmarks.h>
// create a homogenous transformation matrix
inline Q_REQUIRED_RESULT QMatrix4x4 matrix_deg(
float rX = 0.0f,
float rY = 0.0f,
float rZ = 0.0f,
float tX = 0.0f,
float tY = 0.0f,
float tZ = 0.0f
)
inline Q_REQUIRED_RESULT QMatrix4x4 matrix_deg( float rX = 0.0f, float rY = 0.0f, float rZ = 0.0f,
float tX = 0.0f, float tY = 0.0f, float tZ = 0.0f )
{
// Convert rotation angles to radians
float rotationX = qDegreesToRadians(rX);
float rotationY = qDegreesToRadians(rY);
float rotationZ = qDegreesToRadians(rZ);
float rotationX = qDegreesToRadians( rX );
float rotationY = qDegreesToRadians( rY );
float rotationZ = qDegreesToRadians( rZ );
// Calculate sin and cos of the rotation angles
float cosX = qCos(rotationX);
float sinX = qSin(rotationX);
float cosY = qCos(rotationY);
float sinY = qSin(rotationY);
float cosZ = qCos(rotationZ);
float sinZ = qSin(rotationZ);
float cosX = qCos( rotationX );
float sinX = qSin( rotationX );
float cosY = qCos( rotationY );
float sinY = qSin( rotationY );
float cosZ = qCos( rotationZ );
float sinZ = qSin( rotationZ );
// Create the transform matrix
return QMatrix4x4(
cosY * cosZ, sinX * sinY * cosZ - cosX * sinZ, cosX * sinY * cosZ + sinX * sinZ, tX,
cosY * sinZ, sinX * sinY * sinZ + cosX * cosZ, cosX * sinY * sinZ - sinX * cosZ, tY,
-sinY, sinX * cosY, cosX * cosY, tZ,
0, 0, 0, 1
);
return QMatrix4x4( cosY * cosZ, sinX * sinY * cosZ - cosX * sinZ,
cosX * sinY * cosZ + sinX * sinZ, tX, cosY * sinZ, sinX * sinY * sinZ + cosX * cosZ,
cosX * sinY * sinZ - sinX * cosZ, tY, -sinY, sinX * cosY, cosX * cosY, tZ, 0, 0, 0, 1 );
}
template<typename T>
inline Q_REQUIRED_RESULT bool compareExchange(T& dst, const T& src)
template< typename T >
inline Q_REQUIRED_RESULT bool compareExchange( T& dst, const T& src )
{
if (dst != src)
if ( dst != src )
{
dst = src;
return true;
@ -50,9 +41,9 @@ inline Q_REQUIRED_RESULT bool compareExchange(T& dst, const T& src)
}
template<>
inline Q_REQUIRED_RESULT bool compareExchange<float>(float& dst, const float& src)
inline Q_REQUIRED_RESULT bool compareExchange< float >( float& dst, const float& src )
{
if (!qskFuzzyCompare (dst, src))
if ( !qskFuzzyCompare( dst, src ) )
{
dst = src;
return true;
@ -61,9 +52,9 @@ inline Q_REQUIRED_RESULT bool compareExchange<float>(float& dst, const float& sr
}
template<>
inline Q_REQUIRED_RESULT bool compareExchange<qreal>(qreal& dst, const qreal& src)
inline Q_REQUIRED_RESULT bool compareExchange< qreal >( qreal& dst, const qreal& src )
{
if (!qskFuzzyCompare (dst, src))
if ( !qskFuzzyCompare( dst, src ) )
{
dst = src;
return true;
@ -71,25 +62,26 @@ inline Q_REQUIRED_RESULT bool compareExchange<qreal>(qreal& dst, const qreal& sr
return false;
}
inline QskScaleTickmarks filtered(const QskScaleTickmarks& tickmarks, const std::function<bool(QskScaleTickmarks::TickType, qreal)>& predicate)
inline QskScaleTickmarks filtered( const QskScaleTickmarks& tickmarks,
const std::function< bool( QskScaleTickmarks::TickType, qreal ) >& predicate )
{
QskScaleTickmarks result;
QVector<qreal> ticks[3];
QVector< qreal > ticks[ 3 ];
using T = QskScaleTickmarks::TickType;
for (auto type : { T::MinorTick, T::MediumTick, T::MajorTick })
for ( auto type : { T::MinorTick, T::MediumTick, T::MajorTick } )
{
for (const auto tick : tickmarks.ticks(type))
for ( const auto tick : tickmarks.ticks( type ) )
{
if (predicate(type, tick))
if ( predicate( type, tick ) )
{
ticks[type] << tick;
ticks[ type ] << tick;
}
}
}
result.setMinorTicks(ticks[QskScaleTickmarks::MinorTick]);
result.setMediumTicks(ticks[QskScaleTickmarks::MediumTick]);
result.setMajorTicks(ticks[QskScaleTickmarks::MajorTick]);
result.setMinorTicks( ticks[ QskScaleTickmarks::MinorTick ] );
result.setMediumTicks( ticks[ QskScaleTickmarks::MediumTick ] );
result.setMajorTicks( ticks[ QskScaleTickmarks::MajorTick ] );
return result;
}

View File

@ -17,7 +17,7 @@ namespace QskSGNode
{
root = new Root;
}
if constexpr ( mode == Recursive )
{
QSGNode* current = root;