]> git.lyx.org Git - features.git/commitdiff
Refactor
authorRichard Kimberly Heck <rikiheck@lyx.org>
Fri, 19 Oct 2018 01:11:14 +0000 (21:11 -0400)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 12:39:50 +0000 (14:39 +0200)
src/frontends/qt4/CategorizedCombo.cpp
src/frontends/qt4/LayoutBox.cpp
src/support/qstring_helpers.cpp
src/support/qstring_helpers.h

index a762822384aa791bb8c964fd10e9bfc9e5d67ecc..291a4021bcfaef1ae83d8e774614778c52c2233c 100644 (file)
@@ -24,6 +24,7 @@
 #include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
+#include "support/qstring_helpers.h"
 
 #include <QAbstractTextDocumentLayout>
 #include <QComboBox>
@@ -290,20 +291,6 @@ QString CCItemDelegate::underlineFilter(QString const & s) const
 }
 
 
-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();
@@ -315,7 +302,7 @@ void CategorizedCombo::Private::setFilter(QString const & s)
                lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
 
        filter_ = s;
-       filterModel_->setFilterRegExp(charFilterRegExpCC(filter_));
+    filterModel_->setFilterRegExp(charFilterRegExp(filter_));
        countCategories();
 
        // restore old selection
index 66556d99e1e63cff190c0953c32d497f657c4eb8..2bc871470f33e9afd97beab7655cb0cdbd045c64 100644 (file)
@@ -321,20 +321,6 @@ QString LayoutItemDelegate::underlineFilter(QString const & s) const
 }
 
 
-static QString charFilterRegExp(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 LayoutBox::Private::setFilter(QString const & s)
 {
        // exit early if nothing has to be done
index 4f63167b4305f665e9cb04403b346a94054a73ee..ada61250987bc047ee814eb47df6a4d9cfb20eb1 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "support/debug.h"
 #include "support/docstring.h"
+#include "support/qstring_helpers.h"
 
 #include <QString>
 #include <QVector>
@@ -67,4 +68,17 @@ std::string fromqstr(QString const & str)
        return str.isEmpty() ? std::string() : std::string(str.toUtf8());
 }
 
+QString charFilterRegExp(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;
+}
+
 } // namespace lyx
index 9c28092811ed9c980ff04f89c18ec0531a5a2efa..a3fafb43439a5742bfa0bb6daede9117b391a5e0 100644 (file)
@@ -80,6 +80,11 @@ docstring qstring_to_ucs4(QString const & qstr);
  */
 std::string fromqstr(QString const & str);
 
+/**
+ * constructs a regex to filter on consecutive characters
+ */
+QString charFilterRegExp(QString const & filter);
+
 } // namespace lyx
 
 #endif // QSTRING_HELPERS_H