2020-10-11 21:01:21 +02:00
|
|
|
#include "omobidisplaytextmodel.h"
|
|
|
|
|
|
|
|
OmobiDisplayTextModel::OmobiDisplayTextModel(QObject* parent) : QAbstractListModel(parent)
|
|
|
|
{
|
|
|
|
QMap<int, QVariant> sampleText1 = {
|
|
|
|
{ TextRole, "itsblue.de" },
|
|
|
|
{ ActiveRole, true },
|
|
|
|
{ RuntimeRole, 20 },
|
|
|
|
{ ColorRole, "blue" },
|
|
|
|
{ AlignmentRole, "center" },
|
|
|
|
{ ScrollRole, true },
|
|
|
|
{ ScrollCountRole, 20 }
|
|
|
|
};
|
|
|
|
|
|
|
|
QMap<int, QVariant> sampleText2 = {
|
|
|
|
{ TextRole, "Das ist ein tolles Display" },
|
|
|
|
{ ActiveRole, false },
|
|
|
|
{ RuntimeRole, 10 },
|
|
|
|
{ ColorRole, "green" },
|
|
|
|
{ AlignmentRole, "left" },
|
|
|
|
{ ScrollRole, true },
|
|
|
|
{ ScrollCountRole, 10 }
|
|
|
|
};
|
|
|
|
|
|
|
|
this->texts.append(sampleText1);
|
|
|
|
this->texts.append(sampleText2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int OmobiDisplayTextModel::rowCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return this->texts.length();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant OmobiDisplayTextModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (index.row() < rowCount())
|
|
|
|
if(this->texts[index.row()].contains(role))
|
|
|
|
return this->texts[index.row()][role];
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash<int, QByteArray> OmobiDisplayTextModel::roleNames() const
|
|
|
|
{
|
|
|
|
static const QHash<int, QByteArray> roles {
|
|
|
|
{ TextRole, "text" },
|
|
|
|
{ ActiveRole, "active" },
|
|
|
|
{ RuntimeRole, "runtime" },
|
|
|
|
{ ColorRole, "color" },
|
|
|
|
{ AlignmentRole, "alignment" },
|
|
|
|
{ ScrollRole, "scroll" },
|
2020-10-12 14:13:52 +02:00
|
|
|
{ ScrollSpeedRole, "scrollSpeed" },
|
|
|
|
{ ScrollCountRole, "scrollCount" },
|
|
|
|
{ BrightnessRole, "brightness" }
|
2020-10-11 21:01:21 +02:00
|
|
|
};
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OmobiDisplayTextModel::append(
|
|
|
|
QString text,
|
|
|
|
bool active,
|
|
|
|
unsigned int runtime,
|
|
|
|
QString color,
|
|
|
|
QString alignment,
|
|
|
|
bool scroll,
|
2020-10-12 14:13:52 +02:00
|
|
|
unsigned int scrollSpeed,
|
|
|
|
unsigned int scrollCount,
|
|
|
|
unsigned int brightness
|
2020-10-11 21:01:21 +02:00
|
|
|
) {
|
|
|
|
QMap<int, QVariant> roles = {
|
|
|
|
{ TextRole, text },
|
|
|
|
{ ActiveRole, active },
|
|
|
|
{ RuntimeRole, runtime },
|
|
|
|
{ ColorRole, color },
|
|
|
|
{ AlignmentRole, alignment },
|
|
|
|
{ ScrollRole, scroll },
|
2020-10-12 14:13:52 +02:00
|
|
|
{ ScrollSpeedRole, scrollSpeed },
|
|
|
|
{ ScrollCountRole, scrollCount },
|
|
|
|
{ BrightnessRole, brightness }
|
2020-10-11 21:01:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
this->append(roles);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OmobiDisplayTextModel::append(const QMap<int, QVariant> &roles) {
|
|
|
|
int row = this->texts.length();
|
|
|
|
this->beginInsertRows(QModelIndex(), row, row);
|
|
|
|
this->texts.insert(row, roles);
|
|
|
|
this->endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OmobiDisplayTextModel::setData(const QModelIndex &index, const QVariant &value, int role) {
|
|
|
|
if (index.row() >= rowCount() || !this->texts[index.row()].contains(role))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(this->texts[index.row()][role] == value)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
this->texts[index.row()][role] = value;
|
|
|
|
|
|
|
|
emit dataChanged(index, index);
|
|
|
|
|
|
|
|
return QAbstractItemModel::setData(index, value, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OmobiDisplayTextModel::remove(int row)
|
|
|
|
{
|
|
|
|
if (row < 0 || row >= this->rowCount())
|
|
|
|
return;
|
|
|
|
|
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
this->texts.removeAt(row);
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OmobiDisplayTextModel::clear() {
|
|
|
|
for(int i = 0; i < this->texts.length(); i++)
|
|
|
|
this->remove(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString OmobiDisplayTextModel::getAsJson() {
|
2020-10-12 14:13:52 +02:00
|
|
|
return "";
|
2020-10-11 21:01:21 +02:00
|
|
|
}
|