From 0b8d857714de6a31ca5fbb1afc391f196ddf7721 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 16 May 2019 08:14:53 +0200 Subject: [PATCH] takeHint added, removeHint with return code --- src/controls/QskSkinHintTable.cpp | 36 ++++++++++++++++++++++++++++--- src/controls/QskSkinHintTable.h | 9 +++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/controls/QskSkinHintTable.cpp b/src/controls/QskSkinHintTable.cpp index 16384c6e..f417f8b4 100644 --- a/src/controls/QskSkinHintTable.cpp +++ b/src/controls/QskSkinHintTable.cpp @@ -115,12 +115,14 @@ void QskSkinHintTable::setHint( QskAspect::Aspect aspect, const QVariant& skinHi m_hasStates = true; } -void QskSkinHintTable::removeHint( QskAspect::Aspect aspect ) +bool QskSkinHintTable::removeHint( QskAspect::Aspect aspect ) { if ( m_hints == nullptr ) - return; + return false; - if ( m_hints->erase( aspect ) ) + const bool erased = m_hints->erase( aspect ); + + if ( erased ) { if ( aspect.isAnimator() ) m_animatorCount--; @@ -131,6 +133,34 @@ void QskSkinHintTable::removeHint( QskAspect::Aspect aspect ) m_hints = nullptr; } } + + return erased; +} + +QVariant QskSkinHintTable::takeHint( QskAspect::Aspect aspect ) +{ + if ( m_hints ) + { + auto it = m_hints->find( aspect ); + if ( it != m_hints->end() ) + { + const auto value = it->second; + m_hints->erase( it ); + + if ( aspect.isAnimator() ) + m_animatorCount--; + + if ( m_hints->empty() ) + { + delete m_hints; + m_hints = nullptr; + } + + return value; + } + } + + return QVariant(); } void QskSkinHintTable::clear() diff --git a/src/controls/QskSkinHintTable.h b/src/controls/QskSkinHintTable.h index 3c56f156..aeb2c07f 100644 --- a/src/controls/QskSkinHintTable.h +++ b/src/controls/QskSkinHintTable.h @@ -33,7 +33,7 @@ class QSK_EXPORT QskSkinHintTable void setColor( QskAspect::Aspect, QRgb ); void setColor( QskAspect::Aspect, const QColor& ); - QColor color( QskAspect::Aspect aspect ) const; + QColor color( QskAspect::Aspect ) const; void setMetric( QskAspect::Aspect, qreal metric ); qreal metric( QskAspect::Aspect ) const; @@ -62,7 +62,9 @@ class QSK_EXPORT QskSkinHintTable void setHint( QskAspect::Aspect, const QVariant& ); const QVariant& hint( QskAspect::Aspect ) const; - void removeHint( QskAspect::Aspect ); + + bool removeHint( QskAspect::Aspect ); + QVariant takeHint( QskAspect::Aspect ); bool hasHint( QskAspect::Aspect ) const; @@ -160,7 +162,8 @@ inline qreal QskSkinHintTable::metric( QskAspect::Aspect aspect ) const return hint( aspect | QskAspect::Metric ).toReal(); } -inline void QskSkinHintTable::setMargins( QskAspect::Aspect aspect, const QskMargins& margins ) +inline void QskSkinHintTable::setMargins( + QskAspect::Aspect aspect, const QskMargins& margins ) { setHint( aspect | QskAspect::Metric, QVariant::fromValue( margins ) ); }