Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, May 2007
where comes the dumb child “#text”?

Pages: Prev | 1 | 2 | Next

Message 1 in thread

In a tree like this:
<color>
    <name>#FF0000</name>
    <alpha>128</alpha>
</color>

I wish to see an expended tree view:
color......
.....name
.....alpha

Instead, I saw
color......
.....name
……….#text
.....alpha
……….#text

where comes the dumb child “#text”?

Thanks,
Lingfa

--
 [ signature omitted ] 

Message 2 in thread

Lingfa Yang wrote:
> In a tree like this:
> <color>
>    <name>#FF0000</name>
>    <alpha>128</alpha>
> </color>
> 
> I wish to see an expended tree view:
> color......
> .....name
> .....alpha
> 
> Instead, I saw
> color......
> .....name
> ……….#text
> .....alpha
> ……….#text
> 
> where comes the dumb child “#text”?

The #text indicates that your name and alpha nodes have text children; 
if you inspect their values you will see #FF0000 and 128 respectively.

Tim

--
 [ signature omitted ] 

Message 3 in thread

Tim Dewhirst wrote:

> Lingfa Yang wrote:
>
>> In a tree like this:
>> <color>
>>    <name>#FF0000</name>
>>    <alpha>128</alpha>
>> </color>
>>
>> I wish to see an expended tree view:
>> color......
>> .....name
>> .....alpha
>>
>> Instead, I saw
>> color......
>> .....name
>> ……….#text
>> .....alpha
>> ……….#text
>>
>> where comes the dumb child “#text”?
>
>
> The #text indicates that your name and alpha nodes have text children; 
> if you inspect their values you will see #FF0000 and 128 respectively.
>
> Tim
>
Tim, Thank you.
I do not want to see "#text" as a child of "name" or "alpha" in the tree 
view.
I wish to see "name" and "alpha" are two leaves (not expendable).
Do you know how to do that in tree view?
Thanks again,
Lingfa





--
 [ signature omitted ] 

Message 4 in thread

Hi,

Lingfa Yang wrote:
> I do not want to see "#text" as a child of "name" or "alpha" in the tree 
> view.
> I wish to see "name" and "alpha" are two leaves (not expendable).
> Do you know how to do that in tree view?

I may be missing something, but I think it depends on how you are 
populating your tree view. Can you post the code that is generating the 
view?

Tim

--
 [ signature omitted ] 

Message 5 in thread

Tim Dewhirst wrote:

> Hi,
>
> Lingfa Yang wrote:
>
>> I do not want to see "#text" as a child of "name" or "alpha" in the 
>> tree view.
>> I wish to see "name" and "alpha" are two leaves (not expendable).
>> Do you know how to do that in tree view?
>
>
> I may be missing something, but I think it depends on how you are 
> populating your tree view. Can you post the code that is generating 
> the view?
>
> Tim
>
Which is:
QString DomModel::firstColumnText(const QDomNode &node)const
{
    return node.nodeName();
}


--
 [ signature omitted ] 

Message 6 in thread

Lingfa Yang wrote:

> Tim Dewhirst wrote:
>
>> Hi,
>>
>> Lingfa Yang wrote:
>>
>>> I do not want to see "#text" as a child of "name" or "alpha" in the 
>>> tree view.
>>> I wish to see "name" and "alpha" are two leaves (not expendable).
>>> Do you know how to do that in tree view?
>>
>>
>>
>> I may be missing something, but I think it depends on how you are 
>> populating your tree view. Can you post the code that is generating 
>> the view?
>>
>> Tim
>>
> Which is:
> QString DomModel::firstColumnText(const QDomNode &node)const
> {
>    return node.nodeName();
> }
>
Also you may need this:
QVariant DomModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()) return QVariant();
    if (role != Qt::DisplayRole) return QVariant();

    DomItem *item = static_cast<DomItem*>(index.internalPointer());
    const QDomNode node = item->node();
    switch (index.column())
    {
    case 0: return firstColumnText(node);
    case 1: return secondColumnText(node);
    case 2:    return thirdColumnText(node);
    default: return QVariant();
    }
}

--
 [ signature omitted ] 

Message 7 in thread

On Wednesday 30 May 2007, Lingfa Yang wrote:
> Lingfa Yang wrote:
> > Tim Dewhirst wrote:
> >> Hi,
> >>
> >> Lingfa Yang wrote:
> >>> I do not want to see "#text" as a child of "name" or "alpha" in the
> >>> tree view.
> >>> I wish to see "name" and "alpha" are two leaves (not expendable).
> >>> Do you know how to do that in tree view?
> >>
> >> I may be missing something, but I think it depends on how you are
> >> populating your tree view. Can you post the code that is generating
> >> the view?
> >>
> >> Tim
> >
> > Which is:
> > QString DomModel::firstColumnText(const QDomNode &node)const
> > {
> >    return node.nodeName();
> > }
>
> Also you may need this:
> QVariant DomModel::data(const QModelIndex &index, int role) const
> {
>     if (!index.isValid()) return QVariant();
>     if (role != Qt::DisplayRole) return QVariant();
>
>     DomItem *item = static_cast<DomItem*>(index.internalPointer());
>     const QDomNode node = item->node();
>     switch (index.column())
>     {
>     case 0: return firstColumnText(node);
>     case 1: return secondColumnText(node);
>     case 2:    return thirdColumnText(node);
>     default: return QVariant();
>     }
> }

Then you don't want to see the nodes, you want to see the elements, i.e. 
the nodes for which node.isElement() returns true. The elements are the 
items enclosed in <> in XML, a node on the other hand can be anything (the 
document, a comment, an attribute ...).

Bernd

--
 [ signature omitted ] 

Message 8 in thread

>Then you don't want to see the nodes, you want to see the elements, i.e. 
>the nodes for which node.isElement() returns true. The elements are the 
>items enclosed in <> in XML, a node on the other hand can be anything (the 
>document, a comment, an attribute ...).
>
>Bernd
>
>  
>
Yes, I can replace the "#text" by a meaningful text, for example,
    if(node.isText())
        return node.parentNode().toElement().text();

But my real question is the treeview does not display “name” or “alpha” 
as a leaf !!!
The tree view always shows “+” before "name" which means “expendable”.
Is there a way to make <name>#000000</name> not expandable?

Lingfa


--
 [ signature omitted ] 

Message 9 in thread

On 30.05.07 14:23:53, Lingfa Yang wrote:
> 
> >Then you don't want to see the nodes, you want to see the elements, i.e. the 
> >nodes for which node.isElement() returns true. The elements are the items 
> >enclosed in <> in XML, a node on the other hand can be anything (the document, 
> >a comment, an attribute ...).
> >
> >Bernd
> >
> > 
> Yes, I can replace the "#text" by a meaningful text, for example,
>    if(node.isText())
>        return node.parentNode().toElement().text();
> 
> But my real question is the treeview does not display ânameâ or âalphaâ 
> as a leaf !!!
> The tree view always shows â+â before "name" which means âexpendableâ.
> Is there a way to make <name>#000000</name> not expandable?

Sure there is, return 0 for rowCount for such indexes or false for
hasChildren, or both.

Andreas

-- 
 [ signature omitted ] 

Message 10 in thread

Andreas Pakulat wrote:

>On 30.05.07 14:23:53, Lingfa Yang wrote:
>  
>
>>>Then you don't want to see the nodes, you want to see the elements, i.e. the 
>>>nodes for which node.isElement() returns true. The elements are the items 
>>>enclosed in <> in XML, a node on the other hand can be anything (the document, 
>>>a comment, an attribute ...).
>>>
>>>Bernd
>>>
>>>
>>>      
>>>
>>Yes, I can replace the "#text" by a meaningful text, for example,
>>   if(node.isText())
>>       return node.parentNode().toElement().text();
>>
>>But my real question is the treeview does not display ânameâ or âalphaâ 
>>as a leaf !!!
>>The tree view always shows â+â before "name" which means âexpendableâ.
>>Is there a way to make <name>#000000</name> not expandable?
>>    
>>
>
>Sure there is, return 0 for rowCount for such indexes or false for
>hasChildren, or both.
>
>Andreas
>
>  
>
I have overwrote both rowCount() and hasChildren(), but can not get ride 
of the QTextNode.
Any  new  idea?
Thanks
Lingfa

int DomModel::rowCount(const QModelIndex &parent) const
{
    DomItem *parentItem;

    if (!parent.isValid())
        parentItem = rootItem;
    else
        parentItem = static_cast<DomItem*>(parent.internalPointer());

    if(parentItem->node().isText())
        return 0;  // too late to block QTextNode

    return parentItem->node().childNodes().count();
}


--
 [ signature omitted ] 

Message 11 in thread

On 30.05.07 15:18:33, Lingfa Yang wrote:
> Andreas Pakulat wrote:
> 
> >On 30.05.07 14:23:53, Lingfa Yang wrote:
> > 
> >>>Then you don't want to see the nodes, you want to see the elements, i.e. the 
> >>>nodes for which node.isElement() returns true. The elements are the items 
> >>>enclosed in <> in XML, a node on the other hand can be anything (the 
> >>>document, a comment, an attribute ...).
> >>>
> >>>Bernd
> >>>
> >>>
> >>>     
> >>Yes, I can replace the "#text" by a meaningful text, for example,
> >>  if(node.isText())
> >>      return node.parentNode().toElement().text();
> >>
> >>But my real question is the treeview does not display ânameâ or 
> >>âalphaâ as a leaf !!!
> >>The tree view always shows â+â before "name" which means 
> >>âexpendableâ.
> >>Is there a way to make <name>#000000</name> not expandable?
> >>   
> >
> >Sure there is, return 0 for rowCount for such indexes or false for
> >hasChildren, or both.
> >
> >Andreas
> >
> > 
> I have overwrote both rowCount() and hasChildren(), but can not get ride of the 
> QTextNode.
> Any  new  idea?

See the answer from Bernd Brandstetter, you need to redesign your model
to not work on nodes but on elements. I don't know the whole of your
model so I can't give any further assistance here. It seems you're
building your model based on the simpledommodel example which provides
access to the full DOM, if you don't want that you have to adjust your
model.

Andreas

-- 
 [ signature omitted ] 

Message 12 in thread

Andreas Pakulat wrote:

>On 30.05.07 15:18:33, Lingfa Yang wrote:
>  
>
>>Andreas Pakulat wrote:
>>
>>    
>>
>>>On 30.05.07 14:23:53, Lingfa Yang wrote:
>>>
>>>      
>>>
>>>>>Then you don't want to see the nodes, you want to see the elements, i.e. the 
>>>>>nodes for which node.isElement() returns true. The elements are the items 
>>>>>enclosed in <> in XML, a node on the other hand can be anything (the 
>>>>>document, a comment, an attribute ...).
>>>>>
>>>>>Bernd
>>>>>
>>>>>
>>>>>    
>>>>>          
>>>>>
>>>>Yes, I can replace the "#text" by a meaningful text, for example,
>>>> if(node.isText())
>>>>     return node.parentNode().toElement().text();
>>>>
>>>>But my real question is the treeview does not display ânameâ or 
>>>>âalphaâ as a leaf !!!
>>>>The tree view always shows â+â before "name" which means 
>>>>âexpendableâ.
>>>>Is there a way to make <name>#000000</name> not expandable?
>>>>  
>>>>        
>>>>
>>>Sure there is, return 0 for rowCount for such indexes or false for
>>>hasChildren, or both.
>>>
>>>Andreas
>>>
>>>
>>>      
>>>
>>I have overwrote both rowCount() and hasChildren(), but can not get ride of the 
>>QTextNode.
>>Any  new  idea?
>>    
>>
>
>See the answer from Bernd Brandstetter, you need to redesign your model
>to not work on nodes but on elements. I don't know the whole of your
>model so I can't give any further assistance here. It seems you're
>building your model based on the simpledommodel example which provides
>access to the full DOM, if you don't want that you have to adjust your
>model.
>
>Andreas
>
>  
>
One line of code solved the problem ( see the line with six "!" below).
Thanks everyone.
Lingfa

DomItem *DomItem::child(int i)
{
    if (childItems.contains(i))
        return childItems.value(i);

    if (i >= 0 && i < domNode.childNodes().count())
    {
        QDomNode childNode = domNode.childNodes().item(i);
        if(childNode.isText()) return 0; // block QDomText  !!!!!!
        DomItem *childItem = new DomItem(childNode, i, this);
        childItems[i] = childItem;
        return childItem;
    }
    return 0;
}

--
 [ signature omitted ] 

Message 13 in thread

On Wednesday 30 May 2007, Lingfa Yang wrote:
> >Then you don't want to see the nodes, you want to see the elements,
> > i.e. the nodes for which node.isElement() returns true. The elements
> > are the items enclosed in <> in XML, a node on the other hand can be
> > anything (the document, a comment, an attribute ...).
> >
> >Bernd
>
> Yes, I can replace the "#text" by a meaningful text, for example,
>     if(node.isText())
>         return node.parentNode().toElement().text();
>
> But my real question is the treeview does not display ?name? or ?alpha?
> as a leaf !!!
> The tree view always shows ?+? before "name" which means ?expendable?.
> Is there a way to make <name>#000000</name> not expandable?
>
> Lingfa

You don't need to replace anything if you fix your model. Currently your 
model is designed in a way that it includes all XML nodes. Instead it 
should only include the XML elements. You will have to change the model so 
that it ignores all nodes that are not elements.

Bernd

--
 [ signature omitted ] 

Message 14 in thread

Bernd Brandstetter wrote:

>On Wednesday 30 May 2007, Lingfa Yang wrote:
>  
>
>>>Then you don't want to see the nodes, you want to see the elements,
>>>i.e. the nodes for which node.isElement() returns true. The elements
>>>are the items enclosed in <> in XML, a node on the other hand can be
>>>anything (the document, a comment, an attribute ...).
>>>
>>>Bernd
>>>      
>>>
>>Yes, I can replace the "#text" by a meaningful text, for example,
>>    if(node.isText())
>>        return node.parentNode().toElement().text();
>>
>>But my real question is the treeview does not display “name” or “alpha”
>>as a leaf !!!
>>The tree view always shows “+” before "name" which means “expendable”.
>>Is there a way to make <name>#000000</name> not expandable?
>>
>>Lingfa
>>    
>>
>
>You don't need to replace anything if you fix your model. Currently your 
>model is designed in a way that it includes all XML nodes. Instead it 
>should only include the XML elements. You will have to change the model so 
>that it ignores all nodes that are not elements.
>
>Bernd
>
>  
>
I think your are right.
I am changing
 http://doc.trolltech.com/4.2/itemviews-simpledommodel.html
to rander my xml.

I saw this Qt example snapshot does show "#text" in display.
I just do not know how to get ride of it.
Can you speak in detail how to "change the model".
Thanks,
Lingfa


--
 [ signature omitted ] 

Message 15 in thread

On Wednesday 30 May 2007, Lingfa Yang wrote:
> I think your are right.
> I am changing
>  http://doc.trolltech.com/4.2/itemviews-simpledommodel.html
> to rander my xml.
>
> I saw this Qt example snapshot does show "#text" in display.
> I just do not know how to get ride of it.
> Can you speak in detail how to "change the model".
> Thanks,
> Lingfa

I've modified the simpledommodel example to only show the XML elements.
Please find attached the modified files. Not exactly elegant but it seems 
to work.

Bernd

Attachment:

Attachment: elementmodel.zip
Description: Zip archive


Pages: Prev | 1 | 2 | Next