[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:09 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=08aac8a

The following commit has been merged in the master branch:
commit 08aac8a0ba7c0d7b193d3303b8551dfd12f8f05c
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Thu Jan 3 23:54:52 2013 +0000

    Allow empty groups in AbstractGroupingProxyModel
    
    AbstractGroupingProxyModel cannot show empty groups as it does not know
    about them.
    
    Add two public members forceGroup, unforceGroup, which allow empty groups
    to be added to the model. Group will only be removed when empty AND the group
    is not enforced.
    
    Alter AccountsTreeProxyModel to force groups to be shown for all accounts
---
 KTp/Models/abstract-grouping-proxy-model.cpp | 64 +++++++++++++++++++++++++---
 KTp/Models/abstract-grouping-proxy-model.h   |  7 ++-
 KTp/Models/accounts-tree-proxy-model.cpp     | 20 +++++++++
 KTp/Models/accounts-tree-proxy-model.h       |  5 +++
 4 files changed, 88 insertions(+), 8 deletions(-)

diff --git a/KTp/Models/abstract-grouping-proxy-model.cpp b/KTp/Models/abstract-grouping-proxy-model.cpp
index ca9c22d..f3c3356 100644
--- a/KTp/Models/abstract-grouping-proxy-model.cpp
+++ b/KTp/Models/abstract-grouping-proxy-model.cpp
@@ -36,7 +36,7 @@ public:
 
     //item -> groups
     QMultiHash<QPersistentModelIndex, ProxyNode*> proxyMap;
-    QHash<QString, QStandardItem*> groupMap;
+    QHash<QString, GroupNode*> groupMap;
 };
 
 class ProxyNode : public QStandardItem
@@ -55,8 +55,11 @@ public:
     GroupNode(const QString &groupId);
     QString group() const;
     virtual QVariant data(int role) const;
+    bool forced() const;
+    void setForced(bool forced);
 private:
     const QString m_groupId;
+    bool m_forced;
 };
 
 
@@ -90,7 +93,8 @@ QString ProxyNode::group() const
 
 GroupNode::GroupNode(const QString &groupId):
     QStandardItem(),
-    m_groupId(groupId)
+    m_groupId(groupId),
+    m_forced(false)
 {
 }
 
@@ -105,6 +109,15 @@ QVariant GroupNode::data(int role) const
     return proxyModel->dataForGroup(m_groupId, role);
 }
 
+void GroupNode::setForced(bool forced) {
+    m_forced = forced;
+}
+
+bool GroupNode::forced() const
+{
+    return m_forced;
+}
+
 
 KTp::AbstractGroupingProxyModel::AbstractGroupingProxyModel(QAbstractItemModel *source):
     QStandardItemModel(source),
@@ -112,7 +125,7 @@ KTp::AbstractGroupingProxyModel::AbstractGroupingProxyModel(QAbstractItemModel *
 {
     d->source = source;
 
-    QTimer::singleShot(0, this, SLOT(onModelReset()));
+    QTimer::singleShot(0, this, SLOT(onLoad()));
     connect(d->source, SIGNAL(modelReset()), SLOT(onModelReset()));
     connect(d->source, SIGNAL(rowsInserted(QModelIndex, int,int)), SLOT(onRowsInserted(QModelIndex,int,int)));
     connect(d->source, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), SLOT(onRowsRemoved(QModelIndex,int,int)));
@@ -124,6 +137,31 @@ KTp::AbstractGroupingProxyModel::~AbstractGroupingProxyModel()
     delete d;
 }
 
+
+void KTp::AbstractGroupingProxyModel::forceGroup(const QString &group)
+{
+    GroupNode* groupNode = itemForGroup(group);
+    groupNode->setForced(true);
+}
+
+void KTp::AbstractGroupingProxyModel::unforceGroup(const QString &group)
+{
+    GroupNode* groupNode = d->groupMap[group];
+    if (!groupNode) {
+        return;
+    }
+
+    //mark that this group can be removed when it's empty
+    groupNode->setForced(false);
+
+    //if group is already empty remove it
+    if (groupNode->rowCount() == 0) {
+        takeRow(groupNode->row());
+        d->groupMap.remove(groupNode->group());
+    }
+}
+
+
 /* Called when source items inserts a row
  *
  * For each new row, create a proxyNode.
@@ -168,10 +206,14 @@ void KTp::AbstractGroupingProxyModel::removeProxyNodes(const QModelIndex &source
         d->proxyMap.remove(sourceIndex, proxy);
 
         //if the parent item to this proxy node is now empty, and is a top level item
-        if (parentItem->rowCount() == 0 && parentItem->parent() == 0) {
+        if (parentItem->rowCount() == 0 && parentItem->parent() == 0 ) {
             GroupNode* groupNode = dynamic_cast<GroupNode*>(parentItem);
-            takeRow(groupNode->row());
-            d->groupMap.remove(groupNode->group());
+
+            //do not delete forced groups
+            if (groupNode->forced() == false) {
+                takeRow(groupNode->row());
+                d->groupMap.remove(groupNode->group());
+            }
         }
     }
 }
@@ -254,6 +296,14 @@ void KTp::AbstractGroupingProxyModel::onDataChanged(const QModelIndex &sourceTop
     }
 }
 
+
+void KTp::AbstractGroupingProxyModel::onLoad()
+{
+    if (d->source->rowCount() > 0) {
+        onRowsInserted(QModelIndex(), 0, d->source->rowCount()-1);
+    }
+}
+
 /* Called when source model gets reset
  * Delete all local caches/maps and wipe the current QStandardItemModel
  */
@@ -271,7 +321,7 @@ void KTp::AbstractGroupingProxyModel::onModelReset()
     }
 }
 
-QStandardItem* KTp::AbstractGroupingProxyModel::itemForGroup(const QString &group)
+GroupNode* KTp::AbstractGroupingProxyModel::itemForGroup(const QString &group)
 {
     if (d->groupMap.contains(group)) {
         return d->groupMap[group];
diff --git a/KTp/Models/abstract-grouping-proxy-model.h b/KTp/Models/abstract-grouping-proxy-model.h
index c934443..b013eeb 100644
--- a/KTp/Models/abstract-grouping-proxy-model.h
+++ b/KTp/Models/abstract-grouping-proxy-model.h
@@ -39,6 +39,10 @@ public:
     explicit AbstractGroupingProxyModel(QAbstractItemModel *source);
     virtual ~AbstractGroupingProxyModel();
 
+    void forceGroup(const QString &group);
+    void unforceGroup(const QString &group);
+
+
 //protected:
     /** Return a list of all groups this items belongs to. Subclasses must override this*/
     virtual QSet<QString> groupsForIndex(const QModelIndex &sourceIndex) const = 0;
@@ -50,6 +54,7 @@ private Q_SLOTS:
     void onRowsRemoved(const QModelIndex &sourceParent, int start, int end);
     void onDataChanged(const QModelIndex &sourceTopLeft, const QModelIndex &sourceBottomRight);
     void onModelReset();
+    void onLoad();
 
 private:
     Q_DISABLE_COPY(AbstractGroupingProxyModel)
@@ -64,7 +69,7 @@ private:
 
 
     /** Returns the standard Item belonging to a particular group name. Creating one if needed*/
-    QStandardItem *itemForGroup(const QString &group);
+    GroupNode *itemForGroup(const QString &group);
 };
 
 }
diff --git a/KTp/Models/accounts-tree-proxy-model.cpp b/KTp/Models/accounts-tree-proxy-model.cpp
index 15651b3..ead34f6 100644
--- a/KTp/Models/accounts-tree-proxy-model.cpp
+++ b/KTp/Models/accounts-tree-proxy-model.cpp
@@ -22,6 +22,7 @@
 
 #include <TelepathyQt/Account>
 #include <TelepathyQt/AccountManager>
+#include <TelepathyQt/AccountSet>
 
 #include <KIcon>
 
@@ -30,6 +31,7 @@ class KTp::AccountsTreeProxyModel::Private
 {
 public:
     Tp::AccountManagerPtr accountManager;
+    Tp::AccountSetPtr accountSet;
 };
 
 KTp::AccountsTreeProxyModel::AccountsTreeProxyModel(QAbstractItemModel *sourceModel, const Tp::AccountManagerPtr &accountManager) :
@@ -37,6 +39,14 @@ KTp::AccountsTreeProxyModel::AccountsTreeProxyModel(QAbstractItemModel *sourceMo
     d(new Private())
 {
     d->accountManager = accountManager;
+
+    d->accountSet = accountManager->enabledAccounts();
+    connect(d->accountSet.data(), SIGNAL(accountAdded(Tp::AccountPtr)), SLOT(onAccountAdded(Tp::AccountPtr)));
+    connect(d->accountSet.data(), SIGNAL(accountRemoved(Tp::AccountPtr)), SLOT(onAccountRemoved(Tp::AccountPtr)));
+    Q_FOREACH(const Tp::AccountPtr &account, d->accountSet->accounts()) {
+        onAccountAdded(account);
+    }
+
 }
 
 QSet<QString> KTp::AccountsTreeProxyModel::groupsForIndex(const QModelIndex &sourceIndex) const
@@ -86,3 +96,13 @@ QVariant KTp::AccountsTreeProxyModel::dataForGroup(const QString &group, int rol
 
     return QVariant();
 }
+
+void KTp::AccountsTreeProxyModel::onAccountAdded(const Tp::AccountPtr &account)
+{
+    forceGroup(account->objectPath());
+}
+
+void KTp::AccountsTreeProxyModel::onAccountRemoved(const Tp::AccountPtr &account)
+{
+    unforceGroup(account->objectPath());
+}
diff --git a/KTp/Models/accounts-tree-proxy-model.h b/KTp/Models/accounts-tree-proxy-model.h
index ff19de1..9f0eec3 100644
--- a/KTp/Models/accounts-tree-proxy-model.h
+++ b/KTp/Models/accounts-tree-proxy-model.h
@@ -35,6 +35,11 @@ public:
 
     virtual QSet<QString> groupsForIndex(const QModelIndex &sourceIndex) const;
     virtual QVariant dataForGroup(const QString &group, int role) const;
+
+private Q_SLOTS:
+    void onAccountAdded(const Tp::AccountPtr &account);
+    void onAccountRemoved(const Tp::AccountPtr &account);
+
 private:
     class Private;
     Private *d;

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list