summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/divepicturewidget.cpp33
-rw-r--r--qt-ui/divepicturewidget.h6
-rw-r--r--qt-ui/mainwindow.cpp4
-rw-r--r--qt-ui/mainwindow.h1
4 files changed, 42 insertions, 2 deletions
diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp
index a74bba0e6..11849af5f 100644
--- a/qt-ui/divepicturewidget.cpp
+++ b/qt-ui/divepicturewidget.cpp
@@ -1,10 +1,41 @@
#include "divepicturewidget.h"
+#include <dive.h>
void DivePictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyledItemDelegate::paint(painter, option, index);
}
+DivePictureModel::DivePictureModel(QObject *parent): QAbstractTableModel(parent)
+{
+
+}
+
+void DivePictureModel::updateDivePictures(int divenr)
+{
+ beginRemoveRows(QModelIndex(), 0, numberOfPictures-1);
+ numberOfPictures = 0;
+ endRemoveRows();
+
+ struct dive *d = get_dive(divenr);
+ if (!d)
+ 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++;
+ }
+ ev = ev->next;
+ }
+
+ if (numberOfPictures == 0)
+ return;
+ beginInsertRows(QModelIndex(), 0, numberOfPictures-1);
+ endInsertRows();
+}
+
int DivePictureModel::columnCount(const QModelIndex &parent) const
{
@@ -17,7 +48,7 @@ QVariant DivePictureModel::data(const QModelIndex &index, int role) const
int DivePictureModel::rowCount(const QModelIndex &parent) const
{
-
+ return numberOfPictures;
}
DivePictureWidget::DivePictureWidget(QWidget *parent): QListView(parent)
diff --git a/qt-ui/divepicturewidget.h b/qt-ui/divepicturewidget.h
index 7761db32b..062e225d7 100644
--- a/qt-ui/divepicturewidget.h
+++ b/qt-ui/divepicturewidget.h
@@ -7,9 +7,15 @@
#include <QThread>
class DivePictureModel : QAbstractTableModel {
+Q_OBJECT
+public:
+ DivePictureModel(QObject *parent);
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ void updateDivePictures(int divenr);
+private:
+ int numberOfPictures;
};
class DivePictureDelegate : QStyledItemDelegate {
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index dad8e4706..964d2bbc2 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -59,7 +59,8 @@ MainWindow::MainWindow() : QMainWindow(),
yearlyStatsModel(0),
state(VIEWALL),
updateManager(0),
- fakeDiveId(0)
+ fakeDiveId(0),
+ divePictureModel(new DivePictureModel(this))
{
Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!");
m_Instance = this;
@@ -165,6 +166,7 @@ void MainWindow::current_dive_changed(int divenr)
*/
ui.newProfile->plotDives(QList<dive *>() << (current_dive));
ui.InfoWidget->updateDiveInfo(divenr);
+ divePictureModel->updateDivePictures(divenr);
}
void MainWindow::on_actionNew_triggered()
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index 57c205ba4..c8c792ed4 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -180,6 +180,7 @@ private:
bool plannerStateClean();
void createFakeDiveForAddAndPlan();
int fakeDiveId;
+ DivePictureModel *divePictureModel;
};
#endif // MAINWINDOW_H