# HG changeset patch # User Hasan Yavuz ÖZDERYA # Date 2015-09-30 05:20:27 # Node ID 6c4c2a001b767cf0b87b665ead4d49495af64fee # Parent a855faafd02657e2e7fdadf04091efd0f2922acf code cleanup - consistent usage of "snapshot" instead of "snapShot" - removed some dead code - added file headers diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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::OVERLOAD_OF(&QSpinBox::valueChanged), diff --git a/snapshot.cpp b/snapshot.cpp --- a/snapshot.cpp +++ b/snapshot.cpp @@ -1,12 +1,28 @@ +/* + 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 . +*/ #include #include "snapshot.h" #include "snapshotview.h" -#include - -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); diff --git a/snapshot.h b/snapshot.h --- a/snapshot.h +++ b/snapshot.h @@ -1,3 +1,22 @@ +/* + 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 . +*/ + #ifndef SNAPSHOT_H #define SNAPSHOT_H @@ -7,15 +26,15 @@ #include #include -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> 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(); diff --git a/snapshotmanager.cpp b/snapshotmanager.cpp --- a/snapshotmanager.cpp +++ b/snapshotmanager.cpp @@ -1,3 +1,21 @@ +/* + 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 . +*/ #include #include @@ -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(numOfSamples)); + snapshot->data.append(QVector(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); diff --git a/snapshotmanager.h b/snapshotmanager.h --- a/snapshotmanager.h +++ b/snapshotmanager.h @@ -1,3 +1,21 @@ +/* + 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 . +*/ #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* _channelBuffers; - QList snapshots; + QList 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); }; diff --git a/snapshotview.cpp b/snapshotview.cpp --- a/snapshotview.cpp +++ b/snapshotview.cpp @@ -1,26 +1,45 @@ -#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 . +*/ #include -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'; diff --git a/snapshotview.h b/snapshotview.h --- a/snapshotview.h +++ b/snapshotview.h @@ -1,3 +1,22 @@ +/* + 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 . +*/ + #ifndef SNAPSHOTVIEW_H #define SNAPSHOTVIEW_H @@ -9,28 +28,29 @@ #include #include #include + #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 curves; - SnapShot* _snapShot; + Snapshot* _snapshot; QInputDialog renameDialog; void closeEvent(QCloseEvent *event); diff --git a/snapshotview.ui b/snapshotview.ui --- a/snapshotview.ui +++ b/snapshotview.ui @@ -1,7 +1,7 @@ - SnapShotView - + SnapshotView + 0 @@ -86,7 +86,7 @@ actionClose triggered() - SnapShotView + SnapshotView close()