eric6/E5Gui/E5ModelToolBar.py

changeset 7628
f904d0eef264
parent 7360
9190402e4505
child 7759
51aa6c6b66f7
equal deleted inserted replaced
7626:7f643d41464e 7628:f904d0eef264
100 100
101 def _build(self): 101 def _build(self):
102 """ 102 """
103 Protected slot to build the tool bar. 103 Protected slot to build the tool bar.
104 """ 104 """
105 assert self.__model is not None 105 if self.__model is None:
106 return
106 107
107 self.clear() 108 self.clear()
108 109
109 for i in range(self.__model.rowCount(self.__root)): 110 for i in range(self.__model.rowCount(self.__root)):
110 idx = self.__model.index(i, 0, self.__root) 111 idx = self.__model.index(i, 0, self.__root)
195 def dropEvent(self, evt): 196 def dropEvent(self, evt):
196 """ 197 """
197 Protected method to handle drop events. 198 Protected method to handle drop events.
198 199
199 @param evt reference to the event (QDropEvent) 200 @param evt reference to the event (QDropEvent)
201 @exception RuntimeError raised to indicate an invalid model index
200 """ 202 """
201 if self.__model is not None: 203 if self.__model is not None:
202 act = self.actionAt(evt.pos()) 204 act = self.actionAt(evt.pos())
203 parentIndex = self.__root 205 parentIndex = self.__root
204 if act is None: 206 if act is None:
205 row = self.__model.rowCount(self.__root) 207 row = self.__model.rowCount(self.__root)
206 else: 208 else:
207 idx = self.index(act) 209 idx = self.index(act)
208 assert idx.isValid() 210 if not idx.isValid():
211 raise RuntimeError("invalid index")
209 row = idx.row() 212 row = idx.row()
210 if self.__model.hasChildren(idx): 213 if self.__model.hasChildren(idx):
211 parentIndex = idx 214 parentIndex = idx
212 row = self.__model.rowCount(idx) 215 row = self.__model.rowCount(idx)
213 216
222 def mouseMoveEvent(self, evt): 225 def mouseMoveEvent(self, evt):
223 """ 226 """
224 Protected method to handle mouse move events. 227 Protected method to handle mouse move events.
225 228
226 @param evt reference to the event (QMouseEvent) 229 @param evt reference to the event (QMouseEvent)
230 @exception RuntimeError raised to indicate an invalid model index
227 """ 231 """
228 if self.__model is None: 232 if self.__model is None:
229 super(E5ModelToolBar, self).mouseMoveEvent(evt) 233 super(E5ModelToolBar, self).mouseMoveEvent(evt)
230 return 234 return
231 235
243 if act is None: 247 if act is None:
244 super(E5ModelToolBar, self).mouseMoveEvent(evt) 248 super(E5ModelToolBar, self).mouseMoveEvent(evt)
245 return 249 return
246 250
247 idx = self.index(act) 251 idx = self.index(act)
248 assert idx.isValid() 252 if not idx.isValid():
253 raise RuntimeError("invalid index")
249 254
250 drag = QDrag(self) 255 drag = QDrag(self)
251 drag.setMimeData(self.__model.mimeData([idx])) 256 drag.setMimeData(self.__model.mimeData([idx]))
252 actionRect = self.actionGeometry(act) 257 actionRect = self.actionGeometry(act)
253 drag.setPixmap(self.grab(actionRect)) 258 drag.setPixmap(self.grab(actionRect))

eric ide

mercurial