From 38372058479aed98658fe8092d2ed3a0f685fdbb Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 19 Jan 2018 10:07:05 +0100 Subject: [PATCH] [Misc] several static methods from QskControl changed into qskXYZ functions to avoid any conflicts with APIs that might be added to QQuickItem in future versions --- src/controls/QskControl.cpp | 119 +++++++++++++++----------- src/controls/QskControl.h | 16 ++-- src/controls/QskScrollArea.cpp | 15 +--- src/controls/QskScrollViewSkinlet.cpp | 2 +- src/controls/QskSetup.cpp | 2 +- src/controls/QskShortcutMap.cpp | 2 +- src/controls/QskSubWindow.cpp | 4 +- src/controls/QskWindow.cpp | 2 +- src/layouts/QskIndexedLayoutBox.cpp | 2 +- support/SkinnyShortcut.cpp | 4 +- 10 files changed, 86 insertions(+), 82 deletions(-) diff --git a/src/controls/QskControl.cpp b/src/controls/QskControl.cpp index 11889fc2..ab2ae90c 100644 --- a/src/controls/QskControl.cpp +++ b/src/controls/QskControl.cpp @@ -42,6 +42,73 @@ static inline void qskSendEventTo( QObject* object, QEvent::Type type ) QCoreApplication::sendEvent( object, &event ); } +bool qskIsAncestorOf( const QQuickItem* item, const QQuickItem* child ) +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) + return item->isAncestorOf( child ); +#else + while ( child ) + { + if ( child == item ) + return true; + + child = child->parentItem(); + } + + return false; +#endif +} + +bool qskIsTabFence( const QQuickItem* item ) +{ + if ( item == nullptr ) + return false; + + return QQuickItemPrivate::get( item )->isTabFence; +} + +bool qskIsShortcutScope( const QQuickItem* item ) +{ + if ( item == nullptr ) + return false; + + /* + We might have something like CTRL+W to close a "window". + But in Qt/Quick a window is not necessarily a QQuickWindow + like we have f.e QskSubWindow. + + Maybe it's worth to introduce a shortcutScope flag but for + the moment we simply use the isFocusScope/isTabFence combination, + that should usually be set for those "windows". + */ + + return item->isFocusScope() && QQuickItemPrivate::get( item )->isTabFence; +} + +bool qskIsTransparentForPositioner( const QQuickItem* item ) +{ + if ( item == nullptr ) + return true; + + return QQuickItemPrivate::get( item )->isTransparentForPositioner(); +} + +const QSGNode* qskItemNode( const QQuickItem* item ) +{ + if ( item == nullptr ) + return nullptr; + + return QQuickItemPrivate::get( item )->itemNodeInstance; +} + +const QSGNode* qskPaintNode( const QQuickItem* item ) +{ + if ( item == nullptr ) + return nullptr; + + return QQuickItemPrivate::get( item )->paintNode; +} + static inline controlFlags_t qskControlFlags() { // we are only interested in the first 8 bits @@ -479,14 +546,6 @@ bool QskControl::isTransparentForPositioner() const return d_func()->isTransparentForPositioner(); } -bool QskControl::isTransparentForPositioner( const QQuickItem* item ) -{ - if ( item == nullptr ) - return true; - - return QQuickItemPrivate::get( item )->isTransparentForPositioner(); -} - void QskControl::setPolishOnResize( bool on ) { Q_D( QskControl ); @@ -555,32 +614,6 @@ bool QskControl::isTabFence() const return d_func()->isTabFence; } -bool QskControl::isTabFence( const QQuickItem* item ) -{ - if ( item == nullptr ) - return false; - - return QQuickItemPrivate::get( item )->isTabFence; -} - -bool QskControl::isShortcutScope( const QQuickItem* item ) -{ - if ( item == nullptr ) - return false; - - /* - We might have something like CTRL+W to close a "window". - But in Qt/Quick a window is not necessarily a QQuickWindow - like we have f.e QskSubWindow. - - Maybe it's worth to introduce a shortcutScope flag but for - the moment we simply use the isFocusScope/isTabFence combination, - that should usually be set for those "windows". - */ - - return item->isFocusScope() && QQuickItemPrivate::get( item )->isTabFence; -} - QskControl::Flags QskControl::controlFlags() const { return QskControl::Flags( d_func()->controlFlags ); @@ -1170,22 +1203,6 @@ void QskControl::releaseResources() qskReleasedWindowCounter->setWindow( window() ); } -const QSGNode* QskControl::itemNode( const QQuickItem* item ) -{ - if ( item == nullptr ) - return nullptr; - - return QQuickItemPrivate::get( item )->itemNodeInstance; -} - -const QSGNode* QskControl::paintNode( const QQuickItem* item ) -{ - if ( item == nullptr ) - return nullptr; - - return QQuickItemPrivate::get( item )->paintNode; -} - void QskControl::itemChange( QQuickItem::ItemChange change, const QQuickItem::ItemChangeData& value ) { @@ -1210,7 +1227,7 @@ void QskControl::itemChange( QQuickItem::ItemChange change, } case QQuickItem::ItemChildAddedChange: { - if ( d->autoLayoutChildren && !isTransparentForPositioner( value.item ) ) + if ( d->autoLayoutChildren && !qskIsTransparentForPositioner( value.item ) ) polish(); break; diff --git a/src/controls/QskControl.h b/src/controls/QskControl.h index 41cfa31b..4799e178 100644 --- a/src/controls/QskControl.h +++ b/src/controls/QskControl.h @@ -120,11 +120,6 @@ public: void setTransparentForPositioner( bool ); bool isTransparentForPositioner() const; - static bool isTransparentForPositioner( const QQuickItem* ); - - static const QSGNode* itemNode( const QQuickItem* ); - static const QSGNode* paintNode( const QQuickItem* ); - void setWheelEnabled( bool ); bool isWheelEnabled() const; @@ -134,9 +129,6 @@ public: void setTabFence( bool ); bool isTabFence() const; - static bool isTabFence( const QQuickItem* ); - static bool isShortcutScope( const QQuickItem* ); - void setControlFlags( Flags ); void resetControlFlags(); Flags controlFlags() const; @@ -247,6 +239,14 @@ inline QSizeF QskControl::sizeHint() const return effectiveConstraint( Qt::PreferredSize ); } +QSK_EXPORT bool qskIsAncestorOf( const QQuickItem* item, const QQuickItem *child ); +QSK_EXPORT bool qskIsTransparentForPositioner( const QQuickItem* ); +QSK_EXPORT bool qskIsTabFence( const QQuickItem* ); +QSK_EXPORT bool qskIsShortcutScope( const QQuickItem* ); + +QSK_EXPORT const QSGNode* qskItemNode( const QQuickItem* ); +QSK_EXPORT const QSGNode* qskPaintNode( const QQuickItem* ); + Q_DECLARE_OPERATORS_FOR_FLAGS( QskControl::Flags ) Q_DECLARE_METATYPE( QskControl::Flags ) diff --git a/src/controls/QskScrollArea.cpp b/src/controls/QskScrollArea.cpp index 02e64080..b35636cd 100644 --- a/src/controls/QskScrollArea.cpp +++ b/src/controls/QskScrollArea.cpp @@ -15,19 +15,6 @@ QSK_QT_PRIVATE_BEGIN #include QSK_QT_PRIVATE_END -static inline bool qskIsAncestorOf( const QQuickItem* item, const QQuickItem* child ) -{ - while ( child ) - { - if ( child == item ) - return true; - - child = child->parentItem(); - } - - return false; -} - static QSizeF qskAdjustedSize( const QQuickItem* item, const QSizeF& targetSize ) { using namespace QskLayoutConstraint; @@ -312,7 +299,7 @@ void QskScrollAreaClipItem::updateNode( QSGNode* ) const QSGClipNode* QskScrollAreaClipItem::viewPortClipNode() const { - auto node = const_cast< QSGNode* >( QskControl::paintNode( scrollArea() ) ); + auto node = const_cast< QSGNode* >( qskPaintNode( scrollArea() ) ); if ( node ) node = QskSkinlet::findNodeByRole( node, QskScrollViewSkinlet::ContentsRootRole ); diff --git a/src/controls/QskScrollViewSkinlet.cpp b/src/controls/QskScrollViewSkinlet.cpp index b65e486f..48729de6 100644 --- a/src/controls/QskScrollViewSkinlet.cpp +++ b/src/controls/QskScrollViewSkinlet.cpp @@ -166,7 +166,7 @@ QSGNode* QskScrollViewSkinlet::updateContentsNode( QSGNode* QskScrollViewSkinlet::contentsNode( const QskScrollView* scrollView ) { - QSGNode* node = const_cast< QSGNode* >( QskControl::paintNode( scrollView ) ); + QSGNode* node = const_cast< QSGNode* >( qskPaintNode( scrollView ) ); if ( node ) { node = findNodeByRole( node, ContentsRootRole ); diff --git a/src/controls/QskSetup.cpp b/src/controls/QskSetup.cpp index ad75f5cf..f9a0435e 100644 --- a/src/controls/QskSetup.cpp +++ b/src/controls/QskSetup.cpp @@ -306,7 +306,7 @@ bool QskSetup::eventFilter( QObject* object, QEvent* event ) But we also don't want to have how it is done in QC2 by adding the focus management in the event handler of the base class. - This implementatio reverts the expected default behaviour of when + This implementation reverts the expected default behaviour of when events are accepted/ignored + is an error prone nightmare, when it comes to overloading event handlers missing to call the base class. diff --git a/src/controls/QskShortcutMap.cpp b/src/controls/QskShortcutMap.cpp index 49aac566..9cd6ffb2 100644 --- a/src/controls/QskShortcutMap.cpp +++ b/src/controls/QskShortcutMap.cpp @@ -360,7 +360,7 @@ bool QskShortcutMap::contextMatcher( We have to find out if the active focus is inside the surronding shortcut scope. */ - if ( QskControl::isShortcutScope( item ) ) + if ( qskIsShortcutScope( item ) ) { if ( !item->hasFocus() ) return false; diff --git a/src/controls/QskSubWindow.cpp b/src/controls/QskSubWindow.cpp index bb500f05..0960ab4e 100644 --- a/src/controls/QskSubWindow.cpp +++ b/src/controls/QskSubWindow.cpp @@ -144,7 +144,7 @@ QSizeF QskSubWindow::contentsSizeHint() const const auto children = childItems(); for ( auto child : children ) { - if ( isTransparentForPositioner( child ) ) + if ( qskIsTransparentForPositioner( child ) ) continue; const QskControl* control = qobject_cast< QskControl* >( child ); @@ -182,7 +182,7 @@ void QskSubWindow::itemChange( QQuickItem::ItemChange change, case QQuickItem::ItemChildAddedChange: case QQuickItem::ItemChildRemovedChange: { - if ( !isTransparentForPositioner( value.item ) ) + if ( !qskIsTransparentForPositioner( value.item ) ) { resetImplicitSize(); polish(); diff --git a/src/controls/QskWindow.cpp b/src/controls/QskWindow.cpp index f2d0ccca..05566bbe 100644 --- a/src/controls/QskWindow.cpp +++ b/src/controls/QskWindow.cpp @@ -383,7 +383,7 @@ void QskWindow::layoutItems() const auto children = contentItem()->childItems(); for ( auto child : children ) { - if ( !QskControl::isTransparentForPositioner( child ) ) + if ( !qskIsTransparentForPositioner( child ) ) { child->setPosition( contentItem()->position() ); child->setSize( sz ); diff --git a/src/layouts/QskIndexedLayoutBox.cpp b/src/layouts/QskIndexedLayoutBox.cpp index b5405cf8..85c33888 100644 --- a/src/layouts/QskIndexedLayoutBox.cpp +++ b/src/layouts/QskIndexedLayoutBox.cpp @@ -205,7 +205,7 @@ void QskIndexedLayoutBox::itemChange( { if ( m_data->autoAddChildren && !m_data->blockChildAdded ) { - if ( !isTransparentForPositioner( value.item ) ) + if ( !qskIsTransparentForPositioner( value.item ) ) addItem( value.item ); } diff --git a/support/SkinnyShortcut.cpp b/support/SkinnyShortcut.cpp index 10b758ab..a4bf4eec 100644 --- a/support/SkinnyShortcut.cpp +++ b/support/SkinnyShortcut.cpp @@ -192,11 +192,11 @@ static inline void countNodes( const QSGNode* node, int& counter ) static void countNodes( const QQuickItem* item, int& counter ) { - const auto itemNode = QskControl::itemNode( item ); + const auto itemNode = qskItemNode( item ); if ( itemNode ) { - auto node = QskControl::paintNode( item ); + auto node = qskPaintNode( item ); if ( node ) { countNodes( node, counter );