~ubuntu-branches/ubuntu/quantal/lightdm-kde/quantal

« back to all changes in this revision

Viewing changes to greeter/extrarowproxymodel.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-04-18 15:20:54 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120418152054-ahcwjazzqvda1u5n
Tags: 0.1.0-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include <extrarowproxymodel.h>
20
20
 
21
21
#include <KDebug>
 
22
#include <QAbstractItemModel>
22
23
 
23
24
ExtraRowProxyModel::ExtraRowProxyModel(QObject* parent)
24
25
: QAbstractListModel(parent)
25
 
, m_model(0)
26
26
{}
27
27
 
28
28
int ExtraRowProxyModel::appendRow()
29
29
{
30
 
    Row row(rowCount());
 
30
    Row row;
31
31
    m_rows.append(row);
32
32
    return m_rows.count() - 1;
33
33
}
45
45
 
46
46
void ExtraRowProxyModel::setSourceModel(QAbstractItemModel* model)
47
47
{
48
 
    m_model = model;
 
48
    if (! m_model.isNull()) {
 
49
        disconnect(m_model.data(), SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(onSourceRowsInserted(QModelIndex,int,int)));
 
50
        disconnect(m_model.data(), SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(onSourceRowsRemoved(QModelIndex,int,int)));
 
51
        disconnect(m_model.data(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(onSourceDataChanged(QModelIndex,QModelIndex)));
 
52
    }
 
53
 
 
54
    m_model = QWeakPointer<QAbstractItemModel>(model);
49
55
    reset();
50
 
    setRoleNames(m_model->roleNames());
 
56
    setRoleNames(m_model.data()->roleNames());
 
57
 
 
58
    connect(m_model.data(), SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(onSourceRowsInserted(QModelIndex,int,int)));
 
59
    connect(m_model.data(), SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(onSourceRowsRemoved(QModelIndex,int,int)));
 
60
    connect(m_model.data(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(onSourceDataChanged(QModelIndex,QModelIndex)));
51
61
}
52
62
 
53
63
int ExtraRowProxyModel::rowCount(const QModelIndex &) const
54
64
{
55
 
    return m_model->rowCount() + m_rows.count();
 
65
    if (m_model.isNull()) {
 
66
        return m_rows.count();
 
67
    } else {
 
68
        return m_model.data()->rowCount() + m_rows.count();
 
69
    }
 
70
 
56
71
}
57
72
 
58
73
QVariant ExtraRowProxyModel::data(const QModelIndex &index, int role) const
59
74
{
60
 
    int count = m_model->rowCount();
61
 
    if (index.row() < count) {
62
 
        return m_model->data(index, role);
 
75
    int count = 0;
 
76
    if (!m_model.isNull()) {
 
77
        count = m_model.data()->rowCount();
 
78
        if (index.row() < count) {
 
79
            return m_model.data()->data(index, role);
 
80
        }
63
81
    }
64
82
 
65
83
    int extraRow = index.row() - count;
67
85
        return QVariant();
68
86
    }
69
87
 
70
 
    const Item& item = m_rows[extraRow].at(index.column());
 
88
    const Item& item = m_rows[extraRow][index.column()];
71
89
    return item.value(role);
72
90
}
 
91
 
 
92
void ExtraRowProxyModel::onSourceRowsInserted(const QModelIndex &parent, int start, int end)
 
93
{
 
94
    Q_UNUSED(parent);
 
95
    beginInsertRows(QModelIndex(), start, end);
 
96
    endInsertRows();
 
97
}
 
98
 
 
99
void ExtraRowProxyModel::onSourceRowsRemoved(const QModelIndex &parent, int start, int end)
 
100
{
 
101
    Q_UNUSED(parent);
 
102
    beginRemoveRows(QModelIndex(), start, end);
 
103
    endRemoveRows();
 
104
}
 
105
 
 
106
void ExtraRowProxyModel::onSourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
 
107
{
 
108
    dataChanged(createIndex(topLeft.row(), 0)   , createIndex(bottomRight.row(), 0));
 
109
}
 
110
 
 
111