Squashed commit of the following:

commit 547927f937a3260d5b23068f06cd181de9b7c763
Author: Uwe Rathmann <Uwe.Rathmann@tigertal.de>
Date:   Wed Mar 23 15:38:40 2022 +0100

    wip

commit ca06b1da4bf9c5b30ef2857f0b6c1e4fb137a64e
Author: Uwe Rathmann <Uwe.Rathmann@tigertal.de>
Date:   Wed Mar 23 15:30:31 2022 +0100

    using private classes

commit 4977b0afa481039f22b64e7f55262be8053a26c2
Author: Uwe Rathmann <Uwe.Rathmann@tigertal.de>
Date:   Wed Mar 23 15:18:20 2022 +0100

    avoid using private Qt headers in examples
This commit is contained in:
Uwe Rathmann 2022-03-23 15:39:17 +01:00
parent 9be4562d8f
commit f44208213c
5 changed files with 89 additions and 89 deletions

View File

@ -11,6 +11,7 @@
#include <QskArcMetrics.h> #include <QskArcMetrics.h>
#include <QskTextOptions.h> #include <QskTextOptions.h>
#include <QskScaleTickmarks.h>
#include <QFontMetrics> #include <QFontMetrics>
#include <QtMath> #include <QtMath>
@ -125,8 +126,7 @@ QRectF LightDisplaySkinlet::subControlRect( const QskSkinnable* skinnable,
QSGNode* LightDisplaySkinlet::updateSubNode( QSGNode* LightDisplaySkinlet::updateSubNode(
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
{ {
auto* display = static_cast< const LightDisplay* >( skinnable ); const auto* display = static_cast< const LightDisplay* >( skinnable );
switch( nodeRole ) switch( nodeRole )
{ {
@ -166,16 +166,16 @@ QSGNode* LightDisplaySkinlet::updateSubNode(
if ( ticksNode == nullptr ) if ( ticksNode == nullptr )
ticksNode = new RadialTickmarksNode(); ticksNode = new RadialTickmarksNode();
QColor color = display->color( LightDisplay::Tickmarks ); const auto color = display->color( LightDisplay::Tickmarks );
QRectF ticksRect = display->subControlRect( LightDisplay::Tickmarks ); const auto ticksRect = display->subControlRect( LightDisplay::Tickmarks );
QskArcMetrics arcMetrics = display->arcMetricsHint( LightDisplay::Tickmarks ); const auto arcMetrics = display->arcMetricsHint( LightDisplay::Tickmarks );
QskIntervalF boundaries = display->boundaries();
QskScaleTickmarks tickmarks; QskScaleTickmarks tickmarks;
tickmarks.setMajorTicks( { 0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5, 180 } ); tickmarks.setMajorTicks( { 0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5, 180 } );
int tickLineWidth = display->metric( LightDisplay::Tickmarks );
ticksNode->update( color, ticksRect, arcMetrics, boundaries, const auto tickLineWidth = display->metric( LightDisplay::Tickmarks );
tickmarks, tickLineWidth, Qt::Horizontal );
ticksNode->update( color, ticksRect, arcMetrics, tickmarks, tickLineWidth );
return ticksNode; return ticksNode;
} }
@ -207,11 +207,11 @@ QSGNode* LightDisplaySkinlet::updateSubNode(
QSizeF LightDisplaySkinlet::textLabelsSize( const LightDisplay* display ) const QSizeF LightDisplaySkinlet::textLabelsSize( const LightDisplay* display ) const
{ {
QFont font = display->effectiveFont( LightDisplay::LeftLabel ); const QFontMetricsF fm( display->effectiveFont( LightDisplay::LeftLabel ) );
QFontMetricsF fm( font );
qreal w = fm.width( QStringLiteral( " 100" ) ); qreal w = fm.width( QStringLiteral( " 100" ) );
qreal h = fm.height(); qreal h = fm.height();
return { w, h }; return { w, h };
} }

View File

@ -5,48 +5,24 @@
#include "RadialTickmarksNode.h" #include "RadialTickmarksNode.h"
#include <QSGFlatColorMaterial> #include <QskScaleTickmarks.h>
#include <QskArcMetrics.h>
#include <QtMath> #include <QtMath>
QSK_QT_PRIVATE_BEGIN
#include <private/qsgnode_p.h>
QSK_QT_PRIVATE_END
static constexpr inline qreal qskTickFactor( QskScaleTickmarks::TickType type ) static constexpr inline qreal qskTickFactor( QskScaleTickmarks::TickType type )
{ {
using TM = QskScaleTickmarks; using TM = QskScaleTickmarks;
return type == TM::MinorTick ? 0.7 : ( type == TM::MinorTick ? 0.85 : 1.0 ); return type == TM::MinorTick ? 0.7 : ( type == TM::MinorTick ? 0.85 : 1.0 );
} }
class RadialTickmarksNodePrivate final : public QSGGeometryNodePrivate
{
public:
RadialTickmarksNodePrivate()
: geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
{
geometry.setDrawingMode( QSGGeometry::DrawLines );
geometry.setVertexDataPattern( QSGGeometry::StaticPattern );
}
QSGGeometry geometry;
QSGFlatColorMaterial material;
QskIntervalF boundaries;
QskScaleTickmarks tickmarks;
QRectF rect;
int lineWidth = 0;
uint hash = 0;
};
RadialTickmarksNode::RadialTickmarksNode() RadialTickmarksNode::RadialTickmarksNode()
: QSGGeometryNode( *new RadialTickmarksNodePrivate ) : m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
{ {
Q_D( RadialTickmarksNode ); m_geometry.setDrawingMode( QSGGeometry::DrawLines );
m_geometry.setVertexDataPattern( QSGGeometry::StaticPattern );
setGeometry( &d->geometry ); setGeometry( &m_geometry );
setMaterial( &d->material ); setMaterial( &m_material );
} }
RadialTickmarksNode::~RadialTickmarksNode() RadialTickmarksNode::~RadialTickmarksNode()
@ -54,29 +30,25 @@ RadialTickmarksNode::~RadialTickmarksNode()
} }
void RadialTickmarksNode::update( const QColor& color, const QRectF& rect, void RadialTickmarksNode::update( const QColor& color, const QRectF& rect,
const QskArcMetrics& arcMetrics, const QskIntervalF& /*boundaries*/, const QskArcMetrics& arcMetrics, const QskScaleTickmarks& tickmarks, int lineWidth )
const QskScaleTickmarks& tickmarks, int lineWidth,
Qt::Orientation /*orientation*/ )
{ {
Q_D( RadialTickmarksNode ); if( lineWidth != m_lineWidth )
if( lineWidth != d->lineWidth )
{ {
d->lineWidth = lineWidth; m_lineWidth = lineWidth;
d->geometry.setLineWidth( lineWidth ); m_geometry.setLineWidth( lineWidth );
markDirty( QSGNode::DirtyGeometry ); markDirty( QSGNode::DirtyGeometry );
} }
const uint hash = tickmarks.hash( 17435 ); const uint hash = tickmarks.hash( 17435 );
if( ( hash != d->hash ) || ( rect != d->rect ) ) if( ( hash != m_hash ) || ( rect != m_rect ) )
{ {
d->hash = hash; m_hash = hash;
d->rect = rect; m_rect = rect;
d->geometry.allocate( tickmarks.tickCount() * 2 ); m_geometry.allocate( tickmarks.tickCount() * 2 );
auto vertexData = d->geometry.vertexDataAsPoint2D(); auto vertexData = m_geometry.vertexDataAsPoint2D();
const auto center = rect.center(); const auto center = rect.center();
const auto radius = 0.5 * rect.width(); const auto radius = 0.5 * rect.width();
@ -113,13 +85,13 @@ void RadialTickmarksNode::update(const QColor& color, const QRectF& rect,
} }
} }
d->geometry.markVertexDataDirty(); m_geometry.markVertexDataDirty();
markDirty( QSGNode::DirtyGeometry ); markDirty( QSGNode::DirtyGeometry );
} }
if ( color != d->material.color() ) if ( color != m_material.color() )
{ {
d->material.setColor( color ); m_material.setColor( color );
markDirty( QSGNode::DirtyMaterial ); markDirty( QSGNode::DirtyMaterial );
} }
} }

View File

@ -5,13 +5,13 @@
#pragma once #pragma once
#include <QskArcMetrics.h>
#include <QskIntervalF.h> #include <QskIntervalF.h>
#include <QskScaleTickmarks.h>
#include <QSGGeometryNode> #include <QSGGeometryNode>
#include <QSGFlatColorMaterial>
class RadialTickmarksNodePrivate; class QskArcMetrics;
class QskScaleTickmarks;
class RadialTickmarksNode : public QSGGeometryNode class RadialTickmarksNode : public QSGGeometryNode
{ {
@ -19,9 +19,15 @@ class RadialTickmarksNode : public QSGGeometryNode
RadialTickmarksNode(); RadialTickmarksNode();
~RadialTickmarksNode() override; ~RadialTickmarksNode() override;
void update( const QColor&, const QRectF&, const QskArcMetrics&, void update( const QColor&, const QRectF&,
const QskIntervalF&, const QskScaleTickmarks&, int, Qt::Orientation ); const QskArcMetrics&, const QskScaleTickmarks&, int lineWidth );
private: private:
Q_DECLARE_PRIVATE( RadialTickmarksNode ) QSGGeometry m_geometry;
QSGFlatColorMaterial m_material;
QRectF m_rect;
int m_lineWidth = 0;
uint m_hash = 0;
}; };

View File

@ -14,6 +14,10 @@
#include <qsgflatcolormaterial.h> #include <qsgflatcolormaterial.h>
#include <qsgvertexcolormaterial.h> #include <qsgvertexcolormaterial.h>
QSK_QT_PRIVATE_BEGIN
#include <private/qsgnode_p.h>
QSK_QT_PRIVATE_END
Q_GLOBAL_STATIC( QSGVertexColorMaterial, qskMaterialVertex ) Q_GLOBAL_STATIC( QSGVertexColorMaterial, qskMaterialVertex )
static inline uint qskMetricsHash( static inline uint qskMetricsHash(
@ -33,13 +37,28 @@ static inline uint qskColorsHash(
return fillGradient.hash( hash ); return fillGradient.hash( hash );
} }
QskBoxNode::QskBoxNode() class QskBoxNodePrivate final : public QSGGeometryNodePrivate
: m_metricsHash( 0 )
, m_colorsHash( 0 )
, m_geometry( QSGGeometry::defaultAttributes_ColoredPoint2D(), 0 )
{ {
public:
QskBoxNodePrivate()
: geometry( QSGGeometry::defaultAttributes_ColoredPoint2D(), 0 )
{
}
uint metricsHash = 0;
uint colorsHash = 0;
QRectF rect;
QSGGeometry geometry;
};
QskBoxNode::QskBoxNode()
: QSGGeometryNode( *new QskBoxNodePrivate )
{
Q_D( QskBoxNode );
setMaterial( qskMaterialVertex ); setMaterial( qskMaterialVertex );
setGeometry( &m_geometry ); setGeometry( &d->geometry );
} }
QskBoxNode::~QskBoxNode() QskBoxNode::~QskBoxNode()
@ -58,6 +77,8 @@ void QskBoxNode::setBoxData( const QRectF& rect,
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& borderMetrics, const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& borderMetrics,
const QskBoxBorderColors& borderColors, const QskGradient& gradient ) const QskBoxBorderColors& borderColors, const QskGradient& gradient )
{ {
Q_D( QskBoxNode );
QskGradient fillGradient = gradient; QskGradient fillGradient = gradient;
#if 1 #if 1
// Renderer is buggy for monochrome gradients with stops. TODO ... // Renderer is buggy for monochrome gradients with stops. TODO ...
@ -71,15 +92,15 @@ void QskBoxNode::setBoxData( const QRectF& rect,
const uint metricsHash = qskMetricsHash( shape, borderMetrics ); const uint metricsHash = qskMetricsHash( shape, borderMetrics );
const uint colorsHash = qskColorsHash( borderColors, fillGradient ); const uint colorsHash = qskColorsHash( borderColors, fillGradient );
if ( ( metricsHash == m_metricsHash ) && if ( ( metricsHash == d->metricsHash ) &&
( colorsHash == m_colorsHash ) && ( rect == m_rect ) ) ( colorsHash == d->colorsHash ) && ( rect == d->rect ) )
{ {
return; return;
} }
m_metricsHash = metricsHash; d->metricsHash = metricsHash;
m_colorsHash = colorsHash; d->colorsHash = colorsHash;
m_rect = rect; d->rect = rect;
markDirty( QSGNode::DirtyMaterial ); markDirty( QSGNode::DirtyMaterial );
markDirty( QSGNode::DirtyGeometry ); markDirty( QSGNode::DirtyGeometry );
@ -87,7 +108,7 @@ void QskBoxNode::setBoxData( const QRectF& rect,
if ( rect.isEmpty() ) if ( rect.isEmpty() )
{ {
m_geometry.allocate( 0 ); d->geometry.allocate( 0 );
return; return;
} }
@ -106,7 +127,7 @@ void QskBoxNode::setBoxData( const QRectF& rect,
if ( !hasBorder && !hasFill ) if ( !hasBorder && !hasFill )
{ {
m_geometry.allocate( 0 ); d->geometry.allocate( 0 );
return; return;
} }
@ -155,7 +176,7 @@ void QskBoxNode::setBoxData( const QRectF& rect,
{ {
setMonochrome( false ); setMonochrome( false );
renderer.renderBox( m_rect, shape, borderMetrics, renderer.renderBox( d->rect, shape, borderMetrics,
borderColors, fillGradient, *geometry() ); borderColors, fillGradient, *geometry() );
} }
else else
@ -168,12 +189,12 @@ void QskBoxNode::setBoxData( const QRectF& rect,
if ( hasFill ) if ( hasFill )
{ {
flatMaterial->setColor( fillGradient.startColor() ); flatMaterial->setColor( fillGradient.startColor() );
renderer.renderFill( m_rect, shape, QskBoxBorderMetrics(), *geometry() ); renderer.renderFill( d->rect, shape, QskBoxBorderMetrics(), *geometry() );
} }
else else
{ {
flatMaterial->setColor( borderColors.gradient( Qsk::Left ).startColor().rgba() ); flatMaterial->setColor( borderColors.gradient( Qsk::Left ).startColor().rgba() );
renderer.renderBorder( m_rect, shape, borderMetrics, *geometry() ); renderer.renderBorder( d->rect, shape, borderMetrics, *geometry() );
} }
} }
} }
@ -185,14 +206,16 @@ void QskBoxNode::setMonochrome( bool on )
if ( on == ( material != qskMaterialVertex ) ) if ( on == ( material != qskMaterialVertex ) )
return; return;
m_geometry.allocate( 0 ); Q_D( QskBoxNode );
d->geometry.allocate( 0 );
if ( on ) if ( on )
{ {
setMaterial( new QSGFlatColorMaterial() ); setMaterial( new QSGFlatColorMaterial() );
const QSGGeometry g( QSGGeometry::defaultAttributes_Point2D(), 0 ); const QSGGeometry g( QSGGeometry::defaultAttributes_Point2D(), 0 );
memcpy( ( void* ) &m_geometry, ( void* ) &g, sizeof( QSGGeometry ) ); memcpy( ( void* ) &d->geometry, ( void* ) &g, sizeof( QSGGeometry ) );
} }
else else
{ {
@ -200,6 +223,6 @@ void QskBoxNode::setMonochrome( bool on )
delete material; delete material;
const QSGGeometry g( QSGGeometry::defaultAttributes_ColoredPoint2D(), 0 ); const QSGGeometry g( QSGGeometry::defaultAttributes_ColoredPoint2D(), 0 );
memcpy( ( void* ) &m_geometry, ( void* ) &g, sizeof( QSGGeometry ) ); memcpy( ( void* ) &d->geometry, ( void* ) &g, sizeof( QSGGeometry ) );
} }
} }

View File

@ -14,6 +14,8 @@ class QskBoxBorderMetrics;
class QskBoxBorderColors; class QskBoxBorderColors;
class QskGradient; class QskGradient;
class QskBoxNodePrivate;
class QSK_EXPORT QskBoxNode : public QSGGeometryNode class QSK_EXPORT QskBoxNode : public QSGGeometryNode
{ {
public: public:
@ -29,11 +31,8 @@ class QSK_EXPORT QskBoxNode : public QSGGeometryNode
private: private:
void setMonochrome( bool on ); void setMonochrome( bool on );
uint m_metricsHash; Q_DECLARE_PRIVATE( QskBoxNode )
uint m_colorsHash;
QRectF m_rect;
QSGGeometry m_geometry;
}; };
#endif #endif