40
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: ?Description
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <glxmodelwrapper.h>
|
|
19 |
#include <glxmodelparm.h>
|
|
20 |
#include <QDebug>
|
|
21 |
|
|
22 |
GlxModelWrapper::GlxModelWrapper(): mModel ( NULL),
|
|
23 |
mOriginalRole(Qt::DecorationRole),
|
|
24 |
mConvertRole(Qt::DecorationRole)
|
|
25 |
{
|
|
26 |
|
|
27 |
}
|
|
28 |
|
|
29 |
void GlxModelWrapper::setModel(QAbstractItemModel *model)
|
|
30 |
{
|
|
31 |
if(model && mModel != model)
|
|
32 |
{
|
|
33 |
disConnectFromModel();
|
|
34 |
mModel = model;
|
|
35 |
connectToModel();
|
|
36 |
resetTheModel();
|
|
37 |
}
|
|
38 |
}
|
|
39 |
|
|
40 |
|
|
41 |
void GlxModelWrapper::setRoles(int convertrole, int originalrole)
|
|
42 |
{
|
|
43 |
mConvertRole = convertrole;
|
|
44 |
mOriginalRole = originalrole;
|
|
45 |
}
|
|
46 |
|
|
47 |
void GlxModelWrapper::scrollingStarted()
|
|
48 |
{
|
|
49 |
|
|
50 |
}
|
|
51 |
|
|
52 |
void GlxModelWrapper::scrollingEnded()
|
|
53 |
{
|
|
54 |
|
|
55 |
}
|
|
56 |
|
|
57 |
void GlxModelWrapper::connectToModel()
|
|
58 |
{
|
|
59 |
connect(mModel, SIGNAL(destroyed()),this, SLOT(modelDestroyed()));
|
|
60 |
connect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(dataChangedinModel(QModelIndex,QModelIndex)));
|
|
61 |
connect(mModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),this,SLOT(rowsAboutToBeInserted(QModelIndex,int,int)));
|
|
62 |
connect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)),this, SLOT(rowsInserted(QModelIndex,int,int)));
|
|
63 |
connect(mModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),this,SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)));
|
|
64 |
connect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),this,SLOT(rowsRemoved(QModelIndex,int,int)));
|
|
65 |
}
|
|
66 |
|
|
67 |
void GlxModelWrapper::disConnectFromModel()
|
|
68 |
{
|
|
69 |
if(mModel)
|
|
70 |
{
|
|
71 |
disconnect(mModel, SIGNAL(destroyed()),this, SLOT(modelDestroyed()));
|
|
72 |
disconnect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(dataChangedinModel(QModelIndex,QModelIndex)));
|
|
73 |
disconnect(mModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),this,SLOT(rowsAboutToBeInserted(QModelIndex,int,int)));
|
|
74 |
disconnect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)),this, SLOT(rowsInserted(QModelIndex,int,int)));
|
|
75 |
disconnect(mModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),this,SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)));
|
|
76 |
disconnect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),this,SLOT(rowsRemoved(QModelIndex,int,int)));
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
GlxModelWrapper::~GlxModelWrapper()
|
|
82 |
{
|
|
83 |
disConnectFromModel();
|
|
84 |
}
|
|
85 |
|
|
86 |
int GlxModelWrapper::rowCount(const QModelIndex &parent ) const
|
|
87 |
{
|
|
88 |
Q_UNUSED(parent);
|
|
89 |
if(mModel)
|
|
90 |
return (mModel->rowCount());
|
|
91 |
else
|
|
92 |
return 0;
|
|
93 |
}
|
|
94 |
|
|
95 |
int GlxModelWrapper::columnCount(const QModelIndex &parent ) const
|
|
96 |
{
|
|
97 |
Q_UNUSED(parent);
|
|
98 |
return 1;
|
|
99 |
}
|
|
100 |
|
|
101 |
QModelIndex GlxModelWrapper::parent(const QModelIndex &child) const
|
|
102 |
{
|
|
103 |
Q_UNUSED(child);
|
|
104 |
return QModelIndex(); // No need to Check mModel ,Should i Set mModel As parent
|
|
105 |
}
|
|
106 |
|
|
107 |
QVariant GlxModelWrapper::data(const QModelIndex &idx, int role) const
|
|
108 |
{
|
|
109 |
if(mModel)
|
|
110 |
{
|
|
111 |
if(mOriginalRole == role)
|
|
112 |
{
|
|
113 |
return (mModel->data(idx,mConvertRole));
|
|
114 |
}
|
|
115 |
else
|
|
116 |
{
|
|
117 |
return (mModel->data(idx,role));
|
|
118 |
}
|
|
119 |
}
|
|
120 |
else
|
|
121 |
{
|
|
122 |
return QVariant();
|
|
123 |
}
|
|
124 |
}
|
|
125 |
|
|
126 |
bool GlxModelWrapper::setData ( const QModelIndex & idx, const QVariant & value, int role )
|
|
127 |
{
|
|
128 |
if(mModel)
|
|
129 |
{
|
|
130 |
return (mModel->setData(mModel->index(idx.row(),0),value,role));
|
|
131 |
}
|
|
132 |
else
|
|
133 |
{
|
|
134 |
return FALSE;
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
QModelIndex GlxModelWrapper::index(int row, int column, const QModelIndex &parent) const
|
|
139 |
{
|
|
140 |
Q_UNUSED(parent);
|
|
141 |
if ( ( row < 0 ) || ( row >= rowCount() ) || ( column < 0 ) || ( column >= columnCount() ) )
|
|
142 |
{
|
|
143 |
return QModelIndex();
|
|
144 |
}
|
|
145 |
return QAbstractItemModel::createIndex(row, column);
|
|
146 |
}
|
|
147 |
|
|
148 |
QModelIndex GlxModelWrapper::basemodelindex(int row, int column, const QModelIndex &parent) const
|
|
149 |
{
|
|
150 |
Q_UNUSED(parent);
|
|
151 |
if(mModel)
|
|
152 |
{
|
|
153 |
return (mModel->index(row,column));
|
|
154 |
}
|
|
155 |
else
|
|
156 |
{
|
|
157 |
return QModelIndex();
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
void GlxModelWrapper::modelDestroyed()
|
|
162 |
{
|
|
163 |
disConnectFromModel();
|
|
164 |
mModel = NULL;
|
|
165 |
resetTheModel();
|
|
166 |
}
|
|
167 |
|
|
168 |
void GlxModelWrapper::resetTheModel()
|
|
169 |
{
|
|
170 |
beginResetModel();
|
|
171 |
endResetModel();
|
|
172 |
}
|
|
173 |
|
|
174 |
void GlxModelWrapper::dataChangedinModel(QModelIndex startIndex, QModelIndex endIndex)
|
|
175 |
{
|
|
176 |
emit dataChanged(index(startIndex.row(),startIndex.column()),index(endIndex.row(),endIndex.column()));
|
|
177 |
}
|
|
178 |
|
|
179 |
void GlxModelWrapper::rowsAboutToBeInserted(const QModelIndex &parent,int start,int end)
|
|
180 |
{
|
|
181 |
Q_UNUSED(parent);
|
|
182 |
Q_UNUSED(start);
|
|
183 |
Q_UNUSED(end);
|
|
184 |
}
|
|
185 |
|
|
186 |
void GlxModelWrapper::rowsInserted(const QModelIndex &parent, int start, int end)
|
|
187 |
{
|
|
188 |
Q_UNUSED(parent);
|
|
189 |
beginInsertRows(QModelIndex(), start, end);
|
|
190 |
endInsertRows();
|
|
191 |
}
|
|
192 |
|
|
193 |
void GlxModelWrapper::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
|
|
194 |
{
|
|
195 |
Q_UNUSED(parent);
|
|
196 |
Q_UNUSED(start);
|
|
197 |
Q_UNUSED(end);
|
|
198 |
}
|
|
199 |
|
|
200 |
void GlxModelWrapper::rowsRemoved(const QModelIndex &parent, int start, int end)
|
|
201 |
{
|
|
202 |
Q_UNUSED(parent);
|
|
203 |
beginRemoveRows(QModelIndex(), start, end);
|
|
204 |
endRemoveRows();
|
|
205 |
}
|
|
206 |
|
|
207 |
|
|
208 |
|