# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2015-09-20 07:53:03 # Node ID 77513ca7b1d4622277077776b74533db89c34be0 # Parent ad8324c4db4c1b79f51de1e5312b771859d36e6a made SnapShot a class, clicking its action opens snapshot view diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ add_executable(${PROGRAM_NAME} WIN32 scalepicker.cpp scalezoomer.cpp portlist.cpp + snapshot.cpp snapshotview.cpp ${UI_FILES} ${RES_FILES} diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -730,8 +730,7 @@ void MainWindow::messageHandler(QtMsgTyp void MainWindow::takeSnapShot() { qDebug() << "taking a snopshot yay!"; - auto snapShot = new SnapShot(); - snapShot->name = QString("SnapShot"); + auto snapShot = new SnapShot(this, "New Snapshot"); for (unsigned ci = 0; ci < numOfChannels; ci++) { @@ -744,9 +743,6 @@ void MainWindow::takeSnapShot() snapshots.append(snapShot); updateSnapShotMenu(); - - auto sv = new SnapShotView(this, snapShot); - sv->show(); } void MainWindow::updateSnapShotMenu() @@ -758,7 +754,7 @@ void MainWindow::updateSnapShotMenu() ui->menuSnapShots->addSeparator(); for (auto ss : snapshots) { - ui->menuSnapShots->addAction(ss->name); + ui->menuSnapShots->addAction(ss->menuAction()); } ui->menuSnapShots->addSeparator(); ui->menuSnapShots->addAction(ui->actionClearSnapShots); diff --git a/snapshot.cpp b/snapshot.cpp new file mode 100644 --- /dev/null +++ b/snapshot.cpp @@ -0,0 +1,36 @@ + +#include + +#include "snapshot.h" +#include "snapshotview.h" + +#include + +SnapShot::SnapShot(QMainWindow* parent, QString name) : + QObject(parent), + _menuAction(name, this) +{ + view = NULL; + mainWindow = parent; + connect(&_menuAction, &QAction::triggered, this, &SnapShot::show); +} + +QAction* SnapShot::menuAction() +{ + return &_menuAction; +} + +void SnapShot::show() +{ + if (view == NULL) + { + qDebug() << "view == NULL"; + view = new SnapShotView(mainWindow, this); + } + view->show(); +} + +void SnapShot::hide() +{ + +} diff --git a/snapshot.h b/snapshot.h new file mode 100644 --- /dev/null +++ b/snapshot.h @@ -0,0 +1,32 @@ +#ifndef SNAPSHOT_H +#define SNAPSHOT_H + +#include +#include +#include +#include + +class SnapShotView; + +class SnapShot : public QObject +{ + Q_OBJECT + +public: + SnapShot(QMainWindow* parent, QString name); + + // QString _name; + QVector> data; + QAction* menuAction(); + +public slots: + void show(); + void hide(); + +private: + QAction _menuAction; + QMainWindow* mainWindow; + SnapShotView* view; +}; + +#endif /* SNAPSHOT_H */ diff --git a/snapshotview.h b/snapshotview.h --- a/snapshotview.h +++ b/snapshotview.h @@ -7,14 +7,7 @@ #include #include #include "plot.h" - -class SnapShotView; -struct SnapShot -{ - QString name; - QVector> data; - SnapShotView* view; -}; +#include "snapshot.h" namespace Ui { class SnapShotView;