2014-05-30 17:38:27 +00:00
|
|
|
#include "divepicturewidget.h"
|
2014-05-30 18:16:00 +00:00
|
|
|
#include <dive.h>
|
2014-05-31 03:42:54 +00:00
|
|
|
#include <qtconcurrentmap.h>
|
2014-05-30 17:38:27 +00:00
|
|
|
|
|
|
|
void DivePictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|
|
|
}
|
|
|
|
|
2014-05-30 18:16:00 +00:00
|
|
|
DivePictureModel::DivePictureModel(QObject *parent): QAbstractTableModel(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-31 03:42:54 +00:00
|
|
|
typedef QPair<QString, QPixmap> SPixmap;
|
|
|
|
typedef QList<SPixmap> SPixmapList;
|
|
|
|
|
|
|
|
SPixmap scaleImages(const QString& s){
|
|
|
|
QPixmap p = QPixmap(s).scaled(128,128, Qt::KeepAspectRatio);
|
|
|
|
SPixmap ret;
|
|
|
|
ret.first = s;
|
|
|
|
ret.second = p;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-30 18:16:00 +00:00
|
|
|
void DivePictureModel::updateDivePictures(int divenr)
|
|
|
|
{
|
2014-05-31 03:42:54 +00:00
|
|
|
qDebug() << "Updating dive pictures.";
|
2014-05-30 18:16:00 +00:00
|
|
|
beginRemoveRows(QModelIndex(), 0, numberOfPictures-1);
|
|
|
|
numberOfPictures = 0;
|
|
|
|
endRemoveRows();
|
|
|
|
|
2014-05-31 03:42:54 +00:00
|
|
|
QStringList pictures;
|
2014-05-30 18:16:00 +00:00
|
|
|
struct dive *d = get_dive(divenr);
|
2014-05-31 03:42:54 +00:00
|
|
|
if (!d){
|
|
|
|
qDebug() << "Got no dive, exiting.";
|
2014-05-30 18:16:00 +00:00
|
|
|
return;
|
2014-05-31 03:42:54 +00:00
|
|
|
}
|
2014-05-30 18:16:00 +00:00
|
|
|
// All pictures are set in *all* divecomputers. ( waste of memory if > 100 pictures? )
|
|
|
|
// so just get from the first one.
|
|
|
|
struct event *ev = d->dc.events;
|
|
|
|
while(ev){
|
|
|
|
if(ev->type == 123){ // 123 means PICTURE.
|
|
|
|
numberOfPictures++;
|
2014-05-31 03:42:54 +00:00
|
|
|
pictures.push_back(QString(ev->name));
|
2014-05-30 18:16:00 +00:00
|
|
|
}
|
|
|
|
ev = ev->next;
|
|
|
|
}
|
|
|
|
|
2014-05-31 03:42:54 +00:00
|
|
|
SPixmapList retList = QtConcurrent::blockingMapped<SPixmapList>( pictures, scaleImages);
|
|
|
|
Q_FOREACH(const SPixmap & pixmap, retList)
|
|
|
|
stringPixmapCache[pixmap.first] = pixmap.second;
|
|
|
|
|
|
|
|
if (numberOfPictures == 0){
|
|
|
|
qDebug() << "Got no pictures, exiting.";
|
2014-05-30 18:16:00 +00:00
|
|
|
return;
|
2014-05-31 03:42:54 +00:00
|
|
|
}
|
2014-05-30 18:16:00 +00:00
|
|
|
beginInsertRows(QModelIndex(), 0, numberOfPictures-1);
|
|
|
|
endInsertRows();
|
2014-05-31 03:42:54 +00:00
|
|
|
qDebug() << "Everything Ok.";
|
2014-05-30 18:16:00 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 17:38:27 +00:00
|
|
|
int DivePictureModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant DivePictureModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int DivePictureModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
2014-05-30 18:16:00 +00:00
|
|
|
return numberOfPictures;
|
2014-05-30 17:38:27 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 17:50:49 +00:00
|
|
|
DivePictureWidget::DivePictureWidget(QWidget *parent): QListView(parent)
|
2014-05-30 17:38:27 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|