6 """ |
6 """ |
7 Module implementing a dialog to edit a list of strings. |
7 Module implementing a dialog to edit a list of strings. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt6.QtCore import ( |
10 from PyQt6.QtCore import ( |
11 pyqtSlot, pyqtSignal, Qt, QSortFilterProxyModel, QStringListModel |
11 pyqtSlot, |
|
12 pyqtSignal, |
|
13 Qt, |
|
14 QSortFilterProxyModel, |
|
15 QStringListModel, |
12 ) |
16 ) |
13 from PyQt6.QtWidgets import QWidget, QInputDialog, QLineEdit |
17 from PyQt6.QtWidgets import QWidget, QInputDialog, QLineEdit |
14 |
18 |
15 from .Ui_EricStringListEditWidget import Ui_EricStringListEditWidget |
19 from .Ui_EricStringListEditWidget import Ui_EricStringListEditWidget |
16 |
20 |
17 |
21 |
18 class EricStringListEditWidget(QWidget, Ui_EricStringListEditWidget): |
22 class EricStringListEditWidget(QWidget, Ui_EricStringListEditWidget): |
19 """ |
23 """ |
20 Class implementing a dialog to edit a list of strings. |
24 Class implementing a dialog to edit a list of strings. |
21 |
25 |
22 @signal setToDefault() emitted to request the default list of values |
26 @signal setToDefault() emitted to request the default list of values |
23 """ |
27 """ |
|
28 |
24 setToDefault = pyqtSignal() |
29 setToDefault = pyqtSignal() |
25 |
30 |
26 def __init__(self, parent=None): |
31 def __init__(self, parent=None): |
27 """ |
32 """ |
28 Constructor |
33 Constructor |
29 |
34 |
30 @param parent reference to the parent widget (QWidget) |
35 @param parent reference to the parent widget (QWidget) |
31 """ |
36 """ |
32 super().__init__(parent) |
37 super().__init__(parent) |
33 self.setupUi(self) |
38 self.setupUi(self) |
34 |
39 |
35 self.__model = QStringListModel(self) |
40 self.__model = QStringListModel(self) |
36 self.__proxyModel = QSortFilterProxyModel(self) |
41 self.__proxyModel = QSortFilterProxyModel(self) |
37 self.__proxyModel.setFilterCaseSensitivity( |
42 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) |
38 Qt.CaseSensitivity.CaseInsensitive) |
|
39 self.__proxyModel.setSourceModel(self.__model) |
43 self.__proxyModel.setSourceModel(self.__model) |
40 self.stringList.setModel(self.__proxyModel) |
44 self.stringList.setModel(self.__proxyModel) |
41 |
45 |
42 self.defaultButton.hide() |
46 self.defaultButton.hide() |
43 |
47 |
44 self.searchEdit.textChanged.connect( |
48 self.searchEdit.textChanged.connect(self.__proxyModel.setFilterFixedString) |
45 self.__proxyModel.setFilterFixedString) |
49 |
46 |
|
47 self.removeButton.clicked.connect(self.stringList.removeSelected) |
50 self.removeButton.clicked.connect(self.stringList.removeSelected) |
48 self.removeAllButton.clicked.connect(self.stringList.removeAll) |
51 self.removeAllButton.clicked.connect(self.stringList.removeAll) |
49 self.defaultButton.clicked.connect(self.setToDefault) |
52 self.defaultButton.clicked.connect(self.setToDefault) |
50 |
53 |
51 def setList(self, stringList): |
54 def setList(self, stringList): |
52 """ |
55 """ |
53 Public method to set the list of strings to be edited. |
56 Public method to set the list of strings to be edited. |
54 |
57 |
55 @param stringList list of strings to be edited (list of string) |
58 @param stringList list of strings to be edited (list of string) |
56 """ |
59 """ |
57 self.__model.setStringList(stringList) |
60 self.__model.setStringList(stringList) |
58 self.__model.sort(0) |
61 self.__model.sort(0) |
59 |
62 |
60 def getList(self): |
63 def getList(self): |
61 """ |
64 """ |
62 Public method to get the edited list of strings. |
65 Public method to get the edited list of strings. |
63 |
66 |
64 @return edited list of string (list of string) |
67 @return edited list of string (list of string) |
65 """ |
68 """ |
66 return self.__model.stringList()[:] |
69 return self.__model.stringList()[:] |
67 |
70 |
68 def setListWhatsThis(self, txt): |
71 def setListWhatsThis(self, txt): |
69 """ |
72 """ |
70 Public method to set a what's that help text for the string list. |
73 Public method to set a what's that help text for the string list. |
71 |
74 |
72 @param txt help text to be set (string) |
75 @param txt help text to be set (string) |
73 """ |
76 """ |
74 self.stringList.setWhatsThis(txt) |
77 self.stringList.setWhatsThis(txt) |
75 |
78 |
76 def setDefaultVisible(self, visible): |
79 def setDefaultVisible(self, visible): |
77 """ |
80 """ |
78 Public method to show or hide the default button. |
81 Public method to show or hide the default button. |
79 |
82 |
80 @param visible flag indicating the visibility of the default button |
83 @param visible flag indicating the visibility of the default button |
81 @type bool |
84 @type bool |
82 """ |
85 """ |
83 self.defaultButton.setVisible(visible) |
86 self.defaultButton.setVisible(visible) |
84 |
87 |
85 def setAddVisible(self, visible): |
88 def setAddVisible(self, visible): |
86 """ |
89 """ |
87 Public method to show or hide the add button. |
90 Public method to show or hide the add button. |
88 |
91 |
89 @param visible flag indicating the visibility of the add button |
92 @param visible flag indicating the visibility of the add button |
90 @type bool |
93 @type bool |
91 """ |
94 """ |
92 self.addButton.setVisible(visible) |
95 self.addButton.setVisible(visible) |
93 self.addLine.setVisible(visible) |
96 self.addLine.setVisible(visible) |
94 |
97 |
95 @pyqtSlot() |
98 @pyqtSlot() |
96 def on_addButton_clicked(self): |
99 def on_addButton_clicked(self): |
97 """ |
100 """ |
98 Private slot to add an entry to the list. |
101 Private slot to add an entry to the list. |
99 """ |
102 """ |
100 entry, ok = QInputDialog.getText( |
103 entry, ok = QInputDialog.getText( |
101 self, |
104 self, |
102 self.tr("Add Entry"), |
105 self.tr("Add Entry"), |
103 self.tr("Enter the entry to add to the list:"), |
106 self.tr("Enter the entry to add to the list:"), |
104 QLineEdit.EchoMode.Normal) |
107 QLineEdit.EchoMode.Normal, |
|
108 ) |
105 if ok and entry != "" and entry not in self.__model.stringList(): |
109 if ok and entry != "" and entry not in self.__model.stringList(): |
106 self.__model.insertRow(self.__model.rowCount()) |
110 self.__model.insertRow(self.__model.rowCount()) |
107 self.__model.setData( |
111 self.__model.setData(self.__model.index(self.__model.rowCount() - 1), entry) |
108 self.__model.index(self.__model.rowCount() - 1), entry) |
|
109 self.__model.sort(0) |
112 self.__model.sort(0) |