Changeset - 110ac52a6894
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 10 years ago 2016-04-03 14:53:24
hy@ozderya.net
added legend (channel names) to snapshot view
4 files changed with 16 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/snapshot.cpp
Show inline comments
 
@@ -89,12 +89,22 @@ void Snapshot::setName(QString name)
 
{
 
    _name = name;
 
    _showAction.setText(_name);
 
    emit nameChanged(this);
 
}
 

	
 
void Snapshot::setChannelNames(QStringList names)
 
{
 
    _channelNames = names;
 
}
 

	
 
QString Snapshot::channelName(unsigned channel)
 
{
 
    return _channelNames[channel];
 
}
 

	
 
void Snapshot::save(QString fileName)
 
{
 
    // TODO: remove code duplication (MainWindow::onExportCsv)
 
    QSaveFile file(fileName);
 

	
 
    if (file.open(QIODevice::WriteOnly | QIODevice::Text))
src/snapshot.h
Show inline comments
 
@@ -22,12 +22,13 @@
 

	
 
#include <QObject>
 
#include <QMainWindow>
 
#include <QAction>
 
#include <QVector>
 
#include <QString>
 
#include <QStringList>
 

	
 
class SnapshotView;
 

	
 
class Snapshot : public QObject
 
{
 
    Q_OBJECT
 
@@ -39,21 +40,24 @@ public:
 
    QVector<QVector<QPointF>> data;
 
    QAction* showAction();
 
    QAction* deleteAction();
 

	
 
    QString name();
 
    void setName(QString name);
 
    void setChannelNames(QStringList names); // must be called when setting data!
 
    QString channelName(unsigned channel);
 

	
 
    void save(QString fileName); /// save snapshot data as CSV
 

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

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

	
 
private slots:
src/snapshotmanager.cpp
Show inline comments
 
@@ -73,12 +73,13 @@ void SnapshotManager::takeSnapshot()
 
        snapshot->data.append(QVector<QPointF>(numOfSamples));
 
        for (unsigned i = 0; i < numOfSamples; i++)
 
        {
 
            snapshot->data[ci][i] = QPointF(i, _channelMan->channelBuffer(ci)->sample(i));
 
        }
 
    }
 
    snapshot->setChannelNames(_channelMan->channelNames()->stringList());
 

	
 
    addSnapshot(snapshot);
 
}
 

	
 
void SnapshotManager::addSnapshot(Snapshot* snapshot, bool update_menu)
 
{
src/snapshotview.cpp
Show inline comments
 
@@ -32,13 +32,13 @@ SnapshotView::SnapshotView(QWidget *pare
 
    this->setWindowTitle(snapshot->name());
 

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

	
 
    for (unsigned ci = 0; ci < numOfChannels; ci++)
 
    {
 
        QwtPlotCurve* curve = new QwtPlotCurve();
 
        QwtPlotCurve* curve = new QwtPlotCurve(snapshot->channelName(ci));
 
        curves.append(curve);
 
        curve->setSamples(snapshot->data[ci]);
 
        curve->setPen(Plot::makeColor(ci));
 
        curve->attach(ui->plot);
 
    }
 

	
0 comments (0 inline, 0 general)