Changeset - 52acb9a759b7
[Not reviewed]
default
0 6 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-09-17 11:48:37
hy@ozderya.net
warn user if snapshot is not saved
6 files changed with 46 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/mainwindow.cpp
Show inline comments
 
@@ -22,6 +22,7 @@
 
#include <QByteArray>
 
#include <QApplication>
 
#include <QFileDialog>
 
#include <QMessageBox>
 
#include <QFile>
 
#include <QTextStream>
 
#include <QMenu>
 
@@ -230,6 +231,24 @@ MainWindow::~MainWindow()
 
    ui = NULL; // we check if ui is deleted in messageHandler
 
}
 

	
 
void MainWindow::closeEvent(QCloseEvent * event)
 
{
 
    if (!snapshotMan.isAllSaved())
 
    {
 
        auto clickedButton = QMessageBox::warning(
 
            this, "Closing SerialPlot",
 
            "There are un-saved snapshots. If you close you will loose the data.",
 
            QMessageBox::Discard | QMessageBox::Discard,
 
            QMessageBox::Cancel);
 
        if (clickedButton == QMessageBox::Cancel)
 
        {
 
            event->ignore();
 
            return;
 
        }
 
    }
 
    QMainWindow::closeEvent(event);
 
}
 

	
 
void MainWindow::setupAboutDialog()
 
{
 
    Ui_AboutDialog uiAboutDialog;
src/mainwindow.h
Show inline comments
 
@@ -90,6 +90,9 @@ private:
 
    /// Loads main window settings from a `QSettings`
 
    void loadMWSettings(QSettings* settings);
 

	
 
    /// `QWidget::closeEvent` handler
 
    void closeEvent(QCloseEvent * event);
 

	
 
private slots:
 
    void onPortToggled(bool open);
 
    void onPortError(QSerialPort::SerialPortError error);
src/snapshot.cpp
Show inline comments
 
@@ -30,6 +30,7 @@ Snapshot::Snapshot(QMainWindow* parent, 
 
    _deleteAction("Delete", this)
 
{
 
    _name = name;
 
    _saved = false;
 

	
 
    view = NULL;
 
    mainWindow = parent;
 
@@ -137,9 +138,18 @@ void Snapshot::save(QString fileName)
 
        {
 
            qCritical() << "File save error during snapshot save: " << file.error();
 
        }
 
        else
 
        {
 
            _saved = true;
 
        }
 
    }
 
    else
 
    {
 
        qCritical() << "File open error during snapshot save: " << file.error();
 
    }
 
}
 

	
 
bool Snapshot::isSaved()
 
{
 
    return _saved;
 
}
src/snapshot.h
Show inline comments
 
@@ -46,7 +46,8 @@ public:
 
    void setChannelNames(QStringList names); // must be called when setting data!
 
    QString channelName(unsigned channel);
 

	
 
    void save(QString fileName); /// save snapshot data as CSV
 
    void save(QString fileName); ///< save snapshot data as CSV
 
    bool isSaved(); ///< snapshot has been saved at least once
 

	
 
signals:
 
    void deleteRequested(Snapshot*);
 
@@ -59,6 +60,7 @@ private:
 
    QAction _deleteAction;
 
    QMainWindow* mainWindow;
 
    SnapshotView* view;
 
    bool _saved;
 

	
 
private slots:
 
    void show();
src/snapshotmanager.cpp
Show inline comments
 
@@ -205,3 +205,12 @@ QAction* SnapshotManager::takeSnapshotAc
 
{
 
    return &_takeSnapshotAction;
 
}
 

	
 
bool SnapshotManager::isAllSaved()
 
{
 
    for (auto snapshot : snapshots)
 
    {
 
        if (!snapshot->isSaved()) return false;
 
    }
 
    return true;
 
}
src/snapshotmanager.h
Show inline comments
 
@@ -43,6 +43,8 @@ public:
 
    /// @note Caller is responsible for deletion of the returned `Snapshot` object.
 
    Snapshot* makeSnapshot();
 

	
 
    bool isAllSaved(); ///< returns `true` if all snapshots are saved to a file
 

	
 
private:
 
    QMainWindow* _mainWindow;
 
    ChannelManager* _channelMan;
0 comments (0 inline, 0 general)