132 withoutLabel->setText(QHelpSearchQueryWidget::tr("<B>without</B> the words:")); |
131 withoutLabel->setText(QHelpSearchQueryWidget::tr("<B>without</B> the words:")); |
133 exactLabel->setText(QHelpSearchQueryWidget::tr("with <B>exact phrase</B>:")); |
132 exactLabel->setText(QHelpSearchQueryWidget::tr("with <B>exact phrase</B>:")); |
134 allLabel->setText(QHelpSearchQueryWidget::tr("with <B>all</B> of the words:")); |
133 allLabel->setText(QHelpSearchQueryWidget::tr("with <B>all</B> of the words:")); |
135 atLeastLabel->setText(QHelpSearchQueryWidget::tr("with <B>at least one</B> of the words:")); |
134 atLeastLabel->setText(QHelpSearchQueryWidget::tr("with <B>at least one</B> of the words:")); |
136 #endif |
135 #endif |
137 } |
|
138 |
|
139 QString escapeString(const QString &text) |
|
140 { |
|
141 QString retValue = text; |
|
142 const QString escape(QLatin1String("\\")); |
|
143 QStringList escapableCharsList; |
|
144 escapableCharsList << QLatin1String("\\") << QLatin1String("+") |
|
145 << QLatin1String("-") << QLatin1String("!") << QLatin1String("(") |
|
146 << QLatin1String(")") << QLatin1String(":") << QLatin1String("^") |
|
147 << QLatin1String("[") << QLatin1String("]") << QLatin1String("{") |
|
148 << QLatin1String("}") << QLatin1String("~"); |
|
149 |
|
150 // make sure we won't end up with an empty string |
|
151 foreach (const QString &escapeChar, escapableCharsList) { |
|
152 if (retValue.contains(escapeChar)) |
|
153 retValue.replace(escapeChar, QLatin1String("")); |
|
154 } |
|
155 if (retValue.trimmed().isEmpty()) |
|
156 return retValue; |
|
157 |
|
158 retValue = text; // now really escape the string... |
|
159 foreach (const QString &escapeChar, escapableCharsList) { |
|
160 if (retValue.contains(escapeChar)) |
|
161 retValue.replace(escapeChar, escape + escapeChar); |
|
162 } |
|
163 return retValue; |
|
164 } |
136 } |
165 |
137 |
166 QStringList buildTermList(const QString query) |
138 QStringList buildTermList(const QString query) |
167 { |
139 { |
168 bool s = false; |
140 bool s = false; |
220 addTerm(queryPart.wordList.join(" ")); |
192 addTerm(queryPart.wordList.join(" ")); |
221 } |
193 } |
222 } |
194 } |
223 } |
195 } |
224 |
196 |
225 void nextOrPrevQuery(int maxOrMinIndex, int addend, |
197 void nextOrPrevQuery(int maxOrMinIndex, int addend, QToolButton *thisButton, |
226 QToolButton *thisButton, QToolButton *otherButton) |
198 QToolButton *otherButton) |
227 { |
199 { |
228 QueryHistory *queryHist; |
200 QueryHistory *queryHist; |
229 QList<QLineEdit *> lineEdits; |
201 QList<QLineEdit *> lineEdits; |
230 if (simpleSearch) { |
202 if (simpleSearch) { |
231 queryHist = &simpleQueries; |
203 queryHist = &simpleQueries; |
232 lineEdits << defaultQuery; |
204 lineEdits << defaultQuery; |
233 } else { |
205 } else { |
234 queryHist = &complexQueries; |
206 queryHist = &complexQueries; |
235 lineEdits << allQuery << atLeastQuery << similarQuery |
207 lineEdits << allQuery << atLeastQuery << similarQuery |
236 << withoutQuery << exactQuery; |
208 << withoutQuery << exactQuery; |
237 } |
209 } |
238 foreach (QLineEdit *lineEdit, lineEdits) |
210 foreach (QLineEdit *lineEdit, lineEdits) |
239 lineEdit->clear(); |
211 lineEdit->clear(); |
240 |
212 |
241 // Otherwise, the respective button would be disabled. |
213 // Otherwise, the respective button would be disabled. |
304 void searchRequested() |
276 void searchRequested() |
305 { |
277 { |
306 QList<QHelpSearchQuery> queryList; |
278 QList<QHelpSearchQuery> queryList; |
307 #if !defined(QT_CLUCENE_SUPPORT) |
279 #if !defined(QT_CLUCENE_SUPPORT) |
308 queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT, |
280 queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT, |
309 QStringList(defaultQuery->text()))); |
281 QStringList(defaultQuery->text()))); |
310 |
282 |
311 #else |
283 #else |
312 if (defaultQuery->isEnabled()) { |
284 if (defaultQuery->isEnabled()) { |
313 queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT, |
285 queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT, |
314 buildTermList(escapeString(defaultQuery->text())))); |
286 buildTermList(defaultQuery->text()))); |
315 } else { |
287 } else { |
316 const QRegExp exp(QLatin1String("\\s+")); |
288 const QRegExp exp(QLatin1String("\\s+")); |
317 QStringList lst = similarQuery->text().split(exp, QString::SkipEmptyParts); |
289 QStringList lst = similarQuery->text().split(exp, |
|
290 QString::SkipEmptyParts); |
318 if (!lst.isEmpty()) { |
291 if (!lst.isEmpty()) { |
319 QStringList fuzzy; |
292 QStringList fuzzy; |
320 foreach (const QString &term, lst) |
293 foreach (const QString &term, lst) |
321 fuzzy += buildTermList(escapeString(term)); |
294 fuzzy += buildTermList(term); |
322 queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, fuzzy)); |
295 queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, |
|
296 fuzzy)); |
323 } |
297 } |
324 |
298 |
325 lst = withoutQuery->text().split(exp, QString::SkipEmptyParts); |
299 lst = withoutQuery->text().split(exp, QString::SkipEmptyParts); |
326 if (!lst.isEmpty()) { |
300 if (!lst.isEmpty()) { |
327 QStringList without; |
301 QStringList without; |
328 foreach (const QString &term, lst) |
302 foreach (const QString &term, lst) |
329 without.append(escapeString(term)); |
303 without.append(term); |
330 queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, without)); |
304 queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, |
|
305 without)); |
331 } |
306 } |
332 |
307 |
333 if (!exactQuery->text().isEmpty()) { |
308 if (!exactQuery->text().isEmpty()) { |
334 QString phrase = exactQuery->text().remove(QLatin1Char('\"')); |
309 QString phrase = exactQuery->text().remove(QLatin1Char('\"')); |
335 phrase = escapeString(phrase.simplified()); |
310 phrase = phrase.simplified(); |
336 queryList.append(QHelpSearchQuery(QHelpSearchQuery::PHRASE, QStringList(phrase))); |
311 queryList.append(QHelpSearchQuery(QHelpSearchQuery::PHRASE, |
|
312 QStringList(phrase))); |
337 } |
313 } |
338 |
314 |
339 lst = allQuery->text().split(exp, QString::SkipEmptyParts); |
315 lst = allQuery->text().split(exp, QString::SkipEmptyParts); |
340 if (!lst.isEmpty()) { |
316 if (!lst.isEmpty()) { |
341 QStringList all; |
317 QStringList all; |
342 foreach (const QString &term, lst) |
318 foreach (const QString &term, lst) |
343 all.append(escapeString(term)); |
319 all.append(term); |
344 queryList.append(QHelpSearchQuery(QHelpSearchQuery::ALL, all)); |
320 queryList.append(QHelpSearchQuery(QHelpSearchQuery::ALL, all)); |
345 } |
321 } |
346 |
322 |
347 lst = atLeastQuery->text().split(exp, QString::SkipEmptyParts); |
323 lst = atLeastQuery->text().split(exp, QString::SkipEmptyParts); |
348 if (!lst.isEmpty()) { |
324 if (!lst.isEmpty()) { |
349 QStringList atLeast; |
325 QStringList atLeast; |
350 foreach (const QString &term, lst) |
326 foreach (const QString &term, lst) |
351 atLeast += buildTermList(escapeString(term)); |
327 atLeast += buildTermList(term); |
352 queryList.append(QHelpSearchQuery(QHelpSearchQuery::ATLEAST, atLeast)); |
328 queryList.append(QHelpSearchQuery(QHelpSearchQuery::ATLEAST, |
|
329 atLeast)); |
353 } |
330 } |
354 } |
331 } |
355 #endif |
332 #endif |
356 QueryHistory &queryHist = simpleSearch ? simpleQueries : complexQueries; |
333 QueryHistory &queryHist = simpleSearch ? simpleQueries : complexQueries; |
357 saveQuery(queryList, queryHist); |
334 saveQuery(queryList, queryHist); |