From 401adac3bad4d2f8453b80a322920fd68c2065e5 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 17 Jul 2019 17:54:16 +0200 Subject: [PATCH] QskLinearBox::count, src/layouts/QskGridBox::count --- examples/layouts/DynamicConstraintsPage.cpp | 2 +- examples/layouts/FlowLayoutPage.cpp | 2 +- examples/layouts/LinearLayoutPage.cpp | 2 +- examples/sliders/main.cpp | 6 +++--- playground/dialogbuttons/Window.cpp | 2 +- src/controls/QskTabBar.cpp | 8 ++++---- src/layouts/QskGridBox.cpp | 6 +++--- src/layouts/QskGridBox.h | 18 +++++++++++++++--- src/layouts/QskLayoutHint.cpp | 4 ++-- src/layouts/QskLinearBox.cpp | 8 ++++---- src/layouts/QskLinearBox.h | 8 ++++---- 11 files changed, 39 insertions(+), 27 deletions(-) diff --git a/examples/layouts/DynamicConstraintsPage.cpp b/examples/layouts/DynamicConstraintsPage.cpp index 341c9d02..6c611404 100644 --- a/examples/layouts/DynamicConstraintsPage.cpp +++ b/examples/layouts/DynamicConstraintsPage.cpp @@ -105,7 +105,7 @@ Box::Box( QQuickItem* parent ) void Box::flip() { - for ( int i = 0; i < entryCount(); i++ ) + for ( int i = 0; i < count(); i++ ) { if ( auto control = dynamic_cast< Control* >( itemAtIndex( i ) ) ) control->transpose(); diff --git a/examples/layouts/FlowLayoutPage.cpp b/examples/layouts/FlowLayoutPage.cpp index 75fbcbe8..ea5e8faa 100644 --- a/examples/layouts/FlowLayoutPage.cpp +++ b/examples/layouts/FlowLayoutPage.cpp @@ -76,7 +76,7 @@ namespace void addRectangle( const char* colorName ) { auto rect = new TestRectangle( colorName ); - rect->setText( QString::number( entryCount() + 1 ) ); + rect->setText( QString::number( count() + 1 ) ); addItem( rect, Qt::AlignCenter ); } diff --git a/examples/layouts/LinearLayoutPage.cpp b/examples/layouts/LinearLayoutPage.cpp index 29d70f7c..b8fad547 100644 --- a/examples/layouts/LinearLayoutPage.cpp +++ b/examples/layouts/LinearLayoutPage.cpp @@ -69,7 +69,7 @@ namespace void addRectangle( const char* colorName ) { auto rect = new TestRectangle( colorName ); - rect->setText( QString::number( entryCount() + 1 ) ); + rect->setText( QString::number( count() + 1 ) ); addItem( rect, Qt::AlignCenter ); } diff --git a/examples/sliders/main.cpp b/examples/sliders/main.cpp index b06f1492..2d41a243 100644 --- a/examples/sliders/main.cpp +++ b/examples/sliders/main.cpp @@ -131,7 +131,7 @@ class SliderBox : public QskLinearBox customSlider->setStepSize( 10 ); customSlider->setPageSize( 10 ); - for ( int i = 0; i < entryCount(); i++ ) + for ( int i = 0; i < count(); i++ ) { if ( auto slider = qobject_cast< QskSlider* >( itemAtIndex( i ) ) ) { @@ -151,7 +151,7 @@ class SliderBox : public QskLinearBox { setOrientation( inverted( orientation() ) ); - for ( int i = 0; i < entryCount(); i++ ) + for ( int i = 0; i < count(); i++ ) { if ( auto slider = qobject_cast< QskSlider* >( itemAtIndex( i ) ) ) { @@ -159,7 +159,7 @@ class SliderBox : public QskLinearBox slider->setOrientation( orientation ); - if ( i >= entryCount() - 1 ) + if ( i >= count() - 1 ) { // we didn't implement the vertical mode of the heavily // customized slider yet. diff --git a/playground/dialogbuttons/Window.cpp b/playground/dialogbuttons/Window.cpp index f8ee6292..6cc24e00 100644 --- a/playground/dialogbuttons/Window.cpp +++ b/playground/dialogbuttons/Window.cpp @@ -87,7 +87,7 @@ void Window::centerButtons() QVector< QskDialogButtonBox* > Window::dialogBoxes() const { QVector< QskDialogButtonBox* > boxes; - for ( int i = 0; i < m_layoutBox->entryCount(); i++ ) + for ( int i = 0; i < m_layoutBox->count(); i++ ) { if ( auto box = qobject_cast< QskDialogButtonBox* >( m_layoutBox->itemAtIndex( i ) ) ) { diff --git a/src/controls/QskTabBar.cpp b/src/controls/QskTabBar.cpp index 0119d87d..99537a0f 100644 --- a/src/controls/QskTabBar.cpp +++ b/src/controls/QskTabBar.cpp @@ -41,7 +41,7 @@ namespace QskControl::keyPressEvent. */ - for ( int i = 0; i < entryCount(); i++ ) + for ( int i = 0; i < count(); i++ ) { if ( auto button = itemAtIndex( i ) ) button->setZ( i == currentIndex ? 0.001 : 0.0 ); @@ -179,8 +179,8 @@ int QskTabBar::insertTab( int index, QskTabButton* button ) { auto buttonBox = m_data->buttonBox; - if ( index < 0 || index >= buttonBox->entryCount() ) - index = buttonBox->entryCount(); + if ( index < 0 || index >= buttonBox->count() ) + index = buttonBox->count(); if ( isComponentComplete() ) { @@ -323,7 +323,7 @@ int QskTabBar::currentIndex() const int QskTabBar::count() const { - return m_data->buttonBox->entryCount(); + return m_data->buttonBox->count(); } QskTabButton* QskTabBar::buttonAt( int position ) diff --git a/src/layouts/QskGridBox.cpp b/src/layouts/QskGridBox.cpp index 691bd9dd..ed514ac4 100644 --- a/src/layouts/QskGridBox.cpp +++ b/src/layouts/QskGridBox.cpp @@ -106,7 +106,7 @@ void QskGridBox::removeItem( const QQuickItem* item ) void QskGridBox::clear( bool autoDelete ) { - for ( int i = itemCount() - 1; i >= 0; i-- ) + for ( int i = count() - 1; i >= 0; i-- ) { auto item = itemAtIndex( i ); @@ -122,7 +122,7 @@ void QskGridBox::clear( bool autoDelete ) } } -int QskGridBox::itemCount() const +int QskGridBox::count() const { return m_data->engine.itemCount(); } @@ -410,7 +410,7 @@ void QskGridBox::updateLayout() QSizeF QskGridBox::contentsSizeHint() const { - if ( itemCount() == 0 ) + if ( count() == 0 ) return QSizeF( 0, 0 ); return m_data->engine.sizeHint( Qt::PreferredSize, QSizeF() ); diff --git a/src/layouts/QskGridBox.h b/src/layouts/QskGridBox.h index aa8fcfbb..7ec6ed07 100644 --- a/src/layouts/QskGridBox.h +++ b/src/layouts/QskGridBox.h @@ -13,7 +13,7 @@ class QSK_EXPORT QskGridBox : public QskBox Q_OBJECT Q_PROPERTY( bool empty READ isEmpty() ) - Q_PROPERTY( int itemCount READ itemCount() ) + Q_PROPERTY( int count READ count ) using Inherited = QskBox; @@ -35,7 +35,11 @@ class QSK_EXPORT QskGridBox : public QskBox Q_INVOKABLE int rowCount() const; Q_INVOKABLE int columnCount() const; - int itemCount() const; + int count() const; + +#ifdef QSK_LAYOUT_COMPAT + int itemCount() const { return count(); } // items and spacers +#endif QQuickItem* itemAtIndex( int index ) const; int indexOf( const QQuickItem* ) const; @@ -56,7 +60,10 @@ class QSK_EXPORT QskGridBox : public QskBox void resetSpacing( Qt::Orientations ); qreal spacing( Qt::Orientation ) const; + void setSpacing( qreal spacing ); + #ifdef QSK_LAYOUT_COMPAT + void setVerticalSpacing( qreal spacing ) { setSpacing( Qt::Vertical, spacing ); } qreal verticalSpacing() const { return spacing( Qt::Vertical ); } @@ -142,7 +149,12 @@ inline void QskGridBox::addItem( inline bool QskGridBox::isEmpty() const { - return itemCount() <= 0; + return count() <= 0; +} + +inline void QskGridBox::setSpacing( qreal spacing ) +{ + setSpacing( Qt::Horizontal | Qt::Vertical, spacing ); } #endif diff --git a/src/layouts/QskLayoutHint.cpp b/src/layouts/QskLayoutHint.cpp index 6676739e..ccc118a0 100644 --- a/src/layouts/QskLayoutHint.cpp +++ b/src/layouts/QskLayoutHint.cpp @@ -76,7 +76,7 @@ void QskLayoutHint::normalize() bool QskLayoutHint::isDefault() const { - return ( m_minimum == 0.0 ) && (m_preferred == 0.0 ) + return ( m_minimum == 0.0 ) && ( m_preferred == 0.0 ) && ( m_maximum == QskLayoutConstraint::unlimited ); } @@ -97,7 +97,7 @@ QDebug operator<<( QDebug debug, const QskLayoutHint& hint ) QDebugStateSaver saver( debug ); debug.nospace(); - debug << "LayoutHint" << "( " + debug << "LayoutHint" << "( " << qskHintValueString( hint.minimum() ) << ", " << qskHintValueString( hint.preferred() ) << ", " << qskHintValueString( hint.maximum() ) << " )"; diff --git a/src/layouts/QskLinearBox.cpp b/src/layouts/QskLinearBox.cpp index f8c9c785..26293e9d 100644 --- a/src/layouts/QskLinearBox.cpp +++ b/src/layouts/QskLinearBox.cpp @@ -77,7 +77,7 @@ QskLinearBox::~QskLinearBox() { } -int QskLinearBox::entryCount() const +int QskLinearBox::count() const { return m_data->engine.count(); } @@ -155,8 +155,8 @@ void QskLinearBox::clear( bool autoDelete ) { auto& engine = m_data->engine; - // do we have visible entries - const bool hasVisibleEntries = engine.rowCount() > 0; + // do we have visible elements + const bool hasVisibleElements = engine.rowCount() > 0; for ( int i = engine.count() - 1; i >= 0; i-- ) { @@ -174,7 +174,7 @@ void QskLinearBox::clear( bool autoDelete ) } } - if ( hasVisibleEntries ) + if ( hasVisibleElements ) resetImplicitSize(); } diff --git a/src/layouts/QskLinearBox.h b/src/layouts/QskLinearBox.h index 9f8bcab1..b0f5c37a 100644 --- a/src/layouts/QskLinearBox.h +++ b/src/layouts/QskLinearBox.h @@ -27,7 +27,7 @@ class QSK_EXPORT QskLinearBox : public QskIndexedLayoutBox Q_PROPERTY( Qt::Edges extraSpacingAt READ extraSpacingAt WRITE setExtraSpacingAt NOTIFY extraSpacingAtChanged ) - Q_PROPERTY( int entryCount READ entryCount() ) + Q_PROPERTY( int count READ count ) Q_PROPERTY( bool empty READ isEmpty() ) using Inherited = QskIndexedLayoutBox; @@ -40,10 +40,10 @@ class QSK_EXPORT QskLinearBox : public QskIndexedLayoutBox ~QskLinearBox() override; bool isEmpty() const; - int entryCount() const; // items and spacers + int count() const; // items and spacers #ifdef QSK_LAYOUT_COMPAT - int itemCount() const { return entryCount(); } // items and spacers + int itemCount() const { return count(); } #endif int spacingAtIndex( int index ) const; @@ -137,7 +137,7 @@ class QSK_EXPORT QskLinearBox : public QskIndexedLayoutBox inline bool QskLinearBox::isEmpty() const { - return entryCount() <= 0; + return count() <= 0; } #endif