Printing: fix dive lookup for profile generation

The existing code (and templates) looked up dives by number and then used
that as index into the dive table. This worked exactly in one case: if all
dives were numbered consecutively starting with 1. While that is not an
entirely unreasonable case, it's of course not an acceptable assumption to
make.

This commit adds the necessary changes to instead look up dives by their
unique id. That's what it's there fore, after all.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-07-28 13:35:04 -07:00
parent be47ce6241
commit a4608f7c91
5 changed files with 15 additions and 4 deletions

View file

@ -92,8 +92,9 @@ void Printer::render(int Pages = 0)
// render all the dive profiles in the current page // render all the dive profiles in the current page
while (elemNo < collection.count() && collection.at(elemNo).geometry().y() < viewPort.y() + viewPort.height()) { while (elemNo < collection.count() && collection.at(elemNo).geometry().y() < viewPort.y() + viewPort.height()) {
// dive id field should be dive_{{dive_no}} se we remove the first 5 characters // dive id field should be dive_{{dive_no}} se we remove the first 5 characters
int diveNo = collection.at(elemNo).attribute("id").remove(0, 5).toInt(0, 10); QString diveIdString = collection.at(elemNo).attribute("id");
putProfileImage(collection.at(elemNo).geometry(), viewPort, &painter, get_dive(diveNo - 1), profile); int diveId = diveIdString.remove(0, 5).toInt(0, 10);
putProfileImage(collection.at(elemNo).geometry(), viewPort, &painter, get_dive_by_uniq_id(diveId), profile);
elemNo++; elemNo++;
} }

View file

@ -103,7 +103,7 @@
<div class="mainContainer"> <div class="mainContainer">
<div class="innerContainer"> <div class="innerContainer">
<div class="diveDetails"> <div class="diveDetails">
<div class="diveProfile" id="dive_{{ dive.number }}"> <div class="diveProfile" id="dive_{{ dive.id }}">
</div> </div>
<div class="dataSection"> <div class="dataSection">
<table class="table_class"> <table class="table_class">

View file

@ -196,7 +196,7 @@
</td> </td>
</tr> </tr>
</tbody></table> </tbody></table>
<div class="diveProfile" id="dive_{{ dive.number }}"> <div class="diveProfile" id="dive_{{ dive.id }}">
</div> </div>
</div> </div>
<div class="notesPart"> <div class="notesPart">

View file

@ -133,6 +133,11 @@ int Dive::number() const
return m_number; return m_number;
} }
int Dive::id() const
{
return m_id;
}
QString Dive::date() const QString Dive::date() const
{ {
return m_date; return m_date;

View file

@ -31,6 +31,7 @@ signals:
class Dive { class Dive {
private: private:
int m_number; int m_number;
int m_id;
QString m_date; QString m_date;
QString m_time; QString m_time;
QString m_location; QString m_location;
@ -56,6 +57,7 @@ public:
: dive(dive) : dive(dive)
{ {
m_number = dive->number; m_number = dive->number;
m_id = dive->id;
put_date_time(); put_date_time();
put_location(); put_location();
put_duration(); put_duration();
@ -68,6 +70,7 @@ public:
Dive(); Dive();
~Dive(); ~Dive();
int number() const; int number() const;
int id() const;
QString date() const; QString date() const;
QString time() const; QString time() const;
QString location() const; QString location() const;
@ -87,6 +90,8 @@ Q_DECLARE_METATYPE(print_options)
GRANTLEE_BEGIN_LOOKUP(Dive) GRANTLEE_BEGIN_LOOKUP(Dive)
if (property == "number") if (property == "number")
return object.number(); return object.number();
else if (property == "id")
return object.id();
else if (property == "date") else if (property == "date")
return object.date(); return object.date();
else if (property == "time") else if (property == "time")