class TreeController(QObject): def __init__(self, treeview): super(TreeController, self).__init__() self.treeview = treeview self.treeview.setSelectionBehavior(QTreeView.SelectItems) self.treeview.setUniformRowHeights(True) headers = ["item", "visible", "lock"] self.treemodel = TreeModel(self.treeview) self.treemodel.headers = headers self.treeview.setDragDropMode(QAbstractItemView.InternalMove) #self.win.treeview.setItemDelegateForColumn(0, QString()) self.treeview.setAllColumnsShowFocus(True) self.treeview.setModel(self.treemodel) # insert the base level assembly index = self.treeview.currentIndex() nodeparent = self.treemodel.nodeFromIndex(index) node = AssemblyNode("Assembly", Assembly(), None, None) if self.treemodel.insertRow(0, index, node): # set index to the inserted child index = self.treemodel.index(0, 0, index) self.setCurrentIndex(index) # end if self.createConnections() # end def def createConnections(self): # QItemSelectionModel.currentChange emits the previous and current # selected QModelIndex, but we don't use those values #self.treeview.selectionModel().currentChanged.connect(self.updateUi) #self.treeview.activated.connect() # #self.treemodel.dataChanged.connect(self.setDirty_ind) #self.treemodel.rowsRemoved.connect(self.setDirty) #self.treemodel.modelReset.connect(self.setDirty) # clicked is a QAbstractItemView signal self.treeview.clicked.connect(self.activated) # end def def setCurrentIndex(self,index): if index.isValid(): self.treeview.scrollTo(index) self.treeview.setCurrentIndex(index) # end if # end def def addPartNode(self,name,partInst): """ Adds a part to the tree model Makes sure it adds to the closest parent assembly if a part is the current selected item """ index = self.treeview.currentIndex() # this is a QModelIndex nodeparent = self.treemodel.nodeFromIndex(index) # must make it an assembly that we insert at if nodeparent.ntype != AssemblyNode.ntype: index = index.parent() # returns the parent model index nodeparent = nodeparent.parent # go to the parent # end if #node = PartNode(name, partInst,None, nodeparent) node = PartNode(name, partInst,None, None) # currently we insert the new node first in the list but # treemodel handles keeping things alphabetical if self.treemodel.insertRow(0, index,node): # set index to the inserted child index = self.treemodel.index(self.treemodel.lastrow, 0, index) self.setCurrentIndex(index) #self.treeview.edit(index) #self.treemodel.reset() # end if # end def def cut(self): """ returns if the treemodel was able to cut something """ index = self.treeview.currentIndex() self.setCurrentIndex(self.treemodel.cut(index)) return self.treemodel.hasCutItem() # end def def paste(self): index = self.treeview.currentIndex() self.setCurrentIndex(self.treemodel.paste(index)) # end def def moveUp(self): index = self.treeview.currentIndex() self.setCurrentIndex(self.treemodel.moveUp(index)) # end def def moveDown(self): index = self.treeview.currentIndex() self.setCurrentIndex(self.treemodel.moveDown(index)) # end def def promote(self): index = self.treeview.currentIndex() self.setCurrentIndex(self.treemodel.promote(index)) #end def def demote(self): index = self.win.treeview.currentIndex() self.setCurrentIndex(self.treemodel.demote(index)) #end def def hideOrShowNode(self,hide, index): """""" hideThisOne = hide #and self.treemodel.isChecked(index) if index.isValid(): self.treeview.setRowHidden(index.row(), index.parent(), hideThisOne) # end if if not hideThisOne: for row in range(self.treemodel.rowCount(index)): self.hideOrShowNode(hide, self.treemodel.index(row, 0, index)) # end for # end if # end def def activated(self, index): """""" node = self.treemodel.nodeFromIndex(index) if node.ntype==PartNode.ntype: node.object_instance.partselected.emit()