Results 1 to 8 of 8

Thread: Problem representing/drawing c++ tree-like structure via qt quick.

  1. #1
    Join Date
    Feb 2015
    Posts
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Problem representing/drawing c++ tree-like structure via qt quick.

    I have tree-like structure in c++ classes. It's like blocks following one another. Each block can have different number of properties unique to it. Id like to draw them as rectangles listing all of their props. But the problem is that some special blocks can have 1-2 such "chains" of other blocks inside of them. And I'd' like to draw this blocks surrounding/encompassing their "insides". Also I'd like to have and ability to edit such blocks (have access to their properties). And I can't seem to find any way to draw this model (closest thing I found that might help me is ListView + hacky way with Loader as delegate). Can anyone help me?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem representing/drawing c++ tree-like structure via qt quick.

    A delegate that loads itself recursively sounds like the way to go. Whether you use a listview or a repeater plus some positioner for each level's population depends on the target visualziation and behavior you want to achieve.

    One other option is of course to create a custom component that does all in C++.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2015
    Posts
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Problem representing/drawing c++ tree-like structure via qt quick.

    Quote Originally Posted by anda_skoa View Post
    A delegate that loads itself recursively sounds like the way to go. Whether you use a listview or a repeater plus some positioner for each level's population depends on the target visualziation and behavior you want to achieve.

    One other option is of course to create a custom component that does all in C++.

    Cheers,
    _
    Thanks. That's what I'm doing atm. But I'd also like to be able to add blocks/edit their properties and I can't get how to do this without fully copying entire class structure inside qml. For example if blocks have different fields I can pass (as a role) the number of fields and their names but I don't know how to properly generate dialogue with numerous "label(field name)" : "text field to edit" (without another list model of course).

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem representing/drawing c++ tree-like structure via qt quick.

    Assuming you have different types of boxes, you could have a model property that holds the name of an editor QML file and then load the relevant editor on demand.
    This dialog would then know which roles it can access.
    Would even allow more customized editors than just list of name/value pairs.

    Anyway, if your current model has properties for all those fields and you only need a way to access them, consider that these three things are equivalent in JavaScript

    Qt Code:
    1. var foo = model.text
    2. var bar = model["text"]
    3. var key = "text";
    4. var baz = model[key]
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5
    Join Date
    Feb 2015
    Posts
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Problem representing/drawing c++ tree-like structure via qt quick.

    Quote Originally Posted by anda_skoa View Post
    Assuming you have different types of boxes, you could have a model property that holds the name of an editor QML file and then load the relevant editor on demand.
    This dialog would then know which roles it can access.
    Would even allow more customized editors than just list of name/value pairs.
    _
    But that's exactly what I'm trying to avoid!
    I can't get how to do this without fully copying entire class structure inside qml.
    If I have 20+ c++ classes I don't want to create 20+ corresponding qml editors and make extra effort to keep them in sync.
    Quote Originally Posted by anda_skoa View Post
    Anyway, if your current model has properties for all those fields and you only need a way to access them, consider that these three things are equivalent in JavaScript

    Qt Code:
    1. var foo = model.text
    2. var bar = model["text"]
    3. var key = "text";
    4. var baz = model[key]
    To copy to clipboard, switch view to plain text mode 
    But I the roles/properties aren't fixed. And you can only specify and access fixed roles.
    The only solution I found for now is to have something like QStringList propertyNames (or maybe qmap later) and QString blockType and have general editor that only has listview of textedit elements with corresponding property names and is connected to my block via slot/signal passing QVariant of itself. It still would be a pain for creating new blocks with such editor (c++ code would be big big if (type == "...") elsif elsif elsif)

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem representing/drawing c++ tree-like structure via qt quick.

    Quote Originally Posted by flashmozzg View Post
    But I the roles/properties aren't fixed. And you can only specify and access fixed roles.
    The third example is obviously not using a fixed role.

    Cheers,
    _

  7. #7
    Join Date
    Feb 2015
    Posts
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Problem representing/drawing c++ tree-like structure via qt quick.

    Quote Originally Posted by anda_skoa View Post
    The third example is obviously not using a fixed role.

    Cheers,
    _
    This one 'var key = "text";' ?
    How so? How it's even equivalent to 'var bar = model["text"]' ?
    And even the model.text would change model properties. Whereas If I understood correctly model element's properties inside delegate can only be accessed if they are declared as roles.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem representing/drawing c++ tree-like structure via qt quick.

    Quote Originally Posted by flashmozzg View Post
    This one 'var key = "text";' ?
    No, the third example for accessing the model data
    Qt Code:
    1. var baz = model[key]
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by flashmozzg View Post
    And even the model.text would change model properties. Whereas If I understood correctly model element's properties inside delegate can only be accessed if they are declared as roles.
    Well, if your names are not model roles, return the object as one of the model roles and access the object's properties by name.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 3rd October 2011, 15:40
  2. Replies: 6
    Last Post: 20th May 2011, 17:56
  3. QStandardItemModel, parent / child to form tree structure
    By Nightfox in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2010, 17:01
  4. Tree structure
    By ikm in forum Newbie
    Replies: 1
    Last Post: 7th August 2009, 20:19
  5. Create Tree Structure
    By bismitapadhy in forum Qt Programming
    Replies: 4
    Last Post: 4th June 2009, 10:13

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.