Python setItemDelegateForColunm()在没有stacktrace的情况下使应用程序崩溃

Python setItemDelegateForColunm()在没有stacktrace的情况下使应用程序崩溃,python,pyside,qtreeview,qstyleditemdelegate,Python,Pyside,Qtreeview,Qstyleditemdelegate,问题: 在树视图上设置每行或每列的QTSTYLEDITMDELEGATE时,我的应用程序崩溃,没有任何进一步的信息。尽管如此,为整个TreeView作品设置QStyledItemDelegate在我看来似乎很奇怪 有人知道这是一个已知的bug,还是我遗漏了什么 我在Qt 4.8中使用PySide 1.1.2(更改版本不是一个真正的选项,因为这将是一个很大的开销,因为它是一个分布式应用程序,也运行在一个集群上,其中版本更新将包括大量开销…) 这里是一个“最小跑步示例” 作为模型,我正在使用gith

问题:

在树视图上设置每行或每列的QTSTYLEDITMDELEGATE时,我的应用程序崩溃,没有任何进一步的信息。尽管如此,为整个TreeView作品设置QStyledItemDelegate在我看来似乎很奇怪

有人知道这是一个已知的bug,还是我遗漏了什么

我在Qt 4.8中使用PySide 1.1.2(更改版本不是一个真正的选项,因为这将是一个很大的开销,因为它是一个分布式应用程序,也运行在一个集群上,其中版本更新将包括大量开销…)

这里是一个“最小跑步示例”

作为模型,我正在使用github()上提供的storax中的easymodel及其一些扩展。为了完整起见,我使用的模型如下:

"""This module provides a generic interface for tree models

It centers around the TreeModel, which is used for all kinds of trees.
The tree gets customized by the TreeItems. Each TreeItem holds
a specific ItemData subclass. The ItemData is responsible for
delivering the data. Make sure that all TreeItems in one hierarchy have the same ItemData subclasses or at least the same column_count.
If not, make sure the data method can handle columns outside their column count.
If you want to create a tree, create the needed itemdata classes,
create a root tree item that is parent for all top-level items.
The root item does not have to provide data, so the data might be None.
It is advides to use :class:`jukebox.core.gui.treemodel.ListItemData` because the data in the list
will be used for the headers.
Then create the tree items with their appropriate data instances.
Finally create a tree model instance with the root tree item.
"""

import abc

from PySide import QtCore, QtGui
from types import NoneType


class ItemData(object):  # pragma: no cover
    """An abstract class that holds data and is used as an interface for TreeItems

    When subclassing implement :meth:`ItemData.data` and :meth:`ItemData.column_count`.
    It is advised to reimplement :meth:`ItemData.internal_data` too.
    """
    __metaclass__ = abc.ABCMeta

    @abc.abstractmethod
    def data(self, column, role):
        """Return the data for the specified column and role

        The column addresses one attribute of the data.
        When used in a root item, the data should return the horizontal header
        data. When returning None, the section Number is used (starting at 1) by the treemodel.
        So if you want an empty header, return an empty string!

        :param column: the data column
        :type column: int
        :param role: the data role
        :type role: QtCore.Qt.ItemDataRole
        :returns: data depending on the role
        :rtype:
        :raises: None
        """
        pass

    @abc.abstractmethod
    def column_count(self, ):
        """Return the number of columns that can be queried for data

        :returns: the number of columns
        :rtype: int
        :raises: None
        """
        pass

    def internal_data(self, ):
        """Return the internal data of the ItemData

        E.g. a ListItemData could return the list it uses, a
        ProjectItemData could return the Project etc.

        :returns: the data the itemdata uses as information
        :rtype: None|arbitrary data
        :raises: None
        """
        return None

    def flags(self, ):
        """Return the item flags for the item

        Default is QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable

        :returns: the item flags
        :rtype: QtCore.Qt.ItemFlags
        :raises: None
        """
        return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable


class ListItemData(ItemData):
    """Item data for generic lists

    Initialize it with a list of objects. Each element corresponds to a column.
    For DisplayRole the objects are converted to strings with ``str()``.
    """

    def __init__(self, liste,seperateListitemsInView=True):
        """ Constructs a new StringItemData with the given list

        :param list: a list of objects, one for each column
        :type list: list of objects
        :raises: None
        """
        super(ListItemData, self).__init__()
        self._list = liste
        self._seperateListitemsInView = seperateListitemsInView
        self._flags = super(ListItemData, self).flags()

    def data(self, column, role):
        """Return the data for the specified column and role

        For DisplayRole the element in the list will be converted to a sting and returned.

        :param column: the data column
        :type column: int
        :param role: the data role
        :type role: QtCore.Qt.ItemDataRole
        :returns: data depending on the role, or None if the column is out of range
        :rtype: depending on the role or None
        :raises: None
        """
        displayString = ""
        if role == QtCore.Qt.DisplayRole:

            if column == 0 or not self._seperateListitemsInView:
                return str(self._list[column])
            if column > 0 and column < len(self._list):
                try:
                    for l in self._list[column]:
                        displayString += " %s"%l 
                    return displayString
                except:
                    return str(self._list[column])

        if role == QtCore.Qt.BackgroundRole:
            if type(self._list[-1]) is QtGui.QColor: 
                return self._list[-1]
            else:
                return QtGui.QColor().fromRgbF(1.,1.,1.)        

    def column_count(self, ):
        """Return the number of columns that can be queried for data

        :returns: the number of columns
        :rtype: int
        :raises: None
        """
        return len(self._list)

    def internal_data(self, ):
        """Return the list

        :returns: the internal list
        :rtype: :class:`list`
        :raises: None
        """
        return self._list

    def addFlag(self,flag):
        self._flags = self._flags | flag 

    def flags(self, ):
        return self._flags



class TreeItem(object):
    """General TreeItem

    You can represent a tree structure with these tree items. Each item
    should contain some data that it can give to the model.
    Note that each tree always has one root item.
    Even if you have multiple top level items, they are all grouped under one
    root. The data for the root item can be None but it is advised to use
    a ListItemData so you can provide horizontal headers.
    """

    def __init__(self, data, parent=None,index = QtCore.QModelIndex()):
        """Constructs a new TreeItem that holds some data and might be parented under parent

        :param data: the data item. if the tree item is the root, the data will be used for horizontal headers!
                     It is recommended to use :class:`jukebox.core.gui.treeitem.ListItemData` in that case.
        :type data: :class:`jukebox.core.gui.treemodel.ItemData`
        :param parent: the parent treeitem
        :type parent: :class:`jukebox.core.gui.treemodel.TreeItem`
        :raises: None
        """
        self._data = data
        self._parent = parent
        self._index = index
        if self._parent is not None:
            self._parent.childItems.append(self)
        self.childItems = []


    def child(self, row):
        """Return the child at the specified row

        :param row: the row number
        :type row: int
        :returns: the child
        :rtype: :class:`jukebox.core.gui.treemodel.TreeItem`
        :raises: IndexError
        """
        return self.childItems[row]

    def child_count(self, ):
        """Return the number of children

        :returns: child coun
        :rtype: int
        :raises: None
        """
        return len(self.childItems)

    def row(self, ):
        """Return the index of this tree item in the parent rows

        :returns: the row of this TreeItem in the parent
        :rtype: int
        :raises: None
        """
        if self._parent is None:
            return 0
        return self._parent.childItems.index(self)

    def column_count(self, ):
        """Return the number of columns that the children have

        :returns: the column count of the children data
        :rtype: int
        :raises: None
        """
        if self.child_count():
            return self.childItems[0]._data.column_count()
        else:
            return 0

    def data(self, column, role):
        """Return the data for the column and role

        :param column: the data column
        :type column: int
        :param role: the data role
        :type role: QtCore.Qt.ItemDataRole
        :returns: data depending on the role
        :rtype:
        :raises: None
        """
        if self._data is not None and (column >= 0 or column < self._data.column_count()):
            return self._data.data(column, role)

    def parent(self, ):
        """Return the parent tree item

        :returns: the parent or None if there is no parent
        :rtype: :class:`jukebox.core.gui.treemodel.TreeItem`
        :raises: None
        """
        return self._parent

    def itemdata(self, ):
        """Return the internal :class:`ItemData`

        :returns: the internal ItemData
        :rtype: :class:`ItemData`
        :raises: None
        """
        return self._data

    def internal_data(self, ):
        """Return the internal data of the item data

        E.g. a ListItemData could return the list it uses, a
        ProjectItemData could return the Project etc.

        :returns: the data the itemdata uses as information
        :rtype: None|arbitrary data
        :raises: None
        """
        return self._data.internal_data()

    def flags(self, ):
        """Return the flags for the item

        :returns: the flags
        :rtype: QtCore.Qt.ItemFlags
        :raises: None
        """
        return self._data.flags()

    def index(self):
        return self._index

class TreeModel(QtCore.QAbstractItemModel):
    """A tree model that uses the :class:`jukebox.core.gui.treemodel.TreeItem` to represent a general tree.

    """

    def __init__(self, root, parent=None):
        """Constructs a new tree model with the given root treeitem

        :param root:
        :type root:
        :param parent:
        :type parent:
        :raises: None
        """
        super(TreeModel, self).__init__(parent)
        self._root = root
        # Extension for Temanejo: A list of the propertyRootItems which are sorted in incoming order 
        self.propertyRootItems = []

    def index(self, row, column, parent=None):
        """Returns the index of the item in the model specified by the given row, column and parent index.

        :param row: the row of the item
        :type row: int
        :param column: the column for the item
        :type column: int
        :param parent: the parent index
        :type parent: :class:`QtCore.QModelIndex`:
        :returns: the index of the item
        :rtype: :class:`QtCore.QModelIndex`
        :raises: None
        """
        if parent is None:
            parent = QtCore.QModelIndex()
        if not self.hasIndex(row, column, parent):
            return QtCore.QModelIndex()

        if parent.isValid():
            parentItem = parent.internalPointer()
        else:
            parentItem = self._root

        try:
            childItem = parentItem.child(row)
            return self.createIndex(row, column, childItem)
        except IndexError:
            return QtCore.QModelIndex()

    def parent(self, index):
        """Returns the parent of the model item with the given index. If the item has no parent, an invalid QModelIndex is returned.

        :param index: the index that you want to know the parent of
        :type index: :class:`QtCore.QModelIndex`
        :returns: parent index
        :rtype: :class:`QtCore.QModelIndex`
        :raises: None
        """
        if not index.isValid():
            return QtCore.QModelIndex()
        childItem = index.internalPointer()
        parentItem = childItem.parent()
        if parentItem is self._root:
            return QtCore.QModelIndex()
        return self.createIndex(parentItem.row(), 0, parentItem)

    def rowCount(self, parent):
        """Returns the number of rows under the given parent.
        When the parent is valid it means that rowCount is returning the number
        of children of parent.

        :param parent: the parent index
        :type parent: :class:`QtCore.QModelIndex`:
        :returns: the row count
        :rtype: int
        :raises: None
        """
        if parent.column() > 0:
            return 0
        if not parent.isValid():
            parentItem = self._root
        else:
            parentItem = parent.internalPointer()
        return parentItem.child_count()

    def columnCount(self, parent):
        """Returns the number of columns for the children of the given parent.

        :param parent: the parent index
        :type parent: :class:`QtCore.QModelIndex`:
        :returns: the column count
        :rtype: int
        :raises: None
        """
        if parent.isValid():
            return parent.internalPointer().column_count()
        else:
            return self._root.column_count()

    def data(self, index, role=QtCore.Qt.DisplayRole):
        """Returns the data stored under the given role for the item referred to by the index.

        :param index: the index
        :type index: QModelIndex
        :param role: the data role
        :type role: QtCore.Qt.ItemDataRole
        :returns: some data depending on the role
        :raises: None
        """
        if not index.isValid():
            return
        item = index.internalPointer()
        return item.data(index.column(), role)

    def headerData(self, section, orientation, role):
        """

        :param section:
        :type section:
        :param orientation:
        :type orientation:
        :param role:
        :type role:
        :returns: None
        :rtype: None
        :raises: None
        """
        if orientation == QtCore.Qt.Horizontal:
            d = self._root.data(section, role)
            if d is None and role == QtCore.Qt.DisplayRole:
                return str(section+1)
            return d
        if orientation == QtCore.Qt.Vertical and role == QtCore.Qt.DisplayRole:
            return str(section+1)

    def insertRow(self, row, item, parent):
        """Inserts a single item before the given row in the child items of the parent specified.

        :param row: the index where the rows get inserted
        :type row: int
        :param item: the item to insert. When creating the item, make sure it's parent is None.
                     If not it will defeat the purpose of this function.
        :type item: :class:`TreeItem`
        :param parent: the parent
        :type parent: class:`QtCore.QModelIndex`
        :returns: Returns true if the row is inserted; otherwise returns false.
        :rtype: bool
        :raises: None
        """
        parentitem = parent.internalPointer()
        self.beginInsertRows(parent, row, row)
        item._parent = parentitem
        parentitem.childItems.insert(row, item)
        self.endInsertRows()
        return True

    @property
    def root(self, ):
        """Return the root tree item

        :returns: the root item
        :rtype: :class:`TreeItem`
        :raises: None
        """
        return self._root

    def flags(self, index):
        """

        :param index:
        :type index:
        :returns: None
        :rtype: None
        :raises: None
        """
        if index.isValid():
            item = index.internalPointer()
            return item.flags()
        else:
            super(TreeModel, self).flags(index)
此模块为树模型提供通用接口 它以TreeModel为中心,用于各种树。 树由TreeItem定制。每个TreeItem保存 一个特定的ItemData子类。ItemData负责 传递数据。确保一个层次结构中的所有树项都具有相同的ItemData子类或至少具有相同的列计数。 如果没有,请确保data方法可以处理超出其列计数的列。 如果要创建树,请创建所需的itemdata类, 创建作为所有顶级项的父级的根目录树项。 根项不必提供数据,因此数据可能为无。 建议使用:class:`jukebox.core.gui.treemodel.ListItemData`因为列表中的数据 将用于标题。 然后使用相应的数据实例创建树项。 最后,使用根树项创建一个树模型实例。 """ 进口abc 从PySide导入QtCore、QtGui 从类型导入非类型 类ItemData(对象):#pragma:无封面 “”“保存数据并用作TreeItems接口的抽象类 当子类化implement:meth:`ItemData.data`和:meth:`ItemData.column\u count`时。 建议重新实现:meth:`ItemData.internal_data`。 """ __元类_uu=abc.ABCMeta @抽象方法 def数据(自身、列、角色): “”“返回指定列和角色的数据。” 该列处理数据的一个属性。 在根项目中使用时,数据应返回水平标题 返回None时,treemodel使用节号(从1开始)。 因此,如果您想要一个空的标题,请返回一个空字符串! :param column:数据列 :type列:int :param role:数据角色 :类型角色:QtCore.Qt.ItemDataRole :返回:取决于角色的数据 :rtype: :无 """ 通过 @抽象方法 def列_计数(自身) “”“返回可查询数据的列数 :返回:列数 :rtype:int :无 """ 通过 def内部_数据(自身) “”“返回ItemData的内部数据。” 例如,ListItemData可以返回它使用的列表 ProjectItemData可以返回项目等。 :返回:itemdata用作信息的数据 :rtype:None |任意数据 :无 """ 一无所获 def标志(自身),如下所示: “”“返回项目的项目标志。” 默认值为QtCore.Qt.ItemIsEnabled | QtCore.Qt.itemisselect :返回:项目标志 :rtype:QtCore.Qt.ItemFlags :无 """ 返回QtCore.Qt.ItemIsEnabled | QtCore.Qt.itemisselect 类ListItemData(ItemData): “”“通用列表的项目数据” 用对象列表初始化它。每个元素对应一列。 对于DisplayRole,对象将转换为带有“`str()`”的字符串。 """ def uuu init uuuu(self、liste、separateListItemsInView=True): “”“使用给定列表构造新的StringItemData :param list:对象列表,每列一个 :类型列表:对象列表 :无 """ super(ListItemData,self)。\uuuu init\uuuuu() self.\u list=liste self.\u separateListItemsInView=separateListItemsInView self.\u flags=super(ListItemData,self).flags() def数据(自身、列、角色): “”“返回指定列和角色的数据。” 对于DisplayRole,列表中的元素将转换为sting并返回。 :param column:数据列 :type列:int :param role:数据角色 :类型角色:QtCore.Qt.ItemDataRole :返回:数据取决于角色,如果列超出范围,则返回无 :rtype:取决于角色或无 :无 """ displayString=“” 如果角色==QtCore.Qt.DisplayRole: 如果列==0或不是self.\u separateListItemsInView: 返回str(self.\u列表[列]) 如果列>0且列<列(自列): 尝试: 对于l in self.\u列表[列]: displayString+=%s“%l” 返回显示字符串 除: 返回str(self.\u列表[列]) 如果角色==QtCore.Qt.BackgroundRole: 如果类型(self.\u list[-1])为QtGui.QColor: 返回自我列表[-1] 其他: 从rgbf(1,1,1.)返回QtGui.QColor() def列_计数(自身) “”“返回可查询数据的列数 :返回:列数 :rtype:int :无 """ 返回len(self.\u列表) def内部_数据(自身) “”“返回列表 :返回:内部列表 :rtype::class:`list` :无
"""This module provides a generic interface for tree models

It centers around the TreeModel, which is used for all kinds of trees.
The tree gets customized by the TreeItems. Each TreeItem holds
a specific ItemData subclass. The ItemData is responsible for
delivering the data. Make sure that all TreeItems in one hierarchy have the same ItemData subclasses or at least the same column_count.
If not, make sure the data method can handle columns outside their column count.
If you want to create a tree, create the needed itemdata classes,
create a root tree item that is parent for all top-level items.
The root item does not have to provide data, so the data might be None.
It is advides to use :class:`jukebox.core.gui.treemodel.ListItemData` because the data in the list
will be used for the headers.
Then create the tree items with their appropriate data instances.
Finally create a tree model instance with the root tree item.
"""

import abc

from PySide import QtCore, QtGui
from types import NoneType


class ItemData(object):  # pragma: no cover
    """An abstract class that holds data and is used as an interface for TreeItems

    When subclassing implement :meth:`ItemData.data` and :meth:`ItemData.column_count`.
    It is advised to reimplement :meth:`ItemData.internal_data` too.
    """
    __metaclass__ = abc.ABCMeta

    @abc.abstractmethod
    def data(self, column, role):
        """Return the data for the specified column and role

        The column addresses one attribute of the data.
        When used in a root item, the data should return the horizontal header
        data. When returning None, the section Number is used (starting at 1) by the treemodel.
        So if you want an empty header, return an empty string!

        :param column: the data column
        :type column: int
        :param role: the data role
        :type role: QtCore.Qt.ItemDataRole
        :returns: data depending on the role
        :rtype:
        :raises: None
        """
        pass

    @abc.abstractmethod
    def column_count(self, ):
        """Return the number of columns that can be queried for data

        :returns: the number of columns
        :rtype: int
        :raises: None
        """
        pass

    def internal_data(self, ):
        """Return the internal data of the ItemData

        E.g. a ListItemData could return the list it uses, a
        ProjectItemData could return the Project etc.

        :returns: the data the itemdata uses as information
        :rtype: None|arbitrary data
        :raises: None
        """
        return None

    def flags(self, ):
        """Return the item flags for the item

        Default is QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable

        :returns: the item flags
        :rtype: QtCore.Qt.ItemFlags
        :raises: None
        """
        return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable


class ListItemData(ItemData):
    """Item data for generic lists

    Initialize it with a list of objects. Each element corresponds to a column.
    For DisplayRole the objects are converted to strings with ``str()``.
    """

    def __init__(self, liste,seperateListitemsInView=True):
        """ Constructs a new StringItemData with the given list

        :param list: a list of objects, one for each column
        :type list: list of objects
        :raises: None
        """
        super(ListItemData, self).__init__()
        self._list = liste
        self._seperateListitemsInView = seperateListitemsInView
        self._flags = super(ListItemData, self).flags()

    def data(self, column, role):
        """Return the data for the specified column and role

        For DisplayRole the element in the list will be converted to a sting and returned.

        :param column: the data column
        :type column: int
        :param role: the data role
        :type role: QtCore.Qt.ItemDataRole
        :returns: data depending on the role, or None if the column is out of range
        :rtype: depending on the role or None
        :raises: None
        """
        displayString = ""
        if role == QtCore.Qt.DisplayRole:

            if column == 0 or not self._seperateListitemsInView:
                return str(self._list[column])
            if column > 0 and column < len(self._list):
                try:
                    for l in self._list[column]:
                        displayString += " %s"%l 
                    return displayString
                except:
                    return str(self._list[column])

        if role == QtCore.Qt.BackgroundRole:
            if type(self._list[-1]) is QtGui.QColor: 
                return self._list[-1]
            else:
                return QtGui.QColor().fromRgbF(1.,1.,1.)        

    def column_count(self, ):
        """Return the number of columns that can be queried for data

        :returns: the number of columns
        :rtype: int
        :raises: None
        """
        return len(self._list)

    def internal_data(self, ):
        """Return the list

        :returns: the internal list
        :rtype: :class:`list`
        :raises: None
        """
        return self._list

    def addFlag(self,flag):
        self._flags = self._flags | flag 

    def flags(self, ):
        return self._flags



class TreeItem(object):
    """General TreeItem

    You can represent a tree structure with these tree items. Each item
    should contain some data that it can give to the model.
    Note that each tree always has one root item.
    Even if you have multiple top level items, they are all grouped under one
    root. The data for the root item can be None but it is advised to use
    a ListItemData so you can provide horizontal headers.
    """

    def __init__(self, data, parent=None,index = QtCore.QModelIndex()):
        """Constructs a new TreeItem that holds some data and might be parented under parent

        :param data: the data item. if the tree item is the root, the data will be used for horizontal headers!
                     It is recommended to use :class:`jukebox.core.gui.treeitem.ListItemData` in that case.
        :type data: :class:`jukebox.core.gui.treemodel.ItemData`
        :param parent: the parent treeitem
        :type parent: :class:`jukebox.core.gui.treemodel.TreeItem`
        :raises: None
        """
        self._data = data
        self._parent = parent
        self._index = index
        if self._parent is not None:
            self._parent.childItems.append(self)
        self.childItems = []


    def child(self, row):
        """Return the child at the specified row

        :param row: the row number
        :type row: int
        :returns: the child
        :rtype: :class:`jukebox.core.gui.treemodel.TreeItem`
        :raises: IndexError
        """
        return self.childItems[row]

    def child_count(self, ):
        """Return the number of children

        :returns: child coun
        :rtype: int
        :raises: None
        """
        return len(self.childItems)

    def row(self, ):
        """Return the index of this tree item in the parent rows

        :returns: the row of this TreeItem in the parent
        :rtype: int
        :raises: None
        """
        if self._parent is None:
            return 0
        return self._parent.childItems.index(self)

    def column_count(self, ):
        """Return the number of columns that the children have

        :returns: the column count of the children data
        :rtype: int
        :raises: None
        """
        if self.child_count():
            return self.childItems[0]._data.column_count()
        else:
            return 0

    def data(self, column, role):
        """Return the data for the column and role

        :param column: the data column
        :type column: int
        :param role: the data role
        :type role: QtCore.Qt.ItemDataRole
        :returns: data depending on the role
        :rtype:
        :raises: None
        """
        if self._data is not None and (column >= 0 or column < self._data.column_count()):
            return self._data.data(column, role)

    def parent(self, ):
        """Return the parent tree item

        :returns: the parent or None if there is no parent
        :rtype: :class:`jukebox.core.gui.treemodel.TreeItem`
        :raises: None
        """
        return self._parent

    def itemdata(self, ):
        """Return the internal :class:`ItemData`

        :returns: the internal ItemData
        :rtype: :class:`ItemData`
        :raises: None
        """
        return self._data

    def internal_data(self, ):
        """Return the internal data of the item data

        E.g. a ListItemData could return the list it uses, a
        ProjectItemData could return the Project etc.

        :returns: the data the itemdata uses as information
        :rtype: None|arbitrary data
        :raises: None
        """
        return self._data.internal_data()

    def flags(self, ):
        """Return the flags for the item

        :returns: the flags
        :rtype: QtCore.Qt.ItemFlags
        :raises: None
        """
        return self._data.flags()

    def index(self):
        return self._index

class TreeModel(QtCore.QAbstractItemModel):
    """A tree model that uses the :class:`jukebox.core.gui.treemodel.TreeItem` to represent a general tree.

    """

    def __init__(self, root, parent=None):
        """Constructs a new tree model with the given root treeitem

        :param root:
        :type root:
        :param parent:
        :type parent:
        :raises: None
        """
        super(TreeModel, self).__init__(parent)
        self._root = root
        # Extension for Temanejo: A list of the propertyRootItems which are sorted in incoming order 
        self.propertyRootItems = []

    def index(self, row, column, parent=None):
        """Returns the index of the item in the model specified by the given row, column and parent index.

        :param row: the row of the item
        :type row: int
        :param column: the column for the item
        :type column: int
        :param parent: the parent index
        :type parent: :class:`QtCore.QModelIndex`:
        :returns: the index of the item
        :rtype: :class:`QtCore.QModelIndex`
        :raises: None
        """
        if parent is None:
            parent = QtCore.QModelIndex()
        if not self.hasIndex(row, column, parent):
            return QtCore.QModelIndex()

        if parent.isValid():
            parentItem = parent.internalPointer()
        else:
            parentItem = self._root

        try:
            childItem = parentItem.child(row)
            return self.createIndex(row, column, childItem)
        except IndexError:
            return QtCore.QModelIndex()

    def parent(self, index):
        """Returns the parent of the model item with the given index. If the item has no parent, an invalid QModelIndex is returned.

        :param index: the index that you want to know the parent of
        :type index: :class:`QtCore.QModelIndex`
        :returns: parent index
        :rtype: :class:`QtCore.QModelIndex`
        :raises: None
        """
        if not index.isValid():
            return QtCore.QModelIndex()
        childItem = index.internalPointer()
        parentItem = childItem.parent()
        if parentItem is self._root:
            return QtCore.QModelIndex()
        return self.createIndex(parentItem.row(), 0, parentItem)

    def rowCount(self, parent):
        """Returns the number of rows under the given parent.
        When the parent is valid it means that rowCount is returning the number
        of children of parent.

        :param parent: the parent index
        :type parent: :class:`QtCore.QModelIndex`:
        :returns: the row count
        :rtype: int
        :raises: None
        """
        if parent.column() > 0:
            return 0
        if not parent.isValid():
            parentItem = self._root
        else:
            parentItem = parent.internalPointer()
        return parentItem.child_count()

    def columnCount(self, parent):
        """Returns the number of columns for the children of the given parent.

        :param parent: the parent index
        :type parent: :class:`QtCore.QModelIndex`:
        :returns: the column count
        :rtype: int
        :raises: None
        """
        if parent.isValid():
            return parent.internalPointer().column_count()
        else:
            return self._root.column_count()

    def data(self, index, role=QtCore.Qt.DisplayRole):
        """Returns the data stored under the given role for the item referred to by the index.

        :param index: the index
        :type index: QModelIndex
        :param role: the data role
        :type role: QtCore.Qt.ItemDataRole
        :returns: some data depending on the role
        :raises: None
        """
        if not index.isValid():
            return
        item = index.internalPointer()
        return item.data(index.column(), role)

    def headerData(self, section, orientation, role):
        """

        :param section:
        :type section:
        :param orientation:
        :type orientation:
        :param role:
        :type role:
        :returns: None
        :rtype: None
        :raises: None
        """
        if orientation == QtCore.Qt.Horizontal:
            d = self._root.data(section, role)
            if d is None and role == QtCore.Qt.DisplayRole:
                return str(section+1)
            return d
        if orientation == QtCore.Qt.Vertical and role == QtCore.Qt.DisplayRole:
            return str(section+1)

    def insertRow(self, row, item, parent):
        """Inserts a single item before the given row in the child items of the parent specified.

        :param row: the index where the rows get inserted
        :type row: int
        :param item: the item to insert. When creating the item, make sure it's parent is None.
                     If not it will defeat the purpose of this function.
        :type item: :class:`TreeItem`
        :param parent: the parent
        :type parent: class:`QtCore.QModelIndex`
        :returns: Returns true if the row is inserted; otherwise returns false.
        :rtype: bool
        :raises: None
        """
        parentitem = parent.internalPointer()
        self.beginInsertRows(parent, row, row)
        item._parent = parentitem
        parentitem.childItems.insert(row, item)
        self.endInsertRows()
        return True

    @property
    def root(self, ):
        """Return the root tree item

        :returns: the root item
        :rtype: :class:`TreeItem`
        :raises: None
        """
        return self._root

    def flags(self, index):
        """

        :param index:
        :type index:
        :returns: None
        :rtype: None
        :raises: None
        """
        if index.isValid():
            item = index.internalPointer()
            return item.flags()
        else:
            super(TreeModel, self).flags(index)
    self.delegate = QtGui.QStyledItemDelegate()
    treeview.setItemDelegateForColumn(0, self.delegate)
    treeview.setItemDelegateForColumn(0, QtGui.QStyledItemDelegate(treeview))