Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lagfreelog #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 5 additions & 119 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1025,6 +1005,8 @@ void MainWindow::setSettings()

void MainWindow::updateSettingsFromOptionDlg(QSettings& settings)
{
ui->statusLog->setMaximumBlockCount( settings.value( SETTINGS_MAX_STATUS_LINES, 0 ).value<int>() );

QString sinvX = settings.value(SETTINGS_INVERSE_X, "false").value<QString>();
QString sinvY = settings.value(SETTINGS_INVERSE_Y, "false").value<QString>();
QString sinvZ = settings.value(SETTINGS_INVERSE_Z, "false").value<QString>();
Expand Down Expand Up @@ -1197,26 +1179,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();
Expand All @@ -1226,91 +1193,10 @@ 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)
{
Expand Down
43 changes: 0 additions & 43 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <QSettings>
#include <QCloseEvent>
#include <QItemDelegate>
#include <QScrollBar>
#include <QListView>
#include "about.h"
#include "definitions.h"
Expand All @@ -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<QListView*>(parentWidget);
QSize newSize(QItemDelegate::sizeHint(option,index));
if( list ) newSize.setWidth( width );
return newSize;
}
};
*/

namespace Ui {
class MainWindow;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -212,7 +173,6 @@ private slots:
Coord3D workCoordinates;
bool absoluteAfterAxisAdj;
bool checkLogWrite;
QTime scrollStatusTimer;
QTime queuedCommandsEmptyTimer;
QTime queuedCommandsRefreshTimer;
QList<PosItem> posList;
Expand All @@ -221,9 +181,6 @@ private slots:
int sliderZCount;
bool promptedAggrPreload;
ControlParams controlParams;
QTimer *scrollTimer;
bool scrollRequireMove;
bool scrollPressed;
bool queuedCommandsStarved;
int lastQueueCount;
int queuedCommandState;
Expand Down
45 changes: 15 additions & 30 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -344,36 +344,12 @@
</layout>
</item>
<item>
<widget class="QListWidget" name="statusList">
<property name="enabled">
<bool>false</bool>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="autoScrollMargin">
<number>16</number>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="isWrapping" stdset="0">
<bool>false</bool>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
<widget class="QPlainTextEdit" name="statusLog">
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="layoutMode">
<enum>QListView::SinglePass</enum>
</property>
<property name="wordWrap">
<bool>false</bool>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1541,7 +1517,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down
4 changes: 4 additions & 0 deletions options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Options::Options(QWidget *parent) :
double zJogRate = settings.value(SETTINGS_Z_JOG_RATE, DEFAULT_Z_JOG_RATE).value<double>();
ui->doubleSpinZJogRate->setValue(zJogRate);

ui->spinMaxStatusLines->setValue( settings.value( SETTINGS_MAX_STATUS_LINES, 0 ).value<int>() );

QString zRateLimit = settings.value(SETTINGS_Z_RATE_LIMIT, "false").value<QString>();
ui->chkLimitZRate->setChecked(zRateLimit == "true");

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion options.ui
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<x>10</x>
<y>146</y>
<width>451</width>
<height>71</height>
<height>74</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="2,1">
Expand Down Expand Up @@ -91,6 +91,16 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinMaxStatusLines"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelMaxStatusLines">
<property name="text">
<string>Max Log Lines ( 0 : unlimited )</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="verticalLayoutWidget_2">
Expand Down