4 from PyQt4.QtGui import QTreeWidget,QTreeWidgetItem,QInputDialog
11 """ The TreeView widget fills itself using a DataAccessor.
18 logging.debug(__name__ +
": __init__")
19 AbstractView.__init__(self)
20 QTreeWidget.__init__(self, parent)
31 self.setSortingEnabled(
False)
32 self.setColumnCount(1)
33 self.setRootIsDecorated(
True)
37 self.connect(self, SIGNAL(
"itemCollapsed(QTreeWidgetItem*)"), self.
itemExpanded)
38 self.connect(self, SIGNAL(
"itemExpanded(QTreeWidgetItem*)"), self.
itemExpanded)
41 """ Sets the DataAccessor from which the nodes are created.
43 You need to call updateContent() in order to make the changes visible.
45 if not isinstance(accessor, BasicDataAccessor):
46 raise TypeError(__name__ +
" requires data accessor of type BasicDataAccessor.")
47 AbstractView.setDataAccessor(self, accessor)
50 """ Stop all running operations.
55 """ Deletes all items in the TreeView
60 QTreeWidget.clear(self)
63 """ Clear the TreeView and refill it.
81 if not Application.NO_PROCESS_EVENTS:
82 QCoreApplication.instance().processEvents()
93 def _createNode(self, object=None, itemParent=None, positionName="0"):
94 """ Create daughter items of an object recursively.
96 item = QTreeWidgetItem(itemParent)
104 if len(positionName.split(
"-")) < self.
_maxDepth:
106 self.
_createNode(daughter, item, positionName +
"-" + str(i))
110 """ Emits signal selected that the TabController can connect to.
114 self.
_selection = self.currentItem().positionName
115 self.emit(SIGNAL(
"selected"), self.currentItem().object)
118 """ Mark an object in the TreeView as selected.
122 for positionName, item
in self._itemDict.items():
123 if item.object == object:
124 items += [(positionName, item)]
126 item = sorted(items)[0][1]
129 self.setCurrentItem(item)
141 """ Restore selection.
147 self.setCurrentItem(select)
151 """ Return currently selected object.
153 If selection unknown return first object.
166 QTreeWidget.mousePressEvent(self,event)
167 if event.button()==Qt.RightButton:
168 self.emit(SIGNAL(
"mouseRightPressed"), event.globalPos())
171 """ Show dialog and call expandToDepth() function of tree view.
173 if hasattr(QInputDialog,
"getInteger"):
175 (depth, ok) = QInputDialog.getInteger(self,
"Expand to depth...",
"Input depth:", self.
_treeDepth, 0)
178 (depth, ok) = QInputDialog.getInt(self,
"Expand to depth...",
"Input depth:", self.
_treeDepth, 0)
187 QTreeWidget.expandAll(self)
192 QTreeWidget.collapseAll(self)
197 if item.isExpanded():