[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kphotoalbum/annotation_map_2] Map: Implement thumbnails on the MapView (in theory).
From:       Johannes Zarl <johannes () zarl ! at>
Date:       2014-11-30 22:17:58
Message-ID: E1XvCoY-00018t-RC () scm ! kde ! org
[Download RAW message or body]

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 <QStandardItemModel>
 #include <QStandardItem>
 #include <QItemSelectionModel>
+#include <QDebug>
 
 // Local includes
+#include <ImageManager/ThumbnailCache.h>
 #include "MapMarkerModelHelper.h"
 
+#ifdef DEBUG_MAP
+#  define Debug qDebug
+#else
+#  define Debug if (false) qDebug
+#endif
+
 const int CoordinatesRole = Qt::UserRole + 0;
+const int FileNameRole = Qt::UserRole + 1;
 
 Map::MapMarkerModelHelper::MapMarkerModelHelper() : m_itemModel(0), m_itemSelectionModel(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 = 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()), CoordinatesRole);
+    newItem->setData(QVariant::fromValue(image.fileName()), FileNameRole);
+    m_itemModel->appendRow(newItem);
 }
 
-void Map::MapMarkerModelHelper::addItem(KGeoMap::GeoCoordinates coordinates)
+void Map::MapMarkerModelHelper::addImage(const DB::ImageInfoPtr image)
 {
-    QStandardItem* const newItem = 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<KGeoMap::GeoCoordinates>()) {
+    DB::FileName filename = index.data(FileNameRole).value<DB::FileName>();
+    if (! index.data(FileNameRole).canConvert<DB::FileName>()) {
+        Debug() << "Cannot convert icon for " << filename.relative();
         return false;
     }
 
-    return false; //FIXME
+    *pixmap = ImageManager::ThumbnailCache::instance()->lookup( filename );
+    *offset = QPoint(pixmap->width()/2, pixmap->height()-1);
+    Debug() << "Map icon for " << filename.relative() << (pixmap->isNull() ? " missing." : " found.");
+    return !pixmap->isNull();
 }
 
 // vi:expandtab:tabstop=4 shiftwidth=4:
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 ImageManager::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) override;
+    //void requestCanceled() override;
+
 
 private: // Variables
     QStandardItemModel* m_itemModel;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic