mirror of
https://github.com/logos-blockchain/logos-blockchain-ui.git
synced 2026-04-03 09:53:16 +00:00
44 lines
947 B
C++
44 lines
947 B
C++
#include "LogModel.h"
|
|
|
|
int LogModel::rowCount(const QModelIndex& parent) const
|
|
{
|
|
if (parent.isValid())
|
|
return 0;
|
|
return m_lines.size();
|
|
}
|
|
|
|
QVariant LogModel::data(const QModelIndex& index, int role) const
|
|
{
|
|
if (!index.isValid() || index.row() < 0 || index.row() >= m_lines.size())
|
|
return QVariant();
|
|
if (role == TextRole || role == Qt::DisplayRole)
|
|
return m_lines.at(index.row());
|
|
return QVariant();
|
|
}
|
|
|
|
QHash<int, QByteArray> LogModel::roleNames() const
|
|
{
|
|
QHash<int, QByteArray> names;
|
|
names[TextRole] = "text";
|
|
return names;
|
|
}
|
|
|
|
void LogModel::append(const QString& line)
|
|
{
|
|
const int row = m_lines.size();
|
|
beginInsertRows(QModelIndex(), row, row);
|
|
m_lines.append(line);
|
|
endInsertRows();
|
|
emit countChanged();
|
|
}
|
|
|
|
void LogModel::clear()
|
|
{
|
|
if (m_lines.isEmpty())
|
|
return;
|
|
beginResetModel();
|
|
m_lines.clear();
|
|
endResetModel();
|
|
emit countChanged();
|
|
}
|