1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-18 20:04:00 +02:00

Cache height as sizehint is called plenty often

This commit is contained in:
Leo Franchi
2012-02-25 20:13:12 -05:00
parent a73d1cd342
commit 7668f04c0c
3 changed files with 9 additions and 2 deletions

View File

@@ -40,6 +40,7 @@ JobStatusView* JobStatusView::s_instance = 0;
JobStatusView::JobStatusView( AnimatedSplitter* parent ) JobStatusView::JobStatusView( AnimatedSplitter* parent )
: AnimatedWidget( parent ) : AnimatedWidget( parent )
, m_parent( parent ) , m_parent( parent )
, m_cachedHeight( -1 )
{ {
s_instance = this; s_instance = this;
@@ -84,12 +85,14 @@ JobStatusView::setModel( JobStatusModel* m )
connect( m_view->model(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( checkCount() ) ); connect( m_view->model(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( checkCount() ) );
connect( m_view->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( checkCount() ) ); connect( m_view->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( checkCount() ) );
connect( m_view->model(), SIGNAL( modelReset() ), this, SLOT( checkCount() ) );
} }
void void
JobStatusView::checkCount() JobStatusView::checkCount()
{ {
m_cachedHeight = -1;
if ( m_view->model()->rowCount() == 0 && !isHidden() ) if ( m_view->model()->rowCount() == 0 && !isHidden() )
emit hideWidget(); emit hideWidget();
else else
@@ -100,8 +103,10 @@ JobStatusView::checkCount()
QSize QSize
JobStatusView::sizeHint() const JobStatusView::sizeHint() const
{ {
if ( m_cachedHeight >= 0 )
return QSize( 0, m_cachedHeight );
unsigned int y = 0; unsigned int y = 0;
// y += m_tree->header()->height();
y += m_view->contentsMargins().top() + m_view->contentsMargins().bottom(); y += m_view->contentsMargins().top() + m_view->contentsMargins().bottom();
if ( m_view->model()->rowCount() ) if ( m_view->model()->rowCount() )
@@ -113,5 +118,6 @@ JobStatusView::sizeHint() const
y += 2; // some padding y += 2; // some padding
} }
m_cachedHeight = y;
return QSize( 0, y ); return QSize( 0, y );
} }

View File

@@ -56,6 +56,7 @@ private:
QListView* m_view; QListView* m_view;
JobStatusModel* m_model; JobStatusModel* m_model;
AnimatedSplitter* m_parent; AnimatedSplitter* m_parent;
mutable int m_cachedHeight;
static JobStatusView* s_instance; static JobStatusView* s_instance;
}; };

View File

@@ -24,7 +24,7 @@
#include "query.h" #include "query.h"
#include "jobview/ErrorStatusMessage.h" #include "jobview/ErrorStatusMessage.h"
#include "jobview/JobStatusModel.h" #include "jobview/JobStatusModel.h"
#include "jobview/JobStatusView.h"= #include "jobview/JobStatusView.h"
#include <qjson/parser.h> #include <qjson/parser.h>