aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/divepicturewidget.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-05-29 14:42:57 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-29 14:14:27 -0700
commitffc0c8ee993ce6301b8f6c0992b6e1652d2b08d7 (patch)
tree46b2584896a04437ec8d61d4ecc8dc41b3d6259a /qt-ui/divepicturewidget.cpp
parent37bd82f623ae2fc89a53d8193e7a308b7a2910c3 (diff)
downloadsubsurface-ffc0c8ee993ce6301b8f6c0992b6e1652d2b08d7.tar.gz
Move DivePictureModel to qt-models
This class will surely be used on the mobile version, and it was very tangled inside divepicturewidget. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divepicturewidget.cpp')
-rw-r--r--qt-ui/divepicturewidget.cpp125
1 files changed, 3 insertions, 122 deletions
diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp
index 8c1cb3571..bed3d3bd1 100644
--- a/qt-ui/divepicturewidget.cpp
+++ b/qt-ui/divepicturewidget.cpp
@@ -1,4 +1,5 @@
#include "divepicturewidget.h"
+#include "divepicturemodel.h"
#include "metrics.h"
#include "dive.h"
#include "divelist.h"
@@ -14,7 +15,7 @@
#include <qthelper.h>
#include <QStandardPaths>
-void loadPicuture(struct picture *picture)
+void loadPicture(struct picture *picture)
{
ImageDownloader download(picture);
download.load();
@@ -31,7 +32,7 @@ SHashedImage::SHashedImage(struct picture *picture) : QImage()
if (!isNull()) {
QtConcurrent::run(updateHash, picture);
} else {
- QtConcurrent::run(loadPicuture, picture);
+ QtConcurrent::run(loadPicture, picture);
}
} else {
QByteArray hash = hashFile(url.toLocalFile());
@@ -87,126 +88,6 @@ void ImageDownloader::saveImage(QNetworkReply *reply)
reply->deleteLater();
}
-DivePictureModel *DivePictureModel::instance()
-{
- static DivePictureModel *self = new DivePictureModel();
- return self;
-}
-
-DivePictureModel::DivePictureModel() : numberOfPictures(0)
-{
-}
-
-typedef struct picture *picturepointer;
-typedef QPair<picturepointer, QImage> SPixmap;
-typedef QList<struct picture *> SPictureList;
-
-SPixmap scaleImages(picturepointer picture)
-{
- static QHash <QString, QImage > cache;
- SPixmap ret;
- ret.first = picture;
- if (cache.contains(picture->filename) && !cache.value(picture->filename).isNull()) {
- ret.second = cache.value(picture->filename);
- } else {
- int dim = defaultIconMetrics().sz_pic;
- QImage p = SHashedImage(picture);
- if(!p.isNull())
- p = p.scaled(dim, dim, Qt::KeepAspectRatio);
- cache.insert(picture->filename, p);
- ret.second = p;
- }
- return ret;
-}
-
-void DivePictureModel::updateDivePicturesWhenDone(QList<QFuture<void> > futures)
-{
- Q_FOREACH (QFuture<void> f, futures) {
- f.waitForFinished();
- }
- updateDivePictures();
-}
-
-void DivePictureModel::updateDivePictures()
-{
- if (numberOfPictures != 0) {
- beginRemoveRows(QModelIndex(), 0, numberOfPictures - 1);
- numberOfPictures = 0;
- endRemoveRows();
- }
-
- // if the dive_table is empty, ignore the displayed_dive
- numberOfPictures = dive_table.nr == 0 ? 0 : dive_get_picture_count(&displayed_dive);
- if (numberOfPictures == 0) {
- return;
- }
-
- stringPixmapCache.clear();
- SPictureList pictures;
- FOR_EACH_PICTURE_NON_PTR(displayed_dive) {
- stringPixmapCache[QString(picture->filename)].offsetSeconds = picture->offset.seconds;
- pictures.push_back(picture);
- }
-
- QList<SPixmap> list = QtConcurrent::blockingMapped(pictures, scaleImages);
- Q_FOREACH (const SPixmap &pixmap, list)
- stringPixmapCache[pixmap.first->filename].image = pixmap.second;
-
- beginInsertRows(QModelIndex(), 0, numberOfPictures - 1);
- endInsertRows();
-}
-
-int DivePictureModel::columnCount(const QModelIndex &parent) const
-{
- return 2;
-}
-
-QVariant DivePictureModel::data(const QModelIndex &index, int role) const
-{
- QVariant ret;
- if (!index.isValid())
- return ret;
-
- QString key = stringPixmapCache.keys().at(index.row());
- 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();
- break;
- case Qt::DisplayPropertyRole:
- ret = QFileInfo(key).filePath();
- }
- } else if (index.column() == 1) {
- switch (role) {
- case Qt::UserRole:
- ret = QVariant::fromValue((int)stringPixmapCache[key].offsetSeconds);
- break;
- case Qt::DisplayRole:
- ret = key;
- }
- }
- return ret;
-}
-
-void DivePictureModel::removePicture(const QString &fileUrl)
-{
- dive_remove_picture(fileUrl.toUtf8().data());
- copy_dive(current_dive, &displayed_dive);
- updateDivePictures();
- mark_divelist_changed(true);
-}
-
-int DivePictureModel::rowCount(const QModelIndex &parent) const
-{
- return numberOfPictures;
-}
-
DivePictureWidget::DivePictureWidget(QWidget *parent) : QListView(parent)
{
connect(this, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(doubleClicked(const QModelIndex &)));