aboutsummaryrefslogtreecommitdiff
path: root/examples/GuiClient
diff options
context:
space:
mode:
authorManjeet Dahiya <manjeetdahiya@gmail.com>2010-10-16 17:55:00 +0000
committerManjeet Dahiya <manjeetdahiya@gmail.com>2010-10-16 17:55:00 +0000
commit6fc68b21ccbf39b3eb964a606ebfd4d75cbb9ff6 (patch)
tree418485d9726378b3005e54b639d086c12457db15 /examples/GuiClient
parent5fcc76bd7dfe1a785573c2cad98183ea6df76c84 (diff)
downloadqxmpp-6fc68b21ccbf39b3eb964a606ebfd4d75cbb9ff6.tar.gz
add filter for showing/hiding offline contacts
Diffstat (limited to 'examples/GuiClient')
-rw-r--r--examples/GuiClient/rosterItemSortFilterProxyModel.cpp23
-rw-r--r--examples/GuiClient/rosterItemSortFilterProxyModel.h8
2 files changed, 30 insertions, 1 deletions
diff --git a/examples/GuiClient/rosterItemSortFilterProxyModel.cpp b/examples/GuiClient/rosterItemSortFilterProxyModel.cpp
index 70d3112c..35f779fe 100644
--- a/examples/GuiClient/rosterItemSortFilterProxyModel.cpp
+++ b/examples/GuiClient/rosterItemSortFilterProxyModel.cpp
@@ -27,7 +27,7 @@
#include "utils.h"
rosterItemSortFilterProxyModel::rosterItemSortFilterProxyModel(QObject* parent):
- QSortFilterProxyModel(parent)
+ QSortFilterProxyModel(parent), m_showOfflineContacts(true)
{
setDynamicSortFilter(true);
setFilterRole(Qt::DisplayRole);
@@ -63,3 +63,24 @@ bool rosterItemSortFilterProxyModel::lessThan(const QModelIndex &left, const QMo
comparisonWeightsPresenceType(static_cast<QXmppPresence::Type>(rightPresenceType));
}
+bool rosterItemSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
+{
+ if(m_showOfflineContacts)
+ return true;
+
+ QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
+
+ int presenceType = sourceModel()->data(index, rosterItem::PresenceType).toInt();
+
+ if(presenceType == QXmppPresence::Available)
+ return true;
+ else
+ return false;
+}
+
+void rosterItemSortFilterProxyModel::setShowOfflineContacts(bool showOfflineContacts)
+{
+ m_showOfflineContacts = showOfflineContacts;
+
+ invalidateFilter();
+}
diff --git a/examples/GuiClient/rosterItemSortFilterProxyModel.h b/examples/GuiClient/rosterItemSortFilterProxyModel.h
index 9082dafc..584a0a50 100644
--- a/examples/GuiClient/rosterItemSortFilterProxyModel.h
+++ b/examples/GuiClient/rosterItemSortFilterProxyModel.h
@@ -29,11 +29,19 @@
class rosterItemSortFilterProxyModel : public QSortFilterProxyModel
{
+ Q_OBJECT
+
public:
rosterItemSortFilterProxyModel(QObject* parent = 0);
+public slots:
+ void setShowOfflineContacts(bool);
+
private:
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
+ bool filterAcceptsRow(int, const QModelIndex&) const;
+
+ bool m_showOfflineContacts;
};
#endif // ROSTERITEMSORTFILTERPROXYMODEL_H