Factor out text building for label view items for proper sizeHint.

main
Teo Mrnjavac 9 years ago
parent 0be736acf7
commit 0af434bfc1

@ -136,21 +136,9 @@ PartitionLabelsView::getIndexesToDraw( const QModelIndex& parent ) const
}
void
PartitionLabelsView::drawLabels( QPainter* painter,
const QRect& rect,
const QModelIndex& parent )
QStringList
PartitionLabelsView::buildTexts( const QModelIndex& index ) const
{
PartitionModel* modl = qobject_cast< PartitionModel* >( model() );
if ( !modl )
return;
QModelIndexList indexesToDraw = getIndexesToDraw( parent );
int label_x = rect.x();
int label_y = rect.y();
foreach ( const QModelIndex& index, indexesToDraw )
{
QString firstLine, secondLine;
if ( index.data( PartitionModel::IsPartitionNewRole ).toBool() )
@ -189,8 +177,26 @@ PartitionLabelsView::drawLabels( QPainter* painter,
PartitionModel::FileSystemColumn )
.data().toString() );
QStringList texts = { firstLine,
secondLine };
return { firstLine, secondLine };
}
void
PartitionLabelsView::drawLabels( QPainter* painter,
const QRect& rect,
const QModelIndex& parent )
{
PartitionModel* modl = qobject_cast< PartitionModel* >( model() );
if ( !modl )
return;
QModelIndexList indexesToDraw = getIndexesToDraw( parent );
int label_x = rect.x();
int label_y = rect.y();
foreach ( const QModelIndex& index, indexesToDraw )
{
QStringList texts = buildTexts( index );
QSize labelSize = sizeForLabel( texts );
@ -231,10 +237,8 @@ PartitionLabelsView::sizeForAllLabels( int maxLineWidth ) const
int singleLabelHeight = 0;
foreach ( const QModelIndex& index, indexesToDraw )
{
QStringList texts = { index.data().toString(),
index.sibling( index.row(),
PartitionModel::SizeColumn )
.data().toString() };
QStringList texts = buildTexts( index );
QSize labelSize = sizeForLabel( texts );
if ( lineLength + labelSize.width() > maxLineWidth )

@ -66,6 +66,7 @@ private:
QSize sizeForLabel( const QStringList& text ) const;
void drawLabel( QPainter* painter, const QStringList& text, const QColor& color, const QPoint& pos );
QModelIndexList getIndexesToDraw( const QModelIndex& parent ) const;
QStringList buildTexts( const QModelIndex& index ) const;
};
#endif // PARTITIONLABELSVIEW_H

Loading…
Cancel
Save