[SCM] ktp-contact-list packaging branch, master, updated. debian/15.12.1-2-1070-g6c56f91
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:04:41 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=a437e60
The following commit has been merged in the master branch:
commit a437e603777f21c08f895f99220da04b40c8b976
Author: George Goldberg <grundleborg at googlemail.com>
Date: Tue Mar 16 22:12:15 2010 +0000
Make the group-grouping proxy-model work with metacontacts.
svn path=/trunk/playground/network/telepathy-contactlist/; revision=1104165
---
contacts-list-model.cpp | 2 +-
grouped-contacts-proxy-model.cpp | 118 +++++++++++++++++++++++++--------------
grouped-contacts-proxy-model.h | 11 ++--
main-widget.cpp | 6 +-
meta-contact-item.cpp | 16 ++++++
meta-contact-item.h | 1 +
6 files changed, 103 insertions(+), 51 deletions(-)
diff --git a/contacts-list-model.cpp b/contacts-list-model.cpp
index 56eaca4..fe53457 100644
--- a/contacts-list-model.cpp
+++ b/contacts-list-model.cpp
@@ -174,7 +174,7 @@ QVariant ContactsListModel::data(const QModelIndex &index, int role) const
// data.setValue<qint64>(contactItem->presenceType());
break;
case ContactsListModel::GroupsRole:
-// data.setValue<QStringList>(contactItem->groups());
+ data.setValue<QStringList>(metaContactItem->groups());
break;
default:
break;
diff --git a/grouped-contacts-proxy-model.cpp b/grouped-contacts-proxy-model.cpp
index 2ff30c2..68928dd 100644
--- a/grouped-contacts-proxy-model.cpp
+++ b/grouped-contacts-proxy-model.cpp
@@ -57,7 +57,7 @@ QVariant GroupedContactsProxyModel::data(const QModelIndex &index, int role) con
// Return the group data.
QVariant data;
- Item *item = m_rootItem->children.at(index.row());
+ Item *item = dynamic_cast<Item*>(m_rootItem->childItems().at(index.row()));
Q_ASSERT(item);
if (!item) {
@@ -80,69 +80,73 @@ QVariant GroupedContactsProxyModel::data(const QModelIndex &index, int role) con
QModelIndex GroupedContactsProxyModel::index(int row, int column, const QModelIndex &parent) const
{
-// kWarning() << "index called";
- if (parent.isValid() && parent.parent().isValid()) {
+ // 1 column list, so invalid index if the column is not 1.
+ if (parent.isValid() && parent.column() != 0) {
return QModelIndex();
}
- // Only 1 column
- if (column != 0) {
- return QModelIndex();
- }
-
- if (parent.isValid()) {
- if (row >= m_rootItem->children.at(parent.row())->children.length()) {
- return QModelIndex();
- }
+ // Get the parent item.
+ Item *parentItem = item(parent);
- return createIndex(row, column, m_rootItem->children.at(parent.row())->children.at(row));
- }
+ // Get all the parent's children.
+ QList<AbstractTreeItem*> children = parentItem->childItems();
- // Return the index to the item.
- if (row >= m_rootItem->children.length()) {
+ // Check the row doesn't go beyond the end of the list of children.
+ if (row >= children.length()) {
return QModelIndex();
}
- return createIndex(row, column, m_rootItem->children.at(row));
+ // Return the index to the item.
+ return createIndex(row, column, children.at(row));
}
QModelIndex GroupedContactsProxyModel::parent(const QModelIndex &index) const
{
-// kWarning() << "Parent called. Argh";
+ // If the index is invalid, return an invalid parent index.
+ if (!index.isValid()) {
+ return QModelIndex();
+ }
- Item *item = static_cast<Item*>(index.internalPointer());
+ // Get the item we have been passed, and it's parent
+ Item *childItem = item(index);
+ Item *parentItem = dynamic_cast<Item*>(childItem->parentItem());
- Q_ASSERT(item);
- if (!item) {
- kWarning() << "Not a valid internal pointer. Argh :/";
+ // If the parent is the root item, then the parent index of the index we were passed is
+ // by definition an invalid index.
+ if (parentItem == m_rootItem) {
return QModelIndex();
}
- if (item->parent == m_rootItem) {
- return QModelIndex();
+ // The parent of the item is not the root item, meaning that the parent must have a parent too.
+ Item *parentOfParentItem = dynamic_cast<Item*>(parentItem->parentItem());
+
+ // As stated in the previous comment, something is really wrong if it doesn't have a parent.
+ Q_ASSERT(parentOfParentItem);
+ if (!parentOfParentItem) {
+ kWarning() << "Impossible parent situation occurred!";
+ return createIndex(0, 0, parentItem);
}
- return this->index(m_rootItem->children.lastIndexOf(item->parent), 0, QModelIndex());
+ // Return the model index of the parent item.
+ return createIndex(parentOfParentItem->childItems().lastIndexOf(parentItem), 0, parentItem);
}
int GroupedContactsProxyModel::rowCount(const QModelIndex &parent) const
{
- if (parent == QModelIndex()) {
- return m_rootItem->children.length();
+ // If the parent is invalid, then this request is for the root item.
+ if (!parent.isValid()) {
+ return m_rootItem->childItems().length();
}
- if (parent.parent() == QModelIndex()) {
- Item *item = static_cast<Item*>(parent.internalPointer());
-
- Q_ASSERT(item);
- if (!item) {
- kWarning() << "Not a valid internal pointer. Argh :/";
- return 0;
- }
+ // Get the item from the internal pointer of the ModelIndex.
+ AbstractTreeItem *item = static_cast<AbstractTreeItem*>(parent.internalPointer());
- return item->children.length();
+ // If the item is valid, return the number of children it has.
+ if (item) {
+ return item->childItems().length();
}
+ // Otherwise, return 0
return 0;
}
@@ -218,8 +222,11 @@ void GroupedContactsProxyModel::onSourceReset()
// Reset the internal data-layout of this model.
if (m_rootItem) {
- foreach (Item *item, m_rootItem->children) {
- foreach (Item *i, item->children) {
+ foreach (AbstractTreeItem *item, m_rootItem->childItems()) {
+ foreach (AbstractTreeItem *i, item->childItems()) {
+ foreach (AbstractTreeItem *i3, i->childItems()) {
+ delete i3;
+ }
delete i;
}
delete item;
@@ -237,7 +244,12 @@ void GroupedContactsProxyModel::onSourceReset()
foreach (const QString &group, groups) {
Item *item = 0;
- foreach (Item *i, m_rootItem->children) {
+ foreach (AbstractTreeItem *ii, (m_rootItem->childItems())) {
+ Item *i = dynamic_cast<Item*>(ii);
+ if (!i) {
+ continue;
+ }
+
if (i->name == group) {
item = i;
break;
@@ -246,15 +258,23 @@ void GroupedContactsProxyModel::onSourceReset()
if (!item) {
item = new Item;
- item->parent = m_rootItem;
- m_rootItem->children.append(item);
+ item->setParentItem(m_rootItem);
+ m_rootItem->appendChildItem(item);
item->name = group;
}
Item *childItem = new Item;
childItem->sourceIndex = index;
- item->children.append(childItem);
- childItem->parent = item;
+ item->appendChildItem(childItem);
+ childItem->setParentItem(item);
+
+ for (int j=0; j < m_sourceModel->rowCount(index); ++j) {
+ QModelIndex childIndex = m_sourceModel->index(j, 0, index);
+ Item *childChildItem = new Item;
+ childChildItem->sourceIndex = childIndex;
+ childChildItem->setParentItem(childItem);
+ childItem->appendChildItem(childChildItem);
+ }
}
}
@@ -274,6 +294,18 @@ void GroupedContactsProxyModel::onSourceRowsRemoved(const QModelIndex &parent, i
// TODO: Invalidate All Mappings
}
+GroupedContactsProxyModel::Item* GroupedContactsProxyModel::item(const QModelIndex &index) const
+{
+ if (index.isValid()) {
+ Item *item = static_cast<Item*>(index.internalPointer());
+ if (item) {
+ return item;
+ }
+ }
+
+ return m_rootItem;
+}
+
#include "grouped-contacts-proxy-model.moc"
diff --git a/grouped-contacts-proxy-model.h b/grouped-contacts-proxy-model.h
index 3a4388e..91ee2f4 100644
--- a/grouped-contacts-proxy-model.h
+++ b/grouped-contacts-proxy-model.h
@@ -22,6 +22,8 @@
#ifndef TELEPATHY_CONTACTSLIST_PROTOTYPE_GROUPED_CONTACTS_PROXY_MODEL_H
#define TELEPATHY_CONTACTSLIST_PROTOTYPE_GROUPED_CONTACTS_PROXY_MODEL_H
+#include "abstract-tree-item.h"
+
#include <QtGui/QAbstractProxyModel>
class ContactsListModel;
@@ -54,15 +56,16 @@ private Q_SLOTS:
void onSourceReset();
private:
- struct Item {
- Item *parent;
- QList<Item*> children;
+ class Item : public AbstractTreeItem {
+ public:
QString name;
QModelIndex sourceIndex;
- Item() : parent(0) { }
+ Item() { }
};
+ Item *item(const QModelIndex &index) const;
+
ContactsListModel *m_sourceModel;
Item *m_rootItem;
diff --git a/main-widget.cpp b/main-widget.cpp
index 325af61..19567f8 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -41,11 +41,11 @@ MainWidget::MainWidget(QWidget *parent)
m_sortFilterProxyModel = new QSortFilterProxyModel(this);
m_sortFilterProxyModel->setSourceModel(m_model);
- // m_groupedContactsProxyModel = new GroupedContactsProxyModel(this);
- // m_groupedContactsProxyModel->setSourceModel(m_model);
+ m_groupedContactsProxyModel = new GroupedContactsProxyModel(this);
+ m_groupedContactsProxyModel->setSourceModel(m_model);
m_contactsListView->setSortingEnabled(true);
- m_contactsListView->setModel(m_sortFilterProxyModel);
+ m_contactsListView->setModel(m_groupedContactsProxyModel);
}
MainWidget::~MainWidget()
diff --git a/meta-contact-item.cpp b/meta-contact-item.cpp
index b7844e1..276bdf4 100644
--- a/meta-contact-item.cpp
+++ b/meta-contact-item.cpp
@@ -96,6 +96,22 @@ const KIcon &MetaContactItem::presenceIcon() const
return item->presenceIcon();
}
+QStringList MetaContactItem::groups() const
+{
+ // FIXME: What should we actually return here?
+ if (childItems().isEmpty()) {
+ return QStringList();
+ }
+
+ ContactItem *item = dynamic_cast<ContactItem*>(childItems().first());
+
+ if (!item) {
+ return QStringList();
+ }
+
+ return item->groups();
+}
+
#include "meta-contact-item.moc"
diff --git a/meta-contact-item.h b/meta-contact-item.h
index b9414ee..5ef0ef0 100644
--- a/meta-contact-item.h
+++ b/meta-contact-item.h
@@ -50,6 +50,7 @@ public:
QString displayName() const;
const KIcon &presenceIcon() const;
+ QStringList groups() const;
void setPimoPerson(const Nepomuk::Person &pimoPerson);
--
ktp-contact-list packaging
More information about the pkg-kde-commits
mailing list