Changeset - b55fa970f215
[Not reviewed]
Merge default
0 5 3
Hasan Yavuz ÖZDERYA - 7 years ago 2019-01-12 15:22:51
hy@ozderya.net
Merge with new-textview
8 files changed with 290 insertions and 7 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -64,12 +64,13 @@ qt5_wrap_ui(UI_FILES
 
  src/endiannessbox.ui
 
  src/binarystreamreadersettings.ui
 
  src/asciireadersettings.ui
 
  src/framedreadersettings.ui
 
  src/demoreadersettings.ui
 
  src/updatecheckdialog.ui
 
  src/datatextview.ui
 
  )
 

	
 
if (WIN32)
 
  qt5_add_resources(RES_FILES misc/icons.qrc misc/winicons.qrc)
 
else (WIN32)
 
  qt5_add_resources(RES_FILES misc/icons.qrc)
 
@@ -131,12 +132,13 @@ add_executable(${PROGRAM_NAME} WIN32
 
  src/updatecheckdialog.cpp
 
  src/samplepack.cpp
 
  src/source.cpp
 
  src/sink.cpp
 
  src/samplecounter.cpp
 
  src/ledwidget.cpp
 
  src/datatextview.cpp
 
  misc/windows_icon.rc
 
  ${UI_FILES}
 
  ${RES_FILES}
 
  )
 

	
 
# Use the Widgets module from Qt 5.
serialplot.pro
Show inline comments
 
@@ -68,13 +68,14 @@ SOURCES += \
 
    src/framedreader.cpp \
 
    src/plotmanager.cpp \
 
    src/numberformat.cpp \
 
    src/recordpanel.cpp \
 
    src/updatechecker.cpp \
 
    src/updatecheckdialog.cpp \
 
    src/demoreadersettings.cpp
 
    src/demoreadersettings.cpp \
 
    src/datatextview.cpp
 

	
 
HEADERS += \
 
    src/mainwindow.h \
 
    src/utils.h \
 
    src/portcontrol.h \
 
    src/floatswap.h \
 
@@ -111,13 +112,14 @@ HEADERS += \
 
    src/plotmanager.h \
 
    src/setting_defines.h \
 
    src/numberformat.h \
 
    src/recordpanel.h \
 
    src/updatechecker.h \
 
    src/updatecheckdialog.h \
 
    src/demoreadersettings.h
 
    src/demoreadersettings.h \
 
    src/datatextview.h
 

	
 
FORMS += \
 
    src/mainwindow.ui \
 
    src/about_dialog.ui \
 
    src/portcontrol.ui \
 
    src/snapshotview.ui \
 
@@ -129,13 +131,14 @@ FORMS += \
 
    src/endiannessbox.ui \
 
    src/framedreadersettings.ui \
 
    src/binarystreamreadersettings.ui \
 
    src/asciireadersettings.ui \
 
    src/recordpanel.ui \
 
    src/updatecheckdialog.ui \
 
    src/demoreadersettings.ui
 
    src/demoreadersettings.ui \
 
    src/datatextview.ui
 

	
 
INCLUDEPATH += qmake/ src/
 

	
 
CONFIG += c++11
 

	
 
RESOURCES += misc/icons.qrc
src/datatextview.cpp
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2019 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "datatextview.h"
 
#include "ui_datatextview.h"
 

	
 
#include "setting_defines.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<int>::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);
 
    }
 
}
 

	
 
void DataTextView::saveSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_Plot);
 
    settings->setValue(SG_TextView_NumLines, ui->spNumLines->value());
 
    settings->setValue(SG_TextView_Decimals, ui->spDecimals->value());
 
    settings->endGroup();
 
}
 

	
 
void DataTextView::loadSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_Plot);
 
    ui->spNumLines->setValue(
 
        settings->value(SG_TextView_NumLines, ui->spNumLines->value()).toInt());
 
    ui->spDecimals->setValue(
 
        settings->value(SG_TextView_Decimals, ui->spDecimals->value()).toInt());
 
    settings->endGroup();
 
}
src/datatextview.h
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2019 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef DATATEXTVIEW_H
 
#define DATATEXTVIEW_H
 

	
 
#include <QWidget>
 

	
 
#include "stream.h"
 

	
 
namespace Ui {
 
class DataTextView;
 
}
 

	
 
class DataTextViewSink;
 

	
 
class DataTextView : public QWidget
 
{
 
    Q_OBJECT
 

	
 
public:
 
    explicit DataTextView(Stream* stream, QWidget *parent = 0);
 
    ~DataTextView();
 

	
 
    /// Stores settings into a `QSettings`
 
    void saveSettings(QSettings* settings);
 
    /// Loads settings from a `QSettings`.
 
    void loadSettings(QSettings* settings);
 

	
 
protected:
 
    void addData(const SamplePack& data);
 

	
 
    friend DataTextViewSink;
 

	
 
private:
 
    Ui::DataTextView *ui;
 
    DataTextViewSink* sink;
 
    Stream* _stream;
 
};
 

	
 
#endif // DATATEXTVIEW_H
src/datatextview.ui
Show inline comments
 
new file 100644
 
<?xml version="1.0" encoding="UTF-8"?>
 
<ui version="4.0">
 
 <class>DataTextView</class>
 
 <widget class="QWidget" name="DataTextView">
 
  <property name="geometry">
 
   <rect>
 
    <x>0</x>
 
    <y>0</y>
 
    <width>451</width>
 
    <height>212</height>
 
   </rect>
 
  </property>
 
  <property name="windowTitle">
 
   <string>Form</string>
 
  </property>
 
  <layout class="QHBoxLayout" name="horizontalLayout">
 
   <item>
 
    <layout class="QVBoxLayout" name="verticalLayout">
 
     <item>
 
      <widget class="QCheckBox" name="cbEnable">
 
       <property name="toolTip">
 
        <string>Enable display of plotted data as text.</string>
 
       </property>
 
       <property name="text">
 
        <string>Enable</string>
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <widget class="QLabel" name="label">
 
       <property name="text">
 
        <string>Num. Lines:</string>
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <widget class="QSpinBox" name="spNumLines">
 
       <property name="minimum">
 
        <number>1</number>
 
       </property>
 
       <property name="maximum">
 
        <number>10000</number>
 
       </property>
 
       <property name="value">
 
        <number>1000</number>
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <widget class="QLabel" name="label_2">
 
       <property name="text">
 
        <string>Decimals:</string>
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <widget class="QSpinBox" name="spDecimals">
 
       <property name="maximum">
 
        <number>9</number>
 
       </property>
 
       <property name="value">
 
        <number>6</number>
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <spacer name="verticalSpacer">
 
       <property name="orientation">
 
        <enum>Qt::Vertical</enum>
 
       </property>
 
       <property name="sizeHint" stdset="0">
 
        <size>
 
         <width>20</width>
 
         <height>1</height>
 
        </size>
 
       </property>
 
      </spacer>
 
     </item>
 
     <item>
 
      <widget class="QPushButton" name="pbClear">
 
       <property name="text">
 
        <string>Clear</string>
 
       </property>
 
      </widget>
 
     </item>
 
    </layout>
 
   </item>
 
   <item>
 
    <widget class="QPlainTextEdit" name="textView">
 
     <property name="readOnly">
 
      <bool>true</bool>
 
     </property>
 
    </widget>
 
   </item>
 
  </layout>
 
 </widget>
 
 <resources/>
 
 <connections/>
 
</ui>
src/mainwindow.cpp
Show inline comments
 
/*
 
  Copyright © 2018 Hasan Yavuz Özderya
 
  Copyright © 2019 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
@@ -52,36 +52,39 @@ Q_IMPORT_PLUGIN(QWindowsIntegrationPlugi
 
const QMap<int, QString> panelSettingMap({
 
        {0, "Port"},
 
        {1, "DataFormat"},
 
        {2, "Plot"},
 
        {3, "Commands"},
 
        {4, "Record"},
 
        {5, "Log"}
 
        {5, "TextView"},
 
        {6, "Log"}
 
    });
 

	
 
MainWindow::MainWindow(QWidget *parent) :
 
    QMainWindow(parent),
 
    ui(new Ui::MainWindow),
 
    aboutDialog(this),
 
    portControl(&serialPort),
 
    secondaryPlot(NULL),
 
    snapshotMan(this, &stream),
 
    commandPanel(&serialPort),
 
    dataFormatPanel(&serialPort),
 
    recordPanel(&stream),
 
    textView(&stream),
 
    updateCheckDialog(this)
 
{
 
    ui->setupUi(this);
 

	
 
    plotMan = new PlotManager(ui->plotArea, &plotMenu, &stream);
 

	
 
    ui->tabWidget->insertTab(0, &portControl, "Port");
 
    ui->tabWidget->insertTab(1, &dataFormatPanel, "Data Format");
 
    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);
 
    addToolBar(recordPanel.toolbar());
 

	
 
    ui->plotToolBar->addAction(snapshotMan.takeSnapshotAction());
 
@@ -518,12 +521,13 @@ void MainWindow::saveAllSettings(QSettin
 
    dataFormatPanel.saveSettings(settings);
 
    stream.saveSettings(settings);
 
    plotControlPanel.saveSettings(settings);
 
    plotMenu.saveSettings(settings);
 
    commandPanel.saveSettings(settings);
 
    recordPanel.saveSettings(settings);
 
    textView.saveSettings(settings);
 
    updateCheckDialog.saveSettings(settings);
 
}
 

	
 
void MainWindow::loadAllSettings(QSettings* settings)
 
{
 
    loadMWSettings(settings);
 
@@ -531,12 +535,13 @@ void MainWindow::loadAllSettings(QSettin
 
    dataFormatPanel.loadSettings(settings);
 
    stream.loadSettings(settings);
 
    plotControlPanel.loadSettings(settings);
 
    plotMenu.loadSettings(settings);
 
    commandPanel.loadSettings(settings);
 
    recordPanel.loadSettings(settings);
 
    textView.loadSettings(settings);
 
    updateCheckDialog.loadSettings(settings);
 
}
 

	
 
void MainWindow::saveMWSettings(QSettings* settings)
 
{
 
    // save window geometry
src/mainwindow.h
Show inline comments
 
/*
 
  Copyright © 2018 Hasan Yavuz Özderya
 
  Copyright © 2019 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
@@ -43,12 +43,13 @@
 
#include "stream.h"
 
#include "snapshotmanager.h"
 
#include "plotmanager.h"
 
#include "plotmenu.h"
 
#include "updatecheckdialog.h"
 
#include "samplecounter.h"
 
#include "datatextview.h"
 

	
 
namespace Ui {
 
class MainWindow;
 
}
 

	
 
class MainWindow : public QMainWindow
 
@@ -86,12 +87,13 @@ private:
 
    QLabel spsLabel;
 
    CommandPanel commandPanel;
 
    DataFormatPanel dataFormatPanel;
 
    RecordPanel recordPanel;
 
    PlotControlPanel plotControlPanel;
 
    PlotMenu plotMenu;
 
    DataTextView textView;
 
    UpdateCheckDialog updateCheckDialog;
 

	
 
    /// Returns true if demo is running
 
    bool isDemoRunning();
 
    /// Display a secondary plot in the splitter, removing and
 
    /// deleting previous one if it exists
src/setting_defines.h
Show inline comments
 
/*
 
  Copyright © 2018 Hasan Yavuz Özderya
 
  Copyright © 2019 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
@@ -27,12 +27,13 @@ const char SettingGroup_Binary[] = "Data
 
const char SettingGroup_ASCII[] = "DataFormat_ASCII";
 
const char SettingGroup_CustomFrame[] = "DataFormat_CustomFrame";
 
const char SettingGroup_Channels[] = "Channels";
 
const char SettingGroup_Plot[] = "Plot";
 
const char SettingGroup_Commands[] = "Commands";
 
const char SettingGroup_Record[] = "Record";
 
const char SettingGroup_TextView[] = "TextView";
 
const char SettingGroup_UpdateCheck[] = "UpdateCheck";
 

	
 
// mainwindow setting keys
 
const char SG_MainWindow_Size[] = "size";
 
const char SG_MainWindow_Pos[] = "pos";
 
const char SG_MainWindow_ActivePanel[] = "activePanel";
 
@@ -109,11 +110,15 @@ const char SG_Record_RecordPaused[]     
 
const char SG_Record_StopOnClose[]      = "stopOnClose";
 
const char SG_Record_Header[]           = "header";
 
const char SG_Record_Separator[]        = "separator";
 
const char SG_Record_DisableBuffering[] = "disableBuffering";
 
const char SG_Record_Timestamp[]        = "timestamp";
 

	
 
// text view settings keys
 
const char SG_TextView_NumLines[] = "numLines";
 
const char SG_TextView_Decimals[] = "decimals";
 

	
 
// update check settings keys
 
const char SG_UpdateCheck_Periodic[]  = "periodicCheck";
 
const char SG_UpdateCheck_LastCheck[] = "lastCheck";
 

	
 
#endif // SETTING_DEFINES_H
0 comments (0 inline, 0 general)