Better way to compute items in nested/non-nested partitions mode.

main
Teo Mrnjavac 9 years ago
parent d2600bc5dc
commit 3d5753e97c

@ -225,10 +225,10 @@ PartitionBarsView::drawPartitions( QPainter* painter, const QRect& rect, const Q
// Make sure we fill the last pixel column // Make sure we fill the last pixel column
width = rect.right() - x + 1; width = rect.right() - x + 1;
if ( m_nestedPartitionsMode == DrawNestedPartitions )
{
drawSection( painter, rect, x, width, item.index ); drawSection( painter, rect, x, width, item.index );
if ( modl->hasChildren( item.index ) )
if ( m_nestedPartitionsMode == DrawNestedPartitions &&
modl->hasChildren( item.index ) )
{ {
QRect subRect( QRect subRect(
x + EXTENDED_PARTITION_MARGIN, x + EXTENDED_PARTITION_MARGIN,
@ -238,22 +238,6 @@ PartitionBarsView::drawPartitions( QPainter* painter, const QRect& rect, const Q
); );
drawPartitions( painter, subRect, item.index ); drawPartitions( painter, subRect, item.index );
} }
}
else
{
if ( modl->hasChildren( item.index ) )
{
QRect subRect(
x,
rect.y(),
width,
rect.height()
);
drawPartitions( painter, subRect, item.index );
}
else
drawSection( painter, rect, x, width, item.index );
}
x += width; x += width;
} }
@ -301,23 +285,15 @@ PartitionBarsView::indexAt( const QPoint &point,
QRect thisItemRect( x, rect.y(), width, rect.height() ); QRect thisItemRect( x, rect.y(), width, rect.height() );
if ( thisItemRect.contains( point ) ) if ( thisItemRect.contains( point ) )
{ {
if ( modl->hasChildren( item.index ) ) if ( m_nestedPartitionsMode == DrawNestedPartitions &&
modl->hasChildren( item.index ) )
{ {
QRect subRect; QRect subRect(
if ( m_nestedPartitionsMode == DrawNestedPartitions )
subRect = QRect(
x + EXTENDED_PARTITION_MARGIN, x + EXTENDED_PARTITION_MARGIN,
rect.y() + EXTENDED_PARTITION_MARGIN, rect.y() + EXTENDED_PARTITION_MARGIN,
width - 2 * EXTENDED_PARTITION_MARGIN, width - 2 * EXTENDED_PARTITION_MARGIN,
rect.height() - 2 * EXTENDED_PARTITION_MARGIN rect.height() - 2 * EXTENDED_PARTITION_MARGIN
); );
else
subRect = QRect(
x,
rect.y(),
width,
rect.height()
);
if ( subRect.contains( point ) ) if ( subRect.contains( point ) )
{ {
@ -373,24 +349,16 @@ PartitionBarsView::visualRect( const QModelIndex& index,
if ( item.index == index ) if ( item.index == index )
return thisItemRect; return thisItemRect;
if ( modl->hasChildren( item.index ) && if ( m_nestedPartitionsMode == DrawNestedPartitions &&
modl->hasChildren( item.index ) &&
index.parent() == item.index ) index.parent() == item.index )
{ {
QRect subRect; QRect subRect(
if ( m_nestedPartitionsMode == DrawNestedPartitions )
subRect = QRect(
x + EXTENDED_PARTITION_MARGIN, x + EXTENDED_PARTITION_MARGIN,
rect.y() + EXTENDED_PARTITION_MARGIN, rect.y() + EXTENDED_PARTITION_MARGIN,
width - 2 * EXTENDED_PARTITION_MARGIN, width - 2 * EXTENDED_PARTITION_MARGIN,
rect.height() - 2 * EXTENDED_PARTITION_MARGIN rect.height() - 2 * EXTENDED_PARTITION_MARGIN
); );
else
subRect = QRect(
x,
rect.y(),
width,
rect.height()
);
QRect candidateVisualRect = visualRect( index, subRect, item.index ); QRect candidateVisualRect = visualRect( index, subRect, item.index );
if ( !candidateVisualRect.isNull() ) if ( !candidateVisualRect.isNull() )
@ -545,18 +513,31 @@ PartitionBarsView::updateGeometries()
QPair< QVector< PartitionBarsView::Item >, qreal > QPair< QVector< PartitionBarsView::Item >, qreal >
PartitionBarsView::computeItemsVector( const QModelIndex& parent ) const PartitionBarsView::computeItemsVector( const QModelIndex& parent ) const
{ {
const int count = model()->rowCount( parent ); int count = model()->rowCount( parent );
QVector< PartitionBarsView::Item > items( count ); QVector< PartitionBarsView::Item > items;
qreal total = 0; qreal total = 0;
for ( int row = 0; row < count; ++row ) for ( int row = 0; row < count; ++row )
{ {
QModelIndex index = model()->index( row, 0, parent ); QModelIndex index = model()->index( row, 0, parent );
if ( m_nestedPartitionsMode == NoNestedPartitions &&
model()->hasChildren( index ) )
{
QPair< QVector< PartitionBarsView::Item >, qreal > childVect =
computeItemsVector( index );
items += childVect.first;
total += childVect.second;
}
else
{
qreal size = index.data( PartitionModel::SizeRole ).toLongLong(); qreal size = index.data( PartitionModel::SizeRole ).toLongLong();
total += size; total += size;
items[ row ] = { size, index }; items.append( { size, index } );
}
} }
count = items.count();
// The sizes we have are perfect, but now we have to hardcode a minimum size for small // The sizes we have are perfect, but now we have to hardcode a minimum size for small
// partitions and compensate for it in the total. // partitions and compensate for it in the total.
qreal adjustedTotal = total; qreal adjustedTotal = total;

Loading…
Cancel
Save