UI/BrowserModel.py

changeset 4183
856ba07de877
parent 4107
501c964e20e7
child 4529
6becda664299
equal deleted inserted replaced
4182:a84cadf71513 4183:856ba07de877
34 BrowserItemClass = 4 34 BrowserItemClass = 4
35 BrowserItemMethod = 5 35 BrowserItemMethod = 5
36 BrowserItemAttributes = 6 36 BrowserItemAttributes = 6
37 BrowserItemAttribute = 7 37 BrowserItemAttribute = 7
38 BrowserItemCoding = 8 38 BrowserItemCoding = 8
39 BrowserItemImports = 9
40 BrowserItemImport = 10
39 41
40 42
41 class BrowserModel(QAbstractItemModel): 43 class BrowserModel(QAbstractItemModel):
42 """ 44 """
43 Class implementing the browser model. 45 Class implementing the browser model.
637 node = BrowserClassAttributesItem( 639 node = BrowserClassAttributesItem(
638 parentItem, 640 parentItem,
639 dict["@@Globals@@"].globals, 641 dict["@@Globals@@"].globals,
640 QCoreApplication.translate("BrowserModel", "Globals")) 642 QCoreApplication.translate("BrowserModel", "Globals"))
641 self._addItem(node, parentItem) 643 self._addItem(node, parentItem)
644 if "@@Import@@" in keys or "@@ImportFrom@@" in keys:
645 node = BrowserImportsItem(
646 parentItem,
647 QCoreApplication.translate("BrowserModel", "Imports"))
648 self._addItem(node, parentItem)
649 if "@@Import@@" in keys:
650 for importedModule in \
651 dict["@@Import@@"].getImports().values():
652 m_node = BrowserImportItem(
653 node,
654 importedModule.importedModuleName,
655 importedModule.file,
656 importedModule.linenos)
657 self._addItem(m_node, node)
658 for importedName, linenos in \
659 importedModule.importedNames.items():
660 mn_node = BrowserImportItem(
661 m_node,
662 importedName,
663 importedModule.file,
664 linenos,
665 isModule=False)
666 self._addItem(mn_node, m_node)
642 if repopulate: 667 if repopulate:
643 self.endInsertRows() 668 self.endInsertRows()
644 parentItem._populated = True 669 parentItem._populated = True
645 670
646 def populateClassItem(self, parentItem, repopulate=False): 671 def populateClassItem(self, parentItem, repopulate=False):
1739 @param column column number to use for the comparison (integer) 1764 @param column column number to use for the comparison (integer)
1740 @param order sort order (Qt.SortOrder) (for special sorting) 1765 @param order sort order (Qt.SortOrder) (for special sorting)
1741 @return true, if this item is less than other (boolean) 1766 @return true, if this item is less than other (boolean)
1742 """ 1767 """
1743 if issubclass(other.__class__, BrowserClassItem) or \ 1768 if issubclass(other.__class__, BrowserClassItem) or \
1769 issubclass(other.__class__, BrowserClassAttributesItem) or \
1770 issubclass(other.__class__, BrowserImportItem):
1771 return order == Qt.AscendingOrder
1772
1773 return BrowserItem.lessThan(self, other, column, order)
1774
1775
1776 class BrowserImportsItem(BrowserItem):
1777 """
1778 Class implementing the data structure for browser import items.
1779 """
1780 def __init__(self, parent, text):
1781 """
1782 Constructor
1783
1784 @param parent parent item
1785 @param text text to be shown by this item (string)
1786 """
1787 BrowserItem.__init__(self, parent, text)
1788
1789 self.type_ = BrowserItemImports
1790 self.icon = UI.PixmapCache.getIcon("imports.png")
1791
1792 def lessThan(self, other, column, order):
1793 """
1794 Public method to check, if the item is less than the other one.
1795
1796 @param other reference to item to compare against (BrowserItem)
1797 @param column column number to use for the comparison (integer)
1798 @param order sort order (Qt.SortOrder) (for special sorting)
1799 @return true, if this item is less than other (boolean)
1800 """
1801 if issubclass(other.__class__, BrowserClassItem) or \
1744 issubclass(other.__class__, BrowserClassAttributesItem): 1802 issubclass(other.__class__, BrowserClassAttributesItem):
1745 return order == Qt.AscendingOrder 1803 return order == Qt.AscendingOrder
1746 1804
1747 return BrowserItem.lessThan(self, other, column, order) 1805 return BrowserItem.lessThan(self, other, column, order)
1806
1807
1808 class BrowserImportItem(BrowserItem):
1809 """
1810 Class implementing the data structure for browser imported module and
1811 imported names items.
1812 """
1813 def __init__(self, parent, text, filename, lineNumbers, isModule=True):
1814 """
1815 Constructor
1816
1817 @param parent parent item
1818 @param text text to be shown by this item (string)
1819 @param filename name of the file (string)
1820 @param lineNumbers list of line numbers of the import statement
1821 (list of integer)
1822 @param isModule flag indicating a module item entry (boolean)
1823 """
1824 BrowserItem.__init__(self, parent, text)
1825
1826 self.__filename = filename
1827 self.__linenos = lineNumbers[:]
1828
1829 self.type_ = BrowserItemImport
1830 if isModule:
1831 self.icon = UI.PixmapCache.getIcon("importedModule.png")
1832 else:
1833 self.icon = UI.PixmapCache.getIcon("importedName.png")
1834
1835 def fileName(self):
1836 """
1837 Public method returning the filename.
1838
1839 @return filename (string)
1840 """
1841 return self.__filename
1842
1843 def lineno(self):
1844 """
1845 Public method returning the line number of the first import.
1846
1847 @return line number of the first import (integer)
1848 """
1849 return self.__linenos[0]
1850
1851 def linenos(self):
1852 """
1853 Public method returning the line numbers of all imports.
1854
1855 @return line numbers of all imports (list of integers)
1856 """
1857 return self.__linenos[:]
1858
1859 def lessThan(self, other, column, order):
1860 """
1861 Public method to check, if the item is less than the other one.
1862
1863 @param other reference to item to compare against (BrowserItem)
1864 @param column column number to use for the comparison (integer)
1865 @param order sort order (Qt.SortOrder) (for special sorting)
1866 @return true, if this item is less than other (boolean)
1867 """
1868 if Preferences.getUI("BrowsersListContentsByOccurrence") and \
1869 column == 0:
1870 if order == Qt.AscendingOrder:
1871 return self.lineno() < other.lineno()
1872 else:
1873 return self.lineno() > other.lineno()
1874
1875 return BrowserItem.lessThan(self, other, column, order)

eric ide

mercurial