Also hold a pointer to the struct picture on the model.

Changes to hold a pointer to the struct picture on the model, so we can
use it to determine the correct positioning of the image on the profile.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-06-03 19:34:36 -03:00 committed by Dirk Hohndel
parent 43cf9fdb7a
commit b1847f9ebb
2 changed files with 23 additions and 8 deletions

View file

@ -43,15 +43,17 @@ void DivePictureModel::updateDivePictures(int divenr)
return;
}
stringPixmapCache.clear();
QStringList pictures;
FOR_EACH_PICTURE( d ) {
stringPixmapCache[QString(picture->filename)].picture = picture;
pictures.push_back(QString(picture->filename));
}
stringPixmapCache.clear();
SPixmapList retList = QtConcurrent::blockingMapped<SPixmapList>( pictures, scaleImages);
Q_FOREACH(const SPixmap & pixmap, retList)
stringPixmapCache[pixmap.first] = pixmap.second;
stringPixmapCache[pixmap.first].image = pixmap.second;
beginInsertRows(QModelIndex(), 0, numberOfPictures-1);
endInsertRows();
@ -59,7 +61,7 @@ void DivePictureModel::updateDivePictures(int divenr)
int DivePictureModel::columnCount(const QModelIndex &parent) const
{
return 1;
return 2;
}
QVariant DivePictureModel::data(const QModelIndex &index, int role) const
@ -69,10 +71,17 @@ QVariant DivePictureModel::data(const QModelIndex &index, int role) const
return ret;
QString key = stringPixmapCache.keys().at(index.row());
switch(role){
case Qt::ToolTipRole : ret = key; break;
case Qt::DecorationRole : ret = stringPixmapCache[key]; break;
case Qt::DisplayRole : ret = QFileInfo(key).fileName();
if(index.column() == 0){
switch(role){
case Qt::ToolTipRole : ret = key; break;
case Qt::DecorationRole : ret = stringPixmapCache[key].image; break;
case Qt::DisplayRole : ret = QFileInfo(key).fileName();
}
}
else if (index.column() == 1){
switch(role){
case Qt::UserRole : ret = QVariant::fromValue( (void*) stringPixmapCache[key].picture);
}
}
return ret;
}

View file

@ -6,6 +6,12 @@
#include <QListView>
#include <QThread>
struct picture;
struct PhotoHelper{
QImage image;
struct picture *picture;
};
class DivePictureModel : public QAbstractTableModel {
Q_OBJECT
public:
@ -20,7 +26,7 @@ private:
// Currently, load the images on the fly
// Later, use a thread to load the images
// Later, save the thumbnails so we don't need to reopen every time.
QHash<QString, QImage> stringPixmapCache;
QHash<QString, PhotoHelper> stringPixmapCache;
};
class DivePictureDelegate : QStyledItemDelegate {