74 @param parent reference to the parent object (QObject) |
74 @param parent reference to the parent object (QObject) |
75 """ |
75 """ |
76 super().__init__(parent) |
76 super().__init__(parent) |
77 |
77 |
78 self.__searchString = "" |
78 self.__searchString = "" |
79 self.__searchMatcher = QRegExp("", Qt.CaseInsensitive, QRegExp.FixedString) |
79 self.__searchMatcher = QRegExp( |
|
80 "", Qt.CaseInsensitive, QRegExp.FixedString) |
80 self.__wordMatcher = QRegExp("", Qt.CaseInsensitive) |
81 self.__wordMatcher = QRegExp("", Qt.CaseInsensitive) |
81 self.__isValid = False |
82 self.__isValid = False |
82 |
83 |
83 self.setDynamicSortFilter(True) |
84 self.setDynamicSortFilter(True) |
84 |
85 |
88 |
89 |
89 @param index index of history entry to get data for (QModelIndex) |
90 @param index index of history entry to get data for (QModelIndex) |
90 @param role data role (integer) |
91 @param role data role (integer) |
91 @return history entry data |
92 @return history entry data |
92 """ |
93 """ |
93 # If the model is valid, tell QCompleter that everything we have filtered |
94 # If the model is valid, tell QCompleter that everything we have |
94 # matches what the user typed; if not, nothing matches |
95 # filtered matches what the user typed; if not, nothing matches |
95 if role == self.HistoryCompletionRole and index.isValid(): |
96 if role == self.HistoryCompletionRole and index.isValid(): |
96 if self.isValid(): |
97 if self.isValid(): |
97 return "t" |
98 return "t" |
98 else: |
99 else: |
99 return "f" |
100 return "f" |
123 if string == self.__searchString: |
124 if string == self.__searchString: |
124 return |
125 return |
125 |
126 |
126 self.__searchString = string |
127 self.__searchString = string |
127 self.__searchMatcher.setPattern(self.__searchString) |
128 self.__searchMatcher.setPattern(self.__searchString) |
128 self.__wordMatcher.setPattern("\\b" + QRegExp.escape(self.__searchString)) |
129 self.__wordMatcher.setPattern( |
|
130 "\\b" + QRegExp.escape(self.__searchString)) |
129 self.invalidateFilter() |
131 self.invalidateFilter() |
130 |
132 |
131 def isValid(self): |
133 def isValid(self): |
132 """ |
134 """ |
133 Public method to check the model for validity. |
135 Public method to check the model for validity. |
146 return |
148 return |
147 |
149 |
148 self.__isValid = valid |
150 self.__isValid = valid |
149 |
151 |
150 # tell the history completer that the model has changed |
152 # tell the history completer that the model has changed |
151 self.dataChanged.emit(self.index(0, 0), self.index(0, self.rowCount() - 1)) |
153 self.dataChanged.emit(self.index(0, 0), self.index(0, |
|
154 self.rowCount() - 1)) |
152 |
155 |
153 def filterAcceptsRow(self, sourceRow, sourceParent): |
156 def filterAcceptsRow(self, sourceRow, sourceParent): |
154 """ |
157 """ |
155 Protected method to determine, if the row is acceptable. |
158 Protected method to determine, if the row is acceptable. |
156 |
159 |
248 """ |
251 """ |
249 return self.model().data(idx, HistoryModel.UrlStringRole) |
252 return self.model().data(idx, HistoryModel.UrlStringRole) |
250 |
253 |
251 def splitPath(self, path): |
254 def splitPath(self, path): |
252 """ |
255 """ |
253 Public method to split the given path into strings, that are used to match |
256 Public method to split the given path into strings, that are used to |
254 at each level in the model. |
257 match at each level in the model. |
255 |
258 |
256 @param path path to be split (string) |
259 @param path path to be split (string) |
257 @return list of path elements (list of strings) |
260 @return list of path elements (list of strings) |
258 """ |
261 """ |
259 if path == self.__searchString: |
262 if path == self.__searchString: |
260 return ["t"] |
263 return ["t"] |
261 |
264 |
262 # Queue an update to the search string. Wait a bit, so that if the user |
265 # Queue an update to the search string. Wait a bit, so that if the user |
263 # is quickly typing, the completer doesn't try to complete until they pause. |
266 # is quickly typing, the completer doesn't try to complete until they |
|
267 # pause. |
264 if self.__filterTimer.isActive(): |
268 if self.__filterTimer.isActive(): |
265 self.__filterTimer.stop() |
269 self.__filterTimer.stop() |
266 self.__filterTimer.start(150) |
270 self.__filterTimer.start(150) |
267 |
271 |
268 # If the previous search results are not a superset of the current |
272 # If the previous search results are not a superset of the current |
271 self.model().setValid(False) |
275 self.model().setValid(False) |
272 |
276 |
273 self.__searchString = path |
277 self.__searchString = path |
274 |
278 |
275 # The actual filtering is done by the HistoryCompletionModel. Just |
279 # The actual filtering is done by the HistoryCompletionModel. Just |
276 # return a short dummy here so that QCompleter thinks everything matched. |
280 # return a short dummy here so that QCompleter thinks everything |
|
281 # matched. |
277 return ["t"] |
282 return ["t"] |
278 |
283 |
279 def __updateFilter(self): |
284 def __updateFilter(self): |
280 """ |
285 """ |
281 Private slot to update the search string. |
286 Private slot to update the search string. |