From kde-commits Sun Nov 30 22:17:58 2014 From: Johannes Zarl Date: Sun, 30 Nov 2014 22:17:58 +0000 To: kde-commits Subject: [kphotoalbum/annotation_map_2] Map: Implement thumbnails on the MapView (in theory). Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=141738588812252 Git commit 99ea708e3429249e57ac14c8fa9d6693e96be8a1 by Johannes Zarl. Committed on 30/11/2014 at 22:16. Pushed by johanneszarl into branch 'annotation_map_2'. Implement thumbnails on the MapView (in theory). the MapView never tries to load the thumbnails, i.e. I'm still missing something. M +27 -13 Map/MapMarkerModelHelper.cpp M +6 -4 Map/MapMarkerModelHelper.h http://commits.kde.org/kphotoalbum/99ea708e3429249e57ac14c8fa9d6693e96be8a1 diff --git a/Map/MapMarkerModelHelper.cpp b/Map/MapMarkerModelHelper.cpp index 10833aa..757b62a 100644 --- a/Map/MapMarkerModelHelper.cpp +++ b/Map/MapMarkerModelHelper.cpp @@ -20,11 +20,20 @@ #include #include #include +#include = // Local includes +#include #include "MapMarkerModelHelper.h" = +#ifdef DEBUG_MAP +# define Debug qDebug +#else +# define Debug if (false) qDebug +#endif + const int CoordinatesRole =3D Qt::UserRole + 0; +const int FileNameRole =3D Qt::UserRole + 1; = Map::MapMarkerModelHelper::MapMarkerModelHelper() : m_itemModel(0), m_item= SelectionModel(0) { @@ -47,19 +56,18 @@ void Map::MapMarkerModelHelper::clearItems() = void Map::MapMarkerModelHelper::addImage(const DB::ImageInfo& image) { - addItem(image.coordinates()); -} + Debug() << "Adding marker for image " << image.label(); + QStandardItem* const newItem =3D new QStandardItem(image.label()); = -void Map::MapMarkerModelHelper::addImage(const DB::ImageInfoPtr image) -{ - addItem(image->coordinates()); + newItem->setToolTip(image.label()); + newItem->setData(QVariant::fromValue(image.coordinates()), Coordinates= Role); + newItem->setData(QVariant::fromValue(image.fileName()), FileNameRole); + m_itemModel->appendRow(newItem); } = -void Map::MapMarkerModelHelper::addItem(KGeoMap::GeoCoordinates coordinate= s) +void Map::MapMarkerModelHelper::addImage(const DB::ImageInfoPtr image) { - QStandardItem* const newItem =3D new QStandardItem(coordinates.geoUrl(= )); - newItem->setData(QVariant::fromValue(coordinates), CoordinatesRole); - m_itemModel->appendRow(newItem); + addImage(*image); } = void Map::MapMarkerModelHelper::slotDataChanged(const QModelIndex&, const = QModelIndex&) @@ -105,17 +113,23 @@ KGeoMap::ModelHelper::Flags Map::MapMarkerModelHelper= ::itemFlags(const QModelInd return FlagVisible; } = +// FIXME: for some reason, itemIcon is never called -> no thumbnails bool Map::MapMarkerModelHelper::itemIcon(const QModelIndex& index, - QPoint* const, + QPoint* const offset, QSize* const, - QPixmap* const, + QPixmap* const pixmap, KUrl* const) const { - if (! index.data(CoordinatesRole).canConvert(= )) { + DB::FileName filename =3D index.data(FileNameRole).value= (); + if (! index.data(FileNameRole).canConvert()) { + Debug() << "Cannot convert icon for " << filename.relative(); return false; } = - return false; //FIXME + *pixmap =3D ImageManager::ThumbnailCache::instance()->lookup( filename= ); + *offset =3D QPoint(pixmap->width()/2, pixmap->height()-1); + Debug() << "Map icon for " << filename.relative() << (pixmap->isNull()= ? " missing." : " found."); + return !pixmap->isNull(); } = // vi:expandtab:tabstop=3D4 shiftwidth=3D4: diff --git a/Map/MapMarkerModelHelper.h b/Map/MapMarkerModelHelper.h index fe9d28a..9492d81 100644 --- a/Map/MapMarkerModelHelper.h +++ b/Map/MapMarkerModelHelper.h @@ -49,7 +49,7 @@ class GeoCoordinates; namespace Map { = -class MapMarkerModelHelper : public KGeoMap::ModelHelper +class MapMarkerModelHelper : public KGeoMap::ModelHelper//, public ImageMa= nager::ImageClientInterface { Q_OBJECT = @@ -67,7 +67,7 @@ public: */ void clearItems(); = - // all other methods implement the ModelHelper interface: + // ------------------------------ ModelHelper API bool itemCoordinates(const QModelIndex &index, KGeoMap::GeoCoordinates *const coordinates) const= override; QAbstractItemModel* model() const override; @@ -80,8 +80,10 @@ public: QPixmap* const pixmap, KUrl* const url) const override; = -private: // Functions - void addItem(KGeoMap::GeoCoordinates coordinates); + // ------------------------------ ImageClient API + //void pixmapLoaded(ImageRequest* request, const QImage& image) overri= de; + //void requestCanceled() override; + = private: // Variables QStandardItemModel* m_itemModel;