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
 
@@ -16,15 +16,27 @@
 
  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
 
@@ -25,12 +25,14 @@
 
#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),
 
@@ -595,6 +597,14 @@ void MainWindow::onExportCsv()
 
        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
 
@@ -26,12 +26,13 @@
 
#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 {
 
@@ -43,12 +44,15 @@ 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,
mainwindow.ui
Show inline comments
 
@@ -13,13 +13,13 @@
 
  <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>
 
@@ -301,12 +301,41 @@
 
           </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">
 
@@ -389,13 +418,13 @@
 
  </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/>
0 comments (0 inline, 0 general)