Changeset - cb28b6958b0e
[Not reviewed]
default
0 4 1
Hasan Yavuz ÖZDERYA - 10 years ago 2015-04-18 10:24:29
hy@ozderya.net
added about dialog
5 files changed with 113 insertions and 2 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -29,25 +29,25 @@ set(CMAKE_AUTOMOC ON)
 

	
 
# add local path for cmake modules
 
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
 

	
 
# Find the QtWidgets library
 
find_package(Qt5Widgets)
 
find_package(Qwt 6.1 REQUIRED)
 

	
 
# includes
 
include_directories(${QWT_INCLUDE_DIR})
 

	
 
# wrap UI files
 
qt5_wrap_ui(UI_FILES mainwindow.ui)
 
qt5_wrap_ui(UI_FILES mainwindow.ui about_dialog.ui)
 

	
 
# Tell CMake to create the helloworld executable
 
add_executable(serialplot main.cpp mainwindow.cpp customcheckablebutton.cpp ${UI_FILES})
 

	
 
# Use the Widgets module from Qt 5.
 
qt5_use_modules(serialplot Widgets SerialPort)
 
target_link_libraries(serialplot ${QWT_LIBRARY})
 

	
 
# Enable C++11 support, fail if not supported
 
include(CheckCXXCompilerFlag)
 
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
 
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
about_dialog.ui
Show inline comments
 
new file 100644
 
<?xml version="1.0" encoding="UTF-8"?>
 
<ui version="4.0">
 
 <class>AboutDialog</class>
 
 <widget class="QDialog" name="AboutDialog">
 
  <property name="geometry">
 
   <rect>
 
    <x>0</x>
 
    <y>0</y>
 
    <width>487</width>
 
    <height>300</height>
 
   </rect>
 
  </property>
 
  <property name="windowTitle">
 
   <string>About</string>
 
  </property>
 
  <layout class="QVBoxLayout" name="verticalLayout">
 
   <item>
 
    <widget class="QLabel" name="label">
 
     <property name="text">
 
      <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;SerialPlot&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;v0.1&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;Developed by Hasan Yavuz Özderya&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;Using Qt and Qwt (&lt;a href=&quot;http://qwt.sf.net&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;http://qwt.sf.net&lt;/span&gt;&lt;/a&gt;)&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;This software is GPL licensed. You can obtain source code from &lt;a href=&quot;https://bitbucket.org/hyOzd/serialplot&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;https://bitbucket.org/hyOzd/serialplot&lt;/span&gt;&lt;/a&gt;.&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
 
     </property>
 
     <property name="wordWrap">
 
      <bool>true</bool>
 
     </property>
 
     <property name="openExternalLinks">
 
      <bool>true</bool>
 
     </property>
 
    </widget>
 
   </item>
 
   <item>
 
    <layout class="QHBoxLayout" name="horizontalLayout">
 
     <item>
 
      <widget class="QPushButton" name="pbAboutQt">
 
       <property name="text">
 
        <string>About Qt</string>
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <widget class="QDialogButtonBox" name="buttonBox">
 
       <property name="orientation">
 
        <enum>Qt::Horizontal</enum>
 
       </property>
 
       <property name="standardButtons">
 
        <set>QDialogButtonBox::Close</set>
 
       </property>
 
      </widget>
 
     </item>
 
    </layout>
 
   </item>
 
  </layout>
 
 </widget>
 
 <resources/>
 
 <connections>
 
  <connection>
 
   <sender>buttonBox</sender>
 
   <signal>accepted()</signal>
 
   <receiver>AboutDialog</receiver>
 
   <slot>accept()</slot>
 
   <hints>
 
    <hint type="sourcelabel">
 
     <x>248</x>
 
     <y>254</y>
 
    </hint>
 
    <hint type="destinationlabel">
 
     <x>157</x>
 
     <y>274</y>
 
    </hint>
 
   </hints>
 
  </connection>
 
  <connection>
 
   <sender>buttonBox</sender>
 
   <signal>rejected()</signal>
 
   <receiver>AboutDialog</receiver>
 
   <slot>reject()</slot>
 
   <hints>
 
    <hint type="sourcelabel">
 
     <x>316</x>
 
     <y>260</y>
 
    </hint>
 
    <hint type="destinationlabel">
 
     <x>286</x>
 
     <y>274</y>
 
    </hint>
 
   </hints>
 
  </connection>
 
 </connections>
 
</ui>
mainwindow.cpp
Show inline comments
 
@@ -11,36 +11,44 @@
 
  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 <QSerialPortInfo>
 
#include <QApplication>
 
#include <QtDebug>
 
#include <qwt_plot.h>
 
#include <limits.h>
 
#include "utils.h"
 

	
 
MainWindow::MainWindow(QWidget *parent) :
 
    QMainWindow(parent),
 
    ui(new Ui::MainWindow)
 
{
 
    ui->setupUi(this);
 
    setupAboutDialog();
 

	
 
    // init UI signals
 

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

	
 
    // port tab signals
 
    QObject::connect(ui->pbReloadPorts, &QPushButton::clicked,
 
                     this, &MainWindow::loadPortList);
 

	
 
    QObject::connect(ui->pbOpenPort, &QPushButton::clicked,
 
                     this, &MainWindow::togglePort);
 

	
 
    QObject::connect(this, &MainWindow::portToggled,
 
                     this, &MainWindow::onPortToggled);
 

	
 
    QObject::connect(ui->cbPortList,
 
                     SELECT<const QString&>::OVERLOAD_OF(&QComboBox::activated),
 
                     this, &MainWindow::selectPort);
 
@@ -159,24 +167,33 @@ MainWindow::MainWindow(QWidget *parent) 
 
    }
 
}
 

	
 
MainWindow::~MainWindow()
 
{
 
    if (serialPort.isOpen())
 
    {
 
        serialPort.close();
 
    }
 
    delete ui;
 
}
 

	
 
void MainWindow::setupAboutDialog()
 
{
 
    Ui_AboutDialog uiAboutDialog;
 
    uiAboutDialog.setupUi(&aboutDialog);
 

	
 
    QObject::connect(uiAboutDialog.pbAboutQt, &QPushButton::clicked,
 
                     [](){ QApplication::aboutQt();});
 
}
 

	
 
void MainWindow::loadPortList()
 
{
 
    QString currentSelection = ui->cbPortList->currentText();
 

	
 
    ui->cbPortList->clear();
 

	
 
    for (auto port : QSerialPortInfo::availablePorts())
 
    {
 
        ui->cbPortList->addItem(port.portName());
 
    }
 

	
 
    // find current selection in the new list, maybe it doesn't exist anymore?
mainwindow.h
Show inline comments
 
@@ -19,24 +19,26 @@
 

	
 
#ifndef MAINWINDOW_H
 
#define MAINWINDOW_H
 

	
 
#include <QMainWindow>
 
#include <QButtonGroup>
 
#include <QString>
 
#include <QVector>
 
#include <QSerialPort>
 
#include <QSignalMapper>
 
#include <qwt_plot_curve.h>
 

	
 
#include "ui_about_dialog.h"
 

	
 
namespace Ui {
 
class MainWindow;
 
}
 

	
 
class MainWindow : public QMainWindow
 
{
 
    Q_OBJECT
 

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

	
 
@@ -49,24 +51,27 @@ private:
 
        NumberFormat_int8,
 
        NumberFormat_int16,
 
        NumberFormat_int32
 
    };
 

	
 
    Ui::MainWindow *ui;
 
    QButtonGroup numberFormatButtons;
 
    QButtonGroup parityButtons;
 
    QButtonGroup dataBitsButtons;
 
    QButtonGroup stopBitsButtons;
 
    QButtonGroup flowControlButtons;
 

	
 
    QDialog aboutDialog;
 
    void setupAboutDialog();
 

	
 
    QSerialPort serialPort;
 

	
 
    unsigned int numOfSamples;
 
    QwtPlotCurve curve;
 
    QVector<double> dataArray;
 
    QVector<double> dataX;
 
    void addData(QVector<double> data);
 

	
 
    NumberFormat numberFormat;
 
    unsigned int sampleSize; // number of bytes in the selected number format
 
    double (MainWindow::*readSample)();
 

	
serialplot.pro
Show inline comments
 
@@ -32,15 +32,16 @@ TEMPLATE = app
 

	
 
CONFIG += qwt
 

	
 

	
 
SOURCES += main.cpp\
 
        mainwindow.cpp \
 
    customcheckablebutton.cpp
 

	
 
HEADERS  += mainwindow.h \
 
    utils.h \
 
    customcheckablebutton.h
 

	
 
FORMS    += mainwindow.ui
 
FORMS    += mainwindow.ui \
 
    about_dialog.ui
 

	
 
CONFIG += c++11
0 comments (0 inline, 0 general)