commit ba3e6cb2d226c670befb93d10a2b65d07aeefd2e
Author: Guillaume Munch <[email protected]>
Date: Fri Jul 31 01:05:54 2015 +0100
Improve the performance of the source panel by using a QTimer.
Fix bug #9493. The source panel was very slow with auto-update on. Now
we use a timer that ensures that the source is generated only at
rest. The delay is short or long depending on whether we show the
source of a paragraph or the whole source.
diff --git a/src/frontends/qt4/GuiViewSource.cpp
b/src/frontends/qt4/GuiViewSource.cpp
index 3fcaed9..50cfa31 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 = 60;
+ // 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_;
};