[partition] Remove unnecessary methods
- _find and _each Doesn't need to be part of the class API - Rename to *Transform() because that's more in-line with what it does, applying an operation to the tree.
This commit is contained in:
parent
9b0ef5fce5
commit
f64938cb3f
@ -35,6 +35,48 @@ static const int VIEW_HEIGHT
|
|||||||
static const int CORNER_RADIUS = 3;
|
static const int CORNER_RADIUS = 3;
|
||||||
static const int EXTENDED_PARTITION_MARGIN = qMax( 4, VIEW_HEIGHT / 6 );
|
static const int EXTENDED_PARTITION_MARGIN = qMax( 4, VIEW_HEIGHT / 6 );
|
||||||
|
|
||||||
|
/** @brief Applies @p operation to each item
|
||||||
|
*
|
||||||
|
* A PartitionSplitterItem can contain a tree of items (each item has its
|
||||||
|
* own list of children) so recurse over all the children. Returns a count
|
||||||
|
* of how many items were affected.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
countTransform( QVector< PartitionSplitterItem >& items,
|
||||||
|
const std::function< bool( PartitionSplitterItem& ) >& operation )
|
||||||
|
{
|
||||||
|
int opCount = 0;
|
||||||
|
for ( auto it = items.begin(); it != items.end(); ++it )
|
||||||
|
{
|
||||||
|
if ( operation( *it ) )
|
||||||
|
{
|
||||||
|
opCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
opCount += countTransform( it->children, operation );
|
||||||
|
}
|
||||||
|
return opCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PartitionSplitterItem
|
||||||
|
findTransform( QVector< PartitionSplitterItem >& items, std::function< bool( PartitionSplitterItem& ) > condition )
|
||||||
|
{
|
||||||
|
for ( auto it = items.begin(); it != items.end(); ++it )
|
||||||
|
{
|
||||||
|
if ( condition( *it ) )
|
||||||
|
{
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
|
||||||
|
PartitionSplitterItem candidate = findTransform( it->children, condition );
|
||||||
|
if ( !candidate.isNull() )
|
||||||
|
{
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PartitionSplitterItem::null();
|
||||||
|
}
|
||||||
|
|
||||||
PartitionSplitterWidget::PartitionSplitterWidget( QWidget* parent )
|
PartitionSplitterWidget::PartitionSplitterWidget( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, m_itemToResize( PartitionSplitterItem::null() )
|
, m_itemToResize( PartitionSplitterItem::null() )
|
||||||
@ -159,16 +201,16 @@ PartitionSplitterWidget::setSplitPartition( const QString& path, qint64 minSize,
|
|||||||
m_itemToResizePath.clear();
|
m_itemToResizePath.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionSplitterItem itemToResize = _findItem( m_items,
|
PartitionSplitterItem itemToResize = findTransform( m_items,
|
||||||
[ path ]( PartitionSplitterItem& item ) -> bool
|
[ path ]( PartitionSplitterItem& item ) -> bool
|
||||||
{
|
|
||||||
if ( path == item.itemPath )
|
|
||||||
{
|
{
|
||||||
item.status = PartitionSplitterItem::Resizing;
|
if ( path == item.itemPath )
|
||||||
return true;
|
{
|
||||||
}
|
item.status = PartitionSplitterItem::Resizing;
|
||||||
return false;
|
return true;
|
||||||
} );
|
}
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
|
|
||||||
if ( itemToResize.isNull() )
|
if ( itemToResize.isNull() )
|
||||||
{
|
{
|
||||||
@ -186,16 +228,16 @@ PartitionSplitterWidget::setSplitPartition( const QString& path, qint64 minSize,
|
|||||||
|
|
||||||
qint64 newSize = m_itemToResize.size - preferredSize;
|
qint64 newSize = m_itemToResize.size - preferredSize;
|
||||||
m_itemToResize.size = preferredSize;
|
m_itemToResize.size = preferredSize;
|
||||||
int opCount = _eachItem( m_items,
|
int opCount = countTransform( m_items,
|
||||||
[ preferredSize ]( PartitionSplitterItem& item ) -> bool
|
[ preferredSize ]( PartitionSplitterItem& item ) -> bool
|
||||||
{
|
{
|
||||||
if ( item.status == PartitionSplitterItem::Resizing )
|
if ( item.status == PartitionSplitterItem::Resizing )
|
||||||
{
|
{
|
||||||
item.size = preferredSize;
|
item.size = preferredSize;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} );
|
} );
|
||||||
cDebug() << "each splitter item opcount:" << opCount;
|
cDebug() << "each splitter item opcount:" << opCount;
|
||||||
m_itemMinSize = minSize;
|
m_itemMinSize = minSize;
|
||||||
m_itemMaxSize = maxSize;
|
m_itemMaxSize = maxSize;
|
||||||
@ -362,21 +404,21 @@ PartitionSplitterWidget::mouseMoveEvent( QMouseEvent* event )
|
|||||||
|
|
||||||
m_itemToResize.size = qRound64( span * percent );
|
m_itemToResize.size = qRound64( span * percent );
|
||||||
m_itemToResizeNext.size -= m_itemToResize.size - oldsize;
|
m_itemToResizeNext.size -= m_itemToResize.size - oldsize;
|
||||||
_eachItem( m_items,
|
countTransform( m_items,
|
||||||
[ this ]( PartitionSplitterItem& item ) -> bool
|
[ this ]( PartitionSplitterItem& item ) -> bool
|
||||||
{
|
{
|
||||||
if ( item.status == PartitionSplitterItem::Resizing )
|
if ( item.status == PartitionSplitterItem::Resizing )
|
||||||
{
|
{
|
||||||
item.size = m_itemToResize.size;
|
item.size = m_itemToResize.size;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if ( item.status == PartitionSplitterItem::ResizingNext )
|
else if ( item.status == PartitionSplitterItem::ResizingNext )
|
||||||
{
|
{
|
||||||
item.size = m_itemToResizeNext.size;
|
item.size = m_itemToResizeNext.size;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
|
|
||||||
@ -553,46 +595,6 @@ PartitionSplitterWidget::drawPartitions( QPainter* painter,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PartitionSplitterItem
|
|
||||||
PartitionSplitterWidget::_findItem( QVector< PartitionSplitterItem >& items,
|
|
||||||
std::function< bool( PartitionSplitterItem& ) > condition ) const
|
|
||||||
{
|
|
||||||
for ( auto it = items.begin(); it != items.end(); ++it )
|
|
||||||
{
|
|
||||||
if ( condition( *it ) )
|
|
||||||
{
|
|
||||||
return *it;
|
|
||||||
}
|
|
||||||
|
|
||||||
PartitionSplitterItem candidate = _findItem( it->children, condition );
|
|
||||||
if ( !candidate.isNull() )
|
|
||||||
{
|
|
||||||
return candidate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PartitionSplitterItem::null();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
PartitionSplitterWidget::_eachItem( QVector< PartitionSplitterItem >& items,
|
|
||||||
std::function< bool( PartitionSplitterItem& ) > operation ) const
|
|
||||||
{
|
|
||||||
int opCount = 0;
|
|
||||||
for ( auto it = items.begin(); it != items.end(); ++it )
|
|
||||||
{
|
|
||||||
if ( operation( *it ) )
|
|
||||||
{
|
|
||||||
opCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
opCount += _eachItem( it->children, operation );
|
|
||||||
}
|
|
||||||
return opCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QPair< QVector< PartitionSplitterItem >, qreal >
|
QPair< QVector< PartitionSplitterItem >, qreal >
|
||||||
PartitionSplitterWidget::computeItemsVector( const QVector< PartitionSplitterItem >& originalItems ) const
|
PartitionSplitterWidget::computeItemsVector( const QVector< PartitionSplitterItem >& originalItems ) const
|
||||||
{
|
{
|
||||||
|
@ -72,12 +72,6 @@ private:
|
|||||||
void drawSection( QPainter* painter, const QRect& rect_, int x, int width, const PartitionSplitterItem& item );
|
void drawSection( QPainter* painter, const QRect& rect_, int x, int width, const PartitionSplitterItem& item );
|
||||||
void drawResizeHandle( QPainter* painter, const QRect& rect_, int x );
|
void drawResizeHandle( QPainter* painter, const QRect& rect_, int x );
|
||||||
|
|
||||||
PartitionSplitterItem _findItem( QVector< PartitionSplitterItem >& items,
|
|
||||||
std::function< bool( PartitionSplitterItem& ) > condition ) const;
|
|
||||||
|
|
||||||
int _eachItem( QVector< PartitionSplitterItem >& items,
|
|
||||||
std::function< bool( PartitionSplitterItem& ) > operation ) const;
|
|
||||||
|
|
||||||
QPair< QVector< PartitionSplitterItem >, qreal >
|
QPair< QVector< PartitionSplitterItem >, qreal >
|
||||||
computeItemsVector( const QVector< PartitionSplitterItem >& originalItems ) const;
|
computeItemsVector( const QVector< PartitionSplitterItem >& originalItems ) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user