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),
|
58
|
24 |
mConvertRole(Qt::DecorationRole),
|
|
25 |
mPaintPage(false)
|
40
|
26 |
{
|
|
27 |
|
|
28 |
}
|
|
29 |
|
|
30 |
void GlxModelWrapper::setModel(QAbstractItemModel *model)
|
|
31 |
{
|
|
32 |
if(model && mModel != model)
|
|
33 |
{
|
|
34 |
disConnectFromModel();
|
|
35 |
mModel = model;
|
58
|
36 |
QVariant variant = mModel->data(mModel->index(0,0),GlxPaintPageFlag);
|
|
37 |
if (variant.isValid() && variant.canConvert<bool> () )
|
|
38 |
{
|
|
39 |
mPaintPage = variant.value<bool>();
|
|
40 |
}
|
40
|
41 |
connectToModel();
|
|
42 |
resetTheModel();
|
|
43 |
}
|
|
44 |
}
|
|
45 |
|
|
46 |
|
|
47 |
void GlxModelWrapper::setRoles(int convertrole, int originalrole)
|
|
48 |
{
|
|
49 |
mConvertRole = convertrole;
|
|
50 |
mOriginalRole = originalrole;
|
|
51 |
}
|
|
52 |
|
|
53 |
void GlxModelWrapper::scrollingStarted()
|
|
54 |
{
|
|
55 |
|
|
56 |
}
|
|
57 |
|
|
58 |
void GlxModelWrapper::scrollingEnded()
|
|
59 |
{
|
|
60 |
|
|
61 |
}
|
|
62 |
|
|
63 |
void GlxModelWrapper::connectToModel()
|
|
64 |
{
|
|
65 |
connect(mModel, SIGNAL(destroyed()),this, SLOT(modelDestroyed()));
|
|
66 |
connect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(dataChangedinModel(QModelIndex,QModelIndex)));
|
|
67 |
connect(mModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),this,SLOT(rowsAboutToBeInserted(QModelIndex,int,int)));
|
|
68 |
connect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)),this, SLOT(rowsInserted(QModelIndex,int,int)));
|
|
69 |
connect(mModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),this,SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)));
|
|
70 |
connect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),this,SLOT(rowsRemoved(QModelIndex,int,int)));
|
|
71 |
}
|
|
72 |
|
|
73 |
void GlxModelWrapper::disConnectFromModel()
|
|
74 |
{
|
|
75 |
if(mModel)
|
|
76 |
{
|
|
77 |
disconnect(mModel, SIGNAL(destroyed()),this, SLOT(modelDestroyed()));
|
|
78 |
disconnect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(dataChangedinModel(QModelIndex,QModelIndex)));
|
|
79 |
disconnect(mModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),this,SLOT(rowsAboutToBeInserted(QModelIndex,int,int)));
|
|
80 |
disconnect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)),this, SLOT(rowsInserted(QModelIndex,int,int)));
|
|
81 |
disconnect(mModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),this,SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)));
|
|
82 |
disconnect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),this,SLOT(rowsRemoved(QModelIndex,int,int)));
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
|
|
87 |
GlxModelWrapper::~GlxModelWrapper()
|
|
88 |
{
|
|
89 |
disConnectFromModel();
|
|
90 |
}
|
|
91 |
|
|
92 |
int GlxModelWrapper::rowCount(const QModelIndex &parent ) const
|
|
93 |
{
|
|
94 |
Q_UNUSED(parent);
|
|
95 |
if(mModel)
|
|
96 |
return (mModel->rowCount());
|
|
97 |
else
|
|
98 |
return 0;
|
|
99 |
}
|
|
100 |
|
|
101 |
int GlxModelWrapper::columnCount(const QModelIndex &parent ) const
|
|
102 |
{
|
|
103 |
Q_UNUSED(parent);
|
|
104 |
return 1;
|
|
105 |
}
|
|
106 |
|
|
107 |
QModelIndex GlxModelWrapper::parent(const QModelIndex &child) const
|
|
108 |
{
|
|
109 |
Q_UNUSED(child);
|
|
110 |
return QModelIndex(); // No need to Check mModel ,Should i Set mModel As parent
|
|
111 |
}
|
|
112 |
|
|
113 |
QVariant GlxModelWrapper::data(const QModelIndex &idx, int role) const
|
|
114 |
{
|
|
115 |
if(mModel)
|
|
116 |
{
|
|
117 |
if(mOriginalRole == role)
|
|
118 |
{
|
|
119 |
return (mModel->data(idx,mConvertRole));
|
|
120 |
}
|
|
121 |
else
|
|
122 |
{
|
|
123 |
return (mModel->data(idx,role));
|
|
124 |
}
|
|
125 |
}
|
|
126 |
else
|
|
127 |
{
|
|
128 |
return QVariant();
|
|
129 |
}
|
|
130 |
}
|
|
131 |
|
|
132 |
bool GlxModelWrapper::setData ( const QModelIndex & idx, const QVariant & value, int role )
|
|
133 |
{
|
|
134 |
if(mModel)
|
|
135 |
{
|
|
136 |
return (mModel->setData(mModel->index(idx.row(),0),value,role));
|
|
137 |
}
|
|
138 |
else
|
|
139 |
{
|
|
140 |
return FALSE;
|
|
141 |
}
|
|
142 |
}
|
|
143 |
|
|
144 |
QModelIndex GlxModelWrapper::index(int row, int column, const QModelIndex &parent) const
|
|
145 |
{
|
|
146 |
Q_UNUSED(parent);
|
|
147 |
if ( ( row < 0 ) || ( row >= rowCount() ) || ( column < 0 ) || ( column >= columnCount() ) )
|
|
148 |
{
|
|
149 |
return QModelIndex();
|
|
150 |
}
|
|
151 |
return QAbstractItemModel::createIndex(row, column);
|
|
152 |
}
|
|
153 |
|
|
154 |
QModelIndex GlxModelWrapper::basemodelindex(int row, int column, const QModelIndex &parent) const
|
|
155 |
{
|
|
156 |
Q_UNUSED(parent);
|
|
157 |
if(mModel)
|
|
158 |
{
|
|
159 |
return (mModel->index(row,column));
|
|
160 |
}
|
|
161 |
else
|
|
162 |
{
|
|
163 |
return QModelIndex();
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
void GlxModelWrapper::modelDestroyed()
|
|
168 |
{
|
|
169 |
disConnectFromModel();
|
|
170 |
mModel = NULL;
|
|
171 |
resetTheModel();
|
|
172 |
}
|
|
173 |
|
|
174 |
void GlxModelWrapper::resetTheModel()
|
|
175 |
{
|
|
176 |
beginResetModel();
|
|
177 |
endResetModel();
|
|
178 |
}
|
|
179 |
|
|
180 |
void GlxModelWrapper::dataChangedinModel(QModelIndex startIndex, QModelIndex endIndex)
|
|
181 |
{
|
50
|
182 |
int aStartRow = startIndex.row();
|
|
183 |
|
58
|
184 |
if(mPaintPage)
|
|
185 |
{
|
50
|
186 |
if((aStartRow == 14) || (aStartRow+1 == rowCount()))
|
|
187 |
{
|
|
188 |
emit dataChanged(index(0,0),index(endIndex.row(),0));
|
58
|
189 |
mPaintPage = false;
|
50
|
190 |
}
|
|
191 |
else if(aStartRow >= 15)
|
|
192 |
{
|
|
193 |
emit dataChanged(index(aStartRow,0),index(endIndex.row(),0));
|
|
194 |
}
|
58
|
195 |
}
|
50
|
196 |
else
|
|
197 |
{
|
58
|
198 |
emit dataChanged(index(aStartRow,0),index(endIndex.row(),0));
|
50
|
199 |
}
|
40
|
200 |
}
|
|
201 |
|
|
202 |
void GlxModelWrapper::rowsAboutToBeInserted(const QModelIndex &parent,int start,int end)
|
|
203 |
{
|
|
204 |
Q_UNUSED(parent);
|
|
205 |
Q_UNUSED(start);
|
|
206 |
Q_UNUSED(end);
|
|
207 |
}
|
|
208 |
|
|
209 |
void GlxModelWrapper::rowsInserted(const QModelIndex &parent, int start, int end)
|
|
210 |
{
|
|
211 |
Q_UNUSED(parent);
|
|
212 |
beginInsertRows(QModelIndex(), start, end);
|
|
213 |
endInsertRows();
|
|
214 |
}
|
|
215 |
|
|
216 |
void GlxModelWrapper::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
|
|
217 |
{
|
|
218 |
Q_UNUSED(parent);
|
|
219 |
Q_UNUSED(start);
|
|
220 |
Q_UNUSED(end);
|
|
221 |
}
|
|
222 |
|
|
223 |
void GlxModelWrapper::rowsRemoved(const QModelIndex &parent, int start, int end)
|
|
224 |
{
|
|
225 |
Q_UNUSED(parent);
|
|
226 |
beginRemoveRows(QModelIndex(), start, end);
|
|
227 |
endRemoveRows();
|
|
228 |
}
|
|
229 |
|
|
230 |
|
|
231 |
|