Exemplo n.º 1
0
 def dragMoveEvent(self, event):
     """
     """
     # re-implemented so we can customise the autoExpandDelay behaviour
     if self.autoExpandDelay() >= 0:
         self.__openTimer.start(self.autoExpandDelay())
     AbstractView.dragMoveEvent(self, event)
Exemplo n.º 2
0
 def applyState(self, state):
     """
     """
     # expand indexes before calling superclass to ensure selected items are properly scrolled to
     expandOnLoad = state.get('expandOnLoad', 0)
     if type(expandOnLoad) == bool:
         expandOnLoad = -1 if expandOnLoad else 0
     self.setExpandOnLoad(expandOnLoad)
     self.applyExpandOnLoad()
     state = state or {}
     if "expanded" in state and isinstance(state["expanded"], list):
         indexFromUniqueId = self.model().indexFromUniqueId
         blocked = self.blockSignals(True)
         for uniqueId in state["expanded"]:
             index = indexFromUniqueId(uniqueId)
             if index.isValid() and not self.isExpanded(index):
                 # IMPORTANT: must layout the view before calling setExpanded() for lazy-loaded
                 # trees, otherwise expand() will not call fetchMore() and child indexes will not be loaded
                 self.executeDelayedItemsLayout()
                 self.setExpanded(index, True)
         self.blockSignals(blocked)
     AbstractView.applyState(self, state)
     if self.selectionModel() and hasattr(self.selectionModel(),
                                          "requestRefresh"):
         self.selectionModel().requestRefresh()
Exemplo n.º 3
0
 def getState(self):
     """
     """
     state = AbstractView.getState(self)
     if state is None:
         return None
     state['expandOnLoad'] = self.__expandOnLoad
     if not self.__expandOnLoad:
         # expanded indexes
         expandedIds = []
         # the expanded index list must be in order so that when we restore the expanded state,
         # parents are expanded before their children
         indexQueue = [self.rootIndex()]
         while indexQueue:
             parentIndex = indexQueue.pop(0)
             # iterate over all children of this index
             numChildren = self.model().rowCount(parentIndex)
             for i in xrange(numChildren):
                 childIndex = self.model().index(i, 0, parentIndex)
                 if childIndex.isValid() and self.isExpanded(childIndex):
                     uniqueId = self.model().uniqueIdFromIndex(childIndex)
                     if uniqueId is not None:
                         expandedIds.append(uniqueId)
                         indexQueue.append(childIndex)
         state["expanded"] = expandedIds
     return state
Exemplo n.º 4
0
 def setModel(self, model):
     """
     """
     # disconnect any existing model
     oldModel = self.model()
     if oldModel:
         oldModel.modelReset.disconnect(self.applyExpandOnLoad)
     QtGui.QTreeView.setModel(self, model)
     AbstractView.setModel(self, model)
     # tree-specific model setup
     newModel = self.model()
     # update the number of rows we think the model has because the
     # model changed, the can be updated in expandAll() if the model
     # has changed when that is called
     self.modelrows = newModel.num_items()
     newModel.modelReset.connect(self.applyExpandOnLoad)
     # set custom selection model
     self.setSelectionModel(TreeSelectionModel(newModel, self))
     # load the model data
     self.doModelRefresh()
Exemplo n.º 5
0
 def __init__(self, parent=None):
     """
     """
     QtGui.QTreeView.__init__(self, parent)
     AbstractView.__init__(self)
     self.addMenuHandler(TreeMenuHandler(self, parent=self))
     self.addMenuHandler(StandardMenuHandler(self, parent=self))
     # use custom delegate
     self.setItemDelegate(TreeDelegate(self))
     # properties
     self.__refreshOnNextCtrlRelease = False
     self.__showGrid = False
     # timer for auto-expanding branches on drag/drop
     self.__openTimer = QtCore.QTimer(self)
     self.__openTimer.timeout.connect(self.__doAutoExpand)
     # set default values for properties
     self.setAutoExpandDelay(self.AUTO_EXPAND_DELAY)
     # persistent expansion state using model's uniqueId
     self.__expandOnLoad = 0
     self.__expandAllIsExpanded = False
     # cache of the number of things in model, -1 means we haven't
     # set this yet, see setModel
     self.modelrows = -1
Exemplo n.º 6
0
 def loadSettings(self, settings):
     AbstractView.loadSettings(self, settings)
     # allow 'expand on load' to be passed from SITE cfg file.
     # 'state' is usually stored and read from the local cfg, which will override a SITE default being set
     self.setExpandOnLoad(settings['expandOnLoad'] or 0)
Exemplo n.º 7
0
 def viewportEvent(self, event):
     """
     """
     AbstractView.viewportEvent(self, event)
     return QtGui.QTreeView.viewportEvent(self, event)
Exemplo n.º 8
0
 def paintEvent(self, event):
     """
     """
     QtGui.QTreeView.paintEvent(self, event)
     AbstractView.paintEvent(self, event)
Exemplo n.º 9
0
 def restoreState(self):
     blockSignals = self.selectionModel().blockSignals
     block = blockSignals(True)
     AbstractView.restoreState(self)
     blockSignals(block)
     self.applyExpandOnLoad()
Exemplo n.º 10
0
 def setModel(self, model):
     QtGui.QTableView.setModel(self, model)
     AbstractView.setModel(self, model)
     # load the model data
     self.doModelRefresh()
Exemplo n.º 11
0
 def __init__(self, parent=None):
     QtGui.QTableView.__init__(self, parent)
     AbstractView.__init__(self)
     self.__resizeHeightToContents = False
Exemplo n.º 12
0
 def viewportEvent(self, event):
     AbstractView.viewportEvent(self, event)
     return QtGui.QTableView.viewportEvent(self, event)
Exemplo n.º 13
0
 def paintEvent(self, event):
     QtGui.QTableView.paintEvent(self, event)
     AbstractView.paintEvent(self, event)