# HG changeset patch # User Hasan Yavuz ÖZDERYA # Date 2019-01-12 15:06:14 # Node ID 8d241dce831048549dc435cf81ed2bf3ea129276 # Parent ba9e01b30ba26d522b552f72513d83a67a26916c added text view widget diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ qt5_wrap_ui(UI_FILES src/framedreadersettings.ui src/demoreadersettings.ui src/updatecheckdialog.ui + src/datatextview.ui ) if (WIN32) @@ -134,6 +135,7 @@ add_executable(${PROGRAM_NAME} WIN32 src/sink.cpp src/samplecounter.cpp src/ledwidget.cpp + src/datatextview.cpp misc/windows_icon.rc ${UI_FILES} ${RES_FILES} diff --git a/serialplot.pro b/serialplot.pro --- a/serialplot.pro +++ b/serialplot.pro @@ -71,7 +71,8 @@ SOURCES += \ src/recordpanel.cpp \ src/updatechecker.cpp \ src/updatecheckdialog.cpp \ - src/demoreadersettings.cpp + src/demoreadersettings.cpp \ + src/datatextview.cpp HEADERS += \ src/mainwindow.h \ @@ -114,7 +115,8 @@ HEADERS += \ src/recordpanel.h \ src/updatechecker.h \ src/updatecheckdialog.h \ - src/demoreadersettings.h + src/demoreadersettings.h \ + src/datatextview.h FORMS += \ src/mainwindow.ui \ @@ -132,7 +134,8 @@ FORMS += \ src/asciireadersettings.ui \ src/recordpanel.ui \ src/updatecheckdialog.ui \ - src/demoreadersettings.ui + src/demoreadersettings.ui \ + src/datatextview.ui INCLUDEPATH += qmake/ src/ diff --git a/src/datatextview.cpp b/src/datatextview.cpp new file mode 100644 --- /dev/null +++ b/src/datatextview.cpp @@ -0,0 +1,72 @@ +#include "datatextview.h" +#include "ui_datatextview.h" + +#include "utils.h" + +class DataTextViewSink : public Sink +{ +public: + DataTextViewSink(DataTextView* textView) + { + _textView = textView; + } + +protected: + virtual void feedIn(const SamplePack& data) override + { + _textView->addData(data); + }; + +private: + DataTextView* _textView; +}; + +DataTextView::DataTextView(Stream* stream, QWidget *parent) : + QWidget(parent), + ui(new Ui::DataTextView) +{ + _stream = stream; + ui->setupUi(this); + sink = new DataTextViewSink(this); + + connect(ui->cbEnable, &QCheckBox::toggled, [this](bool checked) + { + if (checked) + { + _stream->connectFollower(sink); + } + else + { + _stream->disconnectFollower(sink); + } + }); + + ui->textView->setMaximumBlockCount(ui->spNumLines->value()); + connect(ui->spNumLines, SELECT::OVERLOAD_OF(&QSpinBox::valueChanged), + [this](int value) + { + ui->textView->setMaximumBlockCount(value); + }); + + connect(ui->pbClear, &QPushButton::clicked, ui->textView, &QPlainTextEdit::clear); +} + +DataTextView::~DataTextView() +{ + delete sink; + delete ui; +} + +void DataTextView::addData(const SamplePack& data) +{ + for (unsigned int i = 0; i < data.numSamples(); i++) + { + QString str; + for (unsigned ci = 0; ci < data.numChannels(); ci++) + { + str += QString::number(data.data(ci)[i], 'f', ui->spDecimals->value()); + if (ci != data.numChannels()-1) str += " "; + } + ui->textView->appendPlainText(str); + } +} diff --git a/src/datatextview.h b/src/datatextview.h new file mode 100644 --- /dev/null +++ b/src/datatextview.h @@ -0,0 +1,33 @@ +#ifndef DATATEXTVIEW_H +#define DATATEXTVIEW_H + +#include + +#include "stream.h" + +namespace Ui { +class DataTextView; +} + +class DataTextViewSink; + +class DataTextView : public QWidget +{ + Q_OBJECT + +public: + explicit DataTextView(Stream* stream, QWidget *parent = 0); + ~DataTextView(); + +protected: + void addData(const SamplePack& data); + + friend DataTextViewSink; + +private: + Ui::DataTextView *ui; + DataTextViewSink* sink; + Stream* _stream; +}; + +#endif // DATATEXTVIEW_H diff --git a/src/datatextview.ui b/src/datatextview.ui new file mode 100644 --- /dev/null +++ b/src/datatextview.ui @@ -0,0 +1,99 @@ + + + DataTextView + + + + 0 + 0 + 451 + 212 + + + + Form + + + + + + + + Enable display of plotted data as text. + + + Enable + + + + + + + Num. Lines: + + + + + + + 1 + + + 10000 + + + 1000 + + + + + + + Decimals: + + + + + + + 9 + + + 6 + + + + + + + Qt::Vertical + + + + 20 + 1 + + + + + + + + Clear + + + + + + + + + true + + + + + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,5 +1,5 @@ /* - Copyright © 2018 Hasan Yavuz Özderya + Copyright © 2019 Hasan Yavuz Özderya This file is part of serialplot. @@ -55,7 +55,8 @@ const QMap panelSettingMap {2, "Plot"}, {3, "Commands"}, {4, "Record"}, - {5, "Log"} + {5, "TextView"}, + {6, "Log"} }); MainWindow::MainWindow(QWidget *parent) : @@ -68,6 +69,7 @@ MainWindow::MainWindow(QWidget *parent) commandPanel(&serialPort), dataFormatPanel(&serialPort), recordPanel(&stream), + textView(&stream), updateCheckDialog(this) { ui->setupUi(this); @@ -79,6 +81,7 @@ MainWindow::MainWindow(QWidget *parent) ui->tabWidget->insertTab(2, &plotControlPanel, "Plot"); ui->tabWidget->insertTab(3, &commandPanel, "Commands"); ui->tabWidget->insertTab(4, &recordPanel, "Record"); + ui->tabWidget->insertTab(5, &textView, "Text View"); ui->tabWidget->setCurrentIndex(0); auto tbPortControl = portControl.toolBar(); addToolBar(tbPortControl); diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,5 +1,5 @@ /* - Copyright © 2018 Hasan Yavuz Özderya + Copyright © 2019 Hasan Yavuz Özderya This file is part of serialplot. @@ -46,6 +46,7 @@ #include "plotmenu.h" #include "updatecheckdialog.h" #include "samplecounter.h" +#include "datatextview.h" namespace Ui { class MainWindow; @@ -89,6 +90,7 @@ private: RecordPanel recordPanel; PlotControlPanel plotControlPanel; PlotMenu plotMenu; + DataTextView textView; UpdateCheckDialog updateCheckDialog; /// Returns true if demo is running