src/eric7/WebBrowser/History/HistoryCompleter.py

branch
eric7
changeset 10436
f6881d10e995
parent 10069
435cc5875135
child 10439
21c28b0f9e41
equal deleted inserted replaced
10435:c712d09cc839 10436:f6881d10e995
23 23
24 def __init__(self, parent=None): 24 def __init__(self, parent=None):
25 """ 25 """
26 Constructor 26 Constructor
27 27
28 @param parent reference to the parent widget (QWidget) 28 @param parent reference to the parent widget
29 @type QWidget
29 """ 30 """
30 super().__init__(parent) 31 super().__init__(parent)
31 32
32 self.horizontalHeader().hide() 33 self.horizontalHeader().hide()
33 self.verticalHeader().hide() 34 self.verticalHeader().hide()
43 44
44 def resizeEvent(self, evt): 45 def resizeEvent(self, evt):
45 """ 46 """
46 Protected method handling resize events. 47 Protected method handling resize events.
47 48
48 @param evt reference to the resize event (QResizeEvent) 49 @param evt reference to the resize event
50 @type QResizeEvent
49 """ 51 """
50 self.horizontalHeader().resizeSection(0, int(0.65 * self.width())) 52 self.horizontalHeader().resizeSection(0, int(0.65 * self.width()))
51 self.horizontalHeader().setStretchLastSection(True) 53 self.horizontalHeader().setStretchLastSection(True)
52 54
53 super().resizeEvent(evt) 55 super().resizeEvent(evt)
54 56
55 def sizeHintForRow(self, row): # noqa: U100 57 def sizeHintForRow(self, row): # noqa: U100
56 """ 58 """
57 Public method to give a size hint for rows. 59 Public method to give a size hint for rows.
58 60
59 @param row row number (integer) 61 @param row row number
60 @return desired row height (integer) 62 @type int
63 @return desired row height
64 @rtype int
61 """ 65 """
62 metrics = self.fontMetrics() 66 metrics = self.fontMetrics()
63 return metrics.height() 67 return metrics.height()
64 68
65 69
72 76
73 def __init__(self, parent=None): 77 def __init__(self, parent=None):
74 """ 78 """
75 Constructor 79 Constructor
76 80
77 @param parent reference to the parent object (QObject) 81 @param parent reference to the parent object
82 @type QObject
78 """ 83 """
79 super().__init__(parent) 84 super().__init__(parent)
80 85
81 self.__searchString = "" 86 self.__searchString = ""
82 self.__searchMatcher = None 87 self.__searchMatcher = None
87 92
88 def data(self, index, role=Qt.ItemDataRole.DisplayRole): 93 def data(self, index, role=Qt.ItemDataRole.DisplayRole):
89 """ 94 """
90 Public method to get data from the model. 95 Public method to get data from the model.
91 96
92 @param index index of history entry to get data for (QModelIndex) 97 @param index index of history entry to get data for
93 @param role data role (integer) 98 @type QModelIndex
99 @param role data role
100 @type int
94 @return history entry data 101 @return history entry data
102 @rtype Any
95 """ 103 """
96 # If the model is valid, tell QCompleter that everything we have 104 # If the model is valid, tell QCompleter that everything we have
97 # filtered matches what the user typed; if not, nothing matches 105 # filtered matches what the user typed; if not, nothing matches
98 if role == self.HistoryCompletionRole and index.isValid(): 106 if role == self.HistoryCompletionRole and index.isValid():
99 if self.isValid(): 107 if self.isValid():
111 119
112 def searchString(self): 120 def searchString(self):
113 """ 121 """
114 Public method to get the current search string. 122 Public method to get the current search string.
115 123
116 @return current search string (string) 124 @return current search string
125 @rtype str
117 """ 126 """
118 return self.__searchString 127 return self.__searchString
119 128
120 def setSearchString(self, sstring): 129 def setSearchString(self, sstring):
121 """ 130 """
122 Public method to set the current search string. 131 Public method to set the current search string.
123 132
124 @param sstring new search string (string) 133 @param sstring new search string
134 @type str
125 """ 135 """
126 if sstring != self.__searchString: 136 if sstring != self.__searchString:
127 self.__searchString = sstring 137 self.__searchString = sstring
128 self.__searchMatcher = re.compile( 138 self.__searchMatcher = re.compile(
129 re.escape(self.__searchString), re.IGNORECASE 139 re.escape(self.__searchString), re.IGNORECASE
135 145
136 def isValid(self): 146 def isValid(self):
137 """ 147 """
138 Public method to check the model for validity. 148 Public method to check the model for validity.
139 149
140 @return flag indicating a valid status (boolean) 150 @return flag indicating a valid status
151 @rtype bool
141 """ 152 """
142 return self.__isValid 153 return self.__isValid
143 154
144 def setValid(self, valid): 155 def setValid(self, valid):
145 """ 156 """
146 Public method to set the model's validity. 157 Public method to set the model's validity.
147 158
148 @param valid flag indicating the new valid status (boolean) 159 @param valid flag indicating the new valid status
160 @type bool
149 """ 161 """
150 if valid == self.__isValid: 162 if valid == self.__isValid:
151 return 163 return
152 164
153 self.__isValid = valid 165 self.__isValid = valid
157 169
158 def filterAcceptsRow(self, sourceRow, sourceParent): 170 def filterAcceptsRow(self, sourceRow, sourceParent):
159 """ 171 """
160 Public method to determine, if the row is acceptable. 172 Public method to determine, if the row is acceptable.
161 173
162 @param sourceRow row number in the source model (integer) 174 @param sourceRow row number in the source model
163 @param sourceParent index of the source item (QModelIndex) 175 @type int
164 @return flag indicating acceptance (boolean) 176 @param sourceParent index of the source item
177 @type QModelIndex
178 @return flag indicating acceptance
179 @rtype bool
165 """ 180 """
166 if self.__searchMatcher is not None: 181 if self.__searchMatcher is not None:
167 # Do a case-insensitive substring match against both the url and 182 # Do a case-insensitive substring match against both the url and
168 # title. It's already ensured, that the user doesn't accidentally 183 # title. It's already ensured, that the user doesn't accidentally
169 # use regexp metacharacters (s. setSearchString()). 184 # use regexp metacharacters (s. setSearchString()).
229 244
230 def __init__(self, model, parent=None): 245 def __init__(self, model, parent=None):
231 """ 246 """
232 Constructor 247 Constructor
233 248
234 @param model reference to the model (QAbstractItemModel) 249 @param model reference to the model
235 @param parent reference to the parent object (QObject) 250 @type QAbstractItemModel
251 @param parent reference to the parent object
252 @type QObject
236 """ 253 """
237 super().__init__(model, parent) 254 super().__init__(model, parent)
238 255
239 self.setPopup(HistoryCompletionView()) 256 self.setPopup(HistoryCompletionView())
240 257
253 270
254 def pathFromIndex(self, idx): 271 def pathFromIndex(self, idx):
255 """ 272 """
256 Public method to get a path for a given index. 273 Public method to get a path for a given index.
257 274
258 @param idx reference to the index (QModelIndex) 275 @param idx reference to the index
259 @return the actual URL from the history (string) 276 @type QModelIndex
277 @return the actual URL from the history
278 @rtype str
260 """ 279 """
261 return self.model().data(idx, HistoryModel.UrlStringRole) 280 return self.model().data(idx, HistoryModel.UrlStringRole)
262 281
263 def splitPath(self, path): 282 def splitPath(self, path):
264 """ 283 """
265 Public method to split the given path into strings, that are used to 284 Public method to split the given path into strings, that are used to
266 match at each level in the model. 285 match at each level in the model.
267 286
268 @param path path to be split (string) 287 @param path path to be split
269 @return list of path elements (list of strings) 288 @type str
289 @return list of path elements
290 @rtype list of str
270 """ 291 """
271 if path == self.__searchString: 292 if path == self.__searchString:
272 return ["t"] 293 return ["t"]
273 294
274 # Queue an update to the search string. Wait a bit, so that if the user 295 # Queue an update to the search string. Wait a bit, so that if the user

eric ide

mercurial