mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
Add threaded processing of image pixmaps
This code adds threaded processing of a batch of images. It uses the QtConcurrent implementations to call a function repeteadly using MAX_THREADS (Qt gets that for us) and returns a list of it. This call is blocking, so while the pixmaps are being scaled in threads, it will wait for all scalling to be done. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
e140703d34
commit
f1d67cfbac
2 changed files with 30 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "divepicturewidget.h"
|
#include "divepicturewidget.h"
|
||||||
#include <dive.h>
|
#include <dive.h>
|
||||||
|
#include <qtconcurrentmap.h>
|
||||||
|
|
||||||
void DivePictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void DivePictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
|
@ -11,29 +12,52 @@ DivePictureModel::DivePictureModel(QObject *parent): QAbstractTableModel(parent)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
void DivePictureModel::updateDivePictures(int divenr)
|
void DivePictureModel::updateDivePictures(int divenr)
|
||||||
{
|
{
|
||||||
|
qDebug() << "Updating dive pictures.";
|
||||||
beginRemoveRows(QModelIndex(), 0, numberOfPictures-1);
|
beginRemoveRows(QModelIndex(), 0, numberOfPictures-1);
|
||||||
numberOfPictures = 0;
|
numberOfPictures = 0;
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
|
QStringList pictures;
|
||||||
struct dive *d = get_dive(divenr);
|
struct dive *d = get_dive(divenr);
|
||||||
if (!d)
|
if (!d){
|
||||||
|
qDebug() << "Got no dive, exiting.";
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
// All pictures are set in *all* divecomputers. ( waste of memory if > 100 pictures? )
|
// All pictures are set in *all* divecomputers. ( waste of memory if > 100 pictures? )
|
||||||
// so just get from the first one.
|
// so just get from the first one.
|
||||||
struct event *ev = d->dc.events;
|
struct event *ev = d->dc.events;
|
||||||
while(ev){
|
while(ev){
|
||||||
if(ev->type == 123){ // 123 means PICTURE.
|
if(ev->type == 123){ // 123 means PICTURE.
|
||||||
numberOfPictures++;
|
numberOfPictures++;
|
||||||
|
pictures.push_back(QString(ev->name));
|
||||||
}
|
}
|
||||||
ev = ev->next;
|
ev = ev->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numberOfPictures == 0)
|
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;
|
return;
|
||||||
|
}
|
||||||
beginInsertRows(QModelIndex(), 0, numberOfPictures-1);
|
beginInsertRows(QModelIndex(), 0, numberOfPictures-1);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
qDebug() << "Everything Ok.";
|
||||||
}
|
}
|
||||||
|
|
||||||
int DivePictureModel::columnCount(const QModelIndex &parent) const
|
int DivePictureModel::columnCount(const QModelIndex &parent) const
|
||||||
|
|
|
@ -16,6 +16,10 @@ public:
|
||||||
void updateDivePictures(int divenr);
|
void updateDivePictures(int divenr);
|
||||||
private:
|
private:
|
||||||
int numberOfPictures;
|
int numberOfPictures;
|
||||||
|
// 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, QPixmap> stringPixmapCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DivePictureDelegate : QStyledItemDelegate {
|
class DivePictureDelegate : QStyledItemDelegate {
|
||||||
|
|
Loading…
Reference in a new issue