Changeset - 840ec925ba83
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-01-30 04:05:29
hy@ozderya.net
api for simpler access to channel info
4 files changed with 21 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/channelinfomodel.cpp
Show inline comments
 
@@ -89,24 +89,39 @@ ChannelInfoModel::ChannelInfoModel(const
 
    {
 
        setData(index(i, COLUMN_NAME), channelNames[i], Qt::EditRole);
 
    }
 
}
 

	
 
ChannelInfoModel::ChannelInfo::ChannelInfo(unsigned index)
 
{
 
    name = tr("Channel %1").arg(index + 1);
 
    visibility = true;
 
    color = colors[index % NUMOF_COLORS];
 
}
 

	
 
QString ChannelInfoModel::name(unsigned i)
 
{
 
    return infos[i].name;
 
}
 

	
 
QColor ChannelInfoModel::color(unsigned i)
 
{
 
    return infos[i].color;
 
}
 

	
 
bool ChannelInfoModel::isVisible(unsigned i)
 
{
 
    return infos[i].visibility;
 
}
 

	
 
int ChannelInfoModel::rowCount(const QModelIndex &parent) const
 
{
 
    return _numOfChannels;
 
}
 

	
 
int ChannelInfoModel::columnCount(const QModelIndex & parent) const
 
{
 
    return COLUMN_COUNT;
 
}
 

	
 
Qt::ItemFlags ChannelInfoModel::flags(const QModelIndex &index) const
 
{
src/channelinfomodel.h
Show inline comments
 
@@ -32,24 +32,28 @@ class ChannelInfoModel : public QAbstrac
 
public:
 
    enum ChannelInfoColumn
 
    {
 
        COLUMN_NAME = 0,
 
        COLUMN_VISIBILITY,
 
        COLUMN_COUNT
 
    };
 

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

	
 
    QString name     (unsigned i);
 
    QColor  color    (unsigned i);
 
    bool    isVisible(unsigned i);
 

	
 
    // implemented from QAbstractItemModel
 
    int           rowCount(const QModelIndex &parent = QModelIndex()) const;
 
    int           columnCount(const QModelIndex &parent = QModelIndex()) const;
 
    QVariant      data(const QModelIndex &index, int role = Qt::DisplayRole) const;
 
    bool          setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
 
    Qt::ItemFlags flags(const QModelIndex &index) const;
 
    QVariant      headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
 

	
 
    void setNumOfChannels(unsigned number);
 
    /// Stores all channel info into a `QSettings`
 
    void saveSettings(QSettings* settings);
 
    /// Loads all channel info from a `QSettings`.
src/plotmanager.cpp
Show inline comments
 
@@ -267,26 +267,25 @@ void PlotManager::addCurve(QString title
 
{
 
    auto curve = new QwtPlotCurve(title);
 
    curve->setSamples(data);
 
    _addCurve(curve);
 
}
 

	
 
void PlotManager::_addCurve(QwtPlotCurve* curve)
 
{
 
    // store and init the curve
 
    curves.append(curve);
 

	
 
    unsigned index = curves.size()-1;
 
    auto color = _infoModel->index(index, ChannelInfoModel::COLUMN_NAME)\
 
        .data(Qt::ForegroundRole).value<QColor>();
 
    auto color = _infoModel->color(index);
 
    curve->setPen(color);
 

	
 
    // create the plot for the curve if we are on multi display
 
    Plot* plot;
 
    if (isMulti)
 
    {
 
        // create a new plot widget
 
        plot = addPlotWidget();
 
    }
 
    else
 
    {
 
        plot = plotWidgets[0];
src/snapshot.cpp
Show inline comments
 
@@ -105,26 +105,25 @@ void Snapshot::setName(QString name)
 
    _name = name;
 
    _showAction.setText(_name);
 
    emit nameChanged(this);
 
}
 

	
 
ChannelInfoModel* Snapshot::infoModel()
 
{
 
    return &cInfoModel;
 
}
 

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

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

	
 
    if (file.open(QIODevice::WriteOnly | QIODevice::Text))
 
    {
 
        QTextStream fileStream(&file);
 

	
 
        unsigned numOfChannels = data.size();
0 comments (0 inline, 0 general)