Changeset - 6c4c2a001b76
[Not reviewed]
snapshots
0 8 0
Hasan Yavuz ÖZDERYA - 10 years ago 2015-09-30 05:20:27
hy@ozderya.net
code cleanup

- consistent usage of "snapshot" instead of "snapShot"
- removed some dead code
- added file headers
8 files changed with 173 insertions and 68 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -108,9 +108,6 @@ MainWindow::MainWindow(QWidget *parent) 
 
    QObject::connect(ui->actionClear, SIGNAL(triggered(bool)),
 
                     this, SLOT(clearPlot()));
 

	
 
    // QObject::connect(ui->actionSnapShot, SIGNAL(triggered(bool)),
 
    //                  this, SLOT(takeSnapShot()));
 

	
 
    // setup number of channels spinbox
 
    QObject::connect(ui->spNumOfChannels,
 
                     SELECT<int>::OVERLOAD_OF(&QSpinBox::valueChanged),
snapshot.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 <stddef.h>
 

	
 
#include "snapshot.h"
 
#include "snapshotview.h"
 

	
 
#include <QtDebug>
 

	
 
SnapShot::SnapShot(QMainWindow* parent, QString name) :
 
Snapshot::Snapshot(QMainWindow* parent, QString name) :
 
    QObject(parent),
 
    _showAction(name, this),
 
    _deleteAction("Delete", this)
 
@@ -15,13 +31,13 @@ SnapShot::SnapShot(QMainWindow* parent, 
 

	
 
    view = NULL;
 
    mainWindow = parent;
 
    connect(&_showAction, &QAction::triggered, this, &SnapShot::show);
 
    connect(&_showAction, &QAction::triggered, this, &Snapshot::show);
 

	
 
    _deleteAction.setToolTip(QString("Delete ") + _name);
 
    connect(&_deleteAction, &QAction::triggered, this, &SnapShot::onDeleteTriggered);
 
    connect(&_deleteAction, &QAction::triggered, this, &Snapshot::onDeleteTriggered);
 
}
 

	
 
SnapShot::~SnapShot()
 
Snapshot::~Snapshot()
 
{
 
    if (view != NULL)
 
    {
 
@@ -29,45 +45,45 @@ SnapShot::~SnapShot()
 
    }
 
}
 

	
 
QAction* SnapShot::showAction()
 
QAction* Snapshot::showAction()
 
{
 
    return &_showAction;
 
}
 

	
 
QAction* SnapShot::deleteAction()
 
QAction* Snapshot::deleteAction()
 
{
 
    return &_deleteAction;
 
}
 

	
 
void SnapShot::show()
 
void Snapshot::show()
 
{
 
    if (view == NULL)
 
    {
 
        view = new SnapShotView(mainWindow, this);
 
        connect(view, &SnapShotView::closed, this, &SnapShot::viewClosed);
 
        view = new SnapshotView(mainWindow, this);
 
        connect(view, &SnapshotView::closed, this, &Snapshot::viewClosed);
 
    }
 
    view->show();
 
    view->activateWindow();
 
    view->raise();
 
}
 

	
 
void SnapShot::viewClosed()
 
void Snapshot::viewClosed()
 
{
 
    view->deleteLater();
 
    view = NULL;
 
}
 

	
 
void SnapShot::onDeleteTriggered()
 
void Snapshot::onDeleteTriggered()
 
{
 
    emit deleteRequested(this);
 
}
 

	
 
QString SnapShot::name()
 
QString Snapshot::name()
 
{
 
    return _name;
 
}
 

	
 
void SnapShot::setName(QString name)
 
void Snapshot::setName(QString name)
 
{
 
    _name = name;
 
    _showAction.setText(_name);
snapshot.h
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/>.
 
*/
 

	
 
#ifndef SNAPSHOT_H
 
#define SNAPSHOT_H
 

	
 
@@ -7,15 +26,15 @@
 
#include <QVector>
 
#include <QString>
 

	
 
class SnapShotView;
 
class SnapshotView;
 

	
 
class SnapShot : public QObject
 
class Snapshot : public QObject
 
{
 
    Q_OBJECT
 

	
 
public:
 
    SnapShot(QMainWindow* parent, QString name);
 
    ~SnapShot();
 
    Snapshot(QMainWindow* parent, QString name);
 
    ~Snapshot();
 

	
 
    QVector<QVector<QPointF>> data;
 
    QAction* showAction();
 
@@ -25,15 +44,15 @@ public:
 
    void setName(QString name);
 

	
 
signals:
 
    void deleteRequested(SnapShot*);
 
    void nameChanged(SnapShot*);
 
    void deleteRequested(Snapshot*);
 
    void nameChanged(Snapshot*);
 

	
 
private:
 
    QString _name;
 
    QAction _showAction;
 
    QAction _deleteAction;
 
    QMainWindow* mainWindow;
 
    SnapShotView* view;
 
    SnapshotView* view;
 

	
 
private slots:
 
    void show();
snapshotmanager.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 <QTime>
 
#include <QMenuBar>
 
@@ -44,27 +62,27 @@ SnapshotManager::~SnapshotManager()
 
void SnapshotManager::takeSnapshot()
 
{
 
    QString name = QTime::currentTime().toString("'Snapshot ['HH:mm:ss']'");
 
    auto snapShot = new SnapShot(_mainWindow, name);
 
    auto snapshot = new Snapshot(_mainWindow, name);
 

	
 
    unsigned numOfChannels = _channelBuffers->size();
 
    unsigned numOfSamples = _channelBuffers->at(0)->size();
 

	
 
    for (unsigned ci = 0; ci < numOfChannels; ci++)
 
    {
 
        snapShot->data.append(QVector<QPointF>(numOfSamples));
 
        snapshot->data.append(QVector<QPointF>(numOfSamples));
 
        for (unsigned i = 0; i < numOfSamples; i++)
 
        {
 
            snapShot->data[ci][i] = _channelBuffers->at(ci)->sample(i);
 
            snapshot->data[ci][i] = _channelBuffers->at(ci)->sample(i);
 
        }
 
    }
 

	
 
    addSnapshot(snapShot);
 
    addSnapshot(snapshot);
 
}
 

	
 
void SnapshotManager::addSnapshot(SnapShot* snapshot, bool update_menu)
 
void SnapshotManager::addSnapshot(Snapshot* snapshot, bool update_menu)
 
{
 
    snapshots.append(snapshot);
 
    QObject::connect(snapshot, &SnapShot::deleteRequested,
 
    QObject::connect(snapshot, &Snapshot::deleteRequested,
 
                     this, &SnapshotManager::deleteSnapshot);
 
    if (update_menu) updateMenu();
 
}
 
@@ -96,7 +114,7 @@ void SnapshotManager::clearSnapshots()
 
    updateMenu();
 
}
 

	
 
void SnapshotManager::deleteSnapshot(SnapShot* snapshot)
 
void SnapshotManager::deleteSnapshot(Snapshot* snapshot)
 
{
 
    snapshots.removeOne(snapshot);
 
    snapshot->deleteLater(); // regular delete causes a crash when triggered from menu
 
@@ -163,7 +181,7 @@ void SnapshotManager::loadSnapshotFromFi
 
        lineNum++;
 
    }
 

	
 
    auto snapshot = new SnapShot(_mainWindow, QFileInfo(fileName).baseName());
 
    auto snapshot = new Snapshot(_mainWindow, QFileInfo(fileName).baseName());
 
    snapshot->data = data;
 

	
 
    addSnapshot(snapshot, false);
snapshotmanager.h
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/>.
 
*/
 

	
 
#ifndef SNAPSHOTMANAGER_H
 
#define SNAPSHOTMANAGER_H
 
@@ -9,8 +27,6 @@
 
#include "framebuffer.h"
 
#include "snapshot.h"
 

	
 
// class MainWindow;
 

	
 
class SnapshotManager : public QObject
 
{
 
    Q_OBJECT
 
@@ -26,20 +42,20 @@ private:
 
    QMainWindow* _mainWindow;
 
    QList<FrameBuffer*>* _channelBuffers;
 

	
 
    QList<SnapShot*> snapshots;
 
    QList<Snapshot*> snapshots;
 

	
 
    QMenu _menu;
 
    QAction _takeSnapshotAction;
 
    QAction loadSnapshotAction;
 
    QAction clearAction;
 

	
 
    void addSnapshot(SnapShot* snapshot, bool update_menu=true);
 
    void addSnapshot(Snapshot* snapshot, bool update_menu=true);
 
    void updateMenu();
 

	
 
private slots:
 
    void takeSnapshot();
 
    void clearSnapshots();
 
    void deleteSnapshot(SnapShot* snapshot);
 
    void deleteSnapshot(Snapshot* snapshot);
 
    void loadSnapshots();
 
    void loadSnapshotFromFile(QString fileName);
 
};
snapshotview.cpp
Show inline comments
 
#include "snapshotview.h"
 
#include "ui_snapshotview.h"
 
/*
 
  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 <QSaveFile>
 

	
 
SnapShotView::SnapShotView(QWidget *parent, SnapShot* snapShot) :
 
#include "snapshotview.h"
 
#include "ui_snapshotview.h"
 

	
 
SnapshotView::SnapshotView(QWidget *parent, Snapshot* snapshot) :
 
    QMainWindow(parent),
 
    ui(new Ui::SnapShotView),
 
    ui(new Ui::SnapshotView),
 
    renameDialog(this)
 
{
 
    _snapShot = snapShot;
 
    _snapshot = snapshot;
 

	
 
    ui->setupUi(this);
 
    ui->menuSnapshot->insertAction(ui->actionClose, snapShot->deleteAction());
 
    this->setWindowTitle(snapShot->name());
 
    ui->menuSnapshot->insertAction(ui->actionClose, snapshot->deleteAction());
 
    this->setWindowTitle(snapshot->name());
 

	
 
    unsigned numOfChannels = snapShot->data.size();
 
    unsigned numOfChannels = snapshot->data.size();
 

	
 
    for (unsigned ci = 0; ci < numOfChannels; ci++)
 
    {
 
        QwtPlotCurve* curve = new QwtPlotCurve();
 
        curves.append(curve);
 
        curve->setSamples(snapShot->data[ci]);
 
        curve->setSamples(snapshot->data[ci]);
 
        curve->setPen(Plot::makeColor(ci));
 
        curve->attach(ui->plot);
 
    }
 
@@ -28,10 +47,10 @@ SnapShotView::SnapShotView(QWidget *pare
 
    renameDialog.setWindowTitle("Rename Snapshot");
 
    renameDialog.setLabelText("Enter new name:");
 
    connect(ui->actionRename, &QAction::triggered,
 
            this, &SnapShotView::showRenameDialog);
 
            this, &SnapshotView::showRenameDialog);
 

	
 
    connect(ui->actionExport, &QAction::triggered,
 
            this, &SnapShotView::save);
 
            this, &SnapshotView::save);
 

	
 
    for (auto a : ui->plot->menuActions())
 
    {
 
@@ -39,7 +58,7 @@ SnapShotView::SnapShotView(QWidget *pare
 
    }
 
}
 

	
 
SnapShotView::~SnapShotView()
 
SnapshotView::~SnapshotView()
 
{
 
    for (auto curve : curves)
 
    {
 
@@ -48,25 +67,25 @@ SnapShotView::~SnapShotView()
 
    delete ui;
 
}
 

	
 
void SnapShotView::closeEvent(QCloseEvent *event)
 
void SnapshotView::closeEvent(QCloseEvent *event)
 
{
 
    QMainWindow::closeEvent(event);
 
    emit closed();
 
}
 

	
 
void SnapShotView::showRenameDialog()
 
void SnapshotView::showRenameDialog()
 
{
 
    renameDialog.setTextValue(_snapShot->name());
 
    renameDialog.setTextValue(_snapshot->name());
 
    renameDialog.open(this, SLOT(renameSnapshot(QString)));
 
}
 

	
 
void SnapShotView::renameSnapshot(QString name)
 
void SnapshotView::renameSnapshot(QString name)
 
{
 
    _snapShot->setName(name);
 
    _snapshot->setName(name);
 
    setWindowTitle(name);
 
}
 

	
 
void SnapShotView::save()
 
void SnapshotView::save()
 
{
 
    QString fileName = QFileDialog::getSaveFileName(this, tr("Export CSV File"));
 

	
 
@@ -79,8 +98,8 @@ void SnapShotView::save()
 
    {
 
        QTextStream fileStream(&file);
 

	
 
        unsigned numOfChannels = _snapShot->data.size();
 
        unsigned numOfSamples = _snapShot->data[0].size();
 
        unsigned numOfChannels = _snapshot->data.size();
 
        unsigned numOfSamples = _snapshot->data[0].size();
 

	
 
        // print header
 
        for (unsigned int ci = 0; ci < numOfChannels; ci++)
 
@@ -95,7 +114,7 @@ void SnapShotView::save()
 
        {
 
            for (unsigned int ci = 0; ci < numOfChannels; ci++)
 
            {
 
                fileStream << _snapShot->data[ci][i].y();
 
                fileStream << _snapshot->data[ci][i].y();
 
                if (ci != numOfChannels-1) fileStream << ",";
 
            }
 
            fileStream << '\n';
snapshotview.h
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/>.
 
*/
 

	
 
#ifndef SNAPSHOTVIEW_H
 
#define SNAPSHOTVIEW_H
 

	
 
@@ -9,28 +28,29 @@
 
#include <QPen>
 
#include <QCloseEvent>
 
#include <qwt_plot_curve.h>
 

	
 
#include "plot.h"
 
#include "snapshot.h"
 

	
 
namespace Ui {
 
class SnapShotView;
 
class SnapshotView;
 
}
 

	
 
class SnapShotView : public QMainWindow
 
class SnapshotView : public QMainWindow
 
{
 
    Q_OBJECT
 

	
 
public:
 
    explicit SnapShotView(QWidget *parent, SnapShot* snapShot);
 
    ~SnapShotView();
 
    explicit SnapshotView(QWidget *parent, Snapshot* snapshot);
 
    ~SnapshotView();
 

	
 
signals:
 
    void closed();
 

	
 
private:
 
    Ui::SnapShotView *ui;
 
    Ui::SnapshotView *ui;
 
    QList<QwtPlotCurve*> curves;
 
    SnapShot* _snapShot;
 
    Snapshot* _snapshot;
 
    QInputDialog renameDialog;
 

	
 
    void closeEvent(QCloseEvent *event);
snapshotview.ui
Show inline comments
 
<?xml version="1.0" encoding="UTF-8"?>
 
<ui version="4.0">
 
 <class>SnapShotView</class>
 
 <widget class="QMainWindow" name="SnapShotView">
 
 <class>SnapshotView</class>
 
 <widget class="QMainWindow" name="SnapshotView">
 
  <property name="geometry">
 
   <rect>
 
    <x>0</x>
 
@@ -86,7 +86,7 @@
 
  <connection>
 
   <sender>actionClose</sender>
 
   <signal>triggered()</signal>
 
   <receiver>SnapShotView</receiver>
 
   <receiver>SnapshotView</receiver>
 
   <slot>close()</slot>
 
   <hints>
 
    <hint type="sourcelabel">
0 comments (0 inline, 0 general)