Helpviewer/History/HistoryCompleter.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1112
8a7d1b9d18db
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
11 from PyQt4.QtGui import * 11 from PyQt4.QtGui import *
12 12
13 from .HistoryModel import HistoryModel 13 from .HistoryModel import HistoryModel
14 from .HistoryFilterModel import HistoryFilterModel 14 from .HistoryFilterModel import HistoryFilterModel
15 15
16
16 class HistoryCompletionView(QTableView): 17 class HistoryCompletionView(QTableView):
17 """ 18 """
18 Class implementing a special completer view for history based completions. 19 Class implementing a special completer view for history based completions.
19 """ 20 """
20 def __init__(self, parent = None): 21 def __init__(self, parent=None):
21 """ 22 """
22 Constructor 23 Constructor
23 24
24 @param parent reference to the parent widget (QWidget) 25 @param parent reference to the parent widget (QWidget)
25 """ 26 """
55 @param row row number (integer) 56 @param row row number (integer)
56 """ 57 """
57 metrics = self.fontMetrics() 58 metrics = self.fontMetrics()
58 return metrics.height() 59 return metrics.height()
59 60
61
60 class HistoryCompletionModel(QSortFilterProxyModel): 62 class HistoryCompletionModel(QSortFilterProxyModel):
61 """ 63 """
62 Class implementing a special model for history based completions. 64 Class implementing a special model for history based completions.
63 """ 65 """
64 HistoryCompletionRole = HistoryFilterModel.MaxRole + 1 66 HistoryCompletionRole = HistoryFilterModel.MaxRole + 1
65 67
66 def __init__(self, parent = None): 68 def __init__(self, parent=None):
67 """ 69 """
68 Constructor 70 Constructor
69 71
70 @param parent reference to the parent object (QObject) 72 @param parent reference to the parent object (QObject)
71 """ 73 """
76 self.__wordMatcher = QRegExp("", Qt.CaseInsensitive) 78 self.__wordMatcher = QRegExp("", Qt.CaseInsensitive)
77 self.__isValid = False 79 self.__isValid = False
78 80
79 self.setDynamicSortFilter(True) 81 self.setDynamicSortFilter(True)
80 82
81 def data(self, index, role = Qt.DisplayRole): 83 def data(self, index, role=Qt.DisplayRole):
82 """ 84 """
83 Public method to get data from the model. 85 Public method to get data from the model.
84 86
85 @param index index of history entry to get data for (QModelIndex) 87 @param index index of history entry to get data for (QModelIndex)
86 @param role data role (integer) 88 @param role data role (integer)
171 173
172 def lessThan(self, left, right): 174 def lessThan(self, left, right):
173 """ 175 """
174 Protected method used to sort the displayed items. 176 Protected method used to sort the displayed items.
175 177
176 It implements a special sorting function based on the history entry's 178 It implements a special sorting function based on the history entry's
177 frequency giving a bonus to hits that match on a word boundary so that 179 frequency giving a bonus to hits that match on a word boundary so that
178 e.g. "dot.python-projects.org" is a better result for typing "dot" than 180 e.g. "dot.python-projects.org" is a better result for typing "dot" than
179 "slashdot.org". However, it only looks for the string in the host name, 181 "slashdot.org". However, it only looks for the string in the host name,
180 not the entire URL, since while it makes sense to e.g. give 182 not the entire URL, since while it makes sense to e.g. give
181 "www.phoronix.com" a bonus for "ph", it does NOT make sense to give 183 "www.phoronix.com" a bonus for "ph", it does NOT make sense to give
204 frequency_R *= 2 206 frequency_R *= 2
205 207
206 # Sort results in descending frequency-derived score. 208 # Sort results in descending frequency-derived score.
207 return frequency_R < frequency_L 209 return frequency_R < frequency_L
208 210
211
209 class HistoryCompleter(QCompleter): 212 class HistoryCompleter(QCompleter):
210 def __init__(self, model, parent = None): 213 def __init__(self, model, parent=None):
211 """ 214 """
212 Constructor 215 Constructor
213 216
214 @param model reference to the model (QAbstractItemModel) 217 @param model reference to the model (QAbstractItemModel)
215 @param parent reference to the parent object (QObject) 218 @param parent reference to the parent object (QObject)

eric ide

mercurial