Changeset - 6862f9405cdb
[Not reviewed]
Mehmet Aslan - 7 years ago 2019-04-04 03:23:29
aaslan-mehmet@hotmail.com
Nonexisting configuration file log changed and handled.
Minor name changes and fixes.
3 files changed with 13 insertions and 11 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -169,25 +169,25 @@ endif()
 
# default version
 
set(VERSION_STRING "0.10.0")
 
set(VERSION_REVISION "0")
 

	
 
# get revision number from mercurial and parse version string
 
include(GetVersion)
 

	
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVERSION_STRING=\\\"${VERSION_STRING}\\\" ")
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVERSION_MAJOR=${VERSION_MAJOR} ")
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVERSION_MINOR=${VERSION_MINOR} ")
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVERSION_PATCH=${VERSION_PATCH} ")
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVERSION_REVISION=\\\"${VERSION_REVISION}\\\" ")
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPROGRAM_NAME_STRING=\\\"${PROGRAM_NAME}\\\" ")
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPROGRAM_NAME=\\\"${PROGRAM_NAME}\\\" ")
 

	
 
# add make run target
 
add_custom_target(run
 
    COMMAND ${PROGRAM_NAME}
 
    DEPENDS ${PROGRAM_NAME}
 
    WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
 
)
 

	
 
# installing
 
install(TARGETS ${PROGRAM_NAME} DESTINATION bin)
 

	
 
# for windows put libraries to install directory
src/main.cpp
Show inline comments
 
@@ -61,25 +61,25 @@ void messageHandler(QtMsgType type, cons
 
        pMainWindow->messageHandler(type, logString, msg);
 
    }
 

	
 
    if (type == QtFatalMsg)
 
    {
 
        __builtin_trap();
 
    }
 
}
 

	
 
int main(int argc, char *argv[])
 
{
 
    QApplication a(argc, argv);
 
    QApplication::setApplicationName(PROGRAM_NAME_STRING);
 
    QApplication::setApplicationName(PROGRAM_NAME);
 
    QApplication::setApplicationVersion(VERSION_STRING);
 

	
 
    qInstallMessageHandler(messageHandler);
 
    MainWindow w;
 
    pMainWindow = &w;
 

	
 
    ToolTipFilter ttf;
 
    a.installEventFilter(&ttf);
 

	
 
    // log application information
 
    qDebug() << "SerialPlot" << VERSION_STRING;
 
    qDebug() << "Revision" << VERSION_REVISION;
src/mainwindow.cpp
Show inline comments
 
@@ -26,24 +26,25 @@
 
#include <QFile>
 
#include <QTextStream>
 
#include <QMenu>
 
#include <QDesktopServices>
 
#include <QMap>
 
#include <QtDebug>
 
#include <QCommandLineParser>
 
#include <QFileInfo>
 
#include <qwt_plot.h>
 
#include <limits.h>
 
#include <cmath>
 
#include <iostream>
 
#include <cstdlib>
 

	
 
#include <plot.h>
 
#include <barplot.h>
 

	
 
#include "framebufferseries.h"
 
#include "utils.h"
 
#include "defines.h"
 
#include "version.h"
 
#include "setting_defines.h"
 

	
 
#if defined(Q_OS_WIN) && defined(QT_STATIC)
 
#include <QtPlugin>
 
@@ -244,43 +245,43 @@ MainWindow::MainWindow(QWidget *parent) 
 
    QObject::connect(ui->actionDemoMode, &QAction::toggled,
 
                     this, &MainWindow::enableDemo);
 

	
 
    QObject::connect(ui->actionDemoMode, &QAction::toggled,
 
                     plotMan, &PlotManager::showDemoIndicator);
 

	
 
    // init stream connections
 
    connect(&dataFormatPanel, &DataFormatPanel::sourceChanged,
 
            this, &MainWindow::onSourceChanged);
 
    onSourceChanged(dataFormatPanel.activeSource());
 

	
 
    // load default settings
 
    QSettings settings(PROGRAM_NAME_STRING, PROGRAM_NAME_STRING);
 
    QSettings settings(PROGRAM_NAME, PROGRAM_NAME);
 
    loadAllSettings(&settings);
 

	
 
    handleCommandLineOptions(*QApplication::instance());
 

	
 
    // ensure command panel has 1 command if none loaded
 
    if (!commandPanel.numOfCommands())
 
    {
 
        commandPanel.newCommandAction()->trigger();
 
    }
 

	
 
    // Important: This should be after newCommandAction is triggered
 
    // (above) we don't want user to be greeted with command panel on
 
    // the very first run.
 
    connect(commandPanel.newCommandAction(), &QAction::triggered, [this]()
 
            {
 
                this->ui->tabWidget->setCurrentWidget(&commandPanel);
 
                this->ui->tabWidget->showTabs();
 
            });
 

	
 
    handleCommandLineOptions(*QApplication::instance());
 
}
 

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

	
 
    delete plotMan;
 

	
 
    delete ui;
 
@@ -295,25 +296,25 @@ void MainWindow::closeEvent(QCloseEvent 
 
        auto clickedButton = QMessageBox::warning(
 
            this, "Closing SerialPlot",
 
            "There are un-saved snapshots. If you close you will loose the data.",
 
            QMessageBox::Discard, QMessageBox::Cancel);
 
        if (clickedButton == QMessageBox::Cancel)
 
        {
 
            event->ignore();
 
            return;
 
        }
 
    }
 

	
 
    // save settings
 
    QSettings settings(PROGRAM_NAME_STRING, PROGRAM_NAME_STRING);
 
    QSettings settings(PROGRAM_NAME, PROGRAM_NAME);
 
    saveAllSettings(&settings);
 
    settings.sync();
 

	
 
    if (settings.status() != QSettings::NoError)
 
    {
 
        QString errorText;
 

	
 
        if (settings.status() == QSettings::AccessError)
 
        {
 
            QString file = settings.fileName();
 
            errorText = QString("Serialplot cannot save settings due to access error. \
 
This happens if you have run serialplot as root (with sudo for ex.) previously. \
 
@@ -592,49 +593,50 @@ void MainWindow::onLoadSettings()
 
        loadAllSettings(&settings);
 
    }
 
}
 

	
 
void MainWindow::handleCommandLineOptions(const QCoreApplication &app)
 
{
 
    QCommandLineParser parser;
 
    parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsCompactedShortOptions);
 
    parser.setApplicationDescription("Small and simple software for plotting data from serial port in realtime.");
 
    parser.addHelpOption();
 
    parser.addVersionOption();
 

	
 
    QCommandLineOption loadOpt({"l", "load"}, "Load settings from file.", "filename");
 
    QCommandLineOption configOpt({"c", "config"}, "Load configuration from file.", "filename");
 
    QCommandLineOption portOpt({"p", "port"}, "Set port name.", "port name");
 
    QCommandLineOption baudrateOpt({"b" ,"baudrate"}, "Set port baud rate.", "baud rate");
 
    QCommandLineOption openPortOpt({"o", "open"}, "Open serial port.");
 

	
 
    parser.addOption(loadOpt);
 
    parser.addOption(configOpt);
 
    parser.addOption(portOpt);
 
    parser.addOption(baudrateOpt);
 
    parser.addOption(openPortOpt);
 

	
 
    parser.process(app);
 

	
 
    if (parser.isSet(loadOpt))
 
    if (parser.isSet(configOpt))
 
    {
 
        QString fileName = parser.value(loadOpt);
 
        QString fileName = parser.value(configOpt);
 
        QFileInfo fileInfo(fileName);
 

	
 
        if (fileInfo.exists() && fileInfo.isFile())
 
        {
 
            QSettings settings(fileName, QSettings::IniFormat);
 
            loadAllSettings(&settings);
 
        }
 
        else
 
        {
 
            qWarning() << "Ini file not exist";
 
            qCritical() << "Configuration file not exist. Closing application.";
 
            std::exit(1);
 
        }
 
    }
 

	
 
    if (parser.isSet(portOpt))
 
    {
 
        portControl.selectPort(parser.value(portOpt));
 
    }
 

	
 
    if (parser.isSet(baudrateOpt))
 
    {
 
        portControl.selectBaudrate(parser.value(baudrateOpt));
 
    }
0 comments (0 inline, 0 general)