Dear list,
Here are all my patches to the View Source panel including the ones from
a preview thread with QTimers. This is for the latest master and it
compiles without --enable-cxx11.
Anybody curious can test the patches (please) and make suggestions while
it is still on the stove. See more detail about the changes in the
commit messages.
Remark: the highlighting is off by one line for the very last paragraph
(e.g. when writing in a new document); this is an existing bug in TexRow
which I did not take time to fix.
I also attach a correction to fr.po (source is not always LaTeX).
More specific answers follow.
Le 26/08/2015 13:18, Jean-Marc Lasgouttes a écrit :
Le 24/08/2015 21:19, Georg Baum a écrit :
- qt5 + --enable-cxx11 does not compile. I verified this and that the
patch
fixes the issue and does not break non-cxx11 builds, so I put it in.
Thanks. By the way, Georg, is there any plan to backport 125a2977 and
27f067dd?
- unique_ptr cannot be implemented safely without c++11, so as long as we
want to support C++98, you cannot use it. I agree with Jean-Marc here
that
C++98 support in 2.2 should be maintained. My experience with backporting
from a diverging master is that it is usually not difficult to do, but of
course it will be more than git-cherrypick.
C++98 it is, then.
I do not know that much about auto_ptr and unique_ptr, but would it be
possible to use auto_ptr as a poor man's unique_ptr? If yes, is it
dangerous?
As far as my code was concerned, it was an example where auto_ptr could
not work because I used it within a container. But, I further
reorganised the old code and I don't need the container anymore, which
is why I can now use an auto_ptr (but of course my question was to know
for the future).
- something needs to be done about auto_ptr when compiling with C++11
to get
rid of the warnings, but we don't know the solution yet.
It seems that some pragmas can help gcc >= 4.5
http://stackoverflow.com/questions/13459602/how-can-i-get-rid-of-deprecated-warnings-in-deprecated-functions-in-gcc
Did I miss anything?
Discussing whether we want to turn c++11 on automatically on platforms
that support it.
One problem that we have is that the compiler has to be in c++11 mode
_and_ the configure script has to be aware of it. Currently weird
compilers are not handled at all.
This goes a bit further than what I asked, so I will leave this between
you and Georg, all the more as I don't really have an opinion. I have my
answer: LyX will be not be C++11 until 2.3.
Guillaume
>From 0f39bf5052ce35cb5cfccd34776324351b4fa6c3 Mon Sep 17 00:00:00 2001
From: gadmm <ga...@free.fr>
Date: Tue, 4 Aug 2015 23:16:40 +0100
Subject: [PATCH 3/3] Improvements to the display of the source.
Fix bugs #6501 and #7359.
* Selection highlighting has been broken since a conflict with
reverse-search was repaired (at 00a62b7c), is now fixed.
* The selection highlighting was not accurate, for LaTeX formats (in
full source view), and meaningless, for non LaTeX formats.
* fix regression at cc00b9aa: force_getcontent_ was always true
therefore the code to detect changes in the generated source was
dead. The consequence is that the source view would jump to the
beginning at each updateView() even if no change occurred. Cc00b9aa
was meant to fix #5600, which I cannot reproduce with the new
implementation.
* Various improvements:
* When the position-to-line conversion is unavailable (LyXHTML, LyX
source, etc.) we focus on the first difference instead.
* Get some space around the cursor
* Respect the scrollbars
* Highlight with QTextEdit::ExtraSelections instead of cursor
selection (the latter used to break syntax highlighting of the
TeX code... which was not so much of an issue before because the
wrong part was selected)
---
src/Buffer.cpp | 25 +++--
src/Buffer.h | 7 +-
src/frontends/qt4/GuiViewSource.cpp | 204 ++++++++++++++++++++++++++----------
src/frontends/qt4/GuiViewSource.h | 11 +-
4 files changed, 174 insertions(+), 73 deletions(-)
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 09cff3c..bac45f3 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -3510,11 +3510,12 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to)
}
}
-
-void Buffer::getSourceCode(odocstream & os, string const & format,
+// returns NULL if id-to-row conversion is unsupported
+auto_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
pit_type par_begin, pit_type par_end,
OutputWhat output, bool master) const
{
+ auto_ptr<TexRow> texrow(NULL);
OutputParams runparams(¶ms().encoding());
runparams.nice = true;
runparams.flavor = params().getOutputFlavor(format);
@@ -3568,12 +3569,12 @@ void Buffer::getSourceCode(odocstream & os, string const & format,
LaTeXFeatures features(*this, params(), runparams);
params().validate(features);
runparams.use_polyglossia = features.usePolyglossia();
- TexRow texrow;
- texrow.reset();
- texrow.newline();
- texrow.newline();
+ texrow.reset(new TexRow());
+ texrow->reset();
+ texrow->newline();
+ texrow->newline();
// latex or literate
- otexstream ots(os, texrow);
+ otexstream ots(os, *texrow);
// the real stuff
latexParagraphs(*this, text(), ots, runparams);
@@ -3611,15 +3612,17 @@ void Buffer::getSourceCode(odocstream & os, string const & format,
writeDocBookSource(os, absFileName(), runparams, output);
} else {
// latex or literate
- d->texrow.reset();
- d->texrow.newline();
- d->texrow.newline();
- otexstream ots(os, d->texrow);
+ texrow.reset(new TexRow());
+ texrow->reset();
+ texrow->newline();
+ texrow->newline();
+ otexstream ots(os, *texrow);
if (master)
runparams.is_child = true;
writeLaTeXSource(ots, string(), runparams, output);
}
}
+ return texrow;
}
diff --git a/src/Buffer.h b/src/Buffer.h
index b50d5f4..e945fb3 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -618,9 +618,10 @@ public:
/// get source code (latex/docbook) for some paragraphs, or all paragraphs
/// including preamble
- void getSourceCode(odocstream & os, std::string const & format,
- pit_type par_begin, pit_type par_end, OutputWhat output,
- bool master) const;
+ /// returns NULL if Id to Row conversion is unsupported
+ std::auto_ptr<TexRow> getSourceCode(odocstream & os,
+ std::string const & format, pit_type par_begin,
+ pit_type par_end, OutputWhat output, bool master) const;
/// Access to error list.
/// This method is used only for GUI visualisation of Buffer related
diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp
index aa1b30d..799bf40 100644
--- a/src/frontends/qt4/GuiViewSource.cpp
+++ b/src/frontends/qt4/GuiViewSource.cpp
@@ -17,13 +17,11 @@
#include "LaTeXHighlighter.h"
#include "qt_helpers.h"
-#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "Cursor.h"
#include "Format.h"
#include "Paragraph.h"
-#include "TexRow.h"
#include "support/debug.h"
#include "support/lassert.h"
@@ -34,6 +32,7 @@
#include <QBoxLayout>
#include <QComboBox>
+#include <QScrollBar>
#include <QSettings>
#include <QTextCursor>
#include <QTextDocument>
@@ -47,7 +46,6 @@ namespace frontend {
ViewSourceWidget::ViewSourceWidget()
: bv_(0), document_(new QTextDocument(this)),
highlighter_(new LaTeXHighlighter(document_)),
- force_getcontent_(true),
update_timer_(new QTimer(this))
{
setupUi(this);
@@ -76,6 +74,8 @@ ViewSourceWidget::ViewSourceWidget()
// so we disable the signals here:
document_->blockSignals(true);
viewSourceTV->setDocument(document_);
+ // reset selections
+ setText();
document_->blockSignals(false);
viewSourceTV->setReadOnly(true);
///dialog_->viewSourceTV->setAcceptRichText(false);
@@ -89,21 +89,9 @@ ViewSourceWidget::ViewSourceWidget()
}
-static size_t crcCheck(docstring const & s)
-{
- boost::crc_32_type crc;
- crc.process_bytes(&s[0], sizeof(char_type) * s.size());
- return crc.checksum();
-}
-
-
-/** get the source code of selected paragraphs, or the whole document
- \param fullSource get full source code
- \return true if the content has changed since last call.
- */
-static bool getContent(BufferView const * view, Buffer::OutputWhat output,
- QString & qstr, string const & format, bool force_getcontent,
- bool master)
+auto_ptr<TexRow> ViewSourceWidget::getContent(BufferView const * view,
+ Buffer::OutputWhat output, docstring & str, string const & format,
+ bool master)
{
// get the *top* level paragraphs that contain the cursor,
// or the selected text
@@ -120,31 +108,33 @@ static bool getContent(BufferView const * view, Buffer::OutputWhat output,
if (par_begin > par_end)
swap(par_begin, par_end);
odocstringstream ostr;
- view->buffer().getSourceCode(ostr, format, par_begin, par_end + 1,
- output, master);
- docstring s = ostr.str();
- // FIXME THREAD
- // Could this be private to this particular dialog? We could have
- // more than one of these, in different windows.
- static size_t crc = 0;
- size_t newcrc = crcCheck(s);
- if (newcrc == crc && !force_getcontent)
- return false;
- crc = newcrc;
- qstr = toqstr(s);
- return true;
+ auto_ptr<TexRow> texrow = view->buffer().getSourceCode(ostr, format,
+ par_begin, par_end + 1, output, master);
+ str = ostr.str();
+ return texrow;
}
void ViewSourceWidget::setBufferView(BufferView const * bv)
{
- if (bv_ != bv)
- force_getcontent_ = true;
- bv_ = bv;
+ if (bv_ != bv) {
+ setText();
+ bv_ = bv;
+ }
setEnabled(bv ? true : false);
}
+bool ViewSourceWidget::setText(QString const & qstr)
+{
+ bool const changed = document_->toPlainText() != qstr;
+ viewSourceTV->setExtraSelections(QList<QTextEdit::ExtraSelection>());
+ if (changed)
+ document_->setPlainText(qstr);
+ return changed;
+}
+
+
void ViewSourceWidget::contentsChanged()
{
if (autoUpdateCB->isChecked())
@@ -176,16 +166,21 @@ void ViewSourceWidget::updateViewNow()
void ViewSourceWidget::realUpdateView()
{
if (!bv_) {
- document_->setPlainText(QString());
+ setText();
setEnabled(false);
return;
}
setEnabled(true);
+ // we will try to get that much space around the cursor
+ int const v_margin = 3;
+ int const h_margin = 10;
+ // we will try to preserve this
+ int const h_scroll = viewSourceTV->horizontalScrollBar()->value();
+
string const format = fromqstr(view_format_);
- QString content;
Buffer::OutputWhat output = Buffer::CurrentParagraph;
if (contentsCO->currentIndex() == 1)
output = Buffer::FullSource;
@@ -194,27 +189,121 @@ void ViewSourceWidget::realUpdateView()
else if (contentsCO->currentIndex() == 3)
output = Buffer::OnlyBody;
- if (getContent(bv_, output, content, format,
- force_getcontent_, masterPerspectiveCB->isChecked()))
- document_->setPlainText(content);
-
- CursorSlice beg = bv_->cursor().selectionBegin().bottom();
- CursorSlice end = bv_->cursor().selectionEnd().bottom();
- int const begrow = bv_->buffer().texrow().
- getRowFromIdPos(beg.paragraph().id(), beg.pos());
- int endrow = bv_->buffer().texrow().
- getRowFromIdPos(end.paragraph().id(), end.pos());
- int const nextendrow = bv_->buffer().texrow().
- getRowFromIdPos(end.paragraph().id(), end.pos() + 1);
- if (endrow != nextendrow)
- endrow = nextendrow - 1;
-
- QTextCursor c = QTextCursor(viewSourceTV->document());
- c.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, begrow);
- c.select(QTextCursor::BlockUnderCursor);
- c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor,
- endrow - begrow + 1);
- viewSourceTV->setTextCursor(c);
+ docstring content;
+ auto_ptr<TexRow> texrow = getContent(bv_, output, content, format,
+ masterPerspectiveCB->isChecked());
+ QString old = document_->toPlainText();
+ QString qcontent = toqstr(content);
+ bool const changed = setText(qcontent);
+
+ if (changed && !texrow.get()) {
+ // position-to-row is unavailable
+ // we jump to the first modification
+ const QChar * oc = old.constData();
+ const QChar * nc = qcontent.constData();
+ int pos = 0;
+ while (*oc != '\0' && *nc != '\0' && *oc == *nc) {
+ ++oc;
+ ++nc;
+ ++pos;
+ }
+ QTextCursor c = QTextCursor(viewSourceTV->document());
+ //get some space below the cursor
+ c.setPosition(pos);
+ c.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor,v_margin);
+ viewSourceTV->setTextCursor(c);
+ //get some space on the right of the cursor
+ viewSourceTV->horizontalScrollBar()->setValue(h_scroll);
+ c.setPosition(pos);
+ const int block = c.blockNumber();
+ for (int i = h_margin; i && block == c.blockNumber(); --i) {
+ c.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor);
+ }
+ c.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor);
+ viewSourceTV->setTextCursor(c);
+ //back to the position
+ c.setPosition(pos);
+ //c.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,1);
+ viewSourceTV->setTextCursor(c);
+
+ } else if (texrow.get()) {
+ // Use the available position-to-row conversion to highlight
+ // the current selection in the source
+ //
+ // FIXME:
+ // * it is currently impossible to highlight the very last line
+ // of a document, because TexRow gives the wrong data.
+ // * we currently only compute the top-level position, which
+ // makes it impossible to highlight inside an inset. It is not
+ // a limitation of TexRow, but replacing bottom() with top()
+ // works partially and causes segfaults with math. Solving
+ // this could be seen as a solution to #4725.
+ // * even if we keep computing the top-level position, the data
+ // given by TexRow is false if there is e.g. a float of a
+ // footnote in the paragraph
+ CursorSlice beg = bv_->cursor().selectionBegin().bottom();
+ CursorSlice end = bv_->cursor().selectionEnd().bottom();
+ int const beg_par = beg.paragraph().id();
+ int const end_par = end.paragraph().id();
+ int const beg_pos = beg.pos();
+ int const end_pos = end.pos();
+ int const beg_row = texrow->getRowFromIdPos(beg_par, beg_pos);
+ int end_row, next_end_row;
+ if (beg_par != end_par || beg_pos != end_pos) {
+ end_row = texrow->getRowFromIdPos(end_par, max(0, end_pos - 1));
+ next_end_row = texrow->getRowFromIdPos(end_par, end_pos);
+ } else {
+ end_row = beg_row;
+ next_end_row = texrow->getRowFromIdPos(beg_par, beg_pos + 1);
+ }
+ if (end_row != next_end_row)
+ end_row = next_end_row - 1;
+
+ QTextCursor c = QTextCursor(viewSourceTV->document());
+
+ c.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor,
+ beg_row - 1);
+ const int beg_sel = c.position();
+ //get some space above the cursor
+ c.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor,
+ v_margin);
+ viewSourceTV->setTextCursor(c);
+ c.setPosition(beg_sel, QTextCursor::MoveAnchor);
+
+ c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor,
+ end_row - beg_row +1);
+ const int end_sel = c.position();
+ //get some space below the cursor
+ c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor,
+ v_margin - 1);
+ viewSourceTV->setTextCursor(c);
+ c.setPosition(end_sel, QTextCursor::KeepAnchor);
+
+ viewSourceTV->setTextCursor(c);
+
+ //the real highlighting is done with an ExtraSelection
+ QTextCharFormat format;
+ QPalette palette = viewSourceTV->palette();
+ //Alternative:
+ // QColor bg = palette.color(QPalette::Active,QPalette::Highlight);
+ // bg.setAlpha(64);
+ // format.setBackground(QBrush(bg));
+ //Other alternatives:
+ //format.setBackground(palette.light());
+ //format.setBackground(palette.alternateBase());
+ format.setBackground(palette.toolTipBase());
+ format.setProperty(QTextFormat::FullWidthSelection, true);
+ QTextEdit::ExtraSelection sel;
+ sel.format = format;
+ sel.cursor = c;
+ viewSourceTV->setExtraSelections(
+ QList<QTextEdit::ExtraSelection>() << sel);
+
+ //clean up
+ c.clearSelection();
+ viewSourceTV->setTextCursor(c);
+ viewSourceTV->horizontalScrollBar()->setValue(h_scroll);
+ }
}
@@ -340,6 +429,7 @@ QString GuiViewSource::title() const
{
switch (docType()) {
case LATEX:
+ //FIXME: this is shown for LyXHTML source, LyX source, etc.
return qt_("LaTeX Source");
case DOCBOOK:
return qt_("DocBook Source");
diff --git a/src/frontends/qt4/GuiViewSource.h b/src/frontends/qt4/GuiViewSource.h
index ee664a2..7b451a6 100644
--- a/src/frontends/qt4/GuiViewSource.h
+++ b/src/frontends/qt4/GuiViewSource.h
@@ -16,7 +16,9 @@
#include "ui_ViewSourceUi.h"
+#include "Buffer.h"
#include "DockView.h"
+#include "TexRow.h"
#include <QDockWidget>
#include <QString>
@@ -38,6 +40,8 @@ public:
ViewSourceWidget();
///
void setBufferView(BufferView const * bv);
+ /// returns true if the string has changed
+ bool setText(QString const & qstr = QString());
///
void saveSession(QString const & session_key) const;
///
@@ -64,6 +68,11 @@ private Q_SLOTS:
void realUpdateView();
private:
+ /// Get the source code of selected paragraphs, or the whole document.
+ /// If TexRow is unavailable for the format then t is null.
+ std::auto_ptr<TexRow> getContent(BufferView const * view,
+ Buffer::OutputWhat output, docstring & str,
+ std::string const & format, bool master);
///
BufferView const * bv_;
///
@@ -71,8 +80,6 @@ private:
/// LaTeX syntax highlighter
LaTeXHighlighter * highlighter_;
///
- bool force_getcontent_;
- ///
QString view_format_;
///
QTimer * update_timer_;
--
2.1.4
>From 1010411b25157fe106136c0e3c5ad95c38188cbc Mon Sep 17 00:00:00 2001
From: gadmm <ga...@free.fr>
Date: Fri, 31 Jul 2015 01:05:54 +0100
Subject: [PATCH 2/3] Better session management for the source panel.
---
src/frontends/qt4/GuiViewSource.cpp | 65 ++++++++++++++++++++++++-------------
src/frontends/qt4/GuiViewSource.h | 8 +++--
2 files changed, 48 insertions(+), 25 deletions(-)
diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp
index 50cfa31..aa1b30d 100644
--- a/src/frontends/qt4/GuiViewSource.cpp
+++ b/src/frontends/qt4/GuiViewSource.cpp
@@ -33,6 +33,7 @@
#include <boost/crc.hpp>
#include <QBoxLayout>
+#include <QComboBox>
#include <QSettings>
#include <QTextCursor>
#include <QTextDocument>
@@ -56,13 +57,15 @@ ViewSourceWidget::ViewSourceWidget()
connect(autoUpdateCB, SIGNAL(toggled(bool)),
updatePB, SLOT(setDisabled(bool)));
connect(autoUpdateCB, SIGNAL(toggled(bool)),
- this, SLOT(updateViewNow()));
+ this, SLOT(contentsChanged()));
connect(masterPerspectiveCB, SIGNAL(toggled(bool)),
- this, SLOT(updateViewNow()));
+ this, SLOT(contentsChanged()));
connect(updatePB, SIGNAL(clicked()),
this, SLOT(updateViewNow()));
connect(outputFormatCO, SIGNAL(activated(int)),
- this, SLOT(setViewFormat()));
+ this, SLOT(setViewFormat(int)));
+ connect(outputFormatCO, SIGNAL(activated(int)),
+ this, SLOT(contentsChanged()));
// setting the update timer
update_timer_->setSingleShot(true);
@@ -149,11 +152,10 @@ void ViewSourceWidget::contentsChanged()
}
-void ViewSourceWidget::setViewFormat()
+void ViewSourceWidget::setViewFormat(int const index)
{
- view_format_ = outputFormatCO->itemData(
- outputFormatCO->currentIndex()).toString();
- updateViewNow();
+ outputFormatCO->setCurrentIndex(index);
+ view_format_ = outputFormatCO->itemData(index).toString();
}
@@ -244,7 +246,7 @@ void ViewSourceWidget::updateDefaultFormat()
if (qformat == view_format_)
index = outputFormatCO->count() -1;
}
- outputFormatCO->setCurrentIndex(index);
+ setViewFormat(index);
outputFormatCO->blockSignals(false);
}
@@ -262,6 +264,35 @@ void ViewSourceWidget::resizeEvent (QResizeEvent * event)
QWidget::resizeEvent(event);
}
+void ViewSourceWidget::saveSession(QString const & session_key) const
+{
+ QSettings settings;
+ settings.setValue(session_key + "/output", view_format_);
+ settings.setValue(session_key + "/contents", contentsCO->currentIndex());
+ settings.setValue(session_key + "/autoupdate", autoUpdateCB->isChecked());
+ settings.setValue(session_key + "/masterview",
+ masterPerspectiveCB->isChecked());
+}
+
+
+void ViewSourceWidget::restoreSession(QString const & session_key)
+{
+ QSettings settings;
+ view_format_ = settings.value(session_key + "/output", 0).toString();
+ contentsCO->setCurrentIndex(settings
+ .value(session_key + "/contents", 0)
+ .toInt());
+ masterPerspectiveCB->setChecked(settings
+ .value(session_key + "/masterview", false)
+ .toBool());
+ bool const checked = settings
+ .value(session_key + "/autoupdate", true)
+ .toBool();
+ autoUpdateCB->setChecked(checked);
+ if (checked)
+ updateView();
+}
+
GuiViewSource::GuiViewSource(GuiView & parent,
Qt::DockWidgetArea area, Qt::WindowFlags flags)
@@ -294,7 +325,7 @@ void GuiViewSource::enableView(bool enable)
widget_->updateDefaultFormat();
if (!enable)
// In the opposite case, updateView() will be called anyway.
- widget_->updateView();
+ widget_->contentsChanged();
}
@@ -323,26 +354,14 @@ QString GuiViewSource::title() const
void GuiViewSource::saveSession() const
{
Dialog::saveSession();
- QSettings settings;
- // see below
- // settings.setValue(
- // sessionKey() + "/output", widget_->contentsCO->currentIndex());
- settings.setValue(
- sessionKey() + "/autoupdate", widget_->autoUpdateCB->isChecked());
+ widget_->saveSession(sessionKey());
}
void GuiViewSource::restoreSession()
{
DockView::restoreSession();
- // FIXME: Full source updating is too slow to be done at startup.
- //widget_->outputCO-setCurrentIndex(
- // settings.value(sessionKey() + "/output", false).toInt());
- widget_->contentsCO->setCurrentIndex(0);
- QSettings settings;
- widget_->autoUpdateCB->setChecked(
- settings.value(sessionKey() + "/autoupdate", true).toBool());
- widget_->updateView();
+ widget_->restoreSession(sessionKey());
}
diff --git a/src/frontends/qt4/GuiViewSource.h b/src/frontends/qt4/GuiViewSource.h
index d9425ac..ee664a2 100644
--- a/src/frontends/qt4/GuiViewSource.h
+++ b/src/frontends/qt4/GuiViewSource.h
@@ -38,6 +38,10 @@ public:
ViewSourceWidget();
///
void setBufferView(BufferView const * bv);
+ ///
+ void saveSession(QString const & session_key) const;
+ ///
+ void restoreSession(QString const & session_key);
protected:
///
@@ -49,8 +53,8 @@ public Q_SLOTS:
/// schedule an update now
void updateViewNow();
///
- void setViewFormat();
- ///
+ void setViewFormat(int const index);
+ //
void updateDefaultFormat();
///
void contentsChanged();
--
2.1.4
>From a1956f9a74974d106aa1ba1c2ea2c85484eefcd7 Mon Sep 17 00:00:00 2001
From: gadmm <ga...@free.fr>
Date: Fri, 31 Jul 2015 01:05:54 +0100
Subject: [PATCH 1/3] Improve the performance of the source panel by using a
QTimer.
Fix bug #9493.
---
src/frontends/qt4/GuiViewSource.cpp | 32 ++++++++++++++++++++++++++------
src/frontends/qt4/GuiViewSource.h | 11 ++++++++++-
2 files changed, 36 insertions(+), 7 deletions(-)
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_;
};
--
2.1.4
diff --git a/po/fr.po b/po/fr.po
index a9d3517..7e69b2d 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -23201,16 +23201,16 @@ msgstr "Erreur à l'exécution de commandes externes."
#: src/Buffer.cpp:3560
#, c-format
msgid "Preview source code for paragraph %1$d"
-msgstr "Visionner le code LaTeX du paragraphe %1$d"
+msgstr "Visionner le code source du paragraphe %1$d"
#: src/Buffer.cpp:3564
#, c-format
msgid "Preview source code from paragraph %1$s to %2$s"
-msgstr "Visionner le code LaTeX des paragraphes %1$s à %2$s"
+msgstr "Visionner le code source des paragraphes %1$s à %2$s"
#: src/Buffer.cpp:3618
msgid "Preview source code"
-msgstr "Visionner le code LaTeX"
+msgstr "Visionner le code source"
#: src/Buffer.cpp:3620
msgid "Preview preamble"