123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /*
- * wpa_gui - EventHistory class
- * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
- *
- * This software may be distributed under the terms of the BSD license.
- * See README for more details.
- */
- #include <QHeaderView>
- #include <QScrollBar>
- #include "eventhistory.h"
- int EventListModel::rowCount(const QModelIndex &) const
- {
- return msgList.count();
- }
- int EventListModel::columnCount(const QModelIndex &) const
- {
- return 2;
- }
- QVariant EventListModel::data(const QModelIndex &index, int role) const
- {
- if (!index.isValid())
- return QVariant();
- if (role == Qt::DisplayRole)
- if (index.column() == 0) {
- if (index.row() >= timeList.size())
- return QVariant();
- return timeList.at(index.row());
- } else {
- if (index.row() >= msgList.size())
- return QVariant();
- return msgList.at(index.row());
- }
- else
- return QVariant();
- }
- QVariant EventListModel::headerData(int section, Qt::Orientation orientation,
- int role) const
- {
- if (role != Qt::DisplayRole)
- return QVariant();
- if (orientation == Qt::Horizontal) {
- switch (section) {
- case 0:
- return QString(tr("Timestamp"));
- case 1:
- return QString(tr("Message"));
- default:
- return QVariant();
- }
- } else
- return QString("%1").arg(section);
- }
- void EventListModel::addEvent(QString time, QString msg)
- {
- beginInsertRows(QModelIndex(), msgList.size(), msgList.size() + 1);
- timeList << time;
- msgList << msg;
- endInsertRows();
- }
- EventHistory::EventHistory(QWidget *parent, const char *, bool, Qt::WindowFlags)
- : QDialog(parent)
- {
- setupUi(this);
- connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
- eventListView->setItemsExpandable(false);
- eventListView->setRootIsDecorated(false);
- elm = new EventListModel(parent);
- eventListView->setModel(elm);
- }
- EventHistory::~EventHistory()
- {
- destroy();
- delete elm;
- }
- void EventHistory::languageChange()
- {
- retranslateUi(this);
- }
- void EventHistory::addEvents(WpaMsgList msgs)
- {
- WpaMsgList::iterator it;
- for (it = msgs.begin(); it != msgs.end(); it++)
- addEvent(*it);
- }
- void EventHistory::addEvent(WpaMsg msg)
- {
- bool scroll = true;
- if (eventListView->verticalScrollBar()->value() <
- eventListView->verticalScrollBar()->maximum())
- scroll = false;
- elm->addEvent(msg.getTimestamp().toString("yyyy-MM-dd hh:mm:ss.zzz"),
- msg.getMsg());
- if (scroll)
- eventListView->scrollToBottom();
- }
|