From e5ff524e5b0dba7c8ccbb670ff32e0c95d50bcd4 Mon Sep 17 00:00:00 2001 From: m4444x Date: Mon, 9 Jun 2014 13:49:18 +0200 Subject: [PATCH 1/2] QPlainTextEdit based status log Replaced the lagging ListView with a QPlainTextEdit. This should run much smoother. --- mainwindow.cpp | 122 ++----------------------------------------------- mainwindow.h | 43 ----------------- mainwindow.ui | 45 ++++++------------ 3 files changed, 18 insertions(+), 192 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index eea9776..6fb3ba9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -25,7 +25,6 @@ MainWindow::MainWindow(QWidget *parent) : sliderPressed(false), sliderTo(0.0), sliderZCount(0), - scrollRequireMove(true), scrollPressed(false), queuedCommandsStarved(false), lastQueueCount(0), queuedCommandState(QCS_OK), lastLcdStateValid(true) { @@ -146,28 +145,9 @@ MainWindow::MainWindow(QWidget *parent) : connect(&runtimeTimer, SIGNAL(setRuntime(QString)), ui->outputRuntime, SLOT(setText(QString))); - // This code generates too many messages and chokes operation on raspberry pi. Do not use. - //connect(ui->statusList->model(), SIGNAL(rowsInserted(const QModelIndex&, int, int)), ui->statusList, SLOT(scrollToBottom())); - - // instead, use this one second timer-based approach - scrollTimer = new QTimer(this); - connect(scrollTimer, SIGNAL(timeout()), this, SLOT(doScroll())); - scrollTimer->start(1000); - connect(ui->statusList->verticalScrollBar(), SIGNAL(sliderPressed()), this, SLOT(statusSliderPressed())); - connect(ui->statusList->verticalScrollBar(), SIGNAL(sliderReleased()), this, SLOT(statusSliderReleased())); - runtimeTimerThread.start(); gcodeThread.start(); - // Don't use - it will not show horizontal scrollbar for small app size - //ui->statusList->setUniformItemSizes(true); - - // Does not work correctly for horizontal scrollbar: - //MyItemDelegate *scrollDelegate = new MyItemDelegate(ui->statusList); - //scrollDelegate->setWidth(600); - //ui->statusList->setItemDelegate(scrollDelegate); - - scrollStatusTimer.start(); queuedCommandsEmptyTimer.start(); queuedCommandsRefreshTimer.start(); @@ -249,7 +229,7 @@ MainWindow::MainWindow(QWidget *parent) : ui->btnGoHomeSafe->setEnabled(false); ui->pushButtonRefreshPos->setEnabled(false); styleSheet = ui->btnOpenPort->styleSheet(); - ui->statusList->setEnabled(true); + //ui->statusList->setEnabled(true); ui->openFile->setEnabled(true); this->setWindowTitle(GRBL_CONTROLLER_NAME_AND_VERSION); @@ -1197,26 +1177,11 @@ void MainWindow::addToStatusList(bool in, QString msg) if (!in) nMsg = "> " + msg; - fullStatus.append(msg); - ui->statusList->addItem(nMsg); - - status("%s", nMsg.toLocal8Bit().constData()); - - if (ui->statusList->count() > MAX_STATUS_LINES_WHEN_ACTIVE) - { - int count = ui->statusList->count() - MAX_STATUS_LINES_WHEN_ACTIVE; - for (int i = 0; i < count; i++) - { - ui->statusList->takeItem(0); - } - } - - scrollRequireMove = true; + ui->statusLog->appendPlainText( msg ); } void MainWindow::addToStatusList(QStringList& list) { - QStringList cleanList; foreach (QString msg, list) { msg = msg.trimmed(); @@ -1226,92 +1191,11 @@ void MainWindow::addToStatusList(QStringList& list) if (msg.length() == 0) continue; - cleanList.append(msg); - - fullStatus.append(msg); - + ui->statusLog->appendPlainText( msg ); status("%s", msg.toLocal8Bit().constData()); } - - if (cleanList.size() == 0) - return; - - ui->statusList->addItems(cleanList); - - if (ui->statusList->count() > MAX_STATUS_LINES_WHEN_ACTIVE) - { - int count = ui->statusList->count() - MAX_STATUS_LINES_WHEN_ACTIVE; - for (int i = 0; i < count; i++) - { - ui->statusList->takeItem(0); - } - } - - scrollRequireMove = true; } -void MainWindow::doScroll() -{ - if (!scrollPressed && scrollRequireMove)// && scrollStatusTimer.elapsed() > 1000) - { - ui->statusList->scrollToBottom(); - QApplication::processEvents(); - scrollStatusTimer.restart(); - scrollRequireMove = false; - } -} - -void MainWindow::statusSliderPressed() -{ - scrollPressed = true; - - if (scrollStatusTimer.elapsed() > 3000) - { - ui->statusList->clear(); - ui->statusList->addItems(fullStatus); - } -} - -void MainWindow::statusSliderReleased() -{ - scrollPressed = false; -} - -/* testing optimizing scrollbar, doesn't work -int MainWindow::computeListViewMinimumWidth(QAbstractItemView* view) -{ - int minWidth = 0; - QAbstractItemModel* model = view->model(); - - QStyleOptionViewItem option; - - int rowCount = model->rowCount(); - for (int row = 0; row < rowCount; ++row) - { - QModelIndex index = model->index(row, 0); - QSize size = view->itemDelegate()->sizeHint(option, index); - scrollDelegate = new MyItemDelegate(view); - view->setItemDelegate(scrollDelegate); - - minWidth = qMax(size.width(), minWidth); - } - - if (rowCount > 0) - { - if (scrollDelegate == NULL) - { - scrollDelegate = new MyItemDelegate(view); - QModelIndex index = model->index(0, 0); - view->setItemDelegate(scrollDelegate); - } - - scrollDelegate->setWidth(minWidth); - info("Width is %d\n", minWidth); - } - return minWidth; -} -*/ - void MainWindow::receiveMsg(QString msg) { ui->centralWidget->setStatusTip(msg); diff --git a/mainwindow.h b/mainwindow.h index 6add884..342b17d 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -17,7 +17,6 @@ #include #include #include -#include #include #include "about.h" #include "definitions.h" @@ -41,41 +40,6 @@ #define MAX_STATUS_LINES_WHEN_ACTIVE 200 -/* testing optimizing scrollbar, doesn't work right -class MyItemDelegate : public QItemDelegate -{ -private: - int width; - QAbstractItemView *parentWidget; - -public: - - MyItemDelegate(QAbstractItemView *p) : parentWidget(p) {} - - void setWidth(int w) - { - width = w; - } - - void drawDisplay(QPainter *painter,const - QStyleOptionViewItem &option,const QRect &rect,const QString &text) const{ - - QRect tempRect(rect); - tempRect.setWidth(parentWidget->width()); - QItemDelegate::drawDisplay(painter,option,tempRect,text); - - } - - QSize sizeHint(const QStyleOptionViewItem & option, const - QModelIndex & index ) const { - - QListView *list = qobject_cast(parentWidget); - QSize newSize(QItemDelegate::sizeHint(option,index)); - if( list ) newSize.setWidth( width ); - return newSize; - } -}; -*/ namespace Ui { class MainWindow; @@ -160,9 +124,6 @@ private slots: void zJogSliderDisplay(int pos); void zJogSliderPressed(); void zJogSliderReleased(); - void doScroll(); - void statusSliderPressed(); - void statusSliderReleased(); void setQueuedCommands(int commandCount, bool running); void setLcdState(bool valid); void refreshPosition(); @@ -212,7 +173,6 @@ private slots: Coord3D workCoordinates; bool absoluteAfterAxisAdj; bool checkLogWrite; - QTime scrollStatusTimer; QTime queuedCommandsEmptyTimer; QTime queuedCommandsRefreshTimer; QList posList; @@ -221,9 +181,6 @@ private slots: int sliderZCount; bool promptedAggrPreload; ControlParams controlParams; - QTimer *scrollTimer; - bool scrollRequireMove; - bool scrollPressed; bool queuedCommandsStarved; int lastQueueCount; int queuedCommandState; diff --git a/mainwindow.ui b/mainwindow.ui index 3cfbc95..188ed1a 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -344,36 +344,12 @@ - - - false - - - Qt::ScrollBarAsNeeded - - - 16 - - - QAbstractItemView::NoSelection - - - QAbstractItemView::ScrollPerPixel - - - QListView::Static - - - false - - - QListView::Adjust + + + QPlainTextEdit::NoWrap - - QListView::SinglePass - - - false + + true @@ -1541,7 +1517,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 From 67fb4d7d105bacbb68daa3efae13095516bee410 Mon Sep 17 00:00:00 2001 From: m4444x Date: Tue, 10 Jun 2014 10:45:58 +0200 Subject: [PATCH 2/2] added configuration option to limit the maximum number of status lines to log --- mainwindow.cpp | 2 ++ options.cpp | 4 ++++ options.h | 2 ++ options.ui | 12 +++++++++++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 6fb3ba9..4b546ca 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1005,6 +1005,8 @@ void MainWindow::setSettings() void MainWindow::updateSettingsFromOptionDlg(QSettings& settings) { + ui->statusLog->setMaximumBlockCount( settings.value( SETTINGS_MAX_STATUS_LINES, 0 ).value() ); + QString sinvX = settings.value(SETTINGS_INVERSE_X, "false").value(); QString sinvY = settings.value(SETTINGS_INVERSE_Y, "false").value(); QString sinvZ = settings.value(SETTINGS_INVERSE_Z, "false").value(); diff --git a/options.cpp b/options.cpp index 54a4cae..989a52d 100644 --- a/options.cpp +++ b/options.cpp @@ -94,6 +94,8 @@ Options::Options(QWidget *parent) : double zJogRate = settings.value(SETTINGS_Z_JOG_RATE, DEFAULT_Z_JOG_RATE).value(); ui->doubleSpinZJogRate->setValue(zJogRate); + ui->spinMaxStatusLines->setValue( settings.value( SETTINGS_MAX_STATUS_LINES, 0 ).value() ); + QString zRateLimit = settings.value(SETTINGS_Z_RATE_LIMIT, "false").value(); ui->chkLimitZRate->setChecked(zRateLimit == "true"); @@ -174,6 +176,8 @@ void Options::accept() settings.setValue(SETTINGS_TYPE_POS_REQ, getPosReqType()); settings.setValue(SETTINGS_POS_REQ_FREQ_SEC, ui->doubleSpinBoxPosRequestFreqSec->value()); + settings.setValue(SETTINGS_MAX_STATUS_LINES, ui->spinMaxStatusLines->value()); + connect(this, SIGNAL(setSettings()), parentWidget(), SLOT(setSettings())); emit setSettings(); diff --git a/options.h b/options.h index c97ea62..a364e81 100644 --- a/options.h +++ b/options.h @@ -53,6 +53,8 @@ #define SETTINGS_TYPE_POS_REQ "posRequestType" #define SETTINGS_POS_REQ_FREQ_SEC "posReqFreqSec" +#define SETTINGS_MAX_STATUS_LINES "maxStatusLines" + namespace Ui { class Options; diff --git a/options.ui b/options.ui index e4edec0..2ad8b56 100644 --- a/options.ui +++ b/options.ui @@ -35,7 +35,7 @@ 10 146 451 - 71 + 74 @@ -91,6 +91,16 @@ + + + + + + + Max Log Lines ( 0 : unlimited ) + + +