[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9
Maximiliano Curia
maxy at moszumanska.debian.org
Mon May 9 09:06:07 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=0661317
The following commit has been merged in the master branch:
commit 0661317b78e6649e35b84d2c5c5b087786b40095
Author: Dan Vrátil <dvratil at redhat.com>
Date: Sun Dec 30 12:25:41 2012 +0100
Port ContactsFilterModel away from GroupsModelItem and AccountsModelItem
Make OnlineUsersCountRole and TotalUsersCountRole work with ContactsListModel
as source model. The commit ports the code away from GroupsModelItem and
AccountsModelItem because these are ContactsModel-specific).
REVIEW: 108018
---
KTp/Models/abstract-grouping-proxy-model.cpp | 2 +-
KTp/Models/accounts-tree-proxy-model.cpp | 3 +-
KTp/Models/accounts-tree-proxy-model.h | 2 +-
KTp/Models/contacts-filter-model.cpp | 170 ++++++++++++---------------
4 files changed, 81 insertions(+), 96 deletions(-)
diff --git a/KTp/Models/abstract-grouping-proxy-model.cpp b/KTp/Models/abstract-grouping-proxy-model.cpp
index 533d545..f728136 100644
--- a/KTp/Models/abstract-grouping-proxy-model.cpp
+++ b/KTp/Models/abstract-grouping-proxy-model.cpp
@@ -236,7 +236,7 @@ void AbstractGroupingProxyModel::onModelReset()
m_proxyMap.clear();
m_groupMap.clear();
kDebug() << "reset";
-
+
if (m_source->rowCount() > 0) {
onRowsInserted(QModelIndex(), 0, m_source->rowCount());
}
diff --git a/KTp/Models/accounts-tree-proxy-model.cpp b/KTp/Models/accounts-tree-proxy-model.cpp
index e5ad725..5a2e64f 100644
--- a/KTp/Models/accounts-tree-proxy-model.cpp
+++ b/KTp/Models/accounts-tree-proxy-model.cpp
@@ -35,10 +35,8 @@ QSet<QString> AccountsTreeProxyModel::groupsForIndex(const QModelIndex &sourceIn
{
const Tp::AccountPtr account = sourceIndex.data(ContactsModel::AccountRole).value<Tp::AccountPtr>();
if (account) {
- qDebug() << "account";
return QSet<QString>() << account->objectPath();
} else {
- qDebug() << "no account";
return QSet<QString>() << QLatin1String("Unknown");
}
}
@@ -77,5 +75,6 @@ QVariant AccountsTreeProxyModel::dataForGroup(const QString &group, int role) co
}
return Tp::ConnectionStatusConnected;
}
+
return QVariant();
}
diff --git a/KTp/Models/accounts-tree-proxy-model.h b/KTp/Models/accounts-tree-proxy-model.h
index 98bab16..3b2ad6f 100644
--- a/KTp/Models/accounts-tree-proxy-model.h
+++ b/KTp/Models/accounts-tree-proxy-model.h
@@ -30,7 +30,7 @@ class KTP_EXPORT AccountsTreeProxyModel : public AbstractGroupingProxyModel
Q_OBJECT
public:
AccountsTreeProxyModel(QAbstractItemModel *sourceModel, const Tp::AccountManagerPtr &accountManager);
-
+
virtual QSet<QString> groupsForIndex(const QModelIndex &sourceIndex) const;
virtual QVariant dataForGroup(const QString &group, int role) const;
private:
diff --git a/KTp/Models/contacts-filter-model.cpp b/KTp/Models/contacts-filter-model.cpp
index 269505c..330a368 100644
--- a/KTp/Models/contacts-filter-model.cpp
+++ b/KTp/Models/contacts-filter-model.cpp
@@ -409,53 +409,62 @@ QVariant ContactsFilterModel::data(const QModelIndex &index, int role) const
}
// Special handling for the counts
+ ContactsModel::RowType rowType = static_cast<ContactsModel::RowType>(sourceIndex.data(ContactsModel::TypeRole).toInt());
if (role == ContactsModel::OnlineUsersCountRole) {
- QVariant item = sourceIndex.data(ContactsModel::ItemRole);
- if (item.canConvert<GroupsModelItem*>()) {
- GroupsModelItem *gmItem = item.value<GroupsModelItem*>();
+ if (rowType == ContactsModel::GroupRowType) {
+ const QString groupName = sourceIndex.data(Qt::DisplayRole).toString();
// If there is no cached value, create one
- if (!d->m_onlineContactsCounts.contains(gmItem->groupName())) {
+ if (!d->m_onlineContactsCounts.contains(groupName)) {
countContacts(sourceIndex);
}
- return d->m_onlineContactsCounts.value(gmItem->groupName());
- } else if (item.canConvert<AccountsModelItem*>()) {
- AccountsModelItem *amItem = item.value<AccountsModelItem*>();
+ return d->m_onlineContactsCounts.value(groupName);
+ } else if (rowType == ContactsModel::AccountRowType) {
+ const Tp::AccountPtr account = sourceIndex.data(ContactsModel::AccountRole).value<Tp::AccountPtr>();
+ if (account.isNull()) {
+ return 0;
+ }
// If there is no cached value, create one
- if (!d->m_onlineContactsCounts.contains(amItem->data(ContactsModel::IdRole).toString())) {
+ if (!d->m_onlineContactsCounts.contains(account->uniqueIdentifier())) {
countContacts(sourceIndex);
}
- return d->m_onlineContactsCounts.value(amItem->data(ContactsModel::IdRole).toString());
+ return d->m_onlineContactsCounts.value(account->uniqueIdentifier());
}
} else if (role == ContactsModel::TotalUsersCountRole) {
- QVariant item = sourceIndex.data(ContactsModel::ItemRole);
- if (item.canConvert<GroupsModelItem*>()) {
- GroupsModelItem *gmItem = item.value<GroupsModelItem*>();
+ if (rowType == ContactsModel::GroupRowType) {
+ const QString groupName = sourceIndex.data(Qt::DisplayRole).toString();
// If there is no cached value, create one
- if (!d->m_totalContactsCounts.contains(gmItem->groupName())) {
+ if (!d->m_totalContactsCounts.contains(groupName)) {
countContacts(sourceIndex);
}
- return d->m_totalContactsCounts.value(gmItem->groupName());
- } else if (item.canConvert<AccountsModelItem*>()) {
- AccountsModelItem *amItem = item.value<AccountsModelItem*>();
+ return d->m_totalContactsCounts.value(groupName);
+ } else if (rowType == ContactsModel::AccountRowType) {
+ const Tp::AccountPtr account = sourceIndex.data(ContactsModel::AccountRole).value<Tp::AccountPtr>();
+ if (account.isNull()) {
+ return 0;
+ }
// If there is no cached value, create one
- if (!d->m_totalContactsCounts.contains(amItem->data(ContactsModel::IdRole).toString())) {
+ if (!d->m_totalContactsCounts.contains(account->uniqueIdentifier())) {
countContacts(sourceIndex);
}
- return d->m_totalContactsCounts.value(amItem->data(ContactsModel::IdRole).toString());
+ return d->m_totalContactsCounts.value(account->uniqueIdentifier());
}
}
// In all other cases just delegate it to the source model
- return sourceModel()->data(mapToSource(index), role);
+ return sourceModel()->data(sourceIndex, role);
}
void ContactsFilterModel::setSourceModel(QAbstractItemModel *sourceModel)
{
// Disconnect the previous source model
- disconnect(this->sourceModel(),
- SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this,
- SLOT(countContacts(QModelIndex)));
+ disconnect(this->sourceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+ this, SLOT(countContacts(QModelIndex)));
+ disconnect(this->sourceModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
+ this, SLOT(countContacts(QModelIndex)));
+ disconnect(this->sourceModel(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
+ this, SLOT(countContacts(QModelIndex)));
+ disconnect(this->sourceModel(), SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
+ this, SLOT(countContacts(QModelIndex)));
// Clear all cached values as they aren't valid anymore because the source model changed.
d->m_onlineContactsCounts.clear();
@@ -463,10 +472,14 @@ void ContactsFilterModel::setSourceModel(QAbstractItemModel *sourceModel)
QSortFilterProxyModel::setSourceModel(sourceModel);
// Connect the new source model
- connect(this->sourceModel(),
- SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this,
- SLOT(countContacts(QModelIndex)));
+ connect(this->sourceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+ this, SLOT(countContacts(QModelIndex)));
+ connect(this->sourceModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
+ this, SLOT(countContacts(QModelIndex)));
+ connect(this->sourceModel(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
+ this, SLOT(countContacts(QModelIndex)));
+ connect(this->sourceModel(), SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
+ this, SLOT(countContacts(QModelIndex)));
}
void ContactsFilterModel::invalidateFilter()
@@ -808,84 +821,57 @@ void ContactsFilterModel::setIdFilterMatchFlags(Qt::MatchFlags idFilterMatchFlag
}
}
-void ContactsFilterModel::countContacts(const QModelIndex &index) const
+void ContactsFilterModel::countContacts(const QModelIndex &sourceParent) const
{
- QVariant item = index.data(ContactsModel::ItemRole);
- if (item.canConvert<GroupsModelItem*>()) {
- GroupsModelItem *gmItem = item.value<GroupsModelItem*>();
-
- // Count the online contacts
- int tmpCounter = 0;
-
- for (int i = 0; i < gmItem->size(); ++i) {
- ProxyTreeNode* proxyNode = qobject_cast<ProxyTreeNode*>(gmItem->childAt(i));
- Q_ASSERT(proxyNode);
-
- // We want all online contacts that are accepted by the filter
- if (filterAcceptsRow(gmItem->indexOf(gmItem->childAt(i)), index)
- && proxyNode->data(ContactsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeOffline
- && proxyNode->data(ContactsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeUnknown) {
- tmpCounter++;
- }
- }
-
- d->m_onlineContactsCounts.insert(gmItem->groupName(), tmpCounter);
+ QString key;
- // Now count the total contacts accepted by the filter (but ignore presence filter).
- // Save the presenceTypeFilterFlags to reapply them later, because we need to disable
- // presence filtering to get the right numbers
- PresenceTypeFilterFlags saved = presenceTypeFilterFlags();
- d->presenceTypeFilterFlags = ContactsFilterModel::DoNotFilterByPresence;
-
- tmpCounter = 0;
- for (int i = 0; i < gmItem->size(); ++i) {
- if (filterAcceptsRow(gmItem->indexOf(gmItem->childAt(i)), index)) {
- tmpCounter++;
- }
+ ContactsModel::RowType rowType = static_cast<ContactsModel::RowType>(sourceParent.data(ContactsModel::TypeRole).toInt());
+ if (rowType == ContactsModel::GroupRowType) {
+ key = sourceParent.data(Qt::DisplayRole).toString();
+ } else if (rowType == ContactsModel::AccountRowType) {
+ Tp::AccountPtr account = sourceParent.data(ContactsModel::AccountRole).value<Tp::AccountPtr>();
+ if (account.isNull()) {
+ return;
}
+ key = account->uniqueIdentifier();
+ } else {
+ return;
+ }
- // Restore the saved presenceTypeFilterFlags
- d->presenceTypeFilterFlags = saved;
-
- d->m_totalContactsCounts.insert(gmItem->groupName(), tmpCounter);
- } else if (item.canConvert<AccountsModelItem*>()) {
- AccountsModelItem *amItem = item.value<AccountsModelItem*>();
-
- // Count the online contacts
- int tmpCounter = 0;
+ // Count the online contacts
+ int tmpCounter = 0;
- for (int i = 0; i < amItem->size(); ++i) {
- ContactModelItem* contactNode = qobject_cast<ContactModelItem*>(amItem->childAt(i));
- Q_ASSERT(contactNode);
+ for (int i = 0; i < sourceModel()->rowCount(sourceParent); ++i) {
+ QModelIndex child = sourceModel()->index(i, 0, sourceParent);
- // We want all online contacts that are accepted by the filter
- if (filterAcceptsRow(amItem->indexOf(amItem->childAt(i)), index)
- && contactNode->data(ContactsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeOffline
- && contactNode->data(ContactsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeUnknown) {
- tmpCounter++;
- }
+ // We want all online contacts that are accepted by the filter
+ if (filterAcceptsRow(child.row(), sourceParent)
+ && child.data(ContactsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeOffline
+ && child.data(ContactsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeUnknown) {
+ tmpCounter++;
}
+ }
- d->m_onlineContactsCounts.insert(amItem->data(ContactsModel::IdRole).toString(), tmpCounter);
+ d->m_onlineContactsCounts.insert(key, tmpCounter);
- // Now count the total contacts accepted by the filter (but ignore presence filter).
- // Save the presenceTypeFilterFlags to reapply them later, because we need to disable
- // presence filtering to get the right numbers
- PresenceTypeFilterFlags saved = presenceTypeFilterFlags();
- d->presenceTypeFilterFlags = ContactsFilterModel::DoNotFilterByPresence;
+ // Now count the total contacts accepted by the filter (but ignore presence filter).
+ // Save the presenceTypeFilterFlags to reapply them later, because we need to disable
+ // presence filtering to get the right numbers
+ PresenceTypeFilterFlags saved = presenceTypeFilterFlags();
+ d->presenceTypeFilterFlags = ContactsFilterModel::DoNotFilterByPresence;
- tmpCounter = 0;
- for (int i = 0; i < amItem->size(); ++i) {
- if (filterAcceptsRow(amItem->indexOf(amItem->childAt(i)), index)) {
- tmpCounter++;
- }
+ tmpCounter = 0;
+ for (int i = 0; i < sourceModel()->rowCount(sourceParent); ++i) {
+ QModelIndex child = sourceModel()->index(i, 0, sourceParent);
+ if (filterAcceptsRow(child.row(), sourceParent)) {
+ tmpCounter++;
}
+ }
- // Restore the saved presenceTypeFilterFlags
- d->presenceTypeFilterFlags = saved;
+ // Restore the saved presenceTypeFilterFlags
+ d->presenceTypeFilterFlags = saved;
- d->m_totalContactsCounts.insert(amItem->data(ContactsModel::IdRole).toString(), tmpCounter);
- }
+ d->m_totalContactsCounts.insert(key, tmpCounter);
}
bool ContactsFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list