#include <QHeaderView>
#include <QMenu>
-#include <QTimer>
#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), update_delay_(0)
+ : QWidget(parent), depth_(0), persistent_(false), gui_view_(gui_view),
+ update_timer_short_(new QTimer(this)),
+ update_timer_long_(new QTimer(this))
{
setupUi(this);
connect(filterLE, SIGNAL(textEdited(QString)),
this, SLOT(filterContents()));
+ // setting the update timer
+ update_timer_short_->setSingleShot(true);
+ update_timer_long_->setSingleShot(true);
+ update_timer_short_->setInterval(0);
+ update_timer_long_->setInterval(2000);
+ connect(update_timer_short_, SIGNAL(timeout()),
+ this, SLOT(realUpdateView()));
+ connect(update_timer_long_, SIGNAL(timeout()),
+ this, SLOT(realUpdateView()));
+
init(QString());
}
void TocWidget::on_sortCB_stateChanged(int state)
{
gui_view_.tocModels().sort(current_type_, state == Qt::Checked);
- updateViewForce();
+ updateViewNow();
}
if (index == -1)
return;
current_type_ = typeCO->itemData(index).toString();
- updateViewForce();
+ updateViewNow();
if (typeCO->hasFocus())
gui_view_.setFocus();
}
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;
+ if (!update_timer_long_->isActive())
+ update_timer_short_->start();
+ // resets the timer to trigger after 2s
+ update_timer_long_->start();
}
-void TocWidget::updateViewForce()
+void TocWidget::updateViewNow()
+{
+ update_timer_long_->stop();
+ update_timer_short_->start();
+}
+
+void TocWidget::realUpdateView()
{
- update_delay_ = 2000;
if (!gui_view_.documentBufferView()) {
tocTV->setModel(0);
depthSL->setMaximum(0);
{
if (!gui_view_.documentBufferView() ||
gui_view_.tocModels().model(current_type_) != tocTV->model())
- updateViewForce();
+ realUpdateView();
}
typeCO->blockSignals(true);
typeCO->setCurrentIndex(new_index);
typeCO->blockSignals(false);
-
- // no delay when the whole outliner is reseted.
- update_delay_ = 0;
}
} // namespace frontend
#include "Cursor.h"
#include "FuncCode.h"
+#include <QTimer>
#include <QWidget>
class QModelIndex;
void checkModelChanged();
public Q_SLOTS:
- /// Schedule new update of the display unless already scheduled.
+ /// Schedule an update of the dialog after a delay
void updateView();
- /// Update the display of the dialog whilst it is still visible.
- void updateViewForce();
+ /// Schedule an update of the dialog immediately
+ void updateViewNow();
protected Q_SLOTS:
///
void showContextMenu(const QPoint & pos);
+private Q_SLOTS:
+ /// Update the display of the dialog
+ void realUpdateView();
+
private:
///
void enableControls(bool enable = true);
bool persistent_;
///
GuiView & gui_view_;
- // next delay for outliner update in ms. -1 when already scheduled.
- int update_delay_;
+ // Timers for scheduling updates: one immediately and one after a delay.
+ // This is according to the logic of the previous code: when at rest, the
+ // update is carried out immediately, and when an update was done recently,
+ // we schedule an update to occur 2s after resting.
+ QTimer * update_timer_short_;
+ QTimer * update_timer_long_;
};
} // namespace frontend