82 """ |
82 """ |
83 Public method to get data from the model. |
83 Public method to get data from the model. |
84 |
84 |
85 @param index index of history entry to get data for (QModelIndex) |
85 @param index index of history entry to get data for (QModelIndex) |
86 @param role data role (integer) |
86 @param role data role (integer) |
87 @return history entry data (QVariant) |
87 @return history entry data |
88 """ |
88 """ |
89 # If the model is valid, tell QCompleter that everything we have filtered |
89 # If the model is valid, tell QCompleter that everything we have filtered |
90 # matches what the user typed; if not, nothing matches |
90 # matches what the user typed; if not, nothing matches |
91 if role == self.HistoryCompletionRole and index.isValid(): |
91 if role == self.HistoryCompletionRole and index.isValid(): |
92 if self.isValid(): |
92 if self.isValid(): |
93 return QVariant("t") |
93 return "t" |
94 else: |
94 else: |
95 return QVariant("f") |
95 return "f" |
96 |
96 |
97 if role == Qt.DisplayRole: |
97 if role == Qt.DisplayRole: |
98 if index.column() == 0: |
98 if index.column() == 0: |
99 role = HistoryModel.UrlStringRole |
99 role = HistoryModel.UrlStringRole |
100 else: |
100 else: |
158 # Do a case-insensitive substring match against both the url and title. |
158 # Do a case-insensitive substring match against both the url and title. |
159 # It's already ensured, that the user doesn't accidentally use regexp |
159 # It's already ensured, that the user doesn't accidentally use regexp |
160 # metacharacters (s. setSearchString()). |
160 # metacharacters (s. setSearchString()). |
161 idx = self.sourceModel().index(sourceRow, 0, sourceParent) |
161 idx = self.sourceModel().index(sourceRow, 0, sourceParent) |
162 |
162 |
163 url = self.sourceModel().data(idx, HistoryModel.UrlStringRole).toString() |
163 url = self.sourceModel().data(idx, HistoryModel.UrlStringRole) |
164 if self.__searchMatcher.indexIn(url) != -1: |
164 if self.__searchMatcher.indexIn(url) != -1: |
165 return True |
165 return True |
166 |
166 |
167 title = self.sourceModel().data(idx, HistoryModel.TitleRole).toString() |
167 title = self.sourceModel().data(idx, HistoryModel.TitleRole) |
168 if self.__searchMatcher.indexIn(title) != -1: |
168 if self.__searchMatcher.indexIn(title) != -1: |
169 return True |
169 return True |
170 |
170 |
171 return False |
171 return False |
172 |
172 |
185 @param left index of left item (QModelIndex) |
185 @param left index of left item (QModelIndex) |
186 @param right index of right item (QModelIndex) |
186 @param right index of right item (QModelIndex) |
187 @return true, if left is less than right (boolean) |
187 @return true, if left is less than right (boolean) |
188 """ |
188 """ |
189 frequency_L = \ |
189 frequency_L = \ |
190 self.sourceModel().data(left, HistoryFilterModel.FrequencyRole).toInt()[0] |
190 self.sourceModel().data(left, HistoryFilterModel.FrequencyRole) |
191 url_L = self.sourceModel().data(left, HistoryModel.UrlRole).toUrl().host() |
191 url_L = self.sourceModel().data(left, HistoryModel.UrlRole).host() |
192 title_L = self.sourceModel().data(left, HistoryModel.TitleRole).toString() |
192 title_L = self.sourceModel().data(left, HistoryModel.TitleRole) |
193 |
193 |
194 if self.__wordMatcher.indexIn(url_L) != -1 or \ |
194 if self.__wordMatcher.indexIn(url_L) != -1 or \ |
195 self.__wordMatcher.indexIn(title_L) != -1: |
195 self.__wordMatcher.indexIn(title_L) != -1: |
196 frequency_L *= 2 |
196 frequency_L *= 2 |
197 |
197 |
198 frequency_R = \ |
198 frequency_R = \ |
199 self.sourceModel().data(right, HistoryFilterModel.FrequencyRole).toInt()[0] |
199 self.sourceModel().data(right, HistoryFilterModel.FrequencyRole) |
200 url_R = self.sourceModel().data(right, HistoryModel.UrlRole).toUrl().host() |
200 url_R = self.sourceModel().data(right, HistoryModel.UrlRole).host() |
201 title_R = self.sourceModel().data(right, HistoryModel.TitleRole).toString() |
201 title_R = self.sourceModel().data(right, HistoryModel.TitleRole) |
202 |
202 |
203 if self.__wordMatcher.indexIn(url_R) != -1 or \ |
203 if self.__wordMatcher.indexIn(url_R) != -1 or \ |
204 self.__wordMatcher.indexIn(title_R) != -1: |
204 self.__wordMatcher.indexIn(title_R) != -1: |
205 frequency_R *= 2 |
205 frequency_R *= 2 |
206 |
206 |
237 Public method to get a path for a given index. |
237 Public method to get a path for a given index. |
238 |
238 |
239 @param idx reference to the index (QModelIndex) |
239 @param idx reference to the index (QModelIndex) |
240 @return the actual URL from the history (string) |
240 @return the actual URL from the history (string) |
241 """ |
241 """ |
242 return self.model().data(idx, HistoryModel.UrlStringRole).toString() |
242 return self.model().data(idx, HistoryModel.UrlStringRole) |
243 |
243 |
244 def splitPath(self, path): |
244 def splitPath(self, path): |
245 """ |
245 """ |
246 Public method to split the given path into strings, that are used to match |
246 Public method to split the given path into strings, that are used to match |
247 at each level in the model. |
247 at each level in the model. |