From 341d60e39ba4442133b989ec3cf1e2e0c8f1aca1 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 17 Sep 2021 13:35:11 +0200 Subject: [PATCH] QskGradientStops introduced --- qmlexport/QskQml.cpp | 4 ++-- src/common/QskGradient.cpp | 26 +++++++++++++------------- src/common/QskGradient.h | 14 ++++++++------ src/common/QskRgbPalette.h | 10 +++++----- src/nodes/QskBoxRendererColorMap.h | 4 ++-- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/qmlexport/QskQml.cpp b/qmlexport/QskQml.cpp index 9dd18d76..07a97b30 100644 --- a/qmlexport/QskQml.cpp +++ b/qmlexport/QskQml.cpp @@ -206,11 +206,11 @@ void QskQml::registerTypes() // Support (lists of) GradientStop QMetaType::registerConverter< QJSValue, QskGradientStop >( qskToGradientStop ); - QMetaType::registerConverter< QJSValue, QVector< QskGradientStop > >( + QMetaType::registerConverter< QJSValue, QskGradientStops >( []( const QJSValue& value ) { - QVector< QskGradientStop > stops; + QskGradientStops stops; if ( value.isArray() ) { QJSValueIterator it( value ); diff --git a/src/common/QskGradient.cpp b/src/common/QskGradient.cpp index 064c9f4b..515dfb22 100644 --- a/src/common/QskGradient.cpp +++ b/src/common/QskGradient.cpp @@ -27,7 +27,7 @@ static inline QskGradient::Orientation qskOrientation( Qt::Orientation o ) ? QskGradient::Vertical : QskGradient::Horizontal; } -static inline bool qskIsGradientValid( const QVector< QskGradientStop >& stops ) +static inline bool qskIsGradientValid( const QskGradientStops& stops ) { if ( stops.size() < 2 ) return false; @@ -52,7 +52,7 @@ static inline bool qskIsGradientValid( const QVector< QskGradientStop >& stops ) return true; } -static inline bool qskIsMonochrome( const QVector< QskGradientStop >& stops ) +static inline bool qskIsMonochrome( const QskGradientStops& stops ) { for ( int i = 1; i < stops.size(); i++ ) { @@ -74,7 +74,7 @@ static inline QColor qskInterpolated( } static inline bool qskComparePositions( - const QVector< QskGradientStop >& s1, const QVector< QskGradientStop >& s2 ) + const QskGradientStops& s1, const QskGradientStops& s2 ) { if ( s1.count() != s2.count() ) return false; @@ -89,15 +89,15 @@ static inline bool qskComparePositions( return true; } -static inline QVector< QskGradientStop > qskExpandedStops( - const QVector< QskGradientStop >& s1, const QVector< QskGradientStop >& s2 ) +static inline QskGradientStops qskExpandedStops( + const QskGradientStops& s1, const QskGradientStops& s2 ) { // expand s1 by stops matching to the positions from s2 if ( qskComparePositions( s1, s2 ) ) return s1; - QVector< QskGradientStop > stops; + QskGradientStops stops; stops += s1.first(); @@ -120,10 +120,10 @@ static inline QVector< QskGradientStop > qskExpandedStops( return stops; } -static inline QVector< QskGradientStop > qskExtractedStops( - const QVector< QskGradientStop >& stops, qreal from, qreal to ) +static inline QskGradientStops qskExtractedStops( + const QskGradientStops& stops, qreal from, qreal to ) { - QVector< QskGradientStop > extracted; + QskGradientStops extracted; if ( from == to ) extracted.reserve( 2 ); @@ -192,13 +192,13 @@ QskGradient::QskGradient( Orientation orientation, } QskGradient::QskGradient( Qt::Orientation orientation, - const QVector< QskGradientStop >& stops ) + const QskGradientStops& stops ) : QskGradient( qskOrientation( orientation ), stops ) { } QskGradient::QskGradient( Orientation orientation, - const QVector< QskGradientStop >& stops ) + const QskGradientStops& stops ) : m_orientation( orientation ) , m_stops( stops ) { @@ -272,7 +272,7 @@ void QskGradient::setColors( const QColor& startColor, const QColor& stopColor ) m_stops.append( QskGradientStop( 1.0, stopColor ) ); } -void QskGradient::setStops( const QVector< QskGradientStop >& stops ) +void QskGradient::setStops( const QskGradientStops& stops ) { if ( !qskIsGradientValid( stops ) ) { @@ -284,7 +284,7 @@ void QskGradient::setStops( const QVector< QskGradientStop >& stops ) m_stops = stops; } -QVector< QskGradientStop > QskGradient::stops() const +QskGradientStops QskGradient::stops() const { return m_stops; } diff --git a/src/common/QskGradient.h b/src/common/QskGradient.h index cac89f16..9a84a555 100644 --- a/src/common/QskGradient.h +++ b/src/common/QskGradient.h @@ -15,12 +15,14 @@ class QVariant; +typedef QVector< QskGradientStop > QskGradientStops; + class QSK_EXPORT QskGradient { Q_GADGET Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) - Q_PROPERTY( QVector< QskGradientStop > stops READ stops WRITE setStops ) + Q_PROPERTY( QskGradientStops stops READ stops WRITE setStops ) Q_PROPERTY( bool valid READ isValid ) Q_PROPERTY( bool visible READ isVisible ) @@ -42,10 +44,10 @@ class QSK_EXPORT QskGradient QskGradient( QRgb ); QskGradient( const QColor& ); - QskGradient( Qt::Orientation, const QVector< QskGradientStop >& ); + QskGradient( Qt::Orientation, const QskGradientStops& ); QskGradient( Qt::Orientation, const QColor&, const QColor& ); - QskGradient( Orientation, const QVector< QskGradientStop >& ); + QskGradient( Orientation, const QskGradientStops& ); QskGradient( Orientation, const QColor&, const QColor& ); ~QskGradient(); @@ -66,8 +68,8 @@ class QSK_EXPORT QskGradient Q_INVOKABLE QColor startColor() const; Q_INVOKABLE QColor endColor() const; - Q_INVOKABLE void setStops( const QVector< QskGradientStop >& ); - Q_INVOKABLE QVector< QskGradientStop > stops() const; + Q_INVOKABLE void setStops( const QskGradientStops& ); + Q_INVOKABLE QskGradientStops stops() const; Q_INVOKABLE bool hasStopAt( qreal value ) const; @@ -98,7 +100,7 @@ class QSK_EXPORT QskGradient void setColorAt( int index, const QColor& color ); Orientation m_orientation; - QVector< QskGradientStop > m_stops; + QskGradientStops m_stops; }; Q_DECLARE_METATYPE( QskGradient ) diff --git a/src/common/QskRgbPalette.h b/src/common/QskRgbPalette.h index b5a800ba..050dbe2b 100644 --- a/src/common/QskRgbPalette.h +++ b/src/common/QskRgbPalette.h @@ -7,11 +7,11 @@ #define QSK_RGB_PALETTE_H #include "QskGlobal.h" +#include "QskGradient.h" + #include #include -class QskGradientStop; - class QSK_EXPORT QskRgbPalette { Q_GADGET @@ -75,11 +75,11 @@ class QSK_EXPORT QskRgbPalette return QColor::fromRgba( rgb( weight ) ); } - QVector< QskGradientStop > colorStops( bool discrete = false ) const; + QskGradientStops colorStops( bool discrete = false ) const; - static QVector< QskGradientStop > colorStops( Theme, bool discrete = false ); + static QskGradientStops colorStops( Theme, bool discrete = false ); - static QVector< QskGradientStop > colorStops( + static QskGradientStops colorStops( const QVector< QRgb >&, bool discrete = false ); protected: diff --git a/src/nodes/QskBoxRendererColorMap.h b/src/nodes/QskBoxRendererColorMap.h index f2e57361..b6749b6b 100644 --- a/src/nodes/QskBoxRendererColorMap.h +++ b/src/nodes/QskBoxRendererColorMap.h @@ -148,7 +148,7 @@ namespace QskVertex { public: inline GradientColorIterator( qreal value1, qreal value2, - const QVector< QskGradientStop > stops ) + const QskGradientStops& stops ) : m_value1( value1 ) , m_value2( value2 ) , m_stops( stops ) @@ -207,7 +207,7 @@ namespace QskVertex } const qreal m_value1, m_value2; - QVector< QskGradientStop > m_stops; + const QskGradientStops m_stops; int m_index; qreal m_valueStep1, m_valueStep2, m_stepSize;