[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [marble] src/lib/marble: Avoid the costly full model traversal for label height determination
From:       Dennis_Nienhüser <nienhueser () kde ! org>
Date:       2015-10-31 18:58:47
Message-ID: E1ZsbMV-0006my-MS () scm ! kde ! org
[Download RAW message or body]

Git commit a92af8a26ce0eddfde9f7902f55b744e6e6f478f by Dennis Nienhüser.
Committed on 31/10/2015 at 18:44.
Pushed by nienhueser into branch 'master'.

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)

M  +4    -17   src/lib/marble/PlacemarkLayout.cpp

http://commits.kde.org/marble/a92af8a26ce0eddfde9f7902f55b744e6e6f478f

diff --git a/src/lib/marble/PlacemarkLayout.cpp b/src/lib/marble/PlacemarkLayout.cpp
index 2f3c4e5..c238e69 100644
--- a/src/lib/marble/PlacemarkLayout.cpp
+++ b/src/lib/marble/PlacemarkLayout.cpp
@@ -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;
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic