introducing QskHashValue to work around Qt5/6 incompatibilities

This commit is contained in:
Uwe Rathmann 2022-03-25 10:28:06 +01:00
parent 04ec8b52a1
commit 55d5f99575
36 changed files with 64 additions and 58 deletions

View File

@ -34,7 +34,7 @@ void RadialTickmarksNode::update( const QColor& color, const QRectF& rect,
markDirty( QSGNode::DirtyGeometry ); markDirty( QSGNode::DirtyGeometry );
} }
const uint hash = tickmarks.hash( 17435 ); const auto hash = tickmarks.hash( 17435 );
if( ( hash != m_hash ) || ( rect != m_rect ) ) if( ( hash != m_hash ) || ( rect != m_rect ) )
{ {

View File

@ -29,5 +29,5 @@ class RadialTickmarksNode : public QSGGeometryNode
QRectF m_rect; QRectF m_rect;
int m_lineWidth = 0; int m_lineWidth = 0;
uint m_hash = 0; QskHashValue m_hash = 0;
}; };

View File

@ -86,9 +86,9 @@ QskArcMetrics QskArcMetrics::toAbsolute( const QSizeF& size ) const noexcept
return absoluted; return absoluted;
} }
uint QskArcMetrics::hash( uint seed ) const noexcept QskHashValue QskArcMetrics::hash( QskHashValue seed ) const noexcept
{ {
uint hash = qHash( m_width, seed ); auto hash = qHash( m_width, seed );
hash = qHash( m_startAngle, hash ); hash = qHash( m_startAngle, hash );
hash = qHash( m_spanAngle, hash ); hash = qHash( m_spanAngle, hash );

View File

@ -50,7 +50,7 @@ class QSK_EXPORT QskArcMetrics
QskArcMetrics toAbsolute( const QSizeF& ) const noexcept; QskArcMetrics toAbsolute( const QSizeF& ) const noexcept;
uint hash( uint seed = 0 ) const noexcept; QskHashValue hash( QskHashValue seed = 0 ) const noexcept;
static QVariant interpolate( const QskArcMetrics&, static QVariant interpolate( const QskArcMetrics&,
const QskArcMetrics&, qreal progress ); const QskArcMetrics&, qreal progress );

View File

@ -185,9 +185,9 @@ QVariant QskBoxBorderColors::interpolate(
return QVariant::fromValue( from.interpolated( to, ratio ) ); return QVariant::fromValue( from.interpolated( to, ratio ) );
} }
uint QskBoxBorderColors::hash( uint seed ) const QskHashValue QskBoxBorderColors::hash( QskHashValue seed ) const
{ {
uint h = m_gradients[ 0 ].hash( seed ); auto h = m_gradients[ 0 ].hash( seed );
h = m_gradients[ 1 ].hash( h ); h = m_gradients[ 1 ].hash( h );
h = m_gradients[ 2 ].hash( h ); h = m_gradients[ 2 ].hash( h );
h = m_gradients[ 3 ].hash( h ); h = m_gradients[ 3 ].hash( h );

View File

@ -49,7 +49,7 @@ class QSK_EXPORT QskBoxBorderColors
static QVariant interpolate( const QskBoxBorderColors&, static QVariant interpolate( const QskBoxBorderColors&,
const QskBoxBorderColors&, qreal ratio ); const QskBoxBorderColors&, qreal ratio );
uint hash( uint seed = 0 ) const; QskHashValue hash( QskHashValue seed = 0 ) const;
bool isMonochrome() const; bool isMonochrome() const;
bool isVisible() const; bool isVisible() const;

View File

@ -92,9 +92,9 @@ QVariant QskBoxBorderMetrics::interpolate(
return QVariant::fromValue( from.interpolated( to, progress ) ); return QVariant::fromValue( from.interpolated( to, progress ) );
} }
uint QskBoxBorderMetrics::hash( uint seed ) const noexcept QskHashValue QskBoxBorderMetrics::hash( QskHashValue seed ) const noexcept
{ {
uint hash = qHashBits( &m_widths, sizeof( m_widths ), seed ); auto hash = qHashBits( &m_widths, sizeof( m_widths ), seed );
const int mode = m_sizeMode; const int mode = m_sizeMode;
return qHashBits( &mode, sizeof( mode ), hash ); return qHashBits( &mode, sizeof( mode ), hash );

View File

@ -55,7 +55,7 @@ class QSK_EXPORT QskBoxBorderMetrics
QskBoxBorderMetrics toAbsolute( const QSizeF& ) const noexcept; QskBoxBorderMetrics toAbsolute( const QSizeF& ) const noexcept;
uint hash( uint seed = 0 ) const noexcept; QskHashValue hash( QskHashValue seed = 0 ) const noexcept;
static QVariant interpolate( const QskBoxBorderMetrics&, static QVariant interpolate( const QskBoxBorderMetrics&,
const QskBoxBorderMetrics&, qreal progress ); const QskBoxBorderMetrics&, qreal progress );

View File

@ -151,9 +151,9 @@ QVariant QskBoxShapeMetrics::interpolate(
return QVariant::fromValue( from.interpolated( to, progress ) ); return QVariant::fromValue( from.interpolated( to, progress ) );
} }
uint QskBoxShapeMetrics::hash( uint seed ) const noexcept QskHashValue QskBoxShapeMetrics::hash( QskHashValue seed ) const noexcept
{ {
uint hash = qHash( static_cast< int >( m_sizeMode ), seed ); auto hash = qHash( static_cast< int >( m_sizeMode ), seed );
return qHashBits( m_radii, sizeof( m_radii ), hash ); return qHashBits( m_radii, sizeof( m_radii ), hash );
} }

View File

@ -93,7 +93,7 @@ class QSK_EXPORT QskBoxShapeMetrics
constexpr QskBoxShapeMetrics transposed() const noexcept; constexpr QskBoxShapeMetrics transposed() const noexcept;
uint hash( uint seed = 0 ) const noexcept; QskHashValue hash( QskHashValue seed = 0 ) const noexcept;
static QVariant interpolate( const QskBoxShapeMetrics&, static QVariant interpolate( const QskBoxShapeMetrics&,
const QskBoxShapeMetrics&, qreal progress ) noexcept; const QskBoxShapeMetrics&, qreal progress ) noexcept;

View File

@ -39,4 +39,10 @@
#define QSK_QT_PRIVATE_END \ #define QSK_QT_PRIVATE_END \
QT_WARNING_POP QT_WARNING_POP
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
using QskHashValue = uint;
#else
using QskHashValue = size_t;
#endif
#endif #endif

View File

@ -412,14 +412,14 @@ bool QskGradient::hasStopAt( qreal value ) const
return false; return false;
} }
uint QskGradient::hash( uint seed ) const QskHashValue QskGradient::hash( QskHashValue seed ) const
{ {
if ( m_stops.isEmpty() ) if ( m_stops.isEmpty() )
return seed; return seed;
const auto o = orientation(); const auto o = orientation();
uint hash = qHashBits( &o, sizeof( o ), seed ); auto hash = qHashBits( &o, sizeof( o ), seed );
for ( const auto& stop : m_stops ) for ( const auto& stop : m_stops )
hash = stop.hash( hash ); hash = stop.hash( hash );

View File

@ -96,7 +96,7 @@ class QSK_EXPORT QskGradient
static QVariant interpolate( const QskGradient&, static QVariant interpolate( const QskGradient&,
const QskGradient&, qreal progress ); const QskGradient&, qreal progress );
uint hash( uint seed ) const; QskHashValue hash( QskHashValue seed ) const;
Q_INVOKABLE qreal stopAt( int index ) const; Q_INVOKABLE qreal stopAt( int index ) const;
Q_INVOKABLE QColor colorAt( int index ) const; Q_INVOKABLE QColor colorAt( int index ) const;

View File

@ -44,9 +44,9 @@ void QskGradientStop::setStop( qreal position, const QColor& color ) noexcept
m_color = color; m_color = color;
} }
uint QskGradientStop::hash( uint seed ) const noexcept QskHashValue QskGradientStop::hash( QskHashValue seed ) const noexcept
{ {
uint hash = qHashBits( &m_position, sizeof( m_position ), seed ); auto hash = qHashBits( &m_position, sizeof( m_position ), seed );
return qHashBits( &m_color, sizeof( m_color ), hash ); return qHashBits( &m_color, sizeof( m_color ), hash );
} }

View File

@ -41,7 +41,7 @@ class QSK_EXPORT QskGradientStop
static QColor interpolated( static QColor interpolated(
const QskGradientStop&, const QskGradientStop&, qreal position ) noexcept; const QskGradientStop&, const QskGradientStop&, qreal position ) noexcept;
uint hash( uint seed ) const noexcept; QskHashValue hash( QskHashValue seed ) const noexcept;
private: private:
qreal m_position; qreal m_position;

View File

@ -63,7 +63,7 @@ void QskScaleTickmarks::invert()
std::reverse( m_ticks[ 2 ].begin(), m_ticks[ 2 ].end() ); std::reverse( m_ticks[ 2 ].begin(), m_ticks[ 2 ].end() );
} }
uint QskScaleTickmarks::hash( uint seed ) const QskHashValue QskScaleTickmarks::hash( QskHashValue seed ) const
{ {
seed = qHash( m_ticks[0], seed ); seed = qHash( m_ticks[0], seed );
seed = qHash( m_ticks[1], seed ); seed = qHash( m_ticks[1], seed );

View File

@ -53,7 +53,7 @@ class QSK_EXPORT QskScaleTickmarks
void invert(); void invert();
void reset(); void reset();
uint hash( uint seed = 0 ) const; QskHashValue hash( QskHashValue seed = 0 ) const;
private: private:
QVector< qreal > m_ticks[ 3 ]; QVector< qreal > m_ticks[ 3 ];

View File

@ -83,9 +83,9 @@ QRectF QskShadowMetrics::shadowRect( const QRectF& sourceRect ) const
sourceRect.height() + 2 * extent ); sourceRect.height() + 2 * extent );
} }
uint QskShadowMetrics::hash( uint seed ) const noexcept QskHashValue QskShadowMetrics::hash( QskHashValue seed ) const noexcept
{ {
uint hash; QskHashValue hash;
hash = qHash( m_offset.x(), seed ); hash = qHash( m_offset.x(), seed );
hash = qHash( m_offset.y(), seed ); hash = qHash( m_offset.y(), seed );

View File

@ -56,7 +56,7 @@ class QSK_EXPORT QskShadowMetrics
QRectF shadowRect( const QRectF& sourceRect ) const; QRectF shadowRect( const QRectF& sourceRect ) const;
uint hash( uint seed = 0 ) const noexcept; QskHashValue hash( QskHashValue seed = 0 ) const noexcept;
static QVariant interpolate( const QskShadowMetrics&, static QVariant interpolate( const QskShadowMetrics&,
const QskShadowMetrics&, qreal progress ); const QskShadowMetrics&, qreal progress );

View File

@ -9,7 +9,7 @@
#include <qhashfunctions.h> #include <qhashfunctions.h>
#include <qvariant.h> #include <qvariant.h>
uint QskTextColors::hash( uint seed ) const QskHashValue QskTextColors::hash( QskHashValue seed ) const
{ {
const QRgb rgb[] = { textColor.rgba(), styleColor.rgba(), linkColor.rgba() }; const QRgb rgb[] = { textColor.rgba(), styleColor.rgba(), linkColor.rgba() };
return qHashBits( rgb, sizeof( rgb ), seed ); return qHashBits( rgb, sizeof( rgb ), seed );

View File

@ -25,7 +25,7 @@ class QSK_EXPORT QskTextColors
static QVariant interpolate( const QskTextColors&, static QVariant interpolate( const QskTextColors&,
const QskTextColors&, qreal ratio ); const QskTextColors&, qreal ratio );
uint hash( uint seed = 0 ) const; QskHashValue hash( QskHashValue seed = 0 ) const;
QColor textColor; QColor textColor;
QColor styleColor; QColor styleColor;

View File

@ -50,9 +50,9 @@ QskTextOptions::TextFormat QskTextOptions::effectiveFormat( const QString& text
return m_format; return m_format;
} }
uint qHash( const QskTextOptions& options, uint seed ) noexcept QskHashValue qHash( const QskTextOptions& options, QskHashValue seed ) noexcept
{ {
uint hash; QskHashValue hash;
hash = qHash( options.maximumLineCount(), seed ); hash = qHash( options.maximumLineCount(), seed );
hash = qHash( options.fontSizeMode(), hash ); hash = qHash( options.fontSizeMode(), hash );

View File

@ -164,7 +164,7 @@ inline constexpr bool QskTextOptions::operator!=(
return !( *this == other ); return !( *this == other );
} }
QSK_EXPORT uint qHash( const QskTextOptions&, uint seed = 0 ) noexcept; QSK_EXPORT QskHashValue qHash( const QskTextOptions&, QskHashValue seed = 0 ) noexcept;
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
class QDebug; class QDebug;

View File

@ -1007,7 +1007,7 @@ quint64 QskGraphic::modificationId() const
return m_data->modificationId; return m_data->modificationId;
} }
uint QskGraphic::hash( uint seed ) const QskHashValue QskGraphic::hash( QskHashValue seed ) const
{ {
auto hash = qHash( m_data->renderHints, seed ); auto hash = qHash( m_data->renderHints, seed );

View File

@ -127,7 +127,7 @@ class QSK_EXPORT QskGraphic : public QPaintDevice
static QskGraphic fromPixmapAsImage( const QPixmap& ); static QskGraphic fromPixmapAsImage( const QPixmap& );
quint64 modificationId() const; quint64 modificationId() const;
uint hash( uint seed ) const; QskHashValue hash( QskHashValue seed ) const;
protected: protected:
virtual QSize sizeMetrics() const; virtual QSize sizeMetrics() const;

View File

@ -32,9 +32,9 @@ void QskArcNode::paint( QPainter* painter, const QSizeF& size )
renderer.renderArc( rect, m_metrics, m_gradient, painter ); renderer.renderArc( rect, m_metrics, m_gradient, painter );
} }
uint QskArcNode::hash() const QskHashValue QskArcNode::hash() const
{ {
uint h = m_metrics.hash(); auto h = m_metrics.hash();
for( const auto& stop : qAsConst( m_gradient.stops() ) ) for( const auto& stop : qAsConst( m_gradient.stops() ) )
h = stop.hash( h ); h = stop.hash( h );

View File

@ -20,7 +20,7 @@ class QSK_EXPORT QskArcNode : public QskPaintedNode
const QskGradient&, QQuickWindow* ); const QskGradient&, QQuickWindow* );
void paint( QPainter* painter, const QSizeF& size ) override; void paint( QPainter* painter, const QSizeF& size ) override;
uint hash() const override; QskHashValue hash() const override;
private: private:
QskArcMetrics m_metrics; QskArcMetrics m_metrics;

View File

@ -9,10 +9,10 @@
#include "QskBoxShapeMetrics.h" #include "QskBoxShapeMetrics.h"
#include "QskFunctions.h" #include "QskFunctions.h"
static inline uint qskMetricsHash( static inline QskHashValue qskMetricsHash(
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border ) const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border )
{ {
uint hash = 13000; QskHashValue hash = 13000;
hash = shape.hash( hash ); hash = shape.hash( hash );
return border.hash( hash ); return border.hash( hash );
@ -32,7 +32,7 @@ QskBoxClipNode::~QskBoxClipNode()
void QskBoxClipNode::setBox( const QRectF& rect, void QskBoxClipNode::setBox( const QRectF& rect,
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border ) const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border )
{ {
const uint hash = qskMetricsHash( shape, border ); const auto hash = qskMetricsHash( shape, border );
if ( hash == m_hash && rect == m_rect ) if ( hash == m_hash && rect == m_rect )
return; return;

View File

@ -22,7 +22,7 @@ class QSK_EXPORT QskBoxClipNode : public QSGClipNode
const QskBoxShapeMetrics&, const QskBoxBorderMetrics& ); const QskBoxShapeMetrics&, const QskBoxBorderMetrics& );
private: private:
uint m_hash; QskHashValue m_hash;
QRectF m_rect; QRectF m_rect;
QSGGeometry m_geometry; QSGGeometry m_geometry;

View File

@ -20,19 +20,19 @@ QSK_QT_PRIVATE_END
Q_GLOBAL_STATIC( QSGVertexColorMaterial, qskMaterialVertex ) Q_GLOBAL_STATIC( QSGVertexColorMaterial, qskMaterialVertex )
static inline uint qskMetricsHash( static inline QskHashValue qskMetricsHash(
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& borderMetrics ) const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& borderMetrics )
{ {
uint hash = 13000; QskHashValue hash = 13000;
hash = shape.hash( hash ); hash = shape.hash( hash );
return borderMetrics.hash( hash ); return borderMetrics.hash( hash );
} }
static inline uint qskColorsHash( static inline QskHashValue qskColorsHash(
const QskBoxBorderColors& borderColors, const QskGradient& fillGradient ) const QskBoxBorderColors& borderColors, const QskGradient& fillGradient )
{ {
uint hash = 13000; QskHashValue hash = 13000;
hash = borderColors.hash( hash ); hash = borderColors.hash( hash );
return fillGradient.hash( hash ); return fillGradient.hash( hash );
} }
@ -45,8 +45,8 @@ class QskBoxNodePrivate final : public QSGGeometryNodePrivate
{ {
} }
uint metricsHash = 0; QskHashValue metricsHash = 0;
uint colorsHash = 0; QskHashValue colorsHash = 0;
QRectF rect; QRectF rect;
QSGGeometry geometry; QSGGeometry geometry;
@ -89,8 +89,8 @@ void QskBoxNode::setBoxData( const QRectF& rect,
#endif #endif
#if 1 #if 1
const uint metricsHash = qskMetricsHash( shape, borderMetrics ); const auto metricsHash = qskMetricsHash( shape, borderMetrics );
const uint colorsHash = qskColorsHash( borderColors, fillGradient ); const auto colorsHash = qskColorsHash( borderColors, fillGradient );
if ( ( metricsHash == d->metricsHash ) && if ( ( metricsHash == d->metricsHash ) &&
( colorsHash == d->colorsHash ) && ( rect == d->rect ) ) ( colorsHash == d->colorsHash ) && ( rect == d->rect ) )

View File

@ -8,11 +8,11 @@
#include "QskColorFilter.h" #include "QskColorFilter.h"
#include "QskPainterCommand.h" #include "QskPainterCommand.h"
static inline uint qskHash( static inline QskHashValue qskHash(
const QskGraphic& graphic, const QskColorFilter& colorFilter, const QskGraphic& graphic, const QskColorFilter& colorFilter,
QskTextureRenderer::RenderMode renderMode ) QskTextureRenderer::RenderMode renderMode )
{ {
uint hash = 12000; QskHashValue hash = 12000;
const auto& substitutions = colorFilter.substitutions(); const auto& substitutions = colorFilter.substitutions();
if ( substitutions.size() > 0 ) if ( substitutions.size() > 0 )

View File

@ -28,7 +28,7 @@ class QSK_EXPORT QskGraphicNode : public QskTextureNode
void setTexture( QQuickWindow*, void setTexture( QQuickWindow*,
const QRectF&, uint id, Qt::Orientations ) = delete; const QRectF&, uint id, Qt::Orientations ) = delete;
uint m_hash; QskHashValue m_hash;
}; };
#endif #endif

View File

@ -22,7 +22,7 @@ class QSK_EXPORT QskPaintedNode : public QskTextureNode
virtual void paint( QPainter*, const QSizeF& ) = 0; virtual void paint( QPainter*, const QSizeF& ) = 0;
// a hash value of '0' always results in repainting // a hash value of '0' always results in repainting
virtual uint hash() const = 0; virtual QskHashValue hash() const = 0;
private: private:
class PaintHelper; class PaintHelper;
@ -30,7 +30,7 @@ class QSK_EXPORT QskPaintedNode : public QskTextureNode
void setTexture( QQuickWindow*, void setTexture( QQuickWindow*,
const QRectF&, uint id, Qt::Orientations ) = delete; const QRectF&, uint id, Qt::Orientations ) = delete;
uint m_hash; QskHashValue m_hash;
}; };
#endif #endif

View File

@ -11,12 +11,12 @@
#include <qfont.h> #include <qfont.h>
#include <qstring.h> #include <qstring.h>
static inline uint qskHash( static inline QskHashValue qskHash(
const QString& text, const QSizeF& size, const QFont& font, const QString& text, const QSizeF& size, const QFont& font,
const QskTextOptions& options, const QskTextColors& colors, const QskTextOptions& options, const QskTextColors& colors,
Qt::Alignment alignment, Qsk::TextStyle textStyle ) Qt::Alignment alignment, Qsk::TextStyle textStyle )
{ {
uint hash = 11000; QskHashValue hash = 11000;
hash = qHash( text, hash ); hash = qHash( text, hash );
hash = qHash( font, hash ); hash = qHash( font, hash );
@ -49,7 +49,7 @@ void QskTextNode::setTextData(
if ( matrix != this->matrix() ) // avoid setting DirtyMatrix accidently if ( matrix != this->matrix() ) // avoid setting DirtyMatrix accidently
setMatrix( matrix ); setMatrix( matrix );
const uint hash = qskHash( text, rect.size(), font, const auto hash = qskHash( text, rect.size(), font,
options, colors, alignment, textStyle ); options, colors, alignment, textStyle );
if ( hash != m_hash ) if ( hash != m_hash )

View File

@ -29,7 +29,7 @@ class QSK_EXPORT QskTextNode : public QSGTransformNode
Qt::Alignment, Qsk::TextStyle ); Qt::Alignment, Qsk::TextStyle );
private: private:
uint m_hash; QskHashValue m_hash;
}; };
#endif #endif

View File

@ -34,7 +34,7 @@ class QskTickmarksNodePrivate final : public QSGGeometryNodePrivate
QRectF rect; QRectF rect;
int lineWidth = 0; int lineWidth = 0;
uint hash = 0; QskHashValue hash = 0;
}; };
QskTickmarksNode::QskTickmarksNode() QskTickmarksNode::QskTickmarksNode()
@ -65,7 +65,7 @@ void QskTickmarksNode::update(
markDirty( QSGNode::DirtyGeometry ); markDirty( QSGNode::DirtyGeometry );
} }
const uint hash = tickmarks.hash( 17435 ); const auto hash = tickmarks.hash( 17435 );
if( ( hash != d->hash ) || ( rect != d->rect ) ) if( ( hash != d->hash ) || ( rect != d->rect ) )
{ {