#include "support/gettext.h"
#include "support/lassert.h"
#include "support/lstrings.h"
+#include "support/qstring_helpers.h"
#include <QAbstractTextDocumentLayout>
#include <QComboBox>
QString const & f = cc_->filter();
if (f.isEmpty())
return s;
-
- // step through data item and put "(x)" for every matching character
- QString r;
- int lastp = -1;
- for (int i = 0; i < f.length(); ++i) {
- int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
- if (p < 0)
- continue;
- if (lastp == p - 1 && lastp != -1) {
- // remove ")" and append "x)"
- r = r.left(r.length() - 4) + s[p] + "</u>";
- } else {
- // append "(x)"
- r += s.mid(lastp + 1, p - lastp - 1);
- r += QString("<u>") + s[p] + "</u>";
- }
- lastp = p;
- }
- r += s.mid(lastp + 1);
+ QString r(s);
+ QRegExp pattern(charFilterRegExpC(f));
+ r.replace(pattern, "<u><b>\\1</b></u>");
return r;
}
-static QString charFilterRegExpCC(QString const & filter)
-{
- QString re = ".*";
- for (int i = 0; i < filter.length(); ++i) {
- QChar c = filter[i];
- if (c.isLower())
- re += "[" + QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
- else
- re += QRegExp::escape(c);
- }
- return re;
-}
-
-
void CategorizedCombo::Private::setFilter(QString const & s)
{
bool enabled = p->view()->updatesEnabled();
lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
filter_ = s;
- filterModel_->setFilterRegExp(charFilterRegExpCC(filter_));
+ filterModel_->setFilterRegExp(charFilterRegExp(filter_));
countCategories();
// restore old selection