[SCM] ktp-accounts-kcm packaging branch, master, updated. debian/15.12.1-1-1157-gc4589c5

Maximiliano Curia maxy at moszumanska.debian.org
Fri May 27 23:59:01 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-accounts-kcm.git;a=commitdiff;h=ce2f63c

The following commit has been merged in the master branch:
commit ce2f63c9c76699464d2e063b836fe61b6e62531c
Author: Thomas Richard <thomas9999 at gmail.com>
Date:   Fri Jan 21 09:33:30 2011 +0100

    Fix issues in the AccountsListModel (Thanks to Dominik Schmidt)
    It now fully complies to ModelTest
---
 src/accounts-list-model.cpp | 86 +++++++++++++++++++++++++++++++--------------
 src/accounts-list-model.h   |  4 ++-
 2 files changed, 63 insertions(+), 27 deletions(-)

diff --git a/src/accounts-list-model.cpp b/src/accounts-list-model.cpp
index b51e4f1..fdcee8a 100644
--- a/src/accounts-list-model.cpp
+++ b/src/accounts-list-model.cpp
@@ -31,8 +31,6 @@ AccountsListModel::AccountsListModel(QObject *parent)
  : QAbstractListModel(parent)
 {
     kDebug();
-
-    m_accounts.clear();
 }
 
 AccountsListModel::~AccountsListModel()
@@ -40,10 +38,10 @@ AccountsListModel::~AccountsListModel()
     kDebug();
 }
 
-int AccountsListModel::rowCount(const QModelIndex &index) const
+int AccountsListModel::rowCount(const QModelIndex & parent) const
 {
     // If the index is the root item, then return the row count.
-    if (index == QModelIndex()) {
+    if (parent == QModelIndex()) {
        return m_accounts.size();
     }
 
@@ -52,8 +50,21 @@ int AccountsListModel::rowCount(const QModelIndex &index) const
     return 0;
 }
 
+int AccountsListModel::columnCount(const QModelIndex& parent) const
+{
+    Q_UNUSED(parent);
+
+    // Column count is always 1
+    return 1;
+}
+
+
 QVariant AccountsListModel::data(const QModelIndex &index, int role) const
 {
+    if(!index.isValid()) {
+        return QVariant();
+    }
+
     QVariant data;
     Tp::AccountPtr account = m_accounts.at(index.row())->account();
 
@@ -96,16 +107,37 @@ QVariant AccountsListModel::data(const QModelIndex &index, int role) const
 
 bool AccountsListModel::setData(const QModelIndex &index, const QVariant &value, int role)
 {
-    kDebug();
+    if(!index.isValid()) {
+        return false;
+    }
+
     if(role == Qt::CheckStateRole) {
         m_accounts.at(index.row())->account()->setEnabled(value.toInt() == Qt::Checked);
         return true;
     }
+
     return false;
 }
 
+QModelIndex AccountsListModel::index(int row, int column, const QModelIndex& parent) const
+{
+    if(row < 0 || column < 0 || parent != QModelIndex()) {
+        return QModelIndex();
+    }
+
+    if(row < rowCount() && column < columnCount()) {
+        return createIndex(row, column);
+    }
+
+    return QModelIndex();
+}
+
+
 Qt::ItemFlags AccountsListModel::flags(const QModelIndex &index) const
 {
+    if(!index.isValid()) {
+        return QAbstractItemModel::flags(index);
+    }
     return QAbstractItemModel::flags(index) | Qt::ItemIsUserCheckable;
 }
 
@@ -126,22 +158,22 @@ void AccountsListModel::addAccount(const Tp::AccountPtr &account)
     }
 
     if (found) {
-       kWarning() << "Requested to add account"
-                  << account.data()
-                  << "to model, but it is already present. Doing nothing.";
-   } else {
-       kDebug() << "Account not already in model. Create new AccountItem from account:"
-                << account.data();
-
-       AccountItem *item = new AccountItem(account, this);
-
-       beginInsertRows(QModelIndex(), m_accounts.size(), m_accounts.size());
-       m_accounts.append(item);
-       endInsertRows();
-
-       connect(item, SIGNAL(removed()), SLOT(onAccountItemRemoved()));
-       connect(item, SIGNAL(updated()), SLOT(onAccountItemUpdated()));
-   }
+        kWarning() << "Requested to add account"
+                   << account.data()
+                   << "to model, but it is already present. Doing nothing.";
+    } else {
+        kDebug() << "Account not already in model. Create new AccountItem from account:"
+                 << account.data();
+
+        AccountItem *item = new AccountItem(account, this);
+
+        beginInsertRows(QModelIndex(), m_accounts.size(), m_accounts.size());
+        m_accounts.append(item);
+        endInsertRows();
+
+        connect(item, SIGNAL(removed()), SLOT(onAccountItemRemoved()));
+        connect(item, SIGNAL(updated()), SLOT(onAccountItemUpdated()));
+    }
 }
 
 void AccountsListModel::removeAccount(const QModelIndex &index)
@@ -172,7 +204,6 @@ AccountItem* AccountsListModel::itemForIndex(const QModelIndex &index)
     return accountItem;
 }
 
-
 void AccountsListModel::onAccountItemRemoved()
 {
     kDebug();
@@ -185,11 +216,14 @@ void AccountsListModel::onAccountItemRemoved()
         return;
     }
 
-    beginRemoveRows(QModelIndex(), m_accounts.indexOf(item),
-                    m_accounts.lastIndexOf(item));
+    // We can be pretty sure that there is only one reference to a specific AccountItem in the list
+    // If we screw up here, the styling delegate will screw up even more
+    beginRemoveRows(QModelIndex(), m_accounts.indexOf(item), m_accounts.indexOf(item));
     m_accounts.removeAll(item);
     endRemoveRows();
 
+    // FIXME: Workaround until the KWidgetItemDelegate gets fixed (probably KDE 4.7)
+    reset();
     delete item;
 }
 
@@ -211,9 +245,9 @@ void AccountsListModel::onAccountItemUpdated()
 
 void AccountsListModel::onTitleForCustomPages(QString mandatoryPage, QList<QString> optionalPage)
 {
-	kDebug();
+    kDebug();
 
-	emit setTitleForCustomPages(mandatoryPage, optionalPage);
+    emit setTitleForCustomPages(mandatoryPage, optionalPage);
 }
 
 
diff --git a/src/accounts-list-model.h b/src/accounts-list-model.h
index fa67492..cc81c1e 100644
--- a/src/accounts-list-model.h
+++ b/src/accounts-list-model.h
@@ -41,10 +41,12 @@ public:
 
     explicit AccountsListModel(QObject *parent = 0);
     virtual ~AccountsListModel();
-    virtual int rowCount(const QModelIndex &index) const;
+    virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
+    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
     virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
     virtual Qt::ItemFlags flags(const QModelIndex &index) const;
     virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
+    virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
     void addAccount(const Tp::AccountPtr &account);
     void removeAccount(const QModelIndex &index);
     AccountItem* itemForIndex(const QModelIndex &index);

-- 
ktp-accounts-kcm packaging



More information about the pkg-kde-commits mailing list