Results 1 to 7 of 7

Thread: QTreeView details: what are viewItems?

Hybrid View

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

    Default Re: QTreeView details: what are viewItems?

    The d-pointer idiom is used to keep the public API of QTreeView binary stable while still having the option of adding/removing/renaming functions necessary for the view's procesing.

    The d-pointer points to a private class that holds the actual implementation of the view, often also referred to as PIMPL idiom (pointer to implementation).

    The Q_D() and Q_Q() macros enable const correct access to the private and public class respectively.

    The class you are looking for ist QTreeViewPrivate

    Cheers,
    _

  2. #2
    Join Date
    Jun 2014
    Posts
    98
    Platforms
    Windows
    Thanks
    43
    Thanked 4 Times in 4 Posts

    Default Re: QTreeView details: what are viewItems?

    Quote Originally Posted by anda_skoa View Post
    The d-pointer idiom is used to keep the public API of QTreeView binary stable while still having the option of adding/removing/renaming functions necessary for the view's procesing.

    The d-pointer points to a private class that holds the actual implementation of the view, often also referred to as PIMPL idiom (pointer to implementation).

    The Q_D() and Q_Q() macros enable const correct access to the private and public class respectively.

    The class you are looking for ist QTreeViewPrivate

    Cheers,
    _
    Thanks I will ruck about see what I figure out and post here.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: QTreeView details: what are viewItems?

    Within the Qt source the private implementation is usually in a file named blah_p.h for a class blah with its public API in blah.h. The private header is #included into the implementation file blah.cpp but not inthe public header or user programs.

    I would not worry too much about the internals of the views and models if all you want to do is use them.

  4. The following user says thank you to ChrisW67 for this useful post:

    neuronet (1st January 2015)

  5. #4
    Join Date
    Jun 2014
    Posts
    98
    Platforms
    Windows
    Thanks
    43
    Thanked 4 Times in 4 Posts

    Default Re: QTreeView details: what are viewItems?

    Quote Originally Posted by ChrisW67 View Post
    Within the Qt source the private implementation is usually in a file named blah_p.h for a class blah with its public API in blah.h. The private header is #included into the implementation file blah.cpp but not inthe public header or user programs.

    I would not worry too much about the internals of the views and models if all you want to do is use them.
    Thanks a lot for the specifics, that is helpful, though I am frankly still a bit lost.

    tl;dr
    : Good point: my goal is just to use this software, not become a developer. If it really is important I learn the internals, I will need to learn Qt for real (c++).

    The problem is, as I try to explain to other PySide users what is going on underneath, I often have no idea. For instance "Why the redundancy between model.data() and index.data(): why not always use one or the other?" It is frustrating to not be able to go in and figure such things out easily on my own. c++ code is a labyrinthine mystery to me for the most part. For some things, going to the source is really helpful. With QTreeView, it has been mostly frustrating.

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

    Default Re: QTreeView details: what are viewItems?

    QModelIndex::data() is for convenience, in case you want to retrieve data pointed to by a QModelIndex.

    But the data retrieval function has to be implemented somewhere and since one cannot "inject" something into QModelIndex, the next possible place is the model.

    So QModelIndex::data() can then always be just a simple indirection
    Qt Code:
    1. QVariant QModelIndex::data(int role) const
    2. {
    3. model()->data(*this, role),
    4. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  7. The following user says thank you to anda_skoa for this useful post:

    neuronet (1st January 2015)

  8. #6
    Join Date
    Jun 2014
    Posts
    98
    Platforms
    Windows
    Thanks
    43
    Thanked 4 Times in 4 Posts

    Default Re: QTreeView details: what are viewItems?

    I found a great Doxygen resource for navigating Qt (unfortunately only up to 4.2 I couldn't find any doxygenated 4.8: if anyone has a link let me know...).

    Using it made navigating the c++ code much easier, and the code seems largely the same as in 4.8, so I've been using the doxygen pages (for 4.2) to find stuff in 4.8. For instance, the documentation for qtreeview_p.h has the following useful bit:
    QVector<QTreeViewItem> QTreeViewPrivate::viewItems [mutable]
    Definition at line 134 of file qtreeview_p.h.
    Cool, we have a QVector of QTreeViewItems, and this is the mysterious viewItems that I was asking about! Many of the viewItems methods were actually just QVector methods, and part of my confusion is that QVector is not part of PySide.

    At any rate, in 4.8, on line 178), we see the relevant line:
    Qt Code:
    1. mutable QVector<QTreeViewItem> viewItems;
    To copy to clipboard, switch view to plain text mode 
    So we have a vector of QTreeViewItem types, and QTreeViewItem has its own page here. But more importantly, qtreeviewitem is the first structure defined in qtreeview_p.h! In terms of clues about when it is being populated, check line 2495 of qtreeview.cpp (d->viewItems.insert(insertPos, delta, insertedItems.at(0))). Where 'insert' seems to be a built-in method for QVectors.

    This seems like a very promising line of attack for other Python users (perhaps future me) to insinuate themselves into this often baffling code.

Similar Threads

  1. QTreeView
    By marnando in forum Newbie
    Replies: 1
    Last Post: 13th March 2014, 08:06
  2. QTreeView and d&d
    By FuturePrimitive in forum Qt Programming
    Replies: 1
    Last Post: 10th November 2011, 20:27
  3. Help ...QTreeView
    By Raymond in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2009, 09:18
  4. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 21:22
  5. QTreeView
    By npc in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2007, 07:53

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.