Append newline to end-of-console when resetting
MODIFY
src/console.cpp
src/console.cpp
@@ -50,6 +50,11 @@ void Console::putData(const QByteArray& data) {
bar->setValue(bar->maximum());
}
+void Console::clearConsole() {
+ clear();
+ m_buffer.clear();
+}
+
void Console::backspace() {
// Deletes the last character in the console
auto cursorAtEnd = QTextCursor(document());
@@ -65,6 +70,7 @@ void Console::keyPressEvent(QKeyEvent* e) {
case Qt::Key_Right:
case Qt::Key_Up:
case Qt::Key_Down:
+ QPlainTextEdit::keyPressEvent(e);
break;
default:
if (!e->text().isEmpty()) {

MODIFY
src/console.h
src/console.h
@@ -13,12 +13,13 @@ signals:
public:
Console(QWidget* parent = nullptr);
+ void putData(const QByteArray& data);
+ void clearConsole();
protected:
void keyPressEvent(QKeyEvent* e) override;
private:
- void putData(const QByteArray& data);
void backspace();
bool m_localEchoEnabled = false;

MODIFY
src/processortab.cpp
src/processortab.cpp
@@ -98,13 +98,7 @@ ProcessorTab::ProcessorTab(QToolBar* controlToolbar, QToolBar* additionalToolbar
m_statUpdateTimer->setInterval(100);
connect(m_statUpdateTimer, &QTimer::timeout, this, &ProcessorTab::updateStatistics);
- // Connect ECALL functionality to application output log and scroll to bottom
- connect(this, &ProcessorTab::appendToLog, [this](QString string) {
- m_ui->console->insertPlainText(string);
- m_ui->console->verticalScrollBar()->setValue(m_ui->console->verticalScrollBar()->maximum());
- });
-
- connect(m_ui->clearConsoleButton, &QPushButton::clicked, m_ui->console, &QPlainTextEdit::clear);
+ connect(m_ui->clearConsoleButton, &QPushButton::clicked, m_ui->console, &Console::clearConsole);
m_ui->clearConsoleButton->setIcon(QIcon(":/icons/clear.svg"));
m_ui->clearConsoleButton->setToolTip("Clear console");
@@ -128,9 +122,7 @@ ProcessorTab::ProcessorTab(QToolBar* controlToolbar, QToolBar* additionalToolbar
}
void ProcessorTab::printToLog(const QString& text) {
- m_ui->console->moveCursor(QTextCursor::End);
- m_ui->console->insertPlainText(text);
- m_ui->console->verticalScrollBar()->setValue(m_ui->console->verticalScrollBar()->maximum());
+ m_ui->console->putData(text.toUtf8());
}
void ProcessorTab::loadLayout(const Layout& layout) {
@@ -422,7 +414,7 @@ void ProcessorTab::reset() {
emit processorWasReset();
enableSimulatorControls();
- emit appendToLog("\n");
+ printToLog("\n");
}
void ProcessorTab::setInstructionViewCenterAddr(uint32_t address) {

MODIFY
src/processortab.h
src/processortab.h
@@ -38,7 +38,6 @@ public:
signals:
void update();
void processorWasReset();
- void appendToLog(QString string);
public slots:
void pause();

Append newline to end-of-console when resetting