Skip to content

Commit

Permalink
tickWidth moved into QskGraduationMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
uwerat committed Nov 28, 2023
1 parent 3fabf3e commit 6c826c3
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 60 deletions.
3 changes: 2 additions & 1 deletion playground/plots/PlotSkin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QskRgbValue.h>
#include <QskBoxBorderColors.h>
#include <QskBoxShapeMetrics.h>
#include <QskGraduationMetrics.h>
#include <QskStippleMetrics.h>

#include <QskGraduationRenderer.h>
Expand Down Expand Up @@ -101,7 +102,7 @@ void SkinEditor::setupPlotHints()
setFlag( Q::AxisScale | A::Style, QskGraduationRenderer::Backbone );

// thickness/length of the major ticks
setStrutSize( Q::AxisScale, 1.0, 8.0 );
setGraduationMetrics( Q::AxisScale, { 4.0, 6.0, 8.0, 1.0 } );

// spacing between ticks and labels
setSpacing( Q::AxisScale, 5 );
Expand Down
12 changes: 4 additions & 8 deletions playground/plots/QskPlotViewSkinlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,10 @@ namespace

setTickColor( view->color( aspect ) );

const auto tickSize = view->strutSizeHint( aspect );
setTickWidth( tickSize.width() );

#if 1
const QskGraduationMetrics tickMetrics( qRound( 0.7 * tickSize.height() ),
qRound( 0.85 * tickSize.height() ), tickSize.height() );
setTickMetrics( tickMetrics );
#endif
const auto graduation = view->effectiveSkinHint(
aspect | QskAspect::Metric | QskAspect::Graduation );

setTickMetrics( graduation.value< QskGraduationMetrics >() );

setSpacing( view->spacingHint( aspect ) );

Expand Down
6 changes: 3 additions & 3 deletions src/common/QskGraduationMetrics.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "QskGraduationMetrics.h"

#include <qvariant.h>

static void qskRegisterGraduationMetrics()
Expand All @@ -26,7 +25,8 @@ QskGraduationMetrics QskGraduationMetrics::interpolated(

return { qskInterpolated( m_tickLengths[0], to.m_tickLengths[0], ratio ),
qskInterpolated( m_tickLengths[1], to.m_tickLengths[1], ratio ),
qskInterpolated( m_tickLengths[2], to.m_tickLengths[2], ratio ) };
qskInterpolated( m_tickLengths[2], to.m_tickLengths[2], ratio ),
qskInterpolated( m_tickWidth, to.m_tickWidth, ratio ) };
}

QVariant QskGraduationMetrics::interpolate(
Expand All @@ -49,7 +49,7 @@ QDebug operator<<( QDebug debug, const QskGraduationMetrics& metrics )
debug << "Graduation";
debug << '(';
debug << metrics.minorTickLength() << s << metrics.mediumTickLength()
<< s << metrics.majorTickLength();
<< s << metrics.majorTickLength() << "W:" << metrics.tickWidth();
debug << ')';

return debug;
Expand Down
74 changes: 45 additions & 29 deletions src/common/QskGraduationMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ class QSK_EXPORT QskGraduationMetrics
Q_PROPERTY( qreal majorTickLength READ majorTickLength WRITE setMajorTickLength )
Q_PROPERTY( qreal mediumTickLength READ mediumTickLength WRITE setMediumTickLength )
Q_PROPERTY( qreal minorTickLength READ minorTickLength WRITE setMinorTickLength )
Q_PROPERTY( qreal tickWidth READ tickWidth WRITE setTickWidth )

public:
using TickType = QskTickmarks::TickType;

constexpr QskGraduationMetrics() noexcept = default;

constexpr QskGraduationMetrics( qreal minorTickLength,
qreal mediumTickLength, qreal majorTickLength ) noexcept;
constexpr QskGraduationMetrics( const QskGraduationMetrics& ) noexcept = default;
constexpr QskGraduationMetrics( QskGraduationMetrics&& ) noexcept = default;
qreal mediumTickLength, qreal majorTickLength,
qreal tickWidth = 1.0 ) noexcept;

constexpr QskGraduationMetrics& operator=( const QskGraduationMetrics& ) noexcept = default;
constexpr QskGraduationMetrics& operator=( QskGraduationMetrics&& ) noexcept = default;
[[nodiscard]] constexpr bool operator==( const QskGraduationMetrics& ) const noexcept;
[[nodiscard]] constexpr bool operator!=( const QskGraduationMetrics& ) const noexcept;

[[nodiscard]] constexpr bool operator==( const QskGraduationMetrics& rhs ) const noexcept;
[[nodiscard]] constexpr bool operator!=( const QskGraduationMetrics& rhs ) const noexcept;
constexpr void setTickWidth( qreal ) noexcept;
[[nodiscard]] constexpr qreal tickWidth() const noexcept;

constexpr void setTickLength( TickType, qreal ) noexcept;
[[nodiscard]] constexpr qreal tickLength( TickType ) const noexcept;
Expand All @@ -56,57 +57,61 @@ class QSK_EXPORT QskGraduationMetrics
[[nodiscard]] constexpr qreal maxLength() const noexcept;

private:
static inline constexpr qreal constrainedLength( qreal length )
static inline constexpr qreal validated( qreal value )
{
return std::max( 0.0, length );
return std::max( 0.0, value );
}

qreal m_tickLengths[3] = {};
qreal m_tickWidth = 1.0;
};

inline constexpr QskGraduationMetrics::QskGraduationMetrics(
qreal minorTickLength, qreal mediumTickLength, qreal majorTickLength ) noexcept
: m_tickLengths{ constrainedLength( minorTickLength ),
constrainedLength( mediumTickLength ), constrainedLength( majorTickLength ) }
qreal minorTickLength, qreal mediumTickLength, qreal majorTickLength,
qreal tickWidth ) noexcept
: m_tickLengths{ validated( minorTickLength ),
validated( mediumTickLength ), validated( majorTickLength ) }
, m_tickWidth( tickWidth )
{
}

inline constexpr qreal QskGraduationMetrics::majorTickLength() const noexcept
inline constexpr void QskGraduationMetrics::setMajorTickLength( qreal length ) noexcept
{
return tickLength( QskTickmarks::MajorTick );
setTickLength( QskTickmarks::MajorTick, length );
}

inline constexpr qreal QskGraduationMetrics::mediumTickLength() const noexcept
inline constexpr qreal QskGraduationMetrics::majorTickLength() const noexcept
{
return tickLength( QskTickmarks::MediumTick );
return tickLength( QskTickmarks::MajorTick );
}

inline constexpr qreal QskGraduationMetrics::minorTickLength() const noexcept
inline constexpr void QskGraduationMetrics::setMediumTickLength( qreal length ) noexcept
{
return tickLength( QskTickmarks::MinorTick );
setTickLength( QskTickmarks::MediumTick, length );
}

inline constexpr void QskGraduationMetrics::setMajorTickLength( qreal length ) noexcept
inline constexpr qreal QskGraduationMetrics::mediumTickLength() const noexcept
{
setTickLength( QskTickmarks::MajorTick, length );
return tickLength( QskTickmarks::MediumTick );
}

inline constexpr void QskGraduationMetrics::setMediumTickLength( qreal length ) noexcept
inline constexpr void QskGraduationMetrics::setMinorTickLength( qreal length ) noexcept
{
setTickLength( QskTickmarks::MediumTick, length );
setTickLength( QskTickmarks::MinorTick, length );
}

inline constexpr void QskGraduationMetrics::setMinorTickLength( qreal length ) noexcept
inline constexpr qreal QskGraduationMetrics::minorTickLength() const noexcept
{
setTickLength( QskTickmarks::MinorTick, length );
return tickLength( QskTickmarks::MinorTick );
}

inline constexpr bool QskGraduationMetrics::operator==(
const QskGraduationMetrics& other ) const noexcept
{
return qskFuzzyCompare( m_tickLengths[0], other.m_tickLengths[0] ) &&
qskFuzzyCompare( m_tickLengths[1], other.m_tickLengths[1] ) &&
qskFuzzyCompare( m_tickLengths[2], other.m_tickLengths[2] );
qskFuzzyCompare( m_tickLengths[2], other.m_tickLengths[2] &&
qskFuzzyCompare( m_tickWidth, other.m_tickWidth ) );
}

inline constexpr bool QskGraduationMetrics::operator!=(
Expand All @@ -115,16 +120,26 @@ inline constexpr bool QskGraduationMetrics::operator!=(
return !( *this == rhs );
}

inline constexpr qreal QskGraduationMetrics::tickLength(
const QskTickmarks::TickType type ) const noexcept
inline constexpr void QskGraduationMetrics::setTickWidth( qreal width ) noexcept
{
return m_tickLengths[ type ];
m_tickWidth = validated( width );
}

inline constexpr qreal QskGraduationMetrics::tickWidth() const noexcept
{
return m_tickWidth;
}

inline constexpr void QskGraduationMetrics::setTickLength(
TickType type, qreal length ) noexcept
{
m_tickLengths[ type ] = constrainedLength( length );
m_tickLengths[ type ] = validated( length );
}

inline constexpr qreal QskGraduationMetrics::tickLength(
const QskTickmarks::TickType type ) const noexcept
{
return m_tickLengths[ type ];
}

inline constexpr qreal QskGraduationMetrics::maxLength() const noexcept
Expand All @@ -138,6 +153,7 @@ inline QskHashValue QskGraduationMetrics::hash( const QskHashValue seed ) const
auto hash = qHash( m_tickLengths[0], seed );
hash = qHash( m_tickLengths[1], hash );
hash = qHash( m_tickLengths[2], hash );
hash = qHash( m_tickWidth, hash );
return hash;
}

Expand Down
23 changes: 23 additions & 0 deletions src/controls/QskSkinHintTableEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "QskBoxShapeMetrics.h"
#include "QskBoxBorderMetrics.h"
#include "QskBoxBorderColors.h"
#include "QskGraduationMetrics.h"
#include "QskShadowMetrics.h"
#include "QskStippleMetrics.h"
#include "QskGraphic.h"
Expand Down Expand Up @@ -136,6 +137,11 @@ namespace
{
return aspect | QskAspect::Style;
}

inline QskAspect aspectGraduation( QskAspect aspect )
{
return aspect | QskAspect::Graduation;
}
}

QskSkinHintTableEditor::QskSkinHintTableEditor( QskSkinHintTable* table )
Expand Down Expand Up @@ -629,6 +635,23 @@ QskStippleMetrics QskSkinHintTableEditor::stippleMetrics( QskAspect aspect ) con
return metricHint< QskStippleMetrics >( aspectStipple( aspect ) );
}

void QskSkinHintTableEditor::setGraduationMetrics( QskAspect aspect,
const QskGraduationMetrics& metrics, QskStateCombination combination )
{
setMetricHint( aspectGraduation( aspect ), metrics, combination );
}

bool QskSkinHintTableEditor::removeGraduationMetrics(
QskAspect aspect, QskStateCombination combination )
{
return removeMetricHint( aspectGraduation( aspect ), combination );
}

QskGraduationMetrics QskSkinHintTableEditor::graduationMetrics( QskAspect aspect ) const
{
return metricHint< QskGraduationMetrics >( aspectGraduation( aspect ) );
}

void QskSkinHintTableEditor::setTextOptions( QskAspect aspect,
Qt::TextElideMode elideMode, QskTextOptions::WrapMode wrapMode,
QskStateCombination combination )
Expand Down
10 changes: 10 additions & 0 deletions src/controls/QskSkinHintTableEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class QskGradient;
class QskBoxShapeMetrics;
class QskBoxBorderMetrics;
class QskBoxBorderColors;
class QskGraduationMetrics;
class QskShadowMetrics;
class QskStippleMetrics;
class QskGraphic;
Expand Down Expand Up @@ -282,6 +283,15 @@ class QSK_EXPORT QskSkinHintTableEditor

QskStippleMetrics stippleMetrics( QskAspect ) const;

// graduation metrics

void setGraduationMetrics( QskAspect, const QskGraduationMetrics&,
QskStateCombination = QskStateCombination() );

bool removeGraduationMetrics( QskAspect, QskStateCombination = QskStateCombination() );

QskGraduationMetrics graduationMetrics( QskAspect ) const;

// text options flag

void setTextOptions( QskAspect,
Expand Down
7 changes: 4 additions & 3 deletions src/nodes/QskGraduationNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ void QskGraduationNode::setAxis( Qt::Orientation orientation,
}
}

void QskGraduationNode::setTickGeometry(
Alignment alignment, const QskGraduationMetrics& metrics, qreal tickWidth )
void QskGraduationNode::setTickMetrics(
Alignment alignment, const QskGraduationMetrics& metrics )
{
setLineWidth( tickWidth );

if( metrics != m_data->graduationMetrics || alignment != m_data->alignment )
{
setLineWidth( metrics.tickWidth() );

m_data->graduationMetrics = metrics;
m_data->alignment = alignment;

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/QskGraduationNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class QSK_EXPORT QskGraduationNode : public QskBasicLinesNode
#if 1
// finding better names
void setAxis( Qt::Orientation, qreal pos, const QTransform& );
void setTickGeometry( Alignment, const QskGraduationMetrics&, qreal tickWidth );
void setTickMetrics( Alignment, const QskGraduationMetrics& );
#endif

void update( const QskTickmarks&, const QskIntervalF& );
Expand Down
13 changes: 1 addition & 12 deletions src/nodes/QskGraduationRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class QskGraduationRenderer::PrivateData
QColor tickColor = Qt::black; // rgb value ???
#endif

qreal tickWidth = 1.0;
QskGraduationMetrics metrics = { 4, 6, 8 };
qreal spacing = 5.0;

Expand Down Expand Up @@ -238,16 +237,6 @@ const QskGraduationMetrics& QskGraduationRenderer::tickMetrics() const
return m_data->metrics;
}

void QskGraduationRenderer::setTickWidth( qreal width )
{
m_data->tickWidth = qMax( width, 0.0 );
}

qreal QskGraduationRenderer::tickWidth() const
{
return m_data->tickWidth;
}

void QskGraduationRenderer::setFont( const QFont& font )
{
m_data->font = font;
Expand Down Expand Up @@ -335,7 +324,7 @@ QSGNode* QskGraduationRenderer::updateTicksNode(

graduationNode->setColor( m_data->tickColor );
graduationNode->setAxis( orientation, m_data->position, transform );
graduationNode->setTickGeometry( alignment, m_data->metrics, m_data->tickWidth );
graduationNode->setTickMetrics( alignment, m_data->metrics );
graduationNode->setPixelAlignment( Qt::Horizontal | Qt::Vertical );

graduationNode->update( m_data->tickmarks, backbone );
Expand Down
3 changes: 0 additions & 3 deletions src/nodes/QskGraduationRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ class QSK_EXPORT QskGraduationRenderer
void setTickMetrics( const QskGraduationMetrics& );
const QskGraduationMetrics& tickMetrics() const;

void setTickWidth( qreal );
qreal tickWidth() const;

void setFont( const QFont& );
QFont font() const;

Expand Down

0 comments on commit 6c826c3

Please sign in to comment.