96 |
96 |
97 @param index index of the model cell (QModelIndex) |
97 @param index index of the model cell (QModelIndex) |
98 @return flags (Qt.ItemFlags) |
98 @return flags (Qt.ItemFlags) |
99 """ |
99 """ |
100 if index.column() == 1: |
100 if index.column() == 1: |
101 return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable |
101 return ( |
|
102 Qt.ItemFlag.ItemIsEnabled | |
|
103 Qt.ItemFlag.ItemIsSelectable | |
|
104 Qt.ItemFlag.ItemIsEditable |
|
105 ) |
102 else: |
106 else: |
103 return Qt.ItemIsEnabled | Qt.ItemIsSelectable |
107 return ( |
|
108 Qt.ItemFlag.ItemIsEnabled | |
|
109 Qt.ItemFlag.ItemIsSelectable |
|
110 ) |
104 |
111 |
105 def data(self, index, role): |
112 def data(self, index, role): |
106 """ |
113 """ |
107 Public method to get data from the model. |
114 Public method to get data from the model. |
108 |
115 |
118 |
125 |
119 if engine is None: |
126 if engine is None: |
120 return None |
127 return None |
121 |
128 |
122 if index.column() == 0: |
129 if index.column() == 0: |
123 if role == Qt.DisplayRole: |
130 if role == Qt.ItemDataRole.DisplayRole: |
124 return engine.name() |
131 return engine.name() |
125 |
132 |
126 elif role == Qt.DecorationRole: |
133 elif role == Qt.ItemDataRole.DecorationRole: |
127 image = engine.image() |
134 image = engine.image() |
128 if image.isNull(): |
135 if image.isNull(): |
129 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
136 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
130 icon = WebBrowserWindow.icon(QUrl(engine.imageUrl())) |
137 icon = WebBrowserWindow.icon(QUrl(engine.imageUrl())) |
131 else: |
138 else: |
132 icon = QIcon(QPixmap.fromImage(image)) |
139 icon = QIcon(QPixmap.fromImage(image)) |
133 return icon |
140 return icon |
134 |
141 |
135 elif role == Qt.ToolTipRole: |
142 elif role == Qt.ItemDataRole.ToolTipRole: |
136 description = self.tr( |
143 description = self.tr( |
137 "<strong>Description:</strong> {0}" |
144 "<strong>Description:</strong> {0}" |
138 ).format(engine.description()) |
145 ).format(engine.description()) |
139 if engine.providesSuggestions(): |
146 if engine.providesSuggestions(): |
140 description += "<br/>" |
147 description += "<br/>" |
141 description += self.tr( |
148 description += self.tr( |
142 "<strong>Provides contextual suggestions</strong>") |
149 "<strong>Provides contextual suggestions</strong>") |
143 |
150 |
144 return description |
151 return description |
145 elif index.column() == 1: |
152 elif index.column() == 1: |
146 if role in [Qt.EditRole, Qt.DisplayRole]: |
153 if role in [Qt.ItemDataRole.EditRole, Qt.ItemDataRole.DisplayRole]: |
147 return ",".join(self.__manager.keywordsForEngine(engine)) |
154 return ",".join(self.__manager.keywordsForEngine(engine)) |
148 elif role == Qt.ToolTipRole: |
155 elif role == Qt.ItemDataRole.ToolTipRole: |
149 return self.tr( |
156 return self.tr( |
150 "Comma-separated list of keywords that may" |
157 "Comma-separated list of keywords that may" |
151 " be entered in the location bar followed by search terms" |
158 " be entered in the location bar followed by search terms" |
152 " to search with this engine") |
159 " to search with this engine") |
153 |
160 |
154 return None |
161 return None |
155 |
162 |
156 def setData(self, index, value, role=Qt.EditRole): |
163 def setData(self, index, value, role=Qt.ItemDataRole.EditRole): |
157 """ |
164 """ |
158 Public method to set the data of a model cell. |
165 Public method to set the data of a model cell. |
159 |
166 |
160 @param index index of the model cell (QModelIndex) |
167 @param index index of the model cell (QModelIndex) |
161 @param value value to be set |
168 @param value value to be set |
166 return False |
173 return False |
167 |
174 |
168 if index.row() >= self.rowCount() or index.row() < 0: |
175 if index.row() >= self.rowCount() or index.row() < 0: |
169 return False |
176 return False |
170 |
177 |
171 if role != Qt.EditRole: |
178 if role != Qt.ItemDataRole.EditRole: |
172 return False |
179 return False |
173 |
180 |
174 engineName = self.__manager.allEnginesNames()[index.row()] |
181 engineName = self.__manager.allEnginesNames()[index.row()] |
175 keywords = re.split("[ ,]+", value) |
182 keywords = re.split("[ ,]+", value) |
176 self.__manager.setKeywordsForEngine( |
183 self.__manager.setKeywordsForEngine( |
177 self.__manager.engine(engineName), keywords) |
184 self.__manager.engine(engineName), keywords) |
178 |
185 |
179 return True |
186 return True |
180 |
187 |
181 def headerData(self, section, orientation, role=Qt.DisplayRole): |
188 def headerData(self, section, orientation, |
|
189 role=Qt.ItemDataRole.DisplayRole): |
182 """ |
190 """ |
183 Public method to get the header data. |
191 Public method to get the header data. |
184 |
192 |
185 @param section section number (integer) |
193 @param section section number (integer) |
186 @param orientation header orientation (Qt.Orientation) |
194 @param orientation header orientation (Qt.Orientation) |
187 @param role data role (integer) |
195 @param role data role (Qt.ItemDataRole) |
188 @return header data |
196 @return header data |
189 """ |
197 """ |
190 if orientation == Qt.Horizontal and role == Qt.DisplayRole: |
198 if ( |
|
199 orientation == Qt.Orientation.Horizontal and |
|
200 role == Qt.ItemDataRole.DisplayRole |
|
201 ): |
191 try: |
202 try: |
192 return self.__headers[section] |
203 return self.__headers[section] |
193 except IndexError: |
204 except IndexError: |
194 pass |
205 pass |
195 |
206 |