* fix another crash due to the redraw opti-/minimization during

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
This commit is contained in:
Stefan Schimanski 2008-03-04 09:43:32 +00:00
parent a4b2404cb1
commit b4466b63f6
2 changed files with 32 additions and 4 deletions

View 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));
}

View 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