]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/TocWidget.cpp
Fix the tab ordering of GuiDocument components.
[lyx.git] / src / frontends / qt4 / TocWidget.cpp
index be4c9c7696adc5cda0af02bb524bb7c660bdfc9b..80c9db97d952a6ab773ca96eca3f0675fbc5f7a8 100644 (file)
 
 #include <vector>
 
+#define DELAY_UPDATE_VIEW
+
 using namespace std;
 
 namespace lyx {
 namespace frontend {
 
 TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
-       : QWidget(parent), depth_(0), persistent_(false), gui_view_(gui_view)
+       : QWidget(parent), depth_(0), persistent_(false), gui_view_(gui_view), update_delay_(0)
+
 {
        setupUi(this);
 
@@ -242,14 +245,14 @@ void TocWidget::on_updateTB_clicked()
        // The backend update can take some time so we disable
        // the controls while waiting.
        enableControls(false);
-       gui_view_.tocModels().updateBackend();
+       gui_view_.currentBufferView()->buffer().updateBuffer();
 }
 
 
 void TocWidget::on_sortCB_stateChanged(int state)
 {
        gui_view_.tocModels().sort(current_type_, state == Qt::Checked);
-       updateView();
+       updateViewForce();
 }
 
 
@@ -317,7 +320,7 @@ void TocWidget::on_typeCO_currentIndexChanged(int index)
        if (index == -1)
                return;
        current_type_ = typeCO->itemData(index).toString();
-       updateView();
+       updateViewForce();
        if (typeCO->hasFocus())
                gui_view_.setFocus();
 }
@@ -389,6 +392,27 @@ void TocWidget::enableControls(bool enable)
 
 void TocWidget::updateView()
 {
+// Enable if you dont want the delaying business, cf #7138.
+#ifndef DELAY_UPDATE_VIEW
+       updateViewForce();
+       return;
+#endif
+       // already scheduled?
+       if (update_delay_ == -1)
+               return;
+       QTimer::singleShot(update_delay_, this, SLOT(updateViewForce()));
+       // Subtler optimization for having the delay more UI invisible.
+       // We trigger update immediately for sparse editation actions,
+       // i.e. there was no editation/cursor movement in last 2 sec.
+       // At worst there will be +1 redraw after 2s in a such "calm" mode.
+       if (update_delay_ != 0)
+               updateViewForce();
+       update_delay_ = -1;
+}
+
+void TocWidget::updateViewForce()
+{
+       update_delay_ = 2000;
        if (!gui_view_.documentBufferView()) {
                tocTV->setModel(0);
                depthSL->setMaximum(0);
@@ -495,7 +519,7 @@ void TocWidget::init(QString const & str)
                new_index = typeCO->findData(decodeType(str));
 
        // If everything else fails, settle on the table of contents which is
-       // guaranted to exist.
+       // guaranteed to exist.
        if (new_index == -1) {
                current_type_ = "tableofcontents";
                new_index = typeCO->findData(current_type_);
@@ -506,6 +530,9 @@ void TocWidget::init(QString const & str)
        typeCO->blockSignals(true);
        typeCO->setCurrentIndex(new_index);
        typeCO->blockSignals(false);
+
+       // no delay when the whole outliner is reseted.
+       update_delay_ = 0;
 }
 
 } // namespace frontend