]> 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 319bcb0e9c1f522898048fdd73db8f38a9384e01..0482e1c874fe14a9e6135679166543e0e9e33fa5 100644 (file)
@@ -49,13 +49,13 @@ public:
        {}
        ///
        void paint(QPainter * painter, QStyleOptionViewItem const & option,
-               QModelIndex const & index) const;
+               QModelIndex const & index) const override;
        ///
        void drawDisplay(QPainter * painter, QStyleOptionViewItem const & opt,
-               const QRect & /*rect*/, const QString & text ) const;
+               const QRect & /*rect*/, const QString & text ) const override;
        ///
        QSize sizeHint(QStyleOptionViewItem const & opt,
-               QModelIndex const & index) const;
+               QModelIndex const & index) const override;
 
 private:
        ///
@@ -71,7 +71,7 @@ private:
 class CCFilterModel : public QSortFilterProxyModel {
 public:
        ///
-       CCFilterModel(QObject * parent = 0)
+       CCFilterModel(QObject * parent = nullptr)
                : QSortFilterProxyModel(parent)
        {}
 };
@@ -153,7 +153,8 @@ void CCItemDelegate::paint(QPainter * painter, QStyleOptionViewItem const & opti
        QString cat = categoryCC(*index.model(), index.row());
 
        // not the same as in the previous line?
-       if (index.row() == 0 || cat != categoryCC(*index.model(), index.row() - 1)) {
+       if (cc_->d->visibleCategories_ > 0
+           && (index.row() == 0 || cat != categoryCC(*index.model(), index.row() - 1))) {
                painter->save();
 
                // draw unselected background
@@ -269,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;
 }
@@ -286,7 +287,11 @@ void CategorizedCombo::Private::setFilter(QString const & s)
                lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
 
        filter_ = s;
-    filterModel_->setFilterRegExp(charFilterRegExp(filter_));
+#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
+       filterModel_->setFilterRegExp(charFilterRegExp(filter_));
+#else
+       filterModel_->setFilterRegularExpression(charFilterRegExp(filter_));
+#endif
        countCategories();
 
        // restore old selection
@@ -358,6 +363,7 @@ void CategorizedCombo::Private::countCategories()
 
 void CategorizedCombo::showPopup()
 {
+       lastCurrentIndex_ = currentIndex();
        bool enabled = view()->updatesEnabled();
        view()->setUpdatesEnabled(false);
 
@@ -388,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;
@@ -435,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();
 
@@ -450,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;
        }
 
@@ -462,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);
@@ -538,6 +546,11 @@ void CategorizedCombo::reset()
        d->model_->clear();
 }
 
+void CategorizedCombo::resetFilter()
+{
+       d->resetFilter();
+}
+
 
 void CategorizedCombo::updateCombo()
 {