19 |
19 |
20 class HgHisteditPlanActionComboBox(QComboBox): |
20 class HgHisteditPlanActionComboBox(QComboBox): |
21 """ |
21 """ |
22 Class implementing a combo box to select the action in the plan tree. |
22 Class implementing a combo box to select the action in the plan tree. |
23 """ |
23 """ |
|
24 |
24 def __init__(self, item, column): |
25 def __init__(self, item, column): |
25 """ |
26 """ |
26 Constructor |
27 Constructor |
27 |
28 |
28 @param item reference to the item |
29 @param item reference to the item |
29 @type QTreeWidgetItem |
30 @type QTreeWidgetItem |
30 @param column column number inside the tree widget item |
31 @param column column number inside the tree widget item |
31 @type int |
32 @type int |
32 """ |
33 """ |
33 super().__init__() |
34 super().__init__() |
34 |
35 |
35 self.__item = item |
36 self.__item = item |
36 self.__column = column |
37 self.__column = column |
37 |
38 |
38 self.addItems(["pick", "drop", "mess", "fold", "roll", "edit"]) |
39 self.addItems(["pick", "drop", "mess", "fold", "roll", "edit"]) |
39 txt = self.__item.text(self.__column) |
40 txt = self.__item.text(self.__column) |
40 index = self.findText(txt) |
41 index = self.findText(txt) |
41 if index > -1: |
42 if index > -1: |
42 self.setCurrentIndex(index) |
43 self.setCurrentIndex(index) |
43 |
44 |
44 self.currentIndexChanged.connect(self.__changeItem) |
45 self.currentIndexChanged.connect(self.__changeItem) |
45 |
46 |
46 @pyqtSlot(int) |
47 @pyqtSlot(int) |
47 def __changeItem(self, index): |
48 def __changeItem(self, index): |
48 """ |
49 """ |
49 Private slot to handle the selection of a plan action. |
50 Private slot to handle the selection of a plan action. |
50 |
51 |
51 This method sets the text of the associated item for the specified |
52 This method sets the text of the associated item for the specified |
52 cell in order to be able to retrieve it with a call of the text() |
53 cell in order to be able to retrieve it with a call of the text() |
53 method of the item. |
54 method of the item. |
54 |
55 |
55 @param index index of the selected action |
56 @param index index of the selected action |
56 @type int |
57 @type int |
57 """ |
58 """ |
58 self.__item.setText(self.__column, self.currentText()) |
59 self.__item.setText(self.__column, self.currentText()) |
59 self.__item.treeWidget().setCurrentItem(self.__item) |
60 self.__item.treeWidget().setCurrentItem(self.__item) |
60 |
61 |
61 def showPopup(self): |
62 def showPopup(self): |
62 """ |
63 """ |
63 Public method to show the list of items of the combo box. |
64 Public method to show the list of items of the combo box. |
64 |
65 |
65 This is reimplemented in order to set the associated item as the |
66 This is reimplemented in order to set the associated item as the |
66 current item of the tree widget. |
67 current item of the tree widget. |
67 """ |
68 """ |
68 self.__item.treeWidget().setCurrentItem(self.__item) |
69 self.__item.treeWidget().setCurrentItem(self.__item) |
69 super().showPopup() |
70 super().showPopup() |
71 |
72 |
72 class HgHisteditPlanEditor(QDialog, Ui_HgHisteditPlanEditor): |
73 class HgHisteditPlanEditor(QDialog, Ui_HgHisteditPlanEditor): |
73 """ |
74 """ |
74 Class implementing a dialog to edit the history modification plan. |
75 Class implementing a dialog to edit the history modification plan. |
75 """ |
76 """ |
|
77 |
76 def __init__(self, fileName, parent=None): |
78 def __init__(self, fileName, parent=None): |
77 """ |
79 """ |
78 Constructor |
80 Constructor |
79 |
81 |
80 @param fileName name of the file containing the history edit plan |
82 @param fileName name of the file containing the history edit plan |
81 to be edited |
83 to be edited |
82 @type str |
84 @type str |
83 @param parent reference to the parent widget |
85 @param parent reference to the parent widget |
84 @type QWidget |
86 @type QWidget |
85 """ |
87 """ |
86 super().__init__(parent) |
88 super().__init__(parent) |
87 self.setupUi(self) |
89 self.setupUi(self) |
88 |
90 |
89 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) |
91 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) |
90 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) |
92 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) |
91 |
93 |
92 self.planTreeWidget.headerItem().setText( |
94 self.planTreeWidget.headerItem().setText(self.planTreeWidget.columnCount(), "") |
93 self.planTreeWidget.columnCount(), "") |
95 |
94 |
|
95 self.__fileName = fileName |
96 self.__fileName = fileName |
96 self.__readFile() |
97 self.__readFile() |
97 |
98 |
98 self.__updateButtons() |
99 self.__updateButtons() |
99 |
100 |
100 def __readFile(self): |
101 def __readFile(self): |
101 """ |
102 """ |
102 Private method to read the file containing the edit plan and |
103 Private method to read the file containing the edit plan and |
103 populate the dialog. |
104 populate the dialog. |
104 """ |
105 """ |
107 txt = f.read() |
108 txt = f.read() |
108 except OSError as err: |
109 except OSError as err: |
109 EricMessageBox.critical( |
110 EricMessageBox.critical( |
110 self, |
111 self, |
111 self.tr("Edit Plan"), |
112 self.tr("Edit Plan"), |
112 self.tr("""<p>The file <b>{0}</b> could not be read.</p>""" |
113 self.tr( |
113 """<p>Reason: {1}</p>""").format( |
114 """<p>The file <b>{0}</b> could not be read.</p>""" |
114 self.__fileName, str(err))) |
115 """<p>Reason: {1}</p>""" |
|
116 ).format(self.__fileName, str(err)), |
|
117 ) |
115 self.on_buttonBox_rejected() |
118 self.on_buttonBox_rejected() |
116 return |
119 return |
117 |
120 |
118 infoLines = [] |
121 infoLines = [] |
119 for line in txt.splitlines(): |
122 for line in txt.splitlines(): |
120 if line.startswith("#"): |
123 if line.startswith("#"): |
121 infoLines.append(line[1:].lstrip()) |
124 infoLines.append(line[1:].lstrip()) |
122 else: |
125 else: |
123 self.__createPlanItem(line) |
126 self.__createPlanItem(line) |
124 self.infoEdit.setPlainText("\n".join(infoLines)) |
127 self.infoEdit.setPlainText("\n".join(infoLines)) |
125 |
128 |
126 self.__resizeSections() |
129 self.__resizeSections() |
127 |
130 |
128 def __addActionCombo(self, item): |
131 def __addActionCombo(self, item): |
129 """ |
132 """ |
130 Private method to add an edit action combo to an item. |
133 Private method to add an edit action combo to an item. |
131 |
134 |
132 @param item reference to the tree widget item |
135 @param item reference to the tree widget item |
133 @type QTreeWidgetItem |
136 @type QTreeWidgetItem |
134 """ |
137 """ |
135 actionCombo = HgHisteditPlanActionComboBox(item, 0) |
138 actionCombo = HgHisteditPlanActionComboBox(item, 0) |
136 self.planTreeWidget.setItemWidget(item, 0, actionCombo) |
139 self.planTreeWidget.setItemWidget(item, 0, actionCombo) |
137 item.setSizeHint(0, actionCombo.sizeHint()) |
140 item.setSizeHint(0, actionCombo.sizeHint()) |
138 |
141 |
139 def __createPlanItem(self, text): |
142 def __createPlanItem(self, text): |
140 """ |
143 """ |
141 Private method to create an edit plan tree item. |
144 Private method to create an edit plan tree item. |
142 |
145 |
143 @param text line of text to be parsed |
146 @param text line of text to be parsed |
144 @type str |
147 @type str |
145 """ |
148 """ |
146 if not text.lstrip(): |
149 if not text.lstrip(): |
147 return |
150 return |
148 |
151 |
149 parts = text.split(" ", 3) |
152 parts = text.split(" ", 3) |
150 action = parts[0] |
153 action = parts[0] |
151 try: |
154 try: |
152 rev = int(parts[2]) |
155 rev = int(parts[2]) |
153 summary = parts[3] if len(parts) > 3 else "" |
156 summary = parts[3] if len(parts) > 3 else "" |
154 except ValueError: |
157 except ValueError: |
155 rev = -1 |
158 rev = -1 |
156 summary = " ".join(parts[2:]) |
159 summary = " ".join(parts[2:]) |
157 revision = ("{0:>7}:{1}".format(rev, parts[1]) |
160 revision = "{0:>7}:{1}".format(rev, parts[1]) if rev > -1 else parts[1] |
158 if rev > -1 else parts[1]) |
161 |
159 |
162 itm = QTreeWidgetItem( |
160 itm = QTreeWidgetItem(self.planTreeWidget, [ |
163 self.planTreeWidget, |
161 action, |
164 [ |
162 revision, |
165 action, |
163 summary, |
166 revision, |
164 ]) |
167 summary, |
|
168 ], |
|
169 ) |
165 self.__addActionCombo(itm) |
170 self.__addActionCombo(itm) |
166 |
171 |
167 def __resizeSections(self): |
172 def __resizeSections(self): |
168 """ |
173 """ |
169 Private method to resize the tree widget sections. |
174 Private method to resize the tree widget sections. |
170 """ |
175 """ |
171 for column in range(self.planTreeWidget.columnCount()): |
176 for column in range(self.planTreeWidget.columnCount()): |
172 self.planTreeWidget.resizeColumnToContents(column) |
177 self.planTreeWidget.resizeColumnToContents(column) |
173 self.planTreeWidget.header().setStretchLastSection(True) |
178 self.planTreeWidget.header().setStretchLastSection(True) |
174 |
179 |
175 def __updateButtons(self): |
180 def __updateButtons(self): |
176 """ |
181 """ |
177 Private method to set the enabled state of the up and down buttons. |
182 Private method to set the enabled state of the up and down buttons. |
178 """ |
183 """ |
179 if self.planTreeWidget.currentItem() is None: |
184 if self.planTreeWidget.currentItem() is None: |
180 self.upButton.setEnabled(False) |
185 self.upButton.setEnabled(False) |
181 self.downButton.setEnabled(False) |
186 self.downButton.setEnabled(False) |
182 else: |
187 else: |
183 row = self.planTreeWidget.indexOfTopLevelItem( |
188 row = self.planTreeWidget.indexOfTopLevelItem( |
184 self.planTreeWidget.currentItem()) |
189 self.planTreeWidget.currentItem() |
|
190 ) |
185 self.upButton.setEnabled(row > 0) |
191 self.upButton.setEnabled(row > 0) |
186 self.downButton.setEnabled( |
192 self.downButton.setEnabled( |
187 row < self.planTreeWidget.topLevelItemCount() - 1) |
193 row < self.planTreeWidget.topLevelItemCount() - 1 |
188 |
194 ) |
|
195 |
189 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
196 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
190 def on_planTreeWidget_currentItemChanged(self, current, previous): |
197 def on_planTreeWidget_currentItemChanged(self, current, previous): |
191 """ |
198 """ |
192 Private slot handling the change of the current edit plan item. |
199 Private slot handling the change of the current edit plan item. |
193 |
200 |
194 @param current reference to the current edit plan item |
201 @param current reference to the current edit plan item |
195 @type QTreeWidgetItem |
202 @type QTreeWidgetItem |
196 @param previous reference to the previous current edit plan item |
203 @param previous reference to the previous current edit plan item |
197 @type QTreeWidgetItem |
204 @type QTreeWidgetItem |
198 """ |
205 """ |
199 self.__updateButtons() |
206 self.__updateButtons() |
200 |
207 |
201 @pyqtSlot() |
208 @pyqtSlot() |
202 def on_upButton_clicked(self): |
209 def on_upButton_clicked(self): |
203 """ |
210 """ |
204 Private slot to move the current entry up one line. |
211 Private slot to move the current entry up one line. |
205 """ |
212 """ |
206 row = self.planTreeWidget.indexOfTopLevelItem( |
213 row = self.planTreeWidget.indexOfTopLevelItem(self.planTreeWidget.currentItem()) |
207 self.planTreeWidget.currentItem()) |
|
208 if row > 0: |
214 if row > 0: |
209 targetRow = row - 1 |
215 targetRow = row - 1 |
210 itm = self.planTreeWidget.takeTopLevelItem(row) |
216 itm = self.planTreeWidget.takeTopLevelItem(row) |
211 self.planTreeWidget.insertTopLevelItem(targetRow, itm) |
217 self.planTreeWidget.insertTopLevelItem(targetRow, itm) |
212 self.__addActionCombo(itm) |
218 self.__addActionCombo(itm) |
213 self.planTreeWidget.setCurrentItem(itm) |
219 self.planTreeWidget.setCurrentItem(itm) |
214 |
220 |
215 @pyqtSlot() |
221 @pyqtSlot() |
216 def on_downButton_clicked(self): |
222 def on_downButton_clicked(self): |
217 """ |
223 """ |
218 Private slot to move the current entry down one line. |
224 Private slot to move the current entry down one line. |
219 """ |
225 """ |
220 row = self.planTreeWidget.indexOfTopLevelItem( |
226 row = self.planTreeWidget.indexOfTopLevelItem(self.planTreeWidget.currentItem()) |
221 self.planTreeWidget.currentItem()) |
|
222 if row < self.planTreeWidget.topLevelItemCount() - 1: |
227 if row < self.planTreeWidget.topLevelItemCount() - 1: |
223 targetRow = row + 1 |
228 targetRow = row + 1 |
224 itm = self.planTreeWidget.takeTopLevelItem(row) |
229 itm = self.planTreeWidget.takeTopLevelItem(row) |
225 self.planTreeWidget.insertTopLevelItem(targetRow, itm) |
230 self.planTreeWidget.insertTopLevelItem(targetRow, itm) |
226 self.__addActionCombo(itm) |
231 self.__addActionCombo(itm) |
227 self.planTreeWidget.setCurrentItem(itm) |
232 self.planTreeWidget.setCurrentItem(itm) |
228 |
233 |
229 @pyqtSlot() |
234 @pyqtSlot() |
230 def on_buttonBox_accepted(self): |
235 def on_buttonBox_accepted(self): |
231 """ |
236 """ |
232 Private slot called by the buttonBox accepted signal. |
237 Private slot called by the buttonBox accepted signal. |
233 """ |
238 """ |