LedDisplay/app/leddisplaytextmodel.h

97 lines
2.6 KiB
C++

#ifndef LEDDISPLAYTEXTMODEL_H
#define LEDDISPLAYTEXTMODEL_H
#include <QAbstractListModel>
#include <QObject>
#include <QColor>
#include <QDebug>
class LedDisplayTextModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
Q_PROPERTY(int maximumTextSets READ getMaximumTextSets NOTIFY maximumTextSetsChanged)
public:
friend class LedDisplayBackend;
enum LedDisplayTextModelRole {
TextRole = Qt::DisplayRole,
ActiveRole,
RuntimeRole,
ColorRole,
AlignmentRole,
ScrollRole,
ScrollDirectionRole,
ScrollSpeedRole,
ScrollCountRole,
IndexRole,
LedDisplayTextModelRoleCount
};
Q_ENUM(LedDisplayTextModelRole)
enum OmobiDisplayTextAlignment
{
AlignLeft,
AlignCenter,
AlignRignt
};
Q_INVOKABLE int rowCount(const QModelIndex & = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QVariant data(int i, int role = Qt::DisplayRole) const;
QHash<int, QByteArray> roleNames() const;
Q_INVOKABLE void append(
QString text,
bool active,
unsigned int runtime,
QString color,
unsigned int alignment,
bool scroll,
unsigned int scrollDirection,
unsigned int scrollSpeed,
unsigned int scrollCount
);
void append(const QMap<int, QVariant> &roles);
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
Q_INVOKABLE void remove(int row);
Q_INVOKABLE int getMaximumTextSets();
protected:
LedDisplayTextModel(QObject* parent = nullptr);
bool setTexts(QList<QMap<int, QVariant>> json);
QList<QMap<int, QVariant>> getTexts();
QMap<int, QVariant> getText(const QModelIndex &index);
void clear();
private:
QList<QMap<int, QVariant>> texts;
int maximumTextSets;
int maximumTextLength;
const QMap<LedDisplayTextModelRole, QVariant::Type> roleDataTypes = {
{TextRole, QVariant::String},
{ActiveRole, QVariant::Bool},
{RuntimeRole, QVariant::Int},
{ColorRole, QVariant::String},
{AlignmentRole, QVariant::Int},
{ScrollRole, QVariant::Bool},
{ScrollDirectionRole, QVariant::Int},
{ScrollSpeedRole, QVariant::Int},
{ScrollCountRole, QVariant::Int},
{IndexRole, QVariant::Int}
};
signals:
void rowCountChanged();
void maximumTextSetsChanged();
};
#endif // LEDDISPLAYTEXTMODEL_H