309 return this->objects().size(); |
309 return this->objects().size(); |
310 } |
310 } |
311 |
311 |
312 QVariant Model::data(const QModelIndex& index, int role) const |
312 QVariant Model::data(const QModelIndex& index, int role) const |
313 { |
313 { |
|
314 static QMap<QString, QPixmap> scaledIcons; |
|
315 |
314 if (index.row() < 0 or index.row() >= size()) |
316 if (index.row() < 0 or index.row() >= size()) |
315 return {}; |
317 return {}; |
316 |
318 |
317 LDObject* object = this->objects()[index.row()]; |
319 LDObject* object = this->objects()[index.row()]; |
318 |
320 |
335 |
337 |
336 return result; |
338 return result; |
337 } |
339 } |
338 |
340 |
339 case Qt::DecorationRole: |
341 case Qt::DecorationRole: |
340 return MainWindow::getIcon(object->iconName()); |
342 { |
|
343 QString iconName = object->iconName(); |
|
344 auto it = scaledIcons.find(iconName); |
|
345 if (it == scaledIcons.end()) |
|
346 { |
|
347 QPixmap pixmap = MainWindow::getIcon(object->iconName()) |
|
348 .scaled({24, 24}, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
|
349 it = scaledIcons.insert(iconName, pixmap); |
|
350 } |
|
351 return *it; |
|
352 } |
341 |
353 |
342 case Qt::BackgroundColorRole: |
354 case Qt::BackgroundColorRole: |
343 if (object->type() == LDObjectType::Error) |
355 if (object->type() == LDObjectType::Error) |
344 return QColor {"#AA0000"}; |
356 return QColor {"#AA0000"}; |
345 else |
357 else |