]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/LayoutBox.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / LayoutBox.cpp
index 23017cf6f89e8f8d75ecedfdca2528560bf206b6..783dc78a261750db006da0ab2038ed7835a55c5f 100644 (file)
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "Cursor.h"
+#include "DocumentClassPtr.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "LyXFunc.h"
+#include "LyX.h"
 #include "LyXRC.h"
 #include "Paragraph.h"
 #include "TextClass.h"
@@ -127,7 +128,7 @@ struct LayoutBox::Private
        ///
        GuiView & owner_;
        ///
-       DocumentClass const * text_class_;
+       DocumentClassConstPtr text_class_;
        ///
        Inset const * inset_;
        
@@ -317,7 +318,7 @@ QString LayoutItemDelegate::underlineFilter(QString const & s) const
        layout_->filter();
        for (int i = 0; i < f.length(); ++i) {
                int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
-               LASSERT(p != -1, /**/);
+               LASSERT(p != -1, continue);
                if (lastp == p - 1 && lastp != -1) {
                        // remove ")" and append "x)"
                        r = r.left(r.length() - 4) + s[p] + "</u>";
@@ -349,6 +350,10 @@ static QString charFilterRegExp(QString const & filter)
 
 void LayoutBox::Private::setFilter(QString const & s)
 {
+       // exit early if nothing has to be done
+       if (filter_ == s)
+               return;
+
        bool enabled = p->view()->updatesEnabled();
        p->view()->setUpdatesEnabled(false);
 
@@ -377,7 +382,7 @@ void LayoutBox::Private::setFilter(QString const & s)
                // We do not call our implementation of showPopup because that
                // would reset the filter again. This is only needed if the user clicks
                // on the QComboBox.
-               LASSERT(!inShowPopup_, /**/);
+               LATTEST(!inShowPopup_);
                inShowPopup_ = true;
                p->QComboBox::showPopup();
                inShowPopup_ = false;
@@ -418,6 +423,11 @@ LayoutBox::LayoutBox(GuiView & owner)
 }
 
 
+LayoutBox::~LayoutBox() {
+       delete d;
+}
+
+
 void LayoutBox::Private::countCategories()
 {
        int n = filterModel_->rowCount();
@@ -449,7 +459,7 @@ void LayoutBox::showPopup()
 
        // call QComboBox::showPopup. But set the inShowPopup_ flag to switch on
        // the hack in the item delegate to make space for the headers.
-       LASSERT(!d->inShowPopup_, /**/);
+       LATTEST(!d->inShowPopup_);
        d->inShowPopup_ = true;
        QComboBox::showPopup();
        d->inShowPopup_ = false;
@@ -525,10 +535,13 @@ void LayoutBox::setIconSize(QSize size)
 void LayoutBox::set(docstring const & layout)
 {
        d->resetFilter();
-       
+
        if (!d->text_class_)
                return;
 
+       if (!d->text_class_->hasLayout(layout))
+               return;
+
        Layout const & lay = (*d->text_class_)[layout];
        QString newLayout = toqstr(lay.name());
 
@@ -560,9 +573,9 @@ void LayoutBox::addItemSort(docstring const & item, docstring const & category,
        bool sorted, bool sortedByCat, bool unknown)
 {
        QString qitem = toqstr(item);
-       // FIXME This is wrong for RTL, I'd suppose.
-       QString titem = toqstr(translateIfPossible(item) +
-                              (unknown ? _(" (unknown)") : from_ascii("")));
+       docstring const loc_item = translateIfPossible(item);
+       QString titem = unknown ? toqstr(bformat(_("%1$s (unknown)"), loc_item))
+                               : toqstr(loc_item);
        QString qcat = toqstr(translateIfPossible(category));
 
        QList<QStandardItem *> row;
@@ -620,13 +633,13 @@ void LayoutBox::updateContents(bool reset)
        if (!bv) {
                d->model_->clear();
                setEnabled(false);
-               d->text_class_ = 0;
+               d->text_class_.reset();
                d->inset_ = 0;
                return;
        }
        // we'll only update the layout list if the text class has changed
        // or we've moved from one inset to another
-       DocumentClass const * text_class = &(bv->buffer().params().documentClass());
+       DocumentClassConstPtr text_class = bv->buffer().params().documentClassPtr();
        Inset const * inset = &(bv->cursor().innerText()->inset());
        if (!reset && d->text_class_ == text_class && d->inset_ == inset) {
                set(bv->cursor().innerParagraph().layout().name());