PDA

View Full Version : Problem with Model/View



Shawn
28th August 2007, 08:20
I have parsed an XML file and got this,

class Element
{
public:
Element(const QString &type)
:ElementType(type)
{
content.clear();
}

~Element(void) {}

void addContent(const QString str);
void addSubElement(Element* element);
void addAttr(const QString attr, const QString value);
void toText(QTextStream &os, int level); //print for testing

private:
QString ElementType, content;
QList<Element*> list_subElement;
QMap<QString, QString> map_attr;
};
ElementType represents the name of the tag, content represents the value of this tag,
every element also has many attribute-value pair, which are represented by the QMap,
the child element is represented by the QList<Element*>

For this simple XML file:

<Class No.="02">
<Student No.="0215">Mike Jasen</Student>
</Class>

My Problem is:
I want to show the Element and child elements in a tree-view. If any element is clicked in this tree-view, the attribute-value pairs can be shown in the table-view. How can I implement this?
This pic is want I want, I draw it using photofiltre

jpn
28th August 2007, 08:29
How about writing a model interface around QDomDocument? I mean, with QDom* you already got a readily available XML tree representation. ;)

Shawn
28th August 2007, 08:35
How about writing a model interface around QDomDocument? I mean, with QDom* you already got a readily available XML tree representation. ;)

I start this project without any guidance. I mean when I release that DOM is better, I have already gone that far...

At the very begining I used to use lots of struct to represent the element, that's realy a disaster...

Maybe my problem exsits in how to give the value to the Model? The list member and the map member should be given to different Model?

jpn
28th August 2007, 08:55
Yes, I suppose you need two separate models because a model cannot provide different data for different views. Notice that the actual data behind the curtains is still exactly the same, both models are just interfaces for Qt's interview framework.

jpn
28th August 2007, 10:04
Oh, and by the way, there's also an example out there: Simple DOM Model Example (http://doc.trolltech.com/4.3/itemviews-simpledommodel.html)