summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-08-25 14:00:10 (GMT)
committerTobias Markmann <tm@ayena.de>2016-08-25 14:12:34 (GMT)
commit5a4e7d9518e91cf39b96f14b3b310fe5b9a27594 (patch)
treede15882d3bb6f7b5e8230deada40ccc705a25c9c /Swift/QtUI/MUCSearch/MUCSearchModel.cpp
parent5a19f3167b640966c582e52abe4b55ef20bd79b2 (diff)
downloadswift-5a4e7d9518e91cf39b96f14b3b310fe5b9a27594.zip
swift-5a4e7d9518e91cf39b96f14b3b310fe5b9a27594.tar.bz2
Alphabetically sort MUC search result
This also changes the classes around MUCSearchModel to C++11 smart pointer based memory management. Test-Information: Verified that dtors of MUCSearch*Items are called when old search results are replaced by new search results. This was not the case previously. All unit tests and manual testing with an ASAN enabled build succeeded. Change-Id: I84d62f3b86138728401b98d3774f47c72fdf9a4c
Diffstat (limited to 'Swift/QtUI/MUCSearch/MUCSearchModel.cpp')
-rw-r--r--Swift/QtUI/MUCSearch/MUCSearchModel.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/Swift/QtUI/MUCSearch/MUCSearchModel.cpp b/Swift/QtUI/MUCSearch/MUCSearchModel.cpp
index 2dbfc37..cc36f5f 100644
--- a/Swift/QtUI/MUCSearch/MUCSearchModel.cpp
+++ b/Swift/QtUI/MUCSearch/MUCSearchModel.cpp
@@ -6,6 +6,8 @@
#include <Swift/QtUI/MUCSearch/MUCSearchModel.h>
+#include <memory>
+
#include <Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h>
namespace Swift {
@@ -14,13 +16,19 @@ MUCSearchModel::MUCSearchModel() {
}
void MUCSearchModel::clear() {
- emit layoutAboutToBeChanged();
+ // We need to reset the model, so that model indices containing raw pointers
+ // to MUCSearchServiceItems are invalaidated before we delete the
+ // MUCSearchServiceItems.
+ emit beginResetModel();
services_.clear();
- emit layoutChanged();
+ emit endResetModel();
}
-void MUCSearchModel::addService(MUCSearchServiceItem* service) {
+void MUCSearchModel::addService(std::shared_ptr<MUCSearchServiceItem> service) {
emit layoutAboutToBeChanged();
+ if (sortOrder_) {
+ service->setSorting(*sortOrder_);
+ }
services_.push_back(service);
emit layoutChanged();
}
@@ -42,10 +50,8 @@ QModelIndex MUCSearchModel::index(int row, int column, const QModelIndex & paren
MUCSearchServiceItem* parentItem = static_cast<MUCSearchServiceItem*>(parent.internalPointer());
return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex();
} else {
- return row < services_.size() ? createIndex(row, column, services_[row]) : QModelIndex();
+ return row < services_.size() ? createIndex(row, column, services_[row].get()) : QModelIndex();
}
-
-
}
QModelIndex MUCSearchModel::parent(const QModelIndex& index) const {
@@ -60,7 +66,7 @@ QModelIndex MUCSearchModel::parent(const QModelIndex& index) const {
return QModelIndex();
}
- MUCSearchServiceItem* parent = nullptr;
+ std::shared_ptr<MUCSearchServiceItem> parent;
if (MUCSearchRoomItem* roomItem = dynamic_cast<MUCSearchRoomItem*>(item)) {
parent = roomItem->getParent();
}
@@ -69,7 +75,7 @@ QModelIndex MUCSearchModel::parent(const QModelIndex& index) const {
}
if (parent) {
int row = services_.indexOf(parent);
- return createIndex(row, 1, parent);
+ return createIndex(row, 1, parent.get());
}
else {
return QModelIndex();
@@ -88,4 +94,13 @@ int MUCSearchModel::rowCount(const QModelIndex& parentIndex) const {
}
}
+void MUCSearchModel::sort(int column, Qt::SortOrder order) {
+ sortOrder_ = order;
+ if (column == 0) {
+ for (auto&& serviceItem : services_) {
+ serviceItem->setSorting(*sortOrder_);
+ }
+ }
+}
+
}