]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/CategorizedCombo.cpp
No need (any longer?) to create a new view for lyxfiles-open
[lyx.git] / src / frontends / qt / CategorizedCombo.cpp
index 4aebcf6a917e85ed0c2bfc371cc52ae31c785ee3..0482e1c874fe14a9e6135679166543e0e9e33fa5 100644 (file)
@@ -270,7 +270,7 @@ QString CCItemDelegate::underlineFilter(QString const & s) const
        if (f.isEmpty())
                return s;
        QString r(s);
-       QRegExp pattern(charFilterRegExpC(f));
+       QRegularExpression pattern(charFilterRegExpC(f));
        r.replace(pattern, "<u><b>\\1</b></u>");
        return r;
 }
@@ -287,7 +287,11 @@ void CategorizedCombo::Private::setFilter(QString const & s)
                lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
 
        filter_ = s;
+#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
        filterModel_->setFilterRegExp(charFilterRegExp(filter_));
+#else
+       filterModel_->setFilterRegularExpression(charFilterRegExp(filter_));
+#endif
        countCategories();
 
        // restore old selection
@@ -359,6 +363,7 @@ void CategorizedCombo::Private::countCategories()
 
 void CategorizedCombo::showPopup()
 {
+       lastCurrentIndex_ = currentIndex();
        bool enabled = view()->updatesEnabled();
        view()->setUpdatesEnabled(false);
 
@@ -389,6 +394,7 @@ bool CategorizedCombo::eventFilter(QObject * o, QEvent * e)
        case Qt::Key_Escape:
                if (!modified && !d->filter_.isEmpty()) {
                        d->resetFilter();
+                       setCurrentIndex(lastCurrentIndex_);
                        return true;
                }
                break;
@@ -436,7 +442,7 @@ void CategorizedCombo::setIconSize(QSize size)
 }
 
 
-bool CategorizedCombo::set(QString const & item)
+bool CategorizedCombo::set(QString const & item, bool const report_missing)
 {
        d->resetFilter();
 
@@ -451,7 +457,8 @@ bool CategorizedCombo::set(QString const & item)
 
        QList<QStandardItem *> r = d->model_->findItems(item, Qt::MatchExactly, 1);
        if (r.empty()) {
-               LYXERR0("Trying to select non existent layout type " << item);
+               if (report_missing)
+                       LYXERR0("Trying to select non existent layout type " << item);
                return false;
        }
 
@@ -463,13 +470,13 @@ bool CategorizedCombo::set(QString const & item)
 void CategorizedCombo::addItemSort(QString const & item, QString const & guiname,
                                   QString const & category, QString const & tooltip,
                                   bool sorted, bool sortedByCat, bool sortCats,
-                                  bool available)
+                                  bool available, bool nocategories)
 {
        QString titem = available ? guiname
                                  : toqstr(bformat(_("Unavailable: %1$s"),
                                                   qstring_to_ucs4(guiname)));
        bool const uncategorized = category.isEmpty();
-       QString qcat = uncategorized ? qt_("Uncategorized") : category;
+       QString qcat = (uncategorized && !nocategories) ? qt_("Uncategorized") : category;
 
        QList<QStandardItem *> row;
        QStandardItem * gui = new QStandardItem(titem);