Commit 3ae42e74 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt, selector: don't rebuild the model when not necessary...

This should fix the build-twice-the-model issue and should avoid
rebuilding when clicking the already selected one.
Rebuilding the model is costly enough in time, to not do it all the
time.
parent 7e1526b9
......@@ -129,16 +129,18 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf )
this, inputItemUpdate( input_item_t * ) );
createItems();
/***
* We need to react to both clicks and activation (enter-key) here.
* We use curItem to avoid rebuilding twice.
* See QStyle::SH_ItemView_ActivateItemOnSingleClick
***/
curItem = NULL;
CONNECT( this, itemActivated( QTreeWidgetItem *, int ),
this, setSource( QTreeWidgetItem *) );
CONNECT( this, itemClicked( QTreeWidgetItem *, int ),
this, setSource( QTreeWidgetItem *) );
/* I believe this is unnecessary, seeing
QStyle::SH_ItemView_ActivateItemOnSingleClick
CONNECT( view, itemClicked( QTreeWidgetItem *, int ),
this, setSource( QTreeWidgetItem *) ); */
/* select the first item */
// view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) );
......@@ -258,9 +260,11 @@ void PLSelector::createItems()
void PLSelector::setSource( QTreeWidgetItem *item )
{
if( !item )
if( !item || item == curItem )
return;
curItem = item;
bool b_ok;
int i_type = item->data( 0, TYPE_ROLE ).toInt( &b_ok );
if( !b_ok || i_type == CATEGORY_TYPE )
......
......@@ -135,6 +135,7 @@ private:
intf_thread_t *p_intf;
QTreeWidgetItem *podcastsParent;
int podcastsParentId;
QTreeWidgetItem *curItem;
private slots:
void setSource( QTreeWidgetItem *item );
......
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