PDA

View Full Version : How to inform a QTableView about changes in the underlying QAbstractTablemodel?



olidem
2nd May 2009, 13:46
Hi!

I'm developing a customer library. I have a model and a view class:



class CustomerLibrary : public QAbstractTableModel
{
//...
public slots:
void setSeachString (const QString & str){
_vec_restricted.clear();
foreach(Customer * c, _vec_all)
if(c->contains(str)) _vec_restricted.append(c);
}
private:
QVector<Customer*> _vec_all;
QVector<Customer*> _vec_restricted;
}
class CustomerTableView : public QTableView
{
//...
}

Ok, in order to find quickly an entry, I have a LineEdit whose textChanged signal is connected to the setSearchString(...) method.

So anytime the text changes, drastic changes happen to my model.

How can I inform the view that an update is necessary?
Also I do not want to remove the rows one by one.

Thnaks in advance,
Olli

faldzip
2nd May 2009, 18:18
take a look at QAbstractItemModel::dataChanged() signal or maybe in your case QAbstractItemModel::reset() method would be better.

olidem
5th May 2009, 13:27
Hi!

Thanks for your reply.
The questio I have is on what data the dataChanged signal refers.
Lots of "rows" in my library can disappear and lots can appear.

Eg if I had all entries before and now select only those containing the letter S, what shall I signal then? A dataChanged on all non-S-entires?

faldzip
5th May 2009, 14:37
if you insert rows or remove them there are signals for that: QAbstractItemModel::rowsInserted() and QAbstractItemModel::rowsRemoved(). And when you are for example inserting rows then you are emmiting rowsAboutToBeInserted then isert them and then emit rowsInserted. Please refer to Qt Examples & Demos and Qt Assistant, where whole item's change, insertion an removal is expalind clear.

olidem
6th May 2009, 08:18
Thank you for your replies so far.

I have (temporarily) solved the problem for now by simply calling QAbstractTabelModel::reset(). I will have to come back to this problem eventually later when dealing with more than a only few example customer datas.

Thank you all!