using QskGraduationMetrics
This commit is contained in:
parent
d0472bc617
commit
3fabf3ee03
@ -7,6 +7,7 @@
|
||||
#include "QskPlotView.h"
|
||||
|
||||
#include <QskGraduationRenderer.h>
|
||||
#include <QskGraduationMetrics.h>
|
||||
#include <QskTickmarks.h>
|
||||
#include <QskTextColors.h>
|
||||
#include <QskFunctions.h>
|
||||
@ -79,7 +80,12 @@ namespace
|
||||
|
||||
const auto tickSize = view->strutSizeHint( aspect );
|
||||
setTickWidth( tickSize.width() );
|
||||
setTickLength( tickSize.height() );
|
||||
|
||||
#if 1
|
||||
const QskGraduationMetrics tickMetrics( qRound( 0.7 * tickSize.height() ),
|
||||
qRound( 0.85 * tickSize.height() ), tickSize.height() );
|
||||
setTickMetrics( tickMetrics );
|
||||
#endif
|
||||
|
||||
setSpacing( view->spacingHint( aspect ) );
|
||||
|
||||
@ -91,9 +97,11 @@ namespace
|
||||
|
||||
qreal labelOffset() const
|
||||
{
|
||||
qreal off = tickLength() + spacing();
|
||||
const auto length = tickMetrics().maxLength();
|
||||
|
||||
qreal off = length + spacing();
|
||||
if ( flags() & CenteredTickmarks )
|
||||
off -= 0.5 * tickLength();
|
||||
off -= 0.5 * length;
|
||||
|
||||
return off;
|
||||
}
|
||||
|
@ -99,7 +99,6 @@ list(APPEND SOURCES
|
||||
|
||||
list(APPEND HEADERS
|
||||
nodes/QskArcNode.h
|
||||
nodes/QskAxisScaleNode.h
|
||||
nodes/QskBasicLinesNode.h
|
||||
nodes/QskBoxNode.h
|
||||
nodes/QskBoxClipNode.h
|
||||
@ -113,6 +112,7 @@ list(APPEND HEADERS
|
||||
nodes/QskBoxShadowNode.h
|
||||
nodes/QskColorRamp.h
|
||||
nodes/QskFillNode.h
|
||||
nodes/QskGraduationNode.h
|
||||
nodes/QskGraduationRenderer.h
|
||||
nodes/QskGraphicNode.h
|
||||
nodes/QskLinesNode.h
|
||||
@ -136,7 +136,6 @@ list(APPEND PRIVATE_HEADERS
|
||||
|
||||
list(APPEND SOURCES
|
||||
nodes/QskArcNode.cpp
|
||||
nodes/QskAxisScaleNode.cpp
|
||||
nodes/QskBasicLinesNode.cpp
|
||||
nodes/QskBoxNode.cpp
|
||||
nodes/QskBoxClipNode.cpp
|
||||
@ -149,6 +148,7 @@ list(APPEND SOURCES
|
||||
nodes/QskBoxShadowNode.cpp
|
||||
nodes/QskColorRamp.cpp
|
||||
nodes/QskFillNode.cpp
|
||||
nodes/QskGraduationNode.cpp
|
||||
nodes/QskGraduationRenderer.cpp
|
||||
nodes/QskGraphicNode.cpp
|
||||
nodes/QskLinesNode.cpp
|
||||
|
@ -53,6 +53,8 @@ class QSK_EXPORT QskGraduationMetrics
|
||||
|
||||
[[nodiscard]] QskHashValue hash( QskHashValue seed = 0 ) const noexcept;
|
||||
|
||||
[[nodiscard]] constexpr qreal maxLength() const noexcept;
|
||||
|
||||
private:
|
||||
static inline constexpr qreal constrainedLength( qreal length )
|
||||
{
|
||||
@ -125,6 +127,12 @@ inline constexpr void QskGraduationMetrics::setTickLength(
|
||||
m_tickLengths[ type ] = constrainedLength( length );
|
||||
}
|
||||
|
||||
inline constexpr qreal QskGraduationMetrics::maxLength() const noexcept
|
||||
{
|
||||
using namespace std;
|
||||
return max( max( m_tickLengths[0], m_tickLengths[1] ), m_tickLengths[2] );
|
||||
}
|
||||
|
||||
inline QskHashValue QskGraduationMetrics::hash( const QskHashValue seed ) const noexcept
|
||||
{
|
||||
auto hash = qHash( m_tickLengths[0], seed );
|
||||
|
@ -3,9 +3,10 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*****************************************************************************/
|
||||
|
||||
#include "QskAxisScaleNode.h"
|
||||
#include "QskGraduationNode.h"
|
||||
#include "QskTickmarks.h"
|
||||
#include "QskIntervalF.h"
|
||||
#include "QskGraduationMetrics.h"
|
||||
|
||||
#include <QTransform>
|
||||
|
||||
@ -56,7 +57,7 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
class QskAxisScaleNode::PrivateData
|
||||
class QskGraduationNode::PrivateData
|
||||
{
|
||||
public:
|
||||
inline qreal map( qreal v ) const
|
||||
@ -67,29 +68,14 @@ class QskAxisScaleNode::PrivateData
|
||||
return transform.dy() + transform.m22() * v;
|
||||
}
|
||||
|
||||
inline qreal length( QskTickmarks::TickType type ) const
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case QskTickmarks::MinorTick:
|
||||
return 0.7 * tickLength;
|
||||
|
||||
case QskTickmarks::MediumTick:
|
||||
return 0.85 * tickLength;
|
||||
|
||||
default:
|
||||
return tickLength;
|
||||
}
|
||||
}
|
||||
|
||||
inline qreal origin( qreal length ) const
|
||||
{
|
||||
switch( alignment )
|
||||
{
|
||||
case QskAxisScaleNode::Leading:
|
||||
case QskGraduationNode::Leading:
|
||||
return pos - length;
|
||||
|
||||
case QskAxisScaleNode::Centered:
|
||||
case QskGraduationNode::Centered:
|
||||
return pos - 0.5 * length;
|
||||
|
||||
default:
|
||||
@ -103,24 +89,24 @@ class QskAxisScaleNode::PrivateData
|
||||
QskIntervalF backbone;
|
||||
QTransform transform;
|
||||
|
||||
QskAxisScaleNode::Alignment alignment = QskAxisScaleNode::Centered;
|
||||
qreal tickLength = 0.0;
|
||||
QskGraduationNode::Alignment alignment = QskGraduationNode::Centered;
|
||||
QskGraduationMetrics graduationMetrics;
|
||||
|
||||
QskHashValue hash = 0;
|
||||
|
||||
bool dirty = true;
|
||||
};
|
||||
|
||||
QskAxisScaleNode::QskAxisScaleNode()
|
||||
QskGraduationNode::QskGraduationNode()
|
||||
: m_data( new PrivateData() )
|
||||
{
|
||||
}
|
||||
|
||||
QskAxisScaleNode::~QskAxisScaleNode()
|
||||
QskGraduationNode::~QskGraduationNode()
|
||||
{
|
||||
}
|
||||
|
||||
void QskAxisScaleNode::setAxis( Qt::Orientation orientation,
|
||||
void QskGraduationNode::setAxis( Qt::Orientation orientation,
|
||||
qreal pos, const QTransform& transform )
|
||||
{
|
||||
const bool isHorizontal = ( orientation == Qt::Horizontal );
|
||||
@ -136,21 +122,21 @@ void QskAxisScaleNode::setAxis( Qt::Orientation orientation,
|
||||
}
|
||||
}
|
||||
|
||||
void QskAxisScaleNode::setTickGeometry(
|
||||
Alignment alignment, qreal tickLength, qreal tickWidth )
|
||||
void QskGraduationNode::setTickGeometry(
|
||||
Alignment alignment, const QskGraduationMetrics& metrics, qreal tickWidth )
|
||||
{
|
||||
setLineWidth( tickWidth );
|
||||
|
||||
if( tickLength != m_data->tickLength || alignment != m_data->alignment )
|
||||
if( metrics != m_data->graduationMetrics || alignment != m_data->alignment )
|
||||
{
|
||||
m_data->tickLength = tickLength;
|
||||
m_data->graduationMetrics = metrics;
|
||||
m_data->alignment = alignment;
|
||||
|
||||
m_data->dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void QskAxisScaleNode::update( const QskTickmarks& tickmarks,
|
||||
void QskGraduationNode::update( const QskTickmarks& tickmarks,
|
||||
const QskIntervalF& backbone )
|
||||
{
|
||||
const auto hash = tickmarks.hash( 17435 );
|
||||
@ -190,7 +176,7 @@ void QskAxisScaleNode::update( const QskTickmarks& tickmarks,
|
||||
{
|
||||
const auto tickType = static_cast< QskTickmarks::TickType >( i );
|
||||
|
||||
const auto len = m_data->length( tickType );
|
||||
const auto len = m_data->graduationMetrics.tickLength( tickType );
|
||||
const auto origin = m_data->origin( len );
|
||||
|
||||
const auto ticks = tickmarks.ticks( tickType );
|
@ -3,8 +3,8 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef QSK_AXIS_SCALE_NODE_H
|
||||
#define QSK_AXIS_SCALE_NODE_H
|
||||
#ifndef QSK_GRADUATION_NODE_H
|
||||
#define QSK_GRADUATION_NODE_H
|
||||
|
||||
#include "QskGlobal.h"
|
||||
#include "QskBasicLinesNode.h"
|
||||
@ -14,10 +14,9 @@
|
||||
class QRectF;
|
||||
class QskIntervalF;
|
||||
class QskTickmarks;
|
||||
class QskGraduationMetrics;
|
||||
|
||||
class QskAxisScaleNodePrivate;
|
||||
|
||||
class QSK_EXPORT QskAxisScaleNode : public QskBasicLinesNode
|
||||
class QSK_EXPORT QskGraduationNode : public QskBasicLinesNode
|
||||
{
|
||||
using Inherited = QskBasicLinesNode;
|
||||
|
||||
@ -29,11 +28,14 @@ class QSK_EXPORT QskAxisScaleNode : public QskBasicLinesNode
|
||||
Trailing
|
||||
};
|
||||
|
||||
QskAxisScaleNode();
|
||||
~QskAxisScaleNode() override;
|
||||
QskGraduationNode();
|
||||
~QskGraduationNode() override;
|
||||
|
||||
#if 1
|
||||
// finding better names
|
||||
void setAxis( Qt::Orientation, qreal pos, const QTransform& );
|
||||
void setTickGeometry( Alignment, qreal tickLength, qreal tickWidth );
|
||||
void setTickGeometry( Alignment, const QskGraduationMetrics&, qreal tickWidth );
|
||||
#endif
|
||||
|
||||
void update( const QskTickmarks&, const QskIntervalF& );
|
||||
|
@ -4,10 +4,11 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "QskGraduationRenderer.h"
|
||||
#include "QskGraduationMetrics.h"
|
||||
#include "QskTickmarks.h"
|
||||
#include "QskSkinlet.h"
|
||||
#include "QskSGNode.h"
|
||||
#include "QskAxisScaleNode.h"
|
||||
#include "QskGraduationNode.h"
|
||||
#include "QskTextOptions.h"
|
||||
#include "QskTextColors.h"
|
||||
#include "QskGraphic.h"
|
||||
@ -108,7 +109,7 @@ class QskGraduationRenderer::PrivateData
|
||||
#endif
|
||||
|
||||
qreal tickWidth = 1.0;
|
||||
qreal tickLength = 10.0;
|
||||
QskGraduationMetrics metrics = { 4, 6, 8 };
|
||||
qreal spacing = 5.0;
|
||||
|
||||
QFont font;
|
||||
@ -227,14 +228,14 @@ QColor QskGraduationRenderer::tickColor() const
|
||||
return m_data->tickColor;
|
||||
}
|
||||
|
||||
void QskGraduationRenderer::setTickLength( qreal length )
|
||||
void QskGraduationRenderer::setTickMetrics( const QskGraduationMetrics& metrics )
|
||||
{
|
||||
m_data->tickLength = qMax( length, 0.0 );
|
||||
m_data->metrics = metrics;
|
||||
}
|
||||
|
||||
qreal QskGraduationRenderer::tickLength() const
|
||||
const QskGraduationMetrics& QskGraduationRenderer::tickMetrics() const
|
||||
{
|
||||
return m_data->tickLength;
|
||||
return m_data->metrics;
|
||||
}
|
||||
|
||||
void QskGraduationRenderer::setTickWidth( qreal width )
|
||||
@ -313,7 +314,7 @@ QSGNode* QskGraduationRenderer::updateTicksNode(
|
||||
const auto orientation = qskIsHorizontal( m_data->edge )
|
||||
? Qt::Horizontal : Qt::Vertical;
|
||||
|
||||
auto alignment = QskAxisScaleNode::Centered;
|
||||
auto alignment = QskGraduationNode::Centered;
|
||||
|
||||
if ( !( m_data->flags & CenteredTickmarks ) )
|
||||
{
|
||||
@ -321,25 +322,25 @@ QSGNode* QskGraduationRenderer::updateTicksNode(
|
||||
{
|
||||
case Qt::LeftEdge:
|
||||
case Qt::TopEdge:
|
||||
alignment = QskAxisScaleNode::Leading;
|
||||
alignment = QskGraduationNode::Leading;
|
||||
break;
|
||||
case Qt::BottomEdge:
|
||||
case Qt::RightEdge:
|
||||
alignment = QskAxisScaleNode::Trailing;
|
||||
alignment = QskGraduationNode::Trailing;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
auto axisNode = QskSGNode::ensureNode< QskAxisScaleNode >( node );
|
||||
auto graduationNode = QskSGNode::ensureNode< QskGraduationNode >( node );
|
||||
|
||||
axisNode->setColor( m_data->tickColor );
|
||||
axisNode->setAxis( orientation, m_data->position, transform );
|
||||
axisNode->setTickGeometry( alignment, m_data->tickLength, m_data->tickWidth );
|
||||
axisNode->setPixelAlignment( Qt::Horizontal | Qt::Vertical );
|
||||
graduationNode->setColor( m_data->tickColor );
|
||||
graduationNode->setAxis( orientation, m_data->position, transform );
|
||||
graduationNode->setTickGeometry( alignment, m_data->metrics, m_data->tickWidth );
|
||||
graduationNode->setPixelAlignment( Qt::Horizontal | Qt::Vertical );
|
||||
|
||||
axisNode->update( m_data->tickmarks, backbone );
|
||||
graduationNode->update( m_data->tickmarks, backbone );
|
||||
|
||||
return axisNode;
|
||||
return graduationNode;
|
||||
}
|
||||
|
||||
QSGNode* QskGraduationRenderer::updateLabelsNode( const QskSkinnable* skinnable,
|
||||
@ -476,9 +477,11 @@ QRectF QskGraduationRenderer::labelRect(
|
||||
{
|
||||
const auto isHorizontal = qskIsHorizontal( m_data->edge );
|
||||
|
||||
auto offset = m_data->tickLength + m_data->spacing;
|
||||
const auto tickLength = m_data->metrics.maxLength();
|
||||
|
||||
auto offset = tickLength + m_data->spacing;
|
||||
if ( m_data->flags & CenteredTickmarks )
|
||||
offset -= 0.5 * m_data->tickLength;
|
||||
offset -= 0.5 * tickLength;
|
||||
|
||||
const bool clampLabels = m_data->flags & ClampedLabels;
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
class QskSkinnable;
|
||||
class QskIntervalF;
|
||||
class QskGraduationMetrics;
|
||||
class QskTickmarks;
|
||||
class QskTextColors;
|
||||
class QskColorFilter;
|
||||
@ -75,8 +76,8 @@ class QSK_EXPORT QskGraduationRenderer
|
||||
void setTickColor( const QColor& );
|
||||
QColor tickColor() const;
|
||||
|
||||
void setTickLength( qreal );
|
||||
qreal tickLength() const;
|
||||
void setTickMetrics( const QskGraduationMetrics& );
|
||||
const QskGraduationMetrics& tickMetrics() const;
|
||||
|
||||
void setTickWidth( qreal );
|
||||
qreal tickWidth() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user