summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-03-19 09:17:18 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-03-19 15:10:33 (GMT)
commit580d3d49ea3df7bb1c00cb1052203d17ccaa9a8e (patch)
treec823ef404a7a70c261248c41530827caab07fc52 /Swift/QtUI/EventViewer/EventModel.cpp
parent5d9a6702c244eb4ab30ce96465d9deceedfe955a (diff)
downloadswift-580d3d49ea3df7bb1c00cb1052203d17ccaa9a8e.zip
swift-580d3d49ea3df7bb1c00cb1052203d17ccaa9a8e.tar.bz2
Start of event viewer.
Creates a basic event viewer framework, and plugs it into the Swift controllers, so that messages are displayed (in a very ugly way). Still a long way to go.
Diffstat (limited to 'Swift/QtUI/EventViewer/EventModel.cpp')
-rw-r--r--Swift/QtUI/EventViewer/EventModel.cpp56
1 files changed, 51 insertions, 5 deletions
diff --git a/Swift/QtUI/EventViewer/EventModel.cpp b/Swift/QtUI/EventViewer/EventModel.cpp
index a3d5406..ffe2110 100644
--- a/Swift/QtUI/EventViewer/EventModel.cpp
+++ b/Swift/QtUI/EventViewer/EventModel.cpp
@@ -1,20 +1,66 @@
#include "EventModel.h"
+#include <qdebug>
+
namespace Swift {
EventModel::EventModel() {
}
EventModel::~EventModel() {
-
+ foreach (QtEvent* event, activeEvents_) {
+ delete event;
+ }
+ foreach (QtEvent* event, inactiveEvents_) {
+ delete event;
+ }
+}
+
+QVariant EventModel::data(const QModelIndex& index, int role) const {
+ if (!index.isValid()) {
+ return QVariant();
+ }
+ int row = index.row();
+ QtEvent* item = index.row() < activeEvents_.size() ? activeEvents_[row] : inactiveEvents_[row - activeEvents_.size()];
+ QVariant result = item ? item->data(role) : QVariant();
+ qDebug() << "Asked for data of " << index << ", " << role << " returning " << result;
+ return result;
}
-QVariant EventModel::data(const QModelIndex& /*index*/, int /*role*/) const {
- return QVariant();
+int EventModel::rowCount(const QModelIndex& parent) const {
+ /* Invalid parent = root, valid parent = child, and we're a list not a tree.*/
+ int count = parent.isValid() ? 0 : activeEvents_.size() + inactiveEvents_.size();
+ return count;
}
-int EventModel::rowCount(const QModelIndex& /*parent*/) const {
- return 0;
+void EventModel::addEvent(boost::shared_ptr<Event> event, bool active) {
+ qDebug() << " Adding Event";
+ if (active) {
+ activeEvents_.push_front(new QtEvent(event, active));
+ emit dataChanged(createIndex(0, 0), createIndex(1, 0));
+ } else {
+ inactiveEvents_.push_front(new QtEvent(event, active));
+ emit dataChanged(createIndex(activeEvents_.size() -1, 0), createIndex(activeEvents_.size(), 0));
+ }
+ emit layoutChanged();
+}
+
+void EventModel::removeEvent(boost::shared_ptr<Event> event) {
+ for (int i = 0; i < activeEvents_.size(); i++) {
+ if (event == activeEvents_[i]->getEvent()) {
+ activeEvents_.removeAt(i);
+ emit dataChanged(createIndex(i - 1, 0), createIndex(i - 1, 0));
+ return;
+ }
+ }
+ for (int i = 0; i < inactiveEvents_.size(); i++) {
+ if (event == inactiveEvents_[i]->getEvent()) {
+ inactiveEvents_.removeAt(i);
+ emit dataChanged(createIndex(activeEvents_.size() + i - 1, 0), createIndex(activeEvents_.size() + i - 1, 0));
+ return;
+ }
+ }
+
}
}