2 Copyright (C) 1997-2017 JDERobot Developers Team 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU Library General Public License for more details. 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, see <http://www.gnu.org/licenses/>. 17 Authors : Okan Asik (asik.okan@gmail.com) 19 from PyQt5.QtCore
import Qt, QModelIndex, QAbstractItemModel
20 from PyQt5.QtGui
import QColor
22 from visualstates.gui.tree.treenode
import TreeNode
27 super(QAbstractItemModel, self).
__init__(parent)
28 self.
rootNode = TreeNode(
"ID",
"Name",
"white")
34 return self.rootNode.columnCount()
36 def data(self, index, role):
37 if not index.isValid():
40 if role == Qt.DisplayRole:
41 item = index.internalPointer()
42 return item.data(index.column())
44 elif role == Qt.BackgroundColorRole:
45 item = index.internalPointer()
46 return item.background()
51 if not index.isValid():
54 if not index.parent().isValid():
55 item = index.internalPointer()
61 if not index.isValid():
64 return Qt.ItemIsEnabled | Qt.ItemIsSelectable
67 if orientation == Qt.Horizontal
and role == Qt.DisplayRole:
68 return self.rootNode.data(section)
72 def index(self, row, column, parent):
73 if not self.hasIndex(row, column, parent):
76 if not parent.isValid():
79 parentItem = parent.internalPointer()
81 childItem = parentItem.child(row)
83 return self.createIndex(row, column, childItem)
88 return self.createIndex(child.row(), 0, child)
91 if not index.isValid():
94 childItem = index.internalPointer()
95 parentItem = childItem.parent()
100 return self.createIndex(parentItem.row(), 0, parentItem)
103 if parent.column() > 0:
106 if not parent.isValid():
109 parentItem = parent.internalPointer()
111 return parentItem.childCount()
119 newNode = TreeNode(stateData.id, stateData.name, color, parent)
120 parent.appendChild(newNode)
122 self.layoutChanged.emit()
127 childToBeRemoved =
None 128 for s
in parent.getChildren():
133 if childToBeRemoved
is not None:
135 parent.removeChild(childToBeRemoved)
136 self.layoutChanged.emit()
141 mychildren.append(node)
143 for child
in node.childItems:
157 self.rootNode.removeChildren()
158 self.layoutChanged.emit()
161 for child
in rootState.getChildren():
162 if parentState
is not None:
175 for node
in parent.getChildren():
183 self.layoutChanged.emit()
def headerData(self, section, orientation, role)
def insertStateData(self, stateData, color, parent=None)
def columnCount(self, parent)
def index(self, row, column, parent)
def insertState(self, state, color, parent=None)
def removeState(self, state, parent=None)
def getChildren(self, node)
def loadFromRoot(self, rootState, parentState=None)
def setAllBackgroundByParentId(self, color, parentId)
def data(self, index, role)
def setBackgroundById(self, id, color)
def rowCount(self, parent)
def getByDataId(self, id)
def __init__(self, parent=None)