Results 1 to 8 of 8

Thread: Adapting the "Simple DOM Model Example" to be read/write

  1. #1
    Join Date
    Aug 2008
    Location
    Iowa, USA
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Adapting the "Simple DOM Model Example" to be read/write

    The example is found in the Qt Assistant. I'm trying to use a Tree View with an XML file as my model. I tried to search through these forums to see if something like this has been talked about, but you're not allowed to search for xml and "xml" as a tag has been used four times when I was searching.

    Anyway, the example is read-only. What I'll be wanting to do is either just add comments to elements or to create brand new elements in the xml. I'm new to using Model/View stuff (I've always just used the much easier to use TreeWidget and such before), but I was wondering if someone has made an XML model that is read/write, some helpful tips/code snippets, or links to tutorials who can walk me through this problem.

    Thanks.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adapting the "Simple DOM Model Example" to be read/write

    If you want simply edit functionality, the simplest way would be to use QTextEdit and apply a syntax highlighter on it.

    but then you wont be able to expand/collapse nodes.

    Other thing you can try is setting delegate on the tree view, and edit the node. I had modeified the simple DOM model example applying delegate to it. You can refer this thread. Hope it helps you

  3. #3
    Join Date
    Aug 2008
    Location
    Iowa, USA
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adapting the "Simple DOM Model Example" to be read/write

    I don't want to just display the XML as it's read, but display it differently. Example:

    Say I have a list of bikes. Each bike has the following elements,
    1. Name
    2. Comfort Level
    3. Top Speed

    This list is pretty stupid, but it will get my point across hopefully. Instead of just showing a bike, then you unfold the bike to see it's elements, I want each row in the tree to be a bike and have each column be filled with the data found inside (first column be name, second be comfort). However, I want users to be able to update the underlying XML. Say they select three different bikes, I'd like each selected bike to get an attribute like, springcollection="true", or something along those lines.

    How should I go about adapting the example to my needs, or should I begin building a brand new model? Has anyone done something like this before on these forums?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adapting the "Simple DOM Model Example" to be read/write

    Delegates

    see the spin box delegate example in the Qt Demos. Instead of spinbox u need lineedit.

  5. #5
    Join Date
    Aug 2008
    Location
    Iowa, USA
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adapting the "Simple DOM Model Example" to be read/write

    I'm mostly trying to have quick and easy access to XML for both reading and writing. I'm guessing I could get by with just rapid reading of elements and then just give users the option to save at the end, which would limit how much I'd ever need to write. But the dream is to rapidly read/write from XML.

    For my model, when I reimplemented the data function, is what I really want to do is go to the bike indexed by row, and look at the column to see which part of that bike I want to display? Is that how models work?

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adapting the "Simple DOM Model Example" to be read/write

    For my model, when I reimplemented the data function, is what I really want to do is go to the bike indexed by row, and look at the column to see which part of that bike I want to display? Is that how models work?
    Yes. A row represents a structure, and columns their attributes .
    What did u try till now ?

  7. #7
    Join Date
    Aug 2008
    Location
    Iowa, USA
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adapting the "Simple DOM Model Example" to be read/write

    Sorry about getting back to you so slowly; I'm working on lots of different projects right now.

    What I'm trying to do is use a DOM as the model for my data, and use a QTreeView as my view. However, lots of data in the model I want to be able to ignore. Certain nodes I want to be able to skip, while other nodes I want to have displayed all along the same row, but in separate columns.

    Is there a way to easily handle this using Qt or an example of this somewhere, or will I have to really learn the Model/View well and solve this problem myself with very little outside help?

  8. #8
    Join Date
    Jun 2007
    Location
    Brookline, Ma, USA
    Posts
    4
    Thanked 5 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adapting the "Simple DOM Model Example" to be read/write

    If I understand what you are trying to do, you will need to implement the logic of your application in the model. The view merely displays what you present to it from the model. As I recall, the simple example is displaying three columns that represent the name (tag name in the case of an element), attributes, and the node value (the string or comment contents of a text node.)

    To make your bike program work correctly, you will need to build a model that understands the organization of your data and presents it to the view in the appropriate rows and columns. If you want to implement editing then you will need new delegate to edit within the treeview.
    Senior Qt and Qt Embedded Consultant
    and Certified Qt Trainer
    Integrated Computer Solutions
    Bedford, Ma, USA

  9. The following user says thank you to glebovitz for this useful post:

    joshuajcarson (8th September 2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.