Improve the performance of the source panel by using a QTimer. Solves
<http://www.lyx.org/trac/ticket/9493>. Please criticise.
>From d25446e1dc4aa62eae239fa95098134a1c71d9c0 Mon Sep 17 00:00:00 2001
From: gadmm <ga...@free.fr>
Date: Fri, 31 Jul 2015 01:05:54 +0100
Subject: [PATCH] Improve the performance of the source panel by using a
QTimer.
---
src/frontends/qt4/GuiViewSource.cpp | 32 ++++++++++++++++++++++++++------
src/frontends/qt4/GuiViewSource.h | 11 ++++++++++-
2 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp
index 3fcaed9..ede7e3e 100644
--- a/src/frontends/qt4/GuiViewSource.cpp
+++ b/src/frontends/qt4/GuiViewSource.cpp
@@ -46,7 +46,8 @@ namespace frontend {
ViewSourceWidget::ViewSourceWidget()
: bv_(0), document_(new QTextDocument(this)),
highlighter_(new LaTeXHighlighter(document_)),
- force_getcontent_(true)
+ force_getcontent_(true),
+ update_timer_(new QTimer(this))
{
setupUi(this);
@@ -55,14 +56,19 @@ ViewSourceWidget::ViewSourceWidget()
connect(autoUpdateCB, SIGNAL(toggled(bool)),
updatePB, SLOT(setDisabled(bool)));
connect(autoUpdateCB, SIGNAL(toggled(bool)),
- this, SLOT(updateView()));
+ this, SLOT(updateViewNow()));
connect(masterPerspectiveCB, SIGNAL(toggled(bool)),
- this, SLOT(updateView()));
+ this, SLOT(updateViewNow()));
connect(updatePB, SIGNAL(clicked()),
- this, SLOT(updateView()));
+ this, SLOT(updateViewNow()));
connect(outputFormatCO, SIGNAL(activated(int)),
this, SLOT(setViewFormat()));
+ // setting the update timer
+ update_timer_->setSingleShot(true);
+ connect(update_timer_, SIGNAL(timeout()),
+ this, SLOT(realUpdateView()));
+
// setting a document at this point trigger an assertion in Qt
// so we disable the signals here:
document_->blockSignals(true);
@@ -139,7 +145,7 @@ void ViewSourceWidget::setBufferView(BufferView const * bv)
void ViewSourceWidget::contentsChanged()
{
if (autoUpdateCB->isChecked())
- updateView();
+ updateViewNow();
}
@@ -147,12 +153,26 @@ void ViewSourceWidget::setViewFormat()
{
view_format_ = outputFormatCO->itemData(
outputFormatCO->currentIndex()).toString();
- updateView();
+ updateViewNow();
}
void ViewSourceWidget::updateView()
{
+ const int long_delay = 400;
+ const int short_delay = 40;
+ // a shorter delay if just the current paragraph is shown
+ update_timer_->start((contentsCO->currentIndex() == 0) ?
+ short_delay : long_delay);
+}
+
+void ViewSourceWidget::updateViewNow()
+{
+ update_timer_->start(0);
+}
+
+void ViewSourceWidget::realUpdateView()
+{
if (!bv_) {
document_->setPlainText(QString());
setEnabled(false);
diff --git a/src/frontends/qt4/GuiViewSource.h b/src/frontends/qt4/GuiViewSource.h
index c600269..d9425ac 100644
--- a/src/frontends/qt4/GuiViewSource.h
+++ b/src/frontends/qt4/GuiViewSource.h
@@ -20,6 +20,7 @@
#include <QDockWidget>
#include <QString>
+#include <QTimer>
class QTextDocument;
@@ -43,8 +44,10 @@ protected:
void resizeEvent (QResizeEvent * event);
public Q_SLOTS:
- /// update content
+ /// schedule an update after delay
void updateView();
+ /// schedule an update now
+ void updateViewNow();
///
void setViewFormat();
///
@@ -52,6 +55,10 @@ public Q_SLOTS:
///
void contentsChanged();
+private Q_SLOTS:
+ /// update content
+ void realUpdateView();
+
private:
///
BufferView const * bv_;
@@ -63,6 +70,8 @@ private:
bool force_getcontent_;
///
QString view_format_;
+ ///
+ QTimer * update_timer_;
};
--
2.1.4