[SCM] ktp-contact-applet packaging branch, master, updated. debian/15.12.1-1-966-gde83ac5

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:12:56 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-desktop-applets.git;a=commitdiff;h=8eb5d48

The following commit has been merged in the master branch:
commit 8eb5d48b009deef46cf397b481cdb148fb9af63e
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Thu Feb 2 20:26:15 2012 +0000

    Add flat model proxy
---
 src/flat-model-proxy.cpp | 182 +++++++++++++++++++++++++++++++++++++++++++++++
 src/flat-model-proxy.h   |  64 +++++++++++++++++
 2 files changed, 246 insertions(+)

diff --git a/src/flat-model-proxy.cpp b/src/flat-model-proxy.cpp
new file mode 100644
index 0000000..19312c2
--- /dev/null
+++ b/src/flat-model-proxy.cpp
@@ -0,0 +1,182 @@
+/*
+ * This file is part of TelepathyQt4Yell Models
+ *
+ * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "flat-model-proxy.h"
+
+#include <QDebug>
+
+struct FlatModelProxy::Private
+{
+    int offsetOf(const FlatModelProxy *model, int index) const;
+};
+
+int FlatModelProxy::Private::offsetOf(const FlatModelProxy *model, int index) const
+{
+    int offset = 0;
+    for (int i = 0; i < index; i++) {
+        offset += model->sourceModel()->rowCount(model->sourceModel()->index(i, 0, QModelIndex()));
+    }
+    return offset;
+}
+
+FlatModelProxy::FlatModelProxy(QAbstractItemModel *source)
+    : QAbstractProxyModel(source),
+      mPriv(new Private())
+{
+    setSourceModel(source);
+
+    connect(source,
+            SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
+            SLOT(onRowsAboutToBeInserted(QModelIndex,int,int)));
+    connect(source,
+            SIGNAL(rowsInserted(QModelIndex,int,int)),
+            SLOT(onRowsInserted(QModelIndex,int,int)));
+    connect(source,
+            SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
+            SLOT(onRowsAboutToBeRemoved(QModelIndex,int,int)));
+    connect(source,
+            SIGNAL(rowsRemoved(QModelIndex,int,int)),
+            SLOT(onRowsRemoved(QModelIndex,int,int)));
+    connect(source,
+            SIGNAL(rowsInserted(QModelIndex,int,int)),
+            SIGNAL(rowCountChanged()));
+    connect(source,
+            SIGNAL(rowsRemoved(QModelIndex,int,int)),
+            SIGNAL(rowCountChanged()));
+    connect(source,
+            SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+            SLOT(onDataChanged(QModelIndex,QModelIndex)));
+}
+
+FlatModelProxy::~FlatModelProxy()
+{
+    delete mPriv;
+}
+
+QModelIndex FlatModelProxy::mapFromSource(const QModelIndex &index) const
+{
+    if (!index.isValid()) {
+        return QModelIndex();
+    }
+
+    QModelIndex parent = index.parent();
+
+    if (!parent.isValid()) {
+        return QModelIndex();
+    }
+
+    return createIndex(mPriv->offsetOf(this, parent.row()) + index.row(), index.column(), parent.row());
+}
+
+QModelIndex FlatModelProxy::mapToSource(const QModelIndex &index) const
+{
+    int parentRow = index.internalId();
+    QModelIndex parent = sourceModel()->index(parentRow, 0, QModelIndex());
+    int row = index.row() - mPriv->offsetOf(this, parent.row());
+    return sourceModel()->index(row, index.column(), parent);
+}
+
+QModelIndex FlatModelProxy::index(int row, int column, const QModelIndex &parent) const
+{
+    int count = 0;
+    for (int i = 0; i < sourceModel()->rowCount(QModelIndex()); i++) {
+        QModelIndex sourceIndex = sourceModel()->index(i, 0, QModelIndex());
+        count += sourceModel()->rowCount(sourceIndex);
+        if (row < count) {
+            return createIndex(row, column, i);
+        }
+    }
+
+    return QModelIndex();
+}
+
+QModelIndex FlatModelProxy::parent(const QModelIndex &index) const
+{
+    return QModelIndex();
+}
+
+int FlatModelProxy::columnCount(const QModelIndex &parent) const
+{
+    return 1;
+}
+
+int FlatModelProxy::rowCount() const
+{
+    return rowCount(QModelIndex());
+}
+
+int FlatModelProxy::rowCount(const QModelIndex &parent) const
+{
+    qDebug() << "row count is " << mPriv->offsetOf(this, sourceModel()->rowCount(QModelIndex()));
+    return mPriv->offsetOf(this, sourceModel()->rowCount(QModelIndex()));
+}
+
+void FlatModelProxy::onRowsAboutToBeInserted(const QModelIndex &index, int first, int last)
+{
+    if (index.isValid()) {
+        int offset = mPriv->offsetOf(this, index.row());
+        int firstIndex = offset + first;
+        int lastIndex = offset + last;
+
+        beginInsertRows(QModelIndex(), firstIndex, lastIndex);
+    }
+}
+
+void FlatModelProxy::onRowsAboutToBeRemoved(const QModelIndex &index, int first, int last)
+{
+    if (index.isValid()) {
+        int offset = mPriv->offsetOf(this, index.row());
+        int firstIndex = offset + first;
+        int lastIndex = offset + last;
+
+        beginRemoveRows(QModelIndex(), firstIndex, lastIndex);
+    }
+}
+
+void FlatModelProxy::onRowsInserted(const QModelIndex &index, int first, int last)
+{
+    if (index.isValid()) {
+        endInsertRows();
+    }
+}
+
+void FlatModelProxy::onRowsRemoved(const QModelIndex &index, int first, int last)
+{
+    if (index.isValid()) {
+        endRemoveRows();
+    }
+}
+
+void FlatModelProxy::onDataChanged(const QModelIndex &first, const QModelIndex &last)
+{
+    if (!first.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);
+    }
+}
diff --git a/src/flat-model-proxy.h b/src/flat-model-proxy.h
new file mode 100644
index 0000000..b592f48
--- /dev/null
+++ b/src/flat-model-proxy.h
@@ -0,0 +1,64 @@
+/*
+ * This file is part of TelepathyQt4Yell Models
+ *
+ * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _TelepathyQt4Yell_Models_flat_model_proxy_h_HEADER_GUARD_
+#define _TelepathyQt4Yell_Models_flat_model_proxy_h_HEADER_GUARD_
+
+
+#include <QAbstractProxyModel>
+
+class FlatModelProxy : public QAbstractProxyModel
+{
+    Q_OBJECT
+    Q_DISABLE_COPY(FlatModelProxy)
+    Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
+
+public:
+    FlatModelProxy(QAbstractItemModel *source);
+    virtual ~FlatModelProxy();
+
+    virtual QModelIndex mapFromSource(const QModelIndex &index) const;
+    virtual QModelIndex mapToSource(const QModelIndex &index) const;
+    virtual QModelIndex index(int row, int column, const QModelIndex &parent) const;
+    virtual QModelIndex parent(const QModelIndex &index) const;
+    virtual int rowCount(const QModelIndex &parent) const;
+    virtual int columnCount(const QModelIndex &parent) const;
+
+    int rowCount() const;
+
+Q_SIGNALS:
+    void rowCountChanged();
+
+private Q_SLOTS:
+    void onRowsAboutToBeInserted(const QModelIndex &index, int first, int last);
+    void onRowsInserted(const QModelIndex &index, int first, int last);
+    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);
+
+private:
+    struct Private;
+    friend struct Private;
+    Private *mPriv;
+};
+
+
+
+#endif // _TelepathyQt4Yell_Models_flat_model_proxy_h_HEADER_GUARD_

-- 
ktp-contact-applet packaging



More information about the pkg-kde-commits mailing list