pictures: turn QString into std::string for filenames

For undo of picture manipulation, it will be crucial that the
model and the core have the same order of pictures. The first
sort criterion will be time, the second filename in the case
that two pictures have, for whatever reason, the same timestamp.

However in the core we us C-strings and thus sort byte-wise
using strcmp. In the Qt-part we use QStrings, which sort according
to unicode encoding. To enable consistent sorting, change the
Qt-part to std::string, which uses a C-style 0-terminated string
as its backing store.

One might argue that in general filenames should use system-encoding
and therefore use std::string instead of QString. However, a
broader conversion to std::string turned out to be very painful,
since Qt is (deliberately?) difficult to use with std::string.
Notable all the file-manipulation functions don't take std::string
by default. Thus, this commit only converts the internal data
of DivePictureModel, but continues to use QString for the Qt-facing
interface.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-05-04 09:47:55 +02:00 committed by Dirk Hohndel
parent c50e58d761
commit 4d407dc666
2 changed files with 24 additions and 14 deletions

View file

@ -8,9 +8,11 @@
#include <QImage>
#include <QFuture>
// We use std::string instead of QString to use the same character-encoding
// as in the C core (UTF-8). This is crucial to guarantee the same sort-order.
struct PictureEntry {
int diveId;
QString filename;
std::string filename;
QImage image;
int offsetSeconds;
duration_t length;
@ -34,7 +36,7 @@ public slots:
private:
DivePictureModel();
QVector<PictureEntry> pictures;
int findPictureId(const QString &filename); // Return -1 if not found
int findPictureId(const std::string &filename); // Return -1 if not found
double zoomLevel; // -1.0: minimum, 0.0: standard, 1.0: maximum
int size;
void updateThumbnails();