Skip to content
Snippets Groups Projects
Commit cb6f0dfb authored by mae's avatar mae
Browse files

Re-fix output window. Scrolling was messed up when long paragraphs with

line wrap were appended, also appendOutput and appendOutputInline ended
up doing almost the same thing. It might be that appendOutput is called
in some places where appendOutputInline would be more adequate. The code
now tries to called QPlainTextEdit::appendPlainText() whenever it can
because of its update optimizations when it comes to enforcing maximum
block count. We want application output to be processed fast, even if
the maximum block count was reached!
parent 9fc41bc8
No related branches found
No related tags found
No related merge requests found
...@@ -340,6 +340,8 @@ bool OutputPane::canNavigate() ...@@ -340,6 +340,8 @@ bool OutputPane::canNavigate()
OutputWindow::OutputWindow(QWidget *parent) OutputWindow::OutputWindow(QWidget *parent)
: QPlainTextEdit(parent) : QPlainTextEdit(parent)
{ {
m_enforceNewline = false;
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
//setCenterOnScroll(false); //setCenterOnScroll(false);
setWindowTitle(tr("Application Output Window")); setWindowTitle(tr("Application Output Window"));
...@@ -392,14 +394,13 @@ OutputWindow::~OutputWindow() ...@@ -392,14 +394,13 @@ OutputWindow::~OutputWindow()
void OutputWindow::appendOutput(const QString &out) void OutputWindow::appendOutput(const QString &out)
{ {
QString s = out;
m_enforceNewline = true; // make appendOutputInline put in a newline next time
if (s.endsWith(QLatin1Char('\n'))) {
s.chop(1);
}
setMaximumBlockCount(MaxBlockCount); setMaximumBlockCount(MaxBlockCount);
moveCursor(QTextCursor::End); appendPlainText(out);
if (out.endsWith('\n'))
insertPlainText(out.right(out.length()-1));
else
insertPlainText(out);
// insert newline and get automatic scroll behavior
appendPlainText(""); // makes sure that there's an newline in front
enableUndoRedo(); enableUndoRedo();
} }
...@@ -408,26 +409,32 @@ void OutputWindow::appendOutputInline(const QString &out) ...@@ -408,26 +409,32 @@ void OutputWindow::appendOutputInline(const QString &out)
{ {
setMaximumBlockCount(MaxBlockCount); setMaximumBlockCount(MaxBlockCount);
int newline = out.indexOf(QLatin1Char('\n')); int newline = -1;
if (newline < 0) { bool enforceNewline = m_enforceNewline;
m_enforceNewline = false;
if (!enforceNewline) {
newline = out.indexOf(QLatin1Char('\n'));
moveCursor(QTextCursor::End); moveCursor(QTextCursor::End);
insertPlainText(out); // doesn't insert additional '\n' like appendPlainText bool atBottom = (blockBoundingRect(document()->lastBlock()).bottom() + contentOffset().y()
}else{ <= viewport()->rect().bottom());
int lastnewline = out.lastIndexOf(QLatin1Char('\n')); insertPlainText(newline < 0 ? out : out.left(newline)); // doesn't enforce new paragraph like appendPlainText
// make sure that we use appendPlainText to add the last newline if (atBottom)
// in the string, so we get automatic scrolling verticalScrollBar()->setValue(verticalScrollBar()->maximum());
// and work around the fact that appendPlainText also ensures }
// a newline in front of the appended text
if (lastnewline > 0) { QString s = out.mid(newline+1);
moveCursor(QTextCursor::End); if (s.isEmpty()) {
insertPlainText(out.left(lastnewline)); m_enforceNewline = true;
} } else {
appendPlainText(""); // add the newline if (s.endsWith(QLatin1Char('\n'))) {
if (lastnewline < out.length()-1) { // newline is not last character m_enforceNewline = true;
moveCursor(QTextCursor::End); qDebug() << "CHOP";
insertPlainText(out.mid(lastnewline+1)); s.chop(1);
} }
appendPlainText(s);
} }
enableUndoRedo(); enableUndoRedo();
} }
......
...@@ -129,6 +129,7 @@ public: ...@@ -129,6 +129,7 @@ public:
private: private:
Core::BaseContext *m_outputWindowContext; Core::BaseContext *m_outputWindowContext;
void enableUndoRedo(); void enableUndoRedo();
bool m_enforceNewline;
}; };
#if 0 #if 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment