]> git.lyx.org Git - features.git/commitdiff
Improve the performance of the source panel by using a QTimer.
authorGuillaume Munch <gm@lyx.org>
Fri, 31 Jul 2015 00:05:54 +0000 (01:05 +0100)
committerGuillaume Munch <gm@lyx.org>
Sat, 12 Sep 2015 23:45:41 +0000 (00:45 +0100)
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.

src/frontends/qt4/GuiViewSource.cpp
src/frontends/qt4/GuiViewSource.h

index 3fcaed984a97337dbe0c670ee529e9c4931232f1..50cfa31257793d35b448a8ee8056fca2afb3d91f 100644 (file)
@@ -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,11 +153,25 @@ 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());
index c60026945add83391ad0d2536031b4d18174ed1a..d9425ac0907ccad0dbdc20f06d2f88074daa13b2 100644 (file)
@@ -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_;
 };