Qt-interest Archive, June 2007
How to update/refresh a treeview when its domDocuemnt is modified?
Message 1 in thread
Hello,
I am playing DomItem, DomModel and a QTreeView, just like Qt’s
examples\itemviews\simpledommodel.
A little bit more what I did was a tiny change on the domDocument (for
example, modify a text on a leaf)
I wish the view can be notified somehow, so that it displays the changed
model.
I had tried update() and repaint(), none of them works.
If I drag the windows(resize()) I can see the change appears without do
anything .
Can anyone tell me how to update/refresh the tree view after the
domDocument is modified?
What has been done in the examples\itemviews\simpledommodel is
DomModel *newModel = new DomModel(newDomDocument, this);
view->setModel(newModel);
delete model;
model = newModel;
It works, but it is too expansive for a tiny change on DomDocument and
parsing the whole DOM, and creating a new model to setting a new mode
for the view.
I will be happy if I can use QAbstractItemModel::dataChanged() signal,
but I don’t know to find the corresponding index.
Thanks in advance,
Lingfa
--
[ signature omitted ]
Message 2 in thread
hi,
don't know if it's the same context but...
If you know the row....
/******************************************************************************
* datachange.
* call this function when out mvc entity modify the value of item of model.
*
* @param pRow the modified model data row (data column is 1)
*
******************************************************************************/
void MyQAttributeModel::dataChange(int pRow)
{
//get an index for row and topleft and bottom right indexes
QModelIndex lIndex = index(pRow, 1);
QModelIndex lLeft = index(pRow, 0);
QModelIndex lRight = index(pRow, columnCount() - 1);
//emit a signal to inform model that the data changed inside this
range of indexes
//this to produce a view update effect
emit dataChanged(lLeft, lRight);
}
Lingfa Yang a écrit :
> Hello,
>
> I am playing DomItem, DomModel and a QTreeView, just like Qt’s
> examples\itemviews\simpledommodel.
>
> A little bit more what I did was a tiny change on the domDocument (for
> example, modify a text on a leaf)
> I wish the view can be notified somehow, so that it displays the
> changed model.
>
> I had tried update() and repaint(), none of them works.
>
> If I drag the windows(resize()) I can see the change appears without
> do anything .
>
> Can anyone tell me how to update/refresh the tree view after the
> domDocument is modified?
>
> What has been done in the examples\itemviews\simpledommodel is
>
> DomModel *newModel = new DomModel(newDomDocument, this);
> view->setModel(newModel);
> delete model;
> model = newModel;
>
> It works, but it is too expansive for a tiny change on DomDocument and
> parsing the whole DOM, and creating a new model to setting a new mode
> for the view.
>
> I will be happy if I can use QAbstractItemModel::dataChanged() signal,
> but I don’t know to find the corresponding index.
>
> Thanks in advance,
> Lingfa
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 3 in thread
veronique.lefrere@xxxxxx wrote:
> hi,
> don't know if it's the same context but...
>
> If you know the row....
> /******************************************************************************
>
> * datachange.
> * call this function when out mvc entity modify the value of item of
> model.
> *
> * @param pRow the modified model data row (data column is 1)
> *
> ******************************************************************************/
>
> void MyQAttributeModel::dataChange(int pRow)
> { //get an index for row and topleft and bottom right
> indexes
> QModelIndex lIndex = index(pRow, 1);
> QModelIndex lLeft = index(pRow, 0);
> QModelIndex lRight = index(pRow, columnCount() - 1);
> //emit a signal to inform model that the data changed inside this
> range of indexes
> //this to produce a view update effect
> emit dataChanged(lLeft, lRight);
> }
>
1) I do know the row number, but problem is your dataChange() takes an
integer, but mines takes QModelIndex.
void QAbstractItemModel::dataChanged ( const QModelIndex & topLeft,
const QModelIndex & bottomRight )
2) I have to pass a parent so that it will create a QModelIndex.
QModelIndex PropertyModel::index(int row, int col, const QModelIndex
&parent)const
I do know the node, but I don't know its QModelIndex.
--
[ signature omitted ]
Message 4 in thread
On 18.06.07 15:04:32, Lingfa Yang wrote:
> veronique.lefrere@xxxxxx wrote:
>
> >hi,
> >don't know if it's the same context but...
> >
> >If you know the row....
> >/******************************************************************************
> >* datachange.
> >* call this function when out mvc entity modify the value of item of model.
> >*
> >* @param pRow the modified model data row (data column is 1)
> >*
> >******************************************************************************/
> >void MyQAttributeModel::dataChange(int pRow)
> >{ //get an index for row and topleft and bottom right indexes
> > QModelIndex lIndex = index(pRow, 1);
> > QModelIndex lLeft = index(pRow, 0);
> > QModelIndex lRight = index(pRow, columnCount() - 1);
> > //emit a signal to inform model that the data changed inside this range of
> >indexes
> > //this to produce a view update effect
> > emit dataChanged(lLeft, lRight);
> >}
> >
> 1) I do know the row number, but problem is your dataChange() takes an integer,
> but mines takes QModelIndex.
So you have a QModelIndex for the row that changed? Then it shouldn't be
a problem, just emit dataChanged( index(changedIdx.parent(),
changedIdx.row(), 0), index(changedIdx.parent(), changedIdx.row(), 1) )
(If you have more than 2 columns you need to adjust the second index
call - obviously)
Andreas
--
[ signature omitted ]
Message 5 in thread
Lingfa Yang a écrit :
> veronique.lefrere@xxxxxx wrote:
>
>> hi,
>> don't know if it's the same context but...
>>
>> If you know the row....
>> /******************************************************************************
>>
>> * datachange.
>> * call this function when out mvc entity modify the value of item of
>> model.
>> *
>> * @param pRow the modified model data row (data column is 1)
>> *
>> ******************************************************************************/
>>
>> void MyQAttributeModel::dataChange(int pRow)
>> { //get an index for row and topleft and bottom
>> right indexes
>> QModelIndex lIndex = index(pRow, 1);
>> QModelIndex lLeft = index(pRow, 0);
>> QModelIndex lRight = index(pRow, columnCount() - 1);
>> //emit a signal to inform model that the data changed inside this
>> range of indexes
>> //this to produce a view update effect
>> emit dataChanged(lLeft, lRight);
>> }
>>
> 1) I do know the row number, but problem is your dataChange() takes an
> integer, but mines takes QModelIndex.
> void QAbstractItemModel::dataChanged ( const QModelIndex & topLeft,
> const QModelIndex & bottomRight )
the datachange (not the datachanged) is a function I added in my model.
this function emit the datachanged signal of qabstractitemmodel and
before get the qmodelindex with int row parameter of my function
>
> 2) I have to pass a parent so that it will create a QModelIndex.
> QModelIndex PropertyModel::index(int row, int col, const QModelIndex
> &parent)const
> I do know the node, but I don't know its QModelIndex.
>
I don't know too but call index to generate one.
QModelIndex lIndex = index(pRow, 1);
QModelIndex lLeft = index(pRow, 0);
QModelIndex lRight = index(pRow, columnCount() - 1);
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 6 in thread
On 18.06.07 11:33:31, Lingfa Yang wrote:
> Hello,
>
> I am playing DomItem, DomModel and a QTreeView, just like Qtâs
> examples\itemviews\simpledommodel.
>
> A little bit more what I did was a tiny change on the domDocument (for example,
> modify a text on a leaf)
> I wish the view can be notified somehow, so that it displays the changed model.
>
> I had tried update() and repaint(), none of them works.
>
> If I drag the windows(resize()) I can see the change appears without do
> anything .
>
> Can anyone tell me how to update/refresh the tree view after the domDocument is
> modified?
You're looking for the QAbstractItemModel documentation, there's a
signal that the model should emit when its data changed (as opposed to a
structural change, like adding/removing a row/column).
Andreas
--
[ signature omitted ]