|
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 |
|
19 |
|
20 #include <glxfavmediamodel.h> |
|
21 #include <glxmodelparm.h> |
|
22 #include <glxtracer.h> |
|
23 #include <glxfiltergeneraldefs.h> |
|
24 |
|
25 |
|
26 GlxFavMediaModel::GlxFavMediaModel(GlxModelParm & modelParm) |
|
27 { |
|
28 TRACER("GlxFavMediaModel::GlxFavMediaModel"); |
|
29 mMLWrapper = new GlxMLWrapper(modelParm.collection(),0,EGlxFilterImage,modelParm.path()); |
|
30 mMLWrapper->setContextMode( modelParm.contextMode() ); |
|
31 int err = connect(mMLWrapper, SIGNAL(insertItems(int, int)), this, SLOT(itemsAdded(int, int))); |
|
32 err = connect(mMLWrapper, SIGNAL(removeItems(int, int)), this, SLOT(itemsRemoved(int, int))); |
|
33 } |
|
34 |
|
35 GlxFavMediaModel::~GlxFavMediaModel() |
|
36 { |
|
37 TRACER("GlxFavMediaModel::~GlxFavMediaModel"); |
|
38 int err = disconnect(mMLWrapper, SIGNAL(insertItems(int, int)), this, SLOT(itemsAdded(int, int))); |
|
39 err = disconnect(mMLWrapper, SIGNAL(removeItems(int, int)), this, SLOT(itemsRemoved(int, int))); |
|
40 delete mMLWrapper; |
|
41 } |
|
42 |
|
43 |
|
44 int GlxFavMediaModel::rowCount(const QModelIndex &parent ) const |
|
45 { |
|
46 TRACER("GlxFavMediaModel::rowCount"); |
|
47 Q_UNUSED(parent); |
|
48 return (mMLWrapper->getItemCount()); |
|
49 } |
|
50 |
|
51 int GlxFavMediaModel::columnCount(const QModelIndex &parent ) const |
|
52 { |
|
53 TRACER("GlxFavMediaModel::columnCount"); |
|
54 Q_UNUSED(parent); |
|
55 return 1; |
|
56 } |
|
57 |
|
58 QModelIndex GlxFavMediaModel::parent(const QModelIndex &child) const |
|
59 { |
|
60 TRACER("GlxFavMediaModel::parent"); |
|
61 Q_UNUSED(child); |
|
62 //returns always invalid model index |
|
63 return QModelIndex(); |
|
64 } |
|
65 |
|
66 |
|
67 QVariant GlxFavMediaModel::data(const QModelIndex &index, int role) const |
|
68 { |
|
69 TRACER("GlxFavMediaModel::data"); |
|
70 |
|
71 if ((!index.isValid()) ) { |
|
72 return QVariant(); |
|
73 } |
|
74 |
|
75 if (role == GlxFavorites){ |
|
76 return rowCount(); |
|
77 } |
|
78 |
|
79 return QVariant(); |
|
80 } |
|
81 |
|
82 |
|
83 void GlxFavMediaModel::itemsAdded(int startIndex, int endIndex) |
|
84 { |
|
85 TRACER("GlxFavMediaModel::itemsAdded"); |
|
86 beginInsertRows(QModelIndex(), startIndex, endIndex); |
|
87 emit dataChanged(index(startIndex,0),index(startIndex,0)); |
|
88 endInsertRows(); |
|
89 } |
|
90 |
|
91 void GlxFavMediaModel::itemsRemoved(int startIndex, int endIndex) |
|
92 { |
|
93 TRACER("GlxFavMediaModel::itemsRemoved"); |
|
94 beginRemoveRows(QModelIndex(), startIndex, endIndex); |
|
95 emit dataChanged(index(startIndex,0),index(startIndex,0)); |
|
96 endRemoveRows(); |
|
97 } |
|
98 |
|
99 |
|
100 QModelIndex GlxFavMediaModel::index(int row, int column, const QModelIndex &parent) const |
|
101 { |
|
102 TRACER("GlxFavMediaModel::index"); |
|
103 Q_UNUSED(parent) |
|
104 if ( ( row < 0 ) |
|
105 || ( row > rowCount() ) |
|
106 || ( column < 0 ) |
|
107 || ( column >= columnCount() ) ) { |
|
108 return QModelIndex(); |
|
109 } |
|
110 |
|
111 return QAbstractItemModel::createIndex(row, column); |
|
112 } |
|
113 |