#ifndef WRITEREGISTERMODEL_H
#define WRITEREGISTERMODEL_H

#include <QAbstractItemModel>
#include <QBitArray>
#include <QObject>

class WriteRegisterModel : public QAbstractTableModel
{
private:
    bool isHR;
    int RowCount;
public:
    WriteRegisterModel(QObject *parent = nullptr, int _tmpRC = 85, bool _isHR = false);
    bool get_coil(const QModelIndex &index);
    uint get_holreg(const QModelIndex &index);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role) override;

    Qt::ItemFlags flags(const QModelIndex &index) const override;

    bool set_currentU(unsigned _tmpU, unsigned index);

public slots:
    void setStartAddress(int address);
    void setNumberOfValues(const QString &number);

signals:
    void updateViewport();

public:
    int m_number = 0;
    int m_address = 0;
    QBitArray m_coils;
    QVector<quint16> m_holdingRegisters;
    QVector<quint16> m_currentU;
};
#endif // WRITEREGISTERMODEL_H
