mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
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.
This commit is contained in:
parent
4d1ad336db
commit
ba3e6cb2d2
@ -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());
|
||||
|
@ -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_;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user