24
26
@param project reference to the project object
25
27
@param parent reference to the parent widget (QWidget)
27
FiletypeAssociationForm.__init__(self, parent, None, 1)
29
QDialog.__init__(self, parent)
32
self.filetypeAssociationList.header().setSortIndicator(0, Qt.AscendingOrder)
29
34
# keep these lists in sync
30
self.filetypes = ["SOURCES", "FORMS", "INTERFACES", "OTHERS"]
35
self.filetypes = ["SOURCES", "FORMS", "RESOURCES", "INTERFACES", "OTHERS"]
31
36
self.filetypeStrings = [self.trUtf8("Sources"), self.trUtf8("Forms"),
37
self.trUtf8("Resources"),
32
38
self.trUtf8("Interfaces"), self.trUtf8("Others")]
33
39
self.filetypesList = QStringList()
34
40
for fts in self.filetypeStrings:
35
41
self.filetypesList.append(fts)
36
self.filetypeCombo.insertStringList(self.filetypesList)
42
self.filetypeCombo.addItems(self.filetypesList)
38
44
self.project = project
39
45
for pattern, filetype in self.project.pdata["FILETYPES"].items():
41
47
index = self.filetypes.index(filetype)
42
itm = QListViewItem(self.filetypeAssociationList, pattern,
43
self.filetypeStrings[index])
48
itm = self.__createItem(pattern, self.filetypeStrings[index])
45
50
pass # silently discard entries of unknown type
47
def handleAssociationSelected(self, itm):
49
Private slot to handle the clicked signal of the association list.
51
@param itm reference to the selecte item (QListViewItem)
57
Private method to resort the tree.
59
self.filetypeAssociationList.sortItems(self.filetypeAssociationList.sortColumn(),
60
self.filetypeAssociationList.header().sortIndicatorOrder())
64
Private method to reformat the tree.
66
self.filetypeAssociationList.header().resizeSections(QHeaderView.ResizeToContents)
67
self.filetypeAssociationList.header().setStretchLastSection(True)
69
def __createItem(self, pattern, filetype):
71
Private slot to create a new entry in the association list.
73
@param pattern pattern of the entry (string or QString)
74
@param filetype file type of the entry (string or QString)
75
@return reference to the newly generated entry (QTreeWidgetItem)
77
itm = QTreeWidgetItem(self.filetypeAssociationList,
78
QStringList() << pattern << filetype)
81
def on_filetypeAssociationList_currentItemChanged(self, itm, prevItm):
83
Private slot to handle the currentItemChanged signal of the association list.
85
@param itm reference to the new current item (QTreeWidgetItem)
86
@param prevItm reference to the previous current item (QTreeWidgetItem)
54
89
self.filePatternEdit.clear()
55
self.filetypeCombo.setCurrentItem(0)
56
self.deleteAssociationButton.setEnabled(0)
90
self.filetypeCombo.setCurrentIndex(0)
91
self.deleteAssociationButton.setEnabled(False)
58
93
self.filePatternEdit.setText(itm.text(0))
59
self.filetypeCombo.setCurrentText(itm.text(1))
60
self.deleteAssociationButton.setEnabled(1)
94
self.filetypeCombo.setCurrentIndex(self.filetypeCombo.findText(itm.text(1)))
95
self.deleteAssociationButton.setEnabled(True)
62
def handleAssociationAdd(self):
98
def on_addAssociationButton_clicked(self):
64
Private slot to add the association displayed to the listbox.
100
Private slot to add the association displayed to the list.
66
102
pattern = self.filePatternEdit.text()
67
103
filetype = self.filetypeCombo.currentText()
68
104
if not pattern.isEmpty():
69
itm = self.filetypeAssociationList.findItem(pattern, 0)
71
self.filetypeAssociationList.takeItem(itm)
105
items = self.filetypeAssociationList.findItems(\
106
pattern, Qt.MatchFlags(Qt.MatchExactly), 0)
108
itm = self.filetypeAssociationList.takeTopLevelItem(\
109
self.filetypeAssociationList.indexOfTopLevelItem(itm))
73
itm = QListViewItem(self.filetypeAssociationList, pattern, filetype)
111
itm = self.__createItem(pattern, filetype)
74
114
self.filePatternEdit.clear()
75
self.filetypeCombo.setCurrentItem(0)
76
self.filetypeAssociationList.setSelected(itm, 1)
115
self.filetypeCombo.setCurrentIndex(0)
116
self.filetypeAssociationList.setCurrentItem(itm)
78
def handleAssociationDelete(self):
119
def on_deleteAssociationButton_clicked(self):
80
121
Private slot to delete the currently selected association of the listbox.
82
itm = self.filetypeAssociationList.selectedItem()
84
self.filetypeAssociationList.takeItem(itm)
123
for itm in self.filetypeAssociationList.selectedItems():
124
itm = self.filetypeAssociationList.takeTopLevelItem(\
125
self.filetypeAssociationList.indexOfTopLevelItem(itm))
87
128
self.filetypeAssociationList.clearSelection()
88
129
self.filePatternEdit.clear()
89
self.filetypeCombo.setCurrentItem(0)
130
self.filetypeCombo.setCurrentIndex(0)
91
def handlePatternTextChanged(self, txt):
132
def on_filePatternEdit_textChanged(self, txt):
93
134
Private slot to handle the textChanged signal of the pattern lineedit.
95
136
@param txt text of the lineedit (QString)
98
self.addAssociationButton.setEnabled(0)
99
self.deleteAssociationButton.setEnabled(0)
139
self.addAssociationButton.setEnabled(False)
140
self.deleteAssociationButton.setEnabled(False)
101
self.addAssociationButton.setEnabled(1)
102
if self.filetypeAssociationList.selectedItem() is None:
103
self.deleteAssociationButton.setEnabled(0)
142
self.addAssociationButton.setEnabled(True)
143
if len(self.filetypeAssociationList.selectedItems()) == 0:
144
self.deleteAssociationButton.setEnabled(False)
105
self.deleteAssociationButton.setEnabled(1)
146
self.deleteAssociationButton.setEnabled(\
147
self.filetypeAssociationList.selectedItems()[0].text(0) == txt)
107
149
def transferData(self):
109
151
Public slot to transfer the associations into the projects data structure.
111
153
self.project.pdata["FILETYPES"] = {}
112
itm = self.filetypeAssociationList.firstChild()
113
while itm is not None:
154
for index in range(self.filetypeAssociationList.topLevelItemCount()):
155
itm = self.filetypeAssociationList.topLevelItem(index)
114
156
pattern = unicode(itm.text(0))
115
157
index = self.filetypeStrings.index(itm.text(1))
116
158
self.project.pdata["FILETYPES"][pattern] = self.filetypes[index]
117
itm = itm.nextSibling()