123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include "LogModel.h"
- LogEntry::LogEntry(const QString & nmessage)
- : message(nmessage)
- , time(QTime::currentTime())
- {
- }
- LogEntry::~LogEntry()
- {
- }
- LogModel::LogModel(QObject *parent)
- : QAbstractTableModel(parent)
- {
- }
- LogModel::~LogModel()
- {
- }
- void LogModel::log(const QString & message)
- {
- beginInsertRows(QModelIndex(), rowCount(), rowCount());
- m_entries << LogEntry(message);
- endInsertRows();
- }
- int LogModel::rowCount(const QModelIndex &parent) const
- {
- if (!parent.isValid()) {
- return m_entries.count();
- }
- return 0;
- }
- int LogModel::columnCount(const QModelIndex &parent) const
- {
- if (!parent.isValid()) {
- return ColumnCount;
- }
- return 0;
- }
- QVariant LogModel::data(const QModelIndex &index, int role) const
- {
- if (index.isValid() && role == Qt::DisplayRole) {
- LogEntry entry(m_entries.at(index.row()));
- switch (index.column()) {
- case TimeColumn:
- return entry.time.toString();
- break;
- case MessageColumn:
- return entry.message;
- break;
- default:
- break;
- }
- }
- return QVariant();
- }
|