summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2014-11-13 10:13:25 (GMT)
committerSwift Review <review@swift.im>2014-11-13 22:16:29 (GMT)
commit89ca71d4016415b0f5403b8e76bbbce2012dca13 (patch)
treeaf00dfc565673e331fa2f00b528fa6b26d153494 /Swift
parentef9d71fb8999ea22013ae3286b6a30b9516e753e (diff)
downloadswift-89ca71d4016415b0f5403b8e76bbbce2012dca13.zip
swift-89ca71d4016415b0f5403b8e76bbbce2012dca13.tar.bz2
Correct notification of Qt in EventModel about changes in the model.
Test-Information: UI still updates when events are added. Change-Id: Id37a5291ae7a63a46741781298549b9e87f73b8c
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/EventViewer/EventModel.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/Swift/QtUI/EventViewer/EventModel.cpp b/Swift/QtUI/EventViewer/EventModel.cpp
index a19027a..e8412e0 100644
--- a/Swift/QtUI/EventViewer/EventModel.cpp
+++ b/Swift/QtUI/EventViewer/EventModel.cpp
@@ -1,12 +1,12 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "EventModel.h"
+#include <Swift/QtUI/EventViewer/EventModel.h>
-#include <QtDebug>
+#include <Swiften/Base/Log.h>
namespace Swift {
EventModel::EventModel() {
@@ -23,7 +23,20 @@ EventModel::~EventModel() {
}
QtEvent* EventModel::getItem(int row) const {
- return row < activeEvents_.size() ? activeEvents_[row] : inactiveEvents_[row - activeEvents_.size()];
+ QtEvent* event = NULL;
+ if (row < activeEvents_.size()) {
+ event = activeEvents_[row];
+ }
+ else {
+ int inactiveRow = row - activeEvents_.size();
+ if (inactiveRow < inactiveEvents_.size()) {
+ event = inactiveEvents_[inactiveRow];
+ }
+ else {
+ SWIFT_LOG(error) << "Misbehaving EventModel requests row index outside of range";
+ }
+ }
+ return event;
}
int EventModel::getNewEventCount() {
@@ -57,24 +70,23 @@ int EventModel::rowCount(const QModelIndex& parent) const {
}
void EventModel::addEvent(boost::shared_ptr<StanzaEvent> event, bool active) {
+ beginResetModel();
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));
if (inactiveEvents_.size() > 50) {
removeEvent(inactiveEvents_[20]->getEvent());
}
}
- emit layoutChanged();
+ endResetModel();
}
void EventModel::removeEvent(boost::shared_ptr<StanzaEvent> event) {
+ beginResetModel();
for (int i = inactiveEvents_.size() - 1; i >= 0; i--) {
if (event == inactiveEvents_[i]->getEvent()) {
inactiveEvents_.removeAt(i);
- emit dataChanged(createIndex(activeEvents_.size() + i - 1, 0), createIndex(activeEvents_.size() + i - 1, 0));
return;
}
}
@@ -82,11 +94,10 @@ void EventModel::removeEvent(boost::shared_ptr<StanzaEvent> 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;
}
}
-
+ endResetModel();
}
}