| 1 | /* ============================================================ |
| 2 | * |
| 3 | * This file is a part of digiKam project |
| 4 | * https://www.digikam.org |
| 5 | * |
| 6 | * Date : 2010-03-20 |
| 7 | * Description : sub class of QStandardItem to represent the images |
| 8 | * |
| 9 | * SPDX-FileCopyrightText: 2010 by Michael G. Hansen <mike at mghansen dot de> |
| 10 | * |
| 11 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 12 | * |
| 13 | * ============================================================ */ |
| 14 | |
| 15 | #include "myimageitem.h" |
| 16 | |
| 17 | MyImageItem::MyImageItem(const QUrl& url, const GeoCoordinates& itemCoordinates) |
| 18 | : QTreeWidgetItem(), |
| 19 | coordinates (itemCoordinates), |
| 20 | imageUrl (url) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | MyImageItem::~MyImageItem() |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | QVariant MyImageItem::data(int column, int role) const |
| 29 | { |
| 30 | if (role == RoleCoordinates) |
| 31 | { |
| 32 | return QVariant::fromValue(coordinates); |
| 33 | } |
| 34 | else if (role == Qt::DisplayRole) |
| 35 | { |
| 36 | switch (column) |
| 37 | { |
| 38 | case 0: |
| 39 | { |
| 40 | return imageUrl.fileName(); |
| 41 | } |
| 42 | |
| 43 | case 1: |
| 44 | { |
| 45 | return coordinates.geoUrl(); |
| 46 | } |
| 47 | |
| 48 | default: |
| 49 | { |
| 50 | return QVariant(); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return QTreeWidgetItem::data(column, role); |
| 56 | } |
| 57 | |
| 58 | void MyImageItem::setData(int column, int role, const QVariant& value) |
| 59 | { |
| 60 | if (role == RoleCoordinates) |
| 61 | { |
| 62 | if (value.canConvert<GeoCoordinates>()) |
| 63 | { |
| 64 | coordinates = value.value<GeoCoordinates>(); |
| 65 | emitDataChanged(); |
| 66 | } |
| 67 | |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | QTreeWidgetItem::setData(column, role, value); |
| 72 | } |