Commit a92af8a2 authored by Dennis Nienhüser's avatar Dennis Nienhüser
Browse files

Avoid the costly full model traversal for label height determination

Start with a sane default value and adjust it lazily during rendering.
Leads to a vast performance improvement when the tree model changes
frequently (vector tiles)
parent 51745620
......@@ -167,7 +167,7 @@ PlacemarkLayout::PlacemarkLayout( QAbstractItemModel *placemarkModel,
m_showLandingSites( false ),
m_showCraters( false ),
m_showMaria( false ),
m_maxLabelHeight( 0 ),
m_maxLabelHeight(maxLabelHeight()),
m_styleResetRequested( true )
{
Q_ASSERT(m_placemarkModel);
......@@ -262,22 +262,8 @@ QVector<const GeoDataFeature*> PlacemarkLayout::whichPlacemarkAt( const QPoint&
int PlacemarkLayout::maxLabelHeight() const
{
int maxLabelHeight = 0;
for ( int i = 0; i < m_placemarkModel->rowCount(); ++i ) {
QModelIndex index = m_placemarkModel->index( i, 0 );
const GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>(qvariant_cast<GeoDataObject*>(index.data( MarblePlacemarkModel::ObjectPointerRole ) ));
if ( placemark ) {
GeoDataStyle::ConstPtr style = placemark->style();
QFont labelFont = style->labelStyle().scaledFont();
int textHeight = QFontMetrics( labelFont ).height();
if ( textHeight > maxLabelHeight )
maxLabelHeight = textHeight;
}
}
//mDebug() <<"Detected maxLabelHeight: " << maxLabelHeight;
return maxLabelHeight;
QFont const standardFont(QStringLiteral("Arial"));
return QFontMetrics(standardFont).height();
}
/// feed an internal QMap of placemarks with TileId as key when model changes
......@@ -611,6 +597,7 @@ bool PlacemarkLayout::layoutPlacemark( const GeoDataPlacemark *placemark, qreal
m_paintOrder.append( mark );
m_labelArea += labelRect.width() * labelRect.height();
m_maxLabelHeight = qMax(m_maxLabelHeight, qCeil(labelRect.height()));
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment