]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCompleter.cpp
* fix assert with 4.2.x when setting a null item delegate on an item view.
[lyx.git] / src / frontends / qt4 / GuiCompleter.cpp
index aa54d93d1d406146031b2d365a7c94f1fd87ac80..a56df94e464d2175fa659c6f2d821b102e3a1169 100644 (file)
@@ -46,16 +46,27 @@ public:
        explicit RtlItemDelegate(QObject * parent = 0)
                : QItemDelegate(parent) {}
 
+       void setEnabled(bool enabled = true)
+       {
+               enabled_ = enabled;
+       }
+       
 protected:
        virtual void drawDisplay(QPainter * painter,
                QStyleOptionViewItem const & option,
                QRect const & rect, QString const & text) const
        {
+               if (!enabled_)
+                       return QItemDelegate::drawDisplay(painter, option, rect, text);
+
                // FIXME: do this more elegantly
                docstring stltext = qstring_to_ucs4(text);
                reverse(stltext.begin(), stltext.end());
                QItemDelegate::drawDisplay(painter, option, rect, toqstr(stltext));
        }
+       
+private:
+       bool enabled_;
 };
 
 
@@ -130,10 +141,9 @@ public:
                if (role != Qt::DisplayRole && role != Qt::EditRole)
                    return QVariant();
                    
-               if (index.column() == 0) {
-                       docstring const word = list_->data(index.row());
-                       return toqstr(word);
-               } else if (index.column() == 1) {
+               if (index.column() == 0)
+                       return toqstr(list_->data(index.row()));
+               else if (index.column() == 1) {
                        // get icon from cache
                        QPixmap scaled;
                        QString const name = ":" + toqstr(list_->icon(index.row()));
@@ -180,7 +190,8 @@ GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent)
        setPopup(listView);
        popup()->setItemDelegateForColumn(1, new PixmapItemDelegate(this));
        rtlItemDelegate_ = new RtlItemDelegate(this);
-       
+       popup()->setItemDelegateForColumn(0, rtlItemDelegate_);
+
        // create timeout timers
        popup_timer_.setSingleShot(true);
        inline_timer_.setSingleShot(true);
@@ -438,7 +449,7 @@ void GuiCompleter::updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate
 
        // turn the direction of the strings in the popup.
        // Qt does not do that itself.
-       popup()->setItemDelegateForColumn(0, rtl ? rtlItemDelegate_ : 0);
+       rtlItemDelegate_->setEnabled(rtl);
 
        // set new model
        Inset::CompletionList const * list = cur.inset().createCompletionList(cur);