Changeset - 099df007158d
[Not reviewed]
snapshots
0 6 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-09-20 09:50:08
hy@ozderya.net
implemented delete snapshot function and showing snapshot name in the title
6 files changed with 50 insertions and 17 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -737,41 +737,49 @@ void MainWindow::takeSnapShot()
 
    QString name = QTime::currentTime().toString("'Snapshot ['HH:mm:ss']'");
 
    auto snapShot = new SnapShot(this, name);
 

	
 
    for (unsigned ci = 0; ci < numOfChannels; ci++)
 
    {
 
        snapShot->data.append(QVector<QPointF>(numOfSamples));
 
        for (unsigned i = 0; i < numOfSamples; i++)
 
        {
 
            snapShot->data[ci][i] = channelBuffers[ci]->sample(i);
 
        }
 
    }
 
    snapshots.append(snapShot);
 
    QObject::connect(snapShot, &SnapShot::deleteRequested,
 
                     this, &MainWindow::deleteSnapshot);
 

	
 
    updateSnapShotMenu();
 
}
 

	
 
void MainWindow::updateSnapShotMenu()
 
{
 
    ui->menuSnapShots->clear();
 
    ui->menuSnapShots->addAction(ui->actionSnapShot);
 
    if (snapshots.size())
 
    {
 
        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);
 
    }
 
}
 

	
 
void MainWindow::clearSnapshots()
 
{
 
    for (auto snapshot : snapshots)
 
    {
 
        delete snapshot;
 
    }
 
    snapshots.clear();
 
    updateSnapShotMenu();
 
}
 

	
 
void MainWindow::deleteSnapshot(SnapShot* snapshot)
 
{
 
    delete snapshots.takeAt(snapshots.indexOf(snapshot));
 
    updateSnapShotMenu();
 
}
mainwindow.h
Show inline comments
 
@@ -125,20 +125,21 @@ private slots:
 
    void onRangeSelected();
 

	
 
    void onNumOfChannelsChanged(int value);
 
    void onNumberFormatButtonToggled(int numberFormatId, bool checked);
 
    void selectNumberFormat(NumberFormat numberFormatId);
 

	
 
    void clearPlot();
 

	
 
    void spsTimerTimeout();
 

	
 
    void takeSnapShot();
 
    void clearSnapshots();
 
    void deleteSnapshot(SnapShot* snapshot);
 

	
 
    void demoTimerTimeout();
 
    void enableDemo(bool enabled);
 

	
 
    void onExportCsv();
 
};
 

	
 
#endif // MAINWINDOW_H
snapshot.cpp
Show inline comments
 

	
 
#include <stddef.h>
 

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

	
 
#include <QtDebug>
 

	
 
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()
 
{
 
    if (view != NULL)
 
    {
 
        delete view;
 
    }
 
}
 

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

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

	
 
void SnapShot::show()
 
{
 
    if (view == NULL)
 
    {
 
        qDebug() << "view == NULL";
 
        view = new SnapShotView(mainWindow, this);
 
        connect(view, &SnapShotView::closed, this, &SnapShot::viewClosed);
 
    }
 
    view->show();
 
    view->activateWindow();
 
@@ -42,12 +53,23 @@ void SnapShot::show()
 
}
 

	
 
void SnapShot::hide()
 
{
 

	
 
}
 

	
 
void SnapShot::viewClosed()
 
{
 
    delete view;
 
    view = NULL;
 
}
 

	
 

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

	
 
QString SnapShot::name()
 
{
 
    return _name;
 
}
snapshot.h
Show inline comments
 
@@ -7,30 +7,39 @@
 
#include <QVector>
 

	
 
class SnapShotView;
 

	
 
class SnapShot : public QObject
 
{
 
    Q_OBJECT
 

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

	
 
    // QString _name;
 
    QVector<QVector<QPointF>> 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 */
snapshotview.cpp
Show inline comments
 
#include "snapshotview.h"
 
#include "ui_snapshotview.h"
 

	
 
SnapShotView::SnapShotView(QWidget *parent, SnapShot* snapShot) :
 
    QMainWindow(parent),
 
    ui(new Ui::SnapShotView)
 
{
 
    ui->setupUi(this);
 
    ui->toolBar->addAction(snapShot->deleteAction());
 
    this->setWindowTitle(snapShot->name());
 

	
 
    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->setPen(Plot::makeColor(ci));
 
        curve->attach(ui->plot);
 
    }
 

	
snapshotview.ui
Show inline comments
 
@@ -45,39 +45,30 @@
 
  </widget>
 
  <widget class="QToolBar" name="toolBar">
 
   <property name="windowTitle">
 
    <string>toolBar</string>
 
   </property>
 
   <attribute name="toolBarArea">
 
    <enum>TopToolBarArea</enum>
 
   </attribute>
 
   <attribute name="toolBarBreak">
 
    <bool>false</bool>
 
   </attribute>
 
   <addaction name="actionExportCSV"/>
 
   <addaction name="actionDelete"/>
 
  </widget>
 
  <action name="actionExportCSV">
 
   <property name="text">
 
    <string>Export CSV</string>
 
   </property>
 
  </action>
 
  <action name="actionDelete">
 
   <property name="text">
 
    <string>Delete</string>
 
   </property>
 
   <property name="toolTip">
 
    <string>Delete this snapshot!</string>
 
   </property>
 
  </action>
 
 </widget>
 
 <customwidgets>
 
  <customwidget>
 
   <class>Plot</class>
 
   <extends>QWidget</extends>
 
   <header>plot.h</header>
 
   <container>1</container>
 
  </customwidget>
 
 </customwidgets>
 
 <resources/>
 
 <connections/>
 
</ui>
0 comments (0 inline, 0 general)