Files
        @ 48e24c542d4e
    
        
              Branch filter: 
        
    Location: tempo-plotter/src/channelinfomodel.h
        
            
            48e24c542d4e
            3.7 KiB
            text/plain
        
        
    
    Change binary name
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117  | /*
  Copyright © 2018 Hasan Yavuz Özderya
  This file is part of serialplot.
  serialplot is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  serialplot is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CHANNELINFOMODEL_H
#define CHANNELINFOMODEL_H
#include <QAbstractTableModel>
#include <QColor>
#include <QSettings>
#include <QStringList>
class ChannelInfoModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    enum ChannelInfoColumn
    {
        COLUMN_NAME = 0,
        COLUMN_VISIBILITY,
        COLUMN_GAIN,
        COLUMN_OFFSET,
        COLUMN_COUNT            // MUST be last
    };
    explicit ChannelInfoModel(unsigned numberOfChannels, QObject *parent = 0);
    ChannelInfoModel(const ChannelInfoModel& other);
    explicit ChannelInfoModel(const QStringList& channelNames);
    QString name     (unsigned i) const;
    QColor  color    (unsigned i) const;
    bool    isVisible(unsigned i) const;
    bool    gainEn   (unsigned i) const;
    double  gain     (unsigned i) const;
    bool    offsetEn (unsigned i) const;
    double  offset   (unsigned i) const;
    /// Returns true if any of the channels have gain or offset enabled
    bool gainOrOffsetEn() const;
    /// Returns a list of channel names
    QStringList channelNames() const;
    // 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) const;
    /// Loads all channel info from a `QSettings`.
    void loadSettings(QSettings* settings);
public slots:
    /// reset all channel info (names, color etc.)
    void resetInfos();
    /// reset all channel names
    void resetNames();
    /// reset all channel colors
    void resetColors();
    /// reset all channel gain values and disables gains
    void resetGains();
    /// reset all channel offset values and disables offsets
    void resetOffsets();
    /// reset visibility
    void resetVisibility(bool visible);
private:
    struct ChannelInfo
    {
        explicit ChannelInfo(unsigned index);
        QString name;
        bool visibility;
        QColor color;
        double gain, offset;
        bool gainEn, offsetEn;
    };
    unsigned _numOfChannels;     ///< @note this is not necessarily the length of `infos`
    /**
     * Channel info is added here but never removed so that we can
     * remember user entered info (names, colors etc.).
     */
    QList<ChannelInfo> infos;
    /**
     * Cache for gain and offset enabled variables of channels. If gain and/or
     * offset is not enabled for *any* of the channels this is false otherwise
     * true.
     */
    bool _gainOrOffsetEn;
    /// Updates `_gainOrOffsetEn` by scanning all channel infos.
    void updateGainOrOffsetEn();
};
#endif // CHANNELINFOMODEL_H
 |