2021-09-01 14:01:00 -05:00
|
|
|
#include "SeerVariableLoggerBrowserWidget.h"
|
|
|
|
|
#include "SeerUtl.h"
|
|
|
|
|
#include <QtWidgets/QTreeWidget>
|
|
|
|
|
#include <QtWidgets/QTreeWidgetItemIterator>
|
|
|
|
|
#include <QtWidgets/QApplication>
|
|
|
|
|
#include <QtCore/QRegExp>
|
|
|
|
|
#include <QtCore/QTime>
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
|
|
|
|
|
SeerVariableLoggerBrowserWidget::SeerVariableLoggerBrowserWidget (QWidget* parent) : QWidget(parent) {
|
|
|
|
|
|
|
|
|
|
// Construct the UI.
|
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
|
|
// Setup the widgets
|
2021-10-10 12:57:30 -05:00
|
|
|
variablesTreeWidget->setMouseTracking(true);
|
2021-09-01 14:01:00 -05:00
|
|
|
variablesTreeWidget->setSortingEnabled(false);
|
|
|
|
|
variablesTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(0); // id
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(1); // timestamp
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(2); // name
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(3); // value
|
2022-12-24 15:42:07 -06:00
|
|
|
variablesTreeWidget->setColumnHidden(0, true); // Hide the 'number' column.
|
2021-09-01 14:01:00 -05:00
|
|
|
variablesTreeWidget->clear();
|
|
|
|
|
|
|
|
|
|
// Connect things.
|
2021-10-10 12:57:30 -05:00
|
|
|
QObject::connect(this, &SeerVariableLoggerBrowserWidget::evaluateVariableExpression, this, &SeerVariableLoggerBrowserWidget::handleEvaluateVariableExpression);
|
2022-08-10 20:17:07 -05:00
|
|
|
QObject::connect(variableAddLineEdit, &QLineEdit::returnPressed, this, &SeerVariableLoggerBrowserWidget::handleAddLineEdit);
|
2021-10-10 12:57:30 -05:00
|
|
|
QObject::connect(variableDeleteToolButton, &QToolButton::clicked, this, &SeerVariableLoggerBrowserWidget::handleDeleteToolButton);
|
|
|
|
|
QObject::connect(variableDeleteAllToolButton, &QToolButton::clicked, this, &SeerVariableLoggerBrowserWidget::handleDeleteAllToolButton);
|
|
|
|
|
QObject::connect(variablesTreeWidget, &QTreeWidget::itemEntered, this, &SeerVariableLoggerBrowserWidget::handleItemEntered);
|
2021-09-01 14:01:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SeerVariableLoggerBrowserWidget::~SeerVariableLoggerBrowserWidget () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerVariableLoggerBrowserWidget::handleText (const QString& text) {
|
|
|
|
|
|
|
|
|
|
QApplication::setOverrideCursor(Qt::BusyCursor);
|
|
|
|
|
|
|
|
|
|
if (text.contains(QRegExp("^([0-9]+)\\^done,value="))) {
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
//qDebug() << text;
|
2021-09-01 14:01:00 -05:00
|
|
|
|
|
|
|
|
// "6^done,value=\"\\\"abc\\\"\""
|
|
|
|
|
|
|
|
|
|
QString id_text = text.section('^', 0,0);
|
|
|
|
|
QString value_text = Seer::parseFirst(text, "value=", '"', '"', false);
|
|
|
|
|
|
2022-12-24 15:42:07 -06:00
|
|
|
if (_ids.contains(id_text.toInt()) == true) {
|
2021-09-01 14:01:00 -05:00
|
|
|
|
2022-12-24 15:42:07 -06:00
|
|
|
QList<QTreeWidgetItem*> matches = variablesTreeWidget->findItems(id_text, Qt::MatchExactly, 0);
|
|
|
|
|
|
|
|
|
|
if (matches.size() > 0) {
|
|
|
|
|
matches.first()->setText(3, Seer::filterEscapes(value_text));
|
|
|
|
|
}
|
2021-09-01 14:01:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else if (text.contains(QRegExp("^([0-9]+)\\^error,msg="))) {
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
//qDebug() << text;
|
2021-09-01 14:01:00 -05:00
|
|
|
|
|
|
|
|
// "1^error,msg=\"No symbol \\\"j\\\" in current context.\""
|
|
|
|
|
|
|
|
|
|
QString id_text = text.section('^', 0,0);
|
|
|
|
|
QString msg_text = Seer::parseFirst(text, "msg=", '"', '"', false);
|
|
|
|
|
|
2022-12-24 15:42:07 -06:00
|
|
|
if (_ids.contains(id_text.toInt()) == true) {
|
|
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem*> matches = variablesTreeWidget->findItems(id_text, Qt::MatchExactly, 0);
|
2021-09-01 14:01:00 -05:00
|
|
|
|
2022-12-24 15:42:07 -06:00
|
|
|
if (matches.size() > 0) {
|
|
|
|
|
matches.first()->setText(3, Seer::filterEscapes(msg_text));
|
|
|
|
|
}
|
2021-09-01 14:01:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else if (text.startsWith("^error,msg=\"No registers.\"")) {
|
2022-12-24 15:42:07 -06:00
|
|
|
|
2021-09-01 14:01:00 -05:00
|
|
|
variablesTreeWidget->clear();
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
// Ignore others.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resize columns.
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(0);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(1);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(2);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(3);
|
|
|
|
|
|
|
|
|
|
// Scroll to the bottom.
|
|
|
|
|
QTreeWidgetItem* lastItem = variablesTreeWidget->topLevelItem(variablesTreeWidget->topLevelItemCount()-1);
|
|
|
|
|
if (lastItem) {
|
|
|
|
|
variablesTreeWidget->scrollToItem(lastItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the cursor back.
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerVariableLoggerBrowserWidget::handleEvaluateVariableExpression (int expressionid, QString expression) {
|
|
|
|
|
|
|
|
|
|
QString id_text = QString::number(expressionid);
|
|
|
|
|
|
2022-12-24 15:42:07 -06:00
|
|
|
if (_ids.contains(id_text.toInt()) == false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-01 14:01:00 -05:00
|
|
|
QList<QTreeWidgetItem*> matches = variablesTreeWidget->findItems(id_text, Qt::MatchExactly, 0);
|
|
|
|
|
|
|
|
|
|
// Reuse existing item.
|
|
|
|
|
if (matches.size() > 0) {
|
|
|
|
|
matches.first()->setText(1, QTime::currentTime().toString(Qt::TextDate));
|
|
|
|
|
matches.first()->setText(2, "");
|
|
|
|
|
matches.first()->setText(3, "");
|
|
|
|
|
|
|
|
|
|
// Add new item.
|
|
|
|
|
}else{
|
|
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem;
|
|
|
|
|
item->setText(0, id_text);
|
|
|
|
|
item->setText(1, QTime::currentTime().toString(Qt::TextDate));
|
|
|
|
|
item->setText(2, expression);
|
|
|
|
|
item->setText(3, "");
|
|
|
|
|
|
|
|
|
|
variablesTreeWidget->addTopLevelItem(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resize columns.
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(0);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(1);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(2);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(3);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 16:10:25 -05:00
|
|
|
void SeerVariableLoggerBrowserWidget::addVariableExpression (QString expression) {
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
//qDebug();
|
2021-11-03 16:10:25 -05:00
|
|
|
|
|
|
|
|
if (expression != "") {
|
|
|
|
|
|
|
|
|
|
int id = Seer::createID();
|
|
|
|
|
|
|
|
|
|
emit evaluateVariableExpression(id, expression);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-01 14:01:00 -05:00
|
|
|
void SeerVariableLoggerBrowserWidget::handleAddLineEdit () {
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
//qDebug();
|
2021-09-01 14:01:00 -05:00
|
|
|
|
|
|
|
|
QString variable = variableAddLineEdit->text();
|
|
|
|
|
|
|
|
|
|
variableAddLineEdit->clear();
|
|
|
|
|
|
|
|
|
|
if (variable != "") {
|
|
|
|
|
|
|
|
|
|
int id = Seer::createID();
|
|
|
|
|
|
2022-12-24 15:42:07 -06:00
|
|
|
_ids.insert(id); // Keep track of which ones are entered.
|
|
|
|
|
|
2021-09-01 14:01:00 -05:00
|
|
|
emit evaluateVariableExpression(id, variable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerVariableLoggerBrowserWidget::handleDeleteToolButton () {
|
|
|
|
|
|
|
|
|
|
// Get selected tree items.
|
|
|
|
|
QList<QTreeWidgetItem*> items = variablesTreeWidget->selectedItems();
|
|
|
|
|
|
|
|
|
|
// Remove them.
|
|
|
|
|
for(int i=0; i<items.size(); i++){
|
|
|
|
|
delete items[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resize columns.
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(0);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(1);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(2);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerVariableLoggerBrowserWidget::handleDeleteAllToolButton () {
|
|
|
|
|
|
|
|
|
|
// Remove all.
|
|
|
|
|
variablesTreeWidget->clear();
|
|
|
|
|
|
|
|
|
|
// Resize columns.
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(0);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(1);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(2);
|
|
|
|
|
variablesTreeWidget->resizeColumnToContents(3);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-10 12:57:30 -05:00
|
|
|
void SeerVariableLoggerBrowserWidget::handleItemEntered (QTreeWidgetItem* item, int column) {
|
|
|
|
|
|
2022-04-28 20:20:37 -05:00
|
|
|
Q_UNUSED(column);
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
//qDebug() << item->text(0) << column;
|
2021-10-10 12:57:30 -05:00
|
|
|
|
|
|
|
|
item->setToolTip(0, item->text(1) + " : " + item->text(2) + " : " + item->text(3));
|
|
|
|
|
|
|
|
|
|
for (int i=1; i<variablesTreeWidget->columnCount(); i++) { // Copy tooltip to other columns.
|
|
|
|
|
item->setToolTip(i, item->toolTip(0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|