[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Public QAbstractItemModel methods (wrongfully?) made private in QAbstract(Table|List)Mode
From:       Elvis Stansvik <elvstone () gmail ! com>
Date:       2016-06-02 10:53:21
Message-ID: CAHms=eaKXOhnzGZ984TQdQamDpvm-BtA7usjRjQdF2YULudwbg () mail ! gmail ! com
[Download RAW message or body]

2016-06-02 12:31 GMT+02:00 Phil Thompson <phil@riverbankcomputing.com>:
> On 2 Jun 2016, at 10:53 am, Florian Bruhin <me@the-compiler.org> wrote:
> > 
> > * Elvis Stansvik <elvstone@gmail.com> [2016-06-02 10:36:32 +0200]:
> > > Hi all,
> > > 
> > > From qabstractitemmodel.sip:
> > > 
> > > In the declaration of QAbstractTableModel:
> > > 
> > > private:
> > > ...
> > > virtual QModelIndex parent(const QModelIndex &child) const;
> > > virtual bool hasChildren(const QModelIndex &parent) const;
> > > 
> > > and in the declaration of QAbstractListModel:
> > > 
> > > private:
> > > ...
> > > virtual QModelIndex parent(const QModelIndex &child) const;
> > > virtual int columnCount(const QModelIndex &parent) const;
> > > virtual bool hasChildren(const QModelIndex &parent) const;
> > > 
> > > But these are all public functions in C++, and part of the public
> > > abstract item model API.
> > 
> > No, they are private in C++ as well:
> > https://github.com/qtproject/qtbase/blob/dev/src/corelib/itemmodels/qabstractitemmodel.h#L381-L384
> >  https://github.com/qtproject/qtbase/blob/dev/src/corelib/itemmodels/qabstractitemmodel.h#L407-L411
> >  
> > I guess the rationale is that it makes no sense to ask e.g. how many
> > columns a list has?
> 
> This is an interesting read...
> 
> http://www.gotw.ca/publications/mill18.htm
> 
> > > This leads to things like:
> > > 
> > > [estan@pyret ~]$ cat test.py
> > > from PyQt5.QtCore import QStringListModel
> > > model = QStringListModel()
> > > model.hasChildren()
> > > [estan@pyret ~]$ python test.py
> > > Traceback (most recent call last):
> > > File "test.py", line 3, in <module>
> > > model.hasChildren()
> > > TypeError: QAbstractListModel.hasChildren() is a private method
> > > 
> > > while the same works fine in C++.
> > 
> > It does not for me:
> > 
> > test.cpp: In function 'int main(int, char**)':
> > test.cpp:17:25: error: 'virtual bool QAbstractListModel::hasChildren(const QModelIndex&) \
> > const' is private within this context qsl->hasChildren(idx);
> 
> However the C++ base class should be able to invoke a Python re-implementation. The "private" \
> means that a sub-class cannot call the super-class implementation. This is a problem because \
> there is then no way to fallback to the C++ implementation if there is no Python \
> re-implementation. 
> So - I don't think it can be made to work, so I'm inclined not to change anything...

Yes, fair enough. My original mail was based on a misunderstanding.

Elvis

> 
> Phil
> _______________________________________________
> PyQt mailing list    PyQt@riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic