Re: moving QListViewItems
But what exactly? You have only shown a snippet (not complete one) of a code that does something.
Re: moving QListViewItems
It sounds like you are never exiting your loop. I would put a break in there to make sure your exit condition is met.
Re: moving QListViewItems
actually the full code is too long and the two classes are in separate files so I was trying to just explain the scenario..
here is the myItem class with the bool function ..
Quote:
class myItem : public QListViewItem
{
myItem(QListViewItem *parent,QString label);
bool myBoolFunction();
};
bool myItem::myBoolFunction()
{
if(Flag)
return true;
else
return false;
}
now all I want to do is for each listviewitem in the parentcheck whether the flag is set and is so move the item to the top to make the first child of the parent..
in doing so I would have to iterate through all the childs of the parent and check the flag of each child through myBoolFunction()...
also
Quote:
class myGroup : public QListViewItem
{
myGroup(QListView *parent,QString Label);
void adjustGroups();
}
void adjustGroups()
{
QListViewItem *item =this->firstChild();
while( item )
{
if(((myItem *)item)->isBoolFunction())
{
item->moveItem(this->firstChild());//works fine if i remove this
this->firstChild()->moveItem(item);//works fine if i remove this
count++;
}
item =item->nextSibling();
}
}
the class that adjustGroup() is in is also a QListViewItem however it has several childs..and works fine if I remove the two lines...
my guess is I am moving the item and then agian doing a item->nextSibling().... can we do this in some other way to move one or more items to the top of the list...
where would I use this ??
well in a messenger client when someone comes online then he/she is shifted to the top of its group... like in msn messenger... I am trying to do a similar thing :)
Re: moving QListViewItems
You might do it this way (it's just a concept):
Code:
QPtrList<QListViewItem> _items;
myItem *item = dynamic_cast<myItem>(this->firstChild());
while(item){
if(item->myBoolFunction()) _items.push_back(item);
item = dynamic_cast<myItem>(item->nextSibling());
}
for(QPtrList<QListViewItem>::iterator it = _items.begin(); it!=_items.end();++it){
takeItem(*it);
insertItem(*it); // or some other method like moveItem()
}
The first iteration looks for all items to move upwards, the second does the move.