avoid overlapping tick labels
This commit is contained in:
parent
228e94dcce
commit
a73df141c6
|
@ -168,6 +168,8 @@ QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
|
|
||||||
auto nextNode = node->firstChild();
|
auto nextNode = node->firstChild();
|
||||||
|
|
||||||
|
QRectF labelRect;
|
||||||
|
|
||||||
for ( auto tick : ticks )
|
for ( auto tick : ticks )
|
||||||
{
|
{
|
||||||
enum LabelNodeRole
|
enum LabelNodeRole
|
||||||
|
@ -184,7 +186,7 @@ QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
|
|
||||||
if ( label.canConvert< QString >() )
|
if ( label.canConvert< QString >() )
|
||||||
{
|
{
|
||||||
const auto text = label.toString();
|
auto text = label.toString();
|
||||||
if ( text.isEmpty() )
|
if ( text.isEmpty() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -227,6 +229,30 @@ QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
nextNode = qskRemoveTraillingNodes( node, nextNode );
|
nextNode = qskRemoveTraillingNodes( node, nextNode );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !labelRect.isEmpty() && labelRect.intersects( r ) )
|
||||||
|
{
|
||||||
|
if ( tick != ticks.last() )
|
||||||
|
{
|
||||||
|
text = QString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( auto obsoleteNode = nextNode
|
||||||
|
? nextNode->previousSibling() : node->lastChild() )
|
||||||
|
{
|
||||||
|
node->removeChildNode( obsoleteNode );
|
||||||
|
if ( obsoleteNode->flags() & QSGNode::OwnedByParent )
|
||||||
|
delete obsoleteNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
labelRect = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
labelRect = r;
|
||||||
|
}
|
||||||
|
|
||||||
if ( nextNode == nullptr )
|
if ( nextNode == nullptr )
|
||||||
{
|
{
|
||||||
nextNode = new QskTextNode;
|
nextNode = new QskTextNode;
|
||||||
|
@ -246,8 +272,6 @@ QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
if ( graphic.isNull() )
|
if ( graphic.isNull() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QRectF r;
|
|
||||||
|
|
||||||
const auto h = fm.height();
|
const auto h = fm.height();
|
||||||
const auto w = graphic.widthForHeight( h );
|
const auto w = graphic.widthForHeight( h );
|
||||||
|
|
||||||
|
@ -258,7 +282,7 @@ QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
auto pos = tickmarksRect.x() + tickPos - 0.5 * w;
|
auto pos = tickmarksRect.x() + tickPos - 0.5 * w;
|
||||||
pos = qBound( labelsRect.left(), pos, labelsRect.right() - w );
|
pos = qBound( labelsRect.left(), pos, labelsRect.right() - w );
|
||||||
|
|
||||||
r = QRectF( pos, labelsRect.y(), w, h );
|
labelRect = QRectF( pos, labelsRect.y(), w, h );
|
||||||
alignment = Qt::AlignHCenter | Qt::AlignBottom;
|
alignment = Qt::AlignHCenter | Qt::AlignBottom;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -266,7 +290,7 @@ QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
auto pos = tickmarksRect.bottom() - ( tickPos + 0.5 * h );
|
auto pos = tickmarksRect.bottom() - ( tickPos + 0.5 * h );
|
||||||
pos = qBound( labelsRect.top(), pos, labelsRect.bottom() - h );
|
pos = qBound( labelsRect.top(), pos, labelsRect.bottom() - h );
|
||||||
|
|
||||||
r = QRectF( labelsRect.right() - w, pos, w, h );
|
labelRect = QRectF( labelsRect.right() - w, pos, w, h );
|
||||||
alignment = Qt::AlignRight | Qt::AlignVCenter;
|
alignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +310,7 @@ QSGNode* QskScaleRenderer::updateLabelsNode(
|
||||||
|
|
||||||
QskSkinlet::updateGraphicNode(
|
QskSkinlet::updateGraphicNode(
|
||||||
skinnable->owningControl(), graphicNode,
|
skinnable->owningControl(), graphicNode,
|
||||||
graphic, m_colorFilter, r, alignment );
|
graphic, m_colorFilter, labelRect, alignment );
|
||||||
|
|
||||||
nextNode = nextNode->nextSibling();
|
nextNode = nextNode->nextSibling();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue