Project/ProjectBrowserModel.py

branch
Py2 comp.
changeset 2791
a9577f248f04
parent 2677
3d4277929fb3
parent 2769
8cbebde7a984
child 3057
10516539f238
equal deleted inserted replaced
2790:6686a3326df8 2791:a9577f248f04
435 self.inRefresh = False 435 self.inRefresh = False
436 self.reset() 436 self.reset()
437 437
438 def findParentItemByName(self, type_, name, dontSplit=False): 438 def findParentItemByName(self, type_, name, dontSplit=False):
439 """ 439 """
440 Public method to find an item given it's name. 440 Public method to find an item given its name.
441 441
442 <b>Note</b>: This method creates all necessary parent items, if they 442 <b>Note</b>: This method creates all necessary parent items, if they
443 don't exist. 443 don't exist.
444 444
445 @param type_ type of the item 445 @param type_ type of the item
554 self.dataChanged.emit(index, index) 554 self.dataChanged.emit(index, index)
555 self.repopulateItem(newFilename) 555 self.repopulateItem(newFilename)
556 556
557 def findItem(self, name): 557 def findItem(self, name):
558 """ 558 """
559 Public method to find an item given it's name. 559 Public method to find an item given its name.
560 560
561 @param name name of the item (string) 561 @param name name of the item (string)
562 @return reference to the item found 562 @return reference to the item found
563 """ 563 """
564 if QDir.isAbsolutePath(name): 564 if QDir.isAbsolutePath(name):
575 else: 575 else:
576 return None 576 return None
577 577
578 def itemIndexByName(self, name): 578 def itemIndexByName(self, name):
579 """ 579 """
580 Public method to find an item's index given it's name. 580 Public method to find an item's index given its name.
581 581
582 @param name name of the item (string) 582 @param name name of the item (string)
583 @return index of the item found (QModelIndex) 583 @return index of the item found (QModelIndex)
584 """ 584 """
585 itm = self.findItem(name) 585 itm = self.findItem(name)
586 if itm is None: 586 if itm is None:
587 index = QModelIndex() 587 index = QModelIndex()
588 else: 588 else:
589 index = self.createIndex(itm.row(), 0, itm) 589 index = self.createIndex(itm.row(), 0, itm)
590 return index
591
592 def itemIndexByNameAndLine(self, name, lineno):
593 """
594 Public method to find an item's index given its name.
595
596 @param name name of the item (string)
597 @param lineno one based line number of the item (integer)
598 @return index of the item found (QModelIndex)
599 """
600 index = QModelIndex()
601 itm = self.findItem(name)
602 if itm is not None and \
603 isinstance(itm, ProjectBrowserFileItem):
604 olditem = itm
605 autoPopulate = Preferences.getProject("AutoPopulateItems")
606 while itm is not None:
607 if not itm.isPopulated():
608 if itm.isLazyPopulated() and autoPopulate:
609 self.populateItem(itm)
610 else:
611 break
612 for child in itm.children():
613 try:
614 start, end = child.boundaries()
615 if end == -1:
616 end = 1000000 # assume end of file
617 if start <= lineno <= end:
618 itm = child
619 break
620 except AttributeError:
621 pass
622 else:
623 itm = None
624 if itm:
625 olditem = itm
626 index = self.createIndex(olditem.row(), 0, olditem)
627
590 return index 628 return index
591 629
592 def directoryChanged(self, path): 630 def directoryChanged(self, path):
593 """ 631 """
594 Public slot to handle the directoryChanged signal of the watcher. 632 Public slot to handle the directoryChanged signal of the watcher.

eric ide

mercurial