diff options
author | Mateu Batle <mateu.batle@collabora.co.uk> | 2011-06-30 13:02:26 -0500 |
---|---|---|
committer | Mateu Batle <mateu.batle@collabora.co.uk> | 2011-06-30 13:02:26 -0500 |
commit | 626deaa49eb8733e8aab5900f369f1293b713ad2 (patch) | |
tree | 74f9f6d0494fdf3523729877f42e87f1159dcf0f | |
parent | 534239c4b62e791989bcf38e2dcc380ac521ca8d (diff) | |
parent | 6a972cf2ff2c44c869d7aac990a41dfa42da58d2 (diff) |
Merge branch 'optimization'.
Disabled hierarchical data changes by default, now they should be done explicitly.
Reviewed-by: Alvaro Soliverez <alvaro.soliverez@collabora.co.uk>
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/accounts-model-item.cpp | 57 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/accounts-model-item.h | 19 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/accounts-model.cpp | 29 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/accounts-model.h | 9 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/flat-model-proxy.cpp | 28 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/flat-model-proxy.h | 1 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/tree-node.cpp | 24 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/tree-node.h | 6 |
9 files changed, 138 insertions, 37 deletions
@@ -8,6 +8,8 @@ Fixes: * On connection invalidated, emit the connection status changed signal to make sure the account model item is updated * Add constructor to Tpy::ContactCapabilities so it can be really used * Revert returning UTF-8 for the contact alias and status messages strings + * WARNING: optimization of flat model proxy, dataChanged signal is not hierarchical anymore after we found out it was quite expensive. You need to do explicit hierarchical changes. + * Added hierarchicalDataChanged signal to Tpy::AccountsModel for explicit signalling of changes in account data affecting contacts data (expensive) telepathy-qt4-yell 0.1.6 (2011-06-06) ====================================== diff --git a/TelepathyQt4Yell/Models/accounts-model-item.cpp b/TelepathyQt4Yell/Models/accounts-model-item.cpp index 9e6d4d8..02dbcc6 100644 --- a/TelepathyQt4Yell/Models/accounts-model-item.cpp +++ b/TelepathyQt4Yell/Models/accounts-model-item.cpp @@ -70,54 +70,111 @@ AccountsModelItem::AccountsModelItem(const Tp::AccountPtr &account) SIGNAL(serviceNameChanged(QString)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(serviceNameChanged(QString)), + SIGNAL(serviceNameChanged(QString))); + connect(mPriv->mAccount.data(), + SIGNAL(profileChanged(Tp::ProfilePtr)), + SLOT(onChanged())); + connect(mPriv->mAccount.data(), SIGNAL(profileChanged(Tp::ProfilePtr)), + SIGNAL(profileChanged(Tp::ProfilePtr))); + connect(mPriv->mAccount.data(), + SIGNAL(displayNameChanged(QString)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(displayNameChanged(QString)), + SIGNAL(displayNameChanged(QString))); + connect(mPriv->mAccount.data(), SIGNAL(iconNameChanged(QString)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(iconNameChanged(QString)), + SIGNAL(iconNameChanged(QString))); + connect(mPriv->mAccount.data(), SIGNAL(nicknameChanged(QString)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(nicknameChanged(QString)), + SIGNAL(nicknameChanged(QString))); + connect(mPriv->mAccount.data(), SIGNAL(normalizedNameChanged(QString)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(normalizedNameChanged(QString)), + SIGNAL(normalizedNameChanged(QString))); + connect(mPriv->mAccount.data(), SIGNAL(validityChanged(bool)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(validityChanged(bool)), + SIGNAL(validityChanged(bool))); + connect(mPriv->mAccount.data(), SIGNAL(stateChanged(bool)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(stateChanged(bool)), + SIGNAL(stateChanged(bool))); + connect(mPriv->mAccount.data(), SIGNAL(capabilitiesChanged(Tp::ConnectionCapabilities)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(capabilitiesChanged(Tp::ConnectionCapabilities)), + SIGNAL(capabilitiesChanged(Tp::ConnectionCapabilities))); + connect(mPriv->mAccount.data(), SIGNAL(connectsAutomaticallyPropertyChanged(bool)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(connectsAutomaticallyPropertyChanged(bool)), + SIGNAL(connectsAutomaticallyPropertyChanged(bool))); + connect(mPriv->mAccount.data(), SIGNAL(parametersChanged(QVariantMap)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(parametersChanged(QVariantMap)), + SIGNAL(parametersChanged(QVariantMap))); + connect(mPriv->mAccount.data(), SIGNAL(changingPresence(bool)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(changingPresence(bool)), + SIGNAL(changingPresence(bool))); + connect(mPriv->mAccount.data(), SIGNAL(automaticPresenceChanged(Tp::Presence)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(automaticPresenceChanged(Tp::Presence)), + SIGNAL(automaticPresenceChanged(Tp::Presence))); + connect(mPriv->mAccount.data(), SIGNAL(currentPresenceChanged(Tp::Presence)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(currentPresenceChanged(Tp::Presence)), + SIGNAL(currentPresenceChanged(Tp::Presence))); + connect(mPriv->mAccount.data(), SIGNAL(requestedPresenceChanged(Tp::Presence)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(requestedPresenceChanged(Tp::Presence)), + SIGNAL(requestedPresenceChanged(Tp::Presence))); + connect(mPriv->mAccount.data(), SIGNAL(onlinenessChanged(bool)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(onlinenessChanged(bool)), + SIGNAL(onlinenessChanged(bool))); + connect(mPriv->mAccount.data(), SIGNAL(avatarChanged(Tp::Avatar)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(avatarChanged(Tp::Avatar)), + SIGNAL(avatarChanged(Tp::Avatar))); + connect(mPriv->mAccount.data(), SIGNAL(onlinenessChanged(bool)), SLOT(onChanged())); connect(mPriv->mAccount.data(), + SIGNAL(onlinenessChanged(bool)), + SIGNAL(onlinenessChanged(bool))); + connect(mPriv->mAccount.data(), SIGNAL(connectionChanged(Tp::ConnectionPtr)), SLOT(onConnectionChanged(Tp::ConnectionPtr))); } diff --git a/TelepathyQt4Yell/Models/accounts-model-item.h b/TelepathyQt4Yell/Models/accounts-model-item.h index 7ce141d..f4cb162 100644 --- a/TelepathyQt4Yell/Models/accounts-model-item.h +++ b/TelepathyQt4Yell/Models/accounts-model-item.h @@ -27,6 +27,7 @@ #include <TelepathyQt4Yell/Models/TreeNode> +#include <TelepathyQt4/ConnectionCapabilities> #include <TelepathyQt4/Constants> #include <TelepathyQt4/Contact> #include <TelepathyQt4/Types> @@ -62,6 +63,24 @@ public Q_SLOTS: void onConnectionInvalidated(); Q_SIGNALS: + void serviceNameChanged(const QString &serviceName); + void profileChanged(const Tp::ProfilePtr &profile); + void displayNameChanged(const QString &displayName); + void iconNameChanged(const QString &iconName); + void nicknameChanged(const QString &nickname); + void normalizedNameChanged(const QString &normalizedName); + void validityChanged(bool validity); + void stateChanged(bool state); + void capabilitiesChanged(const Tp::ConnectionCapabilities &capabilities); + void connectsAutomaticallyPropertyChanged(bool connectsAutomatically); + void firstOnline(); + void parametersChanged(const QVariantMap ¶meters); + void changingPresence(bool value); + void automaticPresenceChanged(const Tp::Presence &automaticPresence); + void currentPresenceChanged(const Tp::Presence ¤tPresence); + void requestedPresenceChanged(const Tp::Presence &requestedPresence); + void onlinenessChanged(bool online); + void avatarChanged(const Tp::Avatar &avatar); void connectionStatusChanged(const QString &accountId, int status); private Q_SLOTS: diff --git a/TelepathyQt4Yell/Models/accounts-model.cpp b/TelepathyQt4Yell/Models/accounts-model.cpp index dcc0a7c..9de6961 100644 --- a/TelepathyQt4Yell/Models/accounts-model.cpp +++ b/TelepathyQt4Yell/Models/accounts-model.cpp @@ -56,23 +56,18 @@ AccountsModel::AccountsModel(const Tp::AccountManagerPtr &am, QObject *parent) { mPriv->mTree = new TreeNode; connect(mPriv->mTree, - SIGNAL(changed(TreeNode*)), - SLOT(onItemChanged(TreeNode*))); + SIGNAL(changed(Tpy::TreeNode*)), + SLOT(onItemChanged(Tpy::TreeNode*))); connect(mPriv->mTree, - SIGNAL(childrenAdded(TreeNode*,QList<TreeNode*>)), - SLOT(onItemsAdded(TreeNode*,QList<TreeNode*>))); + SIGNAL(childrenAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>)), + SLOT(onItemsAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>))); connect(mPriv->mTree, - SIGNAL(childrenRemoved(TreeNode*,int,int)), - SLOT(onItemsRemoved(TreeNode*,int,int))); + SIGNAL(childrenRemoved(Tpy::TreeNode*,int,int)), + SLOT(onItemsRemoved(Tpy::TreeNode*,int,int))); connect(mPriv->mAM.data(), SIGNAL(newAccount(Tp::AccountPtr)), SLOT(onNewAccount(Tp::AccountPtr))); - // load existing accounts - foreach (Tp::AccountPtr account, mPriv->mAM->allAccounts()) { - onNewAccount(account); - } - QHash<int, QByteArray> roles; roles[ItemRole] = "item"; roles[IdRole] = "id"; @@ -119,6 +114,8 @@ AccountsModel::AccountsModel(const Tp::AccountManagerPtr &am, QObject *parent) roles[UpgradeCallCapabilityRole] = "upgradeCall"; roles[FileTransferCapabilityRole] = "fileTransfer"; setRoleNames(roles); + + QTimer::singleShot(0, this, SLOT(onLoadAccounts())); } AccountsModel::~AccountsModel() @@ -127,6 +124,14 @@ AccountsModel::~AccountsModel() delete mPriv; } +void AccountsModel::onLoadAccounts() +{ + // load existing accounts + foreach (Tp::AccountPtr account, mPriv->mAM->allAccounts()) { + onNewAccount(account); + } +} + void AccountsModel::onNewAccount(const Tp::AccountPtr &account) { AccountsModelItem *item = new AccountsModelItem(account); @@ -149,7 +154,7 @@ void AccountsModel::onItemChanged(TreeNode *node) emit dataChanged(accountIndex, accountIndex); } -void AccountsModel::onItemsAdded(TreeNode *parent, const QList<TreeNode *> &nodes) +void AccountsModel::onItemsAdded(Tpy::TreeNode *parent, const QList<Tpy::TreeNode *> &nodes) { QModelIndex parentIndex = index(parent); int currentSize = rowCount(parentIndex); diff --git a/TelepathyQt4Yell/Models/accounts-model.h b/TelepathyQt4Yell/Models/accounts-model.h index 1020ee5..93658ba 100644 --- a/TelepathyQt4Yell/Models/accounts-model.h +++ b/TelepathyQt4Yell/Models/accounts-model.h @@ -122,12 +122,15 @@ public: Q_SIGNALS: void accountCountChanged(); void accountConnectionStatusChanged(const QString &accountId, int status); + // expensive operation, updates all children from parents first .. last + void hierarchicalDataChanged(const QModelIndex &first, const QModelIndex &last); protected Q_SLOTS: + void onLoadAccounts(); void onNewAccount(const Tp::AccountPtr &account); - void onItemChanged(TreeNode *node); - void onItemsAdded(TreeNode *parent, const QList<TreeNode *> &nodes); - void onItemsRemoved(TreeNode *parent, int first, int last); + void onItemChanged(Tpy::TreeNode *node); + virtual void onItemsAdded(Tpy::TreeNode *parent, const QList<Tpy::TreeNode *> &nodes); + void onItemsRemoved(Tpy::TreeNode *parent, int first, int last); private: struct Private; diff --git a/TelepathyQt4Yell/Models/flat-model-proxy.cpp b/TelepathyQt4Yell/Models/flat-model-proxy.cpp index e9cf5b6..dae0341 100644 --- a/TelepathyQt4Yell/Models/flat-model-proxy.cpp +++ b/TelepathyQt4Yell/Models/flat-model-proxy.cpp @@ -21,6 +21,7 @@ #include <TelepathyQt4Yell/Models/FlatModelProxy> #include "TelepathyQt4Yell/Models/_gen/flat-model-proxy.moc.hpp" +#include <TelepathyQt4Yell/Models/AccountsModel> namespace Tpy { @@ -66,6 +67,13 @@ FlatModelProxy::FlatModelProxy(QAbstractItemModel *source) connect(source, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(onDataChanged(QModelIndex,QModelIndex))); + + Tpy::AccountsModel *accountsModel = qobject_cast<Tpy::AccountsModel *> (source); + if (accountsModel) { + connect(accountsModel, + SIGNAL(hierarchicalDataChanged(QModelIndex,QModelIndex)), + SLOT(onHierarchicalDataChanged(QModelIndex,QModelIndex))); + } } FlatModelProxy::~FlatModelProxy() @@ -168,18 +176,24 @@ void FlatModelProxy::onRowsRemoved(const QModelIndex &index, int first, int last void FlatModelProxy::onDataChanged(const QModelIndex &first, const QModelIndex &last) { - if (!first.parent().isValid()) { + if (first.parent().isValid() && last.parent().isValid() && first.parent() == last.parent()) { + QModelIndex firstIndex = mapFromSource(first); + QModelIndex lastIndex = mapFromSource(last); + emit dataChanged(firstIndex, lastIndex); + } +} + +void FlatModelProxy::onHierarchicalDataChanged(const QModelIndex &first, const QModelIndex &last) +{ + if (!first.parent().isValid() && !last.parent().isValid()) { int firstOffset = mPriv->offsetOf(this, first.row()); int lastOffset = mPriv->offsetOf(this, last.row() + 1) - 1; - QModelIndex firstIndex = createIndex(firstOffset, 0, first.row()); QModelIndex lastIndex = createIndex(lastOffset, 0, last.row()); emit dataChanged(firstIndex, lastIndex); - } - else if (first.parent() == last.parent()) { - QModelIndex firstIndex = mapFromSource(first); - QModelIndex lastIndex = mapFromSource(last); - emit dataChanged(firstIndex, lastIndex); + } else { + // do not do normal dataChanged, since dataChanged it was already triggered separately + //onDataChanged(first, last); } } diff --git a/TelepathyQt4Yell/Models/flat-model-proxy.h b/TelepathyQt4Yell/Models/flat-model-proxy.h index 116bea0..e926d41 100644 --- a/TelepathyQt4Yell/Models/flat-model-proxy.h +++ b/TelepathyQt4Yell/Models/flat-model-proxy.h @@ -60,6 +60,7 @@ private Q_SLOTS: void onRowsAboutToBeRemoved(const QModelIndex &index, int first, int last); void onRowsRemoved(const QModelIndex &index, int first, int last); void onDataChanged(const QModelIndex &first, const QModelIndex &last); + void onHierarchicalDataChanged(const QModelIndex &fisrt, const QModelIndex &last); private: struct Private; diff --git a/TelepathyQt4Yell/Models/tree-node.cpp b/TelepathyQt4Yell/Models/tree-node.cpp index ae1ae2c..e805954 100644 --- a/TelepathyQt4Yell/Models/tree-node.cpp +++ b/TelepathyQt4Yell/Models/tree-node.cpp @@ -72,14 +72,14 @@ void TreeNode::addChild(TreeNode *node) // chain changed and removed signals connect(node, - SIGNAL(changed(TreeNode*)), - SIGNAL(changed(TreeNode*))); + SIGNAL(changed(Tpy::TreeNode*)), + SIGNAL(changed(Tpy::TreeNode*))); connect(node, - SIGNAL(childrenAdded(TreeNode*,QList<TreeNode*>)), - SIGNAL(childrenAdded(TreeNode*,QList<TreeNode*>))); + SIGNAL(childrenAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>)), + SIGNAL(childrenAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>))); connect(node, - SIGNAL(childrenRemoved(TreeNode*,int,int)), - SIGNAL(childrenRemoved(TreeNode*,int,int))); + SIGNAL(childrenRemoved(Tpy::TreeNode*,int,int)), + SIGNAL(childrenRemoved(Tpy::TreeNode*,int,int))); } int TreeNode::indexOf(TreeNode *node) const { @@ -109,17 +109,17 @@ void TreeNode::remove() { if (mPriv->mParent) { disconnect(this, - SIGNAL(changed(TreeNode*)), + SIGNAL(changed(Tpy::TreeNode*)), mPriv->mParent, - SIGNAL(changed(TreeNode*))); + SIGNAL(changed(Tpy::TreeNode*))); disconnect(this, - SIGNAL(childrenAdded(TreeNode*,QList<TreeNode*>)), + SIGNAL(childrenAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>)), mPriv->mParent, - SIGNAL(childrenAdded(TreeNode*,QList<TreeNode*>))); + SIGNAL(childrenAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>))); disconnect(this, - SIGNAL(childrenRemoved(TreeNode*,int,int)), + SIGNAL(childrenRemoved(Tpy::TreeNode*,int,int)), mPriv->mParent, - SIGNAL(childrenRemoved(TreeNode*,int,int))); + SIGNAL(childrenRemoved(Tpy::TreeNode*,int,int))); } deleteLater(); } diff --git a/TelepathyQt4Yell/Models/tree-node.h b/TelepathyQt4Yell/Models/tree-node.h index 4d00e7d..3f7d366 100644 --- a/TelepathyQt4Yell/Models/tree-node.h +++ b/TelepathyQt4Yell/Models/tree-node.h @@ -58,9 +58,9 @@ public: virtual void remove(); Q_SIGNALS: - void changed(TreeNode *); - void childrenAdded(TreeNode *parent, const QList<TreeNode *> &nodes); - void childrenRemoved(TreeNode *parent, int first, int last); + void changed(Tpy::TreeNode *); + void childrenAdded(Tpy::TreeNode *parent, const QList<Tpy::TreeNode *> &nodes); + void childrenRemoved(Tpy::TreeNode *parent, int first, int last); private: struct Private; |