Changeset - 4bc5e4951d47
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-01-29 13:22:47
hy@ozderya.net
snapshots now uses channelinfomodel for channel names
6 files changed with 44 insertions and 15 deletions:
0 comments (0 inline, 0 general)
cmake/modules/BuildQColorWidgets.cmake
Show inline comments
 
@@ -22,7 +22,8 @@ include(ExternalProject)
 
ExternalProject_Add(QCW
 
  PREFIX qcw
 
  GIT_REPOSITORY https://github.com/mbasaglia/Qt-Color-Widgets
 
  PATCH_COMMAND patch -p1 -i ${CMAKE_CURRENT_LIST_DIR}/qt_5_2_moc_creation_namespace_fix.diff
 
  PATCH_COMMAND patch -t -N -p1 -i ${CMAKE_CURRENT_LIST_DIR}/qt_5_2_moc_creation_namespace_fix.diff
 
  UPDATE_COMMAND ""
 
  INSTALL_COMMAND "")
 

	
 
ExternalProject_Get_Property(QCW binary_dir source_dir)
src/channelinfomodel.cpp
Show inline comments
 
@@ -65,6 +65,32 @@ ChannelInfoModel::ChannelInfoModel(unsig
 
    setNumOfChannels(numberOfChannels);
 
}
 

	
 
ChannelInfoModel::ChannelInfoModel(const ChannelInfoModel& other) :
 
    ChannelInfoModel(other.rowCount(), other.parent())
 
{
 
    for (int i = 0; i < other.rowCount(); i++)
 
    {
 
        setData(index(i, COLUMN_NAME),
 
                other.data(other.index(i, COLUMN_NAME), Qt::EditRole),
 
                Qt::EditRole);
 
        setData(index(i, COLUMN_NAME),
 
                other.data(other.index(i, COLUMN_NAME), Qt::ForegroundRole),
 
                Qt::ForegroundRole);
 
        setData(index(i, COLUMN_VISIBILITY),
 
                other.data(other.index(i, COLUMN_VISIBILITY), Qt::CheckStateRole),
 
                Qt::CheckStateRole);
 
    }
 
}
 

	
 
ChannelInfoModel::ChannelInfoModel(const QStringList& channelNames) :
 
    ChannelInfoModel(channelNames.length(), NULL)
 
{
 
    for (int i = 0; i < channelNames.length(); i++)
 
    {
 
        setData(index(i, COLUMN_NAME), channelNames[i], Qt::EditRole);
 
    }
 
}
 

	
 
ChannelInfoModel::ChannelInfo::ChannelInfo(unsigned index)
 
{
 
    name = tr("Channel %1").arg(index + 1);
src/channelinfomodel.h
Show inline comments
 
@@ -23,6 +23,7 @@
 
#include <QAbstractTableModel>
 
#include <QColor>
 
#include <QSettings>
 
#include <QStringList>
 

	
 
class ChannelInfoModel : public QAbstractTableModel
 
{
 
@@ -37,6 +38,8 @@ public:
 
    };
 

	
 
    explicit ChannelInfoModel(unsigned numberOfChannels, QObject *parent = 0);
 
    ChannelInfoModel(const ChannelInfoModel& other);
 
    explicit ChannelInfoModel(const QStringList& channelNames);
 

	
 
    // implemented from QAbstractItemModel
 
    int           rowCount(const QModelIndex &parent = QModelIndex()) const;
src/snapshot.cpp
Show inline comments
 
@@ -24,8 +24,9 @@
 
#include "snapshot.h"
 
#include "snapshotview.h"
 

	
 
Snapshot::Snapshot(QMainWindow* parent, QString name) :
 
Snapshot::Snapshot(QMainWindow* parent, QString name, ChannelInfoModel infoModel) :
 
    QObject(parent),
 
    cInfoModel(infoModel),
 
    _showAction(this),
 
    _deleteAction("&Delete", this)
 
{
 
@@ -106,14 +107,10 @@ void Snapshot::setName(QString name)
 
    emit nameChanged(this);
 
}
 

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

	
 
QString Snapshot::channelName(unsigned channel)
 
{
 
    return _channelNames[channel];
 
    return cInfoModel.data(cInfoModel.index(channel, ChannelInfoModel::COLUMN_NAME),
 
                           Qt::DisplayRole).toString();
 
}
 

	
 
void Snapshot::save(QString fileName)
src/snapshot.h
Show inline comments
 
@@ -27,6 +27,8 @@
 
#include <QString>
 
#include <QStringList>
 

	
 
#include "channelinfomodel.h"
 

	
 
class SnapshotView;
 

	
 
class Snapshot : public QObject
 
@@ -34,7 +36,7 @@ class Snapshot : public QObject
 
    Q_OBJECT
 

	
 
public:
 
    Snapshot(QMainWindow* parent, QString name);
 
    Snapshot(QMainWindow* parent, QString name, ChannelInfoModel infoModel);
 
    ~Snapshot();
 

	
 
    QVector<QVector<QPointF>> data;
 
@@ -44,7 +46,6 @@ public:
 
    QString name();
 
    QString displayName(); ///< `name()` plus '*' if snapshot is not saved
 
    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
 
@@ -56,7 +57,7 @@ signals:
 

	
 
private:
 
    QString _name;
 
    QStringList _channelNames;
 
    ChannelInfoModel cInfoModel;
 
    QAction _showAction;
 
    QAction _deleteAction;
 
    QMainWindow* mainWindow;
src/snapshotmanager.cpp
Show inline comments
 
@@ -63,7 +63,7 @@ SnapshotManager::~SnapshotManager()
 
Snapshot* SnapshotManager::makeSnapshot()
 
{
 
    QString name = QTime::currentTime().toString("'Snapshot ['HH:mm:ss']'");
 
    auto snapshot = new Snapshot(_mainWindow, name);
 
    auto snapshot = new Snapshot(_mainWindow, name, *(_channelMan->infoModel()));
 

	
 
    unsigned numOfChannels = _channelMan->numOfChannels();
 
    unsigned numOfSamples = _channelMan->numOfSamples();
 
@@ -76,7 +76,6 @@ Snapshot* SnapshotManager::makeSnapshot(
 
            snapshot->data[ci][i] = QPointF(i, _channelMan->channelBuffer(ci)->sample(i));
 
        }
 
    }
 
    snapshot->setChannelNames(_channelMan->channelNames());
 

	
 
    return snapshot;
 
}
 
@@ -189,9 +188,11 @@ void SnapshotManager::loadSnapshotFromFi
 
        lineNum++;
 
    }
 

	
 
    auto snapshot = new Snapshot(_mainWindow, QFileInfo(fileName).baseName());
 
    ChannelInfoModel channelInfo(channelNames);
 

	
 
    auto snapshot = new Snapshot(
 
        _mainWindow, QFileInfo(fileName).baseName(), ChannelInfoModel(channelNames));
 
    snapshot->data = data;
 
    snapshot->setChannelNames(channelNames);
 

	
 
    addSnapshot(snapshot, false);
 
}
0 comments (0 inline, 0 general)