diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -746,6 +746,8 @@ void MainWindow::takeSnapShot() } } snapshots.append(snapShot); + QObject::connect(snapShot, &SnapShot::deleteRequested, + this, &MainWindow::deleteSnapshot); updateSnapShotMenu(); } @@ -759,7 +761,7 @@ void MainWindow::updateSnapShotMenu() ui->menuSnapShots->addSeparator(); for (auto ss : snapshots) { - ui->menuSnapShots->addAction(ss->menuAction()); + ui->menuSnapShots->addAction(ss->showAction()); } ui->menuSnapShots->addSeparator(); ui->menuSnapShots->addAction(ui->actionClearSnapShots); @@ -775,3 +777,9 @@ void MainWindow::clearSnapshots() snapshots.clear(); updateSnapShotMenu(); } + +void MainWindow::deleteSnapshot(SnapShot* snapshot) +{ + delete snapshots.takeAt(snapshots.indexOf(snapshot)); + updateSnapShotMenu(); +} diff --git a/mainwindow.h b/mainwindow.h --- a/mainwindow.h +++ b/mainwindow.h @@ -134,6 +134,7 @@ private slots: void takeSnapShot(); void clearSnapshots(); + void deleteSnapshot(SnapShot* snapshot); void demoTimerTimeout(); void enableDemo(bool enabled); diff --git a/snapshot.cpp b/snapshot.cpp --- a/snapshot.cpp +++ b/snapshot.cpp @@ -8,11 +8,17 @@ SnapShot::SnapShot(QMainWindow* parent, QString name) : QObject(parent), - _menuAction(name, this) + _showAction(name, this), + _deleteAction("Delete", this) { + _name = name; + view = NULL; mainWindow = parent; - connect(&_menuAction, &QAction::triggered, this, &SnapShot::show); + connect(&_showAction, &QAction::triggered, this, &SnapShot::show); + + _deleteAction.setToolTip(QString("Delete ") + _name); + connect(&_deleteAction, &QAction::triggered, this, &SnapShot::onDeleteTriggered); } SnapShot::~SnapShot() @@ -23,9 +29,14 @@ SnapShot::~SnapShot() } } -QAction* SnapShot::menuAction() +QAction* SnapShot::showAction() { - return &_menuAction; + return &_showAction; +} + +QAction* SnapShot::deleteAction() +{ + return &_deleteAction; } void SnapShot::show() @@ -51,3 +62,14 @@ void SnapShot::viewClosed() delete view; view = NULL; } + + +void SnapShot::onDeleteTriggered() +{ + emit deleteRequested(this); +} + +QString SnapShot::name() +{ + return _name; +} diff --git a/snapshot.h b/snapshot.h --- a/snapshot.h +++ b/snapshot.h @@ -16,21 +16,30 @@ public: SnapShot(QMainWindow* parent, QString name); ~SnapShot(); - // QString _name; QVector> data; - QAction* menuAction(); + QAction* showAction(); + QAction* deleteAction(); + + QString name(); public slots: void show(); void hide(); +signals: + void deleteRequested(SnapShot*); + private: - QAction _menuAction; + QString _name; + QAction _showAction; + QAction _deleteAction; QMainWindow* mainWindow; SnapShotView* view; private slots: void viewClosed(); + + void onDeleteTriggered(); }; #endif /* SNAPSHOT_H */ diff --git a/snapshotview.cpp b/snapshotview.cpp --- a/snapshotview.cpp +++ b/snapshotview.cpp @@ -6,6 +6,8 @@ SnapShotView::SnapShotView(QWidget *pare ui(new Ui::SnapShotView) { ui->setupUi(this); + ui->toolBar->addAction(snapShot->deleteAction()); + this->setWindowTitle(snapShot->name()); unsigned numOfChannels = snapShot->data.size(); diff --git a/snapshotview.ui b/snapshotview.ui --- a/snapshotview.ui +++ b/snapshotview.ui @@ -54,21 +54,12 @@ false - Export CSV - - - Delete - - - Delete this snapshot! - -