78 iLogos.append(NULL); |
79 iLogos.append(NULL); |
79 elementCountNeedToAdd--; |
80 elementCountNeedToAdd--; |
80 } |
81 } |
81 iLogos[aIndex] = aIcon; |
82 iLogos[aIndex] = aIcon; |
82 emit dataChanged(index(aIndex), index(aIndex)); |
83 emit dataChanged(index(aIndex), index(aIndex)); |
|
84 } |
|
85 |
|
86 bool IRFavoritesModel::isLogoReady(int aIndex) const |
|
87 { |
|
88 int logoListCount = iLogos.count(); |
|
89 if (aIndex >= 0 |
|
90 && aIndex < logoListCount) |
|
91 { |
|
92 return iLogos[aIndex] != NULL; |
|
93 } |
|
94 else |
|
95 { |
|
96 return false; |
|
97 } |
83 } |
98 } |
84 |
99 |
85 QVariant IRFavoritesModel::data(const QModelIndex &aIndex, int aRole) const |
100 QVariant IRFavoritesModel::data(const QModelIndex &aIndex, int aRole) const |
86 { |
101 { |
87 if (!aIndex.isValid()) |
102 if (!aIndex.isValid()) |
164 { |
179 { |
165 return; |
180 return; |
166 } |
181 } |
167 |
182 |
168 int presetSize = iPresetsList->count(); |
183 int presetSize = iPresetsList->count(); |
|
184 |
|
185 if(!presetSize) |
|
186 { |
|
187 return; |
|
188 } |
|
189 |
169 int uniqId = 0; |
190 int uniqId = 0; |
170 |
191 |
171 for (int i = 0; i < presetSize; ++i) |
192 while(presetSize--) |
172 { |
193 { |
173 uniqId = iFavoritesDb->getUniqId(i); |
194 uniqId = iFavoritesDb->getUniqId(presetSize); |
|
195 |
|
196 //There is the probability that the return value<0, so I added this judgment. |
|
197 if(uniqId < 0 ) |
|
198 { |
|
199 //if here, the Id, which is mapped to preset's item, can't be found. |
|
200 //jump out from while |
|
201 break; |
|
202 } |
174 iFavoritesDb->deletePreset(uniqId); |
203 iFavoritesDb->deletePreset(uniqId); |
175 } |
204 |
176 |
205 } |
|
206 |
177 clearPresetList(); |
207 clearPresetList(); |
178 clearAndDestroyLogos(); |
208 clearAndDestroyLogos(); |
179 emit modelChanged(); |
209 emit modelChanged(); |
180 } |
210 } |
181 |
211 |
207 { |
237 { |
208 return false; |
238 return false; |
209 } |
239 } |
210 |
240 |
211 beginRemoveRows(QModelIndex(), aIndex, aIndex); |
241 beginRemoveRows(QModelIndex(), aIndex, aIndex); |
|
242 delete preset; |
212 iPresetsList->removeAt(aIndex); |
243 iPresetsList->removeAt(aIndex); |
213 |
244 |
214 if (aIndex<iLogos.size()) |
245 if (aIndex<iLogos.size()) |
215 { |
246 { |
216 delete iLogos[aIndex]; |
247 delete iLogos[aIndex]; |
217 iLogos[aIndex] = NULL; |
248 iLogos[aIndex] = NULL; |
218 } |
249 } |
219 iLogos.removeAt(aIndex); |
250 iLogos.removeAt(aIndex); |
220 endRemoveRows(); |
251 endRemoveRows(); |
221 emit modelChanged(); |
|
222 return true; |
252 return true; |
223 } |
253 } |
224 |
254 |
|
255 bool IRFavoritesModel::deleteMultiFavorites(const QModelIndexList &aIndexList) |
|
256 { |
|
257 if (aIndexList.empty()) |
|
258 { |
|
259 return true; |
|
260 } |
|
261 |
|
262 int index = 0; |
|
263 bool retVal = true; |
|
264 QList<int> indexToBeDelete; |
|
265 |
|
266 // delete from DB |
|
267 for (int i = 0; i < aIndexList.count(); i++) |
|
268 { |
|
269 index = aIndexList.at(i).row(); |
|
270 |
|
271 if (index < 0 || index >= iPresetsList->size()) |
|
272 { |
|
273 continue; |
|
274 } |
|
275 |
|
276 if (0 != iFavoritesDb->deletePreset(iPresetsList->at(index)->uniqID)) |
|
277 { |
|
278 retVal = false; |
|
279 continue; |
|
280 } |
|
281 indexToBeDelete.append(index); |
|
282 } |
|
283 |
|
284 qSort(indexToBeDelete); |
|
285 |
|
286 |
|
287 // delete from model |
|
288 for (int i = indexToBeDelete.count() - 1; i >= 0; i--) |
|
289 { |
|
290 index = indexToBeDelete.at(i); |
|
291 |
|
292 beginRemoveRows(QModelIndex(), index, index); |
|
293 IRQPreset *preset = iPresetsList->at(index); |
|
294 delete preset; |
|
295 iPresetsList->removeAt(index); |
|
296 if (index<iLogos.size()) |
|
297 { |
|
298 delete iLogos[index]; |
|
299 iLogos[index] = NULL; |
|
300 } |
|
301 iLogos.removeAt(index); |
|
302 endRemoveRows(); |
|
303 } |
|
304 |
|
305 return retVal; |
|
306 } |
|
307 |