Changeset - f918be7cd46f
[Not reviewed]
default
0 4 0
Hasan Yavuz ÖZDERYA - 10 years ago 2015-05-28 09:57:27
hy@ozderya.net
added log widget for error and warning messages
4 files changed with 58 insertions and 3 deletions:
0 comments (0 inline, 0 general)
main.cpp
Show inline comments
 
/*
 
  Copyright © 2015 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 "mainwindow.h"
 
#include <QApplication>
 
#include <QtGlobal>
 

	
 
MainWindow* pMainWindow;
 

	
 
void messageHandler(QtMsgType type, const QMessageLogContext &context,
 
                    const QString &msg)
 
{
 
    pMainWindow->messageHandler(type, context, msg);
 
}
 

	
 
int main(int argc, char *argv[])
 
{
 
    QApplication a(argc, argv);
 
    MainWindow w;
 
    pMainWindow = &w;
 

	
 
    qInstallMessageHandler(messageHandler);
 

	
 
    w.show();
 

	
 
    return a.exec();
 
}
mainwindow.cpp
Show inline comments
 
@@ -7,48 +7,50 @@
 
  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 "mainwindow.h"
 
#include "ui_mainwindow.h"
 
#include <QByteArray>
 
#include <QApplication>
 
#include <QFileDialog>
 
#include <QFile>
 
#include <QTextStream>
 
#include <QtDebug>
 
#include <qwt_plot.h>
 
#include <limits.h>
 
#include <cmath>
 
#include <iostream>
 

	
 
#include "utils.h"
 
#include "version.h"
 

	
 
MainWindow::MainWindow(QWidget *parent) :
 
    QMainWindow(parent),
 
    ui(new Ui::MainWindow),
 
    portControl(&serialPort)
 
{
 
    ui->setupUi(this);
 
    ui->tabWidget->insertTab(0, &portControl, "Port");
 
    ui->tabWidget->setCurrentIndex(0);
 

	
 
    setupAboutDialog();
 

	
 
    // init UI signals
 

	
 
    // menu signals
 
    QObject::connect(ui->actionHelpAbout, &QAction::triggered,
 
              &aboutDialog, &QWidget::show);
 

	
 
    QObject::connect(ui->actionExportCsv, &QAction::triggered,
 
                     this, &MainWindow::onExportCsv);
 

	
 
    QObject::connect(&portControl, &PortControl::portToggled,
 
@@ -577,24 +579,32 @@ void MainWindow::onExportCsv()
 

	
 
            for (unsigned int ci = 0; ci < numOfChannels; ci++)
 
            {
 
                fileStream << "Channel " << ci;
 
                if (ci != numOfChannels-1) fileStream << ",";
 
            }
 
            fileStream << '\n';
 

	
 
            for (unsigned int i = 0; i < numOfSamples; i++)
 
            {
 
                for (unsigned int ci = 0; ci < numOfChannels; ci++)
 
                {
 
                    fileStream << channelsData[ci][i];
 
                    if (ci != numOfChannels-1) fileStream << ",";
 
                }
 
                fileStream << '\n';
 
            }
 
        }
 
        else
 
        {
 
            qDebug() << "File open error during export: " << file.error();
 
        }
 
    }
 
}
 

	
 
void MainWindow::messageHandler(QtMsgType type,
 
                                const QMessageLogContext &context,
 
                                const QString &msg)
 
{
 
    ui->ptLog->appendPlainText(msg);
 
    std::cerr << msg.toStdString() << std::endl;
 
}
mainwindow.h
Show inline comments
 
@@ -8,65 +8,69 @@
 
  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 MAINWINDOW_H
 
#define MAINWINDOW_H
 

	
 
#include <QMainWindow>
 
#include <QButtonGroup>
 
#include <QString>
 
#include <QVector>
 
#include <QList>
 
#include <QSerialPort>
 
#include <QSignalMapper>
 
#include <QTimer>
 
#include <QColor>
 
#include <QtGlobal>
 
#include <qwt_plot_curve.h>
 

	
 
#include "portcontrol.h"
 
#include "ui_about_dialog.h"
 

	
 
namespace Ui {
 
class MainWindow;
 
}
 

	
 
class MainWindow : public QMainWindow
 
{
 
    Q_OBJECT
 

	
 
public:
 
    explicit MainWindow(QWidget *parent = 0);
 
    ~MainWindow();
 

	
 
    void messageHandler(QtMsgType type, const QMessageLogContext &context,
 
                        const QString &msg);
 

	
 
private:
 
    enum NumberFormat
 
    {
 
        NumberFormat_uint8,
 
        NumberFormat_uint16,
 
        NumberFormat_uint32,
 
        NumberFormat_int8,
 
        NumberFormat_int16,
 
        NumberFormat_int32,
 
        NumberFormat_float,
 
        NumberFormat_ASCII
 
    };
 

	
 
    Ui::MainWindow *ui;
 
    QButtonGroup numberFormatButtons;
 

	
 
    QDialog aboutDialog;
 
    void setupAboutDialog();
 

	
 
    QSerialPort serialPort;
 
    PortControl portControl;
 

	
 
    unsigned int numOfSamples;
 
    unsigned int numOfChannels;
mainwindow.ui
Show inline comments
 
<?xml version="1.0" encoding="UTF-8"?>
 
<ui version="4.0">
 
 <class>MainWindow</class>
 
 <widget class="QMainWindow" name="MainWindow">
 
  <property name="geometry">
 
   <rect>
 
    <x>0</x>
 
    <y>0</y>
 
    <width>653</width>
 
    <height>534</height>
 
   </rect>
 
  </property>
 
  <property name="windowTitle">
 
   <string>SerialPlot</string>
 
  </property>
 
  <widget class="QWidget" name="centralWidget">
 
   <layout class="QVBoxLayout" name="verticalLayout_2">
 
    <item>
 
     <widget class="QwtPlot" name="plot" native="true">
 
     <widget class="QwtPlot" name="plot">
 
      <property name="sizePolicy">
 
       <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
 
        <horstretch>0</horstretch>
 
        <verstretch>0</verstretch>
 
       </sizepolicy>
 
      </property>
 
     </widget>
 
    </item>
 
    <item>
 
     <widget class="QTabWidget" name="tabWidget">
 
      <property name="sizePolicy">
 
       <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
 
        <horstretch>0</horstretch>
 
        <verstretch>0</verstretch>
 
       </sizepolicy>
 
      </property>
 
      <property name="minimumSize">
 
       <size>
 
        <width>0</width>
 
        <height>0</height>
 
       </size>
 
      </property>
 
      <property name="maximumSize">
 
       <size>
 
@@ -283,48 +283,77 @@
 
          </item>
 
          <item row="2" column="1">
 
           <widget class="QDoubleSpinBox" name="spYmax">
 
            <property name="enabled">
 
             <bool>false</bool>
 
            </property>
 
            <property name="maximumSize">
 
             <size>
 
              <width>75</width>
 
              <height>16777215</height>
 
             </size>
 
            </property>
 
            <property name="maximum">
 
             <double>1000.000000000000000</double>
 
            </property>
 
            <property name="value">
 
             <double>1000.000000000000000</double>
 
            </property>
 
           </widget>
 
          </item>
 
         </layout>
 
        </item>
 
       </layout>
 
      </widget>
 
      <widget class="QWidget" name="tabLog">
 
       <attribute name="title">
 
        <string>Log</string>
 
       </attribute>
 
       <attribute name="toolTip">
 
        <string>Error and Warning Messages</string>
 
       </attribute>
 
       <layout class="QHBoxLayout" name="horizontalLayout">
 
        <property name="leftMargin">
 
         <number>4</number>
 
        </property>
 
        <property name="topMargin">
 
         <number>4</number>
 
        </property>
 
        <property name="rightMargin">
 
         <number>4</number>
 
        </property>
 
        <property name="bottomMargin">
 
         <number>4</number>
 
        </property>
 
        <item>
 
         <widget class="QPlainTextEdit" name="ptLog">
 
          <property name="readOnly">
 
           <bool>true</bool>
 
          </property>
 
         </widget>
 
        </item>
 
       </layout>
 
      </widget>
 
     </widget>
 
    </item>
 
   </layout>
 
  </widget>
 
  <widget class="QMenuBar" name="menuBar">
 
   <property name="geometry">
 
    <rect>
 
     <x>0</x>
 
     <y>0</y>
 
     <width>653</width>
 
     <height>20</height>
 
    </rect>
 
   </property>
 
   <widget class="QMenu" name="menuHelp">
 
    <property name="title">
 
     <string>Help</string>
 
    </property>
 
    <addaction name="actionDemoMode"/>
 
    <addaction name="actionHelpAbout"/>
 
   </widget>
 
   <widget class="QMenu" name="menuFile">
 
    <property name="title">
 
     <string>File</string>
 
    </property>
 
@@ -371,32 +400,32 @@
 
  <action name="actionDemoMode">
 
   <property name="checkable">
 
    <bool>true</bool>
 
   </property>
 
   <property name="text">
 
    <string>Demo Mode</string>
 
   </property>
 
   <property name="toolTip">
 
    <string>Toggle Demo Mode</string>
 
   </property>
 
  </action>
 
  <action name="actionExportCsv">
 
   <property name="text">
 
    <string>Export CSV</string>
 
   </property>
 
   <property name="toolTip">
 
    <string>Export plot data to CSV</string>
 
   </property>
 
  </action>
 
 </widget>
 
 <layoutdefault spacing="6" margin="11"/>
 
 <customwidgets>
 
  <customwidget>
 
   <class>QwtPlot</class>
 
   <extends>QWidget</extends>
 
   <extends>QFrame</extends>
 
   <header>qwt_plot.h</header>
 
   <container>1</container>
 
  </customwidget>
 
 </customwidgets>
 
 <resources/>
 
 <connections/>
 
</ui>
0 comments (0 inline, 0 general)