Profile: On dataChanged() only update pictures that actually changed

Only update those pictures of the DivePictureModel that actually changed.
This will be useful once pictures are loaded incrementally.

To do so, replace the pictures array by an array with stable ids. Before
this commit, not-shown pictures are left out of the pictures array, which
makes the mapping from DivePictureModel-ids to the picture array index
non-trivial.

Replace the QList<DivePictureItem *> by a std::vector<std::unique_ptr<DivePictureItem>>
to ease memory management. Sadly, owing to COW semantics, QVector is incompatible
with QScopedPointer.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-04-06 17:58:16 +02:00 committed by Dirk Hohndel
parent f633cb81ae
commit f1830cd44e
2 changed files with 45 additions and 17 deletions

View file

@ -3,6 +3,8 @@
#define PROFILEWIDGET2_H
#include <QGraphicsView>
#include <vector>
#include <memory>
// /* The idea of this widget is to display and edit the profile.
// * It has:
@ -121,6 +123,7 @@ slots: // Necessary to call from QAction's signals.
void deleteCurrentDC();
void pointInserted(const QModelIndex &parent, int start, int end);
void pointsRemoved(const QModelIndex &, int start, int end);
void updatePictures(const QModelIndex &from, const QModelIndex &to);
/* this is called for every move on the handlers. maybe we can speed up this a bit? */
void recreatePlannedDive();
@ -164,6 +167,7 @@ private: /*methods*/
void addActionShortcut(const Qt::Key shortcut, void (ProfileWidget2::*slot)());
void createPPGas(PartialPressureGasItem *item, int verticalColumn, color_index_t color, color_index_t colorAlert,
double *thresholdSettingsMin, double *thresholdSettingsMax);
void clearPictures();
private:
DivePlotDataModel *dataModel;
int zoomLevel;
@ -217,7 +221,9 @@ private:
bool printMode;
QList<QGraphicsSimpleTextItem *> gases;
QList<DivePictureItem *> pictures;
// Use std::vector<> and std::unique_ptr<>, because QVector<QScopedPointer<...>> is unsupported.
std::vector<std::unique_ptr<DivePictureItem>> pictures;
//specifics for ADD and PLAN
#ifndef SUBSURFACE_MOBILE