112 |
112 |
113 bool HgWidgetItem::updateItemData() |
113 bool HgWidgetItem::updateItemData() |
114 { |
114 { |
115 mValidData = false; |
115 mValidData = false; |
116 if( mModelIndex.isValid() ){ |
116 if( mModelIndex.isValid() ){ |
|
117 |
|
118 if (!mHgImage) |
|
119 { |
|
120 mHgImage = mRenderer->createNativeImage(); |
|
121 } |
|
122 |
117 QVariant image = mModelIndex.data(Qt::DecorationRole); |
123 QVariant image = mModelIndex.data(Qt::DecorationRole); |
118 QVariant texts = mModelIndex.data(Qt::DisplayRole); |
124 QVariant texts = mModelIndex.data(Qt::DisplayRole); |
119 |
125 |
120 QVariant vis = mModelIndex.data(HgWidget::HgVisibilityRole); |
126 QVariant vis = mModelIndex.data(HgWidget::HgVisibilityRole); |
121 if (vis.canConvert<bool>()) |
127 if (vis.canConvert<bool>()) |
122 { |
128 { |
123 setVisibility(vis.toBool()); |
129 setVisibility(vis.toBool()); |
124 } |
130 } else { |
125 |
131 setVisibility(true); |
|
132 } |
126 |
133 |
127 // Convert data to correct format if possible. |
134 // Convert data to correct format if possible. |
128 if (image.type() == QVariant::Pixmap) |
135 if (image.type() == QVariant::Pixmap) |
129 { |
136 { |
130 setPixmap(image.value<QPixmap>()); |
137 setPixmap(image.value<QPixmap>()); |
144 QSize size; |
151 QSize size; |
145 foreach(size, sizes){ |
152 foreach(size, sizes){ |
146 if (size.width() != 0 && size.height() != 0 ){ |
153 if (size.width() != 0 && size.height() != 0 ){ |
147 QPixmap pixmap = qicon.pixmap(size); |
154 QPixmap pixmap = qicon.pixmap(size); |
148 if (!pixmap.isNull()){ |
155 if (!pixmap.isNull()){ |
149 QImage tempImage = pixmap.toImage(); |
156 setPixmap(pixmap); |
150 if (!tempImage.isNull()) { |
157 mValidData = true; |
151 setImage(tempImage); |
|
152 mValidData = true; |
|
153 } |
|
154 } |
158 } |
155 break; |
159 break; |
156 } |
160 } |
157 } |
161 } |
158 } |
162 } |
164 QList<QSize> sizes = tempIcon.availableSizes(); |
168 QList<QSize> sizes = tempIcon.availableSizes(); |
165 if (sizes.count() == 0 && !(tempIcon.isNull())) { |
169 if (sizes.count() == 0 && !(tempIcon.isNull())) { |
166 QPixmap pixmap = tempIcon.pixmap(tempIcon.actualSize(QSize(250, 250))); |
170 QPixmap pixmap = tempIcon.pixmap(tempIcon.actualSize(QSize(250, 250))); |
167 if (!pixmap.isNull()){ |
171 if (!pixmap.isNull()){ |
168 INFO("Valid image found for" << mModelIndex); |
172 INFO("Valid image found for" << mModelIndex); |
169 setImage(pixmap.toImage()); |
173 setPixmap(pixmap); |
170 mValidData = true; |
174 mValidData = true; |
171 } |
175 } |
172 } |
176 } |
173 else { |
177 else { |
174 QSize size; |
178 QSize size; |
175 foreach(size, sizes){ |
179 foreach(size, sizes){ |
176 if (size.width() != 0 && size.height() != 0 ){ |
180 if (size.width() != 0 && size.height() != 0 ){ |
177 QPixmap pixmap = tempIcon.pixmap(size); |
181 QPixmap pixmap = tempIcon.pixmap(size); |
178 if (!pixmap.isNull()){ |
182 if (!pixmap.isNull()){ |
179 setImage(pixmap.toImage()); |
183 setPixmap(pixmap); |
180 mValidData = true; |
184 mValidData = true; |
181 } |
185 } |
182 break; |
186 break; |
183 } |
187 } |
184 } |
188 } |
185 } |
189 } |
186 } |
190 } |
187 if( texts.canConvert<QStringList>() ){ |
191 if( texts.canConvert<QStringList>() ){ |
188 QStringList list(texts.toStringList() ); |
192 QStringList list(texts.toStringList() ); |
189 if( list.count() >= 2 ){ |
193 if (list.count() >= 1) { |
|
194 mValidData = true; |
190 setTitle(list.at(0)); |
195 setTitle(list.at(0)); |
|
196 } |
|
197 if (list.count() >= 2){ |
191 setDescription(list.at(1)); |
198 setDescription(list.at(1)); |
192 mValidData = true; |
|
193 } |
199 } |
194 } |
200 } |
195 |
201 |
196 } |
202 } |
197 return mValidData; |
203 return mValidData; |