I want to write my own proxy model to "flatten" a tree-like model (i.e. some items might have children items) into a list-like model (i.e. no items have children) by mapping the indices. Subclassing QtGui.QIdentityProxyModel
seems to be the best way: http://qt-project.org/doc/qt-4.8/qidentityproxymodel.html but I cannot find it in PySide 1.2.1 which is built with Qt 4.8 (which includes QIdentityProxyModel
): http://seanfisk.github.io/pyside-docs/pyside/PySide/QtGui/index.html.
So this seems to leave me two options:
subclass QAbstractProxyModel
or QSortFilterProxyModel
find a way to build PySide myself to include QIdentityProxyModel
Any suggestions will be appreciated.
I would go for 2) because that would be useful for the posterity as well if you have enough time to get it through.
First you need to build and install shiboken as it is a dependency for building pyside. You can accomplish that as follows:
* git clone git@gitorious.org:pyside/shiboken.git
* cd shiboken
* mkdir build
* cd build
* cmake -DCMAKE_INSTALL_PREFIX="/usr/local" ..
* n(make)
* n(make) install
Once that is done, you start working on pyside as follows:
* git clone git@gitorious.org:pyside/pyside.git
* edit the PySide/QtGui/typesystem_gui_common.xml file:
This is my git diff
output:
diff --git a/PySide/QtGui/CMakeLists.txt b/PySide/QtGui/CMakeLists.txt
index 7625634..172f321 100644
--- a/PySide/QtGui/CMakeLists.txt
+++ b/PySide/QtGui/CMakeLists.txt
@@ -275,6 +275,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qshowevent_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qsizepolicy_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qslider_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qsortfilterproxymodel_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qidentityproxymodel_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qsound_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qspaceritem_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qspinbox_wrapper.cpp
diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml
index 711d7cc..4980fa4 100644
--- a/PySide/QtGui/typesystem_gui_common.xml
+++ b/PySide/QtGui/typesystem_gui_common.xml
@@ -4571,6 +4571,16 @@
<modify-function signature="clear()" remove="all"/>
<modify-function signature="filterChanged()" remove="all"/>
<!--### End of obsolete section -->
+</object-type>
+ <object-type name="QIdentityProxyModel">
+ <extra-includes>
+ <include file-name="QItemSelection" location="global"/>
+ </extra-includes>
+ <modify-function signature="setSourceModel(QAbstractItemModel*)">
+ <modify-argument index="1">
+ <reference-count action="set"/>
+ </modify-argument>
+ </modify-function>
</object-type>
<object-type name="QSlider">
<enum-type name="TickPosition" />
After this, you will need to configure, build, and install the project as follows:
* mkdir build
* cd build
* cmake -DCMAKE_INSTALL_PREFIX="/usr/local" -DCMAKE_PREFIX_PATH="/usr/local" ..
* (n)make
* (n)make install
I am providing these commands for Unix, but it is easy to adapt for other operating systems like Windows, too.
I am not claiming my patch is perfect, but that is where you could start the experiment. It should not be too hard.
Also, do not forget that there is a third option, using PyQt where this class seems to be supported:
QIdentityProxyModel Class Reference