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

View File

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

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <QskSkinlet.h>
#include <QSGNode> #include <QSGNode>
#include <QskSkinlet.h>
class QskLevelingSensor; class QskLevelingSensor;
@ -11,7 +11,7 @@ class QSK_EXPORT QskLevelingSensorSkinlet : public QskSkinlet
using Inherited = QskSkinlet; using Inherited = QskSkinlet;
public: public:
enum NodeRole enum NodeRole
{ {
OuterDisk, OuterDisk,
@ -28,26 +28,25 @@ public:
RoleCount RoleCount
}; };
Q_INVOKABLE QskLevelingSensorSkinlet(QskSkin* skin = nullptr); Q_INVOKABLE QskLevelingSensorSkinlet( QskSkin* skin = nullptr );
~QskLevelingSensorSkinlet() override = default; ~QskLevelingSensorSkinlet() override = default;
static Q_REQUIRED_RESULT float outerRadius(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 float innerRadius( const QskSkinnable* const skinnable );
static Q_REQUIRED_RESULT QPointF center(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, Q_REQUIRED_RESULT QSGNode* updateSubNode(
const QRectF& contentsRect, QskAspect::Subcontrol subControl) const override; const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const override;
Q_REQUIRED_RESULT QSGNode* updateSubNode(const QskSkinnable* skinnable, template< NodeRole >
quint8 nodeRole, QSGNode* node) const override; Q_REQUIRED_RESULT QRectF subControlRect(
const QskLevelingSensor* sensor, const QRectF& contentsRect ) const;
template<NodeRole> template< NodeRole >
Q_REQUIRED_RESULT QRectF subControlRect(const QskLevelingSensor* sensor, Q_REQUIRED_RESULT QSGNode* updateSubNode(
const QRectF& contentsRect) const; 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 "QskLevelingSensorUtility.h"
#include <QSGFlatColorMaterial>
#include <QSGGeometry> #include <QSGGeometry>
#include <QSGGeometryNode> #include <QSGGeometryNode>
#include <QSGFlatColorMaterial>
#include <QFontMetricsF> #include <QFontMetricsF>
#include <qmath.h> #include <qmath.h>
class RadialTickmarksNode final : public QSGGeometryNode class RadialTickmarksNode final : public QSGGeometryNode
{ {
public: public:
RadialTickmarksNode() : m_geometry(QSGGeometry::defaultAttributes_Point2D(), 0) RadialTickmarksNode()
: m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
{ {
m_geometry.setDrawingMode(QSGGeometry::DrawLines); m_geometry.setDrawingMode( QSGGeometry::DrawLines );
m_geometry.setVertexDataPattern(QSGGeometry::StaticPattern); m_geometry.setVertexDataPattern( QSGGeometry::StaticPattern );
setGeometry(&m_geometry); setGeometry( &m_geometry );
setMaterial(&m_material); 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); m_material.setColor( color );
markDirty(QSGNode::DirtyMaterial); 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; 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_r1, r1 );
dirty |= compareExchange(m_r2, r2); dirty |= compareExchange( m_r2, r2 );
dirty |= compareExchange(m_tickmarksHash, tickmarks.hash()); dirty |= compareExchange( m_tickmarksHash, tickmarks.hash() );
if (dirty) if ( dirty )
{ {
update(tickmarks); update( tickmarks );
} }
} }
private: private:
void update(const QskScaleTickmarks& tickmarks) 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(); auto* vertexData = m_geometry.vertexDataAsPoint2D();
using T = QskScaleTickmarks::TickType; 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 angleRad = qDegreesToRadians(tick); const auto angleRad = qDegreesToRadians( tick );
const auto x1 = qFastCos(angleRad) * m_r1; const auto x1 = qFastCos( angleRad ) * m_r1;
const auto y1 = qFastSin(angleRad) * m_r1; const auto y1 = qFastSin( angleRad ) * m_r1;
const auto x2 = qFastCos(angleRad) * m_r2[i]; const auto x2 = qFastCos( angleRad ) * m_r2[ i ];
const auto y2 = qFastSin(angleRad) * m_r2[i]; const auto y2 = qFastSin( angleRad ) * m_r2[ i ];
vertexData[0].set(x1, y1); vertexData[ 0 ].set( x1, y1 );
vertexData[1].set(x2, y2); vertexData[ 1 ].set( x2, y2 );
vertexData += 2; vertexData += 2;
} }
} }
m_geometry.markVertexDataDirty(); m_geometry.markVertexDataDirty();
markDirty(QSGNode::DirtyGeometry); markDirty( QSGNode::DirtyGeometry );
} }
QSGGeometry m_geometry; QSGGeometry m_geometry;
@ -90,77 +92,80 @@ private:
class LinearTickmarksNode final : public QSGGeometryNode class LinearTickmarksNode final : public QSGGeometryNode
{ {
public: public:
LinearTickmarksNode() : m_geometry(QSGGeometry::defaultAttributes_Point2D(), 0) LinearTickmarksNode()
: m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
{ {
m_geometry.setDrawingMode(QSGGeometry::DrawLines); m_geometry.setDrawingMode( QSGGeometry::DrawLines );
m_geometry.setVertexDataPattern(QSGGeometry::StaticPattern); m_geometry.setVertexDataPattern( QSGGeometry::StaticPattern );
setGeometry(&m_geometry); setGeometry( &m_geometry );
setMaterial(&m_material); setMaterial( &m_material );
} }
void setMaterialProperties(const QColor& color) void setMaterialProperties( const QColor& color )
{ {
auto dirty = false; 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; 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 |= m_geometry.vertexCount() != tickmarks.tickCount() * 2;
dirty |= compareExchange(m_tickmarkSize, tickmarkSize); dirty |= compareExchange( m_tickmarkSize, tickmarkSize );
dirty |= compareExchange(m_scale, scale); dirty |= compareExchange( m_scale, scale );
dirty |= compareExchange(m_offset, offset); dirty |= compareExchange( m_offset, offset );
if (dirty) if ( dirty )
{ {
update(tickmarks); update( tickmarks );
markDirty(QSGNode::DirtyGeometry); markDirty( QSGNode::DirtyGeometry );
} }
} }
private: private:
void update(const QskScaleTickmarks& tickmarks) 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(); auto* vertexData = m_geometry.vertexDataAsPoint2D();
using T = QskScaleTickmarks::TickType; 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 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 p1 = m_tickmarkSize[ i ] * +1 * d + p + m_offset;
const auto p2 = 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[ 0 ].set( p1.x(), p1.y() );
vertexData[1].set(p2.x(), p2.y()); vertexData[ 1 ].set( p2.x(), p2.y() );
vertexData += 2; vertexData += 2;
} }
} }
@ -177,53 +182,55 @@ private:
class RadialClipNode final : public QSGClipNode class RadialClipNode final : public QSGClipNode
{ {
public: public:
RadialClipNode() : m_geometry(QSGGeometry::defaultAttributes_Point2D(), 0) RadialClipNode()
: m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
{ {
m_geometry.setVertexDataPattern(QSGGeometry::DynamicPattern); m_geometry.setVertexDataPattern( QSGGeometry::DynamicPattern );
m_geometry.setDrawingMode(QSGGeometry::DrawTriangleFan); m_geometry.setDrawingMode( QSGGeometry::DrawTriangleFan );
setGeometry(&m_geometry); setGeometry( &m_geometry );
setIsRectangular(false); 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; auto dirty = false;
dirty |= compareExchange(m_radius, radius); dirty |= compareExchange( m_radius, radius );
dirty |= compareExchange(m_cx, cx); dirty |= compareExchange( m_cx, cx );
dirty |= compareExchange(m_cy, cy); dirty |= compareExchange( m_cy, cy );
dirty |= compareExchange(m_count, count); dirty |= compareExchange( m_count, count );
if (dirty) if ( dirty )
{ {
update(); update();
} }
} }
private: private:
void update() void update()
{ {
const auto step = 2.0 * M_PI / m_count; 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(); 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 ].x = qFastCos( i * step ) * m_radius + m_cx;
vertices[i].y = qFastSin(i * step) * m_radius + m_cy; vertices[ i ].y = qFastSin( i * step ) * m_radius + m_cy;
} }
m_geometry.markVertexDataDirty(); m_geometry.markVertexDataDirty();
markDirty(QSGNode::DirtyGeometry); markDirty( QSGNode::DirtyGeometry );
} }
using QSGClipNode::setIsRectangular;
using QSGClipNode::setClipRect; using QSGClipNode::setClipRect;
using QSGClipNode::setIsRectangular;
QSGGeometry m_geometry; QSGGeometry m_geometry;
qreal m_radius = 1.0; qreal m_radius = 1.0;
@ -232,72 +239,75 @@ private:
int m_count = 360; int m_count = 360;
}; };
template<typename CRTP> template< typename CRTP >
struct TickmarksLabelsNode : public QSGNode struct TickmarksLabelsNode : public QSGNode
{ {
public: public:
QVector2D value(const QVector2D& v, const QVector2D& s, const QVector2D& o) const 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(); 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 QFontMetricsF metrics( skinnable->effectiveFont( subControl ) );
const auto h = skinnable->effectiveFontHeight(subControl); const auto h = skinnable->effectiveFontHeight( subControl );
const auto a = skinnable->alignmentHint(subControl); const auto a = skinnable->alignmentHint( subControl );
auto* textNode = static_cast<QskTextNode*>(firstChild()); auto* textNode = static_cast< QskTextNode* >( firstChild() );
for (const auto& label : qAsConst(labels)) 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 x = v.x();
auto y = v.y(); 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::AlignRight ) ? w : 0;
x -= a.testFlag(Qt::AlignHCenter) ? w / 2 : 0; x -= a.testFlag( Qt::AlignHCenter ) ? w / 2 : 0;
y -= a.testFlag(Qt::AlignBottom) ? h : 0; y -= a.testFlag( Qt::AlignBottom ) ? h : 0;
y -= a.testFlag(Qt::AlignVCenter) ? h / 2 : 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: public:
QVector2D value(const QVector2D& v, const QVector2D& s, const QVector2D& o) const QVector2D value( const QVector2D& v, const QVector2D& s, const QVector2D& o ) const
{ {
return v * s + o; return v * s + o;
} }
}; };
struct RadialTickmarksLabelsNode final : public TickmarksLabelsNode<RadialTickmarksLabelsNode> struct RadialTickmarksLabelsNode final : public TickmarksLabelsNode< RadialTickmarksLabelsNode >
{ {
public: public:
QVector2D value(const QVector2D& v, const QVector2D& s, const QVector2D& o) const QVector2D value( const QVector2D& v, const QVector2D& s, const QVector2D& o ) const
{ {
return QVector2D{ return QVector2D{
(float)qFastCos(qDegreesToRadians(v.x())), ( float ) qFastCos( qDegreesToRadians( v.x() ) ),
(float)qFastSin(qDegreesToRadians(v.y())) ( float ) qFastSin( qDegreesToRadians( v.y() ) )
} *s + o; } * s + o;
} }
}; };

View File

@ -1,8 +1,8 @@
#include <QskLevelingSensorSkinlet.h>
#include <QskLevelingSensor.h>
#include "QskLevelingSensorUtility.h"
#include "QskLevelingSensorNodes.h" #include "QskLevelingSensorNodes.h"
#include "QskLevelingSensorUtility.h"
#include "QskSGNodeUtility.h" #include "QskSGNodeUtility.h"
#include <QskLevelingSensor.h>
#include <QskLevelingSensorSkinlet.h>
#include <QskArcMetrics.h> #include <QskArcMetrics.h>
#include <QskBoxBorderColors.h> #include <QskBoxBorderColors.h>
@ -53,7 +53,7 @@ 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 };
} }
}; };
@ -80,7 +80,7 @@ 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 Q_REQUIRED_RESULT QMatrix4x4 matrix() const noexcept
@ -99,7 +99,7 @@ using namespace QskSGNode;
template< typename Root, typename... Children > template< typename Root, typename... Children >
inline Q_REQUIRED_RESULT Root* ensureNodes( QSGNode* root = nullptr ) 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 ) float QskLevelingSensorSkinlet::outerRadius( const QskSkinnable* const skinnable )
@ -197,7 +197,7 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::OuterDisk >(
const auto boxBorderColors = sensor->boxBorderColorsHint( subControl ); const auto boxBorderColors = sensor->boxBorderColorsHint( subControl );
const auto boxGradient = sensor->gradientHint( 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() ); auto* const bNode = static_cast< QskBoxNode* >( root->firstChild() );
const auto size = outerRadius( sensor ) * sensor->strutSizeHint( Q::OuterDisk ).width(); const auto size = outerRadius( sensor ) * sensor->strutSizeHint( Q::OuterDisk ).width();
@ -221,7 +221,7 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::Horizon >(
const QskLevelingSensor* const sensor, const quint8 nodeRole, QSGNode* const node ) const const QskLevelingSensor* const sensor, const quint8 nodeRole, QSGNode* const node ) const
{ {
const auto subControl = Q::Horizon; 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 dY = 2 * sensor->angle().y();
const auto pY = qBound( 0.0, 0.5 + ( -state.rX / dY ), 1.0 ); 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 tNode = ensureNodes< QSGTransformNode, QskBoxNode >( node );
auto* const boxNode = static_cast< QskBoxNode* >( tNode->firstChild() ); 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 ) * const auto matrix = matrix_deg( 0, 0, 0, state.cX, state.cY, 0 ) *
matrix_deg( 0, 0, 0, -state.r1, -state.r1, 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 QskLevelingSensor* const sensor, const quint8 nodeRole, QSGNode* const node ) const
{ {
const auto subControl = Q::TickmarksX; 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 color = sensor->color( subControl );
const auto scale = sensor->strutSizeHint( subControl ); const auto scale = sensor->strutSizeHint( subControl );
const auto r3 = state.r1 * scale.height(); const auto r3 = state.r1 * scale.height();
auto* const clipping = auto* const clipping =
ensureNodes< RadialClipNode, QSGTransformNode, LinearTickmarksNode >( ensureNodes< RadialClipNode, QSGTransformNode, LinearTickmarksNode >( node );
node );
auto* const transform = static_cast< QSGTransformNode* >( clipping->firstChild() ); auto* const transform = static_cast< QSGTransformNode* >( clipping->firstChild() );
auto* const tickmarks = static_cast< LinearTickmarksNode* >( transform->firstChild() ); auto* const tickmarks = static_cast< LinearTickmarksNode* >( transform->firstChild() );
@ -291,8 +291,7 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksY >(
const auto rotation = sensor->subControlRotation( subControl ); const auto rotation = sensor->subControlRotation( subControl );
auto* const cNode = auto* const cNode =
ensureNodes< RadialClipNode,QSGTransformNode, LinearTickmarksNode>( ensureNodes< RadialClipNode, QSGTransformNode, LinearTickmarksNode >( node );
node );
auto* const tNode = static_cast< QSGTransformNode* >( cNode->firstChild() ); auto* const tNode = static_cast< QSGTransformNode* >( cNode->firstChild() );
auto* const lNode = static_cast< LinearTickmarksNode* >( tNode->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 color = sensor->color( subControl );
const auto scale = sensor->strutSizeHint( subControl ); const auto scale = sensor->strutSizeHint( subControl );
const auto r3 = const auto r3 = qvariant_cast< QVector3D >( sensor->effectiveSkinHint( subControl ) ) *
qvariant_cast< QVector3D >( sensor->effectiveSkinHint( subControl ) ) * ( state.r2 - state.r1 ) + ( state.r2 - state.r1 ) +
QVector3D{ (float)state.r1, (float)state.r1, (float)state.r1 }; QVector3D{ ( float ) state.r1, ( float ) state.r1, ( float ) state.r1 };
auto* const transform = ensureNodes< QSGTransformNode, RadialTickmarksNode >( node ); auto* const transform = ensureNodes< QSGTransformNode, RadialTickmarksNode >( node );
auto* const tickmarksNode = static_cast< RadialTickmarksNode* >( transform->firstChild() ); auto* const tickmarksNode = static_cast< RadialTickmarksNode* >( transform->firstChild() );
@ -338,8 +337,9 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksXLabels >(
{ {
const auto subControl = Q::TickmarksXLabels; const auto subControl = Q::TickmarksXLabels;
const State< QskAspect::Subcontrol > state( sensor, subControl ); const State< QskAspect::Subcontrol > state( sensor, subControl );
const auto r3 = static_cast< float >( state.r1 * sensor->strutSizeHint( Q::TickmarksX ).height() ); const auto r3 =
const auto translation = state.translation().toVector2D() + QVector2D{0, r3}; static_cast< float >( state.r1 * sensor->strutSizeHint( Q::TickmarksX ).height() );
const auto translation = state.translation().toVector2D() + QVector2D{ 0, r3 };
auto* const cNode = auto* const cNode =
ensureNodes< RadialClipNode, QSGTransformNode, LinearTickmarksLabelsNode >( node ); ensureNodes< RadialClipNode, QSGTransformNode, LinearTickmarksLabelsNode >( node );
@ -347,8 +347,8 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksXLabels >(
auto* const lNode = static_cast< LinearTickmarksLabelsNode* >( tNode->firstChild() ); auto* const lNode = static_cast< LinearTickmarksLabelsNode* >( tNode->firstChild() );
cNode->setGeometryProperties( state.r1, state.cX, state.cY ); cNode->setGeometryProperties( state.r1, state.cX, state.cY );
tNode->setMatrix( state.matrix() ); tNode->setMatrix( state.matrix() );
lNode->update( lNode->update( sensor, subControl, sensor->tickmarkLabels( Qt::XAxis ),
sensor, subControl, sensor->tickmarkLabels( Qt::XAxis ), { state.scale().x(), 0.0 }, translation ); { state.scale().x(), 0.0 }, translation );
return cNode; return cNode;
} }
@ -358,14 +358,16 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksYLabels >(
{ {
const auto subControl = Q::TickmarksYLabels; const auto subControl = Q::TickmarksYLabels;
const State< QskAspect::Subcontrol > state( sensor, subControl ); 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 scale = sensor->strutSizeHint( subControl );
const auto angles = sensor->angle(); const auto angles = sensor->angle();
const auto rotation = sensor->subControlRotation( subControl ); const auto rotation = sensor->subControlRotation( subControl );
const auto translation = state.translation().toVector2D() + QVector2D( r3, 0 ); 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 tNode = static_cast< QSGTransformNode* >( cNode->firstChild() );
auto* const lNode = static_cast< LinearTickmarksLabelsNode* >( tNode->firstChild() ); auto* const lNode = static_cast< LinearTickmarksLabelsNode* >( tNode->firstChild() );
cNode->setGeometryProperties( state.r1, state.cX, state.cY ); cNode->setGeometryProperties( state.r1, state.cX, state.cY );
@ -381,7 +383,7 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode< R::TickmarksZLabels >(
{ {
const auto subControl = Q::TickmarksZLabels; const auto subControl = Q::TickmarksZLabels;
const State< QskAspect::Subcontrol > state( sensor, subControl ); const State< QskAspect::Subcontrol > state( sensor, subControl );
auto* const tNode = ensureNodes< QSGTransformNode, RadialTickmarksLabelsNode>( node ); auto* const tNode = ensureNodes< QSGTransformNode, RadialTickmarksLabelsNode >( node );
auto* const lNode = static_cast< RadialTickmarksLabelsNode* >( tNode->firstChild() ); auto* const lNode = static_cast< RadialTickmarksLabelsNode* >( tNode->firstChild() );
const auto r3 = static_cast< float >( state.r1 * sensor->strutSizeHint( subControl ).width() ); const auto r3 = static_cast< float >( state.r1 * sensor->strutSizeHint( subControl ).width() );
lNode->update( sensor, subControl, sensor->tickmarkLabels( Qt::ZAxis ), { r3, r3 } ); lNode->update( sensor, subControl, sensor->tickmarkLabels( Qt::ZAxis ), { r3, r3 } );

View File

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