summaryrefslogtreecommitdiffstats
path: root/qt-ui/divepicturewidget.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-06-02 18:41:19 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-03 00:01:13 -0700
commit42f36d6315f9eda15f982ee1f7fce3ec7c6cedf2 (patch)
treec251786a89b64ca565cd17e8558a8e3aabb1e01a /qt-ui/divepicturewidget.cpp
parentd95d1735b5f0fec2941696a4bb1720eb00a6f59c (diff)
downloadsubsurface-42f36d6315f9eda15f982ee1f7fce3ec7c6cedf2.tar.gz
Update the picture model to use the new picture function calls.
Update the picture model to use the new picture function calls, wich made the code smaller and easyer to understand. AND as a plus, it doesn't use the magic 123 identifier for pictures. AND it correctly adds images without timestamp to the list. 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.cpp35
1 files changed, 13 insertions, 22 deletions
diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp
index eda4ff68c..d0155bd0f 100644
--- a/qt-ui/divepicturewidget.cpp
+++ b/qt-ui/divepicturewidget.cpp
@@ -15,7 +15,7 @@ DivePictureModel::DivePictureModel(QObject *parent): QAbstractTableModel(parent)
typedef QPair<QString, QPixmap> SPixmap;
typedef QList<SPixmap> SPixmapList;
-SPixmap scaleImages(const QString& s){
+SPixmap scaleImages(const QString& s) {
QPixmap p = QPixmap(s).scaled(128,128, Qt::KeepAspectRatio);
SPixmap ret;
ret.first = s;
@@ -25,39 +25,30 @@ SPixmap scaleImages(const QString& s){
void DivePictureModel::updateDivePictures(int divenr)
{
- qDebug() << "Updating dive pictures.";
- beginRemoveRows(QModelIndex(), 0, numberOfPictures-1);
- numberOfPictures = 0;
- endRemoveRows();
+ if (numberOfPictures != 0) {
+ beginRemoveRows(QModelIndex(), 0, numberOfPictures-1);
+ numberOfPictures = 0;
+ endRemoveRows();
+ }
- QStringList pictures;
struct dive *d = get_dive(divenr);
- if (!d){
- qDebug() << "Got no dive, exiting.";
+ int numberOfPictures = dive_get_picture_count(d);
+ if (!d || numberOfPictures == 0) {
return;
}
- // 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++;
- pictures.push_back(QString(ev->name));
- }
- ev = ev->next;
+
+ QStringList pictures;
+ FOR_EACH_PICTURE( d ) {
+ 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;
- if (numberOfPictures == 0){
- qDebug() << "Got no pictures, exiting.";
- return;
- }
beginInsertRows(QModelIndex(), 0, numberOfPictures-1);
endInsertRows();
- qDebug() << "Everything Ok.";
}
int DivePictureModel::columnCount(const QModelIndex &parent) const