summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/UserSearch/UserSearchModel.cpp')
-rw-r--r--Swift/QtUI/UserSearch/UserSearchModel.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/Swift/QtUI/UserSearch/UserSearchModel.cpp b/Swift/QtUI/UserSearch/UserSearchModel.cpp
new file mode 100644
index 0000000..782d2d0
--- /dev/null
+++ b/Swift/QtUI/UserSearch/UserSearchModel.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2010 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swift/QtUI/UserSearch/UserSearchModel.h"
+
+#include "Swift/QtUI/QtSwiftUtil.h"
+
+namespace Swift {
+
+UserSearchModel::UserSearchModel() {
+}
+
+void UserSearchModel::clear() {
+ emit layoutAboutToBeChanged();
+ results_.clear();
+ emit layoutChanged();
+}
+
+void UserSearchModel::setResults(const std::vector<UserSearchResult>& results) {
+ clear();
+ emit layoutAboutToBeChanged();
+ results_ = results;
+ emit layoutChanged();
+}
+
+int UserSearchModel::columnCount(const QModelIndex& /*parent*/) const {
+ return 1;
+}
+
+QVariant UserSearchModel::data(const QModelIndex& index, int role) const {
+ if (!index.isValid()) return QVariant();
+ UserSearchResult* result = static_cast<UserSearchResult*>(index.internalPointer());
+ switch (role) {
+ case Qt::DisplayRole: return QVariant(P2QSTRING(result->getJID().toString()));
+ default: return QVariant();
+ }
+}
+
+QModelIndex UserSearchModel::index(int row, int column, const QModelIndex & parent) const {
+ if (!hasIndex(row, column, parent)) {
+ return QModelIndex();
+ }
+ return row < (int)results_.size() ? createIndex(row, column, (void*)&(results_[row])) : QModelIndex();
+}
+
+QModelIndex UserSearchModel::parent(const QModelIndex& /*index*/) const {
+ return QModelIndex();
+}
+
+int UserSearchModel::rowCount(const QModelIndex& parentIndex) const {
+ if (!parentIndex.isValid()) {
+ return results_.size();
+ }
+ return 0;
+}
+
+}