18 class E5ListSelectionDialog(QDialog, Ui_E5ListSelectionDialog): |
18 class E5ListSelectionDialog(QDialog, Ui_E5ListSelectionDialog): |
19 """ |
19 """ |
20 Class implementing a dialog to select from a list of strings. |
20 Class implementing a dialog to select from a list of strings. |
21 """ |
21 """ |
22 def __init__(self, entries, |
22 def __init__(self, entries, |
23 selectionMode=QAbstractItemView.ExtendedSelection, |
23 selectionMode=QAbstractItemView.SelectionMode |
|
24 .ExtendedSelection, |
24 title="", message="", checkBoxSelection=False, parent=None): |
25 title="", message="", checkBoxSelection=False, parent=None): |
25 """ |
26 """ |
26 Constructor |
27 Constructor |
27 |
28 |
28 @param entries list of entries to select from |
29 @param entries list of entries to select from |
48 self.messageLabel.setText(message) |
49 self.messageLabel.setText(message) |
49 |
50 |
50 self.__checkCount = 0 |
51 self.__checkCount = 0 |
51 self.__isCheckBoxSelection = checkBoxSelection |
52 self.__isCheckBoxSelection = checkBoxSelection |
52 if self.__isCheckBoxSelection: |
53 if self.__isCheckBoxSelection: |
53 self.selectionList.setSelectionMode(QAbstractItemView.NoSelection) |
54 self.selectionList.setSelectionMode( |
|
55 QAbstractItemView.SelectionMode.NoSelection) |
54 for entry in entries: |
56 for entry in entries: |
55 itm = QListWidgetItem(entry) |
57 itm = QListWidgetItem(entry) |
56 itm.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) |
58 itm.setFlags(Qt.ItemFlag.ItemIsUserCheckable | |
57 itm.setCheckState(Qt.Unchecked) |
59 Qt.ItemFlag.ItemIsEnabled) |
|
60 itm.setCheckState(Qt.CheckState.Unchecked) |
58 self.selectionList.addItem(itm) |
61 self.selectionList.addItem(itm) |
59 else: |
62 else: |
60 self.selectionList.setSelectionMode(selectionMode) |
63 self.selectionList.setSelectionMode(selectionMode) |
61 self.selectionList.addItems(entries) |
64 self.selectionList.addItems(entries) |
62 |
65 |
63 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
66 self.buttonBox.button( |
|
67 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
64 |
68 |
65 @pyqtSlot() |
69 @pyqtSlot() |
66 def on_selectionList_itemSelectionChanged(self): |
70 def on_selectionList_itemSelectionChanged(self): |
67 """ |
71 """ |
68 Private slot handling a change of the selection. |
72 Private slot handling a change of the selection. |
69 """ |
73 """ |
70 if not self.__isCheckBoxSelection: |
74 if not self.__isCheckBoxSelection: |
71 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
75 self.buttonBox.button( |
72 len(self.selectionList.selectedItems()) > 0) |
76 QDialogButtonBox.StandardButton.Ok).setEnabled( |
|
77 len(self.selectionList.selectedItems()) > 0) |
73 |
78 |
74 def on_selectionList_itemChanged(self, itm): |
79 def on_selectionList_itemChanged(self, itm): |
75 """ |
80 """ |
76 Private slot handling a change of an item. |
81 Private slot handling a change of an item. |
77 |
82 |
78 @param itm reference to the changed item |
83 @param itm reference to the changed item |
79 @type QListWidgetItem |
84 @type QListWidgetItem |
80 """ |
85 """ |
81 if self.__isCheckBoxSelection: |
86 if self.__isCheckBoxSelection: |
82 if itm.checkState() == Qt.Checked: |
87 if itm.checkState() == Qt.CheckState.Checked: |
83 self.__checkCount += 1 |
88 self.__checkCount += 1 |
84 else: |
89 else: |
85 self.__checkCount -= 1 |
90 self.__checkCount -= 1 |
86 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
91 self.buttonBox.button( |
|
92 QDialogButtonBox.StandardButton.Ok).setEnabled( |
87 self.__checkCount > 0) |
93 self.__checkCount > 0) |
88 |
94 |
89 def getSelection(self): |
95 def getSelection(self): |
90 """ |
96 """ |
91 Public method to retrieve the selected items. |
97 Public method to retrieve the selected items. |
95 """ |
101 """ |
96 entries = [] |
102 entries = [] |
97 if self.__isCheckBoxSelection: |
103 if self.__isCheckBoxSelection: |
98 for row in range(self.selectionList.count()): |
104 for row in range(self.selectionList.count()): |
99 item = self.selectionList.item(row) |
105 item = self.selectionList.item(row) |
100 if item.checkState() == Qt.Checked: |
106 if item.checkState() == Qt.CheckState.Checked: |
101 entries.append(item.text()) |
107 entries.append(item.text()) |
102 else: |
108 else: |
103 for item in self.selectionList.selectedItems(): |
109 for item in self.selectionList.selectedItems(): |
104 entries.append(item.text()) |
110 entries.append(item.text()) |
105 return entries |
111 return entries |