]> git.lyx.org Git - features.git/commitdiff
* fix another crash due to the redraw opti-/minimization during
authorStefan Schimanski <sts@lyx.org>
Tue, 4 Mar 2008 09:43:32 +0000 (09:43 +0000)
committerStefan Schimanski <sts@lyx.org>
Tue, 4 Mar 2008 09:43:32 +0000 (09:43 +0000)
completion. We have to show and hide the popup asynchronously with a
singleshot timer. Otherwise it might trigger accesses to the coord
cache although the metrics have not been done yet.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23424 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiCompleter.cpp
src/frontends/qt4/GuiCompleter.h

index 8459bf630ae45f5a6c7808435da7e41a4fb7f973..11348e5dcb95fc2c0d27b0637cbd39471080d6f6 100644 (file)
@@ -171,7 +171,7 @@ private:
 
 GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent)
        : QCompleter(parent), gui_(gui), updateLock_(0),
-         inlineVisible_(false)
+         inlineVisible_(false), popupVisible_(false)
 {
        // Setup the completion popup
        setModel(new GuiCompletionModel(this, 0));
@@ -260,7 +260,7 @@ bool GuiCompleter::completionAvailable() const
 
 bool GuiCompleter::popupVisible() const
 {
-       return popup()->isVisible();
+       return popupVisible_;
 }
 
 
@@ -392,9 +392,28 @@ void GuiCompleter::updatePopup(Cursor & cur)
        if (!cur.inset().completionSupported(cur))
                return;
        
-       if (completionCount() == 0)
+       popupVisible_ = true;
+
+       if (completionCount() == 0) {
+               QTimer::singleShot(0, popup(), SLOT(hide()));
                return;
-       
+       }
+
+       // show asynchronously to avoid lookups before the metrics
+       // have been computed. This can happen because we might be in
+       // the middle of a dispatch.
+       QTimer::singleShot(0, this, SLOT(asyncCompletePopup()));
+}
+
+
+void GuiCompleter::asyncCompletePopup()
+{
+       Cursor cur = gui_->bufferView().cursor();
+       if (!cur.inset().completionSupported(cur)) {
+               popupVisible_ = false;
+               return;
+       }
+
        // get dimensions of completion prefix
        Dimension dim;
        int x;
@@ -504,6 +523,8 @@ void GuiCompleter::showPopup(Cursor & cur)
 
 void GuiCompleter::hidePopup(Cursor & cur)
 {
+       popupVisible_ = false;
+       
        // hide popup asynchronously because we might be here inside of
        // LFUN dispatchers. Hiding a popup can trigger a focus event on the 
        // workarea which then redisplays the cursor. But the metrics are not
@@ -533,6 +554,9 @@ void GuiCompleter::hideInline(Cursor & cur)
        gui_->bufferView().setInlineCompletion(cur, DocIterator(), docstring());
        inlineVisible_ = false;
        
+       if (inline_timer_.isActive())
+               inline_timer_.stop();
+       
        if (!popupVisible())
                setModel(new GuiCompletionModel(this, 0));
 }
index b53220c16124c579397bd75414af02fcd09dd603..7cb87535a09187043bee5e6b3681480d181d519f 100644 (file)
@@ -88,6 +88,8 @@ private Q_SLOTS:
        void popupHighlighted(const QString & completion);
        ///
        void updateAvailability();
+       ///
+       void asyncCompletePopup();
        
 private:
        ///
@@ -128,6 +130,8 @@ private:
        /// in addition to know whether the completion is to be kept visible.
        bool inlineVisible_;
        ///
+       bool popupVisible_;
+       ///
        RtlItemDelegate * rtlItemDelegate_;
 }; // GuiCompleter