avoid warnings about narrowing size_t to int

This commit is contained in:
Uwe Rathmann 2022-04-22 08:13:19 +02:00
parent 3f818470e8
commit 8680423c33
2 changed files with 25 additions and 13 deletions

View File

@ -195,6 +195,13 @@ namespace
QRect m_grid; QRect m_grid;
bool m_isSpacer; bool m_isSpacer;
}; };
class ElementsVector : public std::vector< Element >
{
public:
// to avoid warnings when assigning size_t to int
inline int count() const { return static_cast< int >( size() ); }
};
} }
Element::Element( QQuickItem* item, const QRect& grid ) Element::Element( QQuickItem* item, const QRect& grid )
@ -304,8 +311,7 @@ class QskGridLayoutEngine::PrivateData
public: public:
inline Element* elementAt( int index ) const inline Element* elementAt( int index ) const
{ {
const int count = this->elements.size(); if ( index < 0 || index >= this->elements.count() )
if ( index < 0 || index >= count )
return nullptr; return nullptr;
return const_cast< Element* >( &this->elements[index] ); return const_cast< Element* >( &this->elements[index] );
@ -340,7 +346,7 @@ class QskGridLayoutEngine::PrivateData
rowCount = qMax( rowCount, grid.bottom() + 1 ); rowCount = qMax( rowCount, grid.bottom() + 1 );
columnCount = qMax( columnCount, grid.right() + 1 ); columnCount = qMax( columnCount, grid.right() + 1 );
return this->elements.size() - 1; return this->elements.count() - 1;
} }
QRect effectiveGrid( const Element& element ) const QRect effectiveGrid( const Element& element ) const
@ -363,7 +369,7 @@ class QskGridLayoutEngine::PrivateData
? that->columnSettings : that->rowSettings; ? that->columnSettings : that->rowSettings;
} }
std::vector< Element > elements; ElementsVector elements;
Settings rowSettings; Settings rowSettings;
Settings columnSettings; Settings columnSettings;
@ -383,7 +389,7 @@ QskGridLayoutEngine::~QskGridLayoutEngine()
int QskGridLayoutEngine::count() const int QskGridLayoutEngine::count() const
{ {
return m_data->elements.size(); return m_data->elements.count();
} }
bool QskGridLayoutEngine::setStretchFactor( bool QskGridLayoutEngine::setStretchFactor(
@ -626,7 +632,7 @@ void QskGridLayoutEngine::setupChain( Qt::Orientation orientation,
before adding those that occupy more than one cell before adding those that occupy more than one cell
*/ */
QVarLengthArray< const Element* > postponed; QVarLengthArray< const Element* > postponed;
postponed.reserve( m_data->elements.size() ); postponed.reserve( m_data->elements.count() );
for ( const auto& element : m_data->elements ) for ( const auto& element : m_data->elements )
{ {

View File

@ -50,6 +50,13 @@ namespace
int m_stretch = -1; int m_stretch = -1;
bool m_isSpacer; bool m_isSpacer;
}; };
class ElementsVector : public std::vector< Element >
{
public:
// to avoid warnings when assigning size_t to int
inline int count() const { return static_cast< int >( size() ); }
};
} }
Element::Element( QQuickItem* item ) Element::Element( QQuickItem* item )
@ -164,14 +171,13 @@ class QskLinearLayoutEngine::PrivateData
inline Element* elementAt( int index ) const inline Element* elementAt( int index ) const
{ {
const int count = this->elements.size(); if ( ( index < 0 ) || ( index >= this->elements.count() ) )
if ( ( index < 0 ) || ( index >= count ) )
return nullptr; return nullptr;
return const_cast< Element* >( &this->elements[index] ); return const_cast< Element* >( &this->elements[index] );
} }
std::vector< Element > elements; ElementsVector elements;
uint dimension; uint dimension;
@ -230,7 +236,7 @@ uint QskLinearLayoutEngine::dimension() const
int QskLinearLayoutEngine::count() const int QskLinearLayoutEngine::count() const
{ {
return m_data->elements.size(); return m_data->elements.count();
} }
bool QskLinearLayoutEngine::setStretchFactorAt( int index, int stretchFactor ) bool QskLinearLayoutEngine::setStretchFactorAt( int index, int stretchFactor )
@ -266,7 +272,7 @@ int QskLinearLayoutEngine::insertItem( QQuickItem* item, int index )
if ( index < 0 || index > count() ) if ( index < 0 || index > count() )
{ {
index = elements.size(); index = elements.count();
elements.emplace_back( item ); elements.emplace_back( item );
} }
else else
@ -286,7 +292,7 @@ int QskLinearLayoutEngine::insertSpacerAt( int index, qreal spacing )
if ( index < 0 || index > count() ) if ( index < 0 || index > count() )
{ {
index = elements.size(); index = elements.count();
elements.emplace_back( spacing ); elements.emplace_back( spacing );
} }
else else
@ -416,7 +422,7 @@ int QskLinearLayoutEngine::effectiveCount() const
} }
} }
return m_data->elements.size() - m_data->sumIgnored; return m_data->elements.count() - m_data->sumIgnored;
} }
void QskLinearLayoutEngine::invalidateElementCache() void QskLinearLayoutEngine::invalidateElementCache()