mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Massive automated whitespace cleanup
I know everyone will hate it. Go ahead. Complain. Call me names. At least now things are consistent and reproducible. If you want changes, have your complaint come with a patch to scripts/whitespace.pl so that we can automate it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
006265d7a0
commit
76e6420f6b
114 changed files with 4370 additions and 3717 deletions
34
cochran.c
34
cochran.c
|
@ -30,12 +30,12 @@
|
|||
* 230 bytes and 234 bytes respectively.
|
||||
*/
|
||||
static unsigned int partial_decode(unsigned int start, unsigned int end,
|
||||
const unsigned char *decode, unsigned offset, unsigned mod,
|
||||
const unsigned char *buf, unsigned int size, unsigned char *dst)
|
||||
const unsigned char *decode, unsigned offset, unsigned mod,
|
||||
const unsigned char *buf, unsigned int size, unsigned char *dst)
|
||||
{
|
||||
unsigned i, sum = 0;
|
||||
|
||||
for (i = start ; i < end; i++) {
|
||||
for (i = start; i < end; i++) {
|
||||
unsigned char d = decode[offset++];
|
||||
if (i >= size)
|
||||
break;
|
||||
|
@ -79,7 +79,7 @@ static int figure_out_modulus(const unsigned char *decode, const unsigned char *
|
|||
return best;
|
||||
}
|
||||
|
||||
#define hexchar(n) ("0123456789abcdef"[(n)&15])
|
||||
#define hexchar(n) ("0123456789abcdef"[(n) & 15])
|
||||
|
||||
static int show_line(unsigned offset, const unsigned char *data, unsigned size, int show_empty)
|
||||
{
|
||||
|
@ -94,11 +94,11 @@ static int show_line(unsigned offset, const unsigned char *data, unsigned size,
|
|||
memset(buffer, ' ', sizeof(buffer));
|
||||
off = sprintf(buffer, "%06x ", offset);
|
||||
for (i = 0; i < size; i++) {
|
||||
char *hex = buffer + off + 3*i;
|
||||
char *hex = buffer + off + 3 * i;
|
||||
char *asc = buffer + off + 50 + i;
|
||||
unsigned char byte = data[i];
|
||||
|
||||
hex[0] = hexchar(byte>>4);
|
||||
hex[0] = hexchar(byte >> 4);
|
||||
hex[1] = hexchar(byte);
|
||||
bits |= byte;
|
||||
if (byte < 32 || byte > 126)
|
||||
|
@ -125,13 +125,13 @@ static void cochran_debug_write(const char *filename, const unsigned char *data,
|
|||
}
|
||||
|
||||
static void parse_cochran_header(const char *filename,
|
||||
const unsigned char *decode, unsigned mod,
|
||||
const unsigned char *in, unsigned size)
|
||||
const unsigned char *decode, unsigned mod,
|
||||
const unsigned char *in, unsigned size)
|
||||
{
|
||||
char *buf = malloc(size);
|
||||
|
||||
/* Do the "null decode" using a one-byte decode array of '\0' */
|
||||
partial_decode(0 , 0x0b14, "", 0, 1, in, size, buf);
|
||||
partial_decode(0, 0x0b14, "", 0, 1, in, size, buf);
|
||||
|
||||
/*
|
||||
* The header scrambling is different form the dive
|
||||
|
@ -142,7 +142,7 @@ static void parse_cochran_header(const char *filename,
|
|||
partial_decode(0x1b14, 0x2b14, decode, 0, mod, in, size, buf);
|
||||
partial_decode(0x2b14, 0x3b14, decode, 0, mod, in, size, buf);
|
||||
partial_decode(0x3b14, 0x5414, decode, 0, mod, in, size, buf);
|
||||
partial_decode(0x5414, size, decode, 0, mod, in, size, buf);
|
||||
partial_decode(0x5414, size, decode, 0, mod, in, size, buf);
|
||||
|
||||
printf("\n%s, header\n\n", filename);
|
||||
cochran_debug_write(filename, buf, size);
|
||||
|
@ -204,13 +204,13 @@ static void cochran_profile_write(const unsigned char *buf, int size)
|
|||
for (i = 0; i < size; i++) {
|
||||
unsigned char c = buf[i];
|
||||
printf("%d %d\n",
|
||||
c >> 6, c & 0x3f);
|
||||
c >> 6, c & 0x3f);
|
||||
}
|
||||
}
|
||||
|
||||
static void parse_cochran_dive(const char *filename, int dive,
|
||||
const unsigned char *decode, unsigned mod,
|
||||
const unsigned char *in, unsigned size)
|
||||
const unsigned char *decode, unsigned mod,
|
||||
const unsigned char *in, unsigned size)
|
||||
{
|
||||
char *buf = malloc(size);
|
||||
#ifdef DON
|
||||
|
@ -229,7 +229,7 @@ static void parse_cochran_dive(const char *filename, int dive,
|
|||
* the same way the file size is off by one. It's as if the
|
||||
* cochran software forgot to write one byte at the beginning.
|
||||
*/
|
||||
partial_decode(0 , 0x0fff, decode, 1, mod, in, size, buf);
|
||||
partial_decode(0, 0x0fff, decode, 1, mod, in, size, buf);
|
||||
partial_decode(0x0fff, 0x1fff, decode, 0, mod, in, size, buf);
|
||||
partial_decode(0x1fff, 0x2fff, decode, 0, mod, in, size, buf);
|
||||
partial_decode(0x2fff, 0x48ff, decode, 0, mod, in, size, buf);
|
||||
|
@ -241,7 +241,7 @@ static void parse_cochran_dive(const char *filename, int dive,
|
|||
* so this just descrambles part of it:
|
||||
*/
|
||||
partial_decode(0x48ff, offset, decode, 0, mod, in, size, buf);
|
||||
partial_decode(offset, size, decode, 0, mod, in, size, buf);
|
||||
partial_decode(offset, size, decode, 0, mod, in, size, buf);
|
||||
|
||||
printf("\n%s, dive %d\n\n", filename, dive);
|
||||
cochran_debug_write(filename, buf, size);
|
||||
|
@ -271,12 +271,12 @@ int try_to_open_cochran(const char *filename, struct memblock *mem, GError **err
|
|||
|
||||
for (i = 0; i < 65534; i++) {
|
||||
dive1 = offsets[i];
|
||||
dive2 = offsets[i+1];
|
||||
dive2 = offsets[i + 1];
|
||||
if (dive2 < dive1)
|
||||
break;
|
||||
if (dive2 > mem->size)
|
||||
break;
|
||||
parse_cochran_dive(filename, i+1, decode, mod, mem->buffer + dive1, dive2 - dive1);
|
||||
parse_cochran_dive(filename, i + 1, decode, mod, mem->buffer + dive1, dive2 - dive1);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
|
80
color.h
80
color.h
|
@ -7,54 +7,54 @@
|
|||
#include <QColor>
|
||||
|
||||
// Greens
|
||||
#define CAMARONE1 QColor::fromRgbF( 0.0, 0.4, 0.0, 1 )
|
||||
#define FUNGREEN1 QColor::fromRgbF( 0.0, 0.4, 0.2, 1 )
|
||||
#define FUNGREEN1_HIGH_TRANS QColor::fromRgbF( 0.0, 0.4, 0.2, 0.25 )
|
||||
#define KILLARNEY1 QColor::fromRgbF( 0.2, 0.4, 0.2, 1 )
|
||||
#define APPLE1 QColor::fromRgbF( 0.2, 0.6, 0.2, 1 )
|
||||
#define APPLE1_MED_TRANS QColor::fromRgbF( 0.2, 0.6, 0.2, 0.5 )
|
||||
#define APPLE1_HIGH_TRANS QColor::fromRgbF( 0.2, 0.6, 0.2, 0.25 )
|
||||
#define LIMENADE1 QColor::fromRgbF( 0.4, 0.8, 0.0, 1 )
|
||||
#define ATLANTIS1 QColor::fromRgbF( 0.4, 0.8, 0.2, 1 )
|
||||
#define ATLANTIS2 QColor::fromRgbF( 0.6, 0.8, 0.2, 1 )
|
||||
#define RIOGRANDE1 QColor::fromRgbF( 0.8, 0.8, 0.0, 1 )
|
||||
#define EARLSGREEN1 QColor::fromRgbF( 0.8, 0.8, 0.2, 1 )
|
||||
#define FORESTGREEN1 QColor::fromRgbF( 0.1, 0.5, 0.1, 1 )
|
||||
#define CAMARONE1 QColor::fromRgbF(0.0, 0.4, 0.0, 1)
|
||||
#define FUNGREEN1 QColor::fromRgbF(0.0, 0.4, 0.2, 1)
|
||||
#define FUNGREEN1_HIGH_TRANS QColor::fromRgbF(0.0, 0.4, 0.2, 0.25)
|
||||
#define KILLARNEY1 QColor::fromRgbF(0.2, 0.4, 0.2, 1)
|
||||
#define APPLE1 QColor::fromRgbF(0.2, 0.6, 0.2, 1)
|
||||
#define APPLE1_MED_TRANS QColor::fromRgbF(0.2, 0.6, 0.2, 0.5)
|
||||
#define APPLE1_HIGH_TRANS QColor::fromRgbF(0.2, 0.6, 0.2, 0.25)
|
||||
#define LIMENADE1 QColor::fromRgbF(0.4, 0.8, 0.0, 1)
|
||||
#define ATLANTIS1 QColor::fromRgbF(0.4, 0.8, 0.2, 1)
|
||||
#define ATLANTIS2 QColor::fromRgbF(0.6, 0.8, 0.2, 1)
|
||||
#define RIOGRANDE1 QColor::fromRgbF(0.8, 0.8, 0.0, 1)
|
||||
#define EARLSGREEN1 QColor::fromRgbF(0.8, 0.8, 0.2, 1)
|
||||
#define FORESTGREEN1 QColor::fromRgbF(0.1, 0.5, 0.1, 1)
|
||||
|
||||
// Reds
|
||||
#define PERSIANRED1 QColor::fromRgbF( 0.8, 0.2, 0.2, 1 )
|
||||
#define TUSCANY1 QColor::fromRgbF( 0.8, 0.4, 0.2, 1 )
|
||||
#define PIRATEGOLD1 QColor::fromRgbF( 0.8, 0.5, 0.0, 1 )
|
||||
#define HOKEYPOKEY1 QColor::fromRgbF( 0.8, 0.6, 0.2, 1 )
|
||||
#define CINNABAR1 QColor::fromRgbF( 0.9, 0.3, 0.2, 1 )
|
||||
#define REDORANGE1 QColor::fromRgbF( 1.0, 0.2, 0.2, 1 )
|
||||
#define REDORANGE1_HIGH_TRANS QColor::fromRgbF( 1.0, 0.2, 0.2, 0.25 )
|
||||
#define REDORANGE1_MED_TRANS QColor::fromRgbF( 1.0, 0.2, 0.2, 0.5 )
|
||||
#define RED1_MED_TRANS QColor::fromRgbF( 1.0, 0.0, 0.0, 0.5 )
|
||||
#define RED1 QColor::fromRgbF( 1.0, 0.0, 0.0, 1 )
|
||||
#define PERSIANRED1 QColor::fromRgbF(0.8, 0.2, 0.2, 1)
|
||||
#define TUSCANY1 QColor::fromRgbF(0.8, 0.4, 0.2, 1)
|
||||
#define PIRATEGOLD1 QColor::fromRgbF(0.8, 0.5, 0.0, 1)
|
||||
#define HOKEYPOKEY1 QColor::fromRgbF(0.8, 0.6, 0.2, 1)
|
||||
#define CINNABAR1 QColor::fromRgbF(0.9, 0.3, 0.2, 1)
|
||||
#define REDORANGE1 QColor::fromRgbF(1.0, 0.2, 0.2, 1)
|
||||
#define REDORANGE1_HIGH_TRANS QColor::fromRgbF(1.0, 0.2, 0.2, 0.25)
|
||||
#define REDORANGE1_MED_TRANS QColor::fromRgbF(1.0, 0.2, 0.2, 0.5)
|
||||
#define RED1_MED_TRANS QColor::fromRgbF(1.0, 0.0, 0.0, 0.5)
|
||||
#define RED1 QColor::fromRgbF(1.0, 0.0, 0.0, 1)
|
||||
|
||||
// Monochromes
|
||||
#define BLACK1 QColor::fromRgbF( 0.0, 0.0, 0.0, 1 )
|
||||
#define BLACK1_LOW_TRANS QColor::fromRgbF( 0.0, 0.0, 0.0, 0.75 )
|
||||
#define BLACK1_HIGH_TRANS QColor::fromRgbF( 0.0, 0.0, 0.0, 0.25 )
|
||||
#define TUNDORA1_MED_TRANS QColor::fromRgbF( 0.3, 0.3, 0.3, 0.5 )
|
||||
#define MERCURY1_MED_TRANS QColor::fromRgbF( 0.9, 0.9, 0.9, 0.5 )
|
||||
#define CONCRETE1_LOWER_TRANS QColor::fromRgbF( 0.95, 0.95, 0.95, 0.9 )
|
||||
#define WHITE1_MED_TRANS QColor::fromRgbF( 1.0, 1.0, 1.0, 0.5 )
|
||||
#define WHITE1 QColor::fromRgbF( 1.0, 1.0, 1.0, 1 )
|
||||
#define BLACK1 QColor::fromRgbF(0.0, 0.0, 0.0, 1)
|
||||
#define BLACK1_LOW_TRANS QColor::fromRgbF(0.0, 0.0, 0.0, 0.75)
|
||||
#define BLACK1_HIGH_TRANS QColor::fromRgbF(0.0, 0.0, 0.0, 0.25)
|
||||
#define TUNDORA1_MED_TRANS QColor::fromRgbF(0.3, 0.3, 0.3, 0.5)
|
||||
#define MERCURY1_MED_TRANS QColor::fromRgbF(0.9, 0.9, 0.9, 0.5)
|
||||
#define CONCRETE1_LOWER_TRANS QColor::fromRgbF(0.95, 0.95, 0.95, 0.9)
|
||||
#define WHITE1_MED_TRANS QColor::fromRgbF(1.0, 1.0, 1.0, 0.5)
|
||||
#define WHITE1 QColor::fromRgbF(1.0, 1.0, 1.0, 1)
|
||||
|
||||
// Blues
|
||||
#define GOVERNORBAY2 QColor::fromRgbF( 0.2, 0.2, 0.7, 1 )
|
||||
#define GOVERNORBAY1_MED_TRANS QColor::fromRgbF( 0.2, 0.2, 0.8, 0.5 )
|
||||
#define ROYALBLUE2 QColor::fromRgbF( 0.2, 0.2, 0.9, 1 )
|
||||
#define ROYALBLUE2_LOW_TRANS QColor::fromRgbF( 0.2, 0.2, 0.9, 0.75 )
|
||||
#define GOVERNORBAY2 QColor::fromRgbF(0.2, 0.2, 0.7, 1)
|
||||
#define GOVERNORBAY1_MED_TRANS QColor::fromRgbF(0.2, 0.2, 0.8, 0.5)
|
||||
#define ROYALBLUE2 QColor::fromRgbF(0.2, 0.2, 0.9, 1)
|
||||
#define ROYALBLUE2_LOW_TRANS QColor::fromRgbF(0.2, 0.2, 0.9, 0.75)
|
||||
|
||||
// Yellows / BROWNS
|
||||
#define SPRINGWOOD1 QColor::fromRgbF( 0.95, 0.95, 0.9, 1 )
|
||||
#define BROOM1_LOWER_TRANS QColor::fromRgbF( 1.0, 1.0, 0.1, 0.9 )
|
||||
#define PEANUT QColor::fromRgbF( 0.5, 0.2, 0.1, 1.0 )
|
||||
#define PEANUT_MED_TRANS QColor::fromRgbF( 0.5, 0.2, 0.1, 0.5 )
|
||||
#define SPRINGWOOD1 QColor::fromRgbF(0.95, 0.95, 0.9, 1)
|
||||
#define BROOM1_LOWER_TRANS QColor::fromRgbF(1.0, 1.0, 0.1, 0.9)
|
||||
#define PEANUT QColor::fromRgbF(0.5, 0.2, 0.1, 1.0)
|
||||
#define PEANUT_MED_TRANS QColor::fromRgbF(0.5, 0.2, 0.1, 0.5)
|
||||
// Magentas
|
||||
#define MEDIUMREDVIOLET1_HIGHER_TRANS QColor::fromRgbF( 0.7, 0.2, 0.7, 0.1 )
|
||||
#define MEDIUMREDVIOLET1_HIGHER_TRANS QColor::fromRgbF(0.7, 0.2, 0.7, 0.1)
|
||||
|
||||
#endif // COLOR_H
|
||||
|
|
88
deco.c
88
deco.c
|
@ -21,57 +21,59 @@
|
|||
|
||||
//! Option structure for Buehlmann decompression.
|
||||
struct buehlmann_config {
|
||||
double satmult; //! safety at inert gas accumulation as percentage of effect (more than 100).
|
||||
double desatmult; //! safety at inert gas depletion as percentage of effect (less than 100).
|
||||
unsigned int last_deco_stop_in_mtr; //! depth of last_deco_stop.
|
||||
double gf_high; //! gradient factor high (at surface).
|
||||
double gf_low; //! gradient factor low (at bottom/start of deco calculation).
|
||||
double gf_low_position_min; //! gf_low_position below surface_min_shallow.
|
||||
bool gf_low_at_maxdepth; //! if true, gf_low applies at max depth instead of at deepest ceiling.
|
||||
double satmult; //! safety at inert gas accumulation as percentage of effect (more than 100).
|
||||
double desatmult; //! safety at inert gas depletion as percentage of effect (less than 100).
|
||||
unsigned int last_deco_stop_in_mtr; //! depth of last_deco_stop.
|
||||
double gf_high; //! gradient factor high (at surface).
|
||||
double gf_low; //! gradient factor low (at bottom/start of deco calculation).
|
||||
double gf_low_position_min; //! gf_low_position below surface_min_shallow.
|
||||
bool gf_low_at_maxdepth; //! if true, gf_low applies at max depth instead of at deepest ceiling.
|
||||
};
|
||||
struct buehlmann_config buehlmann_config = { 1.0, 1.01, 0, 0.75, 0.35, 2.0, false };
|
||||
|
||||
const double buehlmann_N2_a[] = {1.1696, 1.0, 0.8618, 0.7562,
|
||||
0.62, 0.5043, 0.441, 0.4,
|
||||
0.375, 0.35, 0.3295, 0.3065,
|
||||
0.2835, 0.261, 0.248, 0.2327};
|
||||
const double buehlmann_N2_a[] = { 1.1696, 1.0, 0.8618, 0.7562,
|
||||
0.62, 0.5043, 0.441, 0.4,
|
||||
0.375, 0.35, 0.3295, 0.3065,
|
||||
0.2835, 0.261, 0.248, 0.2327 };
|
||||
|
||||
const double buehlmann_N2_b[] = {0.5578, 0.6514, 0.7222, 0.7825,
|
||||
0.8126, 0.8434, 0.8693, 0.8910,
|
||||
0.9092, 0.9222, 0.9319, 0.9403,
|
||||
0.9477, 0.9544, 0.9602, 0.9653};
|
||||
const double buehlmann_N2_b[] = { 0.5578, 0.6514, 0.7222, 0.7825,
|
||||
0.8126, 0.8434, 0.8693, 0.8910,
|
||||
0.9092, 0.9222, 0.9319, 0.9403,
|
||||
0.9477, 0.9544, 0.9602, 0.9653 };
|
||||
|
||||
const double buehlmann_N2_t_halflife[] = {5.0, 8.0, 12.5, 18.5,
|
||||
27.0, 38.3, 54.3, 77.0,
|
||||
109.0, 146.0, 187.0, 239.0,
|
||||
305.0, 390.0, 498.0, 635.0};
|
||||
const double buehlmann_N2_t_halflife[] = { 5.0, 8.0, 12.5, 18.5,
|
||||
27.0, 38.3, 54.3, 77.0,
|
||||
109.0, 146.0, 187.0, 239.0,
|
||||
305.0, 390.0, 498.0, 635.0 };
|
||||
|
||||
const double buehlmann_N2_factor_expositon_one_second[] = {
|
||||
2.30782347297664E-003, 1.44301447809736E-003, 9.23769302935806E-004, 6.24261986779007E-004,
|
||||
4.27777107246730E-004, 3.01585140931371E-004, 2.12729727268379E-004, 1.50020603047807E-004,
|
||||
1.05980191127841E-004, 7.91232600646508E-005, 6.17759153688224E-005, 4.83354552742732E-005,
|
||||
3.78761777920511E-005, 2.96212356654113E-005, 2.31974277413727E-005, 1.81926738960225E-005};
|
||||
3.78761777920511E-005, 2.96212356654113E-005, 2.31974277413727E-005, 1.81926738960225E-005
|
||||
};
|
||||
|
||||
const double buehlmann_He_a[] = { 1.6189, 1.383 , 1.1919, 1.0458,
|
||||
0.922 , 0.8205, 0.7305, 0.6502,
|
||||
0.595 , 0.5545, 0.5333, 0.5189,
|
||||
0.5181, 0.5176, 0.5172, 0.5119};
|
||||
const double buehlmann_He_a[] = { 1.6189, 1.383, 1.1919, 1.0458,
|
||||
0.922, 0.8205, 0.7305, 0.6502,
|
||||
0.595, 0.5545, 0.5333, 0.5189,
|
||||
0.5181, 0.5176, 0.5172, 0.5119 };
|
||||
|
||||
const double buehlmann_He_b[] = {0.4770, 0.5747, 0.6527, 0.7223,
|
||||
0.7582, 0.7957, 0.8279, 0.8553,
|
||||
0.8757, 0.8903, 0.8997, 0.9073,
|
||||
0.9122, 0.9171, 0.9217, 0.9267};
|
||||
const double buehlmann_He_b[] = { 0.4770, 0.5747, 0.6527, 0.7223,
|
||||
0.7582, 0.7957, 0.8279, 0.8553,
|
||||
0.8757, 0.8903, 0.8997, 0.9073,
|
||||
0.9122, 0.9171, 0.9217, 0.9267 };
|
||||
|
||||
const double buehlmann_He_t_halflife[] = {1.88, 3.02, 4.72, 6.99,
|
||||
10.21, 14.48, 20.53, 29.11,
|
||||
41.20, 55.19, 70.69, 90.34,
|
||||
115.29, 147.42, 188.24, 240.03};
|
||||
const double buehlmann_He_t_halflife[] = { 1.88, 3.02, 4.72, 6.99,
|
||||
10.21, 14.48, 20.53, 29.11,
|
||||
41.20, 55.19, 70.69, 90.34,
|
||||
115.29, 147.42, 188.24, 240.03 };
|
||||
|
||||
const double buehlmann_He_factor_expositon_one_second[] = {
|
||||
6.12608039419837E-003, 3.81800836683133E-003, 2.44456078654209E-003, 1.65134647076792E-003,
|
||||
1.13084424730725E-003, 7.97503165599123E-004, 5.62552521860549E-004, 3.96776399429366E-004,
|
||||
2.80360036664540E-004, 2.09299583354805E-004, 1.63410794820518E-004, 1.27869320250551E-004,
|
||||
1.00198406028040E-004, 7.83611475491108E-005, 6.13689891868496E-005, 4.81280465299827E-005};
|
||||
1.00198406028040E-004, 7.83611475491108E-005, 6.13689891868496E-005, 4.81280465299827E-005
|
||||
};
|
||||
|
||||
#define WV_PRESSURE 0.0627 // water vapor pressure in bar
|
||||
#define DECO_STOPS_MULTIPLIER_MM 3000.0
|
||||
|
@ -94,8 +96,7 @@ static double tissue_tolerance_calc(const struct dive *dive)
|
|||
double gf_low = buehlmann_config.gf_low;
|
||||
double surface = get_surface_pressure_in_mbar(dive, true) / 1000.0;
|
||||
|
||||
for (ci = 0; ci < 16; ci++)
|
||||
{
|
||||
for (ci = 0; ci < 16; ci++) {
|
||||
double tolerated;
|
||||
|
||||
tissue_inertgas_saturation = tissue_n2_sat[ci] + tissue_he_sat[ci];
|
||||
|
@ -106,22 +107,21 @@ static double tissue_tolerance_calc(const struct dive *dive)
|
|||
|
||||
if (!buehlmann_config.gf_low_at_maxdepth) {
|
||||
double lowest_ceiling = (buehlmann_inertgas_b * tissue_inertgas_saturation - gf_low * buehlmann_inertgas_a * buehlmann_inertgas_b) /
|
||||
((1.0 - buehlmann_inertgas_b) * gf_low + buehlmann_inertgas_b);
|
||||
((1.0 - buehlmann_inertgas_b) * gf_low + buehlmann_inertgas_b);
|
||||
if (lowest_ceiling > gf_low_pressure_this_dive)
|
||||
gf_low_pressure_this_dive = lowest_ceiling;
|
||||
}
|
||||
|
||||
tolerated = (-buehlmann_inertgas_a * buehlmann_inertgas_b * (gf_high * gf_low_pressure_this_dive - gf_low * surface) -
|
||||
(1.0 - buehlmann_inertgas_b) * (gf_high - gf_low) * gf_low_pressure_this_dive * surface +
|
||||
buehlmann_inertgas_b * (gf_low_pressure_this_dive - surface) * tissue_inertgas_saturation) /
|
||||
(1.0 - buehlmann_inertgas_b) * (gf_high - gf_low) * gf_low_pressure_this_dive * surface +
|
||||
buehlmann_inertgas_b * (gf_low_pressure_this_dive - surface) * tissue_inertgas_saturation) /
|
||||
(-buehlmann_inertgas_a * buehlmann_inertgas_b * (gf_high - gf_low) +
|
||||
(1.0 - buehlmann_inertgas_b)*(gf_low * gf_low_pressure_this_dive - gf_high * surface) +
|
||||
buehlmann_inertgas_b * (gf_low_pressure_this_dive - surface));
|
||||
(1.0 - buehlmann_inertgas_b) * (gf_low * gf_low_pressure_this_dive - gf_high * surface) +
|
||||
buehlmann_inertgas_b * (gf_low_pressure_this_dive - surface));
|
||||
|
||||
tolerated_by_tissue[ci] = tolerated;
|
||||
|
||||
if (tolerated > ret_tolerance_limit_ambient_pressure)
|
||||
{
|
||||
if (tolerated > ret_tolerance_limit_ambient_pressure) {
|
||||
ci_pointing_to_guiding_tissue = ci;
|
||||
ret_tolerance_limit_ambient_pressure = tolerated;
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ double n2_factor(int period_in_seconds, int ci)
|
|||
|
||||
if (period_in_seconds != cache[ci].last_period) {
|
||||
cache[ci].last_period = period_in_seconds;
|
||||
cache[ci].last_factor = 1 - pow(2.0, - period_in_seconds / (buehlmann_N2_t_halflife[ci] * 60));
|
||||
cache[ci].last_factor = 1 - pow(2.0, -period_in_seconds / (buehlmann_N2_t_halflife[ci] * 60));
|
||||
}
|
||||
|
||||
return cache[ci].last_factor;
|
||||
|
@ -166,7 +166,7 @@ double he_factor(int period_in_seconds, int ci)
|
|||
|
||||
if (period_in_seconds != cache[ci].last_period) {
|
||||
cache[ci].last_period = period_in_seconds;
|
||||
cache[ci].last_factor = 1 - pow(2.0, - period_in_seconds / (buehlmann_He_t_halflife[ci] * 60));
|
||||
cache[ci].last_factor = 1 - pow(2.0, -period_in_seconds / (buehlmann_He_t_halflife[ci] * 60));
|
||||
}
|
||||
|
||||
return cache[ci].last_factor;
|
||||
|
|
30
device.c
30
device.c
|
@ -63,19 +63,23 @@
|
|||
*/
|
||||
static int fill_samples(struct sample *s, int max_d, int avg_d, int max_t, double slope, double d_frac)
|
||||
{
|
||||
double t_frac = max_t*(1-avg_d/(double)max_d);
|
||||
double t_frac = max_t * (1 - avg_d / (double)max_d);
|
||||
int t1 = max_d / slope;
|
||||
int t4 = max_t - t1*d_frac;
|
||||
int t3 = t4-(t_frac-t1)/(1-d_frac);
|
||||
int t2 = t3-t1*(1-d_frac);
|
||||
int t4 = max_t - t1 * d_frac;
|
||||
int t3 = t4 - (t_frac - t1) / (1 - d_frac);
|
||||
int t2 = t3 - t1 * (1 - d_frac);
|
||||
|
||||
if (t1 < 0 || t1 > t2 || t2 > t3 || t3 > t4 || t4 > max_t)
|
||||
return 0;
|
||||
|
||||
s[1].time.seconds = t1; s[1].depth.mm = max_d;
|
||||
s[2].time.seconds = t2; s[2].depth.mm = max_d;
|
||||
s[3].time.seconds = t3; s[3].depth.mm = max_d * d_frac;
|
||||
s[4].time.seconds = t4; s[4].depth.mm = max_d * d_frac;
|
||||
s[1].time.seconds = t1;
|
||||
s[1].depth.mm = max_d;
|
||||
s[2].time.seconds = t2;
|
||||
s[2].depth.mm = max_d;
|
||||
s[3].time.seconds = t3;
|
||||
s[3].depth.mm = max_d * d_frac;
|
||||
s[4].time.seconds = t4;
|
||||
s[4].depth.mm = max_d * d_frac;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -88,8 +92,10 @@ static void fill_samples_no_avg(struct sample *s, int max_d, int max_t, double s
|
|||
{
|
||||
// shallow or short dives are just trapecoids based on the given slope
|
||||
if (max_d < 10000 || max_t < 600) {
|
||||
s[1].time.seconds = max_d / slope; s[1].depth.mm = max_d;
|
||||
s[2].time.seconds = max_t - max_d / slope; s[2].depth.mm = max_d;
|
||||
s[1].time.seconds = max_d / slope;
|
||||
s[1].depth.mm = max_d;
|
||||
s[2].time.seconds = max_t - max_d / slope;
|
||||
s[2].depth.mm = max_d;
|
||||
} else {
|
||||
s[1].time.seconds = max_d / slope;
|
||||
s[1].depth.mm = max_d;
|
||||
|
@ -102,7 +108,7 @@ static void fill_samples_no_avg(struct sample *s, int max_d, int max_t, double s
|
|||
}
|
||||
}
|
||||
|
||||
struct divecomputer* fake_dc(struct divecomputer* dc)
|
||||
struct divecomputer *fake_dc(struct divecomputer *dc)
|
||||
{
|
||||
static struct sample fake[6];
|
||||
static struct divecomputer fakedc;
|
||||
|
@ -139,7 +145,7 @@ struct divecomputer* fake_dc(struct divecomputer* dc)
|
|||
return &fakedc;
|
||||
}
|
||||
if (avg_d < max_d / 10 || avg_d >= max_d) {
|
||||
avg_d = (max_d+10000)/3;
|
||||
avg_d = (max_d + 10000) / 3;
|
||||
if (avg_d > max_d)
|
||||
avg_d = max_d * 2 / 3;
|
||||
}
|
||||
|
|
2
device.h
2
device.h
|
@ -6,7 +6,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct divecomputer *fake_dc(struct divecomputer* dc);
|
||||
extern struct divecomputer *fake_dc(struct divecomputer *dc);
|
||||
extern void create_device_node(const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname);
|
||||
extern void call_for_each_dc(void *f, void (*callback)(void *, const char *, uint32_t,
|
||||
const char *, const char *, const char *));
|
||||
|
|
15
display.h
15
display.h
|
@ -39,13 +39,20 @@ struct graphics_context {
|
|||
struct plot_info pi;
|
||||
};
|
||||
|
||||
typedef enum { SC_SCREEN, SC_PRINT } scale_mode_t;
|
||||
typedef enum {
|
||||
SC_SCREEN,
|
||||
SC_PRINT
|
||||
} scale_mode_t;
|
||||
|
||||
extern struct divecomputer *select_dc(struct divecomputer *main);
|
||||
extern void get_plot_details(struct graphics_context *gc, int time, struct membuffer *mb);
|
||||
|
||||
struct options {
|
||||
enum { PRETTY, TABLE, TWOPERPAGE } type;
|
||||
enum {
|
||||
PRETTY,
|
||||
TABLE,
|
||||
TWOPERPAGE
|
||||
} type;
|
||||
int print_selected;
|
||||
int color_selected;
|
||||
bool notes_up;
|
||||
|
@ -59,8 +66,8 @@ extern unsigned int amount_selected;
|
|||
extern int is_default_dive_computer_device(const char *);
|
||||
extern int is_default_dive_computer(const char *, const char *);
|
||||
|
||||
typedef void (*device_callback_t) (const char *name, void *userdata);
|
||||
int enumerate_devices (device_callback_t callback, void *userdata);
|
||||
typedef void (*device_callback_t)(const char *name, void *userdata);
|
||||
int enumerate_devices(device_callback_t callback, void *userdata);
|
||||
|
||||
extern const char *default_dive_computer_vendor;
|
||||
extern const char *default_dive_computer_product;
|
||||
|
|
179
dive.c
179
dive.c
|
@ -9,9 +9,9 @@
|
|||
|
||||
struct tag_entry *g_tag_list = NULL;
|
||||
|
||||
static const char* default_tags[] = {
|
||||
static const char *default_tags[] = {
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "boat"), QT_TRANSLATE_NOOP("gettextFromC", "shore"), QT_TRANSLATE_NOOP("gettextFromC", "drift"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "deep"), QT_TRANSLATE_NOOP("gettextFromC", "cavern") , QT_TRANSLATE_NOOP("gettextFromC", "ice"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "deep"), QT_TRANSLATE_NOOP("gettextFromC", "cavern"), QT_TRANSLATE_NOOP("gettextFromC", "ice"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "wreck"), QT_TRANSLATE_NOOP("gettextFromC", "cave"), QT_TRANSLATE_NOOP("gettextFromC", "altitude"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "pool"), QT_TRANSLATE_NOOP("gettextFromC", "lake"), QT_TRANSLATE_NOOP("gettextFromC", "river"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "night"), QT_TRANSLATE_NOOP("gettextFromC", "fresh"), QT_TRANSLATE_NOOP("gettextFromC", "student"),
|
||||
|
@ -48,22 +48,22 @@ void add_event(struct divecomputer *dc, int time, int type, int flags, int value
|
|||
int get_pressure_units(unsigned int mb, const char **units)
|
||||
{
|
||||
int pressure;
|
||||
const char* unit;
|
||||
const char *unit;
|
||||
struct units *units_p = get_units();
|
||||
|
||||
switch (units_p->pressure) {
|
||||
case PASCAL:
|
||||
pressure = mb * 100;
|
||||
unit = translate("gettextFromC","pascal");
|
||||
unit = translate("gettextFromC", "pascal");
|
||||
break;
|
||||
case BAR:
|
||||
default:
|
||||
pressure = (mb + 500) / 1000;
|
||||
unit = translate("gettextFromC","bar");
|
||||
unit = translate("gettextFromC", "bar");
|
||||
break;
|
||||
case PSI:
|
||||
pressure = mbar_to_PSI(mb);
|
||||
unit = translate("gettextFromC","psi");
|
||||
unit = translate("gettextFromC", "psi");
|
||||
break;
|
||||
}
|
||||
if (units)
|
||||
|
@ -100,12 +100,12 @@ double get_volume_units(unsigned int ml, int *frac, const char **units)
|
|||
case LITER:
|
||||
default:
|
||||
vol = ml / 1000.0;
|
||||
unit = translate("gettextFromC","l");
|
||||
unit = translate("gettextFromC", "l");
|
||||
decimals = 1;
|
||||
break;
|
||||
case CUFT:
|
||||
vol = ml_to_cuft(ml);
|
||||
unit = translate("gettextFromC","cuft");
|
||||
unit = translate("gettextFromC", "cuft");
|
||||
decimals = 2;
|
||||
break;
|
||||
}
|
||||
|
@ -134,12 +134,12 @@ double get_depth_units(unsigned int mm, int *frac, const char **units)
|
|||
case METERS:
|
||||
default:
|
||||
d = mm / 1000.0;
|
||||
unit = translate("gettextFromC","m");
|
||||
unit = translate("gettextFromC", "m");
|
||||
decimals = d < 20;
|
||||
break;
|
||||
case FEET:
|
||||
d = mm_to_feet(mm);
|
||||
unit = translate("gettextFromC","ft");
|
||||
unit = translate("gettextFromC", "ft");
|
||||
decimals = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -161,11 +161,11 @@ double get_vertical_speed_units(unsigned int mms, int *frac, const char **units)
|
|||
case METERS:
|
||||
default:
|
||||
d = mms / 1000.0 * time_factor;
|
||||
unit = translate("gettextFromC",(units_p->vertical_speed_time == MINUTES) ? "m/min" : "m/s");
|
||||
unit = translate("gettextFromC", (units_p->vertical_speed_time == MINUTES) ? "m/min" : "m/s");
|
||||
break;
|
||||
case FEET:
|
||||
d = mm_to_feet(mms) * time_factor;
|
||||
unit = translate("gettextFromC",(units_p->vertical_speed_time == MINUTES) ? "ft/min" : "ft/s");
|
||||
unit = translate("gettextFromC", (units_p->vertical_speed_time == MINUTES) ? "ft/min" : "ft/s");
|
||||
break;
|
||||
}
|
||||
if (frac)
|
||||
|
@ -179,16 +179,16 @@ double get_weight_units(unsigned int grams, int *frac, const char **units)
|
|||
{
|
||||
int decimals;
|
||||
double value;
|
||||
const char* unit;
|
||||
const char *unit;
|
||||
struct units *units_p = get_units();
|
||||
|
||||
if (units_p->weight == LBS) {
|
||||
value = grams_to_lbs(grams);
|
||||
unit = translate("gettextFromC","lbs");
|
||||
unit = translate("gettextFromC", "lbs");
|
||||
decimals = 0;
|
||||
} else {
|
||||
value = grams / 1000.0;
|
||||
unit = translate("gettextFromC","kg");
|
||||
unit = translate("gettextFromC", "kg");
|
||||
decimals = 1;
|
||||
}
|
||||
if (frac)
|
||||
|
@ -255,7 +255,7 @@ struct sample *prepare_sample(struct divecomputer *dc)
|
|||
if (nr >= alloc_samples) {
|
||||
struct sample *newsamples;
|
||||
|
||||
alloc_samples = (alloc_samples * 3)/2 + 10;
|
||||
alloc_samples = (alloc_samples * 3) / 2 + 10;
|
||||
newsamples = realloc(dc->sample, alloc_samples * sizeof(struct sample));
|
||||
if (!newsamples)
|
||||
return NULL;
|
||||
|
@ -333,21 +333,21 @@ static void fixup_dc_duration(struct divecomputer *dc)
|
|||
/* We ignore segments at the surface */
|
||||
if (depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD) {
|
||||
duration += time - lasttime;
|
||||
depthtime += (time - lasttime)*(depth+lastdepth)/2;
|
||||
depthtime += (time - lasttime) * (depth + lastdepth) / 2;
|
||||
}
|
||||
lastdepth = depth;
|
||||
lasttime = time;
|
||||
}
|
||||
if (duration) {
|
||||
dc->duration.seconds = duration;
|
||||
dc->meandepth.mm = (depthtime + duration/2) / duration;
|
||||
dc->meandepth.mm = (depthtime + duration / 2) / duration;
|
||||
}
|
||||
}
|
||||
|
||||
void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *mean, int *duration)
|
||||
{
|
||||
int i;
|
||||
int depthtime[MAX_CYLINDERS] = {0,};
|
||||
int depthtime[MAX_CYLINDERS] = { 0, };
|
||||
int lasttime = 0, lastdepth = 0;
|
||||
int idx = 0;
|
||||
|
||||
|
@ -426,7 +426,7 @@ double surface_volume_multiplier(pressure_t pressure)
|
|||
double bar = pressure.mbar / 1000.0;
|
||||
|
||||
if (bar > 200)
|
||||
bar = 0.00038*bar*bar + 0.51629*bar + 81.542;
|
||||
bar = 0.00038 * bar * bar + 0.51629 * bar + 81.542;
|
||||
return bar_to_atm(bar);
|
||||
}
|
||||
|
||||
|
@ -469,7 +469,7 @@ static void sanitize_gasmix(struct gasmix *mix)
|
|||
}
|
||||
|
||||
/* Sane mix? */
|
||||
if (o2 <= 1000 && he <= 1000 && o2+he <= 1000)
|
||||
if (o2 <= 1000 && he <= 1000 && o2 + he <= 1000)
|
||||
return;
|
||||
fprintf(stderr, "Odd gasmix: %u O2 %u He\n", o2, he);
|
||||
memset(mix, 0, sizeof(*mix));
|
||||
|
@ -495,29 +495,29 @@ static void match_standard_cylinder(cylinder_type_t *type)
|
|||
psi = to_PSI(type->workingpressure);
|
||||
|
||||
switch (psi) {
|
||||
case 2300 ... 2500: /* 2400 psi: LP tank */
|
||||
case 2300 ... 2500: /* 2400 psi: LP tank */
|
||||
fmt = "LP%d";
|
||||
break;
|
||||
case 2600 ... 2700: /* 2640 psi: LP+10% */
|
||||
case 2600 ... 2700: /* 2640 psi: LP+10% */
|
||||
fmt = "LP%d";
|
||||
break;
|
||||
case 2900 ... 3100: /* 3000 psi: ALx tank */
|
||||
case 2900 ... 3100: /* 3000 psi: ALx tank */
|
||||
fmt = "AL%d";
|
||||
break;
|
||||
case 3400 ... 3500: /* 3442 psi: HP tank */
|
||||
case 3400 ... 3500: /* 3442 psi: HP tank */
|
||||
fmt = "HP%d";
|
||||
break;
|
||||
case 3700 ... 3850: /* HP+10% */
|
||||
case 3700 ... 3850: /* HP+10% */
|
||||
fmt = "HP%d+";
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
len = snprintf(buffer, sizeof(buffer), fmt, rint(cuft));
|
||||
p = malloc(len+1);
|
||||
p = malloc(len + 1);
|
||||
if (!p)
|
||||
return;
|
||||
memcpy(p, buffer, len+1);
|
||||
memcpy(p, buffer, len + 1);
|
||||
type->description = p;
|
||||
}
|
||||
|
||||
|
@ -631,7 +631,7 @@ static void fixup_surface_pressure(struct dive *dive)
|
|||
}
|
||||
}
|
||||
if (nr)
|
||||
dive->surface_pressure.mbar = (sum + nr/2)/nr;
|
||||
dive->surface_pressure.mbar = (sum + nr / 2) / nr;
|
||||
}
|
||||
|
||||
static void fixup_water_salinity(struct dive *dive)
|
||||
|
@ -646,7 +646,7 @@ static void fixup_water_salinity(struct dive *dive)
|
|||
}
|
||||
}
|
||||
if (nr)
|
||||
dive->salinity = (sum + nr/2)/nr;
|
||||
dive->salinity = (sum + nr / 2) / nr;
|
||||
}
|
||||
|
||||
static void fixup_meandepth(struct dive *dive)
|
||||
|
@ -670,7 +670,7 @@ static void fixup_duration(struct dive *dive)
|
|||
int duration = 0;
|
||||
|
||||
for_each_dc(dive, dc)
|
||||
duration = MAX(duration, dc->duration.seconds);
|
||||
duration = MAX(duration, dc->duration.seconds);
|
||||
|
||||
dive->duration.seconds = duration;
|
||||
}
|
||||
|
@ -786,7 +786,7 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
|
|||
int mintemp = 0;
|
||||
int lastdepth = 0;
|
||||
int lasttemp = 0, lastpressure = 0;
|
||||
int pressure_delta[MAX_CYLINDERS] = {INT_MAX, };
|
||||
int pressure_delta[MAX_CYLINDERS] = { INT_MAX, };
|
||||
|
||||
/* Fixup duration and mean depth */
|
||||
fixup_dc_duration(dc);
|
||||
|
@ -871,9 +871,9 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
|
|||
for (i = 0; i < dc->samples; i++)
|
||||
if (dc->sample[i].sensor == j)
|
||||
dc->sample[i].cylinderpressure.mbar = 0;
|
||||
if (! cyl->start.mbar)
|
||||
if (!cyl->start.mbar)
|
||||
cyl->start.mbar = cyl->sample_start.mbar;
|
||||
if (! cyl->end.mbar)
|
||||
if (!cyl->end.mbar)
|
||||
cyl->end.mbar = cyl->sample_end.mbar;
|
||||
cyl->sample_start.mbar = 0;
|
||||
cyl->sample_end.mbar = 0;
|
||||
|
@ -896,7 +896,7 @@ struct dive *fixup_dive(struct dive *dive)
|
|||
dive->maxcns = dive->cns;
|
||||
|
||||
for_each_dc(dive, dc)
|
||||
fixup_dive_dc(dive, dc);
|
||||
fixup_dive_dc(dive, dc);
|
||||
|
||||
fixup_water_salinity(dive);
|
||||
fixup_surface_pressure(dive);
|
||||
|
@ -924,7 +924,7 @@ struct dive *fixup_dive(struct dive *dive)
|
|||
|
||||
/* Don't pick a zero for MERGE_MIN() */
|
||||
#define MERGE_MAX(res, a, b, n) res->n = MAX(a->n, b->n)
|
||||
#define MERGE_MIN(res, a, b, n) res->n = (a->n)?(b->n)?MIN(a->n, b->n):(a->n):(b->n)
|
||||
#define MERGE_MIN(res, a, b, n) res->n = (a->n) ? (b->n) ? MIN(a->n, b->n) : (a->n) : (b->n)
|
||||
#define MERGE_TXT(res, a, b, n) res->n = merge_text(a->n, b->n)
|
||||
#define MERGE_NONZERO(res, a, b, n) res->n = a->n ? a->n : b->n
|
||||
|
||||
|
@ -950,7 +950,7 @@ static struct sample *add_sample(struct sample *sample, int time, struct divecom
|
|||
*/
|
||||
static void merge_one_sample(struct sample *sample, int time, struct divecomputer *dc)
|
||||
{
|
||||
int last = dc->samples-1;
|
||||
int last = dc->samples - 1;
|
||||
if (last >= 0) {
|
||||
static struct sample surface;
|
||||
struct sample *prev = dc->sample + last;
|
||||
|
@ -962,7 +962,7 @@ static void merge_one_sample(struct sample *sample, int time, struct divecompute
|
|||
* a minute apart, and shallower than 5m
|
||||
*/
|
||||
if (time > last_time + 60 && last_depth < 5000) {
|
||||
add_sample(&surface, last_time+20, dc);
|
||||
add_sample(&surface, last_time + 20, dc);
|
||||
add_sample(&surface, time - 20, dc);
|
||||
}
|
||||
}
|
||||
|
@ -1011,7 +1011,7 @@ static void merge_samples(struct divecomputer *res, struct divecomputer *a, stru
|
|||
|
||||
/* Only samples from a? */
|
||||
if (bt < 0) {
|
||||
add_sample_a:
|
||||
add_sample_a:
|
||||
merge_one_sample(as, at, res);
|
||||
as++;
|
||||
asamples--;
|
||||
|
@ -1020,7 +1020,7 @@ add_sample_a:
|
|||
|
||||
/* Only samples from b? */
|
||||
if (at < 0) {
|
||||
add_sample_b:
|
||||
add_sample_b:
|
||||
merge_one_sample(bs, bt, res);
|
||||
bs++;
|
||||
bsamples--;
|
||||
|
@ -1073,24 +1073,25 @@ static char *merge_text(const char *a, const char *b)
|
|||
return b ? strdup(b) : NULL;
|
||||
if (!b || !*b)
|
||||
return strdup(a);
|
||||
if (!strcmp(a,b))
|
||||
if (!strcmp(a, b))
|
||||
return a ? strdup(a) : NULL;
|
||||
res = malloc(strlen(a) + strlen(b) + 32);
|
||||
if (!res)
|
||||
return (char *)a;
|
||||
sprintf(res, translate("gettextFromC","(%s) or (%s)"), a, b);
|
||||
sprintf(res, translate("gettextFromC", "(%s) or (%s)"), a, b);
|
||||
return res;
|
||||
}
|
||||
|
||||
#define SORT(a,b,field) \
|
||||
if (a->field != b->field) return a->field < b->field ? -1 : 1
|
||||
#define SORT(a, b, field) \
|
||||
if (a->field != b->field) \
|
||||
return a->field < b->field ? -1 : 1
|
||||
|
||||
static int sort_event(struct event *a, struct event *b)
|
||||
{
|
||||
SORT(a,b,time.seconds);
|
||||
SORT(a,b,type);
|
||||
SORT(a,b,flags);
|
||||
SORT(a,b,value);
|
||||
SORT(a, b, time.seconds);
|
||||
SORT(a, b, type);
|
||||
SORT(a, b, flags);
|
||||
SORT(a, b, value);
|
||||
return strcmp(a->name, b->name);
|
||||
}
|
||||
|
||||
|
@ -1185,8 +1186,8 @@ static int gasmix_distance(const struct gasmix *a, const struct gasmix *b)
|
|||
int a_he = get_he(a), b_he = get_he(b);
|
||||
int delta_o2 = a_o2 - b_o2, delta_he = a_he - b_he;
|
||||
|
||||
delta_he = delta_he*delta_he;
|
||||
delta_o2 = delta_o2*delta_o2;
|
||||
delta_he = delta_he * delta_he;
|
||||
delta_o2 = delta_o2 * delta_o2;
|
||||
return delta_he + delta_o2;
|
||||
}
|
||||
|
||||
|
@ -1201,9 +1202,9 @@ static int find_cylinder_match(cylinder_t *cyl, cylinder_t array[], unsigned int
|
|||
const cylinder_t *match;
|
||||
int distance;
|
||||
|
||||
if (used & (1<<i))
|
||||
if (used & (1 << i))
|
||||
continue;
|
||||
match = array+i;
|
||||
match = array + i;
|
||||
distance = gasmix_distance(&cyl->gasmix, &match->gasmix);
|
||||
if (distance >= score)
|
||||
continue;
|
||||
|
@ -1235,7 +1236,7 @@ static void dc_cylinder_renumber(struct dive *dive, struct divecomputer *dc, int
|
|||
|
||||
/* Remap the sensor indexes */
|
||||
for (i = 0; i < dc->samples; i++) {
|
||||
struct sample *s = dc->sample+i;
|
||||
struct sample *s = dc->sample + i;
|
||||
int sensor;
|
||||
|
||||
if (!s->cylinderpressure.mbar)
|
||||
|
@ -1291,7 +1292,7 @@ static void merge_cylinders(struct dive *res, struct dive *a, struct dive *b)
|
|||
if (j < 0)
|
||||
continue;
|
||||
used |= 1 << j;
|
||||
merge_cylinder_info(cyl, res->cylinder+j);
|
||||
merge_cylinder_info(cyl, res->cylinder + j);
|
||||
|
||||
/* If that renumbered the cylinders, fix it up! */
|
||||
if (i != j)
|
||||
|
@ -1307,7 +1308,7 @@ static void merge_equipment(struct dive *res, struct dive *a, struct dive *b)
|
|||
|
||||
merge_cylinders(res, a, b);
|
||||
for (i = 0; i < MAX_WEIGHTSYSTEMS; i++)
|
||||
merge_weightsystem_info(res->weightsystem+i, a->weightsystem + i, b->weightsystem + i);
|
||||
merge_weightsystem_info(res->weightsystem + i, a->weightsystem + i, b->weightsystem + i);
|
||||
}
|
||||
|
||||
static void merge_airtemps(struct dive *res, struct dive *a, struct dive *b)
|
||||
|
@ -1410,7 +1411,7 @@ static int compare_sample(struct sample *s, struct sample *a, struct sample *b,
|
|||
/* cut off at one meter difference */
|
||||
if (diff > 1000)
|
||||
diff = 1000;
|
||||
return diff*diff;
|
||||
return diff * diff;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1434,7 +1435,8 @@ static unsigned long sample_difference(struct divecomputer *a, struct divecomput
|
|||
* skip the first sample - this way we know can always look at
|
||||
* as/bs[-1] to look at the samples around it in the loop.
|
||||
*/
|
||||
as++; bs++;
|
||||
as++;
|
||||
bs++;
|
||||
asamples--;
|
||||
bsamples--;
|
||||
|
||||
|
@ -1459,17 +1461,19 @@ static unsigned long sample_difference(struct divecomputer *a, struct divecomput
|
|||
}
|
||||
|
||||
if (at < bt) {
|
||||
diff = compare_sample(as, bs-1, bs, bt - at);
|
||||
diff = compare_sample(as, bs - 1, bs, bt - at);
|
||||
as++;
|
||||
asamples--;
|
||||
} else if (at > bt) {
|
||||
diff = compare_sample(bs, as-1, as, at - bt);
|
||||
diff = compare_sample(bs, as - 1, as, at - bt);
|
||||
bs++;
|
||||
bsamples--;
|
||||
} else {
|
||||
diff = compare_sample(as, bs, NULL, 0);
|
||||
as++; bs++;
|
||||
asamples--; bsamples--;
|
||||
as++;
|
||||
bs++;
|
||||
asamples--;
|
||||
bsamples--;
|
||||
}
|
||||
|
||||
/* Invalid comparison point? */
|
||||
|
@ -1559,7 +1563,8 @@ static int similar(unsigned long a, unsigned long b, unsigned long expected)
|
|||
if (a && b) {
|
||||
unsigned long min, max, diff;
|
||||
|
||||
min = a; max = b;
|
||||
min = a;
|
||||
max = b;
|
||||
if (a > b) {
|
||||
min = b;
|
||||
max = a;
|
||||
|
@ -1570,7 +1575,7 @@ static int similar(unsigned long a, unsigned long b, unsigned long expected)
|
|||
if (diff < expected)
|
||||
return 1;
|
||||
/* Error less than 10% or the maximum */
|
||||
if (diff*10 < max)
|
||||
if (diff * 10 < max)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -1672,7 +1677,7 @@ static int likely_same_dive(struct dive *a, struct dive *b)
|
|||
*/
|
||||
if (!similar(a->maxdepth.mm, b->maxdepth.mm, 1000) ||
|
||||
(a->meandepth.mm && b->meandepth.mm && !similar(a->meandepth.mm, b->meandepth.mm, 1000)) ||
|
||||
!similar(a->duration.seconds, b->duration.seconds, 5*60))
|
||||
!similar(a->duration.seconds, b->duration.seconds, 5 * 60))
|
||||
return 0;
|
||||
|
||||
/* See if we can get an exact match on the dive computer */
|
||||
|
@ -1761,7 +1766,7 @@ static int same_dc(struct divecomputer *a, struct divecomputer *b)
|
|||
if (a->samples != b->samples)
|
||||
return 0;
|
||||
for (i = 0; i < a->samples; i++)
|
||||
if (!same_sample(a->sample+i, b->sample+i))
|
||||
if (!same_sample(a->sample + i, b->sample + i))
|
||||
return 0;
|
||||
eva = a->events;
|
||||
evb = b->events;
|
||||
|
@ -1852,7 +1857,7 @@ static void copy_dive_computer(struct divecomputer *res, struct divecomputer *a)
|
|||
* merge them. If not, we just take the data from 'a'.
|
||||
*/
|
||||
static void interleave_dive_computers(struct divecomputer *res,
|
||||
struct divecomputer *a, struct divecomputer *b, int offset)
|
||||
struct divecomputer *a, struct divecomputer *b, int offset)
|
||||
{
|
||||
do {
|
||||
struct divecomputer *match;
|
||||
|
@ -1921,19 +1926,20 @@ static void join_dive_computers(struct divecomputer *res, struct divecomputer *a
|
|||
remove_redundant_dc(res, prefer_downloaded);
|
||||
}
|
||||
|
||||
int taglist_get_tagstring(struct tag_entry *tag_list, char *buffer, int len) {
|
||||
int taglist_get_tagstring(struct tag_entry *tag_list, char *buffer, int len)
|
||||
{
|
||||
int i = 0;
|
||||
struct tag_entry *tmp;
|
||||
tmp = tag_list->next;
|
||||
memset(buffer, 0, len);
|
||||
while(tmp != NULL) {
|
||||
while (tmp != NULL) {
|
||||
int newlength = strlen(tmp->tag->name);
|
||||
if (i > 0)
|
||||
newlength += 2;
|
||||
if ((i+newlength) < len) {
|
||||
if ((i + newlength) < len) {
|
||||
if (i > 0) {
|
||||
strcpy(buffer+i, ", ");
|
||||
strcpy(buffer+i+2, tmp->tag->name);
|
||||
strcpy(buffer + i, ", ");
|
||||
strcpy(buffer + i + 2, tmp->tag->name);
|
||||
} else {
|
||||
strcpy(buffer, tmp->tag->name);
|
||||
}
|
||||
|
@ -1950,7 +1956,7 @@ struct divetag *taglist_get_tag(struct tag_entry *tag_list, const char *tag)
|
|||
{
|
||||
struct tag_entry *tmp;
|
||||
tmp = tag_list->next;
|
||||
while(tmp != NULL) {
|
||||
while (tmp != NULL) {
|
||||
if (tmp->tag != NULL) {
|
||||
if (strcmp(tmp->tag->name, tag) == 0)
|
||||
return tmp->tag;
|
||||
|
@ -1961,7 +1967,8 @@ struct divetag *taglist_get_tag(struct tag_entry *tag_list, const char *tag)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static inline void taglist_free_divetag(struct divetag *tag) {
|
||||
static inline void taglist_free_divetag(struct divetag *tag)
|
||||
{
|
||||
if (tag->name != NULL)
|
||||
free(tag->name);
|
||||
if (tag->source != NULL)
|
||||
|
@ -1975,7 +1982,7 @@ static struct divetag *taglist_add_divetag(struct tag_entry *tag_list, struct di
|
|||
struct tag_entry *tmp, *last;
|
||||
last = tag_list;
|
||||
tmp = tag_list->next;
|
||||
while(1) {
|
||||
while (1) {
|
||||
if (tmp == NULL || strcmp(tmp->tag->name, tag->name) > 0) {
|
||||
/* Insert in front of it */
|
||||
last->next = malloc(sizeof(struct tag_entry));
|
||||
|
@ -1999,7 +2006,7 @@ struct divetag *taglist_add_tag(struct tag_entry *tag_list, const char *tag)
|
|||
const char *translation;
|
||||
new_tag = malloc(sizeof(struct divetag));
|
||||
|
||||
for (i=0; i<sizeof(default_tags)/sizeof(char*); i++) {
|
||||
for (i = 0; i < sizeof(default_tags) / sizeof(char *); i++) {
|
||||
if (strcmp(default_tags[i], tag) == 0) {
|
||||
is_default_tag = 1;
|
||||
break;
|
||||
|
@ -2008,14 +2015,14 @@ struct divetag *taglist_add_tag(struct tag_entry *tag_list, const char *tag)
|
|||
/* Only translate default tags */
|
||||
if (is_default_tag) {
|
||||
translation = translate("gettextFromC", tag);
|
||||
new_tag->name = malloc(strlen(translation)+1);
|
||||
memcpy(new_tag->name, translation, strlen(translation)+1);
|
||||
new_tag->source = malloc(strlen(tag)+1);
|
||||
memcpy(new_tag->source, tag, strlen(tag)+1);
|
||||
new_tag->name = malloc(strlen(translation) + 1);
|
||||
memcpy(new_tag->name, translation, strlen(translation) + 1);
|
||||
new_tag->source = malloc(strlen(tag) + 1);
|
||||
memcpy(new_tag->source, tag, strlen(tag) + 1);
|
||||
} else {
|
||||
new_tag->source = NULL;
|
||||
new_tag->name = malloc(strlen(tag)+1);
|
||||
memcpy(new_tag->name, tag, strlen(tag)+1);
|
||||
new_tag->name = malloc(strlen(tag) + 1);
|
||||
memcpy(new_tag->name, tag, strlen(tag) + 1);
|
||||
}
|
||||
/* Try to insert new_tag into g_tag_list if we are not operating on it */
|
||||
if (tag_list != g_tag_list) {
|
||||
|
@ -2032,14 +2039,16 @@ struct divetag *taglist_add_tag(struct tag_entry *tag_list, const char *tag)
|
|||
return ret_tag;
|
||||
}
|
||||
|
||||
void taglist_init(struct tag_entry **tag_list) {
|
||||
void taglist_init(struct tag_entry **tag_list)
|
||||
{
|
||||
*tag_list = malloc(sizeof(struct tag_entry));
|
||||
(*tag_list)->next = NULL;
|
||||
(*tag_list)->tag = NULL;
|
||||
}
|
||||
|
||||
/* Clear everything but the first element */
|
||||
void taglist_clear(struct tag_entry *tag_list) {
|
||||
void taglist_clear(struct tag_entry *tag_list)
|
||||
{
|
||||
struct tag_entry *current_tag_entry, *next;
|
||||
current_tag_entry = tag_list->next;
|
||||
while (current_tag_entry != NULL) {
|
||||
|
@ -2071,7 +2080,7 @@ void taglist_init_global()
|
|||
int i;
|
||||
taglist_init(&g_tag_list);
|
||||
|
||||
for(i=0; i<sizeof(default_tags)/sizeof(char*); i++)
|
||||
for (i = 0; i < sizeof(default_tags) / sizeof(char *); i++)
|
||||
taglist_add_tag(g_tag_list, default_tags[i]);
|
||||
}
|
||||
|
||||
|
@ -2166,7 +2175,7 @@ void shift_times(const timestamp_t amount)
|
|||
int i;
|
||||
struct dive *dive;
|
||||
|
||||
for_each_dive (i, dive) {
|
||||
for_each_dive(i, dive) {
|
||||
if (!dive->selected)
|
||||
continue;
|
||||
dive->when += amount;
|
||||
|
|
184
dive.h
184
dive.h
|
@ -21,7 +21,7 @@
|
|||
(void) (&_max1 == &_max2); \
|
||||
_max1 > _max2 ? _max1 : _max2; })
|
||||
|
||||
#define IS_FP_SAME(_a,_b) (fabs((_a) - (_b)) < 0.000001 * MAX(fabs(_a), fabs(_b)))
|
||||
#define IS_FP_SAME(_a, _b) (fabs((_a) - (_b)) < 0.000001 * MAX(fabs(_a), fabs(_b)))
|
||||
|
||||
#include <libxml/tree.h>
|
||||
#include <libxslt/transform.h>
|
||||
|
@ -34,18 +34,18 @@ extern "C" {
|
|||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#define O2_IN_AIR 209 // permille
|
||||
#define N2_IN_AIR 781
|
||||
#define O2_DENSITY 1429 // mg/Liter
|
||||
#define N2_DENSITY 1251
|
||||
#define HE_DENSITY 179
|
||||
#define SURFACE_PRESSURE 1013 // mbar
|
||||
#define O2_IN_AIR 209 // permille
|
||||
#define N2_IN_AIR 781
|
||||
#define O2_DENSITY 1429 // mg/Liter
|
||||
#define N2_DENSITY 1251
|
||||
#define HE_DENSITY 179
|
||||
#define SURFACE_PRESSURE 1013 // mbar
|
||||
#define SURFACE_PRESSURE_STRING "1013"
|
||||
#define ZERO_C_IN_MKELVIN 273150 // mKelvin
|
||||
#define ZERO_C_IN_MKELVIN 273150 // mKelvin
|
||||
|
||||
/* Salinity is expressed in weight in grams per 10l */
|
||||
#define SEAWATER_SALINITY 10300
|
||||
#define FRESHWATER_SALINITY 10000
|
||||
#define SEAWATER_SALINITY 10300
|
||||
#define FRESHWATER_SALINITY 10000
|
||||
|
||||
/*
|
||||
* Some silly typedefs to make our units very explicit.
|
||||
|
@ -84,35 +84,43 @@ extern "C" {
|
|||
*/
|
||||
typedef int64_t timestamp_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int seconds;
|
||||
} duration_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int mm;
|
||||
} depth_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int mbar;
|
||||
} pressure_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int mkelvin;
|
||||
} temperature_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int mliter;
|
||||
} volume_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int permille;
|
||||
} fraction_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int grams;
|
||||
} weight_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int udeg;
|
||||
} degrees_t;
|
||||
|
||||
|
@ -121,13 +129,15 @@ struct gasmix {
|
|||
fraction_t he;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
volume_t size;
|
||||
pressure_t workingpressure;
|
||||
const char *description; /* "LP85", "AL72", "AL80", "HP100+" or whatever */
|
||||
const char *description; /* "LP85", "AL72", "AL80", "HP100+" or whatever */
|
||||
} cylinder_type_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
cylinder_type_t type;
|
||||
struct gasmix gasmix;
|
||||
pressure_t start, end, sample_start, sample_end;
|
||||
|
@ -135,9 +145,10 @@ typedef struct {
|
|||
bool used;
|
||||
} cylinder_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
weight_t weight;
|
||||
const char *description; /* "integrated", "belt", "ankle" */
|
||||
const char *description; /* "integrated", "belt", "ankle" */
|
||||
} weightsystem_t;
|
||||
|
||||
extern int get_pressure_units(unsigned int mb, const char **units);
|
||||
|
@ -196,7 +207,7 @@ static inline double mkelvin_to_F(int mkelvin)
|
|||
|
||||
static inline unsigned long F_to_mkelvin(double f)
|
||||
{
|
||||
return rint((f-32) * 1000 / 1.8 + ZERO_C_IN_MKELVIN);
|
||||
return rint((f - 32) * 1000 / 1.8 + ZERO_C_IN_MKELVIN);
|
||||
}
|
||||
|
||||
static inline unsigned long C_to_mkelvin(double c)
|
||||
|
@ -211,7 +222,7 @@ static inline double psi_to_bar(double psi)
|
|||
|
||||
static inline long psi_to_mbar(double psi)
|
||||
{
|
||||
return rint(psi_to_bar(psi)*1000);
|
||||
return rint(psi_to_bar(psi) * 1000);
|
||||
}
|
||||
|
||||
static inline int to_PSI(pressure_t pressure)
|
||||
|
@ -226,7 +237,7 @@ static inline double bar_to_atm(double bar)
|
|||
|
||||
static inline double mbar_to_atm(int mbar)
|
||||
{
|
||||
return (double) mbar / SURFACE_PRESSURE;
|
||||
return (double)mbar / SURFACE_PRESSURE;
|
||||
}
|
||||
|
||||
/* Volume in mliter of a cylinder at pressure 'p' */
|
||||
|
@ -235,13 +246,13 @@ extern int wet_volume(double cuft, pressure_t p);
|
|||
|
||||
static inline int mbar_to_PSI(int mbar)
|
||||
{
|
||||
pressure_t p = {mbar};
|
||||
pressure_t p = { mbar };
|
||||
return to_PSI(p);
|
||||
}
|
||||
|
||||
static inline int get_o2(const struct gasmix *mix)
|
||||
{
|
||||
return mix->o2.permille ? : O2_IN_AIR;
|
||||
return mix->o2.permille ?: O2_IN_AIR;
|
||||
}
|
||||
|
||||
static inline int get_he(const struct gasmix *mix)
|
||||
|
@ -258,7 +269,7 @@ static inline bool is_air(int o2, int he)
|
|||
static inline int interpolate(int a, int b, int part, int whole)
|
||||
{
|
||||
/* It is doubtful that we actually need floating point for this, but whatever */
|
||||
double x = (double) a * (whole - part) + (double) b * part;
|
||||
double x = (double)a * (whole - part) + (double)b * part;
|
||||
return rint(x / whole);
|
||||
}
|
||||
|
||||
|
@ -267,7 +278,7 @@ struct sample {
|
|||
depth_t depth;
|
||||
temperature_t temperature;
|
||||
pressure_t cylinderpressure;
|
||||
int sensor; /* Cylinder pressure sensor index */
|
||||
int sensor; /* Cylinder pressure sensor index */
|
||||
duration_t ndl;
|
||||
duration_t stoptime;
|
||||
depth_t stopdepth;
|
||||
|
@ -366,16 +377,23 @@ struct divecomputer {
|
|||
#define W_IDX_PRIMARY 0
|
||||
#define W_IDX_SECONDARY 1
|
||||
|
||||
typedef enum { TF_NONE, NO_TRIP, IN_TRIP, ASSIGNED_TRIP, NUM_TRIPFLAGS } tripflag_t;
|
||||
typedef enum {
|
||||
TF_NONE,
|
||||
NO_TRIP,
|
||||
IN_TRIP,
|
||||
ASSIGNED_TRIP,
|
||||
NUM_TRIPFLAGS
|
||||
} tripflag_t;
|
||||
|
||||
typedef struct dive_trip {
|
||||
typedef struct dive_trip
|
||||
{
|
||||
timestamp_t when;
|
||||
char *location;
|
||||
char *notes;
|
||||
struct dive *dives;
|
||||
int nrdives;
|
||||
int index;
|
||||
unsigned expanded:1, selected:1, autogen:1, fixup:1;
|
||||
unsigned expanded : 1, selected : 1, autogen : 1, fixup : 1;
|
||||
struct dive_trip *next;
|
||||
} dive_trip_t;
|
||||
|
||||
|
@ -486,7 +504,7 @@ extern short autogroup;
|
|||
/* random threashold: three days without diving -> new trip
|
||||
* this works very well for people who usually dive as part of a trip and don't
|
||||
* regularly dive at a local facility; this is why trips are an optional feature */
|
||||
#define TRIP_THRESHOLD 3600*24*3
|
||||
#define TRIP_THRESHOLD 3600 * 24 * 3
|
||||
|
||||
#define UNGROUPED_DIVE(_dive) ((_dive)->tripflag == NO_TRIP)
|
||||
#define DIVE_IN_TRIP(_dive) ((_dive)->tripflag == IN_TRIP || (_dive)->tripflag == ASSIGNED_TRIP)
|
||||
|
@ -509,12 +527,32 @@ extern void insert_trip(dive_trip_t **trip);
|
|||
#undef PASCAL
|
||||
#endif
|
||||
struct units {
|
||||
enum { METERS, FEET } length;
|
||||
enum { LITER, CUFT } volume;
|
||||
enum { BAR, PSI, PASCAL } pressure;
|
||||
enum { CELSIUS, FAHRENHEIT, KELVIN } temperature;
|
||||
enum { KG, LBS } weight;
|
||||
enum { SECONDS, MINUTES } vertical_speed_time;
|
||||
enum {
|
||||
METERS,
|
||||
FEET
|
||||
} length;
|
||||
enum {
|
||||
LITER,
|
||||
CUFT
|
||||
} volume;
|
||||
enum {
|
||||
BAR,
|
||||
PSI,
|
||||
PASCAL
|
||||
} pressure;
|
||||
enum {
|
||||
CELSIUS,
|
||||
FAHRENHEIT,
|
||||
KELVIN
|
||||
} temperature;
|
||||
enum {
|
||||
KG,
|
||||
LBS
|
||||
} weight;
|
||||
enum {
|
||||
SECONDS,
|
||||
MINUTES
|
||||
} vertical_speed_time;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -524,23 +562,15 @@ struct units {
|
|||
* actually use. Similarly, C instead of Kelvin.
|
||||
* And kg instead of g.
|
||||
*/
|
||||
#define SI_UNITS { \
|
||||
.length = METERS, \
|
||||
.volume = LITER, \
|
||||
.pressure = BAR, \
|
||||
.temperature = CELSIUS, \
|
||||
.weight = KG, \
|
||||
.vertical_speed_time = MINUTES \
|
||||
}
|
||||
#define SI_UNITS \
|
||||
{ \
|
||||
.length = METERS, .volume = LITER, .pressure = BAR, .temperature = CELSIUS, .weight = KG, .vertical_speed_time = MINUTES \
|
||||
}
|
||||
|
||||
#define IMPERIAL_UNITS { \
|
||||
.length = FEET, \
|
||||
.volume = CUFT, \
|
||||
.pressure = PSI, \
|
||||
.temperature = FAHRENHEIT, \
|
||||
.weight = LBS, \
|
||||
.vertical_speed_time = MINUTES \
|
||||
}
|
||||
#define IMPERIAL_UNITS \
|
||||
{ \
|
||||
.length = FEET, .volume = CUFT, .pressure = PSI, .temperature = FAHRENHEIT, .weight = LBS, .vertical_speed_time = MINUTES \
|
||||
}
|
||||
extern const struct units SI_units, IMPERIAL_units;
|
||||
extern struct units xml_parsing_units;
|
||||
|
||||
|
@ -589,14 +619,14 @@ static inline struct divecomputer *get_dive_dc(struct dive *dive, int nr)
|
|||
* I don't think anybody really wants the index, and we could make
|
||||
* it local to the for-loop, but that would make us requires C99.
|
||||
*/
|
||||
#define for_each_dive(_i,_x) \
|
||||
for ((_i) = 0; ((_x) = get_dive(_i)) != NULL; (_i)++)
|
||||
#define for_each_dive(_i, _x) \
|
||||
for ((_i) = 0; ((_x) = get_dive(_i)) != NULL; (_i)++)
|
||||
|
||||
#define for_each_dc(_dive,_dc) \
|
||||
for (_dc = &_dive->dc; _dc; _dc = _dc->next)
|
||||
#define for_each_dc(_dive, _dc) \
|
||||
for (_dc = &_dive->dc; _dc; _dc = _dc->next)
|
||||
|
||||
#define for_each_gps_location(_i,_x) \
|
||||
for ((_i) = 0; ((_x) = get_gps_location(_i, &gps_location_table)) != NULL; (_i)++)
|
||||
#define for_each_gps_location(_i, _x) \
|
||||
for ((_i) = 0; ((_x) = get_gps_location(_i, &gps_location_table)) != NULL; (_i)++)
|
||||
|
||||
static inline struct dive *get_dive_by_diveid(uint32_t diveid, uint32_t deviceid)
|
||||
{
|
||||
|
@ -731,19 +761,19 @@ const char *monthname(int mon);
|
|||
#define UTF8_SUBSCRIPT_2 "\xe2\x82\x82"
|
||||
#define UTF8_WHITESTAR "\xe2\x98\x86"
|
||||
#define UTF8_BLACKSTAR "\xe2\x98\x85"
|
||||
#define ZERO_STARS UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||
#define ONE_STARS UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||
#define TWO_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||
#define THREE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||
#define FOUR_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR
|
||||
#define FIVE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR
|
||||
#define ZERO_STARS UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||
#define ONE_STARS UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||
#define TWO_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||
#define THREE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||
#define FOUR_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR
|
||||
#define FIVE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR
|
||||
extern const char *star_strings[];
|
||||
|
||||
extern const char *existing_filename;
|
||||
extern void subsurface_command_line_init(int *, char ***);
|
||||
extern void subsurface_command_line_exit(int *, char ***);
|
||||
|
||||
#define FRACTION(n,x) ((unsigned)(n)/(x)),((unsigned)(n)%(x))
|
||||
#define FRACTION(n, x) ((unsigned)(n) / (x)), ((unsigned)(n) % (x))
|
||||
|
||||
extern double add_segment(double pressure, const struct gasmix *gasmix, int period_in_seconds, int setpoint, const struct dive *dive);
|
||||
extern void clear_deco(double surface_pressure);
|
||||
|
@ -766,9 +796,9 @@ struct divedatapoint {
|
|||
struct diveplan {
|
||||
timestamp_t when;
|
||||
int lastdive_nr;
|
||||
int surface_pressure; /* mbar */
|
||||
int bottomsac; /* ml/min */
|
||||
int decosac; /* ml/min */
|
||||
int surface_pressure; /* mbar */
|
||||
int bottomsac; /* ml/min */
|
||||
int decosac; /* ml/min */
|
||||
short gflow;
|
||||
short gfhigh;
|
||||
struct divedatapoint *dp;
|
||||
|
@ -814,15 +844,15 @@ extern void remove_weightsystem(struct dive *dive, int idx);
|
|||
/*
|
||||
* String handling.
|
||||
*/
|
||||
#define STRTOD_NO_SIGN 0x01
|
||||
#define STRTOD_NO_DOT 0x02
|
||||
#define STRTOD_NO_COMMA 0x04
|
||||
#define STRTOD_NO_EXPONENT 0x08
|
||||
#define STRTOD_NO_SIGN 0x01
|
||||
#define STRTOD_NO_DOT 0x02
|
||||
#define STRTOD_NO_COMMA 0x04
|
||||
#define STRTOD_NO_EXPONENT 0x08
|
||||
extern double strtod_flags(const char *str, const char **ptr, unsigned int flags);
|
||||
|
||||
#define STRTOD_ASCII (STRTOD_NO_COMMA)
|
||||
|
||||
#define ascii_strtod(str,ptr) strtod_flags(str,ptr,STRTOD_ASCII)
|
||||
#define ascii_strtod(str, ptr) strtod_flags(str, ptr, STRTOD_ASCII)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
99
divelist.c
99
divelist.c
|
@ -133,9 +133,8 @@ void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p)
|
|||
if (is_air(o2, he)) {
|
||||
if (is_air(event_o2 * 10, event_he * 10))
|
||||
used = 1;
|
||||
}
|
||||
else {
|
||||
if (he == event_he*10 && o2 == event_o2*10)
|
||||
} else {
|
||||
if (he == event_he * 10 && o2 == event_o2 * 10)
|
||||
used = 1;
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +163,7 @@ void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p)
|
|||
continue;
|
||||
if (o2 <= maxo2)
|
||||
continue;
|
||||
newmax:
|
||||
newmax:
|
||||
maxhe = he;
|
||||
maxo2 = o2;
|
||||
}
|
||||
|
@ -181,7 +180,7 @@ int total_weight(struct dive *dive)
|
|||
int i, total_grams = 0;
|
||||
|
||||
if (dive)
|
||||
for (i=0; i< MAX_WEIGHTSYSTEMS; i++)
|
||||
for (i = 0; i < MAX_WEIGHTSYSTEMS; i++)
|
||||
total_grams += dive->weightsystem[i].weight.grams;
|
||||
return total_grams;
|
||||
}
|
||||
|
@ -199,7 +198,7 @@ static int active_o2(struct dive *dive, struct divecomputer *dc, duration_t time
|
|||
break;
|
||||
if (strcmp(event->name, "gaschange"))
|
||||
continue;
|
||||
o2permille = 10*(event->value & 0xffff);
|
||||
o2permille = 10 * (event->value & 0xffff);
|
||||
}
|
||||
return o2permille;
|
||||
}
|
||||
|
@ -230,18 +229,18 @@ static int calculate_otu(struct dive *dive)
|
|||
}
|
||||
/* calculate CNS for a dive - this only takes the first divecomputer into account */
|
||||
int const cns_table[][3] = {
|
||||
/* po2, Maximum Single Exposure, Maximum 24 hour Exposure */
|
||||
{1600, 45 * 60, 150 * 60},
|
||||
{1500, 120 * 60, 180 * 60},
|
||||
{1400, 150 * 60, 180 * 60},
|
||||
{1300, 180 * 60, 210 * 60},
|
||||
{1200, 210 * 60, 240 * 60},
|
||||
{1100, 240 * 60, 270 * 60},
|
||||
{1000, 300 * 60, 300 * 60},
|
||||
{ 900, 360 * 60, 360 * 60},
|
||||
{ 800, 450 * 60, 450 * 60},
|
||||
{ 700, 570 * 60, 570 * 60},
|
||||
{ 600, 720 * 60, 720 * 60}
|
||||
/* po2, Maximum Single Exposure, Maximum 24 hour Exposure */
|
||||
{ 1600, 45 * 60, 150 * 60 },
|
||||
{ 1500, 120 * 60, 180 * 60 },
|
||||
{ 1400, 150 * 60, 180 * 60 },
|
||||
{ 1300, 180 * 60, 210 * 60 },
|
||||
{ 1200, 210 * 60, 240 * 60 },
|
||||
{ 1100, 240 * 60, 270 * 60 },
|
||||
{ 1000, 300 * 60, 300 * 60 },
|
||||
{ 900, 360 * 60, 360 * 60 },
|
||||
{ 800, 450 * 60, 450 * 60 },
|
||||
{ 700, 570 * 60, 570 * 60 },
|
||||
{ 600, 720 * 60, 720 * 60 }
|
||||
};
|
||||
|
||||
/* this only gets called if dive->maxcns == 0 which means we know that
|
||||
|
@ -265,12 +264,12 @@ static int calculate_cns(struct dive *dive)
|
|||
*/
|
||||
divenr = get_divenr(dive);
|
||||
if (divenr) {
|
||||
prev_dive = get_dive(divenr -1 );
|
||||
prev_dive = get_dive(divenr - 1);
|
||||
if (prev_dive) {
|
||||
endtime = prev_dive->when + prev_dive->duration.seconds;
|
||||
if (dive->when < (endtime + 3600 * 12)) {
|
||||
cns = calculate_cns(prev_dive);
|
||||
cns = cns * 1/pow(2, (dive->when - endtime) / (90.0 * 60.0));
|
||||
cns = cns * 1 / pow(2, (dive->when - endtime) / (90.0 * 60.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -288,11 +287,11 @@ static int calculate_cns(struct dive *dive)
|
|||
po2 = o2 / depth_to_atm(sample->depth.mm, dive);
|
||||
}
|
||||
/* Find what table-row we should calculate % for */
|
||||
for (j = 1; j < sizeof(cns_table)/(sizeof(int) * 3); j++)
|
||||
for (j = 1; j < sizeof(cns_table) / (sizeof(int) * 3); j++)
|
||||
if (po2 > cns_table[j][0])
|
||||
break;
|
||||
j--;
|
||||
cns += ((double)t)/((double)cns_table[j][1]) * 100;
|
||||
cns += ((double)t) / ((double)cns_table[j][1]) * 100;
|
||||
}
|
||||
/* save calculated cns in dive struct */
|
||||
dive->cns = cns;
|
||||
|
@ -362,8 +361,8 @@ static void add_dive_to_deco(struct dive *dive)
|
|||
|
||||
for (j = t0; j < t1; j++) {
|
||||
int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0);
|
||||
(void) add_segment(depth_to_mbar(depth, dive) / 1000.0,
|
||||
&dive->cylinder[sample->sensor].gasmix, 1, sample->po2, dive);
|
||||
(void)add_segment(depth_to_mbar(depth, dive) / 1000.0,
|
||||
&dive->cylinder[sample->sensor].gasmix, 1, sample->po2, dive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -373,8 +372,8 @@ int get_divenr(struct dive *dive)
|
|||
int i;
|
||||
struct dive *d;
|
||||
for_each_dive(i, d)
|
||||
if (d == dive)
|
||||
return i;
|
||||
if (d == dive)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -396,7 +395,7 @@ double init_decompression(struct dive *dive)
|
|||
when = dive->when;
|
||||
i = divenr;
|
||||
while (i && --i) {
|
||||
struct dive* pdive = get_dive(i);
|
||||
struct dive *pdive = get_dive(i);
|
||||
/* we don't want to mix dives from different trips as we keep looking
|
||||
* for how far back we need to go */
|
||||
if (dive->divetrip && pdive->divetrip != dive->divetrip)
|
||||
|
@ -407,7 +406,7 @@ double init_decompression(struct dive *dive)
|
|||
lasttime = when + pdive->duration.seconds;
|
||||
}
|
||||
while (++i < divenr) {
|
||||
struct dive* pdive = get_dive(i);
|
||||
struct dive *pdive = get_dive(i);
|
||||
/* again skip dives from different trips */
|
||||
if (dive->divetrip && dive->divetrip != pdive->divetrip)
|
||||
continue;
|
||||
|
@ -429,7 +428,7 @@ double init_decompression(struct dive *dive)
|
|||
lasttime = pdive->when + pdive->duration.seconds;
|
||||
tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0, dive);
|
||||
#if DECO_CALC_DEBUG & 2
|
||||
printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60));
|
||||
printf("after surface intervall of %d:%02u\n", FRACTION(surface_time, 60));
|
||||
dump_tissues();
|
||||
#endif
|
||||
}
|
||||
|
@ -440,7 +439,7 @@ double init_decompression(struct dive *dive)
|
|||
surface_pressure = get_surface_pressure_in_mbar(dive, true) / 1000.0;
|
||||
tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0, dive);
|
||||
#if DECO_CALC_DEBUG & 2
|
||||
printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60));
|
||||
printf("after surface intervall of %d:%02u\n", FRACTION(surface_time, 60));
|
||||
dump_tissues();
|
||||
#endif
|
||||
}
|
||||
|
@ -488,7 +487,7 @@ char *get_nitrox_string(struct dive *dive)
|
|||
else
|
||||
snprintf(buffer, MAX_NITROX_STRING, "%d" UTF8_ELLIPSIS "%d", o2low, o2);
|
||||
else
|
||||
strcpy(buffer, translate("gettextFromC","air"));
|
||||
strcpy(buffer, translate("gettextFromC", "air"));
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
@ -500,7 +499,7 @@ char *get_nitrox_string(struct dive *dive)
|
|||
void dump_trip_list(void)
|
||||
{
|
||||
dive_trip_t *trip;
|
||||
int i=0;
|
||||
int i = 0;
|
||||
timestamp_t last_time = 0;
|
||||
|
||||
for (trip = dive_trip_list; trip; trip = trip->next) {
|
||||
|
@ -509,10 +508,10 @@ void dump_trip_list(void)
|
|||
if (trip->when < last_time)
|
||||
printf("\n\ndive_trip_list OUT OF ORDER!!!\n\n\n");
|
||||
printf("%s trip %d to \"%s\" on %04u-%02u-%02u %02u:%02u:%02u (%d dives - %p)\n",
|
||||
trip->autogen ? "autogen " : "",
|
||||
++i, trip->location,
|
||||
tm.tm_year + 1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
|
||||
trip->nrdives, trip);
|
||||
trip->autogen ? "autogen " : "",
|
||||
++i, trip->location,
|
||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
|
||||
trip->nrdives, trip);
|
||||
last_time = trip->when;
|
||||
}
|
||||
printf("-----\n");
|
||||
|
@ -537,9 +536,9 @@ dive_trip_t *find_matching_trip(timestamp_t when)
|
|||
struct tm tm;
|
||||
utc_mkdate(trip->when, &tm);
|
||||
printf("found trip %p @ %04d-%02d-%02d %02d:%02d:%02d\n",
|
||||
trip,
|
||||
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
|
||||
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
trip,
|
||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
|
||||
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
}
|
||||
#endif
|
||||
return trip;
|
||||
|
@ -560,9 +559,9 @@ void insert_trip(dive_trip_t **dive_trip_p)
|
|||
p = &trip->next;
|
||||
|
||||
if (trip && trip->when == dive_trip->when) {
|
||||
if (! trip->location)
|
||||
if (!trip->location)
|
||||
trip->location = dive_trip->location;
|
||||
if (! trip->notes)
|
||||
if (!trip->notes)
|
||||
trip->notes = dive_trip->notes;
|
||||
divep = dive_trip->dives;
|
||||
while (divep) {
|
||||
|
@ -729,7 +728,7 @@ void delete_single_dive(int idx)
|
|||
if (dive->selected)
|
||||
deselect_dive(idx);
|
||||
for (i = idx; i < dive_table.nr - 1; i++)
|
||||
dive_table.dives[i] = dive_table.dives[i+1];
|
||||
dive_table.dives[i] = dive_table.dives[i + 1];
|
||||
dive_table.dives[--dive_table.nr] = NULL;
|
||||
/* free all allocations */
|
||||
free(dive->dc.sample);
|
||||
|
@ -757,7 +756,7 @@ void add_single_dive(int idx, struct dive *dive)
|
|||
dive_table.nr++;
|
||||
if (dive->selected)
|
||||
amount_selected++;
|
||||
for (i = idx; i < dive_table.nr ; i++) {
|
||||
for (i = idx; i < dive_table.nr; i++) {
|
||||
struct dive *tmp = dive_table.dives[i];
|
||||
dive_table.dives[i] = dive;
|
||||
dive = tmp;
|
||||
|
@ -791,7 +790,7 @@ bool consecutive_selected()
|
|||
struct dive *merge_two_dives(struct dive *a, struct dive *b)
|
||||
{
|
||||
struct dive *res;
|
||||
int i,j;
|
||||
int i, j;
|
||||
int id = a->id;
|
||||
|
||||
if (!a || !b)
|
||||
|
@ -803,7 +802,7 @@ struct dive *merge_two_dives(struct dive *a, struct dive *b)
|
|||
return NULL;
|
||||
|
||||
add_single_dive(i, res);
|
||||
delete_single_dive(i+1);
|
||||
delete_single_dive(i + 1);
|
||||
delete_single_dive(j);
|
||||
// now make sure that we keep the id of the first dive.
|
||||
// why?
|
||||
|
@ -909,7 +908,7 @@ static void try_to_renumber(struct dive *last, int preexisting)
|
|||
* we're going to expect the user to do a manual
|
||||
* renumbering.
|
||||
*/
|
||||
if (preexisting && get_dive(preexisting-1) != last)
|
||||
if (preexisting && get_dive(preexisting - 1) != last)
|
||||
return;
|
||||
|
||||
/*
|
||||
|
@ -952,12 +951,12 @@ void process_dives(bool is_imported, bool prefer_imported)
|
|||
set_dc_nickname(dive_table.dives[i]);
|
||||
|
||||
/* This does the right thing for -1: NULL */
|
||||
last = get_dive(preexisting-1);
|
||||
last = get_dive(preexisting - 1);
|
||||
|
||||
sort_table(&dive_table);
|
||||
|
||||
for (i = 1; i < dive_table.nr; i++) {
|
||||
struct dive **pp = &dive_table.dives[i-1];
|
||||
struct dive **pp = &dive_table.dives[i - 1];
|
||||
struct dive *prev = pp[0];
|
||||
struct dive *dive = pp[1];
|
||||
struct dive *merged;
|
||||
|
@ -983,8 +982,8 @@ void process_dives(bool is_imported, bool prefer_imported)
|
|||
/* Redo the new 'i'th dive */
|
||||
i--;
|
||||
add_single_dive(i, merged);
|
||||
delete_single_dive(i+1);
|
||||
delete_single_dive(i+1);
|
||||
delete_single_dive(i + 1);
|
||||
delete_single_dive(i + 1);
|
||||
// keep the id or the first dive for the merged dive
|
||||
merged->id = id;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ extern void update_cylinder_related_info(struct dive *);
|
|||
extern void mark_divelist_changed(int);
|
||||
extern int unsaved_changes(void);
|
||||
extern void remove_autogen_trips(void);
|
||||
extern double init_decompression(struct dive * dive);
|
||||
extern double init_decompression(struct dive *dive);
|
||||
|
||||
/* divelist core logic functions */
|
||||
extern void process_dives(bool imported, bool prefer_imported);
|
||||
|
|
72
equipment.c
72
equipment.c
|
@ -50,19 +50,19 @@ void add_weightsystem_description(weightsystem_t *weightsystem)
|
|||
|
||||
bool cylinder_nodata(cylinder_t *cyl)
|
||||
{
|
||||
return !cyl->type.size.mliter &&
|
||||
!cyl->type.workingpressure.mbar &&
|
||||
!cyl->type.description &&
|
||||
!cyl->gasmix.o2.permille &&
|
||||
!cyl->gasmix.he.permille &&
|
||||
!cyl->start.mbar &&
|
||||
!cyl->end.mbar;
|
||||
return !cyl->type.size.mliter &&
|
||||
!cyl->type.workingpressure.mbar &&
|
||||
!cyl->type.description &&
|
||||
!cyl->gasmix.o2.permille &&
|
||||
!cyl->gasmix.he.permille &&
|
||||
!cyl->start.mbar &&
|
||||
!cyl->end.mbar;
|
||||
}
|
||||
|
||||
static bool cylinder_nosamples(cylinder_t *cyl)
|
||||
{
|
||||
return !cyl->sample_start.mbar &&
|
||||
!cyl->sample_end.mbar;
|
||||
return !cyl->sample_start.mbar &&
|
||||
!cyl->sample_end.mbar;
|
||||
}
|
||||
|
||||
bool cylinder_none(void *_data)
|
||||
|
@ -75,8 +75,8 @@ bool cylinder_none(void *_data)
|
|||
and the same text */
|
||||
static bool description_equal(const char *desc1, const char *desc2)
|
||||
{
|
||||
return ((! desc1 && ! desc2) ||
|
||||
(desc1 && desc2 && strcmp(desc1, desc2) == 0));
|
||||
return ((!desc1 && !desc2) ||
|
||||
(desc1 && desc2 && strcmp(desc1, desc2) == 0));
|
||||
}
|
||||
|
||||
bool weightsystem_none(void *_data)
|
||||
|
@ -98,7 +98,7 @@ bool no_weightsystems(weightsystem_t *ws)
|
|||
static bool one_weightsystem_equal(weightsystem_t *ws1, weightsystem_t *ws2)
|
||||
{
|
||||
return ws1->weight.grams == ws2->weight.grams &&
|
||||
description_equal(ws1->description, ws2->description);
|
||||
description_equal(ws1->description, ws2->description);
|
||||
}
|
||||
|
||||
bool weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2)
|
||||
|
@ -125,38 +125,38 @@ struct tank_info_t tank_info[100] = {
|
|||
{ "11.1 l", .ml = 11100 },
|
||||
|
||||
/* Most common AL cylinders */
|
||||
{ "AL40", .cuft = 40, .psi = 3000 },
|
||||
{ "AL50", .cuft = 50, .psi = 3000 },
|
||||
{ "AL63", .cuft = 63, .psi = 3000 },
|
||||
{ "AL72", .cuft = 72, .psi = 3000 },
|
||||
{ "AL80", .cuft = 80, .psi = 3000 },
|
||||
{ "AL40", .cuft = 40, .psi = 3000 },
|
||||
{ "AL50", .cuft = 50, .psi = 3000 },
|
||||
{ "AL63", .cuft = 63, .psi = 3000 },
|
||||
{ "AL72", .cuft = 72, .psi = 3000 },
|
||||
{ "AL80", .cuft = 80, .psi = 3000 },
|
||||
{ "AL100", .cuft = 100, .psi = 3300 },
|
||||
|
||||
/* Somewhat common LP steel cylinders */
|
||||
{ "LP85", .cuft = 85, .psi = 2640 },
|
||||
{ "LP95", .cuft = 95, .psi = 2640 },
|
||||
{ "LP85", .cuft = 85, .psi = 2640 },
|
||||
{ "LP95", .cuft = 95, .psi = 2640 },
|
||||
{ "LP108", .cuft = 108, .psi = 2640 },
|
||||
{ "LP121", .cuft = 121, .psi = 2640 },
|
||||
|
||||
/* Somewhat common HP steel cylinders */
|
||||
{ "HP65", .cuft = 65, .psi = 3442 },
|
||||
{ "HP80", .cuft = 80, .psi = 3442 },
|
||||
{ "HP65", .cuft = 65, .psi = 3442 },
|
||||
{ "HP80", .cuft = 80, .psi = 3442 },
|
||||
{ "HP100", .cuft = 100, .psi = 3442 },
|
||||
{ "HP119", .cuft = 119, .psi = 3442 },
|
||||
{ "HP130", .cuft = 130, .psi = 3442 },
|
||||
|
||||
/* Common European steel cylinders */
|
||||
{ "3L 232 bar", .ml = 3000, .bar = 232 },
|
||||
{ "3L 300 bar", .ml = 3000, .bar = 300 },
|
||||
{ "10L 300 bar", .ml = 10000, .bar = 300 },
|
||||
{ "12L 200 bar", .ml = 12000, .bar = 200 },
|
||||
{ "12L 232 bar", .ml = 12000, .bar = 232 },
|
||||
{ "12L 300 bar", .ml = 12000, .bar = 300 },
|
||||
{ "15L 200 bar", .ml = 15000, .bar = 200 },
|
||||
{ "15L 232 bar", .ml = 15000, .bar = 232 },
|
||||
{ "D7 300 bar", .ml = 14000, .bar = 300 },
|
||||
{ "3L 232 bar", .ml = 3000, .bar = 232 },
|
||||
{ "3L 300 bar", .ml = 3000, .bar = 300 },
|
||||
{ "10L 300 bar", .ml = 10000, .bar = 300 },
|
||||
{ "12L 200 bar", .ml = 12000, .bar = 200 },
|
||||
{ "12L 232 bar", .ml = 12000, .bar = 232 },
|
||||
{ "12L 300 bar", .ml = 12000, .bar = 300 },
|
||||
{ "15L 200 bar", .ml = 15000, .bar = 200 },
|
||||
{ "15L 232 bar", .ml = 15000, .bar = 232 },
|
||||
{ "D7 300 bar", .ml = 14000, .bar = 300 },
|
||||
{ "D8.5 232 bar", .ml = 17000, .bar = 232 },
|
||||
{ "D12 232 bar", .ml = 24000, .bar = 232 },
|
||||
{ "D12 232 bar", .ml = 24000, .bar = 232 },
|
||||
|
||||
/* We'll fill in more from the dive log dynamically */
|
||||
{ NULL, }
|
||||
|
@ -167,11 +167,11 @@ struct tank_info_t tank_info[100] = {
|
|||
* This is a bit odd as the weight system types don't usually encode weight
|
||||
*/
|
||||
struct ws_info_t ws_info[100] = {
|
||||
{ QT_TRANSLATE_NOOP("gettextFromC","integrated"), 0 },
|
||||
{ QT_TRANSLATE_NOOP("gettextFromC","belt"), 0 },
|
||||
{ QT_TRANSLATE_NOOP("gettextFromC","ankle"), 0 },
|
||||
{ QT_TRANSLATE_NOOP("gettextFromC","backplate weight"), 0 },
|
||||
{ QT_TRANSLATE_NOOP("gettextFromC","clip-on"), 0 },
|
||||
{ QT_TRANSLATE_NOOP("gettextFromC", "integrated"), 0 },
|
||||
{ QT_TRANSLATE_NOOP("gettextFromC", "belt"), 0 },
|
||||
{ QT_TRANSLATE_NOOP("gettextFromC", "ankle"), 0 },
|
||||
{ QT_TRANSLATE_NOOP("gettextFromC", "backplate weight"), 0 },
|
||||
{ QT_TRANSLATE_NOOP("gettextFromC", "clip-on"), 0 },
|
||||
};
|
||||
|
||||
void remove_cylinder(struct dive *dive, int idx)
|
||||
|
|
40
file.c
40
file.c
|
@ -37,7 +37,7 @@ int readfile(const char *filename, struct memblock *mem)
|
|||
ret = 0;
|
||||
if (!st.st_size)
|
||||
goto out;
|
||||
buf = malloc(st.st_size+1);
|
||||
buf = malloc(st.st_size + 1);
|
||||
ret = -1;
|
||||
errno = ENOMEM;
|
||||
if (!buf)
|
||||
|
@ -67,7 +67,7 @@ static void zip_read(struct zip_file *file, char **error, const char *filename)
|
|||
int size = 1024, n, read = 0;
|
||||
char *mem = malloc(size);
|
||||
|
||||
while ((n = zip_fread(file, mem+read, size-read)) > 0) {
|
||||
while ((n = zip_fread(file, mem + read, size - read)) > 0) {
|
||||
read += n;
|
||||
size = read * 3 / 2;
|
||||
mem = realloc(mem, size);
|
||||
|
@ -85,7 +85,7 @@ static int try_to_open_zip(const char *filename, struct memblock *mem, char **er
|
|||
|
||||
if (zip) {
|
||||
int index;
|
||||
for (index = 0; ;index++) {
|
||||
for (index = 0;; index++) {
|
||||
struct zip_file *file = zip_fopen_index(zip, index, 0);
|
||||
if (!file)
|
||||
break;
|
||||
|
@ -104,9 +104,9 @@ static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, char
|
|||
|
||||
if (readfile(filename, mem) < 0) {
|
||||
if (error) {
|
||||
int len = strlen(translate("gettextFromC","Failed to read '%s'")) + strlen(filename);
|
||||
int len = strlen(translate("gettextFromC", "Failed to read '%s'")) + strlen(filename);
|
||||
*error = malloc(len);
|
||||
snprintf(*error, len, translate("gettextFromC","Failed to read '%s'"), filename);
|
||||
snprintf(*error, len, translate("gettextFromC", "Failed to read '%s'"), filename);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -167,7 +167,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, char **err
|
|||
retval = sqlite3_open(filename, &handle);
|
||||
|
||||
if (retval) {
|
||||
fprintf(stderr, translate("gettextFromC","Database connection failed '%s'.\n"), filename);
|
||||
fprintf(stderr, translate("gettextFromC", "Database connection failed '%s'.\n"), filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ timestamp_t parse_date(const char *date)
|
|||
}
|
||||
if (tm.tm_mon > 11)
|
||||
return 0;
|
||||
date = p+3;
|
||||
date = p + 3;
|
||||
tm.tm_year = strtol(date, &p, 10);
|
||||
if (date == p)
|
||||
return 0;
|
||||
|
@ -225,7 +225,9 @@ timestamp_t parse_date(const char *date)
|
|||
}
|
||||
|
||||
enum csv_format {
|
||||
CSV_DEPTH, CSV_TEMP, CSV_PRESSURE
|
||||
CSV_DEPTH,
|
||||
CSV_TEMP,
|
||||
CSV_PRESSURE
|
||||
};
|
||||
|
||||
static void add_sample_data(struct sample *sample, enum csv_format type, double val)
|
||||
|
@ -238,7 +240,7 @@ static void add_sample_data(struct sample *sample, enum csv_format type, double
|
|||
sample->temperature.mkelvin = F_to_mkelvin(val);
|
||||
break;
|
||||
case CSV_PRESSURE:
|
||||
sample->cylinderpressure.mbar = psi_to_mbar(val*4);
|
||||
sample->cylinderpressure.mbar = psi_to_mbar(val * 4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -292,7 +294,7 @@ static int try_to_open_csv(const char *filename, struct memblock *mem, enum csv_
|
|||
struct sample *sample;
|
||||
|
||||
errno = 0;
|
||||
val = strtod(p,&end); // FIXME == localization issue
|
||||
val = strtod(p, &end); // FIXME == localization issue
|
||||
if (end == p)
|
||||
break;
|
||||
if (errno)
|
||||
|
@ -307,7 +309,7 @@ static int try_to_open_csv(const char *filename, struct memblock *mem, enum csv_
|
|||
dc->duration.seconds = time;
|
||||
if (*end != ',')
|
||||
break;
|
||||
p = end+1;
|
||||
p = end + 1;
|
||||
}
|
||||
record_dive(dive);
|
||||
return 1;
|
||||
|
@ -343,7 +345,7 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
|
|||
static void parse_file_buffer(const char *filename, struct memblock *mem, char **error)
|
||||
{
|
||||
char *fmt = strrchr(filename, '.');
|
||||
if (fmt && open_by_filename(filename, fmt+1, mem, error))
|
||||
if (fmt && open_by_filename(filename, fmt + 1, mem, error))
|
||||
return;
|
||||
|
||||
if (!mem->size || !mem->buffer)
|
||||
|
@ -359,13 +361,13 @@ void parse_file(const char *filename, char **error)
|
|||
|
||||
if (readfile(filename, &mem) < 0) {
|
||||
/* we don't want to display an error if this was the default file */
|
||||
if (prefs.default_filename && ! strcmp(filename, prefs.default_filename))
|
||||
if (prefs.default_filename && !strcmp(filename, prefs.default_filename))
|
||||
return;
|
||||
|
||||
if (error) {
|
||||
int len = strlen(translate("gettextFromC","Failed to read '%s'")) + strlen(filename);
|
||||
int len = strlen(translate("gettextFromC", "Failed to read '%s'")) + strlen(filename);
|
||||
*error = malloc(len);
|
||||
snprintf(*error, len, translate("gettextFromC","Failed to read '%s'"), filename);
|
||||
snprintf(*error, len, translate("gettextFromC", "Failed to read '%s'"), filename);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -388,7 +390,7 @@ void parse_file(const char *filename, char **error)
|
|||
void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, int stopdepthf, int sepidx, const char *csvtemplate, int unitidx, char **error)
|
||||
{
|
||||
struct memblock mem;
|
||||
int pnr=0;
|
||||
int pnr = 0;
|
||||
char *params[21];
|
||||
char timebuf[MAXCOLDIGITS];
|
||||
char depthbuf[MAXCOLDIGITS];
|
||||
|
@ -403,7 +405,7 @@ void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int
|
|||
char curdate[9];
|
||||
char curtime[6];
|
||||
|
||||
if (timef >= MAXCOLS || depthf >= MAXCOLS || tempf >= MAXCOLS || po2f >= MAXCOLS || cnsf >= MAXCOLS || stopdepthf >= MAXCOLS ) {
|
||||
if (timef >= MAXCOLS || depthf >= MAXCOLS || tempf >= MAXCOLS || po2f >= MAXCOLS || cnsf >= MAXCOLS || stopdepthf >= MAXCOLS) {
|
||||
int len = strlen(translate("gettextFromC", "Maximum number of supported columns on CSV import is %d")) + MAXCOLDIGITS;
|
||||
*error = malloc(len);
|
||||
snprintf(*error, len, translate("gettextFromC", "Maximum number of supported columns on CSV import is %d"), MAXCOLS);
|
||||
|
@ -461,7 +463,7 @@ void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int
|
|||
void parse_manual_file(const char *filename, int sepidx, int units, int numberf, int datef, int timef, int durationf, int locationf, int gpsf, int maxdepthf, int meandepthf, int buddyf, int notesf, int weightf, int tagsf, char **error)
|
||||
{
|
||||
struct memblock mem;
|
||||
int pnr=0;
|
||||
int pnr = 0;
|
||||
char *params[33];
|
||||
char numberbuf[MAXCOLDIGITS];
|
||||
char datebuf[MAXCOLDIGITS];
|
||||
|
@ -482,7 +484,7 @@ void parse_manual_file(const char *filename, int sepidx, int units, int numberf,
|
|||
char curdate[9];
|
||||
char curtime[6];
|
||||
|
||||
if ( numberf >= MAXCOLS || datef >= MAXCOLS || timef >= MAXCOLS || durationf >= MAXCOLS || locationf >= MAXCOLS || gpsf >= MAXCOLS || maxdepthf >= MAXCOLS || meandepthf >= MAXCOLS || buddyf >= MAXCOLS || notesf >= MAXCOLS || weightf >= MAXCOLS || tagsf >= MAXCOLS ) {
|
||||
if (numberf >= MAXCOLS || datef >= MAXCOLS || timef >= MAXCOLS || durationf >= MAXCOLS || locationf >= MAXCOLS || gpsf >= MAXCOLS || maxdepthf >= MAXCOLS || meandepthf >= MAXCOLS || buddyf >= MAXCOLS || notesf >= MAXCOLS || weightf >= MAXCOLS || tagsf >= MAXCOLS) {
|
||||
int len = strlen(translate("gettextFromC", "Maximum number of supported columns on CSV import is %d")) + MAXCOLDIGITS;
|
||||
*error = malloc(len);
|
||||
snprintf(*error, len, translate("gettextFromC", "Maximum number of supported columns on CSV import is %d"), MAXCOLS);
|
||||
|
|
|
@ -15,7 +15,7 @@ void gettextFromC::reset(void)
|
|||
translationCache.clear();
|
||||
}
|
||||
|
||||
gettextFromC* gettextFromC::instance()
|
||||
gettextFromC *gettextFromC::instance()
|
||||
{
|
||||
static QScopedPointer<gettextFromC> self(new gettextFromC());
|
||||
return self.data();
|
||||
|
|
|
@ -5,14 +5,13 @@
|
|||
|
||||
extern "C" const char *trGettext(const char *text);
|
||||
|
||||
class gettextFromC
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(gettextFromC)
|
||||
class gettextFromC {
|
||||
Q_DECLARE_TR_FUNCTIONS(gettextFromC)
|
||||
public:
|
||||
static gettextFromC *instance();
|
||||
const char *trGettext(const char *text);
|
||||
void reset(void);
|
||||
QHash <QByteArray, QByteArray> translationCache;
|
||||
QHash<QByteArray, QByteArray> translationCache;
|
||||
};
|
||||
|
||||
#endif // GETTEXTFROMC_H
|
||||
|
|
|
@ -28,18 +28,18 @@ void set_default_dive_computer_device(const char *name);
|
|||
QString getSubsurfaceDataPath(QString folderToFind);
|
||||
extern const QString get_dc_nickname(const char *model, uint32_t deviceid);
|
||||
int gettimezoneoffset();
|
||||
int parseTemperatureToMkelvin(const QString& text);
|
||||
int parseTemperatureToMkelvin(const QString &text);
|
||||
QString get_dive_date_string(timestamp_t when);
|
||||
QString get_short_dive_date_string(timestamp_t when);
|
||||
QString get_trip_date_string(timestamp_t when, int nr);
|
||||
|
||||
extern DiveComputerList dcList;
|
||||
|
||||
#define M_OR_FT(_m,_f) ((prefs.units.length == units::METERS) ? ((_m) * 1000) : (feet_to_mm(_f)))
|
||||
#define M_OR_FT(_m, _f) ((prefs.units.length == units::METERS) ? ((_m) * 1000) : (feet_to_mm(_f)))
|
||||
|
||||
#if defined __APPLE__
|
||||
#define TITLE_OR_TEXT(_t,_m) "", _t + "\n" + _m
|
||||
#define TITLE_OR_TEXT(_t, _m) "", _t + "\n" + _m
|
||||
#else
|
||||
#define TITLE_OR_TEXT(_t,_m) _t, _m
|
||||
#define TITLE_OR_TEXT(_t, _m) _t, _m
|
||||
#endif
|
||||
#endif // HELPERS_H
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
|
||||
/* Christ. Libdivecomputer has the worst configuration system ever. */
|
||||
#ifdef HW_FROG_H
|
||||
#define NOT_FROG , 0
|
||||
#define LIBDIVECOMPUTER_SUPPORTS_FROG
|
||||
#define NOT_FROG , 0
|
||||
#define LIBDIVECOMPUTER_SUPPORTS_FROG
|
||||
#else
|
||||
#define NOT_FROG
|
||||
#define NOT_FROG
|
||||
#endif
|
||||
|
||||
char *dumpfile_name;
|
||||
|
@ -40,16 +40,16 @@ static dc_status_t create_parser(device_data_t *devdata, dc_parser_t **parser)
|
|||
struct atomics_gas_info {
|
||||
uint8_t gas_nr;
|
||||
uint8_t po2imit;
|
||||
uint8_t tankspecmethod; /* 1: CF@psi 2: CF@bar 3: wet vol in deciliter */
|
||||
uint8_t tankspecmethod; /* 1: CF@psi 2: CF@bar 3: wet vol in deciliter */
|
||||
uint8_t gasmixtype;
|
||||
uint8_t fo2;
|
||||
uint8_t fhe;
|
||||
uint16_t startpressure; /* in psi */
|
||||
uint16_t tanksize; /* CF or dl */
|
||||
uint16_t startpressure; /* in psi */
|
||||
uint16_t tanksize; /* CF or dl */
|
||||
uint16_t workingpressure;
|
||||
uint16_t sensorid;
|
||||
uint16_t endpressure; /* in psi */
|
||||
uint16_t totalconsumption; /* in liters */
|
||||
uint16_t endpressure; /* in psi */
|
||||
uint16_t totalconsumption; /* in liters */
|
||||
};
|
||||
#define COBALT_CFATPSI 1
|
||||
#define COBALT_CFATBAR 2
|
||||
|
@ -72,7 +72,7 @@ static bool get_tanksize(device_data_t *devdata, const unsigned char *data, cyli
|
|||
printf("incorrect header for Atomics dive\n");
|
||||
return false;
|
||||
}
|
||||
atomics_gas_info = (void*)(data + COBALT_HEADER);
|
||||
atomics_gas_info = (void *)(data + COBALT_HEADER);
|
||||
switch (atomics_gas_info[idx].tankspecmethod) {
|
||||
case COBALT_CFATPSI:
|
||||
airvolume = cuft_to_l(atomics_gas_info[idx].tanksize) * 1000.0;
|
||||
|
@ -96,13 +96,13 @@ static bool get_tanksize(device_data_t *devdata, const unsigned char *data, cyli
|
|||
}
|
||||
|
||||
static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t *parser, int ngases,
|
||||
const unsigned char *data)
|
||||
const unsigned char *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ngases; i++) {
|
||||
int rc;
|
||||
dc_gasmix_t gasmix = {0};
|
||||
dc_gasmix_t gasmix = { 0 };
|
||||
int o2, he;
|
||||
|
||||
rc = dc_parser_get_field(parser, DC_FIELD_GASMIX, i, &gasmix);
|
||||
|
@ -118,7 +118,7 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
|
|||
/* Ignore bogus data - libdivecomputer does some crazy stuff */
|
||||
if (o2 + he <= O2_IN_AIR || o2 >= 1000)
|
||||
o2 = 0;
|
||||
if (he < 0 || he >= 800 || o2+he >= 1000)
|
||||
if (he < 0 || he >= 800 || o2 + he >= 1000)
|
||||
he = 0;
|
||||
|
||||
dive->cylinder[i].gasmix.o2.permille = o2;
|
||||
|
@ -136,12 +136,12 @@ static void handle_event(struct divecomputer *dc, struct sample *sample, dc_samp
|
|||
/* we mark these for translation here, but we store the untranslated strings
|
||||
* and only translate them when they are displayed on screen */
|
||||
static const char *events[] = {
|
||||
QT_TRANSLATE_NOOP("gettextFromC","none"), QT_TRANSLATE_NOOP("gettextFromC","deco stop"), QT_TRANSLATE_NOOP("gettextFromC","rbt"), QT_TRANSLATE_NOOP("gettextFromC","ascent"), QT_TRANSLATE_NOOP("gettextFromC","ceiling"), QT_TRANSLATE_NOOP("gettextFromC","workload"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC","transmitter"), QT_TRANSLATE_NOOP("gettextFromC","violation"), QT_TRANSLATE_NOOP("gettextFromC","bookmark"), QT_TRANSLATE_NOOP("gettextFromC","surface"), QT_TRANSLATE_NOOP("gettextFromC","safety stop"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC","gaschange"), QT_TRANSLATE_NOOP("gettextFromC","safety stop (voluntary)"), QT_TRANSLATE_NOOP("gettextFromC","safety stop (mandatory)"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC","deepstop"), QT_TRANSLATE_NOOP("gettextFromC","ceiling (safety stop)"), QT_TRANSLATE_NOOP3("gettextFromC","below floor","event showing dive is below deco floor and adding deco time"), QT_TRANSLATE_NOOP("gettextFromC","divetime"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC","maxdepth"), QT_TRANSLATE_NOOP("gettextFromC","OLF"), QT_TRANSLATE_NOOP("gettextFromC","PO2"), QT_TRANSLATE_NOOP("gettextFromC","airtime"), QT_TRANSLATE_NOOP("gettextFromC","rgbm"), QT_TRANSLATE_NOOP("gettextFromC","heading"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC","tissue level warning"), QT_TRANSLATE_NOOP("gettextFromC","gaschange"), QT_TRANSLATE_NOOP("gettextFromC","non stop time")
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "none"), QT_TRANSLATE_NOOP("gettextFromC", "deco stop"), QT_TRANSLATE_NOOP("gettextFromC", "rbt"), QT_TRANSLATE_NOOP("gettextFromC", "ascent"), QT_TRANSLATE_NOOP("gettextFromC", "ceiling"), QT_TRANSLATE_NOOP("gettextFromC", "workload"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "transmitter"), QT_TRANSLATE_NOOP("gettextFromC", "violation"), QT_TRANSLATE_NOOP("gettextFromC", "bookmark"), QT_TRANSLATE_NOOP("gettextFromC", "surface"), QT_TRANSLATE_NOOP("gettextFromC", "safety stop"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "gaschange"), QT_TRANSLATE_NOOP("gettextFromC", "safety stop (voluntary)"), QT_TRANSLATE_NOOP("gettextFromC", "safety stop (mandatory)"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "deepstop"), QT_TRANSLATE_NOOP("gettextFromC", "ceiling (safety stop)"), QT_TRANSLATE_NOOP3("gettextFromC", "below floor", "event showing dive is below deco floor and adding deco time"), QT_TRANSLATE_NOOP("gettextFromC", "divetime"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "maxdepth"), QT_TRANSLATE_NOOP("gettextFromC", "OLF"), QT_TRANSLATE_NOOP("gettextFromC", "PO2"), QT_TRANSLATE_NOOP("gettextFromC", "airtime"), QT_TRANSLATE_NOOP("gettextFromC", "rgbm"), QT_TRANSLATE_NOOP("gettextFromC", "heading"),
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "tissue level warning"), QT_TRANSLATE_NOOP("gettextFromC", "gaschange"), QT_TRANSLATE_NOOP("gettextFromC", "non stop time")
|
||||
};
|
||||
const int nr_events = sizeof(events) / sizeof(const char *);
|
||||
const char *name;
|
||||
|
@ -158,7 +158,7 @@ static void handle_event(struct divecomputer *dc, struct sample *sample, dc_samp
|
|||
* Other evens might be more interesting, but for now we just print them out.
|
||||
*/
|
||||
type = value.event.type;
|
||||
name = QT_TRANSLATE_NOOP("gettextFromC","invalid event number");
|
||||
name = QT_TRANSLATE_NOOP("gettextFromC", "invalid event number");
|
||||
if (type < nr_events)
|
||||
name = events[type];
|
||||
|
||||
|
@ -180,7 +180,7 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
|
|||
* We fill in the "previous" sample - except for DC_SAMPLE_TIME,
|
||||
* which creates a new one.
|
||||
*/
|
||||
sample = dc->samples ? dc->sample+dc->samples-1 : NULL;
|
||||
sample = dc->samples ? dc->sample + dc->samples - 1 : NULL;
|
||||
|
||||
/*
|
||||
* Ok, sanity check.
|
||||
|
@ -227,9 +227,9 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
|
|||
break;
|
||||
case DC_SAMPLE_VENDOR:
|
||||
printf(" <vendor time='%u:%02u' type=\"%u\" size=\"%u\">", FRACTION(sample->time.seconds, 60),
|
||||
value.vendor.type, value.vendor.size);
|
||||
value.vendor.type, value.vendor.size);
|
||||
for (i = 0; i < value.vendor.size; ++i)
|
||||
printf("%02X", ((unsigned char *) value.vendor.data)[i]);
|
||||
printf("%02X", ((unsigned char *)value.vendor.data)[i]);
|
||||
printf("</vendor>\n");
|
||||
break;
|
||||
#if DC_VERSION_CHECK(0, 3, 0)
|
||||
|
@ -358,9 +358,9 @@ static char *str_printf(const char *fmt, ...)
|
|||
char buf[1024];
|
||||
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf, sizeof(buf)-1, fmt, args);
|
||||
vsnprintf(buf, sizeof(buf) - 1, fmt, args);
|
||||
va_end(args);
|
||||
buf[sizeof(buf)-1] = 0;
|
||||
buf[sizeof(buf) - 1] = 0;
|
||||
return strdup(buf);
|
||||
}
|
||||
|
||||
|
@ -384,13 +384,13 @@ static uint32_t calculate_diveid(const unsigned char *fingerprint, unsigned int
|
|||
/* returns true if we want libdivecomputer's dc_device_foreach() to continue,
|
||||
* false otherwise */
|
||||
static int dive_cb(const unsigned char *data, unsigned int size,
|
||||
const unsigned char *fingerprint, unsigned int fsize,
|
||||
void *userdata)
|
||||
const unsigned char *fingerprint, unsigned int fsize,
|
||||
void *userdata)
|
||||
{
|
||||
int rc;
|
||||
dc_parser_t *parser = NULL;
|
||||
device_data_t *devdata = userdata;
|
||||
dc_datetime_t dt = {0};
|
||||
dc_datetime_t dt = { 0 };
|
||||
struct tm tm;
|
||||
struct dive *dive;
|
||||
|
||||
|
@ -400,13 +400,13 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
|
||||
rc = create_parser(devdata, &parser);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dev_info(devdata, translate("gettextFromC","Unable to create parser for %s %s"), devdata->vendor, devdata->product);
|
||||
dev_info(devdata, translate("gettextFromC", "Unable to create parser for %s %s"), devdata->vendor, devdata->product);
|
||||
return false;
|
||||
}
|
||||
|
||||
rc = dc_parser_set_data(parser, data, size);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dev_info(devdata, translate("gettextFromC","Error registering the data"));
|
||||
dev_info(devdata, translate("gettextFromC", "Error registering the data"));
|
||||
dc_parser_destroy(parser);
|
||||
return false;
|
||||
}
|
||||
|
@ -415,7 +415,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
dive = alloc_dive();
|
||||
rc = dc_parser_get_datetime(parser, &dt);
|
||||
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||
dev_info(devdata, translate("gettextFromC","Error parsing the datetime"));
|
||||
dev_info(devdata, translate("gettextFromC", "Error parsing the datetime"));
|
||||
dc_parser_destroy(parser);
|
||||
return false;
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
dive->dc.diveid = calculate_diveid(fingerprint, fsize);
|
||||
|
||||
tm.tm_year = dt.year;
|
||||
tm.tm_mon = dt.month-1;
|
||||
tm.tm_mon = dt.month - 1;
|
||||
tm.tm_mday = dt.day;
|
||||
tm.tm_hour = dt.hour;
|
||||
tm.tm_min = dt.minute;
|
||||
|
@ -432,12 +432,12 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
dive->when = dive->dc.when = utc_mktime(&tm);
|
||||
|
||||
// Parse the divetime.
|
||||
dev_info(devdata, translate("gettextFromC","Dive %d: %s %d %04d"), import_dive_number,
|
||||
monthname(tm.tm_mon), tm.tm_mday, year(tm.tm_year));
|
||||
dev_info(devdata, translate("gettextFromC", "Dive %d: %s %d %04d"), import_dive_number,
|
||||
monthname(tm.tm_mon), tm.tm_mday, year(tm.tm_year));
|
||||
unsigned int divetime = 0;
|
||||
rc = dc_parser_get_field (parser, DC_FIELD_DIVETIME, 0, &divetime);
|
||||
rc = dc_parser_get_field(parser, DC_FIELD_DIVETIME, 0, &divetime);
|
||||
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||
dev_info(devdata, translate("gettextFromC","Error parsing the divetime"));
|
||||
dev_info(devdata, translate("gettextFromC", "Error parsing the divetime"));
|
||||
dc_parser_destroy(parser);
|
||||
return false;
|
||||
}
|
||||
|
@ -447,7 +447,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
double maxdepth = 0.0;
|
||||
rc = dc_parser_get_field(parser, DC_FIELD_MAXDEPTH, 0, &maxdepth);
|
||||
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||
dev_info(devdata, translate("gettextFromC","Error parsing the maxdepth"));
|
||||
dev_info(devdata, translate("gettextFromC", "Error parsing the maxdepth"));
|
||||
dc_parser_destroy(parser);
|
||||
return false;
|
||||
}
|
||||
|
@ -457,7 +457,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
unsigned int ngases = 0;
|
||||
rc = dc_parser_get_field(parser, DC_FIELD_GASMIX_COUNT, 0, &ngases);
|
||||
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||
dev_info(devdata, translate("gettextFromC","Error parsing the gas mix count"));
|
||||
dev_info(devdata, translate("gettextFromC", "Error parsing the gas mix count"));
|
||||
dc_parser_destroy(parser);
|
||||
return false;
|
||||
}
|
||||
|
@ -466,11 +466,11 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
// Check if the libdivecomputer version already supports salinity & atmospheric
|
||||
dc_salinity_t salinity = {
|
||||
.type = DC_WATER_SALT,
|
||||
.density = SEAWATER_SALINITY/10.0
|
||||
.density = SEAWATER_SALINITY / 10.0
|
||||
};
|
||||
rc = dc_parser_get_field(parser, DC_FIELD_SALINITY, 0, &salinity);
|
||||
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||
dev_info(devdata, translate("gettextFromC","Error obtaining water salinity"));
|
||||
dev_info(devdata, translate("gettextFromC", "Error obtaining water salinity"));
|
||||
dc_parser_destroy(parser);
|
||||
return false;
|
||||
}
|
||||
|
@ -479,7 +479,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
double surface_pressure = 0;
|
||||
rc = dc_parser_get_field(parser, DC_FIELD_ATMOSPHERIC, 0, &surface_pressure);
|
||||
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||
dev_info(devdata, translate("gettextFromC","Error obtaining surface pressure"));
|
||||
dev_info(devdata, translate("gettextFromC", "Error obtaining surface pressure"));
|
||||
dc_parser_destroy(parser);
|
||||
return false;
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
|
||||
rc = parse_gasmixes(devdata, dive, parser, ngases, data);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dev_info(devdata, translate("gettextFromC","Error parsing the gas mix"));
|
||||
dev_info(devdata, translate("gettextFromC", "Error parsing the gas mix"));
|
||||
dc_parser_destroy(parser);
|
||||
return false;
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
// Initialize the sample data.
|
||||
rc = parse_samples(devdata, &dive->dc, parser);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dev_info(devdata, translate("gettextFromC","Error parsing the samples"));
|
||||
dev_info(devdata, translate("gettextFromC", "Error parsing the samples"));
|
||||
dc_parser_destroy(parser);
|
||||
return false;
|
||||
}
|
||||
|
@ -570,10 +570,14 @@ static unsigned int undo_libdivecomputer_suunto_nr_changes(unsigned int serial)
|
|||
return serial;
|
||||
|
||||
/* Nope, it was converted. */
|
||||
b0 = serial % 100; serial /= 100;
|
||||
b1 = serial % 100; serial /= 100;
|
||||
b2 = serial % 100; serial /= 100;
|
||||
b3 = serial % 100; serial /= 100;
|
||||
b0 = serial % 100;
|
||||
serial /= 100;
|
||||
b1 = serial % 100;
|
||||
serial /= 100;
|
||||
b2 = serial % 100;
|
||||
serial /= 100;
|
||||
b3 = serial % 100;
|
||||
serial /= 100;
|
||||
|
||||
serial = b0 + (b1 << 8) + (b2 << 16) + (b3 << 24);
|
||||
return serial;
|
||||
|
@ -591,16 +595,16 @@ static unsigned int fixup_suunto_versions(device_data_t *devdata, const dc_event
|
|||
|
||||
if (serial) {
|
||||
snprintf(serial_nr, sizeof(serial_nr), "%02d%02d%02d%02d",
|
||||
(devinfo->serial >> 24) & 0xff,
|
||||
(devinfo->serial >> 16) & 0xff,
|
||||
(devinfo->serial >> 8) & 0xff,
|
||||
(devinfo->serial >> 0) & 0xff);
|
||||
(devinfo->serial >> 24) & 0xff,
|
||||
(devinfo->serial >> 16) & 0xff,
|
||||
(devinfo->serial >> 8) & 0xff,
|
||||
(devinfo->serial >> 0) & 0xff);
|
||||
}
|
||||
if (devinfo->firmware) {
|
||||
snprintf(firmware, sizeof(firmware), "%d.%d.%d",
|
||||
(devinfo->firmware >> 16) & 0xff,
|
||||
(devinfo->firmware >> 8) & 0xff,
|
||||
(devinfo->firmware >> 0) & 0xff);
|
||||
(devinfo->firmware >> 16) & 0xff,
|
||||
(devinfo->firmware >> 8) & 0xff,
|
||||
(devinfo->firmware >> 0) & 0xff);
|
||||
}
|
||||
create_device_node(devdata->model, devdata->deviceid, serial_nr, firmware, "");
|
||||
|
||||
|
@ -618,18 +622,18 @@ static void event_cb(dc_device_t *device, dc_event_type_t event, const void *dat
|
|||
|
||||
switch (event) {
|
||||
case DC_EVENT_WAITING:
|
||||
dev_info(devdata, translate("gettextFromC","Event: waiting for user action"));
|
||||
dev_info(devdata, translate("gettextFromC", "Event: waiting for user action"));
|
||||
break;
|
||||
case DC_EVENT_PROGRESS:
|
||||
if (!progress->maximum)
|
||||
break;
|
||||
progress_bar_fraction = (double) progress->current / (double) progress->maximum;
|
||||
progress_bar_fraction = (double)progress->current / (double)progress->maximum;
|
||||
break;
|
||||
case DC_EVENT_DEVINFO:
|
||||
dev_info(devdata, translate("gettextFromC","model=%u (0x%08x), firmware=%u (0x%08x), serial=%u (0x%08x)"),
|
||||
devinfo->model, devinfo->model,
|
||||
devinfo->firmware, devinfo->firmware,
|
||||
devinfo->serial, devinfo->serial);
|
||||
dev_info(devdata, translate("gettextFromC", "model=%u (0x%08x), firmware=%u (0x%08x), serial=%u (0x%08x)"),
|
||||
devinfo->model, devinfo->model,
|
||||
devinfo->firmware, devinfo->firmware,
|
||||
devinfo->serial, devinfo->serial);
|
||||
if (devdata->libdc_logfile) {
|
||||
fprintf(devdata->libdc_logfile, "Event: model=%u (0x%08x), firmware=%u (0x%08x), serial=%u (0x%08x)\n",
|
||||
devinfo->model, devinfo->model,
|
||||
|
@ -647,10 +651,10 @@ static void event_cb(dc_device_t *device, dc_event_type_t event, const void *dat
|
|||
|
||||
break;
|
||||
case DC_EVENT_CLOCK:
|
||||
dev_info(devdata, translate("gettextFromC","Event: systime=%"PRId64", devtime=%u\n"),
|
||||
(uint64_t)clock->systime, clock->devtime);
|
||||
dev_info(devdata, translate("gettextFromC", "Event: systime=%" PRId64 ", devtime=%u\n"),
|
||||
(uint64_t)clock->systime, clock->devtime);
|
||||
if (devdata->libdc_logfile) {
|
||||
fprintf(devdata->libdc_logfile, "Event: systime=%"PRId64", devtime=%u\n",
|
||||
fprintf(devdata->libdc_logfile, "Event: systime=%" PRId64 ", devtime=%u\n",
|
||||
(uint64_t)clock->systime, clock->devtime);
|
||||
}
|
||||
break;
|
||||
|
@ -659,7 +663,7 @@ static void event_cb(dc_device_t *device, dc_event_type_t event, const void *dat
|
|||
fprintf(devdata->libdc_logfile, "Event: vendor=");
|
||||
for (unsigned int i = 0; i < vendor->size; ++i)
|
||||
fprintf(devdata->libdc_logfile, "%02X", vendor->data[i]);
|
||||
fprintf(devdata->libdc_logfile,"\n");
|
||||
fprintf(devdata->libdc_logfile, "\n");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -667,7 +671,7 @@ static void event_cb(dc_device_t *device, dc_event_type_t event, const void *dat
|
|||
}
|
||||
}
|
||||
|
||||
int import_thread_cancelled;
|
||||
int import_thread_cancelled;
|
||||
|
||||
static int
|
||||
cancel_cb(void *userdata)
|
||||
|
@ -686,33 +690,33 @@ static const char *do_device_import(device_data_t *data)
|
|||
int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK | DC_EVENT_VENDOR;
|
||||
rc = dc_device_set_events(device, events, event_cb, data);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return translate("gettextFromC","Error registering the event handler.");
|
||||
return translate("gettextFromC", "Error registering the event handler.");
|
||||
|
||||
// Register the cancellation handler.
|
||||
rc = dc_device_set_cancel(device, cancel_cb, data);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return translate("gettextFromC","Error registering the cancellation handler.");
|
||||
return translate("gettextFromC", "Error registering the cancellation handler.");
|
||||
|
||||
if (data->libdc_dump) {
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
dc_buffer_t *buffer = dc_buffer_new(0);
|
||||
|
||||
rc = dc_device_dump (device, buffer);
|
||||
rc = dc_device_dump(device, buffer);
|
||||
if (rc == DC_STATUS_SUCCESS && dumpfile_name) {
|
||||
FILE* fp = subsurface_fopen(dumpfile_name, "wb");
|
||||
FILE *fp = subsurface_fopen(dumpfile_name, "wb");
|
||||
if (fp != NULL) {
|
||||
fwrite (dc_buffer_get_data (buffer), 1, dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
fwrite(dc_buffer_get_data(buffer), 1, dc_buffer_get_size(buffer), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
dc_buffer_free(buffer);
|
||||
} else {
|
||||
rc = dc_device_foreach(device, dive_cb, data);
|
||||
}
|
||||
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
progress_bar_fraction = 0.0;
|
||||
return translate("gettextFromC","Dive data import error");
|
||||
return translate("gettextFromC", "Dive data import error");
|
||||
}
|
||||
|
||||
/* All good */
|
||||
|
@ -722,9 +726,9 @@ static const char *do_device_import(device_data_t *data)
|
|||
static void
|
||||
logfunc(dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata)
|
||||
{
|
||||
const char *loglevels[] = {"NONE", "ERROR", "WARNING", "INFO", "DEBUG", "ALL"};
|
||||
const char *loglevels[] = { "NONE", "ERROR", "WARNING", "INFO", "DEBUG", "ALL" };
|
||||
|
||||
FILE *fp = (FILE *) userdata;
|
||||
FILE *fp = (FILE *)userdata;
|
||||
|
||||
if (loglevel == DC_LOGLEVEL_ERROR || loglevel == DC_LOGLEVEL_WARNING) {
|
||||
fprintf(fp, "%s: %s [in %s:%d (%s)]\n", loglevels[loglevel], msg, file, line, function);
|
||||
|
@ -751,14 +755,14 @@ const char *do_libdivecomputer_import(device_data_t *data)
|
|||
|
||||
rc = dc_context_new(&data->context);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return translate("gettextFromC","Unable to create libdivecomputer context");
|
||||
return translate("gettextFromC", "Unable to create libdivecomputer context");
|
||||
|
||||
if (fp) {
|
||||
dc_context_set_loglevel(data->context, DC_LOGLEVEL_ALL);
|
||||
dc_context_set_logfunc(data->context, logfunc, fp);
|
||||
}
|
||||
|
||||
err = translate("gettextFromC","Unable to open %s %s (%s)");
|
||||
err = translate("gettextFromC", "Unable to open %s %s (%s)");
|
||||
rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
|
||||
if (rc == DC_STATUS_SUCCESS) {
|
||||
err = do_device_import(data);
|
||||
|
|
|
@ -15,7 +15,8 @@ extern "C" {
|
|||
|
||||
/* don't forget to include the UI toolkit specific display-XXX.h first
|
||||
to get the definition of progressbar_t */
|
||||
typedef struct device_data_t {
|
||||
typedef struct device_data_t
|
||||
{
|
||||
dc_descriptor_t *descriptor;
|
||||
const char *vendor, *product, *devname;
|
||||
const char *model;
|
||||
|
|
20
linux.c
20
linux.c
|
@ -25,7 +25,7 @@ const char *system_default_filename(void)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
int enumerate_devices (device_callback_t callback, void *userdata)
|
||||
int enumerate_devices(device_callback_t callback, void *userdata)
|
||||
{
|
||||
int index = -1;
|
||||
DIR *dp = NULL;
|
||||
|
@ -44,28 +44,28 @@ int enumerate_devices (device_callback_t callback, void *userdata)
|
|||
char *fname;
|
||||
size_t len;
|
||||
|
||||
dp = opendir (dirname);
|
||||
dp = opendir(dirname);
|
||||
if (dp == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ((ep = readdir (dp)) != NULL) {
|
||||
while ((ep = readdir(dp)) != NULL) {
|
||||
for (i = 0; patterns[i] != NULL; ++i) {
|
||||
if (fnmatch (patterns[i], ep->d_name, 0) == 0) {
|
||||
if (fnmatch(patterns[i], ep->d_name, 0) == 0) {
|
||||
char filename[1024];
|
||||
int n = snprintf (filename, sizeof (filename), "%s/%s", dirname, ep->d_name);
|
||||
if (n >= sizeof (filename)) {
|
||||
closedir (dp);
|
||||
int n = snprintf(filename, sizeof(filename), "%s/%s", dirname, ep->d_name);
|
||||
if (n >= sizeof(filename)) {
|
||||
closedir(dp);
|
||||
return -1;
|
||||
}
|
||||
callback (filename, userdata);
|
||||
callback(filename, userdata);
|
||||
if (is_default_dive_computer_device(filename))
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir (dp);
|
||||
closedir(dp);
|
||||
|
||||
file = fopen("/proc/mounts", "r");
|
||||
if (file == NULL)
|
||||
|
@ -91,7 +91,7 @@ int enumerate_devices (device_callback_t callback, void *userdata)
|
|||
index = i;
|
||||
i++;
|
||||
free((void *)fname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(line);
|
||||
|
|
24
macos.c
24
macos.c
|
@ -17,9 +17,9 @@
|
|||
* but no similar macros if a C string variable is supposed to be
|
||||
* the argument. We add this here (hardcoding the default allocator
|
||||
* and MacRoman encoding */
|
||||
#define CFSTR_VAR(_var) CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, \
|
||||
(_var), kCFStringEncodingMacRoman, \
|
||||
kCFAllocatorNull)
|
||||
#define CFSTR_VAR(_var) CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, \
|
||||
(_var), kCFStringEncodingMacRoman, \
|
||||
kCFAllocatorNull)
|
||||
|
||||
#define SUBSURFACE_PREFERENCES CFSTR("org.hohndel.subsurface")
|
||||
#define ICON_NAME "Subsurface.icns"
|
||||
|
@ -41,7 +41,7 @@ const char *system_default_filename(void)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
int enumerate_devices (device_callback_t callback, void *userdata)
|
||||
int enumerate_devices(device_callback_t callback, void *userdata)
|
||||
{
|
||||
int index = -1;
|
||||
DIR *dp = NULL;
|
||||
|
@ -54,21 +54,21 @@ int enumerate_devices (device_callback_t callback, void *userdata)
|
|||
NULL
|
||||
};
|
||||
|
||||
dp = opendir (dirname);
|
||||
dp = opendir(dirname);
|
||||
if (dp == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ((ep = readdir (dp)) != NULL) {
|
||||
while ((ep = readdir(dp)) != NULL) {
|
||||
for (i = 0; patterns[i] != NULL; ++i) {
|
||||
if (fnmatch (patterns[i], ep->d_name, 0) == 0) {
|
||||
if (fnmatch(patterns[i], ep->d_name, 0) == 0) {
|
||||
char filename[1024];
|
||||
int n = snprintf (filename, sizeof (filename), "%s/%s", dirname, ep->d_name);
|
||||
if (n >= sizeof (filename)) {
|
||||
closedir (dp);
|
||||
int n = snprintf(filename, sizeof(filename), "%s/%s", dirname, ep->d_name);
|
||||
if (n >= sizeof(filename)) {
|
||||
closedir(dp);
|
||||
return -1;
|
||||
}
|
||||
callback (filename, userdata);
|
||||
callback(filename, userdata);
|
||||
if (is_default_dive_computer_device(filename))
|
||||
index = i;
|
||||
break;
|
||||
|
@ -77,7 +77,7 @@ int enumerate_devices (device_callback_t callback, void *userdata)
|
|||
}
|
||||
// TODO: list UEMIS mount point from /proc/mounts
|
||||
|
||||
closedir (dp);
|
||||
closedir(dp);
|
||||
return index;
|
||||
}
|
||||
|
||||
|
|
2
main.cpp
2
main.cpp
|
@ -45,7 +45,7 @@ int main(int argc, char **argv)
|
|||
if (no_filenames) {
|
||||
QString defaultFile(prefs.default_filename);
|
||||
if (!defaultFile.isEmpty())
|
||||
files.push_back( QString(prefs.default_filename) );
|
||||
files.push_back(QString(prefs.default_filename));
|
||||
}
|
||||
parse_xml_exit();
|
||||
MainWindow::instance()->loadFiles(files);
|
||||
|
|
|
@ -24,7 +24,7 @@ void flush_buffer(struct membuffer *b, FILE *f)
|
|||
|
||||
void strip_mb(struct membuffer *b)
|
||||
{
|
||||
while (b->len && isspace(b->buffer[b->len-1]))
|
||||
while (b->len && isspace(b->buffer[b->len - 1]))
|
||||
b->len--;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ struct membuffer {
|
|||
};
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define __printf(x,y) __attribute__ ((__format__ (__printf__, x, y)))
|
||||
#define __printf(x, y) __attribute__((__format__(__printf__, x, y)))
|
||||
#else
|
||||
#define __printf(x,y)
|
||||
#define __printf(x, y)
|
||||
#endif
|
||||
|
||||
extern void free_buffer(struct membuffer *);
|
||||
|
@ -23,8 +23,8 @@ extern void flush_buffer(struct membuffer *, FILE *);
|
|||
extern void put_bytes(struct membuffer *, const char *, int);
|
||||
extern void put_string(struct membuffer *, const char *);
|
||||
extern void strip_mb(struct membuffer *);
|
||||
extern __printf(2,0) void put_vformat(struct membuffer *, const char *, va_list);
|
||||
extern __printf(2,3) void put_format(struct membuffer *, const char *fmt, ...);
|
||||
extern __printf(2, 0) void put_vformat(struct membuffer *, const char *, va_list);
|
||||
extern __printf(2, 3) void put_format(struct membuffer *, const char *fmt, ...);
|
||||
|
||||
/* Output one of our "milli" values with type and pre/post data */
|
||||
extern void put_milli(struct membuffer *, const char *, int, const char *);
|
||||
|
|
96
planner.c
96
planner.c
|
@ -18,8 +18,7 @@ unsigned int decostoplevels[] = { 0, 3000, 6000, 9000, 12000, 15000, 18000, 2100
|
|||
60000, 63000, 66000, 69000, 72000, 75000, 78000, 81000, 84000, 87000,
|
||||
90000, 100000, 110000, 120000, 130000, 140000, 150000, 160000, 170000,
|
||||
180000, 190000, 200000, 220000, 240000, 260000, 280000, 300000,
|
||||
320000, 340000, 360000, 380000
|
||||
};
|
||||
320000, 340000, 360000, 380000 };
|
||||
double plangflow, plangfhigh;
|
||||
char *disclaimer;
|
||||
|
||||
|
@ -30,21 +29,20 @@ void dump_plan(struct diveplan *diveplan)
|
|||
struct tm tm;
|
||||
|
||||
if (!diveplan) {
|
||||
printf ("Diveplan NULL\n");
|
||||
printf("Diveplan NULL\n");
|
||||
return;
|
||||
}
|
||||
utc_mkdate(diveplan->when, &tm);
|
||||
|
||||
printf("\nDiveplan @ %04d-%02d-%02d %02d:%02d:%02d (surfpres %dmbar):\n",
|
||||
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
|
||||
tm.tm_hour, tm.tm_min, tm.tm_sec,
|
||||
diveplan->surface_pressure);
|
||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
|
||||
tm.tm_hour, tm.tm_min, tm.tm_sec,
|
||||
diveplan->surface_pressure);
|
||||
dp = diveplan->dp;
|
||||
while (dp) {
|
||||
printf("\t%3u:%02u: %dmm gas: %d o2 %d h2\n", FRACTION(dp->time, 60), dp->depth, dp->o2, dp->he);
|
||||
dp = dp->next;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -94,11 +92,11 @@ int get_gasidx(struct dive *dive, int o2, int he)
|
|||
void get_gas_string(int o2, int he, char *text, int len)
|
||||
{
|
||||
if (is_air(o2, he))
|
||||
snprintf(text, len, "%s", translate("gettextFromC","air"));
|
||||
snprintf(text, len, "%s", translate("gettextFromC", "air"));
|
||||
else if (he == 0)
|
||||
snprintf(text, len, translate("gettextFromC","EAN%d"), (o2 + 5) / 10);
|
||||
snprintf(text, len, translate("gettextFromC", "EAN%d"), (o2 + 5) / 10);
|
||||
else
|
||||
snprintf(text, len, "(%d/%d)", (o2 + 5) / 10, (he + 5) / 10);
|
||||
snprintf(text, len, "(%d/%d)", (o2 + 5) / 10, (he + 5) / 10);
|
||||
}
|
||||
|
||||
/* returns the tissue tolerance at the end of this (partial) dive */
|
||||
|
@ -131,7 +129,7 @@ double tissue_at_end(struct dive *dive, char **cached_datap, const char **error_
|
|||
t1 = sample->time.seconds;
|
||||
get_gas_from_events(&dive->dc, t0, &o2, &he);
|
||||
if ((gasidx = get_gasidx(dive, o2, he)) == -1) {
|
||||
snprintf(buf, sizeof(buf),translate("gettextFromC","Can't find gas %d/%d"), (o2 + 5) / 10, (he + 5) / 10);
|
||||
snprintf(buf, sizeof(buf), translate("gettextFromC", "Can't find gas %d/%d"), (o2 + 5) / 10, (he + 5) / 10);
|
||||
*error_string_p = buf;
|
||||
gasidx = 0;
|
||||
}
|
||||
|
@ -288,10 +286,11 @@ struct dive *create_dive_from_plan(struct diveplan *diveplan, const char **error
|
|||
int plano2 = (o2 + 5) / 10 * 10;
|
||||
int planhe = (he + 5) / 10 * 10;
|
||||
int idx;
|
||||
if ((idx = add_gas(dive, plano2, planhe)) < 0)
|
||||
if ((idx = add_gas(dive, plano2, planhe)) < 0)
|
||||
goto gas_error_exit;
|
||||
add_gas_switch_event(dive, dc, lasttime, idx);
|
||||
oldo2 = o2; oldhe = he;
|
||||
oldo2 = o2;
|
||||
oldhe = he;
|
||||
}
|
||||
/* Create sample */
|
||||
sample = prepare_sample(dc);
|
||||
|
@ -318,7 +317,7 @@ struct dive *create_dive_from_plan(struct diveplan *diveplan, const char **error
|
|||
|
||||
gas_error_exit:
|
||||
free(dive);
|
||||
*error_string = translate("gettextFromC","Too many gas mixes");
|
||||
*error_string = translate("gettextFromC", "Too many gas mixes");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -379,11 +378,11 @@ void add_to_end_of_diveplan(struct diveplan *diveplan, struct divedatapoint *dp)
|
|||
dp->time += lasttime;
|
||||
}
|
||||
|
||||
struct divedatapoint * plan_add_segment(struct diveplan *diveplan, int duration, int depth, int o2, int he, int po2)
|
||||
struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int o2, int he, int po2)
|
||||
{
|
||||
struct divedatapoint *dp = create_dp(duration, depth, o2, he, po2);
|
||||
add_to_end_of_diveplan(diveplan, dp);
|
||||
return(dp);
|
||||
return (dp);
|
||||
}
|
||||
|
||||
struct gaschanges {
|
||||
|
@ -427,8 +426,8 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive
|
|||
#if DEBUG_PLAN & 16
|
||||
for (nr = 0; nr < *gaschangenr; nr++)
|
||||
printf("gaschange nr %d: @ %5.2lfm gasidx %d (%d/%d)\n", nr, gaschanges[nr].depth / 1000.0,
|
||||
gaschanges[nr].gasidx, (dive->cylinder[gaschanges[nr].gasidx].gasmix.o2.permille + 5) / 10,
|
||||
(dive->cylinder[gaschanges[nr].gasidx].gasmix.he.permille + 5) / 10);
|
||||
gaschanges[nr].gasidx, (dive->cylinder[gaschanges[nr].gasidx].gasmix.o2.permille + 5) / 10,
|
||||
(dive->cylinder[gaschanges[nr].gasidx].gasmix.he.permille + 5) / 10);
|
||||
#endif
|
||||
return gaschanges;
|
||||
}
|
||||
|
@ -477,8 +476,8 @@ static unsigned int *sort_stops(unsigned int *dstops, int dnr, struct gaschanges
|
|||
|
||||
#if DEBUG_PLAN & 16
|
||||
int k;
|
||||
for (k = gnr + dnr -1; k >= 0; k--) {
|
||||
printf("stoplevel[%d]: %5.2lfm\n", k, stoplevels[k]/1000.0);
|
||||
for (k = gnr + dnr - 1; k >= 0; k--) {
|
||||
printf("stoplevel[%d]: %5.2lfm\n", k, stoplevels[k] / 1000.0);
|
||||
if (stoplevels[k] == 0)
|
||||
break;
|
||||
}
|
||||
|
@ -498,8 +497,8 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
|
|||
if (!dp)
|
||||
return;
|
||||
|
||||
snprintf(buffer, sizeof(buffer), translate("gettextFromC","%s\nSubsurface dive plan\nbased on GFlow = %.0f and GFhigh = %.0f\n\n"),
|
||||
disclaimer, plangflow * 100, plangfhigh * 100);
|
||||
snprintf(buffer, sizeof(buffer), translate("gettextFromC", "%s\nSubsurface dive plan\nbased on GFlow = %.0f and GFhigh = %.0f\n\n"),
|
||||
disclaimer, plangflow * 100, plangfhigh * 100);
|
||||
/* we start with gas 0, then check if that was changed */
|
||||
o2 = dive->cylinder[0].gasmix.o2.permille;
|
||||
he = dive->cylinder[0].gasmix.he.permille;
|
||||
|
@ -538,28 +537,28 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
|
|||
len = strlen(buffer);
|
||||
if (dp->depth != lastdepth) {
|
||||
used = diveplan->bottomsac / 1000.0 * depth_to_mbar((dp->depth + lastdepth) / 2, dive) *
|
||||
(dp->time - lasttime) / 60;
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC","Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s\n"),
|
||||
decimals, depthvalue, depth_unit,
|
||||
FRACTION(dp->time - lasttime, 60),
|
||||
FRACTION(dp->time, 60),
|
||||
gas);
|
||||
(dp->time - lasttime) / 60;
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s\n"),
|
||||
decimals, depthvalue, depth_unit,
|
||||
FRACTION(dp->time - lasttime, 60),
|
||||
FRACTION(dp->time, 60),
|
||||
gas);
|
||||
} else {
|
||||
/* we use deco SAC rate during the calculated deco stops, bottom SAC rate everywhere else */
|
||||
int sac = dp->entered ? diveplan->bottomsac : diveplan->decosac;
|
||||
used = sac / 1000.0 * depth_to_mbar(dp->depth, dive) * (dp->time - lasttime) / 60;
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC","Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s\n"),
|
||||
decimals, depthvalue, depth_unit,
|
||||
FRACTION(dp->time - lasttime, 60),
|
||||
FRACTION(dp->time, 60),
|
||||
gas);
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s\n"),
|
||||
decimals, depthvalue, depth_unit,
|
||||
FRACTION(dp->time - lasttime, 60),
|
||||
FRACTION(dp->time, 60),
|
||||
gas);
|
||||
}
|
||||
if (gasidx != -1)
|
||||
consumption[gasidx] += used;
|
||||
get_gas_string(newo2, newhe, gas, sizeof(gas));
|
||||
if (o2 != newo2 || he != newhe) {
|
||||
len = strlen(buffer);
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC","Switch gas to %s\n"), gas);
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s\n"), gas);
|
||||
}
|
||||
o2 = newo2;
|
||||
he = newhe;
|
||||
|
@ -567,7 +566,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
|
|||
lastdepth = dp->depth;
|
||||
} while ((dp = dp->next) != NULL);
|
||||
len = strlen(buffer);
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC","Gas consumption:\n"));
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Gas consumption:\n"));
|
||||
for (gasidx = 0; gasidx < MAX_CYLINDERS; gasidx++) {
|
||||
double volume;
|
||||
const char *unit;
|
||||
|
@ -577,8 +576,8 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
|
|||
len = strlen(buffer);
|
||||
volume = get_volume_units(consumption[gasidx], NULL, &unit);
|
||||
get_gas_string(dive->cylinder[gasidx].gasmix.o2.permille,
|
||||
dive->cylinder[gasidx].gasmix.he.permille, gas, sizeof(gas));
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC","%.0f%s of %s\n"), volume, unit, gas);
|
||||
dive->cylinder[gasidx].gasmix.he.permille, gas, sizeof(gas));
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%.0f%s of %s\n"), volume, unit, gas);
|
||||
}
|
||||
dive->notes = strdup(buffer);
|
||||
}
|
||||
|
@ -679,7 +678,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, b
|
|||
he = dive->cylinder[gaschanges[gi].gasidx].gasmix.he.permille;
|
||||
#if DEBUG_PLAN & 16
|
||||
printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi].gasidx,
|
||||
(o2 + 5) / 10, (he + 5) / 10, gaschanges[gi].depth / 1000.0);
|
||||
(o2 + 5) / 10, (he + 5) / 10, gaschanges[gi].depth / 1000.0);
|
||||
#endif
|
||||
gi--;
|
||||
}
|
||||
|
@ -691,7 +690,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, b
|
|||
tissue_tolerance = tissue_at_end(dive, cached_datap, error_string_p);
|
||||
ceiling = deco_allowed_depth(tissue_tolerance, diveplan->surface_pressure / 1000.0, dive, 1);
|
||||
printf("waittime %d:%02d at depth %5.2lfm; ceiling %5.2lfm\n", FRACTION(wait_time, 60),
|
||||
stoplevels[stopidx] / 1000.0, ceiling / 1000.0);
|
||||
stoplevels[stopidx] / 1000.0, ceiling / 1000.0);
|
||||
#endif
|
||||
if (wait_time)
|
||||
plan_add_segment(diveplan, wait_time, stoplevels[stopidx], o2, he, po2);
|
||||
|
@ -773,14 +772,18 @@ int validate_gas(const char *text, int *o2_p, int *he_p)
|
|||
if (!*text)
|
||||
return 0;
|
||||
|
||||
if (!strcasecmp(text, translate("gettextFromC","air"))) {
|
||||
o2 = O2_IN_AIR; he = 0; text += strlen(translate("gettextFromC","air"));
|
||||
} else if (!strncasecmp(text, translate("gettextFromC","ean"), 3)) {
|
||||
o2 = get_permille(text+3, &text); he = 0;
|
||||
if (!strcasecmp(text, translate("gettextFromC", "air"))) {
|
||||
o2 = O2_IN_AIR;
|
||||
he = 0;
|
||||
text += strlen(translate("gettextFromC", "air"));
|
||||
} else if (!strncasecmp(text, translate("gettextFromC", "ean"), 3)) {
|
||||
o2 = get_permille(text + 3, &text);
|
||||
he = 0;
|
||||
} else {
|
||||
o2 = get_permille(text, &text); he = 0;
|
||||
o2 = get_permille(text, &text);
|
||||
he = 0;
|
||||
if (*text == '/')
|
||||
he = get_permille(text+1, &text);
|
||||
he = get_permille(text + 1, &text);
|
||||
}
|
||||
|
||||
/* We don't want any extra crud */
|
||||
|
@ -790,7 +793,7 @@ int validate_gas(const char *text, int *o2_p, int *he_p)
|
|||
return 0;
|
||||
|
||||
/* Validate the gas mix */
|
||||
if (*text || o2 < 1 || o2 > 1000 || he < 0 || o2+he > 1000)
|
||||
if (*text || o2 < 1 || o2 > 1000 || he < 0 || o2 + he > 1000)
|
||||
return 0;
|
||||
|
||||
/* Let it rip */
|
||||
|
@ -821,4 +824,3 @@ int validate_po2(const char *text, int *mbar_po2)
|
|||
*mbar_po2 = po2 * 100;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
9
pref.h
9
pref.h
|
@ -6,7 +6,8 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
/* can't use 'bool' for the boolean values - different size in C and C++ */
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
short po2;
|
||||
short pn2;
|
||||
short phe;
|
||||
|
@ -40,7 +41,11 @@ struct preferences {
|
|||
bool display_unused_tanks;
|
||||
bool zoomed_plot;
|
||||
};
|
||||
enum unit_system_values { METRIC, IMPERIAL, PERSONALIZE };
|
||||
enum unit_system_values {
|
||||
METRIC,
|
||||
IMPERIAL,
|
||||
PERSONALIZE
|
||||
};
|
||||
|
||||
extern struct preferences prefs, default_prefs;
|
||||
|
||||
|
|
292
profile.c
292
profile.c
|
@ -23,31 +23,31 @@ static struct plot_data *last_pi_entry = NULL, *last_pi_entry_new = NULL;
|
|||
|
||||
#ifdef DEBUG_PI
|
||||
/* debugging tool - not normally used */
|
||||
static void dump_pi (struct plot_info *pi)
|
||||
static void dump_pi(struct plot_info *pi)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("pi:{nr:%d maxtime:%d meandepth:%d maxdepth:%d \n"
|
||||
" maxpressure:%d mintemp:%d maxtemp:%d\n",
|
||||
pi->nr, pi->maxtime, pi->meandepth, pi->maxdepth,
|
||||
pi->maxpressure, pi->mintemp, pi->maxtemp);
|
||||
" maxpressure:%d mintemp:%d maxtemp:%d\n",
|
||||
pi->nr, pi->maxtime, pi->meandepth, pi->maxdepth,
|
||||
pi->maxpressure, pi->mintemp, pi->maxtemp);
|
||||
for (i = 0; i < pi->nr; i++) {
|
||||
struct plot_data *entry = &pi->entry[i];
|
||||
printf(" entry[%d]:{cylinderindex:%d sec:%d pressure:{%d,%d}\n"
|
||||
" time:%d:%02d temperature:%d depth:%d stopdepth:%d stoptime:%d ndl:%d smoothed:%d po2:%lf phe:%lf pn2:%lf sum-pp %lf}\n",
|
||||
i, entry->cylinderindex, entry->sec,
|
||||
entry->pressure[0], entry->pressure[1],
|
||||
entry->sec / 60, entry->sec % 60,
|
||||
entry->temperature, entry->depth, entry->stopdepth, entry->stoptime, entry->ndl, entry->smoothed,
|
||||
entry->po2, entry->phe, entry->pn2,
|
||||
entry->po2 + entry->phe + entry->pn2);
|
||||
" time:%d:%02d temperature:%d depth:%d stopdepth:%d stoptime:%d ndl:%d smoothed:%d po2:%lf phe:%lf pn2:%lf sum-pp %lf}\n",
|
||||
i, entry->cylinderindex, entry->sec,
|
||||
entry->pressure[0], entry->pressure[1],
|
||||
entry->sec / 60, entry->sec % 60,
|
||||
entry->temperature, entry->depth, entry->stopdepth, entry->stoptime, entry->ndl, entry->smoothed,
|
||||
entry->po2, entry->phe, entry->pn2,
|
||||
entry->po2 + entry->phe + entry->pn2);
|
||||
}
|
||||
printf(" }\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#define ROUND_UP(x,y) ((((x)+(y)-1)/(y))*(y))
|
||||
#define DIV_UP(x,y) (((x)+(y)-1)/(y))
|
||||
#define ROUND_UP(x, y) ((((x) + (y) - 1) / (y)) * (y))
|
||||
#define DIV_UP(x, y) (((x) + (y) - 1) / (y))
|
||||
|
||||
/*
|
||||
* When showing dive profiles, we scale things to the
|
||||
|
@ -68,12 +68,12 @@ int get_maxtime(struct plot_info *pi)
|
|||
* This is seamless since 600/4 = 150.
|
||||
*/
|
||||
if (seconds < 600)
|
||||
return ROUND_UP(seconds+seconds/4, 60);
|
||||
return ROUND_UP(seconds + seconds / 4, 60);
|
||||
else
|
||||
return ROUND_UP(seconds+150, 60);
|
||||
return ROUND_UP(seconds + 150, 60);
|
||||
} else {
|
||||
/* min 30 minutes, rounded up to 5 minutes, with at least 2.5 minutes to spare */
|
||||
return MAX(30*60, ROUND_UP(seconds+150, 60*5));
|
||||
return MAX(30 * 60, ROUND_UP(seconds + 150, 60 * 5));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,10 +87,10 @@ int get_maxdepth(struct plot_info *pi)
|
|||
|
||||
if (prefs.zoomed_plot) {
|
||||
/* Rounded up to 10m, with at least 3m to spare */
|
||||
md = ROUND_UP(mm+3000, 10000);
|
||||
md = ROUND_UP(mm + 3000, 10000);
|
||||
} else {
|
||||
/* Minimum 30m, rounded up to 10m, with at least 3m to spare */
|
||||
md = MAX((unsigned)30000, ROUND_UP(mm+3000, 10000));
|
||||
md = MAX((unsigned)30000, ROUND_UP(mm + 3000, 10000));
|
||||
}
|
||||
md += pi->maxpp * 9000;
|
||||
return md;
|
||||
|
@ -102,13 +102,12 @@ int evn_allocated;
|
|||
int evn_used;
|
||||
|
||||
#if WE_DONT_USE_THIS /* we need to implement event filters in Qt */
|
||||
int evn_foreach(void (*callback)(const char *, bool *, void *), void *data)
|
||||
{
|
||||
int evn_foreach(void (*callback)(const char *, bool *, void *), void *data) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < evn_used; i++) {
|
||||
/* here we display an event name on screen - so translate */
|
||||
callback(translate("gettextFromC",ev_namelist[i].ev_name), &ev_namelist[i].plot_ev, data);
|
||||
callback(translate("gettextFromC", ev_namelist[i].ev_name), &ev_namelist[i].plot_ev, data);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
@ -133,7 +132,7 @@ void remember_event(const char *eventname)
|
|||
if (evn_used == evn_allocated) {
|
||||
evn_allocated += 10;
|
||||
ev_namelist = realloc(ev_namelist, evn_allocated * sizeof(struct ev_select));
|
||||
if (! ev_namelist)
|
||||
if (!ev_namelist)
|
||||
/* we are screwed, but let's just bail out */
|
||||
return;
|
||||
}
|
||||
|
@ -152,13 +151,14 @@ int setup_temperature_limits(struct graphics_context *gc)
|
|||
mintemp = pi->mintemp;
|
||||
maxtemp = pi->maxtemp;
|
||||
|
||||
gc->leftx = 0; gc->rightx = maxtime;
|
||||
gc->leftx = 0;
|
||||
gc->rightx = maxtime;
|
||||
/* Show temperatures in roughly the lower third, but make sure the scale
|
||||
is at least somewhat reasonable */
|
||||
delta = maxtemp - mintemp;
|
||||
if (delta < 3000) /* less than 3K in fluctuation */
|
||||
delta = 3000;
|
||||
gc->topy = maxtemp + delta*2;
|
||||
gc->topy = maxtemp + delta * 2;
|
||||
|
||||
if (PP_GRAPHS_ENABLED)
|
||||
gc->bottomy = mintemp - delta * 2;
|
||||
|
@ -198,7 +198,7 @@ int get_cylinder_pressure_range(struct graphics_context *gc)
|
|||
return false;
|
||||
|
||||
while (gc->pi.endtempcoord <= SCALEY(gc, gc->pi.minpressure - (gc->topy) * 0.1))
|
||||
gc->bottomy -= gc->topy * 0.1 * gc->maxy/abs(gc->maxy);
|
||||
gc->bottomy -= gc->topy * 0.1 * gc->maxy / abs(gc->maxy);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ static void analyze_plot_info_minmax_minute(struct plot_data *entry, struct plot
|
|||
{
|
||||
struct plot_data *p = entry;
|
||||
int time = entry->sec;
|
||||
int seconds = 90*(index+1);
|
||||
int seconds = 90 * (index + 1);
|
||||
struct plot_data *min, *max;
|
||||
int avg, nr;
|
||||
|
||||
|
@ -259,7 +259,7 @@ static void analyze_plot_info_minmax_minute(struct plot_data *entry, struct plot
|
|||
if (p->sec > time + seconds)
|
||||
break;
|
||||
avg += depth;
|
||||
nr ++;
|
||||
nr++;
|
||||
if (depth < min->depth)
|
||||
min = p;
|
||||
if (depth > max->depth)
|
||||
|
@ -267,7 +267,7 @@ static void analyze_plot_info_minmax_minute(struct plot_data *entry, struct plot
|
|||
}
|
||||
entry->min[index] = min;
|
||||
entry->max[index] = max;
|
||||
entry->avg[index] = (avg + nr/2) / nr;
|
||||
entry->avg[index] = (avg + nr / 2) / nr;
|
||||
}
|
||||
|
||||
static void analyze_plot_info_minmax(struct plot_data *entry, struct plot_data *first, struct plot_data *last)
|
||||
|
@ -312,12 +312,12 @@ struct plot_info *analyze_plot_info(struct plot_info *pi)
|
|||
|
||||
/* Smoothing function: 5-point triangular smooth */
|
||||
for (i = 2; i < nr; i++) {
|
||||
struct plot_data *entry = pi->entry+i;
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
int depth;
|
||||
|
||||
if (i < nr-2) {
|
||||
depth = entry[-2].depth + 2*entry[-1].depth + 3*entry[0].depth + 2*entry[1].depth + entry[2].depth;
|
||||
entry->smoothed = (depth+4) / 9;
|
||||
if (i < nr - 2) {
|
||||
depth = entry[-2].depth + 2 * entry[-1].depth + 3 * entry[0].depth + 2 * entry[1].depth + entry[2].depth;
|
||||
entry->smoothed = (depth + 4) / 9;
|
||||
}
|
||||
/* vertical velocity in mm/sec */
|
||||
/* Linus wants to smooth this - let's at least look at the samples that aren't FAST or CRAZY */
|
||||
|
@ -327,10 +327,10 @@ struct plot_info *analyze_plot_info(struct plot_info *pi)
|
|||
/* if our samples are short and we aren't too FAST*/
|
||||
if (entry[0].sec - entry[-1].sec < 15 && entry->velocity < FAST) {
|
||||
int past = -2;
|
||||
while (i+past > 0 && entry[0].sec - entry[past].sec < 15)
|
||||
while (i + past > 0 && entry[0].sec - entry[past].sec < 15)
|
||||
past--;
|
||||
entry->velocity = velocity((entry[0].depth - entry[past].depth) /
|
||||
(entry[0].sec - entry[past].sec));
|
||||
(entry[0].sec - entry[past].sec));
|
||||
}
|
||||
} else {
|
||||
entry->velocity = STABLE;
|
||||
|
@ -340,8 +340,8 @@ struct plot_info *analyze_plot_info(struct plot_info *pi)
|
|||
|
||||
/* One-, two- and three-minute minmax data */
|
||||
for (i = 0; i < nr; i++) {
|
||||
struct plot_data *entry = pi->entry +i;
|
||||
analyze_plot_info_minmax(entry, pi->entry, pi->entry+nr);
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
analyze_plot_info_minmax(entry, pi->entry, pi->entry + nr);
|
||||
}
|
||||
|
||||
return pi;
|
||||
|
@ -361,7 +361,8 @@ struct pr_track_struct {
|
|||
pr_track_t *next;
|
||||
};
|
||||
|
||||
static pr_track_t *pr_track_alloc(int start, int t_start) {
|
||||
static pr_track_t *pr_track_alloc(int start, int t_start)
|
||||
{
|
||||
pr_track_t *pt = malloc(sizeof(pr_track_t));
|
||||
pt->start = start;
|
||||
pt->end = 0;
|
||||
|
@ -410,7 +411,7 @@ static void dump_pr_track(pr_track_t **track_pr)
|
|||
list = track_pr[cyl];
|
||||
while (list) {
|
||||
printf("cyl%d: start %d end %d t_start %d t_end %d pt %d\n", cyl,
|
||||
list->start, list->end, list->t_start, list->t_end, list->pressure_time);
|
||||
list->start, list->end, list->t_start, list->t_end, list->pressure_time);
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
|
@ -487,7 +488,7 @@ static void fill_missing_segment_pressures(pr_track_t *list)
|
|||
pt += list->pressure_time;
|
||||
pressure = start;
|
||||
if (pt_sum)
|
||||
pressure -= (start-end)*(double)pt/pt_sum;
|
||||
pressure -= (start - end) * (double)pt / pt_sum;
|
||||
list->end = pressure;
|
||||
if (list == tmp)
|
||||
break;
|
||||
|
@ -514,7 +515,7 @@ static void fill_missing_segment_pressures(pr_track_t *list)
|
|||
static inline int pressure_time(struct dive *dive, struct divecomputer *dc, struct plot_data *a, struct plot_data *b)
|
||||
{
|
||||
int time = b->sec - a->sec;
|
||||
int depth = (a->depth + b->depth)/2;
|
||||
int depth = (a->depth + b->depth) / 2;
|
||||
|
||||
if (depth <= SURFACE_THRESHOLD)
|
||||
return 0;
|
||||
|
@ -623,7 +624,7 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi,
|
|||
/* if this segment has pressure time, calculate a new interpolated pressure */
|
||||
if (interpolate.pressure_time) {
|
||||
/* Overall pressure change over total pressure-time for this segment*/
|
||||
magic = (interpolate.end - interpolate.start) / (double) interpolate.pressure_time;
|
||||
magic = (interpolate.end - interpolate.start) / (double)interpolate.pressure_time;
|
||||
|
||||
/* Use that overall pressure change to update the current pressure */
|
||||
cur_pr[cyl] = rint(interpolate.start + magic * interpolate.acc_pressure_time);
|
||||
|
@ -650,7 +651,7 @@ int get_cylinder_index(struct dive *dive, struct event *ev)
|
|||
* mix.
|
||||
*/
|
||||
for (i = 0; i < MAX_CYLINDERS; i++) {
|
||||
cylinder_t *cyl = dive->cylinder+i;
|
||||
cylinder_t *cyl = dive->cylinder + i;
|
||||
int delta_o2, delta_he, distance;
|
||||
|
||||
if (cylinder_nodata(cyl))
|
||||
|
@ -700,7 +701,7 @@ static int count_events(struct divecomputer *dc)
|
|||
static int set_cylinder_index(struct plot_info *pi, int i, int cylinderindex, unsigned int end)
|
||||
{
|
||||
while (i < pi->nr) {
|
||||
struct plot_data *entry = pi->entry+i;
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
if (entry->sec > end)
|
||||
break;
|
||||
if (entry->cylinderindex != cylinderindex) {
|
||||
|
@ -869,12 +870,12 @@ void calculate_max_limits(struct dive *dive, struct divecomputer *dc, struct gra
|
|||
/* copy the previous entry (we know this exists), update time and depth
|
||||
* and zero out the sensor pressure (since this is a synthetic entry)
|
||||
* increment the entry pointer and the count of synthetic entries. */
|
||||
#define INSERT_ENTRY(_time,_depth) \
|
||||
*entry = entry[-1]; \
|
||||
entry->sec = _time; \
|
||||
entry->depth = _depth; \
|
||||
SENSOR_PRESSURE(entry) = 0; \
|
||||
entry++; \
|
||||
#define INSERT_ENTRY(_time, _depth) \
|
||||
*entry = entry[-1]; \
|
||||
entry->sec = _time; \
|
||||
entry->depth = _depth; \
|
||||
SENSOR_PRESSURE(entry) = 0; \
|
||||
entry++; \
|
||||
idx++
|
||||
|
||||
struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
|
||||
|
@ -908,7 +909,7 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
|
|||
ev = ev->next;
|
||||
for (i = 0; i < dc->samples; i++) {
|
||||
struct plot_data *entry = plot_data + idx;
|
||||
struct sample *sample = dc->sample+i;
|
||||
struct sample *sample = dc->sample + i;
|
||||
int time = sample->time.seconds;
|
||||
int depth = sample->depth.mm;
|
||||
int offset, delta;
|
||||
|
@ -975,8 +976,8 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
|
|||
}
|
||||
|
||||
/* Add two final surface events */
|
||||
plot_data[idx++].sec = lasttime+1;
|
||||
plot_data[idx++].sec = lasttime+2;
|
||||
plot_data[idx++].sec = lasttime + 1;
|
||||
plot_data[idx++].sec = lasttime + 2;
|
||||
pi->nr = idx;
|
||||
|
||||
return plot_data;
|
||||
|
@ -990,7 +991,7 @@ static void populate_cylinder_pressure_data(int idx, int start, int end, struct
|
|||
|
||||
/* First: check that none of the entries has sensor pressure for this cylinder index */
|
||||
for (i = 0; i < pi->nr; i++) {
|
||||
struct plot_data *entry = pi->entry+i;
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
if (entry->cylinderindex != idx)
|
||||
continue;
|
||||
if (SENSOR_PRESSURE(entry))
|
||||
|
@ -999,7 +1000,7 @@ static void populate_cylinder_pressure_data(int idx, int start, int end, struct
|
|||
|
||||
/* Then: populate the first entry with the beginning cylinder pressure */
|
||||
for (i = 0; i < pi->nr; i++) {
|
||||
struct plot_data *entry = pi->entry+i;
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
if (entry->cylinderindex != idx)
|
||||
continue;
|
||||
SENSOR_PRESSURE(entry) = start;
|
||||
|
@ -1008,7 +1009,7 @@ static void populate_cylinder_pressure_data(int idx, int start, int end, struct
|
|||
|
||||
/* .. and the last entry with the ending cylinder pressure */
|
||||
for (i = pi->nr; --i >= 0; /* nothing */) {
|
||||
struct plot_data *entry = pi->entry+i;
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
if (entry->cylinderindex != idx)
|
||||
continue;
|
||||
SENSOR_PRESSURE(entry) = end;
|
||||
|
@ -1022,7 +1023,7 @@ static void calculate_sac(struct dive *dive, struct plot_info *pi)
|
|||
struct plot_data *last_entry = NULL;
|
||||
|
||||
for (i = 0; i < pi->nr; i++) {
|
||||
struct plot_data *entry = pi->entry+i;
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
if (!last_entry || last_entry->cylinderindex != entry->cylinderindex) {
|
||||
last = i;
|
||||
last_entry = entry;
|
||||
|
@ -1053,9 +1054,9 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
|
|||
|
||||
/* First, populate the pressures with the manual cylinder data.. */
|
||||
for (i = 0; i < MAX_CYLINDERS; i++) {
|
||||
cylinder_t *cyl = dive->cylinder+i;
|
||||
int start = cyl->start.mbar ? : cyl->sample_start.mbar;
|
||||
int end = cyl->end.mbar ? : cyl->sample_end.mbar;
|
||||
cylinder_t *cyl = dive->cylinder + i;
|
||||
int start = cyl->start.mbar ?: cyl->sample_start.mbar;
|
||||
int end = cyl->end.mbar ?: cyl->sample_end.mbar;
|
||||
|
||||
if (!start || !end)
|
||||
continue;
|
||||
|
@ -1079,7 +1080,7 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
|
|||
static void populate_pressure_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
|
||||
{
|
||||
int i, cylinderindex;
|
||||
pr_track_t *track_pr[MAX_CYLINDERS] = {NULL, };
|
||||
pr_track_t *track_pr[MAX_CYLINDERS] = { NULL, };
|
||||
pr_track_t *current;
|
||||
bool missing_pr = false;
|
||||
|
||||
|
@ -1091,7 +1092,7 @@ static void populate_pressure_information(struct dive *dive, struct divecomputer
|
|||
|
||||
/* discrete integration of pressure over time to get the SAC rate equivalent */
|
||||
if (current) {
|
||||
entry->pressure_time = pressure_time(dive, dc, entry-1, entry);
|
||||
entry->pressure_time = pressure_time(dive, dc, entry - 1, entry);
|
||||
current->pressure_time += entry->pressure_time;
|
||||
current->t_end = entry->sec;
|
||||
}
|
||||
|
@ -1112,7 +1113,7 @@ static void populate_pressure_information(struct dive *dive, struct divecomputer
|
|||
current->end = pressure;
|
||||
|
||||
/* Was it continuous? */
|
||||
if (SENSOR_PRESSURE(entry-1))
|
||||
if (SENSOR_PRESSURE(entry - 1))
|
||||
continue;
|
||||
|
||||
/* transmitter changed its working status */
|
||||
|
@ -1128,7 +1129,8 @@ static void populate_pressure_information(struct dive *dive, struct divecomputer
|
|||
}
|
||||
|
||||
/* calculate DECO STOP / TTS / NDL */
|
||||
static void calculate_ndl_tts(double tissue_tolerance, struct plot_data *entry, struct dive *dive, double surface_pressure) {
|
||||
static void calculate_ndl_tts(double tissue_tolerance, struct plot_data *entry, struct dive *dive, double surface_pressure)
|
||||
{
|
||||
/* FIXME: This should be configurable */
|
||||
/* ascent speed up to first deco stop */
|
||||
const int ascent_s_per_step = 1;
|
||||
|
@ -1157,7 +1159,7 @@ static void calculate_ndl_tts(double tissue_tolerance, struct plot_data *entry,
|
|||
while (entry->ndl_calc < max_ndl && deco_allowed_depth(tissue_tolerance, surface_pressure, dive, 1) <= 0) {
|
||||
entry->ndl_calc += time_stepsize;
|
||||
tissue_tolerance = add_segment(depth_to_mbar(entry->depth, dive) / 1000.0,
|
||||
&dive->cylinder[cylinderindex].gasmix, time_stepsize, entry->po2 * 1000, dive);
|
||||
&dive->cylinder[cylinderindex].gasmix, time_stepsize, entry->po2 * 1000, dive);
|
||||
}
|
||||
/* we don't need to calculate anything else */
|
||||
return;
|
||||
|
@ -1169,7 +1171,7 @@ static void calculate_ndl_tts(double tissue_tolerance, struct plot_data *entry,
|
|||
/* Add segments for movement to stopdepth */
|
||||
for (; ascent_depth > next_stop; ascent_depth -= ascent_mm_per_step, entry->tts_calc += ascent_s_per_step) {
|
||||
tissue_tolerance = add_segment(depth_to_mbar(ascent_depth, dive) / 1000.0,
|
||||
&dive->cylinder[cylinderindex].gasmix, ascent_s_per_step, entry->po2 * 1000, dive);
|
||||
&dive->cylinder[cylinderindex].gasmix, ascent_s_per_step, entry->po2 * 1000, dive);
|
||||
next_stop = ROUND_UP(deco_allowed_depth(tissue_tolerance, surface_pressure, dive, 1), deco_stepsize);
|
||||
}
|
||||
ascent_depth = next_stop;
|
||||
|
@ -1180,20 +1182,20 @@ static void calculate_ndl_tts(double tissue_tolerance, struct plot_data *entry,
|
|||
next_stop -= deco_stepsize;
|
||||
|
||||
/* And how long is the total TTS */
|
||||
while(next_stop >= 0) {
|
||||
while (next_stop >= 0) {
|
||||
/* save the time for the first stop to show in the graph */
|
||||
if (ascent_depth == entry->stopdepth_calc)
|
||||
entry->stoptime_calc += time_stepsize;
|
||||
|
||||
entry->tts_calc += time_stepsize;
|
||||
tissue_tolerance = add_segment(depth_to_mbar(ascent_depth, dive) / 1000.0,
|
||||
&dive->cylinder[cylinderindex].gasmix, time_stepsize, entry->po2 * 1000, dive);
|
||||
&dive->cylinder[cylinderindex].gasmix, time_stepsize, entry->po2 * 1000, dive);
|
||||
|
||||
if (deco_allowed_depth(tissue_tolerance, surface_pressure, dive, 1) <= next_stop) {
|
||||
/* move to the next stop and add the travel between stops */
|
||||
for (; ascent_depth > next_stop ; ascent_depth -= ascent_mm_per_deco_step, entry->tts_calc += ascent_s_per_deco_step)
|
||||
for (; ascent_depth > next_stop; ascent_depth -= ascent_mm_per_deco_step, entry->tts_calc += ascent_s_per_deco_step)
|
||||
tissue_tolerance = add_segment(depth_to_mbar(ascent_depth, dive) / 1000.0,
|
||||
&dive->cylinder[cylinderindex].gasmix, ascent_s_per_deco_step, entry->po2 * 1000, dive);
|
||||
&dive->cylinder[cylinderindex].gasmix, ascent_s_per_deco_step, entry->po2 * 1000, dive);
|
||||
ascent_depth = next_stop;
|
||||
next_stop -= deco_stepsize;
|
||||
}
|
||||
|
@ -1211,17 +1213,17 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
|
|||
for (i = 1; i < pi->nr; i++) {
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
int j, t0 = (entry - 1)->sec, t1 = entry->sec;
|
||||
for (j = t0+1; j <= t1; j++) {
|
||||
for (j = t0 + 1; j <= t1; j++) {
|
||||
int depth = interpolate(entry[-1].depth, entry[0].depth, j - t0, t1 - t0);
|
||||
double min_pressure = add_segment(depth_to_mbar(depth, dive) / 1000.0,
|
||||
&dive->cylinder[entry->cylinderindex].gasmix, 1, entry->po2 * 1000, dive);
|
||||
&dive->cylinder[entry->cylinderindex].gasmix, 1, entry->po2 * 1000, dive);
|
||||
tissue_tolerance = min_pressure;
|
||||
}
|
||||
if (t0 == t1)
|
||||
entry->ceiling = (entry - 1)->ceiling;
|
||||
else
|
||||
entry->ceiling = deco_allowed_depth(tissue_tolerance, surface_pressure, dive, !prefs.calc_ceiling_3m_incr);
|
||||
for (j=0; j<16; j++)
|
||||
for (j = 0; j < 16; j++)
|
||||
entry->ceilings[j] = deco_allowed_depth(tolerated_by_tissue[j], surface_pressure, dive, 1);
|
||||
|
||||
/* should we do more calculations?
|
||||
|
@ -1241,7 +1243,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
|
|||
#endif
|
||||
}
|
||||
|
||||
static void calculate_gas_information(struct dive *dive, struct plot_info *pi)
|
||||
static void calculate_gas_information(struct dive *dive, struct plot_info *pi)
|
||||
{
|
||||
int i;
|
||||
double amb_pressure;
|
||||
|
@ -1276,13 +1278,17 @@ static void calculate_gas_information(struct dive *dive, struct plot_info *pi)
|
|||
* END just uses N2 */
|
||||
entry->mod = (prefs.mod_ppO2 / fo2 * 1000 - 1) * 10000;
|
||||
entry->ead = (entry->depth + 10000) *
|
||||
(entry->po2 + (amb_pressure - entry->po2) * (1 - ratio)) / amb_pressure - 10000;
|
||||
(entry->po2 + (amb_pressure - entry->po2) * (1 - ratio)) / amb_pressure -
|
||||
10000;
|
||||
entry->end = (entry->depth + 10000) *
|
||||
(amb_pressure - entry->po2) * (1 - ratio) / amb_pressure / N2_IN_AIR * 1000 - 10000;
|
||||
(amb_pressure - entry->po2) * (1 - ratio) / amb_pressure / N2_IN_AIR * 1000 -
|
||||
10000;
|
||||
entry->eadd = (entry->depth + 10000) *
|
||||
(entry->po2 / amb_pressure * O2_DENSITY + entry->pn2 / amb_pressure *
|
||||
N2_DENSITY + entry->phe / amb_pressure * HE_DENSITY) /
|
||||
(O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000 -10000;
|
||||
(entry->po2 / amb_pressure * O2_DENSITY + entry->pn2 / amb_pressure *
|
||||
N2_DENSITY +
|
||||
entry->phe / amb_pressure * HE_DENSITY) /
|
||||
(O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000 -
|
||||
10000;
|
||||
if (entry->mod < 0)
|
||||
entry->mod = 0;
|
||||
if (entry->ead < 0)
|
||||
|
@ -1302,7 +1308,7 @@ static void calculate_gas_information(struct dive *dive, struct plot_info *pi)
|
|||
}
|
||||
|
||||
|
||||
static void calculate_gas_information_new(struct dive *dive, struct plot_info *pi)
|
||||
static void calculate_gas_information_new(struct dive *dive, struct plot_info *pi)
|
||||
{
|
||||
int i;
|
||||
double amb_pressure;
|
||||
|
@ -1337,13 +1343,17 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *
|
|||
* END just uses N2 */
|
||||
entry->mod = (prefs.mod_ppO2 / fo2 * 1000 - 1) * 10000;
|
||||
entry->ead = (entry->depth + 10000) *
|
||||
(entry->po2 + (amb_pressure - entry->po2) * (1 - ratio)) / amb_pressure - 10000;
|
||||
(entry->po2 + (amb_pressure - entry->po2) * (1 - ratio)) / amb_pressure -
|
||||
10000;
|
||||
entry->end = (entry->depth + 10000) *
|
||||
(amb_pressure - entry->po2) * (1 - ratio) / amb_pressure / N2_IN_AIR * 1000 - 10000;
|
||||
(amb_pressure - entry->po2) * (1 - ratio) / amb_pressure / N2_IN_AIR * 1000 -
|
||||
10000;
|
||||
entry->eadd = (entry->depth + 10000) *
|
||||
(entry->po2 / amb_pressure * O2_DENSITY + entry->pn2 / amb_pressure *
|
||||
N2_DENSITY + entry->phe / amb_pressure * HE_DENSITY) /
|
||||
(O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000 -10000;
|
||||
(entry->po2 / amb_pressure * O2_DENSITY + entry->pn2 / amb_pressure *
|
||||
N2_DENSITY +
|
||||
entry->phe / amb_pressure * HE_DENSITY) /
|
||||
(O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000 -
|
||||
10000;
|
||||
if (entry->mod < 0)
|
||||
entry->mod = 0;
|
||||
if (entry->ead < 0)
|
||||
|
@ -1408,15 +1418,15 @@ struct plot_info *create_plot_info(struct dive *dive, struct divecomputer *dc, s
|
|||
void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
|
||||
{
|
||||
init_decompression(dive);
|
||||
if (last_pi_entry_new) /* Create the new plot data */
|
||||
if (last_pi_entry_new) /* Create the new plot data */
|
||||
free((void *)last_pi_entry_new);
|
||||
last_pi_entry_new = populate_plot_entries(dive, dc, pi);
|
||||
check_gas_change_events(dive, dc, pi); /* Populate the gas index from the gas change events */
|
||||
setup_gas_sensor_pressure(dive, dc, pi); /* Try to populate our gas pressure knowledge */
|
||||
populate_pressure_information(dive, dc, pi);/* .. calculate missing pressure entries */
|
||||
calculate_sac(dive, pi); /* Calculate sac */
|
||||
check_gas_change_events(dive, dc, pi); /* Populate the gas index from the gas change events */
|
||||
setup_gas_sensor_pressure(dive, dc, pi); /* Try to populate our gas pressure knowledge */
|
||||
populate_pressure_information(dive, dc, pi); /* .. calculate missing pressure entries */
|
||||
calculate_sac(dive, pi); /* Calculate sac */
|
||||
calculate_deco_information(dive, dc, pi, false);
|
||||
calculate_gas_information_new(dive, pi); /* And finaly calculate gas partial pressures */
|
||||
calculate_gas_information_new(dive, pi); /* And finaly calculate gas partial pressures */
|
||||
pi->meandepth = dive->dc.meandepth.mm;
|
||||
analyze_plot_info(pi);
|
||||
}
|
||||
|
@ -1456,98 +1466,98 @@ static void plot_string(struct plot_data *entry, struct membuffer *b, bool has_n
|
|||
double depthvalue, tempvalue, speedvalue;
|
||||
|
||||
depthvalue = get_depth_units(entry->depth, NULL, &depth_unit);
|
||||
put_format(b, translate("gettextFromC","@: %d:%02d\nD: %.1f%s\n"), FRACTION(entry->sec, 60), depthvalue, depth_unit);
|
||||
put_format(b, translate("gettextFromC", "@: %d:%02d\nD: %.1f%s\n"), FRACTION(entry->sec, 60), depthvalue, depth_unit);
|
||||
if (GET_PRESSURE(entry)) {
|
||||
pressurevalue = get_pressure_units(GET_PRESSURE(entry), &pressure_unit);
|
||||
put_format(b, translate("gettextFromC","P: %d%s\n"), pressurevalue, pressure_unit);
|
||||
put_format(b, translate("gettextFromC", "P: %d%s\n"), pressurevalue, pressure_unit);
|
||||
}
|
||||
if (entry->temperature) {
|
||||
tempvalue = get_temp_units(entry->temperature, &temp_unit);
|
||||
put_format(b, translate("gettextFromC","T: %.1f%s\n"), tempvalue, temp_unit);
|
||||
put_format(b, translate("gettextFromC", "T: %.1f%s\n"), tempvalue, temp_unit);
|
||||
}
|
||||
speedvalue = get_vertical_speed_units(abs(entry->speed), NULL, &vertical_speed_unit);
|
||||
/* Ascending speeds are positive, descending are negative */
|
||||
if (entry->speed > 0)
|
||||
speedvalue *= -1;
|
||||
put_format(b, translate("gettextFromC","V: %.1f%s\n"), speedvalue, vertical_speed_unit);
|
||||
put_format(b, translate("gettextFromC", "V: %.1f%s\n"), speedvalue, vertical_speed_unit);
|
||||
|
||||
if (entry->sac && prefs.show_sac)
|
||||
put_format(b, translate("gettextFromC","SAC: %2.1fl/min\n"), entry->sac / 1000.0);
|
||||
put_format(b, translate("gettextFromC", "SAC: %2.1fl/min\n"), entry->sac / 1000.0);
|
||||
if (entry->cns)
|
||||
put_format(b, translate("gettextFromC","CNS: %u%%\n"), entry->cns);
|
||||
put_format(b, translate("gettextFromC", "CNS: %u%%\n"), entry->cns);
|
||||
if (prefs.pp_graphs.po2)
|
||||
put_format(b, translate("gettextFromC","pO%s: %.2fbar\n"), UTF8_SUBSCRIPT_2, entry->po2);
|
||||
put_format(b, translate("gettextFromC", "pO%s: %.2fbar\n"), UTF8_SUBSCRIPT_2, entry->po2);
|
||||
if (prefs.pp_graphs.pn2)
|
||||
put_format(b, translate("gettextFromC","pN%s: %.2fbar\n"), UTF8_SUBSCRIPT_2, entry->pn2);
|
||||
put_format(b, translate("gettextFromC", "pN%s: %.2fbar\n"), UTF8_SUBSCRIPT_2, entry->pn2);
|
||||
if (prefs.pp_graphs.phe)
|
||||
put_format(b, translate("gettextFromC","pHe: %.2fbar\n"), entry->phe);
|
||||
put_format(b, translate("gettextFromC", "pHe: %.2fbar\n"), entry->phe);
|
||||
if (prefs.mod) {
|
||||
mod = (int)get_depth_units(entry->mod, NULL, &depth_unit);
|
||||
put_format(b, translate("gettextFromC","MOD: %d%s\n"), mod, depth_unit);
|
||||
put_format(b, translate("gettextFromC", "MOD: %d%s\n"), mod, depth_unit);
|
||||
}
|
||||
if (prefs.ead) {
|
||||
ead = (int)get_depth_units(entry->ead, NULL, &depth_unit);
|
||||
end = (int)get_depth_units(entry->end, NULL, &depth_unit);
|
||||
eadd = (int)get_depth_units(entry->eadd, NULL, &depth_unit);
|
||||
put_format(b, translate("gettextFromC","EAD: %d%s\nEND: %d%s\nEADD: %d%s\n"), ead, depth_unit, end, depth_unit, eadd, depth_unit);
|
||||
put_format(b, translate("gettextFromC", "EAD: %d%s\nEND: %d%s\nEADD: %d%s\n"), ead, depth_unit, end, depth_unit, eadd, depth_unit);
|
||||
}
|
||||
if (entry->stopdepth) {
|
||||
depthvalue = get_depth_units(entry->stopdepth, NULL, &depth_unit);
|
||||
if (entry->ndl) {
|
||||
/* this is a safety stop as we still have ndl */
|
||||
if (entry->stoptime)
|
||||
put_format(b, translate("gettextFromC","Safetystop: %umin @ %.0f%s\n"), DIV_UP(entry->stoptime, 60),
|
||||
depthvalue, depth_unit);
|
||||
put_format(b, translate("gettextFromC", "Safetystop: %umin @ %.0f%s\n"), DIV_UP(entry->stoptime, 60),
|
||||
depthvalue, depth_unit);
|
||||
else
|
||||
put_format(b, translate("gettextFromC","Safetystop: unkn time @ %.0f%s\n"),
|
||||
depthvalue, depth_unit);
|
||||
put_format(b, translate("gettextFromC", "Safetystop: unkn time @ %.0f%s\n"),
|
||||
depthvalue, depth_unit);
|
||||
} else {
|
||||
/* actual deco stop */
|
||||
if (entry->stoptime)
|
||||
put_format(b, translate("gettextFromC","Deco: %umin @ %.0f%s\n"), DIV_UP(entry->stoptime, 60),
|
||||
depthvalue, depth_unit);
|
||||
put_format(b, translate("gettextFromC", "Deco: %umin @ %.0f%s\n"), DIV_UP(entry->stoptime, 60),
|
||||
depthvalue, depth_unit);
|
||||
else
|
||||
put_format(b, translate("gettextFromC","Deco: unkn time @ %.0f%s\n"),
|
||||
depthvalue, depth_unit);
|
||||
put_format(b, translate("gettextFromC", "Deco: unkn time @ %.0f%s\n"),
|
||||
depthvalue, depth_unit);
|
||||
}
|
||||
} else if (entry->in_deco) {
|
||||
put_string(b, translate("gettextFromC","In deco\n"));
|
||||
put_string(b, translate("gettextFromC", "In deco\n"));
|
||||
} else if (has_ndl) {
|
||||
put_format(b, translate("gettextFromC","NDL: %umin\n"), DIV_UP(entry->ndl, 60));
|
||||
put_format(b, translate("gettextFromC", "NDL: %umin\n"), DIV_UP(entry->ndl, 60));
|
||||
}
|
||||
if (entry->stopdepth_calc && entry->stoptime_calc) {
|
||||
depthvalue = get_depth_units(entry->stopdepth_calc, NULL, &depth_unit);
|
||||
put_format(b, translate("gettextFromC","Deco: %umin @ %.0f%s (calc)\n"), DIV_UP(entry->stoptime_calc, 60),
|
||||
depthvalue, depth_unit);
|
||||
put_format(b, translate("gettextFromC", "Deco: %umin @ %.0f%s (calc)\n"), DIV_UP(entry->stoptime_calc, 60),
|
||||
depthvalue, depth_unit);
|
||||
} else if (entry->in_deco_calc) {
|
||||
/* This means that we have no NDL left,
|
||||
* and we have no deco stop,
|
||||
* so if we just accend to the surface slowly
|
||||
* (ascent_mm_per_step / ascent_s_per_step)
|
||||
* everything will be ok. */
|
||||
put_string(b, translate("gettextFromC","In deco (calc)\n"));
|
||||
put_string(b, translate("gettextFromC", "In deco (calc)\n"));
|
||||
} else if (prefs.calc_ndl_tts && entry->ndl_calc != 0) {
|
||||
put_format(b, translate("gettextFromC","NDL: %umin (calc)\n"), DIV_UP(entry->ndl_calc, 60));
|
||||
put_format(b, translate("gettextFromC", "NDL: %umin (calc)\n"), DIV_UP(entry->ndl_calc, 60));
|
||||
}
|
||||
if (entry->tts_calc)
|
||||
put_format(b, translate("gettextFromC","TTS: %umin (calc)\n"), DIV_UP(entry->tts_calc, 60));
|
||||
put_format(b, translate("gettextFromC", "TTS: %umin (calc)\n"), DIV_UP(entry->tts_calc, 60));
|
||||
if (entry->ceiling) {
|
||||
depthvalue = get_depth_units(entry->ceiling, NULL, &depth_unit);
|
||||
put_format(b, translate("gettextFromC","Calculated ceiling %.0f%s\n"), depthvalue, depth_unit);
|
||||
put_format(b, translate("gettextFromC", "Calculated ceiling %.0f%s\n"), depthvalue, depth_unit);
|
||||
if (prefs.calc_all_tissues) {
|
||||
int k;
|
||||
for (k=0; k<16; k++) {
|
||||
for (k = 0; k < 16; k++) {
|
||||
if (entry->ceilings[k]) {
|
||||
depthvalue = get_depth_units(entry->ceilings[k], NULL, &depth_unit);
|
||||
put_format(b, translate("gettextFromC","Tissue %.0fmin: %.0f%s\n"), buehlmann_N2_t_halflife[k], depthvalue, depth_unit);
|
||||
put_format(b, translate("gettextFromC", "Tissue %.0fmin: %.0f%s\n"), buehlmann_N2_t_halflife[k], depthvalue, depth_unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entry->heartbeat)
|
||||
put_format(b, translate("gettextFromC","heartbeat: %d\n"), entry->heartbeat);
|
||||
put_format(b, translate("gettextFromC", "heartbeat: %d\n"), entry->heartbeat);
|
||||
if (entry->bearing)
|
||||
put_format(b, translate("gettextFromC","bearing: %d\n"), entry->bearing);
|
||||
put_format(b, translate("gettextFromC", "bearing: %d\n"), entry->bearing);
|
||||
strip_mb(b);
|
||||
}
|
||||
|
||||
|
@ -1615,8 +1625,8 @@ void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int
|
|||
max_asc_speed = 0;
|
||||
max_desc_speed = 0;
|
||||
|
||||
delta_depth = abs(start->depth-stop->depth);
|
||||
delta_time = abs(start->sec-stop->sec);
|
||||
delta_depth = abs(start->depth - stop->depth);
|
||||
delta_time = abs(start->sec - stop->sec);
|
||||
avg_depth = 0;
|
||||
max_depth = 0;
|
||||
min_depth = INT_MAX;
|
||||
|
@ -1627,12 +1637,12 @@ void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int
|
|||
|
||||
data = start;
|
||||
while (data != stop) {
|
||||
data = start+count;
|
||||
data = start + count;
|
||||
if (sum)
|
||||
avg_speed += abs(data->speed)*(data->sec-last_sec);
|
||||
avg_speed += abs(data->speed) * (data->sec - last_sec);
|
||||
else
|
||||
avg_speed += data->speed*(data->sec-last_sec);
|
||||
avg_depth += data->depth*(data->sec-last_sec);
|
||||
avg_speed += data->speed * (data->sec - last_sec);
|
||||
avg_depth += data->depth * (data->sec - last_sec);
|
||||
|
||||
if (data->speed > max_desc_speed)
|
||||
max_desc_speed = data->speed;
|
||||
|
@ -1644,52 +1654,52 @@ void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int
|
|||
if (data->depth > max_depth)
|
||||
max_depth = data->depth;
|
||||
/* Try to detect gas changes */
|
||||
if (GET_PRESSURE(data) < last_pressure+2000)
|
||||
bar_used += last_pressure-GET_PRESSURE(data);
|
||||
if (GET_PRESSURE(data) < last_pressure + 2000)
|
||||
bar_used += last_pressure - GET_PRESSURE(data);
|
||||
|
||||
count+=1;
|
||||
count += 1;
|
||||
last_sec = data->sec;
|
||||
last_pressure = GET_PRESSURE(data);
|
||||
}
|
||||
avg_depth /= stop->sec-start->sec;
|
||||
avg_speed /= stop->sec-start->sec;
|
||||
avg_depth /= stop->sec - start->sec;
|
||||
avg_speed /= stop->sec - start->sec;
|
||||
|
||||
snprintf(buf, bufsize, translate("gettextFromC","%sT: %d:%02d min"), UTF8_DELTA, delta_time/60, delta_time%60);
|
||||
snprintf(buf, bufsize, translate("gettextFromC", "%sT: %d:%02d min"), UTF8_DELTA, delta_time / 60, delta_time % 60);
|
||||
memcpy(buf2, buf, bufsize);
|
||||
|
||||
depthvalue = get_depth_units(delta_depth, NULL, &depth_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC","%s %sD:%.1f%s"), buf2, UTF8_DELTA, depthvalue, depth_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC", "%s %sD:%.1f%s"), buf2, UTF8_DELTA, depthvalue, depth_unit);
|
||||
memcpy(buf2, buf, bufsize);
|
||||
|
||||
depthvalue = get_depth_units(min_depth, NULL, &depth_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC","%s %sD:%.1f%s"), buf2, UTF8_DOWNWARDS_ARROW, depthvalue, depth_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC", "%s %sD:%.1f%s"), buf2, UTF8_DOWNWARDS_ARROW, depthvalue, depth_unit);
|
||||
memcpy(buf2, buf, bufsize);
|
||||
|
||||
depthvalue = get_depth_units(max_depth, NULL, &depth_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC","%s %sD:%.1f%s"), buf2, UTF8_UPWARDS_ARROW, depthvalue, depth_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC", "%s %sD:%.1f%s"), buf2, UTF8_UPWARDS_ARROW, depthvalue, depth_unit);
|
||||
memcpy(buf2, buf, bufsize);
|
||||
|
||||
depthvalue = get_depth_units(avg_depth, NULL, &depth_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC","%s %sD:%.1f%s\n"), buf2, UTF8_AVERAGE, depthvalue, depth_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC", "%s %sD:%.1f%s\n"), buf2, UTF8_AVERAGE, depthvalue, depth_unit);
|
||||
memcpy(buf2, buf, bufsize);
|
||||
|
||||
speedvalue = get_vertical_speed_units(abs(max_desc_speed), NULL, &vertical_speed_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC","%s%sV:%.2f%s"), buf2, UTF8_DOWNWARDS_ARROW, speedvalue, vertical_speed_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC", "%s%sV:%.2f%s"), buf2, UTF8_DOWNWARDS_ARROW, speedvalue, vertical_speed_unit);
|
||||
memcpy(buf2, buf, bufsize);
|
||||
|
||||
speedvalue = get_vertical_speed_units(abs(max_asc_speed), NULL, &vertical_speed_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC","%s %sV:%.2f%s"), buf2, UTF8_UPWARDS_ARROW, speedvalue, vertical_speed_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC", "%s %sV:%.2f%s"), buf2, UTF8_UPWARDS_ARROW, speedvalue, vertical_speed_unit);
|
||||
memcpy(buf2, buf, bufsize);
|
||||
|
||||
speedvalue = get_vertical_speed_units(abs(avg_speed), NULL, &vertical_speed_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC","%s %sV:%.2f%s"), buf2, UTF8_AVERAGE, speedvalue, vertical_speed_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC", "%s %sV:%.2f%s"), buf2, UTF8_AVERAGE, speedvalue, vertical_speed_unit);
|
||||
memcpy(buf2, buf, bufsize);
|
||||
|
||||
/* Only print if gas has been used */
|
||||
if (bar_used) {
|
||||
pressurevalue = get_pressure_units(bar_used, &pressure_unit);
|
||||
memcpy(buf2, buf, bufsize);
|
||||
snprintf(buf, bufsize, translate("gettextFromC","%s %sP:%d %s"), buf2, UTF8_DELTA, pressurevalue, pressure_unit);
|
||||
snprintf(buf, bufsize, translate("gettextFromC", "%s %sP:%d %s"), buf2, UTF8_DELTA, pressurevalue, pressure_unit);
|
||||
}
|
||||
|
||||
free(buf2);
|
||||
|
|
26
profile.h
26
profile.h
|
@ -5,14 +5,20 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { STABLE, SLOW, MODERATE, FAST, CRAZY } velocity_t;
|
||||
typedef enum {
|
||||
STABLE,
|
||||
SLOW,
|
||||
MODERATE,
|
||||
FAST,
|
||||
CRAZY
|
||||
} velocity_t;
|
||||
|
||||
struct membuffer;
|
||||
struct divecomputer;
|
||||
struct graphics_context;
|
||||
struct plot_info;
|
||||
struct plot_data {
|
||||
unsigned int in_deco:1;
|
||||
unsigned int in_deco : 1;
|
||||
int cylinderindex;
|
||||
int sec;
|
||||
/* pressure[0] is sensor pressure
|
||||
|
@ -37,7 +43,7 @@ struct plot_data {
|
|||
struct plot_data *max[3];
|
||||
int avg[3];
|
||||
/* values calculated by us */
|
||||
unsigned int in_deco_calc:1;
|
||||
unsigned int in_deco_calc : 1;
|
||||
int ndl_calc;
|
||||
int tts_calc;
|
||||
int stoptime_calc;
|
||||
|
@ -109,13 +115,13 @@ void setup_pp_limits(struct graphics_context *gc);
|
|||
#define MIDDLE (-0.5)
|
||||
#define BOTTOM (-1)
|
||||
|
||||
#define SCALEXGC(x) (((x) - gc.leftx) / (gc.rightx - gc.leftx) * gc.maxx)
|
||||
#define SCALEYGC(y) (((y) - gc.topy) / (gc.bottomy - gc.topy) * gc.maxy)
|
||||
#define SCALEGC(x,y) SCALEXGC(x),SCALEYGC(y)
|
||||
#define SCALEXGC(x) (((x) - gc.leftx) / (gc.rightx - gc.leftx) * gc.maxx)
|
||||
#define SCALEYGC(y) (((y) - gc.topy) / (gc.bottomy - gc.topy) * gc.maxy)
|
||||
#define SCALEGC(x, y) SCALEXGC(x), SCALEYGC(y)
|
||||
|
||||
#define SCALEX(gc,x) (((x)-gc->leftx)/(gc->rightx-gc->leftx)*gc->maxx)
|
||||
#define SCALEY(gc,y) (((y)-gc->topy)/(gc->bottomy-gc->topy)*gc->maxy)
|
||||
#define SCALE(gc,x,y) SCALEX(gc,x),SCALEY(gc,y)
|
||||
#define SCALEX(gc, x) (((x) - gc->leftx) / (gc->rightx - gc->leftx) * gc->maxx)
|
||||
#define SCALEY(gc, y) (((y) - gc->topy) / (gc->bottomy - gc->topy) * gc->maxy)
|
||||
#define SCALE(gc, x, y) SCALEX(gc, x), SCALEY(gc, y)
|
||||
|
||||
#define SENSOR_PR 0
|
||||
#define INTERPOLATED_PR 1
|
||||
|
@ -123,7 +129,7 @@ void setup_pp_limits(struct graphics_context *gc);
|
|||
#define INTERPOLATED_PRESSURE(_entry) (_entry)->pressure[INTERPOLATED_PR]
|
||||
#define GET_PRESSURE(_entry) (SENSOR_PRESSURE(_entry) ? SENSOR_PRESSURE(_entry) : INTERPOLATED_PRESSURE(_entry))
|
||||
|
||||
#define SAC_WINDOW 45 /* sliding window in seconds for current SAC calculation */
|
||||
#define SAC_WINDOW 45 /* sliding window in seconds for current SAC calculation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
100
qt-gui.cpp
100
qt-gui.cpp
|
@ -53,7 +53,7 @@ DiveComputerList dcList;
|
|||
static QApplication *application = NULL;
|
||||
static MainWindow *window = NULL;
|
||||
|
||||
int error_count;
|
||||
int error_count;
|
||||
const char *existing_filename;
|
||||
|
||||
const char *getSetting(QSettings &s, QString name)
|
||||
|
@ -94,10 +94,10 @@ void init_ui(int *argcp, char ***argvp)
|
|||
// 106 is "UTF-8", this is faster than lookup by name
|
||||
// [http://www.iana.org/assignments/character-sets/character-sets.xml]
|
||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForMib(106));
|
||||
# ifdef Q_OS_WIN
|
||||
#ifdef Q_OS_WIN
|
||||
QFile::setDecodingFunction(decodeUtf8);
|
||||
QFile::setEncodingFunction(encodeUtf8);
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
QCoreApplication::setOrganizationName("Subsurface");
|
||||
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
||||
|
@ -109,7 +109,7 @@ void init_ui(int *argcp, char ***argvp)
|
|||
s.beginGroup("Language");
|
||||
QLocale loc;
|
||||
|
||||
if (!s.value("UseSystemLanguage", true).toBool()){
|
||||
if (!s.value("UseSystemLanguage", true).toBool()) {
|
||||
loc = QLocale(s.value("UiLanguage", QLocale().uiLanguages().first()).toString());
|
||||
}
|
||||
|
||||
|
@ -128,16 +128,15 @@ void init_ui(int *argcp, char ***argvp)
|
|||
// on Linux this tends to be en-US, but on the Mac it's just en
|
||||
if (!uiLang.startsWith("en")) {
|
||||
qtTranslator = new QTranslator;
|
||||
if (qtTranslator->load(loc,"qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
|
||||
if (qtTranslator->load(loc, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
|
||||
application->installTranslator(qtTranslator);
|
||||
} else {
|
||||
qDebug() << "can't find Qt localization for locale" << uiLang <<
|
||||
"searching in" << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
||||
qDebug() << "can't find Qt localization for locale" << uiLang << "searching in" << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
||||
}
|
||||
ssrfTranslator = new QTranslator;
|
||||
if (ssrfTranslator->load(loc,"subsurface", "_") ||
|
||||
ssrfTranslator->load(loc,"subsurface", "_", getSubsurfaceDataPath("translations")) ||
|
||||
ssrfTranslator->load(loc,"subsurface", "_", getSubsurfaceDataPath("../translations"))) {
|
||||
if (ssrfTranslator->load(loc, "subsurface", "_") ||
|
||||
ssrfTranslator->load(loc, "subsurface", "_", getSubsurfaceDataPath("translations")) ||
|
||||
ssrfTranslator->load(loc, "subsurface", "_", getSubsurfaceDataPath("../translations"))) {
|
||||
application->installTranslator(ssrfTranslator);
|
||||
} else {
|
||||
qDebug() << "can't find Subsurface localization for locale" << uiLang;
|
||||
|
@ -146,7 +145,7 @@ void init_ui(int *argcp, char ***argvp)
|
|||
|
||||
s.beginGroup("DiveComputer");
|
||||
default_dive_computer_vendor = getSetting(s, "dive_computer_vendor");
|
||||
default_dive_computer_product = getSetting(s,"dive_computer_product");
|
||||
default_dive_computer_product = getSetting(s, "dive_computer_product");
|
||||
default_dive_computer_device = getSetting(s, "dive_computer_device");
|
||||
s.endGroup();
|
||||
|
||||
|
@ -230,10 +229,10 @@ QString get_depth_string(int mm, bool showunit, bool showdecimal)
|
|||
{
|
||||
if (prefs.units.length == units::METERS) {
|
||||
double meters = mm / 1000.0;
|
||||
return QString("%1%2").arg(meters, 0, 'f', (showdecimal && meters < 20.0) ? 1 : 0 ).arg(showunit ? translate("gettextFromC","m") : "");
|
||||
return QString("%1%2").arg(meters, 0, 'f', (showdecimal && meters < 20.0) ? 1 : 0).arg(showunit ? translate("gettextFromC", "m") : "");
|
||||
} else {
|
||||
double feet = mm_to_feet(mm);
|
||||
return QString("%1%2").arg(feet, 0, 'f', showdecimal ? 1 : 0). arg(showunit ? translate("gettextFromC","ft") : "");
|
||||
return QString("%1%2").arg(feet, 0, 'f', showdecimal ? 1 : 0).arg(showunit ? translate("gettextFromC", "ft") : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,18 +244,18 @@ QString get_depth_string(depth_t depth, bool showunit, bool showdecimal)
|
|||
QString get_depth_unit()
|
||||
{
|
||||
if (prefs.units.length == units::METERS)
|
||||
return QString("%1").arg(translate("gettextFromC","m"));
|
||||
return QString("%1").arg(translate("gettextFromC", "m"));
|
||||
else
|
||||
return QString("%1").arg(translate("gettextFromC","ft"));
|
||||
return QString("%1").arg(translate("gettextFromC", "ft"));
|
||||
}
|
||||
|
||||
QString get_weight_string(weight_t weight, bool showunit)
|
||||
{
|
||||
QString str = weight_string (weight.grams);
|
||||
QString str = weight_string(weight.grams);
|
||||
if (get_units()->weight == units::KG) {
|
||||
str = QString ("%1%2").arg(str).arg(showunit ? translate("gettextFromC","kg") : "");
|
||||
str = QString("%1%2").arg(str).arg(showunit ? translate("gettextFromC", "kg") : "");
|
||||
} else {
|
||||
str = QString ("%1%2").arg(str).arg(showunit ? translate("gettextFromC","lbs") : "");
|
||||
str = QString("%1%2").arg(str).arg(showunit ? translate("gettextFromC", "lbs") : "");
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
@ -264,20 +263,20 @@ QString get_weight_string(weight_t weight, bool showunit)
|
|||
QString get_weight_unit()
|
||||
{
|
||||
if (prefs.units.weight == units::KG)
|
||||
return QString("%1").arg(translate("gettextFromC","kg"));
|
||||
return QString("%1").arg(translate("gettextFromC", "kg"));
|
||||
else
|
||||
return QString("%1").arg(translate("gettextFromC","lbs"));
|
||||
return QString("%1").arg(translate("gettextFromC", "lbs"));
|
||||
}
|
||||
|
||||
/* these methods retrieve used gas per cylinder */
|
||||
static unsigned start_pressure(cylinder_t *cyl)
|
||||
{
|
||||
return cyl->start.mbar ? : cyl->sample_start.mbar;
|
||||
return cyl->start.mbar ?: cyl->sample_start.mbar;
|
||||
}
|
||||
|
||||
static unsigned end_pressure(cylinder_t *cyl)
|
||||
{
|
||||
return cyl->end.mbar ? : cyl->sample_end.mbar;
|
||||
return cyl->end.mbar ?: cyl->sample_end.mbar;
|
||||
}
|
||||
|
||||
QString get_cylinder_used_gas_string(cylinder_t *cyl, bool showunit)
|
||||
|
@ -303,15 +302,13 @@ QString get_cylinder_used_gas_string(cylinder_t *cyl, bool showunit)
|
|||
QString get_temperature_string(temperature_t temp, bool showunit)
|
||||
{
|
||||
if (temp.mkelvin == 0) {
|
||||
return ""; //temperature not defined
|
||||
return ""; //temperature not defined
|
||||
} else if (prefs.units.temperature == units::CELSIUS) {
|
||||
double celsius = mkelvin_to_C(temp.mkelvin);
|
||||
return QString("%1%2%3").arg(celsius, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE): "")
|
||||
.arg(showunit ? translate("gettextFromC","C") : "");
|
||||
return QString("%1%2%3").arg(celsius, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE) : "").arg(showunit ? translate("gettextFromC", "C") : "");
|
||||
} else {
|
||||
double fahrenheit = mkelvin_to_F(temp.mkelvin);
|
||||
return QString("%1%2%3").arg(fahrenheit, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE): "")
|
||||
.arg(showunit ? translate("gettextFromC","F") : "");
|
||||
return QString("%1%2%3").arg(fahrenheit, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE) : "").arg(showunit ? translate("gettextFromC", "F") : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -327,12 +324,12 @@ QString get_volume_string(volume_t volume, bool showunit, unsigned int mbar)
|
|||
{
|
||||
if (prefs.units.volume == units::LITER) {
|
||||
double liter = volume.mliter / 1000.0;
|
||||
return QString("%1%2").arg(liter, 0, 'f', liter >= 40.0 ? 0 : 1 ).arg(showunit ? translate("gettextFromC","l") : "");
|
||||
return QString("%1%2").arg(liter, 0, 'f', liter >= 40.0 ? 0 : 1).arg(showunit ? translate("gettextFromC", "l") : "");
|
||||
} else {
|
||||
double cuft = ml_to_cuft(volume.mliter);
|
||||
if (mbar)
|
||||
cuft *= bar_to_atm(mbar / 1000.0);
|
||||
return QString("%1%2").arg(cuft, 0, 'f', cuft >= 20.0 ? 0 : (cuft >= 2.0 ? 1 : 2)).arg(showunit ? translate("gettextFromC","cuft") : "");
|
||||
return QString("%1%2").arg(cuft, 0, 'f', cuft >= 20.0 ? 0 : (cuft >= 2.0 ? 1 : 2)).arg(showunit ? translate("gettextFromC", "cuft") : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,10 +345,10 @@ QString get_pressure_string(pressure_t pressure, bool showunit)
|
|||
{
|
||||
if (prefs.units.pressure == units::BAR) {
|
||||
double bar = pressure.mbar / 1000.0;
|
||||
return QString("%1%2").arg(bar, 0, 'f', 1).arg(showunit ? translate("gettextFromC","bar") : "");
|
||||
return QString("%1%2").arg(bar, 0, 'f', 1).arg(showunit ? translate("gettextFromC", "bar") : "");
|
||||
} else {
|
||||
double psi = mbar_to_PSI(pressure.mbar);
|
||||
return QString("%1%2").arg(psi, 0, 'f', 0).arg(showunit ? translate("gettextFromC","psi") : "");
|
||||
return QString("%1%2").arg(psi, 0, 'f', 0).arg(showunit ? translate("gettextFromC", "psi") : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,7 +361,7 @@ double get_screen_dpi()
|
|||
int is_default_dive_computer(const char *vendor, const char *product)
|
||||
{
|
||||
return default_dive_computer_vendor && !strcmp(vendor, default_dive_computer_vendor) &&
|
||||
default_dive_computer_product && !strcmp(product, default_dive_computer_product);
|
||||
default_dive_computer_product && !strcmp(product, default_dive_computer_product);
|
||||
}
|
||||
|
||||
int is_default_dive_computer_device(const char *name)
|
||||
|
@ -473,11 +470,11 @@ int gettimezoneoffset()
|
|||
return dt2.secsTo(dt1);
|
||||
}
|
||||
|
||||
int parseTemperatureToMkelvin(const QString& text)
|
||||
int parseTemperatureToMkelvin(const QString &text)
|
||||
{
|
||||
int mkelvin;
|
||||
QString numOnly = text;
|
||||
numOnly.replace(",",".").remove(QRegExp("[^-0-9.]"));
|
||||
numOnly.replace(",", ".").remove(QRegExp("[^-0-9.]"));
|
||||
if (numOnly == "")
|
||||
return 0;
|
||||
double number = numOnly.toDouble();
|
||||
|
@ -492,7 +489,6 @@ int parseTemperatureToMkelvin(const QString& text)
|
|||
mkelvin = 0;
|
||||
}
|
||||
return mkelvin;
|
||||
|
||||
}
|
||||
|
||||
QString get_dive_date_string(timestamp_t when)
|
||||
|
@ -500,12 +496,12 @@ QString get_dive_date_string(timestamp_t when)
|
|||
struct tm tm;
|
||||
utc_mkdate(when, &tm);
|
||||
return translate("gettextFromC", "%1, %2 %3, %4 %5:%6")
|
||||
.arg(weekday(tm.tm_wday))
|
||||
.arg(monthname(tm.tm_mon))
|
||||
.arg(tm.tm_mday)
|
||||
.arg(tm.tm_year + 1900)
|
||||
.arg(tm.tm_hour, 2, 10, QChar('0'))
|
||||
.arg(tm.tm_min, 2, 10, QChar('0'));
|
||||
.arg(weekday(tm.tm_wday))
|
||||
.arg(monthname(tm.tm_mon))
|
||||
.arg(tm.tm_mday)
|
||||
.arg(tm.tm_year + 1900)
|
||||
.arg(tm.tm_hour, 2, 10, QChar('0'))
|
||||
.arg(tm.tm_min, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
QString get_short_dive_date_string(timestamp_t when)
|
||||
|
@ -513,11 +509,11 @@ QString get_short_dive_date_string(timestamp_t when)
|
|||
struct tm tm;
|
||||
utc_mkdate(when, &tm);
|
||||
return translate("gettextFromC", "%1 %2, %3\n%4:%5")
|
||||
.arg(monthname(tm.tm_mon))
|
||||
.arg(tm.tm_mday)
|
||||
.arg(tm.tm_year + 1900)
|
||||
.arg(tm.tm_hour, 2, 10, QChar('0'))
|
||||
.arg(tm.tm_min, 2, 10, QChar('0'));
|
||||
.arg(monthname(tm.tm_mon))
|
||||
.arg(tm.tm_mday)
|
||||
.arg(tm.tm_year + 1900)
|
||||
.arg(tm.tm_hour, 2, 10, QChar('0'))
|
||||
.arg(tm.tm_min, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
QString get_trip_date_string(timestamp_t when, int nr)
|
||||
|
@ -526,13 +522,13 @@ QString get_trip_date_string(timestamp_t when, int nr)
|
|||
utc_mkdate(when, &tm);
|
||||
if (nr != 1)
|
||||
return translate("gettextFromC", "%1 %2 (%3 dives)")
|
||||
.arg(monthname(tm.tm_mon))
|
||||
.arg(tm.tm_year + 1900)
|
||||
.arg(nr);
|
||||
.arg(monthname(tm.tm_mon))
|
||||
.arg(tm.tm_year + 1900)
|
||||
.arg(nr);
|
||||
else
|
||||
return translate("gettextFromC", "%1 %2 (1 dive)")
|
||||
.arg(monthname(tm.tm_mon))
|
||||
.arg(tm.tm_year + 1900);
|
||||
.arg(monthname(tm.tm_mon))
|
||||
.arg(tm.tm_year + 1900);
|
||||
}
|
||||
|
||||
static xmlDocPtr get_stylesheet_doc(const xmlChar *uri, xmlDictPtr, int, void *, xsltLoadType)
|
||||
|
@ -558,7 +554,7 @@ xsltStylesheetPtr get_stylesheet(const char *name)
|
|||
if (!doc)
|
||||
return NULL;
|
||||
|
||||
// xsltSetGenericErrorFunc(stderr, NULL);
|
||||
// xsltSetGenericErrorFunc(stderr, NULL);
|
||||
xsltStylesheetPtr xslt = xsltParseStylesheetDoc(doc);
|
||||
if (!xslt) {
|
||||
xmlFreeDoc(doc);
|
||||
|
|
|
@ -9,12 +9,12 @@ SubsurfaceAbout::SubsurfaceAbout(QWidget *parent, Qt::WindowFlags f) : QDialog(p
|
|||
|
||||
setWindowModality(Qt::ApplicationModal);
|
||||
|
||||
ui.aboutLabel->setText(tr("<span style='font-size: 18pt; font-weight: bold;'>" \
|
||||
"Subsurface %1 </span><br><br>" \
|
||||
"Multi-platform divelog software<br>" \
|
||||
"<span style='font-size: 8pt'>" \
|
||||
"Linus Torvalds, Dirk Hohndel, Tomaz Canabrava, and others, 2011-2014" \
|
||||
"</span>").arg(VERSION_STRING));
|
||||
ui.aboutLabel->setText(tr("<span style='font-size: 18pt; font-weight: bold;'>"
|
||||
"Subsurface %1 </span><br><br>"
|
||||
"Multi-platform divelog software<br>"
|
||||
"<span style='font-size: 8pt'>"
|
||||
"Linus Torvalds, Dirk Hohndel, Tomaz Canabrava, and others, 2011-2014"
|
||||
"</span>").arg(VERSION_STRING));
|
||||
}
|
||||
|
||||
void SubsurfaceAbout::on_licenseButton_clicked()
|
||||
|
|
|
@ -9,10 +9,12 @@ class SubsurfaceAbout : public QDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SubsurfaceAbout(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
private slots:
|
||||
explicit SubsurfaceAbout(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
private
|
||||
slots:
|
||||
void on_licenseButton_clicked();
|
||||
void on_websiteButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::SubsurfaceAbout ui;
|
||||
};
|
||||
|
|
|
@ -2,35 +2,38 @@
|
|||
#include "dive.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
#define CREATE_UPDATE_METHOD(Class, diveStructMember) \
|
||||
void Class::updateModel() \
|
||||
{ \
|
||||
QStringList list; \
|
||||
struct dive* dive; \
|
||||
int i = 0; \
|
||||
for_each_dive(i, dive) { \
|
||||
QString buddy(dive->diveStructMember); \
|
||||
if (!list.contains(buddy)) { \
|
||||
list.append(buddy); \
|
||||
} \
|
||||
} \
|
||||
setStringList(list); \
|
||||
}
|
||||
#define CREATE_UPDATE_METHOD(Class, diveStructMember) \
|
||||
void Class::updateModel() \
|
||||
{ \
|
||||
QStringList list; \
|
||||
struct dive *dive; \
|
||||
int i = 0; \
|
||||
for_each_dive(i, dive) \
|
||||
{ \
|
||||
QString buddy(dive->diveStructMember); \
|
||||
if (!list.contains(buddy)) { \
|
||||
list.append(buddy); \
|
||||
} \
|
||||
} \
|
||||
setStringList(list); \
|
||||
}
|
||||
|
||||
#define CREATE_CSV_UPDATE_METHOD(Class, diveStructMember) \
|
||||
void Class::updateModel() \
|
||||
{ \
|
||||
QSet<QString> set; \
|
||||
struct dive* dive; \
|
||||
int i = 0; \
|
||||
for_each_dive(i, dive) { \
|
||||
QString buddy(dive->diveStructMember); \
|
||||
foreach (const QString &value, buddy.split(",", QString::SkipEmptyParts)) { \
|
||||
set.insert(value.trimmed()); \
|
||||
} \
|
||||
} \
|
||||
setStringList(set.toList()); \
|
||||
}
|
||||
#define CREATE_CSV_UPDATE_METHOD(Class, diveStructMember) \
|
||||
void Class::updateModel() \
|
||||
{ \
|
||||
QSet<QString> set; \
|
||||
struct dive *dive; \
|
||||
int i = 0; \
|
||||
for_each_dive(i, dive) \
|
||||
{ \
|
||||
QString buddy(dive->diveStructMember); \
|
||||
foreach(const QString &value, buddy.split(",", QString::SkipEmptyParts)) \
|
||||
{ \
|
||||
set.insert(value.trimmed()); \
|
||||
} \
|
||||
} \
|
||||
setStringList(set.toList()); \
|
||||
}
|
||||
|
||||
CREATE_CSV_UPDATE_METHOD(BuddyCompletionModel, buddy);
|
||||
CREATE_CSV_UPDATE_METHOD(DiveMasterCompletionModel, divemaster);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "../qthelper.h"
|
||||
#include "../helpers.h"
|
||||
|
||||
DiveComputerManagementDialog::DiveComputerManagementDialog(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f),
|
||||
DiveComputerManagementDialog::DiveComputerManagementDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f),
|
||||
model(0)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
@ -20,7 +20,7 @@ void DiveComputerManagementDialog::init()
|
|||
ui.tableView->setModel(model);
|
||||
}
|
||||
|
||||
DiveComputerManagementDialog* DiveComputerManagementDialog::instance()
|
||||
DiveComputerManagementDialog *DiveComputerManagementDialog::instance()
|
||||
{
|
||||
static DiveComputerManagementDialog *self = new DiveComputerManagementDialog(MainWindow::instance());
|
||||
self->setAttribute(Qt::WA_QuitOnClose, false);
|
||||
|
@ -35,17 +35,16 @@ void DiveComputerManagementDialog::update()
|
|||
layout()->activate();
|
||||
}
|
||||
|
||||
void DiveComputerManagementDialog::tryRemove(const QModelIndex& index)
|
||||
void DiveComputerManagementDialog::tryRemove(const QModelIndex &index)
|
||||
{
|
||||
if (index.column() != DiveComputerModel::REMOVE)
|
||||
return;
|
||||
|
||||
QMessageBox::StandardButton response = QMessageBox::question(
|
||||
this, TITLE_OR_TEXT(
|
||||
tr("Remove the selected Dive Computer?"),
|
||||
tr("Are you sure that you want to \n remove the selected dive computer?")),
|
||||
QMessageBox::Ok | QMessageBox::Cancel
|
||||
);
|
||||
this, TITLE_OR_TEXT(
|
||||
tr("Remove the selected Dive Computer?"),
|
||||
tr("Are you sure that you want to \n remove the selected dive computer?")),
|
||||
QMessageBox::Ok | QMessageBox::Cancel);
|
||||
|
||||
if (response == QMessageBox::Ok)
|
||||
model->remove(index);
|
||||
|
|
|
@ -6,21 +6,22 @@
|
|||
class QModelIndex;
|
||||
class DiveComputerModel;
|
||||
|
||||
class DiveComputerManagementDialog : public QDialog{
|
||||
Q_OBJECT
|
||||
class DiveComputerManagementDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static DiveComputerManagementDialog *instance();
|
||||
void update();
|
||||
void init();
|
||||
|
||||
public slots:
|
||||
void tryRemove(const QModelIndex& index);
|
||||
public
|
||||
slots:
|
||||
void tryRemove(const QModelIndex &index);
|
||||
void accept();
|
||||
void reject();
|
||||
|
||||
private:
|
||||
explicit DiveComputerManagementDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
explicit DiveComputerManagementDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
Ui::DiveComputerManagementDialog ui;
|
||||
DiveComputerModel *model;
|
||||
};
|
||||
|
|
|
@ -27,8 +27,7 @@
|
|||
#include <iostream>
|
||||
|
||||
|
||||
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false),
|
||||
sortColumn(0), currentOrder(Qt::DescendingOrder), searchBox(this)
|
||||
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false), sortColumn(0), currentOrder(Qt::DescendingOrder), searchBox(this)
|
||||
{
|
||||
setItemDelegate(new DiveListDelegate(this));
|
||||
setUniformRowHeights(true);
|
||||
|
@ -47,7 +46,7 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
|
|||
header()->setMinimumHeight(metrics.height() + 10);
|
||||
header()->setStretchLastSection(true);
|
||||
QAction *showSearchBox = new QAction(tr("Show Search Box"), this);
|
||||
showSearchBox->setShortcut( Qt::CTRL + Qt::Key_F);
|
||||
showSearchBox->setShortcut(Qt::CTRL + Qt::Key_F);
|
||||
showSearchBox->setShortcutContext(Qt::WindowShortcut);
|
||||
addAction(showSearchBox);
|
||||
|
||||
|
@ -112,23 +111,23 @@ int DiveListView::lastVisibleColumn()
|
|||
void DiveListView::backupExpandedRows()
|
||||
{
|
||||
expandedRows.clear();
|
||||
for(int i = 0; i < model()->rowCount(); i++)
|
||||
if (isExpanded( model()->index(i, 0) ))
|
||||
for (int i = 0; i < model()->rowCount(); i++)
|
||||
if (isExpanded(model()->index(i, 0)))
|
||||
expandedRows.push_back(i);
|
||||
}
|
||||
|
||||
void DiveListView::restoreExpandedRows()
|
||||
{
|
||||
setAnimated(false);
|
||||
Q_FOREACH(const int &i, expandedRows)
|
||||
setExpanded( model()->index(i, 0), true );
|
||||
Q_FOREACH(const int & i, expandedRows)
|
||||
setExpanded(model()->index(i, 0), true);
|
||||
setAnimated(true);
|
||||
}
|
||||
void DiveListView::fixMessyQtModelBehaviour()
|
||||
{
|
||||
QAbstractItemModel *m = model();
|
||||
for(int i = 0; i < model()->rowCount(); i++)
|
||||
if (m->rowCount( m->index(i, 0) ) != 0)
|
||||
for (int i = 0; i < model()->rowCount(); i++)
|
||||
if (m->rowCount(m->index(i, 0)) != 0)
|
||||
setFirstColumnSpanned(i, QModelIndex(), true);
|
||||
}
|
||||
|
||||
|
@ -137,10 +136,10 @@ void DiveListView::rememberSelection()
|
|||
{
|
||||
selectedDives.clear();
|
||||
QItemSelection selection = selectionModel()->selection();
|
||||
Q_FOREACH(const QModelIndex& index , selection.indexes()) {
|
||||
Q_FOREACH(const QModelIndex & index, selection.indexes()) {
|
||||
if (index.column() != 0) // We only care about the dives, so, let's stick to rows and discard columns.
|
||||
continue;
|
||||
struct dive *d = (struct dive *) index.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
struct dive *d = (struct dive *)index.data(DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
if (d)
|
||||
selectedDives.insert(d->divetrip, get_divenr(d));
|
||||
}
|
||||
|
@ -149,7 +148,7 @@ void DiveListView::rememberSelection()
|
|||
void DiveListView::restoreSelection()
|
||||
{
|
||||
unselectDives();
|
||||
Q_FOREACH(dive_trip_t *trip, selectedDives.keys()) {
|
||||
Q_FOREACH(dive_trip_t * trip, selectedDives.keys()) {
|
||||
QList<int> divesOnTrip = getDivesInTrip(trip);
|
||||
QList<int> selectedDivesOnTrip = selectedDives.values(trip);
|
||||
|
||||
|
@ -167,18 +166,18 @@ void DiveListView::restoreSelection()
|
|||
}
|
||||
}
|
||||
|
||||
void DiveListView::selectTrip ( dive_trip_t* trip )
|
||||
void DiveListView::selectTrip(dive_trip_t *trip)
|
||||
{
|
||||
if (!trip)
|
||||
return;
|
||||
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
|
||||
QModelIndexList match = m->match(m->index(0,0), DiveTripModel::TRIP_ROLE, QVariant::fromValue<void*>(trip), 2, Qt::MatchRecursive);
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model());
|
||||
QModelIndexList match = m->match(m->index(0, 0), DiveTripModel::TRIP_ROLE, QVariant::fromValue<void *>(trip), 2, Qt::MatchRecursive);
|
||||
QItemSelectionModel::SelectionFlags flags;
|
||||
if (!match.count())
|
||||
return;
|
||||
QModelIndex idx = match.first();
|
||||
flags = QItemSelectionModel::Select;
|
||||
flags = QItemSelectionModel::Select;
|
||||
flags |= QItemSelectionModel::Rows;
|
||||
selectionModel()->select(idx, flags);
|
||||
expand(idx);
|
||||
|
@ -189,12 +188,12 @@ void DiveListView::unselectDives()
|
|||
selectionModel()->clearSelection();
|
||||
}
|
||||
|
||||
QList< dive_trip_t* > DiveListView::selectedTrips()
|
||||
QList<dive_trip_t *> DiveListView::selectedTrips()
|
||||
{
|
||||
QModelIndexList indexes = selectionModel()->selectedRows();
|
||||
QList<dive_trip_t*> ret;
|
||||
Q_FOREACH(const QModelIndex& index, indexes) {
|
||||
dive_trip_t *trip = static_cast<dive_trip_t*>(index.data(DiveTripModel::TRIP_ROLE).value<void*>());
|
||||
QList<dive_trip_t *> ret;
|
||||
Q_FOREACH(const QModelIndex & index, indexes) {
|
||||
dive_trip_t *trip = static_cast<dive_trip_t *>(index.data(DiveTripModel::TRIP_ROLE).value<void *>());
|
||||
if (!trip)
|
||||
continue;
|
||||
ret.push_back(trip);
|
||||
|
@ -204,10 +203,10 @@ QList< dive_trip_t* > DiveListView::selectedTrips()
|
|||
|
||||
void DiveListView::selectDive(int i, bool scrollto, bool toggle)
|
||||
{
|
||||
if ( i == -1)
|
||||
if (i == -1)
|
||||
return;
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
|
||||
QModelIndexList match = m->match(m->index(0,0), DiveTripModel::DIVE_IDX, i, 2, Qt::MatchRecursive);
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model());
|
||||
QModelIndexList match = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, i, 2, Qt::MatchRecursive);
|
||||
QItemSelectionModel::SelectionFlags flags;
|
||||
QModelIndex idx = match.first();
|
||||
flags = toggle ? QItemSelectionModel::Toggle : QItemSelectionModel::Select;
|
||||
|
@ -222,19 +221,19 @@ void DiveListView::selectDive(int i, bool scrollto, bool toggle)
|
|||
scrollTo(idx, PositionAtCenter);
|
||||
}
|
||||
|
||||
void DiveListView::selectDives(const QList< int >& newDiveSelection)
|
||||
void DiveListView::selectDives(const QList<int> &newDiveSelection)
|
||||
{
|
||||
if (!newDiveSelection.count())
|
||||
return;
|
||||
|
||||
disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
||||
this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
|
||||
disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
||||
this, SLOT(currentChanged(QModelIndex,QModelIndex)));
|
||||
disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
||||
this, SLOT(selectionChanged(QItemSelection, QItemSelection)));
|
||||
disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)),
|
||||
this, SLOT(currentChanged(QModelIndex, QModelIndex)));
|
||||
|
||||
setAnimated(false);
|
||||
collapseAll();
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model());
|
||||
QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::Select | QItemSelectionModel::Rows;
|
||||
|
||||
QItemSelection newDeselected = selectionModel()->selection();
|
||||
|
@ -246,17 +245,17 @@ void DiveListView::selectDives(const QList< int >& newDiveSelection)
|
|||
struct dive *dive;
|
||||
for_each_dive(i, dive) {
|
||||
dive->selected = newDiveSelection.contains(i) == true;
|
||||
if (firstSelectedDive == -1 && dive->selected ) {
|
||||
if (firstSelectedDive == -1 && dive->selected) {
|
||||
firstSelectedDive = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
select_dive(firstSelectedDive);
|
||||
Q_FOREACH(int i, newDiveSelection) {
|
||||
diveList.append(m->match(m->index(0,0), DiveTripModel::DIVE_IDX,
|
||||
i, 2, Qt::MatchRecursive).first());
|
||||
diveList.append(m->match(m->index(0, 0), DiveTripModel::DIVE_IDX,
|
||||
i, 2, Qt::MatchRecursive).first());
|
||||
}
|
||||
Q_FOREACH(const QModelIndex& idx, diveList) {
|
||||
Q_FOREACH(const QModelIndex & idx, diveList) {
|
||||
selectionModel()->select(idx, flags);
|
||||
if (idx.parent().isValid() && !isExpanded(idx.parent())) {
|
||||
expand(idx.parent());
|
||||
|
@ -264,12 +263,12 @@ void DiveListView::selectDives(const QList< int >& newDiveSelection)
|
|||
}
|
||||
setAnimated(true);
|
||||
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
|
||||
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
||||
this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
|
||||
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
||||
this, SLOT(currentChanged(QModelIndex,QModelIndex)));
|
||||
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
||||
this, SLOT(selectionChanged(QItemSelection, QItemSelection)));
|
||||
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)),
|
||||
this, SLOT(currentChanged(QModelIndex, QModelIndex)));
|
||||
Q_EMIT currentDiveChanged(selected_dive);
|
||||
const QModelIndex& idx = m->match(m->index(0,0), DiveTripModel::DIVE_IDX,selected_dive, 2, Qt::MatchRecursive).first();
|
||||
const QModelIndex &idx = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, selected_dive, 2, Qt::MatchRecursive).first();
|
||||
scrollTo(idx);
|
||||
}
|
||||
|
||||
|
@ -279,17 +278,17 @@ void DiveListView::showSearchEdit()
|
|||
searchBox.setFocus();
|
||||
}
|
||||
|
||||
bool DiveListView::eventFilter(QObject* , QEvent* event)
|
||||
bool DiveListView::eventFilter(QObject *, QEvent *event)
|
||||
{
|
||||
if (event->type() != QEvent::KeyPress)
|
||||
return false;
|
||||
QKeyEvent *keyEv = static_cast<QKeyEvent*>(event);
|
||||
QKeyEvent *keyEv = static_cast<QKeyEvent *>(event);
|
||||
if (keyEv->key() != Qt::Key_Escape)
|
||||
return false;
|
||||
|
||||
searchBox.clear();
|
||||
searchBox.hide();
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model());
|
||||
m->setFilterFixedString(QString());
|
||||
return true;
|
||||
}
|
||||
|
@ -300,7 +299,7 @@ bool DiveListView::eventFilter(QObject* , QEvent* event)
|
|||
// index. TRIP_ROLE vs DIVE_ROLE?
|
||||
void DiveListView::headerClicked(int i)
|
||||
{
|
||||
DiveTripModel::Layout newLayout = i == (int) DiveTripModel::NR ? DiveTripModel::TREE : DiveTripModel::LIST;
|
||||
DiveTripModel::Layout newLayout = i == (int)DiveTripModel::NR ? DiveTripModel::TREE : DiveTripModel::LIST;
|
||||
rememberSelection();
|
||||
unselectDives();
|
||||
/* No layout change? Just re-sort, and scroll to first selection, making sure all selections are expanded */
|
||||
|
@ -328,14 +327,14 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
|||
layout = currentLayout;
|
||||
else
|
||||
currentLayout = layout;
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
header()->setClickable(true);
|
||||
#else
|
||||
header()->setSectionsClickable(true);
|
||||
#endif
|
||||
connect(header(), SIGNAL(sectionPressed(int)), this, SLOT(headerClicked(int)), Qt::UniqueConnection);
|
||||
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model());
|
||||
QAbstractItemModel *oldModel = m->sourceModel();
|
||||
if (oldModel) {
|
||||
oldModel->deleteLater();
|
||||
|
@ -352,10 +351,10 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
|||
if (amount_selected && current_dive != NULL) {
|
||||
selectDive(selected_dive, true);
|
||||
} else {
|
||||
QModelIndex firstDiveOrTrip = m->index(0,0);
|
||||
QModelIndex firstDiveOrTrip = m->index(0, 0);
|
||||
if (firstDiveOrTrip.isValid()) {
|
||||
if (m->index(0,0, firstDiveOrTrip).isValid())
|
||||
setCurrentIndex(m->index(0,0, firstDiveOrTrip));
|
||||
if (m->index(0, 0, firstDiveOrTrip).isValid())
|
||||
setCurrentIndex(m->index(0, 0, firstDiveOrTrip));
|
||||
else
|
||||
setCurrentIndex(firstDiveOrTrip);
|
||||
}
|
||||
|
@ -382,19 +381,12 @@ void DiveListView::reloadHeaderActions()
|
|||
if (!header()->actions().size()) {
|
||||
QSettings s;
|
||||
s.beginGroup("DiveListColumnState");
|
||||
for(int i = 0; i < model()->columnCount(); i++) {
|
||||
for (int i = 0; i < model()->columnCount(); i++) {
|
||||
QString title = QString("%1").arg(model()->headerData(i, Qt::Horizontal).toString());
|
||||
QString settingName = QString("showColumn%1").arg(i);
|
||||
QAction *a = new QAction(title, header());
|
||||
bool showHeaderFirstRun = !(
|
||||
i == DiveTripModel::MAXCNS
|
||||
|| i == DiveTripModel::NITROX
|
||||
|| i == DiveTripModel::OTU
|
||||
|| i == DiveTripModel::TEMPERATURE
|
||||
|| i == DiveTripModel::TOTALWEIGHT
|
||||
|| i == DiveTripModel::SUIT
|
||||
|| i == DiveTripModel::CYLINDER
|
||||
|| i == DiveTripModel::SAC );
|
||||
i == DiveTripModel::MAXCNS || i == DiveTripModel::NITROX || i == DiveTripModel::OTU || i == DiveTripModel::TEMPERATURE || i == DiveTripModel::TOTALWEIGHT || i == DiveTripModel::SUIT || i == DiveTripModel::CYLINDER || i == DiveTripModel::SAC);
|
||||
bool shown = s.value(settingName, showHeaderFirstRun).toBool();
|
||||
a->setCheckable(true);
|
||||
a->setChecked(shown);
|
||||
|
@ -406,7 +398,7 @@ void DiveListView::reloadHeaderActions()
|
|||
}
|
||||
s.endGroup();
|
||||
} else {
|
||||
for(int i = 0; i < model()->columnCount(); i++) {
|
||||
for (int i = 0; i < model()->columnCount(); i++) {
|
||||
QString title = QString("%1").arg(model()->headerData(i, Qt::Horizontal).toString());
|
||||
header()->actions()[i]->setText(title);
|
||||
}
|
||||
|
@ -415,7 +407,7 @@ void DiveListView::reloadHeaderActions()
|
|||
|
||||
void DiveListView::toggleColumnVisibilityByIndex()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction*>(sender());
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
if (!action)
|
||||
return;
|
||||
|
||||
|
@ -428,29 +420,29 @@ void DiveListView::toggleColumnVisibilityByIndex()
|
|||
setColumnWidth(lastVisibleColumn(), 10);
|
||||
}
|
||||
|
||||
void DiveListView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
|
||||
void DiveListView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
if (!current.isValid())
|
||||
return;
|
||||
scrollTo(current);
|
||||
}
|
||||
|
||||
void DiveListView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
|
||||
void DiveListView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||
{
|
||||
QItemSelection newSelected = selected.size() ? selected : selectionModel()->selection();
|
||||
QItemSelection newDeselected = deselected;
|
||||
|
||||
disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
|
||||
disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
|
||||
disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection)));
|
||||
disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex)));
|
||||
|
||||
Q_FOREACH(const QModelIndex& index, newDeselected.indexes()) {
|
||||
Q_FOREACH(const QModelIndex & index, newDeselected.indexes()) {
|
||||
if (index.column() != 0)
|
||||
continue;
|
||||
const QAbstractItemModel *model = index.model();
|
||||
struct dive *dive = (struct dive*) model->data(index, DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
if (!dive) { // it's a trip!
|
||||
if (model->rowCount(index)) {
|
||||
struct dive *child = (struct dive*) model->data(index.child(0,0), DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
struct dive *child = (struct dive *)model->data(index.child(0, 0), DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
while (child) {
|
||||
deselect_dive(get_divenr(child));
|
||||
child = child->next;
|
||||
|
@ -460,21 +452,21 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
|
|||
deselect_dive(get_divenr(dive));
|
||||
}
|
||||
}
|
||||
Q_FOREACH(const QModelIndex& index, newSelected.indexes()) {
|
||||
Q_FOREACH(const QModelIndex & index, newSelected.indexes()) {
|
||||
if (index.column() != 0)
|
||||
continue;
|
||||
|
||||
const QAbstractItemModel *model = index.model();
|
||||
struct dive *dive = (struct dive*) model->data(index, DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
if (!dive) { // it's a trip!
|
||||
if (model->rowCount(index)) {
|
||||
QItemSelection selection;
|
||||
struct dive *child = (struct dive*) model->data(index.child(0,0), DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
struct dive *child = (struct dive *)model->data(index.child(0, 0), DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
while (child) {
|
||||
select_dive(get_divenr(child));
|
||||
child = child->next;
|
||||
}
|
||||
selection.select(index.child(0,0), index.child(model->rowCount(index) -1 , 0));
|
||||
selection.select(index.child(0, 0), index.child(model->rowCount(index) - 1, 0));
|
||||
selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::NoUpdate);
|
||||
if (!isExpanded(index))
|
||||
|
@ -485,8 +477,8 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
|
|||
}
|
||||
}
|
||||
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
|
||||
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
|
||||
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
|
||||
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection)));
|
||||
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex)));
|
||||
// now that everything is up to date, update the widgets
|
||||
Q_EMIT currentDiveChanged(selected_dive);
|
||||
}
|
||||
|
@ -498,7 +490,7 @@ static bool can_merge(const struct dive *a, const struct dive *b)
|
|||
if (a->when > b->when)
|
||||
return false;
|
||||
/* Don't merge dives if there's more than half an hour between them */
|
||||
if (a->when + a->duration.seconds + 30*60 < b->when)
|
||||
if (a->when + a->duration.seconds + 30 * 60 < b->when)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -524,10 +516,10 @@ void DiveListView::mergeDives()
|
|||
void DiveListView::merge_trip(const QModelIndex &a, int offset)
|
||||
{
|
||||
int i = a.row() + offset;
|
||||
QModelIndex b = a.sibling(i,0);
|
||||
QModelIndex b = a.sibling(i, 0);
|
||||
|
||||
dive_trip_t *trip_a = (dive_trip_t *) a.data(DiveTripModel::TRIP_ROLE).value<void*>();
|
||||
dive_trip_t *trip_b = (dive_trip_t *) b.data(DiveTripModel::TRIP_ROLE).value<void*>();
|
||||
dive_trip_t *trip_a = (dive_trip_t *)a.data(DiveTripModel::TRIP_ROLE).value<void *>();
|
||||
dive_trip_t *trip_b = (dive_trip_t *)b.data(DiveTripModel::TRIP_ROLE).value<void *>();
|
||||
|
||||
if (trip_a == trip_b || !trip_a || !trip_b)
|
||||
return;
|
||||
|
@ -574,7 +566,7 @@ void DiveListView::newTripAbove()
|
|||
{
|
||||
dive_trip_t *trip;
|
||||
int idx;
|
||||
struct dive *d = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
if (!d) // shouldn't happen as we only are setting up this action if this is a dive
|
||||
return;
|
||||
rememberSelection();
|
||||
|
@ -595,7 +587,7 @@ void DiveListView::addToTripAbove()
|
|||
int idx, delta = (currentOrder == Qt::AscendingOrder) ? -1 : +1;
|
||||
dive_trip_t *trip = NULL;
|
||||
struct dive *pd = NULL;
|
||||
struct dive *d = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
if (!d) // shouldn't happen as we only are setting up this action if this is a dive
|
||||
return;
|
||||
rememberSelection();
|
||||
|
@ -638,10 +630,10 @@ void DiveListView::addToTripAbove()
|
|||
void DiveListView::markDiveInvalid()
|
||||
{
|
||||
int i;
|
||||
struct dive *d = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
if (!d)
|
||||
return;
|
||||
for_each_dive (i, d) {
|
||||
for_each_dive(i, d) {
|
||||
if (!d->selected)
|
||||
continue;
|
||||
// now mark the dive invalid... how do we do THAT?
|
||||
|
@ -663,7 +655,7 @@ void DiveListView::markDiveInvalid()
|
|||
void DiveListView::deleteDive()
|
||||
{
|
||||
int i;
|
||||
struct dive *d = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
if (!d)
|
||||
return;
|
||||
// after a dive is deleted the ones following it move forward in the dive_table
|
||||
|
@ -693,12 +685,12 @@ void DiveListView::deleteDive()
|
|||
|
||||
void DiveListView::testSlot()
|
||||
{
|
||||
struct dive *d = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
if (d) {
|
||||
qDebug("testSlot called on dive #%d", d->number);
|
||||
} else {
|
||||
QModelIndex child = contextMenuIndex.child(0, 0);
|
||||
d = (struct dive *) child.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
d = (struct dive *)child.data(DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
if (d)
|
||||
qDebug("testSlot called on trip including dive #%d", d->number);
|
||||
else
|
||||
|
@ -711,8 +703,8 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
|
|||
QAction *collapseAction = NULL;
|
||||
// let's remember where we are
|
||||
contextMenuIndex = indexAt(event->pos());
|
||||
struct dive *d = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
||||
dive_trip_t *trip = (dive_trip_t *) contextMenuIndex.data(DiveTripModel::TRIP_ROLE).value<void*>();
|
||||
struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>();
|
||||
dive_trip_t *trip = (dive_trip_t *)contextMenuIndex.data(DiveTripModel::TRIP_ROLE).value<void *>();
|
||||
QMenu popup(this);
|
||||
if (currentLayout == DiveTripModel::TREE) {
|
||||
popup.addAction(tr("expand all"), this, SLOT(expandAll()));
|
||||
|
@ -746,7 +738,7 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
|
|||
popup.addAction(tr("upload dive(s) to divelogs.de"), this, SLOT(uploadToDivelogsDE()));
|
||||
// "collapse all" really closes all trips,
|
||||
// "collapse" keeps the trip with the selected dive open
|
||||
QAction * actionTaken = popup.exec(event->globalPos());
|
||||
QAction *actionTaken = popup.exec(event->globalPos());
|
||||
if (actionTaken == collapseAction && collapseAction) {
|
||||
this->setAnimated(false);
|
||||
selectDive(selected_dive, true);
|
||||
|
@ -776,7 +768,7 @@ void DiveListView::saveSelectedDivesAs()
|
|||
// Keep last open dir
|
||||
QFileInfo fileInfo(fileName);
|
||||
settings.beginGroup("FileDialog");
|
||||
settings.setValue("LastDir",fileInfo.dir().path());
|
||||
settings.setValue("LastDir", fileInfo.dir().path());
|
||||
settings.endGroup();
|
||||
|
||||
QByteArray bt = QFile::encodeName(fileName);
|
||||
|
@ -821,7 +813,7 @@ void DiveListView::loadImages()
|
|||
for (int i = 0; i < fileNames.size(); ++i) {
|
||||
if (readfile(fileNames.at(i).toUtf8().data(), &mem) <= 0)
|
||||
continue;
|
||||
retval = exif.parseFrom((const unsigned char *) mem.buffer, (unsigned) mem.size);
|
||||
retval = exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
|
||||
free(mem.buffer);
|
||||
if (retval != PARSE_EXIF_SUCCESS)
|
||||
continue;
|
||||
|
@ -831,21 +823,21 @@ void DiveListView::loadImages()
|
|||
imagetime += shiftDialog.amount();
|
||||
int j = 0;
|
||||
struct dive *dive;
|
||||
for_each_dive(j, dive){
|
||||
for_each_dive(j, dive) {
|
||||
if (!dive->selected)
|
||||
continue;
|
||||
// FIXME: this adds the events only to the first DC
|
||||
if (dive->when - 3600 < imagetime && dive->when + dive->duration.seconds + 3600 > imagetime){
|
||||
if (dive->when - 3600 < imagetime && dive->when + dive->duration.seconds + 3600 > imagetime) {
|
||||
if (dive->when > imagetime) {
|
||||
// Before dive
|
||||
add_event(&(dive->dc), 0, 123, 0, 0, fileNames.at(i).toUtf8().data());
|
||||
} else if (dive->when + dive->duration.seconds < imagetime){
|
||||
} else if (dive->when + dive->duration.seconds < imagetime) {
|
||||
// After dive
|
||||
add_event(&(dive->dc), dive->duration.seconds, 123, 0, 0, fileNames.at(i).toUtf8().data());
|
||||
} else {
|
||||
add_event(&(dive->dc), imagetime - dive->when, 123, 0, 0, fileNames.at(i).toUtf8().data());
|
||||
}
|
||||
if (!dive->latitude.udeg && !IS_FP_SAME(exif.GeoLocation.Latitude, 0.0)){
|
||||
if (!dive->latitude.udeg && !IS_FP_SAME(exif.GeoLocation.Latitude, 0.0)) {
|
||||
dive->latitude.udeg = lrint(1000000.0 * exif.GeoLocation.Latitude);
|
||||
dive->longitude.udeg = lrint(1000000.0 * exif.GeoLocation.Longitude);
|
||||
}
|
||||
|
@ -873,7 +865,7 @@ QString DiveListView::lastUsedImageDir()
|
|||
return lastImageDir;
|
||||
}
|
||||
|
||||
void DiveListView::updateLastUsedImageDir(const QString& dir)
|
||||
void DiveListView::updateLastUsedImageDir(const QString &dir)
|
||||
{
|
||||
QSettings s;
|
||||
s.beginGroup("FileDialog");
|
||||
|
|
|
@ -15,24 +15,24 @@
|
|||
#include <QLineEdit>
|
||||
#include "models.h"
|
||||
|
||||
class DiveListView : public QTreeView
|
||||
{
|
||||
class DiveListView : public QTreeView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiveListView(QWidget *parent = 0);
|
||||
~DiveListView();
|
||||
void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
|
||||
void currentChanged(const QModelIndex& current, const QModelIndex& previous);
|
||||
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void reload(DiveTripModel::Layout layout, bool forceSort = true);
|
||||
bool eventFilter(QObject* , QEvent* );
|
||||
bool eventFilter(QObject *, QEvent *);
|
||||
void unselectDives();
|
||||
void selectDive(int dive_table_idx, bool scrollto = false, bool toggle = false);
|
||||
void selectDives(const QList<int>& newDiveSelection);
|
||||
void selectDives(const QList<int> &newDiveSelection);
|
||||
void rememberSelection();
|
||||
void restoreSelection();
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
QList<dive_trip_t*> selectedTrips();
|
||||
public slots:
|
||||
QList<dive_trip_t *> selectedTrips();
|
||||
public
|
||||
slots:
|
||||
void toggleColumnVisibilityByIndex();
|
||||
void reloadHeaderActions();
|
||||
void headerClicked(int);
|
||||
|
@ -73,8 +73,8 @@ private:
|
|||
void backupExpandedRows();
|
||||
void restoreExpandedRows();
|
||||
int lastVisibleColumn();
|
||||
void selectTrip ( dive_trip_t* trip );
|
||||
void updateLastUsedImageDir(const QString& s);
|
||||
void selectTrip(dive_trip_t *trip);
|
||||
void updateLastUsedImageDir(const QString &s);
|
||||
void updateLastImageTimeOffset(int offset);
|
||||
int lastImageTimeOffset();
|
||||
};
|
||||
|
|
|
@ -5,15 +5,14 @@
|
|||
#include "ui_divelogimportdialog.h"
|
||||
|
||||
const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = {
|
||||
{"", },
|
||||
{"APD Log Viewer", 1, 2, 16, 7, 18, 19, "Tab"},
|
||||
{"XP5", 1, 2, 10, -1, -1, -1, "Tab"},
|
||||
{"SensusCSV", 10, 11, -1, -1, -1, -1, ","},
|
||||
{NULL,}
|
||||
{ "", },
|
||||
{ "APD Log Viewer", 1, 2, 16, 7, 18, 19, "Tab" },
|
||||
{ "XP5", 1, 2, 10, -1, -1, -1, "Tab" },
|
||||
{ "SensusCSV", 10, 11, -1, -1, -1, -1, "," },
|
||||
{ NULL, }
|
||||
};
|
||||
|
||||
DiveLogImportDialog::DiveLogImportDialog(QStringList *fn, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
DiveLogImportDialog::DiveLogImportDialog(QStringList *fn, QWidget *parent) : QDialog(parent),
|
||||
selector(true),
|
||||
ui(new Ui::DiveLogImportDialog)
|
||||
{
|
||||
|
@ -52,7 +51,7 @@ DiveLogImportDialog::~DiveLogImportDialog()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
#define VALUE_IF_CHECKED(x) (ui->x->isEnabled() ? ui->x->value() - 1: -1)
|
||||
#define VALUE_IF_CHECKED(x) (ui->x->isEnabled() ? ui->x->value() - 1 : -1)
|
||||
void DiveLogImportDialog::on_buttonBox_accepted()
|
||||
{
|
||||
char *error = NULL;
|
||||
|
@ -60,14 +59,14 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
|||
if (ui->tabWidget->currentIndex() == 0) {
|
||||
for (int i = 0; i < fileNames.size(); ++i) {
|
||||
parse_csv_file(fileNames[i].toUtf8().data(), ui->CSVTime->value() - 1,
|
||||
ui->CSVDepth->value() - 1, VALUE_IF_CHECKED(CSVTemperature),
|
||||
VALUE_IF_CHECKED(CSVpo2),
|
||||
VALUE_IF_CHECKED(CSVcns),
|
||||
VALUE_IF_CHECKED(CSVstopdepth),
|
||||
ui->CSVSeparator->currentIndex(),
|
||||
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
|
||||
ui->CSVUnits->currentIndex(),
|
||||
&error);
|
||||
ui->CSVDepth->value() - 1, VALUE_IF_CHECKED(CSVTemperature),
|
||||
VALUE_IF_CHECKED(CSVpo2),
|
||||
VALUE_IF_CHECKED(CSVcns),
|
||||
VALUE_IF_CHECKED(CSVstopdepth),
|
||||
ui->CSVSeparator->currentIndex(),
|
||||
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
|
||||
ui->CSVUnits->currentIndex(),
|
||||
&error);
|
||||
if (error != NULL) {
|
||||
MainWindow::instance()->showError(error);
|
||||
free(error);
|
||||
|
@ -77,16 +76,16 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
|||
} else {
|
||||
for (int i = 0; i < fileNames.size(); ++i) {
|
||||
parse_manual_file(fileNames[i].toUtf8().data(),
|
||||
ui->ManualSeparator->currentIndex(),
|
||||
ui->Units->currentIndex(),
|
||||
VALUE_IF_CHECKED(DiveNumber),
|
||||
VALUE_IF_CHECKED(Date), VALUE_IF_CHECKED(Time),
|
||||
VALUE_IF_CHECKED(Duration), VALUE_IF_CHECKED(Location),
|
||||
VALUE_IF_CHECKED(Gps), VALUE_IF_CHECKED(MaxDepth),
|
||||
VALUE_IF_CHECKED(MeanDepth), VALUE_IF_CHECKED(Buddy),
|
||||
VALUE_IF_CHECKED(Notes), VALUE_IF_CHECKED(Weight),
|
||||
VALUE_IF_CHECKED(Tags),
|
||||
&error);
|
||||
ui->ManualSeparator->currentIndex(),
|
||||
ui->Units->currentIndex(),
|
||||
VALUE_IF_CHECKED(DiveNumber),
|
||||
VALUE_IF_CHECKED(Date), VALUE_IF_CHECKED(Time),
|
||||
VALUE_IF_CHECKED(Duration), VALUE_IF_CHECKED(Location),
|
||||
VALUE_IF_CHECKED(Gps), VALUE_IF_CHECKED(MaxDepth),
|
||||
VALUE_IF_CHECKED(MeanDepth), VALUE_IF_CHECKED(Buddy),
|
||||
VALUE_IF_CHECKED(Notes), VALUE_IF_CHECKED(Weight),
|
||||
VALUE_IF_CHECKED(Tags),
|
||||
&error);
|
||||
if (error != NULL) {
|
||||
MainWindow::instance()->showError(error);
|
||||
free(error);
|
||||
|
@ -104,8 +103,8 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
|||
ui->CSV->setValue(VAL);\
|
||||
ui->CSV->setEnabled(VAL >= 0);\
|
||||
ui->BOX->setChecked(VAL >= 0);\
|
||||
ui->CSV->blockSignals(false);\
|
||||
})
|
||||
ui->CSV->blockSignals(false); \
|
||||
})
|
||||
void DiveLogImportDialog::on_knownImports_currentIndexChanged(int index)
|
||||
{
|
||||
if (specialCSV.contains(index)) {
|
||||
|
|
|
@ -6,19 +6,20 @@
|
|||
#include "../dive.h"
|
||||
#include "../divelist.h"
|
||||
|
||||
namespace Ui {
|
||||
class DiveLogImportDialog;
|
||||
namespace Ui
|
||||
{
|
||||
class DiveLogImportDialog;
|
||||
}
|
||||
|
||||
class DiveLogImportDialog : public QDialog
|
||||
{
|
||||
class DiveLogImportDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DiveLogImportDialog(QStringList *fn, QWidget *parent = 0);
|
||||
~DiveLogImportDialog();
|
||||
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
void on_buttonBox_accepted();
|
||||
void on_knownImports_currentIndexChanged(int index);
|
||||
void unknownImports();
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -12,19 +12,30 @@
|
|||
class QListView;
|
||||
class QModelIndex;
|
||||
|
||||
class DivePlannerPointsModel : public QAbstractTableModel{
|
||||
class DivePlannerPointsModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static DivePlannerPointsModel* instance();
|
||||
enum Sections{REMOVE, DEPTH, DURATION, GAS, CCSETPOINT, COLUMNS};
|
||||
enum Mode { NOTHING, PLAN, ADD };
|
||||
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;
|
||||
static DivePlannerPointsModel *instance();
|
||||
enum Sections {
|
||||
REMOVE,
|
||||
DEPTH,
|
||||
DURATION,
|
||||
GAS,
|
||||
CCSETPOINT,
|
||||
COLUMNS
|
||||
};
|
||||
enum Mode {
|
||||
NOTHING,
|
||||
PLAN,
|
||||
ADD
|
||||
};
|
||||
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;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
void removeSelectedPoints(const QVector<int>& rows);
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
void removeSelectedPoints(const QVector<int> &rows);
|
||||
void setPlanMode(Mode mode);
|
||||
bool isPlanner();
|
||||
void createSimpleDive();
|
||||
|
@ -37,35 +48,37 @@ public:
|
|||
/**
|
||||
* @return the row number.
|
||||
*/
|
||||
void editStop(int row, divedatapoint newData );
|
||||
void editStop(int row, divedatapoint newData);
|
||||
divedatapoint at(int row);
|
||||
int size();
|
||||
struct diveplan getDiveplan();
|
||||
QStringList &getGasList();
|
||||
QVector<QPair<int, int> > collectGases(dive *d);
|
||||
|
||||
public slots:
|
||||
int addStop(int millimeters = 0, int seconds = 0, int o2 = 0, int he = 0, int ccpoint = 0 );
|
||||
public
|
||||
slots:
|
||||
int addStop(int millimeters = 0, int seconds = 0, int o2 = 0, int he = 0, int ccpoint = 0);
|
||||
void addCylinder_clicked();
|
||||
void setGFHigh(const int gfhigh);
|
||||
void setGFLow(const int ghflow);
|
||||
void setSurfacePressure(int pressure);
|
||||
void setBottomSac(int sac);
|
||||
void setDecoSac(int sac);
|
||||
void setStartTime(const QTime& t);
|
||||
void setStartTime(const QTime &t);
|
||||
void setLastStop6m(bool value);
|
||||
void createPlan();
|
||||
void remove(const QModelIndex& index);
|
||||
void remove(const QModelIndex &index);
|
||||
void cancelPlan();
|
||||
void createTemporaryPlan();
|
||||
void deleteTemporaryPlan();
|
||||
void loadFromDive(dive* d);
|
||||
void loadFromDive(dive *d);
|
||||
void restoreBackupDive();
|
||||
signals:
|
||||
void planCreated();
|
||||
void planCanceled();
|
||||
|
||||
private:
|
||||
explicit DivePlannerPointsModel(QObject* parent = 0);
|
||||
explicit DivePlannerPointsModel(QObject *parent = 0);
|
||||
bool addGas(int o2, int he);
|
||||
struct diveplan diveplan;
|
||||
Mode mode;
|
||||
|
@ -81,13 +94,15 @@ private:
|
|||
class Button : public QObject, public QGraphicsRectItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Button(QObject* parent = 0, QGraphicsItem *itemParent = 0);
|
||||
void setText(const QString& text);
|
||||
void setPixmap(const QPixmap& pixmap);
|
||||
Button(QObject *parent = 0, QGraphicsItem *itemParent = 0);
|
||||
void setText(const QString &text);
|
||||
void setPixmap(const QPixmap &pixmap);
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
private:
|
||||
QGraphicsPixmapItem *icon;
|
||||
QGraphicsSimpleTextItem *text;
|
||||
|
@ -101,27 +116,31 @@ public:
|
|||
QGraphicsPixmapItem *icon;
|
||||
Button *increaseBtn;
|
||||
Button *decreaseBtn;
|
||||
|
||||
private:
|
||||
QGraphicsPixmapItem *bg;
|
||||
QGraphicsPixmapItem *leftWing;
|
||||
QGraphicsPixmapItem *rightWing;
|
||||
};
|
||||
|
||||
class DiveHandler : public QObject, public QGraphicsEllipseItem{
|
||||
Q_OBJECT
|
||||
class DiveHandler : public QObject, public QGraphicsEllipseItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiveHandler();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
||||
|
||||
private:
|
||||
int parentIndex();
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void selfRemove();
|
||||
void changeGas();
|
||||
};
|
||||
|
||||
class Ruler : public QGraphicsLineItem{
|
||||
class Ruler : public QGraphicsLineItem {
|
||||
public:
|
||||
Ruler();
|
||||
~Ruler();
|
||||
|
@ -133,19 +152,19 @@ public:
|
|||
void updateTicks();
|
||||
double minimum() const;
|
||||
double maximum() const;
|
||||
qreal valueAt(const QPointF& p);
|
||||
qreal percentAt(const QPointF& p);
|
||||
qreal valueAt(const QPointF &p);
|
||||
qreal percentAt(const QPointF &p);
|
||||
qreal posAtValue(qreal value);
|
||||
void setColor(const QColor& color);
|
||||
void setTextColor(const QColor& color);
|
||||
void setColor(const QColor &color);
|
||||
void setTextColor(const QColor &color);
|
||||
int unitSystem;
|
||||
|
||||
private:
|
||||
void eraseAll();
|
||||
|
||||
Qt::Orientation orientation;
|
||||
QList<QGraphicsLineItem*> ticks;
|
||||
QList<QGraphicsSimpleTextItem*> labels;
|
||||
QList<QGraphicsLineItem *> ticks;
|
||||
QList<QGraphicsSimpleTextItem *> labels;
|
||||
double min;
|
||||
double max;
|
||||
double interval;
|
||||
|
@ -156,19 +175,22 @@ private:
|
|||
class DivePlannerGraphics : public QGraphicsView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DivePlannerGraphics(QWidget* parent = 0);
|
||||
DivePlannerGraphics(QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent* event);
|
||||
virtual void showEvent(QShowEvent* event);
|
||||
virtual void resizeEvent(QResizeEvent* event);
|
||||
virtual void mouseMoveEvent(QMouseEvent* event);
|
||||
virtual void mousePressEvent(QMouseEvent* event);
|
||||
virtual void mouseReleaseEvent(QMouseEvent* event);
|
||||
bool isPointOutOfBoundaries(const QPointF& point);
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event);
|
||||
virtual void showEvent(QShowEvent *event);
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
virtual void mouseMoveEvent(QMouseEvent *event);
|
||||
virtual void mousePressEvent(QMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event);
|
||||
bool isPointOutOfBoundaries(const QPointF &point);
|
||||
qreal fromPercent(qreal percent, Qt::Orientation orientation);
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void settingsChanged();
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
void keyEscAction();
|
||||
void keyDeleteAction();
|
||||
void keyUpAction();
|
||||
|
@ -180,17 +202,18 @@ private slots:
|
|||
void decreaseTime();
|
||||
void decreaseDepth();
|
||||
void drawProfile();
|
||||
void pointInserted(const QModelIndex&, int start, int end);
|
||||
void pointsRemoved(const QModelIndex&, int start, int end);
|
||||
void pointInserted(const QModelIndex &, int start, int end);
|
||||
void pointsRemoved(const QModelIndex &, int start, int end);
|
||||
|
||||
private:
|
||||
void moveActiveHandler(const QPointF& MappedPos, const int pos);
|
||||
void moveActiveHandler(const QPointF &MappedPos, const int pos);
|
||||
|
||||
/* This are the lines of the plotted dive. */
|
||||
QList<QGraphicsLineItem*> lines;
|
||||
QList<QGraphicsLineItem *> lines;
|
||||
|
||||
/* This is the user-entered handles. */
|
||||
QList<DiveHandler *> handles;
|
||||
QList<QGraphicsSimpleTextItem*> gases;
|
||||
QList<QGraphicsSimpleTextItem *> gases;
|
||||
|
||||
/* those are the lines that follows the mouse. */
|
||||
QGraphicsLineItem *verticalLine;
|
||||
|
@ -219,8 +242,8 @@ private:
|
|||
ExpanderGraphics *timeHandler;
|
||||
|
||||
int minMinutes; // this holds the minimum requested window time
|
||||
int minDepth; // this holds the minimum requested window depth
|
||||
int dpMaxTime; // this is the time of the dive calculated by the deco.
|
||||
int minDepth; // this holds the minimum requested window depth
|
||||
int dpMaxTime; // this is the time of the dive calculated by the deco.
|
||||
|
||||
friend class DiveHandler;
|
||||
};
|
||||
|
@ -230,13 +253,15 @@ private:
|
|||
class DivePlannerWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DivePlannerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
explicit DivePlannerWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void settingsChanged();
|
||||
void atmPressureChanged(const QString& pressure);
|
||||
void bottomSacChanged(const QString& bottomSac);
|
||||
void decoSacChanged(const QString& decosac);
|
||||
void atmPressureChanged(const QString &pressure);
|
||||
void bottomSacChanged(const QString &bottomSac);
|
||||
void decoSacChanged(const QString &decosac);
|
||||
|
||||
private:
|
||||
Ui::DivePlanner ui;
|
||||
};
|
||||
|
|
|
@ -32,11 +32,12 @@ struct mydescriptor {
|
|||
unsigned int model;
|
||||
};
|
||||
|
||||
namespace DownloadFromDcGlobal {
|
||||
namespace DownloadFromDcGlobal
|
||||
{
|
||||
const char *err_string;
|
||||
};
|
||||
|
||||
DownloadFromDCWidget::DownloadFromDCWidget(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f),
|
||||
DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f),
|
||||
thread(0),
|
||||
downloading(false),
|
||||
previousLast(0),
|
||||
|
@ -87,7 +88,7 @@ void DownloadFromDCWidget::updateProgressBar()
|
|||
ui.progressBar->setFormat(progress_bar_text);
|
||||
} else {
|
||||
ui.progressBar->setFormat("%p%");
|
||||
ui.progressBar->setValue(progress_bar_fraction *100);
|
||||
ui.progressBar->setValue(progress_bar_fraction * 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,8 +112,7 @@ void DownloadFromDCWidget::updateState(states state)
|
|||
|
||||
// user pressed cancel but the application isn't doing anything.
|
||||
// means close the window
|
||||
else if ((currentState == INITIAL || currentState == CANCELLED || currentState == DONE || currentState == ERROR)
|
||||
&& state == CANCELLING) {
|
||||
else if ((currentState == INITIAL || currentState == CANCELLED || currentState == DONE || currentState == ERROR) && state == CANCELLING) {
|
||||
timer->stop();
|
||||
reject();
|
||||
ui.ok->setText(tr("OK"));
|
||||
|
@ -168,7 +168,7 @@ void DownloadFromDCWidget::updateState(states state)
|
|||
currentState = state;
|
||||
}
|
||||
|
||||
void DownloadFromDCWidget::on_vendor_currentIndexChanged(const QString& vendor)
|
||||
void DownloadFromDCWidget::on_vendor_currentIndexChanged(const QString &vendor)
|
||||
{
|
||||
QAbstractItemModel *currentModel = ui.product->model();
|
||||
if (!currentModel)
|
||||
|
@ -205,7 +205,7 @@ void DownloadFromDCWidget::fill_computer_list()
|
|||
|
||||
QStringList computer;
|
||||
dc_descriptor_iterator(&iterator);
|
||||
while (dc_iterator_next (iterator, &descriptor) == DC_STATUS_SUCCESS) {
|
||||
while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) {
|
||||
const char *vendor = dc_descriptor_get_vendor(descriptor);
|
||||
const char *product = dc_descriptor_get_product(descriptor);
|
||||
|
||||
|
@ -225,7 +225,7 @@ void DownloadFromDCWidget::fill_computer_list()
|
|||
this WILL BREAK if libdivecomputer changes the dc_descriptor struct...
|
||||
eventually the UEMIS code needs to move into libdivecomputer, I guess */
|
||||
|
||||
mydescriptor = (struct mydescriptor*) malloc(sizeof(struct mydescriptor));
|
||||
mydescriptor = (struct mydescriptor *)malloc(sizeof(struct mydescriptor));
|
||||
mydescriptor->vendor = "Uemis";
|
||||
mydescriptor->product = "Zurich";
|
||||
mydescriptor->type = DC_FAMILY_NULL;
|
||||
|
@ -246,9 +246,9 @@ void DownloadFromDCWidget::on_search_clicked()
|
|||
{
|
||||
if (ui.vendor->currentText() == "Uemis") {
|
||||
QString dirName = QFileDialog::getExistingDirectory(this,
|
||||
tr("Find Uemis dive computer"),
|
||||
QDir::homePath(),
|
||||
QFileDialog::ShowDirsOnly);
|
||||
tr("Find Uemis dive computer"),
|
||||
QDir::homePath(),
|
||||
QFileDialog::ShowDirsOnly);
|
||||
qDebug() << dirName;
|
||||
if (ui.device->findText(dirName) == -1)
|
||||
ui.device->addItem(dirName);
|
||||
|
@ -284,7 +284,7 @@ void DownloadFromDCWidget::on_ok_clicked()
|
|||
thread = new DownloadThread(this, &data);
|
||||
|
||||
connect(thread, SIGNAL(finished()),
|
||||
this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection);
|
||||
this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection);
|
||||
|
||||
MainWindow *w = MainWindow::instance();
|
||||
connect(thread, SIGNAL(finished()), w, SLOT(refreshDisplay()));
|
||||
|
@ -311,7 +311,7 @@ void DownloadFromDCWidget::checkLogFile(int state)
|
|||
|
||||
void DownloadFromDCWidget::pickLogFile()
|
||||
{
|
||||
QString filename = existing_filename ? : prefs.default_filename;
|
||||
QString filename = existing_filename ?: prefs.default_filename;
|
||||
QFileInfo fi(filename);
|
||||
filename = fi.absolutePath().append(QDir::separator()).append("subsurface.log");
|
||||
logFile = QFileDialog::getSaveFileName(this, tr("Choose file for divecomputer download logfile"),
|
||||
|
@ -340,7 +340,7 @@ void DownloadFromDCWidget::checkDumpFile(int state)
|
|||
|
||||
void DownloadFromDCWidget::pickDumpFile()
|
||||
{
|
||||
QString filename = existing_filename ? : prefs.default_filename;
|
||||
QString filename = existing_filename ?: prefs.default_filename;
|
||||
QFileInfo fi(filename);
|
||||
filename = fi.absolutePath().append(QDir::separator()).append("subsurface.bin");
|
||||
dumpFile = QFileDialog::getSaveFileName(this, tr("Choose file for divecomputer binary dump file"),
|
||||
|
@ -429,7 +429,7 @@ void DownloadFromDCWidget::fill_device_list()
|
|||
ui.device->setCurrentIndex(deviceIndex);
|
||||
}
|
||||
|
||||
DownloadThread::DownloadThread(QObject* parent, device_data_t* data): QThread(parent),
|
||||
DownloadThread::DownloadThread(QObject *parent, device_data_t *data) : QThread(parent),
|
||||
data(data)
|
||||
{
|
||||
}
|
||||
|
@ -438,7 +438,7 @@ static QString str_error(const char *fmt, ...)
|
|||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
const QString str = QString().vsprintf( fmt, args );
|
||||
const QString str = QString().vsprintf(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return str;
|
||||
|
@ -453,5 +453,5 @@ void DownloadThread::run()
|
|||
else
|
||||
errorText = do_libdivecomputer_import(data);
|
||||
if (errorText)
|
||||
error = str_error(errorText, data->devname, data->vendor, data->product);
|
||||
error = str_error(errorText, data->devname, data->vendor, data->product);
|
||||
}
|
||||
|
|
|
@ -9,21 +9,22 @@
|
|||
#include "../libdivecomputer.h"
|
||||
#include "ui_downloadfromdivecomputer.h"
|
||||
|
||||
class DownloadThread : public QThread{
|
||||
class DownloadThread : public QThread {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DownloadThread(QObject* parent, device_data_t* data);
|
||||
DownloadThread(QObject *parent, device_data_t *data);
|
||||
virtual void run();
|
||||
|
||||
QString error;
|
||||
|
||||
private:
|
||||
device_data_t *data;
|
||||
};
|
||||
|
||||
class DownloadFromDCWidget : public QDialog{
|
||||
class DownloadFromDCWidget : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DownloadFromDCWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
explicit DownloadFromDCWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
void reject();
|
||||
|
||||
enum states {
|
||||
|
@ -35,11 +36,12 @@ public:
|
|||
DONE,
|
||||
};
|
||||
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void on_ok_clicked();
|
||||
void on_cancel_clicked();
|
||||
void on_search_clicked();
|
||||
void on_vendor_currentIndexChanged(const QString& vendor);
|
||||
void on_vendor_currentIndexChanged(const QString &vendor);
|
||||
void on_product_currentIndexChanged();
|
||||
|
||||
void onDownloadThreadFinished();
|
||||
|
@ -76,7 +78,6 @@ public:
|
|||
bool preferDownloaded();
|
||||
void updateState(states state);
|
||||
states currentState;
|
||||
|
||||
};
|
||||
|
||||
#endif // DOWNLOADFROMDIVECOMPUTER_H
|
||||
|
|
922
qt-ui/exif.cpp
922
qt-ui/exif.cpp
|
@ -34,158 +34,166 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
namespace {
|
||||
// IF Entry
|
||||
struct IFEntry {
|
||||
// Raw fields
|
||||
unsigned short tag;
|
||||
unsigned short format;
|
||||
unsigned data;
|
||||
unsigned length;
|
||||
namespace
|
||||
{
|
||||
// IF Entry
|
||||
struct IFEntry {
|
||||
// Raw fields
|
||||
unsigned short tag;
|
||||
unsigned short format;
|
||||
unsigned data;
|
||||
unsigned length;
|
||||
|
||||
// Parsed fields
|
||||
string val_string;
|
||||
unsigned short val_16;
|
||||
unsigned val_32;
|
||||
double val_rational;
|
||||
unsigned char val_byte;
|
||||
};
|
||||
// Parsed fields
|
||||
string val_string;
|
||||
unsigned short val_16;
|
||||
unsigned val_32;
|
||||
double val_rational;
|
||||
unsigned char val_byte;
|
||||
};
|
||||
|
||||
// Helper functions
|
||||
unsigned int parse32(const unsigned char *buf, bool intel) {
|
||||
if (intel)
|
||||
return ((unsigned)buf[3]<<24) |
|
||||
((unsigned)buf[2]<<16) |
|
||||
((unsigned)buf[1]<<8) |
|
||||
buf[0];
|
||||
// Helper functions
|
||||
unsigned int parse32(const unsigned char *buf, bool intel)
|
||||
{
|
||||
if (intel)
|
||||
return ((unsigned)buf[3] << 24) |
|
||||
((unsigned)buf[2] << 16) |
|
||||
((unsigned)buf[1] << 8) |
|
||||
buf[0];
|
||||
|
||||
return ((unsigned)buf[0]<<24) |
|
||||
((unsigned)buf[1]<<16) |
|
||||
((unsigned)buf[2]<<8) |
|
||||
buf[3];
|
||||
}
|
||||
return ((unsigned)buf[0] << 24) |
|
||||
((unsigned)buf[1] << 16) |
|
||||
((unsigned)buf[2] << 8) |
|
||||
buf[3];
|
||||
}
|
||||
|
||||
unsigned short parse16(const unsigned char *buf, bool intel) {
|
||||
if (intel)
|
||||
return ((unsigned) buf[1]<<8) | buf[0];
|
||||
return ((unsigned) buf[0]<<8) | buf[1];
|
||||
}
|
||||
unsigned short parse16(const unsigned char *buf, bool intel)
|
||||
{
|
||||
if (intel)
|
||||
return ((unsigned)buf[1] << 8) | buf[0];
|
||||
return ((unsigned)buf[0] << 8) | buf[1];
|
||||
}
|
||||
|
||||
string parseEXIFString(const unsigned char *buf,
|
||||
const unsigned num_components,
|
||||
const unsigned data,
|
||||
const unsigned base,
|
||||
const unsigned len) {
|
||||
string value;
|
||||
if (num_components <= 4)
|
||||
value.assign( (const char*)&data, num_components );
|
||||
else {
|
||||
if (base+data+num_components <= len)
|
||||
value.assign( (const char*)(buf+base+data), num_components );
|
||||
}
|
||||
return value;
|
||||
}
|
||||
string parseEXIFString(const unsigned char *buf,
|
||||
const unsigned num_components,
|
||||
const unsigned data,
|
||||
const unsigned base,
|
||||
const unsigned len)
|
||||
{
|
||||
string value;
|
||||
if (num_components <= 4)
|
||||
value.assign((const char *)&data, num_components);
|
||||
else {
|
||||
if (base + data + num_components <= len)
|
||||
value.assign((const char *)(buf + base + data), num_components);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
double parseEXIFRational(const unsigned char *buf, bool intel) {
|
||||
double numerator = 0;
|
||||
double denominator = 1;
|
||||
double parseEXIFRational(const unsigned char *buf, bool intel)
|
||||
{
|
||||
double numerator = 0;
|
||||
double denominator = 1;
|
||||
|
||||
numerator = (double) parse32(buf, intel);
|
||||
denominator= (double) parse32(buf+4, intel);
|
||||
if(denominator < 1e-20)
|
||||
return 0;
|
||||
return numerator/denominator;
|
||||
}
|
||||
numerator = (double)parse32(buf, intel);
|
||||
denominator = (double)parse32(buf + 4, intel);
|
||||
if (denominator < 1e-20)
|
||||
return 0;
|
||||
return numerator / denominator;
|
||||
}
|
||||
|
||||
IFEntry parseIFEntry(const unsigned char *buf,
|
||||
const unsigned offs,
|
||||
const bool alignIntel,
|
||||
const unsigned base,
|
||||
const unsigned len) {
|
||||
IFEntry result;
|
||||
IFEntry parseIFEntry(const unsigned char *buf,
|
||||
const unsigned offs,
|
||||
const bool alignIntel,
|
||||
const unsigned base,
|
||||
const unsigned len)
|
||||
{
|
||||
IFEntry result;
|
||||
|
||||
// Each directory entry is composed of:
|
||||
// 2 bytes: tag number (data field)
|
||||
// 2 bytes: data format
|
||||
// 4 bytes: number of components
|
||||
// 4 bytes: data value or offset to data value
|
||||
result.tag = parse16(buf + offs, alignIntel);
|
||||
result.format = parse16(buf + offs + 2, alignIntel);
|
||||
result.length = parse32(buf + offs + 4, alignIntel);
|
||||
result.data = parse32(buf + offs + 8, alignIntel);
|
||||
// Each directory entry is composed of:
|
||||
// 2 bytes: tag number (data field)
|
||||
// 2 bytes: data format
|
||||
// 4 bytes: number of components
|
||||
// 4 bytes: data value or offset to data value
|
||||
result.tag = parse16(buf + offs, alignIntel);
|
||||
result.format = parse16(buf + offs + 2, alignIntel);
|
||||
result.length = parse32(buf + offs + 4, alignIntel);
|
||||
result.data = parse32(buf + offs + 8, alignIntel);
|
||||
|
||||
// Parse value in specified format
|
||||
switch (result.format) {
|
||||
case 1:
|
||||
result.val_byte = (unsigned char) *(buf + offs + 8);
|
||||
break;
|
||||
case 2:
|
||||
result.val_string = parseEXIFString(buf, result.length, result.data, base, len);
|
||||
break;
|
||||
case 3:
|
||||
result.val_16 = parse16((const unsigned char *) buf + offs + 8, alignIntel);
|
||||
break;
|
||||
case 4:
|
||||
result.val_32 = result.data;
|
||||
break;
|
||||
case 5:
|
||||
if (base + result.data + 8 <= len)
|
||||
result.val_rational = parseEXIFRational(buf + base + result.data, alignIntel);
|
||||
break;
|
||||
case 7:
|
||||
case 9:
|
||||
case 10:
|
||||
break;
|
||||
default:
|
||||
result.tag = 0xFF;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Parse value in specified format
|
||||
switch (result.format) {
|
||||
case 1:
|
||||
result.val_byte = (unsigned char)*(buf + offs + 8);
|
||||
break;
|
||||
case 2:
|
||||
result.val_string = parseEXIFString(buf, result.length, result.data, base, len);
|
||||
break;
|
||||
case 3:
|
||||
result.val_16 = parse16((const unsigned char *)buf + offs + 8, alignIntel);
|
||||
break;
|
||||
case 4:
|
||||
result.val_32 = result.data;
|
||||
break;
|
||||
case 5:
|
||||
if (base + result.data + 8 <= len)
|
||||
result.val_rational = parseEXIFRational(buf + base + result.data, alignIntel);
|
||||
break;
|
||||
case 7:
|
||||
case 9:
|
||||
case 10:
|
||||
break;
|
||||
default:
|
||||
result.tag = 0xFF;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Locates the EXIF segment and parses it using parseFromEXIFSegment
|
||||
//
|
||||
int EXIFInfo::parseFrom(const unsigned char *buf, unsigned len) {
|
||||
// Sanity check: all JPEG files start with 0xFFD8 and end with 0xFFD9
|
||||
// This check also ensures that the user has supplied a correct value for len.
|
||||
if (!buf || len < 4)
|
||||
return PARSE_EXIF_ERROR_NO_EXIF;
|
||||
if (buf[0] != 0xFF || buf[1] != 0xD8)
|
||||
return PARSE_EXIF_ERROR_NO_JPEG;
|
||||
if (buf[len-2] != 0xFF || buf[len-1] != 0xD9)
|
||||
return PARSE_EXIF_ERROR_NO_JPEG;
|
||||
clear();
|
||||
int EXIFInfo::parseFrom(const unsigned char *buf, unsigned len)
|
||||
{
|
||||
// Sanity check: all JPEG files start with 0xFFD8 and end with 0xFFD9
|
||||
// This check also ensures that the user has supplied a correct value for len.
|
||||
if (!buf || len < 4)
|
||||
return PARSE_EXIF_ERROR_NO_EXIF;
|
||||
if (buf[0] != 0xFF || buf[1] != 0xD8)
|
||||
return PARSE_EXIF_ERROR_NO_JPEG;
|
||||
if (buf[len - 2] != 0xFF || buf[len - 1] != 0xD9)
|
||||
return PARSE_EXIF_ERROR_NO_JPEG;
|
||||
clear();
|
||||
|
||||
// Scan for EXIF header (bytes 0xFF 0xE1) and do a sanity check by
|
||||
// looking for bytes "Exif\0\0". The marker length data is in Motorola
|
||||
// byte order, which results in the 'false' parameter to parse16().
|
||||
// The marker has to contain at least the TIFF header, otherwise the
|
||||
// EXIF data is corrupt. So the minimum length specified here has to be:
|
||||
// 2 bytes: section size
|
||||
// 6 bytes: "Exif\0\0" string
|
||||
// 2 bytes: TIFF header (either "II" or "MM" string)
|
||||
// 2 bytes: TIFF magic (short 0x2a00 in Motorola byte order)
|
||||
// 4 bytes: Offset to first IFD
|
||||
// =========
|
||||
// 16 bytes
|
||||
unsigned offs = 0; // current offset into buffer
|
||||
for (offs = 0; offs < len-1; offs++)
|
||||
if (buf[offs] == 0xFF && buf[offs+1] == 0xE1)
|
||||
break;
|
||||
if (offs + 4 > len)
|
||||
return PARSE_EXIF_ERROR_NO_EXIF;
|
||||
offs += 2;
|
||||
unsigned short section_length = parse16(buf + offs, false);
|
||||
if (offs + section_length > len || section_length < 16)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
offs += 2;
|
||||
// Scan for EXIF header (bytes 0xFF 0xE1) and do a sanity check by
|
||||
// looking for bytes "Exif\0\0". The marker length data is in Motorola
|
||||
// byte order, which results in the 'false' parameter to parse16().
|
||||
// The marker has to contain at least the TIFF header, otherwise the
|
||||
// EXIF data is corrupt. So the minimum length specified here has to be:
|
||||
// 2 bytes: section size
|
||||
// 6 bytes: "Exif\0\0" string
|
||||
// 2 bytes: TIFF header (either "II" or "MM" string)
|
||||
// 2 bytes: TIFF magic (short 0x2a00 in Motorola byte order)
|
||||
// 4 bytes: Offset to first IFD
|
||||
// =========
|
||||
// 16 bytes
|
||||
unsigned offs = 0; // current offset into buffer
|
||||
for (offs = 0; offs < len - 1; offs++)
|
||||
if (buf[offs] == 0xFF && buf[offs + 1] == 0xE1)
|
||||
break;
|
||||
if (offs + 4 > len)
|
||||
return PARSE_EXIF_ERROR_NO_EXIF;
|
||||
offs += 2;
|
||||
unsigned short section_length = parse16(buf + offs, false);
|
||||
if (offs + section_length > len || section_length < 16)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
offs += 2;
|
||||
|
||||
return parseFromEXIFSegment(buf + offs, len - offs);
|
||||
return parseFromEXIFSegment(buf + offs, len - offs);
|
||||
}
|
||||
|
||||
int EXIFInfo::parseFrom(const string &data) {
|
||||
return parseFrom((const unsigned char *)data.data(), data.length());
|
||||
int EXIFInfo::parseFrom(const string &data)
|
||||
{
|
||||
return parseFrom((const unsigned char *)data.data(), data.length());
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -194,366 +202,368 @@ int EXIFInfo::parseFrom(const string &data) {
|
|||
// PARAM: 'buf' start of the EXIF TIFF, which must be the bytes "Exif\0\0".
|
||||
// PARAM: 'len' length of buffer
|
||||
//
|
||||
int EXIFInfo::parseFromEXIFSegment(const unsigned char *buf, unsigned len) {
|
||||
bool alignIntel = true; // byte alignment (defined in EXIF header)
|
||||
unsigned offs = 0; // current offset into buffer
|
||||
if (!buf || len < 6)
|
||||
return PARSE_EXIF_ERROR_NO_EXIF;
|
||||
int EXIFInfo::parseFromEXIFSegment(const unsigned char *buf, unsigned len)
|
||||
{
|
||||
bool alignIntel = true; // byte alignment (defined in EXIF header)
|
||||
unsigned offs = 0; // current offset into buffer
|
||||
if (!buf || len < 6)
|
||||
return PARSE_EXIF_ERROR_NO_EXIF;
|
||||
|
||||
if (!std::equal(buf, buf+6, "Exif\0\0"))
|
||||
return PARSE_EXIF_ERROR_NO_EXIF;
|
||||
offs += 6;
|
||||
if (!std::equal(buf, buf + 6, "Exif\0\0"))
|
||||
return PARSE_EXIF_ERROR_NO_EXIF;
|
||||
offs += 6;
|
||||
|
||||
// Now parsing the TIFF header. The first two bytes are either "II" or
|
||||
// "MM" for Intel or Motorola byte alignment. Sanity check by parsing
|
||||
// the unsigned short that follows, making sure it equals 0x2a. The
|
||||
// last 4 bytes are an offset into the first IFD, which are added to
|
||||
// the global offset counter. For this block, we expect the following
|
||||
// minimum size:
|
||||
// 2 bytes: 'II' or 'MM'
|
||||
// 2 bytes: 0x002a
|
||||
// 4 bytes: offset to first IDF
|
||||
// -----------------------------
|
||||
// 8 bytes
|
||||
if (offs + 8 > len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
unsigned tiff_header_start = offs;
|
||||
if (buf[offs] == 'I' && buf[offs+1] == 'I')
|
||||
alignIntel = true;
|
||||
else {
|
||||
if(buf[offs] == 'M' && buf[offs+1] == 'M')
|
||||
alignIntel = false;
|
||||
else
|
||||
return PARSE_EXIF_ERROR_UNKNOWN_BYTEALIGN;
|
||||
}
|
||||
this->ByteAlign = alignIntel;
|
||||
offs += 2;
|
||||
if (0x2a != parse16(buf+offs, alignIntel))
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
offs += 2;
|
||||
unsigned first_ifd_offset = parse32(buf + offs, alignIntel);
|
||||
offs += first_ifd_offset - 4;
|
||||
if (offs >= len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
// Now parsing the TIFF header. The first two bytes are either "II" or
|
||||
// "MM" for Intel or Motorola byte alignment. Sanity check by parsing
|
||||
// the unsigned short that follows, making sure it equals 0x2a. The
|
||||
// last 4 bytes are an offset into the first IFD, which are added to
|
||||
// the global offset counter. For this block, we expect the following
|
||||
// minimum size:
|
||||
// 2 bytes: 'II' or 'MM'
|
||||
// 2 bytes: 0x002a
|
||||
// 4 bytes: offset to first IDF
|
||||
// -----------------------------
|
||||
// 8 bytes
|
||||
if (offs + 8 > len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
unsigned tiff_header_start = offs;
|
||||
if (buf[offs] == 'I' && buf[offs + 1] == 'I')
|
||||
alignIntel = true;
|
||||
else {
|
||||
if (buf[offs] == 'M' && buf[offs + 1] == 'M')
|
||||
alignIntel = false;
|
||||
else
|
||||
return PARSE_EXIF_ERROR_UNKNOWN_BYTEALIGN;
|
||||
}
|
||||
this->ByteAlign = alignIntel;
|
||||
offs += 2;
|
||||
if (0x2a != parse16(buf + offs, alignIntel))
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
offs += 2;
|
||||
unsigned first_ifd_offset = parse32(buf + offs, alignIntel);
|
||||
offs += first_ifd_offset - 4;
|
||||
if (offs >= len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
|
||||
// Now parsing the first Image File Directory (IFD0, for the main image).
|
||||
// An IFD consists of a variable number of 12-byte directory entries. The
|
||||
// first two bytes of the IFD section contain the number of directory
|
||||
// entries in the section. The last 4 bytes of the IFD contain an offset
|
||||
// to the next IFD, which means this IFD must contain exactly 6 + 12 * num
|
||||
// bytes of data.
|
||||
if (offs + 2 > len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
int num_entries = parse16(buf + offs, alignIntel);
|
||||
if (offs + 6 + 12 * num_entries > len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
offs += 2;
|
||||
unsigned exif_sub_ifd_offset = len;
|
||||
unsigned gps_sub_ifd_offset = len;
|
||||
while (--num_entries >= 0) {
|
||||
IFEntry result = parseIFEntry(buf, offs, alignIntel, tiff_header_start, len);
|
||||
offs += 12;
|
||||
switch(result.tag) {
|
||||
case 0x102:
|
||||
// Bits per sample
|
||||
if (result.format == 3)
|
||||
this->BitsPerSample = result.val_16;
|
||||
break;
|
||||
// Now parsing the first Image File Directory (IFD0, for the main image).
|
||||
// An IFD consists of a variable number of 12-byte directory entries. The
|
||||
// first two bytes of the IFD section contain the number of directory
|
||||
// entries in the section. The last 4 bytes of the IFD contain an offset
|
||||
// to the next IFD, which means this IFD must contain exactly 6 + 12 * num
|
||||
// bytes of data.
|
||||
if (offs + 2 > len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
int num_entries = parse16(buf + offs, alignIntel);
|
||||
if (offs + 6 + 12 * num_entries > len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
offs += 2;
|
||||
unsigned exif_sub_ifd_offset = len;
|
||||
unsigned gps_sub_ifd_offset = len;
|
||||
while (--num_entries >= 0) {
|
||||
IFEntry result = parseIFEntry(buf, offs, alignIntel, tiff_header_start, len);
|
||||
offs += 12;
|
||||
switch (result.tag) {
|
||||
case 0x102:
|
||||
// Bits per sample
|
||||
if (result.format == 3)
|
||||
this->BitsPerSample = result.val_16;
|
||||
break;
|
||||
|
||||
case 0x10E:
|
||||
// Image description
|
||||
if (result.format == 2)
|
||||
this->ImageDescription = result.val_string;
|
||||
break;
|
||||
case 0x10E:
|
||||
// Image description
|
||||
if (result.format == 2)
|
||||
this->ImageDescription = result.val_string;
|
||||
break;
|
||||
|
||||
case 0x10F:
|
||||
// Digicam make
|
||||
if (result.format == 2)
|
||||
this->Make = result.val_string;
|
||||
break;
|
||||
case 0x10F:
|
||||
// Digicam make
|
||||
if (result.format == 2)
|
||||
this->Make = result.val_string;
|
||||
break;
|
||||
|
||||
case 0x110:
|
||||
// Digicam model
|
||||
if (result.format == 2)
|
||||
this->Model = result.val_string;
|
||||
break;
|
||||
case 0x110:
|
||||
// Digicam model
|
||||
if (result.format == 2)
|
||||
this->Model = result.val_string;
|
||||
break;
|
||||
|
||||
case 0x112:
|
||||
// Orientation of image
|
||||
if (result.format == 3)
|
||||
this->Orientation = result.val_16;
|
||||
break;
|
||||
case 0x112:
|
||||
// Orientation of image
|
||||
if (result.format == 3)
|
||||
this->Orientation = result.val_16;
|
||||
break;
|
||||
|
||||
case 0x131:
|
||||
// Software used for image
|
||||
if (result.format == 2)
|
||||
this->Software = result.val_string;
|
||||
break;
|
||||
case 0x131:
|
||||
// Software used for image
|
||||
if (result.format == 2)
|
||||
this->Software = result.val_string;
|
||||
break;
|
||||
|
||||
case 0x132:
|
||||
// EXIF/TIFF date/time of image modification
|
||||
if (result.format == 2)
|
||||
this->DateTime = result.val_string;
|
||||
break;
|
||||
case 0x132:
|
||||
// EXIF/TIFF date/time of image modification
|
||||
if (result.format == 2)
|
||||
this->DateTime = result.val_string;
|
||||
break;
|
||||
|
||||
case 0x8298:
|
||||
// Copyright information
|
||||
if (result.format == 2)
|
||||
this->Copyright = result.val_string;
|
||||
break;
|
||||
case 0x8298:
|
||||
// Copyright information
|
||||
if (result.format == 2)
|
||||
this->Copyright = result.val_string;
|
||||
break;
|
||||
|
||||
case 0x8825:
|
||||
// GPS IFS offset
|
||||
gps_sub_ifd_offset = tiff_header_start + result.data;
|
||||
break;
|
||||
case 0x8825:
|
||||
// GPS IFS offset
|
||||
gps_sub_ifd_offset = tiff_header_start + result.data;
|
||||
break;
|
||||
|
||||
case 0x8769:
|
||||
// EXIF SubIFD offset
|
||||
exif_sub_ifd_offset = tiff_header_start + result.data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
case 0x8769:
|
||||
// EXIF SubIFD offset
|
||||
exif_sub_ifd_offset = tiff_header_start + result.data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Jump to the EXIF SubIFD if it exists and parse all the information
|
||||
// there. Note that it's possible that the EXIF SubIFD doesn't exist.
|
||||
// The EXIF SubIFD contains most of the interesting information that a
|
||||
// typical user might want.
|
||||
if (exif_sub_ifd_offset + 4 <= len) {
|
||||
offs = exif_sub_ifd_offset;
|
||||
int num_entries = parse16(buf + offs, alignIntel);
|
||||
if (offs + 6 + 12 * num_entries > len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
offs += 2;
|
||||
while (--num_entries >= 0) {
|
||||
IFEntry result = parseIFEntry(buf, offs, alignIntel, tiff_header_start, len);
|
||||
switch(result.tag) {
|
||||
case 0x829a:
|
||||
// Exposure time in seconds
|
||||
if (result.format == 5)
|
||||
this->ExposureTime = result.val_rational;
|
||||
break;
|
||||
// Jump to the EXIF SubIFD if it exists and parse all the information
|
||||
// there. Note that it's possible that the EXIF SubIFD doesn't exist.
|
||||
// The EXIF SubIFD contains most of the interesting information that a
|
||||
// typical user might want.
|
||||
if (exif_sub_ifd_offset + 4 <= len) {
|
||||
offs = exif_sub_ifd_offset;
|
||||
int num_entries = parse16(buf + offs, alignIntel);
|
||||
if (offs + 6 + 12 * num_entries > len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
offs += 2;
|
||||
while (--num_entries >= 0) {
|
||||
IFEntry result = parseIFEntry(buf, offs, alignIntel, tiff_header_start, len);
|
||||
switch (result.tag) {
|
||||
case 0x829a:
|
||||
// Exposure time in seconds
|
||||
if (result.format == 5)
|
||||
this->ExposureTime = result.val_rational;
|
||||
break;
|
||||
|
||||
case 0x829d:
|
||||
// FNumber
|
||||
if (result.format == 5)
|
||||
this->FNumber = result.val_rational;
|
||||
break;
|
||||
case 0x829d:
|
||||
// FNumber
|
||||
if (result.format == 5)
|
||||
this->FNumber = result.val_rational;
|
||||
break;
|
||||
|
||||
case 0x8827:
|
||||
// ISO Speed Rating
|
||||
if (result.format == 3)
|
||||
this->ISOSpeedRatings = result.val_16;
|
||||
break;
|
||||
case 0x8827:
|
||||
// ISO Speed Rating
|
||||
if (result.format == 3)
|
||||
this->ISOSpeedRatings = result.val_16;
|
||||
break;
|
||||
|
||||
case 0x9003:
|
||||
// Original date and time
|
||||
if (result.format == 2)
|
||||
this->DateTimeOriginal = result.val_string;
|
||||
break;
|
||||
case 0x9003:
|
||||
// Original date and time
|
||||
if (result.format == 2)
|
||||
this->DateTimeOriginal = result.val_string;
|
||||
break;
|
||||
|
||||
case 0x9004:
|
||||
// Digitization date and time
|
||||
if (result.format == 2)
|
||||
this->DateTimeDigitized = result.val_string;
|
||||
break;
|
||||
case 0x9004:
|
||||
// Digitization date and time
|
||||
if (result.format == 2)
|
||||
this->DateTimeDigitized = result.val_string;
|
||||
break;
|
||||
|
||||
case 0x9201:
|
||||
// Shutter speed value
|
||||
if (result.format == 5)
|
||||
this->ShutterSpeedValue = result.val_rational;
|
||||
break;
|
||||
case 0x9201:
|
||||
// Shutter speed value
|
||||
if (result.format == 5)
|
||||
this->ShutterSpeedValue = result.val_rational;
|
||||
break;
|
||||
|
||||
case 0x9204:
|
||||
// Exposure bias value
|
||||
if (result.format == 5)
|
||||
this->ExposureBiasValue = result.val_rational;
|
||||
break;
|
||||
case 0x9204:
|
||||
// Exposure bias value
|
||||
if (result.format == 5)
|
||||
this->ExposureBiasValue = result.val_rational;
|
||||
break;
|
||||
|
||||
case 0x9206:
|
||||
// Subject distance
|
||||
if (result.format == 5)
|
||||
this->SubjectDistance = result.val_rational;
|
||||
break;
|
||||
case 0x9206:
|
||||
// Subject distance
|
||||
if (result.format == 5)
|
||||
this->SubjectDistance = result.val_rational;
|
||||
break;
|
||||
|
||||
case 0x9209:
|
||||
// Flash used
|
||||
if (result.format == 3)
|
||||
this->Flash = result.data ? 1 : 0;
|
||||
break;
|
||||
case 0x9209:
|
||||
// Flash used
|
||||
if (result.format == 3)
|
||||
this->Flash = result.data ? 1 : 0;
|
||||
break;
|
||||
|
||||
case 0x920a:
|
||||
// Focal length
|
||||
if (result.format == 5)
|
||||
this->FocalLength = result.val_rational;
|
||||
break;
|
||||
case 0x920a:
|
||||
// Focal length
|
||||
if (result.format == 5)
|
||||
this->FocalLength = result.val_rational;
|
||||
break;
|
||||
|
||||
case 0x9207:
|
||||
// Metering mode
|
||||
if (result.format == 3)
|
||||
this->MeteringMode = result.val_16;
|
||||
break;
|
||||
case 0x9207:
|
||||
// Metering mode
|
||||
if (result.format == 3)
|
||||
this->MeteringMode = result.val_16;
|
||||
break;
|
||||
|
||||
case 0x9291:
|
||||
// Subsecond original time
|
||||
if (result.format == 2)
|
||||
this->SubSecTimeOriginal = result.val_string;
|
||||
break;
|
||||
case 0x9291:
|
||||
// Subsecond original time
|
||||
if (result.format == 2)
|
||||
this->SubSecTimeOriginal = result.val_string;
|
||||
break;
|
||||
|
||||
case 0xa002:
|
||||
// EXIF Image width
|
||||
if (result.format == 4)
|
||||
this->ImageWidth = result.val_32;
|
||||
if (result.format == 3)
|
||||
this->ImageWidth = result.val_16;
|
||||
break;
|
||||
case 0xa002:
|
||||
// EXIF Image width
|
||||
if (result.format == 4)
|
||||
this->ImageWidth = result.val_32;
|
||||
if (result.format == 3)
|
||||
this->ImageWidth = result.val_16;
|
||||
break;
|
||||
|
||||
case 0xa003:
|
||||
// EXIF Image height
|
||||
if (result.format == 4)
|
||||
this->ImageHeight = result.val_32;
|
||||
if (result.format == 3)
|
||||
this->ImageHeight = result.val_16;
|
||||
break;
|
||||
case 0xa003:
|
||||
// EXIF Image height
|
||||
if (result.format == 4)
|
||||
this->ImageHeight = result.val_32;
|
||||
if (result.format == 3)
|
||||
this->ImageHeight = result.val_16;
|
||||
break;
|
||||
|
||||
case 0xa405:
|
||||
// Focal length in 35mm film
|
||||
if (result.format == 3)
|
||||
this->FocalLengthIn35mm = result.val_16;
|
||||
break;
|
||||
}
|
||||
offs += 12;
|
||||
}
|
||||
}
|
||||
case 0xa405:
|
||||
// Focal length in 35mm film
|
||||
if (result.format == 3)
|
||||
this->FocalLengthIn35mm = result.val_16;
|
||||
break;
|
||||
}
|
||||
offs += 12;
|
||||
}
|
||||
}
|
||||
|
||||
// Jump to the GPS SubIFD if it exists and parse all the information
|
||||
// there. Note that it's possible that the GPS SubIFD doesn't exist.
|
||||
if (gps_sub_ifd_offset + 4 <= len) {
|
||||
offs = gps_sub_ifd_offset;
|
||||
int num_entries = parse16(buf + offs, alignIntel);
|
||||
if (offs + 6 + 12 * num_entries > len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
offs += 2;
|
||||
while (--num_entries >= 0) {
|
||||
unsigned short tag = parse16(buf + offs, alignIntel);
|
||||
unsigned short format = parse16(buf + offs + 2, alignIntel);
|
||||
unsigned length = parse32(buf + offs + 4, alignIntel);
|
||||
unsigned data = parse32(buf + offs + 8, alignIntel);
|
||||
switch(tag) {
|
||||
case 1:
|
||||
// GPS north or south
|
||||
this->GeoLocation.LatComponents.direction = *(buf + offs + 8);
|
||||
if ('S' == this->GeoLocation.LatComponents.direction)
|
||||
this->GeoLocation.Latitude = -this->GeoLocation.Latitude;
|
||||
break;
|
||||
// Jump to the GPS SubIFD if it exists and parse all the information
|
||||
// there. Note that it's possible that the GPS SubIFD doesn't exist.
|
||||
if (gps_sub_ifd_offset + 4 <= len) {
|
||||
offs = gps_sub_ifd_offset;
|
||||
int num_entries = parse16(buf + offs, alignIntel);
|
||||
if (offs + 6 + 12 * num_entries > len)
|
||||
return PARSE_EXIF_ERROR_CORRUPT;
|
||||
offs += 2;
|
||||
while (--num_entries >= 0) {
|
||||
unsigned short tag = parse16(buf + offs, alignIntel);
|
||||
unsigned short format = parse16(buf + offs + 2, alignIntel);
|
||||
unsigned length = parse32(buf + offs + 4, alignIntel);
|
||||
unsigned data = parse32(buf + offs + 8, alignIntel);
|
||||
switch (tag) {
|
||||
case 1:
|
||||
// GPS north or south
|
||||
this->GeoLocation.LatComponents.direction = *(buf + offs + 8);
|
||||
if ('S' == this->GeoLocation.LatComponents.direction)
|
||||
this->GeoLocation.Latitude = -this->GeoLocation.Latitude;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// GPS latitude
|
||||
if (format == 5 && length == 3) {
|
||||
this->GeoLocation.LatComponents.degrees =
|
||||
parseEXIFRational(buf + data + tiff_header_start, alignIntel);
|
||||
this->GeoLocation.LatComponents.minutes =
|
||||
parseEXIFRational(buf + data + tiff_header_start + 8, alignIntel);
|
||||
this->GeoLocation.LatComponents.seconds =
|
||||
parseEXIFRational(buf + data + tiff_header_start + 16, alignIntel);
|
||||
this->GeoLocation.Latitude =
|
||||
this->GeoLocation.LatComponents.degrees +
|
||||
this->GeoLocation.LatComponents.minutes / 60 +
|
||||
this->GeoLocation.LatComponents.seconds / 3600;
|
||||
if ('S' == this->GeoLocation.LatComponents.direction)
|
||||
this->GeoLocation.Latitude = -this->GeoLocation.Latitude;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
// GPS latitude
|
||||
if (format == 5 && length == 3) {
|
||||
this->GeoLocation.LatComponents.degrees =
|
||||
parseEXIFRational(buf + data + tiff_header_start, alignIntel);
|
||||
this->GeoLocation.LatComponents.minutes =
|
||||
parseEXIFRational(buf + data + tiff_header_start + 8, alignIntel);
|
||||
this->GeoLocation.LatComponents.seconds =
|
||||
parseEXIFRational(buf + data + tiff_header_start + 16, alignIntel);
|
||||
this->GeoLocation.Latitude =
|
||||
this->GeoLocation.LatComponents.degrees +
|
||||
this->GeoLocation.LatComponents.minutes / 60 +
|
||||
this->GeoLocation.LatComponents.seconds / 3600;
|
||||
if ('S' == this->GeoLocation.LatComponents.direction)
|
||||
this->GeoLocation.Latitude = -this->GeoLocation.Latitude;
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
// GPS east or west
|
||||
this->GeoLocation.LonComponents.direction = *(buf + offs + 8);
|
||||
if ('W' == this->GeoLocation.LonComponents.direction)
|
||||
this->GeoLocation.Longitude = -this->GeoLocation.Longitude;
|
||||
break;
|
||||
case 3:
|
||||
// GPS east or west
|
||||
this->GeoLocation.LonComponents.direction = *(buf + offs + 8);
|
||||
if ('W' == this->GeoLocation.LonComponents.direction)
|
||||
this->GeoLocation.Longitude = -this->GeoLocation.Longitude;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
// GPS longitude
|
||||
if (format == 5 && length == 3) {
|
||||
this->GeoLocation.LonComponents.degrees =
|
||||
parseEXIFRational(buf + data + tiff_header_start, alignIntel);
|
||||
this->GeoLocation.LonComponents.minutes =
|
||||
parseEXIFRational(buf + data + tiff_header_start + 8, alignIntel);
|
||||
this->GeoLocation.LonComponents.seconds =
|
||||
parseEXIFRational(buf + data + tiff_header_start + 16, alignIntel);
|
||||
this->GeoLocation.Longitude =
|
||||
this->GeoLocation.LonComponents.degrees +
|
||||
this->GeoLocation.LonComponents.minutes / 60 +
|
||||
this->GeoLocation.LonComponents.seconds / 3600;
|
||||
if ('W' == this->GeoLocation.LonComponents.direction)
|
||||
this->GeoLocation.Longitude = -this->GeoLocation.Longitude;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
// GPS longitude
|
||||
if (format == 5 && length == 3) {
|
||||
this->GeoLocation.LonComponents.degrees =
|
||||
parseEXIFRational(buf + data + tiff_header_start, alignIntel);
|
||||
this->GeoLocation.LonComponents.minutes =
|
||||
parseEXIFRational(buf + data + tiff_header_start + 8, alignIntel);
|
||||
this->GeoLocation.LonComponents.seconds =
|
||||
parseEXIFRational(buf + data + tiff_header_start + 16, alignIntel);
|
||||
this->GeoLocation.Longitude =
|
||||
this->GeoLocation.LonComponents.degrees +
|
||||
this->GeoLocation.LonComponents.minutes / 60 +
|
||||
this->GeoLocation.LonComponents.seconds / 3600;
|
||||
if ('W' == this->GeoLocation.LonComponents.direction)
|
||||
this->GeoLocation.Longitude = -this->GeoLocation.Longitude;
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
// GPS altitude reference (below or above sea level)
|
||||
this->GeoLocation.AltitudeRef = *(buf + offs + 8);
|
||||
if (1 == this->GeoLocation.AltitudeRef)
|
||||
this->GeoLocation.Altitude = -this->GeoLocation.Altitude;
|
||||
break;
|
||||
case 5:
|
||||
// GPS altitude reference (below or above sea level)
|
||||
this->GeoLocation.AltitudeRef = *(buf + offs + 8);
|
||||
if (1 == this->GeoLocation.AltitudeRef)
|
||||
this->GeoLocation.Altitude = -this->GeoLocation.Altitude;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
// GPS altitude reference
|
||||
if (format == 5) {
|
||||
this->GeoLocation.Altitude =
|
||||
parseEXIFRational(buf + data + tiff_header_start, alignIntel);
|
||||
if (1 == this->GeoLocation.AltitudeRef)
|
||||
this->GeoLocation.Altitude = -this->GeoLocation.Altitude;
|
||||
}
|
||||
break;
|
||||
}
|
||||
offs += 12;
|
||||
}
|
||||
}
|
||||
case 6:
|
||||
// GPS altitude reference
|
||||
if (format == 5) {
|
||||
this->GeoLocation.Altitude =
|
||||
parseEXIFRational(buf + data + tiff_header_start, alignIntel);
|
||||
if (1 == this->GeoLocation.AltitudeRef)
|
||||
this->GeoLocation.Altitude = -this->GeoLocation.Altitude;
|
||||
}
|
||||
break;
|
||||
}
|
||||
offs += 12;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSE_EXIF_SUCCESS;
|
||||
return PARSE_EXIF_SUCCESS;
|
||||
}
|
||||
|
||||
void EXIFInfo::clear() {
|
||||
// Strings
|
||||
ImageDescription = "";
|
||||
Make = "";
|
||||
Model = "";
|
||||
Software = "";
|
||||
DateTime = "";
|
||||
DateTimeOriginal = "";
|
||||
DateTimeDigitized = "";
|
||||
SubSecTimeOriginal= "";
|
||||
Copyright = "";
|
||||
void EXIFInfo::clear()
|
||||
{
|
||||
// Strings
|
||||
ImageDescription = "";
|
||||
Make = "";
|
||||
Model = "";
|
||||
Software = "";
|
||||
DateTime = "";
|
||||
DateTimeOriginal = "";
|
||||
DateTimeDigitized = "";
|
||||
SubSecTimeOriginal = "";
|
||||
Copyright = "";
|
||||
|
||||
// Shorts / unsigned / double
|
||||
ByteAlign = 0;
|
||||
Orientation = 0;
|
||||
// Shorts / unsigned / double
|
||||
ByteAlign = 0;
|
||||
Orientation = 0;
|
||||
|
||||
BitsPerSample = 0;
|
||||
ExposureTime = 0;
|
||||
FNumber = 0;
|
||||
ISOSpeedRatings = 0;
|
||||
ShutterSpeedValue = 0;
|
||||
ExposureBiasValue = 0;
|
||||
SubjectDistance = 0;
|
||||
FocalLength = 0;
|
||||
FocalLengthIn35mm = 0;
|
||||
Flash = 0;
|
||||
MeteringMode = 0;
|
||||
ImageWidth = 0;
|
||||
ImageHeight = 0;
|
||||
BitsPerSample = 0;
|
||||
ExposureTime = 0;
|
||||
FNumber = 0;
|
||||
ISOSpeedRatings = 0;
|
||||
ShutterSpeedValue = 0;
|
||||
ExposureBiasValue = 0;
|
||||
SubjectDistance = 0;
|
||||
FocalLength = 0;
|
||||
FocalLengthIn35mm = 0;
|
||||
Flash = 0;
|
||||
MeteringMode = 0;
|
||||
ImageWidth = 0;
|
||||
ImageHeight = 0;
|
||||
|
||||
// Geolocation
|
||||
GeoLocation.Latitude = 0;
|
||||
GeoLocation.Longitude = 0;
|
||||
GeoLocation.Altitude = 0;
|
||||
GeoLocation.AltitudeRef = 0;
|
||||
GeoLocation.LatComponents.degrees = 0;
|
||||
GeoLocation.LatComponents.minutes = 0;
|
||||
GeoLocation.LatComponents.seconds = 0;
|
||||
GeoLocation.LatComponents.direction = 0;
|
||||
GeoLocation.LonComponents.degrees = 0;
|
||||
GeoLocation.LonComponents.minutes = 0;
|
||||
GeoLocation.LonComponents.seconds = 0;
|
||||
GeoLocation.LonComponents.direction = 0;
|
||||
// Geolocation
|
||||
GeoLocation.Latitude = 0;
|
||||
GeoLocation.Longitude = 0;
|
||||
GeoLocation.Altitude = 0;
|
||||
GeoLocation.AltitudeRef = 0;
|
||||
GeoLocation.LatComponents.degrees = 0;
|
||||
GeoLocation.LatComponents.minutes = 0;
|
||||
GeoLocation.LatComponents.seconds = 0;
|
||||
GeoLocation.LatComponents.direction = 0;
|
||||
GeoLocation.LonComponents.degrees = 0;
|
||||
GeoLocation.LonComponents.minutes = 0;
|
||||
GeoLocation.LonComponents.seconds = 0;
|
||||
GeoLocation.LonComponents.direction = 0;
|
||||
}
|
||||
|
|
160
qt-ui/exif.h
160
qt-ui/exif.h
|
@ -15,17 +15,17 @@
|
|||
================
|
||||
|
||||
2.1: Released July 2013
|
||||
-- fixed a bug where JPEGs without an EXIF SubIFD would not be parsed
|
||||
-- fixed a bug in parsing GPS coordinate seconds
|
||||
-- fixed makefile bug
|
||||
-- added two pathological test images from Matt Galloway
|
||||
-- fixed a bug where JPEGs without an EXIF SubIFD would not be parsed
|
||||
-- fixed a bug in parsing GPS coordinate seconds
|
||||
-- fixed makefile bug
|
||||
-- added two pathological test images from Matt Galloway
|
||||
http://www.galloway.me.uk/2012/01/uiimageorientation-exif-orientation-sample-images/
|
||||
-- split main parsing routine for easier integration into Firefox
|
||||
-- split main parsing routine for easier integration into Firefox
|
||||
|
||||
2.0: Released February 2013
|
||||
-- complete rewrite
|
||||
-- no new/delete
|
||||
-- added GPS support
|
||||
-- complete rewrite
|
||||
-- no new/delete
|
||||
-- added GPS support
|
||||
|
||||
1.0: Released 2010
|
||||
|
||||
|
@ -58,86 +58,88 @@
|
|||
// Class responsible for storing and parsing EXIF information from a JPEG blob
|
||||
//
|
||||
class EXIFInfo {
|
||||
public:
|
||||
// Parsing function for an entire JPEG image buffer.
|
||||
//
|
||||
// PARAM 'data': A pointer to a JPEG image.
|
||||
// PARAM 'length': The length of the JPEG image.
|
||||
// RETURN: PARSE_EXIF_SUCCESS (0) on succes with 'result' filled out
|
||||
// error code otherwise, as defined by the PARSE_EXIF_ERROR_* macros
|
||||
int parseFrom(const unsigned char *data, unsigned length);
|
||||
int parseFrom(const std::string &data);
|
||||
public:
|
||||
// Parsing function for an entire JPEG image buffer.
|
||||
//
|
||||
// PARAM 'data': A pointer to a JPEG image.
|
||||
// PARAM 'length': The length of the JPEG image.
|
||||
// RETURN: PARSE_EXIF_SUCCESS (0) on succes with 'result' filled out
|
||||
// error code otherwise, as defined by the PARSE_EXIF_ERROR_* macros
|
||||
int parseFrom(const unsigned char *data, unsigned length);
|
||||
int parseFrom(const std::string &data);
|
||||
|
||||
// Parsing function for an EXIF segment. This is used internally by parseFrom()
|
||||
// but can be called for special cases where only the EXIF section is
|
||||
// available (i.e., a blob starting with the bytes "Exif\0\0").
|
||||
int parseFromEXIFSegment(const unsigned char *buf, unsigned len);
|
||||
// Parsing function for an EXIF segment. This is used internally by parseFrom()
|
||||
// but can be called for special cases where only the EXIF section is
|
||||
// available (i.e., a blob starting with the bytes "Exif\0\0").
|
||||
int parseFromEXIFSegment(const unsigned char *buf, unsigned len);
|
||||
|
||||
// Set all data members to default values.
|
||||
void clear();
|
||||
// Set all data members to default values.
|
||||
void clear();
|
||||
|
||||
// Data fields filled out by parseFrom()
|
||||
char ByteAlign; // 0 = Motorola byte alignment, 1 = Intel
|
||||
std::string ImageDescription; // Image description
|
||||
std::string Make; // Camera manufacturer's name
|
||||
std::string Model; // Camera model
|
||||
unsigned short Orientation; // Image orientation, start of data corresponds to
|
||||
// 0: unspecified in EXIF data
|
||||
// 1: upper left of image
|
||||
// 3: lower right of image
|
||||
// 6: upper right of image
|
||||
// 8: lower left of image
|
||||
// 9: undefined
|
||||
unsigned short BitsPerSample; // Number of bits per component
|
||||
std::string Software; // Software used
|
||||
std::string DateTime; // File change date and time
|
||||
std::string DateTimeOriginal; // Original file date and time (may not exist)
|
||||
std::string DateTimeDigitized; // Digitization date and time (may not exist)
|
||||
std::string SubSecTimeOriginal; // Sub-second time that original picture was taken
|
||||
std::string Copyright; // File copyright information
|
||||
double ExposureTime; // Exposure time in seconds
|
||||
double FNumber; // F/stop
|
||||
unsigned short ISOSpeedRatings; // ISO speed
|
||||
double ShutterSpeedValue; // Shutter speed (reciprocal of exposure time)
|
||||
double ExposureBiasValue; // Exposure bias value in EV
|
||||
double SubjectDistance; // Distance to focus point in meters
|
||||
double FocalLength; // Focal length of lens in millimeters
|
||||
unsigned short FocalLengthIn35mm; // Focal length in 35mm film
|
||||
char Flash; // 0 = no flash, 1 = flash used
|
||||
unsigned short MeteringMode; // Metering mode
|
||||
// 1: average
|
||||
// 2: center weighted average
|
||||
// 3: spot
|
||||
// 4: multi-spot
|
||||
// 5: multi-segment
|
||||
unsigned ImageWidth; // Image width reported in EXIF data
|
||||
unsigned ImageHeight; // Image height reported in EXIF data
|
||||
struct Geolocation_t { // GPS information embedded in file
|
||||
double Latitude; // Image latitude expressed as decimal
|
||||
double Longitude; // Image longitude expressed as decimal
|
||||
double Altitude; // Altitude in meters, relative to sea level
|
||||
char AltitudeRef; // 0 = above sea level, -1 = below sea level
|
||||
struct Coord_t {
|
||||
double degrees;
|
||||
double minutes;
|
||||
double seconds;
|
||||
char direction;
|
||||
} LatComponents, LonComponents; // Latitude, Longitude expressed in deg/min/sec
|
||||
} GeoLocation;
|
||||
EXIFInfo() {
|
||||
clear();
|
||||
}
|
||||
// Data fields filled out by parseFrom()
|
||||
char ByteAlign; // 0 = Motorola byte alignment, 1 = Intel
|
||||
std::string ImageDescription; // Image description
|
||||
std::string Make; // Camera manufacturer's name
|
||||
std::string Model; // Camera model
|
||||
unsigned short Orientation; // Image orientation, start of data corresponds to
|
||||
// 0: unspecified in EXIF data
|
||||
// 1: upper left of image
|
||||
// 3: lower right of image
|
||||
// 6: upper right of image
|
||||
// 8: lower left of image
|
||||
// 9: undefined
|
||||
unsigned short BitsPerSample; // Number of bits per component
|
||||
std::string Software; // Software used
|
||||
std::string DateTime; // File change date and time
|
||||
std::string DateTimeOriginal; // Original file date and time (may not exist)
|
||||
std::string DateTimeDigitized; // Digitization date and time (may not exist)
|
||||
std::string SubSecTimeOriginal; // Sub-second time that original picture was taken
|
||||
std::string Copyright; // File copyright information
|
||||
double ExposureTime; // Exposure time in seconds
|
||||
double FNumber; // F/stop
|
||||
unsigned short ISOSpeedRatings; // ISO speed
|
||||
double ShutterSpeedValue; // Shutter speed (reciprocal of exposure time)
|
||||
double ExposureBiasValue; // Exposure bias value in EV
|
||||
double SubjectDistance; // Distance to focus point in meters
|
||||
double FocalLength; // Focal length of lens in millimeters
|
||||
unsigned short FocalLengthIn35mm; // Focal length in 35mm film
|
||||
char Flash; // 0 = no flash, 1 = flash used
|
||||
unsigned short MeteringMode; // Metering mode
|
||||
// 1: average
|
||||
// 2: center weighted average
|
||||
// 3: spot
|
||||
// 4: multi-spot
|
||||
// 5: multi-segment
|
||||
unsigned ImageWidth; // Image width reported in EXIF data
|
||||
unsigned ImageHeight; // Image height reported in EXIF data
|
||||
struct Geolocation_t
|
||||
{ // GPS information embedded in file
|
||||
double Latitude; // Image latitude expressed as decimal
|
||||
double Longitude; // Image longitude expressed as decimal
|
||||
double Altitude; // Altitude in meters, relative to sea level
|
||||
char AltitudeRef; // 0 = above sea level, -1 = below sea level
|
||||
struct Coord_t {
|
||||
double degrees;
|
||||
double minutes;
|
||||
double seconds;
|
||||
char direction;
|
||||
} LatComponents, LonComponents; // Latitude, Longitude expressed in deg/min/sec
|
||||
} GeoLocation;
|
||||
EXIFInfo()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
};
|
||||
|
||||
// Parse was successful
|
||||
#define PARSE_EXIF_SUCCESS 0
|
||||
#define PARSE_EXIF_SUCCESS 0
|
||||
// No JPEG markers found in buffer, possibly invalid JPEG file
|
||||
#define PARSE_EXIF_ERROR_NO_JPEG 1982
|
||||
#define PARSE_EXIF_ERROR_NO_JPEG 1982
|
||||
// No EXIF header found in JPEG file.
|
||||
#define PARSE_EXIF_ERROR_NO_EXIF 1983
|
||||
#define PARSE_EXIF_ERROR_NO_EXIF 1983
|
||||
// Byte alignment specified in EXIF file was unknown (not Motorola or Intel).
|
||||
#define PARSE_EXIF_ERROR_UNKNOWN_BYTEALIGN 1984
|
||||
#define PARSE_EXIF_ERROR_UNKNOWN_BYTEALIGN 1984
|
||||
// EXIF header was found, but data was corrupted.
|
||||
#define PARSE_EXIF_ERROR_CORRUPT 1985
|
||||
#define PARSE_EXIF_ERROR_CORRUPT 1985
|
||||
|
||||
#endif // EXIF_H
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <QMouseEvent>
|
||||
#include <QMessageBox>
|
||||
|
||||
GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent),
|
||||
GlobeGPS::GlobeGPS(QWidget *parent) : MarbleWidget(parent),
|
||||
loadedDives(0),
|
||||
messageWidget(new KMessageWidget(this)),
|
||||
fixZoomTimer(new QTimer(this)),
|
||||
|
@ -35,7 +35,7 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent),
|
|||
// if not, check if they are in a known location
|
||||
MapThemeManager mtm;
|
||||
QStringList list = mtm.mapThemeIds();
|
||||
QString subsurfaceDataPath;
|
||||
QString subsurfaceDataPath;
|
||||
QDir marble;
|
||||
if (!list.contains("earth/googlesat/googlesat.dgml")) {
|
||||
subsurfaceDataPath = getSubsurfaceDataPath("marbledata");
|
||||
|
@ -55,7 +55,7 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent),
|
|||
setProjection(Marble::Spherical);
|
||||
|
||||
setAnimationsEnabled(true);
|
||||
Q_FOREACH(AbstractFloatItem *i, floatItems()) {
|
||||
Q_FOREACH(AbstractFloatItem * i, floatItems()) {
|
||||
i->setVisible(false);
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent),
|
|||
setShowScaleBar(true);
|
||||
setShowCompass(false);
|
||||
connect(this, SIGNAL(mouseClickGeoPosition(qreal, qreal, GeoDataCoordinates::Unit)),
|
||||
this, SLOT(mouseClicked(qreal, qreal, GeoDataCoordinates::Unit)));
|
||||
this, SLOT(mouseClicked(qreal, qreal, GeoDataCoordinates::Unit)));
|
||||
|
||||
setMinimumHeight(0);
|
||||
setMinimumWidth(0);
|
||||
|
@ -86,22 +86,22 @@ bool GlobeGPS::eventFilter(QObject *obj, QEvent *ev)
|
|||
// we need to move this to our 'contextMenuEvent'
|
||||
// if we plan to do a different one in the future.
|
||||
if (ev->type() == QEvent::ContextMenu) {
|
||||
contextMenuEvent(static_cast<QContextMenuEvent*>(ev));
|
||||
contextMenuEvent(static_cast<QContextMenuEvent *>(ev));
|
||||
return true;
|
||||
}
|
||||
if (ev->type() == QEvent::MouseButtonPress) {
|
||||
QMouseEvent *e = static_cast<QMouseEvent*>(ev);
|
||||
if (e->button() == Qt::RightButton)
|
||||
QMouseEvent *e = static_cast<QMouseEvent *>(ev);
|
||||
if (e->button() == Qt::RightButton)
|
||||
return true;
|
||||
}
|
||||
return QObject::eventFilter(obj,ev );
|
||||
return QObject::eventFilter(obj, ev);
|
||||
}
|
||||
|
||||
void GlobeGPS::contextMenuEvent(QContextMenuEvent* ev)
|
||||
void GlobeGPS::contextMenuEvent(QContextMenuEvent *ev)
|
||||
{
|
||||
QMenu m;
|
||||
QAction *a = m.addAction(tr("Edit Selected Dive Locations"), this, SLOT(prepareForGetDiveCoordinates()));
|
||||
a->setData(QVariant::fromValue<void*>(&m));
|
||||
a->setData(QVariant::fromValue<void *>(&m));
|
||||
m.exec(ev->globalPos());
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ void GlobeGPS::repopulateLabels()
|
|||
for_each_dive(idx, dive) {
|
||||
if (dive_has_gps_location(dive)) {
|
||||
GeoDataPlacemark *place = new GeoDataPlacemark(dive->location);
|
||||
place->setCoordinate(dive->longitude.udeg / 1000000.0,dive->latitude.udeg / 1000000.0 , 0, GeoDataCoordinates::Degree);
|
||||
place->setCoordinate(dive->longitude.udeg / 1000000.0, dive->latitude.udeg / 1000000.0, 0, GeoDataCoordinates::Degree);
|
||||
// don't add dive locations twice, unless they are at least 50m apart
|
||||
if (locationMap[QString(dive->location)]) {
|
||||
GeoDataCoordinates existingLocation = locationMap[QString(dive->location)]->coordinate();
|
||||
|
@ -200,7 +200,7 @@ void GlobeGPS::reload()
|
|||
repopulateLabels();
|
||||
}
|
||||
|
||||
void GlobeGPS::centerOn(dive* dive)
|
||||
void GlobeGPS::centerOn(dive *dive)
|
||||
{
|
||||
// dive has changed, if we had the 'editingDive', hide it.
|
||||
if (messageWidget->isVisible() && (!dive || dive_has_gps_location(dive)))
|
||||
|
@ -221,12 +221,12 @@ void GlobeGPS::centerOn(dive* dive)
|
|||
zoomView(zoomFromDistance(3));
|
||||
|
||||
if (!fixZoomTimer->isActive())
|
||||
currentZoomLevel = zoom();
|
||||
currentZoomLevel = zoom();
|
||||
// From the marble source code, the maximum time of
|
||||
// 'spin and fit' is 2 seconds, so wait a bit them zoom again.
|
||||
fixZoomTimer->start(2100);
|
||||
|
||||
centerOn(longitude,latitude, true);
|
||||
centerOn(longitude, latitude, true);
|
||||
}
|
||||
|
||||
void GlobeGPS::fixZoom()
|
||||
|
@ -260,7 +260,7 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U
|
|||
|
||||
/* change everything on the selection. */
|
||||
int i;
|
||||
struct dive* dive;
|
||||
struct dive *dive;
|
||||
for_each_dive(i, dive) {
|
||||
if (!dive->selected)
|
||||
continue;
|
||||
|
@ -273,7 +273,7 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U
|
|||
MainWindow::instance()->refreshDisplay();
|
||||
}
|
||||
|
||||
void GlobeGPS::mousePressEvent(QMouseEvent* event)
|
||||
void GlobeGPS::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
qreal lat, lon;
|
||||
bool clickOnGlobe = geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree);
|
||||
|
@ -287,9 +287,9 @@ void GlobeGPS::mousePressEvent(QMouseEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void GlobeGPS::resizeEvent(QResizeEvent* event)
|
||||
void GlobeGPS::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
int size = event->size().width();
|
||||
int size = event->size().width();
|
||||
MarbleWidget::resizeEvent(event);
|
||||
if (size > 600)
|
||||
messageWidget->setGeometry((size - 600) / 2, 5, 600, 0);
|
||||
|
|
|
@ -11,32 +11,34 @@ class KMessageWidget;
|
|||
using namespace Marble;
|
||||
struct dive;
|
||||
|
||||
class GlobeGPS : public MarbleWidget{
|
||||
class GlobeGPS : public MarbleWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using MarbleWidget::centerOn;
|
||||
GlobeGPS(QWidget *parent);
|
||||
void reload();
|
||||
void repopulateLabels();
|
||||
void centerOn(struct dive* dive);
|
||||
bool eventFilter(QObject*, QEvent*);
|
||||
void centerOn(struct dive *dive);
|
||||
bool eventFilter(QObject *, QEvent *);
|
||||
|
||||
protected:
|
||||
/* reimp */ void resizeEvent(QResizeEvent *event);
|
||||
/* reimp */ void mousePressEvent(QMouseEvent* event);
|
||||
/* reimp */ void contextMenuEvent(QContextMenuEvent*);
|
||||
/* reimp */ void mousePressEvent(QMouseEvent *event);
|
||||
/* reimp */ void contextMenuEvent(QContextMenuEvent *);
|
||||
|
||||
private:
|
||||
GeoDataDocument *loadedDives;
|
||||
KMessageWidget* messageWidget;
|
||||
KMessageWidget *messageWidget;
|
||||
QTimer *fixZoomTimer;
|
||||
int currentZoomLevel;
|
||||
bool editingDiveLocation;
|
||||
|
||||
public slots:
|
||||
void changeDiveGeoPosition(qreal lon,qreal lat,GeoDataCoordinates::Unit);
|
||||
public
|
||||
slots:
|
||||
void changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::Unit);
|
||||
void mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit);
|
||||
void fixZoom();
|
||||
void prepareForGetDiveCoordinates();
|
||||
|
||||
};
|
||||
|
||||
#endif // GLOBE_H
|
||||
|
|
|
@ -4,58 +4,58 @@ QMap<color_indice_t, QVector<QColor> > profile_color;
|
|||
|
||||
void fill_profile_color()
|
||||
{
|
||||
#define COLOR(x, y, z) QVector<QColor>() << x << y << z;
|
||||
profile_color[SAC_1] = COLOR(FUNGREEN1, BLACK1_LOW_TRANS, FUNGREEN1);
|
||||
profile_color[SAC_2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1);
|
||||
profile_color[SAC_3] = COLOR(ATLANTIS1, BLACK1_LOW_TRANS, ATLANTIS1);
|
||||
profile_color[SAC_4] = COLOR(ATLANTIS2, BLACK1_LOW_TRANS, ATLANTIS2);
|
||||
profile_color[SAC_5] = COLOR(EARLSGREEN1, BLACK1_LOW_TRANS, EARLSGREEN1);
|
||||
profile_color[SAC_6] = COLOR(HOKEYPOKEY1, BLACK1_LOW_TRANS, HOKEYPOKEY1);
|
||||
profile_color[SAC_7] = COLOR(TUSCANY1, BLACK1_LOW_TRANS, TUSCANY1);
|
||||
profile_color[SAC_8] = COLOR(CINNABAR1, BLACK1_LOW_TRANS, CINNABAR1);
|
||||
profile_color[SAC_9] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1);
|
||||
#define COLOR(x, y, z) QVector<QColor>() << x << y << z;
|
||||
profile_color[SAC_1] = COLOR(FUNGREEN1, BLACK1_LOW_TRANS, FUNGREEN1);
|
||||
profile_color[SAC_2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1);
|
||||
profile_color[SAC_3] = COLOR(ATLANTIS1, BLACK1_LOW_TRANS, ATLANTIS1);
|
||||
profile_color[SAC_4] = COLOR(ATLANTIS2, BLACK1_LOW_TRANS, ATLANTIS2);
|
||||
profile_color[SAC_5] = COLOR(EARLSGREEN1, BLACK1_LOW_TRANS, EARLSGREEN1);
|
||||
profile_color[SAC_6] = COLOR(HOKEYPOKEY1, BLACK1_LOW_TRANS, HOKEYPOKEY1);
|
||||
profile_color[SAC_7] = COLOR(TUSCANY1, BLACK1_LOW_TRANS, TUSCANY1);
|
||||
profile_color[SAC_8] = COLOR(CINNABAR1, BLACK1_LOW_TRANS, CINNABAR1);
|
||||
profile_color[SAC_9] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1);
|
||||
|
||||
profile_color[VELO_STABLE] = COLOR(CAMARONE1, BLACK1_LOW_TRANS, CAMARONE1);
|
||||
profile_color[VELO_SLOW] = COLOR(LIMENADE1, BLACK1_LOW_TRANS, LIMENADE1);
|
||||
profile_color[VELO_MODERATE] = COLOR(RIOGRANDE1, BLACK1_LOW_TRANS, RIOGRANDE1);
|
||||
profile_color[VELO_FAST] = COLOR(PIRATEGOLD1, BLACK1_LOW_TRANS, PIRATEGOLD1);
|
||||
profile_color[VELO_CRAZY] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
|
||||
profile_color[VELO_STABLE] = COLOR(CAMARONE1, BLACK1_LOW_TRANS, CAMARONE1);
|
||||
profile_color[VELO_SLOW] = COLOR(LIMENADE1, BLACK1_LOW_TRANS, LIMENADE1);
|
||||
profile_color[VELO_MODERATE] = COLOR(RIOGRANDE1, BLACK1_LOW_TRANS, RIOGRANDE1);
|
||||
profile_color[VELO_FAST] = COLOR(PIRATEGOLD1, BLACK1_LOW_TRANS, PIRATEGOLD1);
|
||||
profile_color[VELO_CRAZY] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
|
||||
|
||||
profile_color[PO2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1);
|
||||
profile_color[PO2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
|
||||
profile_color[PN2] = COLOR(BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS);
|
||||
profile_color[PN2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
|
||||
profile_color[PHE] = COLOR(PEANUT, BLACK1_LOW_TRANS, PEANUT);
|
||||
profile_color[PHE_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
|
||||
profile_color[PP_LINES] = COLOR(BLACK1_HIGH_TRANS, BLACK1_LOW_TRANS, BLACK1_HIGH_TRANS);
|
||||
profile_color[PO2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1);
|
||||
profile_color[PO2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
|
||||
profile_color[PN2] = COLOR(BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS);
|
||||
profile_color[PN2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
|
||||
profile_color[PHE] = COLOR(PEANUT, BLACK1_LOW_TRANS, PEANUT);
|
||||
profile_color[PHE_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
|
||||
profile_color[PP_LINES] = COLOR(BLACK1_HIGH_TRANS, BLACK1_LOW_TRANS, BLACK1_HIGH_TRANS);
|
||||
|
||||
profile_color[TEXT_BACKGROUND] = COLOR(CONCRETE1_LOWER_TRANS, WHITE1, CONCRETE1_LOWER_TRANS);
|
||||
profile_color[ALERT_BG] = COLOR(BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS, BROOM1_LOWER_TRANS);
|
||||
profile_color[ALERT_FG] = COLOR(BLACK1_LOW_TRANS, WHITE1, BLACK1_LOW_TRANS);
|
||||
profile_color[EVENTS] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1);
|
||||
profile_color[SAMPLE_DEEP] = COLOR(QColor(Qt::red).darker(), BLACK1, PERSIANRED1);
|
||||
profile_color[SAMPLE_SHALLOW] = COLOR(QColor(Qt::red).lighter(), BLACK1_LOW_TRANS, PERSIANRED1);
|
||||
profile_color[SMOOTHED] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_LOW_TRANS, REDORANGE1_HIGH_TRANS);
|
||||
profile_color[MINUTE] = COLOR(MEDIUMREDVIOLET1_HIGHER_TRANS, BLACK1_LOW_TRANS, MEDIUMREDVIOLET1_HIGHER_TRANS);
|
||||
profile_color[TIME_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS);
|
||||
profile_color[TIME_TEXT] = COLOR(FORESTGREEN1, BLACK1, FORESTGREEN1);
|
||||
profile_color[DEPTH_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS);
|
||||
profile_color[MEAN_DEPTH] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS);
|
||||
profile_color[HR_PLOT] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS);
|
||||
profile_color[HR_TEXT] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS);
|
||||
profile_color[DEPTH_BOTTOM] = COLOR(GOVERNORBAY1_MED_TRANS, BLACK1_HIGH_TRANS, GOVERNORBAY1_MED_TRANS);
|
||||
profile_color[DEPTH_TOP] = COLOR(MERCURY1_MED_TRANS, WHITE1_MED_TRANS, MERCURY1_MED_TRANS);
|
||||
profile_color[TEMP_TEXT] = COLOR(GOVERNORBAY2, BLACK1_LOW_TRANS, GOVERNORBAY2);
|
||||
profile_color[TEMP_PLOT] = COLOR(ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS, ROYALBLUE2_LOW_TRANS);
|
||||
profile_color[SAC_DEFAULT] = COLOR(WHITE1, BLACK1_LOW_TRANS, FORESTGREEN1);
|
||||
profile_color[BOUNDING_BOX] = COLOR(WHITE1, BLACK1_LOW_TRANS, TUNDORA1_MED_TRANS);
|
||||
profile_color[PRESSURE_TEXT] = COLOR(KILLARNEY1, BLACK1_LOW_TRANS, KILLARNEY1);
|
||||
profile_color[BACKGROUND] = COLOR(SPRINGWOOD1, WHITE1, SPRINGWOOD1);
|
||||
profile_color[ALERT_BG] = COLOR(BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS, BROOM1_LOWER_TRANS);
|
||||
profile_color[ALERT_FG] = COLOR(BLACK1_LOW_TRANS, WHITE1, BLACK1_LOW_TRANS);
|
||||
profile_color[EVENTS] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1);
|
||||
profile_color[SAMPLE_DEEP] = COLOR(QColor(Qt::red).darker(), BLACK1, PERSIANRED1);
|
||||
profile_color[SAMPLE_SHALLOW] = COLOR(QColor(Qt::red).lighter(), BLACK1_LOW_TRANS, PERSIANRED1);
|
||||
profile_color[SMOOTHED] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_LOW_TRANS, REDORANGE1_HIGH_TRANS);
|
||||
profile_color[MINUTE] = COLOR(MEDIUMREDVIOLET1_HIGHER_TRANS, BLACK1_LOW_TRANS, MEDIUMREDVIOLET1_HIGHER_TRANS);
|
||||
profile_color[TIME_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS);
|
||||
profile_color[TIME_TEXT] = COLOR(FORESTGREEN1, BLACK1, FORESTGREEN1);
|
||||
profile_color[DEPTH_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS);
|
||||
profile_color[MEAN_DEPTH] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS);
|
||||
profile_color[HR_PLOT] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS);
|
||||
profile_color[HR_TEXT] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS);
|
||||
profile_color[DEPTH_BOTTOM] = COLOR(GOVERNORBAY1_MED_TRANS, BLACK1_HIGH_TRANS, GOVERNORBAY1_MED_TRANS);
|
||||
profile_color[DEPTH_TOP] = COLOR(MERCURY1_MED_TRANS, WHITE1_MED_TRANS, MERCURY1_MED_TRANS);
|
||||
profile_color[TEMP_TEXT] = COLOR(GOVERNORBAY2, BLACK1_LOW_TRANS, GOVERNORBAY2);
|
||||
profile_color[TEMP_PLOT] = COLOR(ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS, ROYALBLUE2_LOW_TRANS);
|
||||
profile_color[SAC_DEFAULT] = COLOR(WHITE1, BLACK1_LOW_TRANS, FORESTGREEN1);
|
||||
profile_color[BOUNDING_BOX] = COLOR(WHITE1, BLACK1_LOW_TRANS, TUNDORA1_MED_TRANS);
|
||||
profile_color[PRESSURE_TEXT] = COLOR(KILLARNEY1, BLACK1_LOW_TRANS, KILLARNEY1);
|
||||
profile_color[BACKGROUND] = COLOR(SPRINGWOOD1, WHITE1, SPRINGWOOD1);
|
||||
profile_color[CEILING_SHALLOW] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_HIGH_TRANS, REDORANGE1_HIGH_TRANS);
|
||||
profile_color[CEILING_DEEP] = COLOR(RED1_MED_TRANS, BLACK1_HIGH_TRANS, RED1_MED_TRANS);
|
||||
profile_color[CEILING_DEEP] = COLOR(RED1_MED_TRANS, BLACK1_HIGH_TRANS, RED1_MED_TRANS);
|
||||
profile_color[CALC_CEILING_SHALLOW] = COLOR(FUNGREEN1_HIGH_TRANS, BLACK1_HIGH_TRANS, FUNGREEN1_HIGH_TRANS);
|
||||
profile_color[CALC_CEILING_DEEP] = COLOR(APPLE1_HIGH_TRANS, BLACK1_HIGH_TRANS, APPLE1_HIGH_TRANS);
|
||||
#undef COLOR
|
||||
profile_color[CALC_CEILING_DEEP] = COLOR(APPLE1_HIGH_TRANS, BLACK1_HIGH_TRANS, APPLE1_HIGH_TRANS);
|
||||
#undef COLOR
|
||||
}
|
||||
|
||||
QColor getColor(const color_indice_t i, bool isGrayscale = false)
|
||||
|
|
|
@ -13,23 +13,62 @@
|
|||
|
||||
typedef enum {
|
||||
/* SAC colors. Order is important, the SAC_COLORS_START_IDX define above. */
|
||||
SAC_1, SAC_2, SAC_3, SAC_4, SAC_5, SAC_6, SAC_7, SAC_8, SAC_9,
|
||||
SAC_1,
|
||||
SAC_2,
|
||||
SAC_3,
|
||||
SAC_4,
|
||||
SAC_5,
|
||||
SAC_6,
|
||||
SAC_7,
|
||||
SAC_8,
|
||||
SAC_9,
|
||||
|
||||
/* Velocity colors. Order is still important, ref VELOCITY_COLORS_START_IDX. */
|
||||
VELO_STABLE, VELO_SLOW, VELO_MODERATE, VELO_FAST, VELO_CRAZY,
|
||||
VELO_STABLE,
|
||||
VELO_SLOW,
|
||||
VELO_MODERATE,
|
||||
VELO_FAST,
|
||||
VELO_CRAZY,
|
||||
|
||||
/* gas colors */
|
||||
PO2, PO2_ALERT, PN2, PN2_ALERT, PHE, PHE_ALERT, PP_LINES,
|
||||
PO2,
|
||||
PO2_ALERT,
|
||||
PN2,
|
||||
PN2_ALERT,
|
||||
PHE,
|
||||
PHE_ALERT,
|
||||
PP_LINES,
|
||||
|
||||
/* Other colors */
|
||||
TEXT_BACKGROUND, ALERT_BG, ALERT_FG, EVENTS, SAMPLE_DEEP, SAMPLE_SHALLOW,
|
||||
SMOOTHED, MINUTE, TIME_GRID, TIME_TEXT, DEPTH_GRID, MEAN_DEPTH, HR_TEXT, HR_PLOT, DEPTH_TOP,
|
||||
DEPTH_BOTTOM, TEMP_TEXT, TEMP_PLOT, SAC_DEFAULT, BOUNDING_BOX, PRESSURE_TEXT, BACKGROUND,
|
||||
CEILING_SHALLOW, CEILING_DEEP, CALC_CEILING_SHALLOW, CALC_CEILING_DEEP
|
||||
TEXT_BACKGROUND,
|
||||
ALERT_BG,
|
||||
ALERT_FG,
|
||||
EVENTS,
|
||||
SAMPLE_DEEP,
|
||||
SAMPLE_SHALLOW,
|
||||
SMOOTHED,
|
||||
MINUTE,
|
||||
TIME_GRID,
|
||||
TIME_TEXT,
|
||||
DEPTH_GRID,
|
||||
MEAN_DEPTH,
|
||||
HR_TEXT,
|
||||
HR_PLOT,
|
||||
DEPTH_TOP,
|
||||
DEPTH_BOTTOM,
|
||||
TEMP_TEXT,
|
||||
TEMP_PLOT,
|
||||
SAC_DEFAULT,
|
||||
BOUNDING_BOX,
|
||||
PRESSURE_TEXT,
|
||||
BACKGROUND,
|
||||
CEILING_SHALLOW,
|
||||
CEILING_DEEP,
|
||||
CALC_CEILING_SHALLOW,
|
||||
CALC_CEILING_DEEP
|
||||
} color_indice_t;
|
||||
|
||||
|
||||
|
||||
/* profile_color[color indice] = COLOR(screen color, b/w printer color, color printer}} printer & screen colours could be different */
|
||||
|
||||
extern QMap<color_indice_t, QVector<QColor> > profile_color;
|
||||
|
|
|
@ -54,9 +54,8 @@ struct GroupedLineEdit::Private {
|
|||
QVector<QColor> colors;
|
||||
};
|
||||
|
||||
GroupedLineEdit::GroupedLineEdit(QWidget* parent)
|
||||
: QPlainTextEdit(parent),
|
||||
d(new Private)
|
||||
GroupedLineEdit::GroupedLineEdit(QWidget *parent) : QPlainTextEdit(parent),
|
||||
d(new Private)
|
||||
{
|
||||
setWordWrapMode(QTextOption::NoWrap);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
|
@ -90,7 +89,7 @@ void GroupedLineEdit::addBlock(int start, int end)
|
|||
|
||||
block.start = start;
|
||||
block.end = end;
|
||||
block.text = text().mid(start, end-start+1).trimmed();
|
||||
block.text = text().mid(start, end - start + 1).trimmed();
|
||||
d->blocks.append(block);
|
||||
viewport()->update();
|
||||
}
|
||||
|
@ -110,7 +109,7 @@ QStringList GroupedLineEdit::getBlockStringList()
|
|||
QStringList retList;
|
||||
Private::Block block;
|
||||
foreach(block, d->blocks)
|
||||
retList.append(block.text);
|
||||
retList.append(block.text);
|
||||
return retList;
|
||||
}
|
||||
|
||||
|
@ -150,11 +149,10 @@ void GroupedLineEdit::removeAllBlocks()
|
|||
QSize GroupedLineEdit::sizeHint() const
|
||||
{
|
||||
QSize rs(
|
||||
40,
|
||||
document()->findBlock(0).layout()->lineAt(0).height() +
|
||||
document()->documentMargin() * 2 +
|
||||
frameWidth() * 2
|
||||
);
|
||||
40,
|
||||
document()->findBlock(0).layout()->lineAt(0).height() +
|
||||
document()->documentMargin() * 2 +
|
||||
frameWidth() * 2);
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
@ -191,23 +189,22 @@ void GroupedLineEdit::paintEvent(QPaintEvent *e)
|
|||
|
||||
QVectorIterator<QColor> i(d->colors);
|
||||
i.toFront();
|
||||
foreach (const Private::Block &block, d->blocks) {
|
||||
foreach(const Private::Block & block, d->blocks) {
|
||||
qreal start_x = line.cursorToX(block.start, QTextLine::Trailing);
|
||||
qreal end_x = line.cursorToX(block.end + 1, QTextLine::Leading);
|
||||
QPainterPath path;
|
||||
QRectF rectangle(
|
||||
start_x - 1.0 - double(horizontalScrollBar()->value()),
|
||||
1.0,
|
||||
end_x - start_x + 2.0,
|
||||
double(viewport()->height() - 2)
|
||||
);
|
||||
if (! i.hasNext())
|
||||
start_x - 1.0 - double(horizontalScrollBar()->value()),
|
||||
1.0,
|
||||
end_x - start_x + 2.0,
|
||||
double(viewport()->height() - 2));
|
||||
if (!i.hasNext())
|
||||
i.toFront();
|
||||
path.addRoundedRect(rectangle, 5.0, 5.0);
|
||||
painter.setPen(i.peekNext());
|
||||
if (palette().color(QPalette::Text).lightnessF() <= 0.3 )
|
||||
if (palette().color(QPalette::Text).lightnessF() <= 0.3)
|
||||
painter.setBrush(i.next().lighter());
|
||||
else if (palette().color(QPalette::Text).lightnessF() <= 0.6 )
|
||||
else if (palette().color(QPalette::Text).lightnessF() <= 0.6)
|
||||
painter.setBrush(i.next());
|
||||
else
|
||||
painter.setBrush(i.next().darker());
|
||||
|
|
|
@ -33,8 +33,7 @@
|
|||
#include <QPlainTextEdit>
|
||||
#include <QStringList>
|
||||
|
||||
class GroupedLineEdit : public QPlainTextEdit
|
||||
{
|
||||
class GroupedLineEdit : public QPlainTextEdit {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -65,6 +64,7 @@ signals:
|
|||
protected:
|
||||
virtual void paintEvent(QPaintEvent *e);
|
||||
virtual void keyPressEvent(QKeyEvent *e);
|
||||
|
||||
private:
|
||||
struct Private;
|
||||
Private *d;
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <QStyle>
|
||||
#include <QAction>
|
||||
|
||||
void KMessageWidgetPrivate::init(KMessageWidget* q_ptr)
|
||||
void KMessageWidgetPrivate::init(KMessageWidget *q_ptr)
|
||||
{
|
||||
q = q_ptr;
|
||||
|
||||
|
@ -52,10 +52,10 @@ void KMessageWidgetPrivate::init(KMessageWidget* q_ptr)
|
|||
textLabel = new QLabel(content);
|
||||
textLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
textLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
QObject::connect(textLabel, SIGNAL(linkActivated(const QString&)), q, SIGNAL(linkActivated(const QString&)));
|
||||
QObject::connect(textLabel, SIGNAL(linkHovered(const QString&)), q, SIGNAL(linkHovered(const QString&)));
|
||||
QObject::connect(textLabel, SIGNAL(linkActivated(const QString &)), q, SIGNAL(linkActivated(const QString &)));
|
||||
QObject::connect(textLabel, SIGNAL(linkHovered(const QString &)), q, SIGNAL(linkHovered(const QString &)));
|
||||
|
||||
QAction* closeAction = new QAction(QObject::tr("Close"), q);
|
||||
QAction *closeAction = new QAction(QObject::tr("Close"), q);
|
||||
q->connect(closeAction, SIGNAL(triggered(bool)), q, SLOT(animatedHide()));
|
||||
|
||||
closeButton = new QToolButton(content);
|
||||
|
@ -74,8 +74,8 @@ void KMessageWidgetPrivate::createLayout()
|
|||
qDeleteAll(buttons);
|
||||
buttons.clear();
|
||||
|
||||
Q_FOREACH(QAction* action, q->actions()) {
|
||||
QToolButton* button = new QToolButton(content);
|
||||
Q_FOREACH(QAction * action, q->actions()) {
|
||||
QToolButton *button = new QToolButton(content);
|
||||
button->setDefaultAction(action);
|
||||
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
buttons.append(button);
|
||||
|
@ -87,14 +87,14 @@ void KMessageWidgetPrivate::createLayout()
|
|||
closeButton->setAutoRaise(buttons.isEmpty());
|
||||
|
||||
if (wordWrap) {
|
||||
QGridLayout* layout = new QGridLayout(content);
|
||||
QGridLayout *layout = new QGridLayout(content);
|
||||
// Set alignment to make sure icon does not move down if text wraps
|
||||
layout->addWidget(iconLabel, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
|
||||
layout->addWidget(textLabel, 0, 1);
|
||||
|
||||
QHBoxLayout* buttonLayout = new QHBoxLayout;
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
Q_FOREACH(QToolButton* button, buttons) {
|
||||
Q_FOREACH(QToolButton * button, buttons) {
|
||||
// For some reason, calling show() is necessary if wordwrap is true,
|
||||
// otherwise the buttons do not show up. It is not needed if
|
||||
// wordwrap is false.
|
||||
|
@ -104,11 +104,11 @@ void KMessageWidgetPrivate::createLayout()
|
|||
buttonLayout->addWidget(closeButton);
|
||||
layout->addItem(buttonLayout, 1, 0, 1, 2);
|
||||
} else {
|
||||
QHBoxLayout* layout = new QHBoxLayout(content);
|
||||
QHBoxLayout *layout = new QHBoxLayout(content);
|
||||
layout->addWidget(iconLabel);
|
||||
layout->addWidget(textLabel);
|
||||
|
||||
Q_FOREACH(QToolButton* button, buttons) {
|
||||
Q_FOREACH(QToolButton * button, buttons) {
|
||||
layout->addWidget(button);
|
||||
}
|
||||
|
||||
|
@ -174,16 +174,12 @@ int KMessageWidgetPrivate::bestContentHeight() const
|
|||
//---------------------------------------------------------------------
|
||||
// KMessageWidget
|
||||
//---------------------------------------------------------------------
|
||||
KMessageWidget::KMessageWidget(QWidget* parent)
|
||||
: QFrame(parent)
|
||||
, d(new KMessageWidgetPrivate)
|
||||
KMessageWidget::KMessageWidget(QWidget *parent) : QFrame(parent), d(new KMessageWidgetPrivate)
|
||||
{
|
||||
d->init(this);
|
||||
}
|
||||
|
||||
KMessageWidget::KMessageWidget(const QString& text, QWidget* parent)
|
||||
: QFrame(parent)
|
||||
, d(new KMessageWidgetPrivate)
|
||||
KMessageWidget::KMessageWidget(const QString &text, QWidget *parent) : QFrame(parent), d(new KMessageWidgetPrivate)
|
||||
{
|
||||
d->init(this);
|
||||
setText(text);
|
||||
|
@ -199,7 +195,7 @@ QString KMessageWidget::text() const
|
|||
return d->textLabel->text();
|
||||
}
|
||||
|
||||
void KMessageWidget::setText(const QString& text)
|
||||
void KMessageWidget::setText(const QString &text)
|
||||
{
|
||||
d->textLabel->setText(text);
|
||||
updateGeometry();
|
||||
|
@ -242,7 +238,7 @@ void KMessageWidget::setMessageType(KMessageWidget::MessageType type)
|
|||
bg2 = bg1.darker(110);
|
||||
border = bg2.darker(110);
|
||||
d->content->setStyleSheet(
|
||||
QString(".QFrame {"
|
||||
QString(".QFrame {"
|
||||
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
||||
" stop: 0 %1,"
|
||||
" stop: 0.1 %2,"
|
||||
|
@ -251,20 +247,17 @@ void KMessageWidget::setMessageType(KMessageWidget::MessageType type)
|
|||
"border: 1px solid %4;"
|
||||
"margin: %5px;"
|
||||
"}"
|
||||
".QLabel { color: %6; }"
|
||||
).arg(bg0.name())
|
||||
".QLabel { color: %6; }").arg(bg0.name())
|
||||
.arg(bg1.name())
|
||||
.arg(bg2.name())
|
||||
.arg(border.name())
|
||||
/*
|
||||
/*
|
||||
DefaultFrameWidth returns the size of the external margin + border width.
|
||||
We know our border is 1px, so we subtract this from the frame
|
||||
normal QStyle FrameWidth to get our margin
|
||||
*/
|
||||
|
||||
.arg(style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this) -1)
|
||||
.arg(fg.name())
|
||||
);
|
||||
.arg(style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this) - 1)
|
||||
.arg(fg.name()));
|
||||
}
|
||||
|
||||
QSize KMessageWidget::sizeHint() const
|
||||
|
@ -279,7 +272,7 @@ QSize KMessageWidget::minimumSizeHint() const
|
|||
return d->content->minimumSizeHint();
|
||||
}
|
||||
|
||||
bool KMessageWidget::event(QEvent* event)
|
||||
bool KMessageWidget::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::Polish && !d->content->layout()) {
|
||||
d->createLayout();
|
||||
|
@ -288,7 +281,7 @@ bool KMessageWidget::event(QEvent* event)
|
|||
return QFrame::event(event);
|
||||
}
|
||||
|
||||
void KMessageWidget::resizeEvent(QResizeEvent* event)
|
||||
void KMessageWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QFrame::resizeEvent(event);
|
||||
|
||||
|
@ -303,7 +296,7 @@ int KMessageWidget::heightForWidth(int width) const
|
|||
return d->content->heightForWidth(width);
|
||||
}
|
||||
|
||||
void KMessageWidget::paintEvent(QPaintEvent* event)
|
||||
void KMessageWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QFrame::paintEvent(event);
|
||||
|
||||
|
@ -314,7 +307,7 @@ void KMessageWidget::paintEvent(QPaintEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void KMessageWidget::showEvent(QShowEvent* event)
|
||||
void KMessageWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
// Keep this method here to avoid breaking binary compatibility:
|
||||
// QFrame::showEvent() used to be reimplemented.
|
||||
|
@ -354,13 +347,13 @@ void KMessageWidget::setCloseButtonVisible(bool show)
|
|||
updateGeometry();
|
||||
}
|
||||
|
||||
void KMessageWidget::addAction(QAction* action)
|
||||
void KMessageWidget::addAction(QAction *action)
|
||||
{
|
||||
QFrame::addAction(action);
|
||||
d->updateLayout();
|
||||
}
|
||||
|
||||
void KMessageWidget::removeAction(QAction* action)
|
||||
void KMessageWidget::removeAction(QAction *action)
|
||||
{
|
||||
QFrame::removeAction(action);
|
||||
d->updateLayout();
|
||||
|
@ -408,15 +401,14 @@ QIcon KMessageWidget::icon() const
|
|||
return d->icon;
|
||||
}
|
||||
|
||||
void KMessageWidget::setIcon(const QIcon& icon)
|
||||
void KMessageWidget::setIcon(const QIcon &icon)
|
||||
{
|
||||
d->icon = icon;
|
||||
|
||||
if (d->icon.isNull()) {
|
||||
d->iconLabel->hide();
|
||||
} else {
|
||||
d->iconLabel->setPixmap(d->icon.pixmap(QSize(16,16)));
|
||||
d->iconLabel->setPixmap(d->icon.pixmap(QSize(16, 16)));
|
||||
d->iconLabel->show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,118 +87,118 @@ class KMessageWidgetPrivate;
|
|||
* @author Aurélien Gâteau <agateau@kde.org>
|
||||
* @since 4.7
|
||||
*/
|
||||
class KMessageWidget : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(MessageType)
|
||||
class KMessageWidget : public QFrame {
|
||||
Q_OBJECT
|
||||
Q_ENUMS(MessageType)
|
||||
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
|
||||
Q_PROPERTY(bool closeButtonVisible READ isCloseButtonVisible WRITE setCloseButtonVisible)
|
||||
Q_PROPERTY(MessageType messageType READ messageType WRITE setMessageType)
|
||||
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
|
||||
Q_PROPERTY(bool closeButtonVisible READ isCloseButtonVisible WRITE setCloseButtonVisible)
|
||||
Q_PROPERTY(MessageType messageType READ messageType WRITE setMessageType)
|
||||
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
|
||||
public:
|
||||
enum MessageType {
|
||||
Positive,
|
||||
Information,
|
||||
Warning,
|
||||
Error
|
||||
};
|
||||
enum MessageType {
|
||||
Positive,
|
||||
Information,
|
||||
Warning,
|
||||
Error
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Constructs a KMessageWidget with the specified parent.
|
||||
*/
|
||||
explicit KMessageWidget(QWidget *parent = 0);
|
||||
explicit KMessageWidget(QWidget *parent = 0);
|
||||
|
||||
explicit KMessageWidget(const QString &text, QWidget *parent = 0);
|
||||
explicit KMessageWidget(const QString &text, QWidget *parent = 0);
|
||||
|
||||
~KMessageWidget();
|
||||
~KMessageWidget();
|
||||
|
||||
QString text() const;
|
||||
QString text() const;
|
||||
|
||||
bool wordWrap() const;
|
||||
bool wordWrap() const;
|
||||
|
||||
bool isCloseButtonVisible() const;
|
||||
bool isCloseButtonVisible() const;
|
||||
|
||||
MessageType messageType() const;
|
||||
MessageType messageType() const;
|
||||
|
||||
void addAction(QAction *action);
|
||||
void addAction(QAction *action);
|
||||
|
||||
void removeAction(QAction *action);
|
||||
void removeAction(QAction *action);
|
||||
|
||||
QSize sizeHint() const;
|
||||
QSize sizeHint() const;
|
||||
|
||||
QSize minimumSizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
int heightForWidth(int width) const;
|
||||
int heightForWidth(int width) const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* The icon shown on the left of the text. By default, no icon is shown.
|
||||
* @since 4.11
|
||||
*/
|
||||
QIcon icon() const;
|
||||
QIcon icon() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setText(const QString &text);
|
||||
public
|
||||
Q_SLOTS:
|
||||
void setText(const QString &text);
|
||||
|
||||
void setWordWrap(bool wordWrap);
|
||||
void setWordWrap(bool wordWrap);
|
||||
|
||||
void setCloseButtonVisible(bool visible);
|
||||
void setCloseButtonVisible(bool visible);
|
||||
|
||||
void setMessageType(KMessageWidget::MessageType type);
|
||||
void setMessageType(KMessageWidget::MessageType type);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Show the widget using an animation, unless
|
||||
* KGlobalSettings::graphicsEffectLevel() does not allow simple effects.
|
||||
*/
|
||||
void animatedShow();
|
||||
void animatedShow();
|
||||
|
||||
/**
|
||||
/**
|
||||
* Hide the widget using an animation, unless
|
||||
* KGlobalSettings::graphicsEffectLevel() does not allow simple effects.
|
||||
*/
|
||||
void animatedHide();
|
||||
void animatedHide();
|
||||
|
||||
/**
|
||||
/**
|
||||
* Define an icon to be shown on the left of the text
|
||||
* @since 4.11
|
||||
*/
|
||||
void setIcon(const QIcon &icon);
|
||||
void setIcon(const QIcon &icon);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
/**
|
||||
* This signal is emitted when the user clicks a link in the text label.
|
||||
* The URL referred to by the href anchor is passed in contents.
|
||||
* @param contents text of the href anchor
|
||||
* @see QLabel::linkActivated()
|
||||
* @since 4.10
|
||||
*/
|
||||
void linkActivated(const QString& contents);
|
||||
void linkActivated(const QString &contents);
|
||||
|
||||
/**
|
||||
/**
|
||||
* This signal is emitted when the user hovers over a link in the text label.
|
||||
* The URL referred to by the href anchor is passed in contents.
|
||||
* @param contents text of the href anchor
|
||||
* @see QLabel::linkHovered()
|
||||
* @since 4.11
|
||||
*/
|
||||
void linkHovered(const QString& contents);
|
||||
void linkHovered(const QString &contents);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
bool event(QEvent *event);
|
||||
bool event(QEvent *event);
|
||||
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
void showEvent(QShowEvent *event);
|
||||
void showEvent(QShowEvent *event);
|
||||
|
||||
private:
|
||||
KMessageWidgetPrivate *const d;
|
||||
friend class KMessageWidgetPrivate;
|
||||
KMessageWidgetPrivate *const d;
|
||||
friend class KMessageWidgetPrivate;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void slotTimeLineChanged(qreal))
|
||||
Q_PRIVATE_SLOT(d, void slotTimeLineFinished())
|
||||
Q_PRIVATE_SLOT(d, void slotTimeLineChanged(qreal))
|
||||
Q_PRIVATE_SLOT(d, void slotTimeLineFinished())
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
@ -209,22 +209,21 @@ class QToolButton;
|
|||
class QTimeLine;
|
||||
#include <QIcon>
|
||||
|
||||
class KMessageWidgetPrivate
|
||||
{
|
||||
class KMessageWidgetPrivate {
|
||||
public:
|
||||
void init(KMessageWidget*);
|
||||
void init(KMessageWidget *);
|
||||
|
||||
KMessageWidget* q;
|
||||
QFrame* content;
|
||||
QLabel* iconLabel;
|
||||
QLabel* textLabel;
|
||||
QToolButton* closeButton;
|
||||
QTimeLine* timeLine;
|
||||
KMessageWidget *q;
|
||||
QFrame *content;
|
||||
QLabel *iconLabel;
|
||||
QLabel *textLabel;
|
||||
QToolButton *closeButton;
|
||||
QTimeLine *timeLine;
|
||||
QIcon icon;
|
||||
|
||||
KMessageWidget::MessageType messageType;
|
||||
bool wordWrap;
|
||||
QList<QToolButton*> buttons;
|
||||
QList<QToolButton *> buttons;
|
||||
QPixmap contentSnapShot;
|
||||
|
||||
void createLayout();
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
#include <QScrollBar>
|
||||
|
||||
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
||||
weightModel(new WeightModel(this)),
|
||||
cylindersModel(CylindersModel::instance()),
|
||||
editMode(NONE)
|
||||
weightModel(new WeightModel(this)),
|
||||
cylindersModel(CylindersModel::instance()),
|
||||
editMode(NONE)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
|
@ -69,8 +69,8 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
|||
ui.tagWidget->installEventFilter(this);
|
||||
|
||||
QList<QObject *> statisticsTabWidgets = ui.statisticsTab->children();
|
||||
Q_FOREACH(QObject* obj, statisticsTabWidgets) {
|
||||
QLabel* label = qobject_cast<QLabel *>(obj);
|
||||
Q_FOREACH(QObject * obj, statisticsTabWidgets) {
|
||||
QLabel *label = qobject_cast<QLabel *>(obj);
|
||||
if (label)
|
||||
label->setAlignment(Qt::AlignHCenter);
|
||||
}
|
||||
|
@ -134,18 +134,17 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
|||
" background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
||||
" stop: 0 #E0E0E0, stop: 1 #FFFFFF);"
|
||||
"}");
|
||||
Q_FOREACH(QGroupBox *box, findChildren<QGroupBox*>()) {
|
||||
Q_FOREACH(QGroupBox * box, findChildren<QGroupBox *>()) {
|
||||
box->setStyleSheet(gnomeCss);
|
||||
}
|
||||
|
||||
}
|
||||
ui.cylinders->view()->horizontalHeader()->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup("cylinders_dialog");
|
||||
for(int i = 0; i < CylindersModel::COLUMNS; i++) {
|
||||
for (int i = 0; i < CylindersModel::COLUMNS; i++) {
|
||||
if ((i == CylindersModel::REMOVE) || (i == CylindersModel::TYPE))
|
||||
continue;
|
||||
continue;
|
||||
bool checked = s.value(QString("column%1_hidden").arg(i)).toBool();
|
||||
action = new QAction(cylindersModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(), ui.cylinders->view());
|
||||
action->setCheckable(true);
|
||||
|
@ -161,16 +160,16 @@ MainTab::~MainTab()
|
|||
{
|
||||
QSettings s;
|
||||
s.beginGroup("cylinders_dialog");
|
||||
for(int i = 0; i < CylindersModel::COLUMNS; i++) {
|
||||
for (int i = 0; i < CylindersModel::COLUMNS; i++) {
|
||||
if ((i == CylindersModel::REMOVE) || (i == CylindersModel::TYPE))
|
||||
continue;
|
||||
continue;
|
||||
s.setValue(QString("column%1_hidden").arg(i), ui.cylinders->view()->isColumnHidden(i));
|
||||
}
|
||||
}
|
||||
|
||||
void MainTab::toggleTriggeredColumn()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction*>(sender());
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
int col = action->data().toInt();
|
||||
QTableView *view = ui.cylinders->view();
|
||||
|
||||
|
@ -178,8 +177,7 @@ void MainTab::toggleTriggeredColumn()
|
|||
view->showColumn(col);
|
||||
if (view->columnWidth(col) <= 15)
|
||||
view->setColumnWidth(col, 80);
|
||||
}
|
||||
else
|
||||
} else
|
||||
view->hideColumn(col);
|
||||
}
|
||||
|
||||
|
@ -188,7 +186,7 @@ void MainTab::addDiveStarted()
|
|||
enableEdition(ADD);
|
||||
}
|
||||
|
||||
void MainTab::addMessageAction(QAction* action)
|
||||
void MainTab::addMessageAction(QAction *action)
|
||||
{
|
||||
ui.diveEquipmentMessage->addAction(action);
|
||||
ui.diveNotesMessage->addAction(action);
|
||||
|
@ -272,7 +270,7 @@ void MainTab::enableEdition(EditMode newEditMode)
|
|||
notesBackup[mydive].visibility = mydive->visibility;
|
||||
notesBackup[mydive].latitude = mydive->latitude;
|
||||
notesBackup[mydive].longitude = mydive->longitude;
|
||||
notesBackup[mydive].coordinates = ui.coordinates->text();
|
||||
notesBackup[mydive].coordinates = ui.coordinates->text();
|
||||
notesBackup[mydive].airtemp = get_temperature_string(mydive->airtemp, true);
|
||||
notesBackup[mydive].watertemp = get_temperature_string(mydive->watertemp, true);
|
||||
notesBackup[mydive].datetime = QDateTime::fromTime_t(mydive->when).toUTC().toString();
|
||||
|
@ -293,7 +291,7 @@ void MainTab::enableEdition(EditMode newEditMode)
|
|||
}
|
||||
}
|
||||
|
||||
bool MainTab::eventFilter(QObject* object, QEvent* event)
|
||||
bool MainTab::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
if (!isEnabled())
|
||||
return false;
|
||||
|
@ -349,17 +347,17 @@ void MainTab::clearStats()
|
|||
ui.timeLimits->clear();
|
||||
}
|
||||
|
||||
#define UPDATE_TEXT(d, field) \
|
||||
if (!d || !d->field) \
|
||||
ui.field->setText(""); \
|
||||
else \
|
||||
ui.field->setText(d->field)
|
||||
#define UPDATE_TEXT(d, field) \
|
||||
if (!d || !d->field) \
|
||||
ui.field->setText(""); \
|
||||
else \
|
||||
ui.field->setText(d->field)
|
||||
|
||||
#define UPDATE_TEMP(d, field) \
|
||||
if (!d || d->field.mkelvin == 0) \
|
||||
ui.field->setText(""); \
|
||||
else \
|
||||
ui.field->setText(get_temperature_string(d->field, true))
|
||||
#define UPDATE_TEMP(d, field) \
|
||||
if (!d || d->field.mkelvin == 0) \
|
||||
ui.field->setText(""); \
|
||||
else \
|
||||
ui.field->setText(get_temperature_string(d->field, true))
|
||||
|
||||
bool MainTab::isEditing()
|
||||
{
|
||||
|
@ -480,7 +478,7 @@ void MainTab::updateDiveInfo(int dive)
|
|||
} else {
|
||||
SACs = QString(tr("unknown"));
|
||||
}
|
||||
for(int i=1; i < MAX_CYLINDERS && gases[i].mliter != 0; i++) {
|
||||
for (int i = 1; i < MAX_CYLINDERS && gases[i].mliter != 0; i++) {
|
||||
volumes.append("\n" + get_volume_string(gases[i], true));
|
||||
if (duration[i]) {
|
||||
sac.mliter = gases[i].mliter / (depth_to_atm(mean[i], d) * duration[i] / 60);
|
||||
|
@ -507,7 +505,7 @@ void MainTab::updateDiveInfo(int dive)
|
|||
else
|
||||
ui.airPressureText->clear();
|
||||
if (d->salinity)
|
||||
ui.salinityText->setText(QString("%1g/l").arg(d->salinity/10.0));
|
||||
ui.salinityText->setText(QString("%1g/l").arg(d->salinity / 10.0));
|
||||
else
|
||||
ui.salinityText->clear();
|
||||
ui.depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, true));
|
||||
|
@ -542,7 +540,7 @@ void MainTab::updateDiveInfo(int dive)
|
|||
ui.coordinates->clear();
|
||||
ui.visibility->setCurrentStars(0);
|
||||
/* turns out this is non-trivial for a dateTimeEdit... this is a partial hack */
|
||||
QLineEdit *le = ui.dateTimeEdit->findChild<QLineEdit*>();
|
||||
QLineEdit *le = ui.dateTimeEdit->findChild<QLineEdit *>();
|
||||
le->setText("");
|
||||
}
|
||||
}
|
||||
|
@ -580,28 +578,28 @@ void MainTab::acceptChanges()
|
|||
/* now figure out if things have changed */
|
||||
if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
|
||||
if (notesBackup[NULL].notes != ui.notes->toPlainText() ||
|
||||
notesBackup[NULL].location != ui.location->text())
|
||||
notesBackup[NULL].location != ui.location->text())
|
||||
mark_divelist_changed(true);
|
||||
} else {
|
||||
struct dive *curr = current_dive;
|
||||
//Reset coordinates field, in case it contains garbage.
|
||||
updateGpsCoordinates(curr);
|
||||
if (notesBackup[curr].buddy != ui.buddy->text() ||
|
||||
notesBackup[curr].suit != ui.suit->text() ||
|
||||
notesBackup[curr].notes != ui.notes->toPlainText() ||
|
||||
notesBackup[curr].divemaster != ui.divemaster->text() ||
|
||||
notesBackup[curr].location != ui.location->text() ||
|
||||
notesBackup[curr].coordinates != ui.coordinates->text() ||
|
||||
notesBackup[curr].rating != ui.visibility->currentStars() ||
|
||||
notesBackup[curr].airtemp != ui.airtemp->text() ||
|
||||
notesBackup[curr].watertemp != ui.watertemp->text() ||
|
||||
notesBackup[curr].datetime != ui.dateTimeEdit->dateTime().toString() ||
|
||||
notesBackup[curr].visibility != ui.rating->currentStars() ||
|
||||
notesBackup[curr].tags != ui.tagWidget->text()) {
|
||||
notesBackup[curr].suit != ui.suit->text() ||
|
||||
notesBackup[curr].notes != ui.notes->toPlainText() ||
|
||||
notesBackup[curr].divemaster != ui.divemaster->text() ||
|
||||
notesBackup[curr].location != ui.location->text() ||
|
||||
notesBackup[curr].coordinates != ui.coordinates->text() ||
|
||||
notesBackup[curr].rating != ui.visibility->currentStars() ||
|
||||
notesBackup[curr].airtemp != ui.airtemp->text() ||
|
||||
notesBackup[curr].watertemp != ui.watertemp->text() ||
|
||||
notesBackup[curr].datetime != ui.dateTimeEdit->dateTime().toString() ||
|
||||
notesBackup[curr].visibility != ui.rating->currentStars() ||
|
||||
notesBackup[curr].tags != ui.tagWidget->text()) {
|
||||
mark_divelist_changed(true);
|
||||
}
|
||||
if (notesBackup[curr].location != ui.location->text() ||
|
||||
notesBackup[curr].coordinates != ui.coordinates->text()) {
|
||||
notesBackup[curr].coordinates != ui.coordinates->text()) {
|
||||
MainWindow::instance()->globe()->reload();
|
||||
}
|
||||
|
||||
|
@ -611,7 +609,7 @@ void MainTab::acceptChanges()
|
|||
DivePlannerPointsModel::instance()->copyCylinders(curr);
|
||||
} else if (editMode != ADD && cylindersModel->changed) {
|
||||
mark_divelist_changed(true);
|
||||
Q_FOREACH (dive *d, notesBackup.keys()) {
|
||||
Q_FOREACH(dive * d, notesBackup.keys()) {
|
||||
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
||||
if (notesBackup.keys().count() > 1)
|
||||
// only copy the cylinder type, none of the other values
|
||||
|
@ -624,13 +622,12 @@ void MainTab::acceptChanges()
|
|||
|
||||
if (weightModel->changed) {
|
||||
mark_divelist_changed(true);
|
||||
Q_FOREACH (dive *d, notesBackup.keys()) {
|
||||
Q_FOREACH(dive * d, notesBackup.keys()) {
|
||||
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
||||
d->weightsystem[i] = multiEditEquipmentPlaceholder.weightsystem[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (current_dive->divetrip) {
|
||||
current_dive->divetrip->when = current_dive->when;
|
||||
|
@ -650,7 +647,7 @@ void MainTab::acceptChanges()
|
|||
}
|
||||
// each dive that was selected might have had the temperatures in its active divecomputer changed
|
||||
// so re-populate the temperatures - easiest way to do this is by calling fixup_dive
|
||||
Q_FOREACH(dive *d, notesBackup.keys()) {
|
||||
Q_FOREACH(dive * d, notesBackup.keys()) {
|
||||
if (d)
|
||||
fixup_dive(d);
|
||||
}
|
||||
|
@ -658,13 +655,13 @@ void MainTab::acceptChanges()
|
|||
resetPallete();
|
||||
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
|
||||
MainWindow::instance()->dive_list()->unselectDives();
|
||||
struct dive *d = get_dive(dive_table.nr -1 );
|
||||
struct dive *d = get_dive(dive_table.nr - 1);
|
||||
// mark the dive as remembered (abusing the selected flag)
|
||||
// and then clear that flag out on the other side of the sort_table()
|
||||
d->selected = true;
|
||||
sort_table(&dive_table);
|
||||
int i = 0;
|
||||
for_each_dive(i,d) {
|
||||
for_each_dive(i, d) {
|
||||
if (d->selected) {
|
||||
d->selected = false;
|
||||
break;
|
||||
|
@ -672,7 +669,7 @@ void MainTab::acceptChanges()
|
|||
}
|
||||
editMode = NONE;
|
||||
MainWindow::instance()->refreshDisplay();
|
||||
MainWindow::instance()->dive_list()->selectDive( i, true );
|
||||
MainWindow::instance()->dive_list()->selectDive(i, true);
|
||||
} else {
|
||||
editMode = NONE;
|
||||
MainWindow::instance()->dive_list()->rememberSelection();
|
||||
|
@ -700,14 +697,14 @@ void MainTab::resetPallete()
|
|||
ui.tagWidget->setPalette(p);
|
||||
}
|
||||
|
||||
#define EDIT_TEXT2(what, text) \
|
||||
#define EDIT_TEXT2(what, text) \
|
||||
textByteArray = text.toUtf8(); \
|
||||
free(what);\
|
||||
free(what); \
|
||||
what = strdup(textByteArray.data());
|
||||
|
||||
#define EDIT_TEXT(what, text) \
|
||||
#define EDIT_TEXT(what, text) \
|
||||
QByteArray textByteArray = text.toUtf8(); \
|
||||
free(what);\
|
||||
free(what); \
|
||||
what = strdup(textByteArray.data());
|
||||
|
||||
void MainTab::rejectChanges()
|
||||
|
@ -718,19 +715,19 @@ void MainTab::rejectChanges()
|
|||
|
||||
MainWindow::instance()->dive_list()->setEnabled(true);
|
||||
if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
|
||||
ui.notes->setText(notesBackup[NULL].notes );
|
||||
ui.notes->setText(notesBackup[NULL].notes);
|
||||
ui.location->setText(notesBackup[NULL].location);
|
||||
} else {
|
||||
if (lastMode == ADD) {
|
||||
// clean up
|
||||
DivePlannerPointsModel::instance()->cancelPlan();
|
||||
} else if (lastMode == MANUALLY_ADDED_DIVE ) {
|
||||
} else if (lastMode == MANUALLY_ADDED_DIVE) {
|
||||
// when we tried to edit a manually added dive, we destroyed
|
||||
// the dive we edited, so let's just restore it from backup
|
||||
DivePlannerPointsModel::instance()->restoreBackupDive();
|
||||
}
|
||||
struct dive *curr = current_dive;
|
||||
ui.notes->setText(notesBackup[curr].notes );
|
||||
ui.notes->setText(notesBackup[curr].notes);
|
||||
ui.location->setText(notesBackup[curr].location);
|
||||
ui.buddy->setText(notesBackup[curr].buddy);
|
||||
ui.suit->setText(notesBackup[curr].suit);
|
||||
|
@ -744,7 +741,7 @@ void MainTab::rejectChanges()
|
|||
if (curr) {
|
||||
ui.dateTimeEdit->setDateTime(QDateTime::fromString(notesBackup[curr].datetime));
|
||||
} else {
|
||||
QLineEdit *le = ui.dateTimeEdit->findChild<QLineEdit*>();
|
||||
QLineEdit *le = ui.dateTimeEdit->findChild<QLineEdit *>();
|
||||
le->setText("");
|
||||
}
|
||||
|
||||
|
@ -810,74 +807,72 @@ void MainTab::rejectChanges()
|
|||
}
|
||||
#undef EDIT_TEXT2
|
||||
|
||||
#define EDIT_SELECTED_DIVES( WHAT ) do { \
|
||||
if (editMode == NONE) \
|
||||
return; \
|
||||
\
|
||||
for (int _i = 0; _i < dive_table.nr; _i++) { \
|
||||
struct dive *mydive = get_dive(_i); \
|
||||
if (!mydive) \
|
||||
continue; \
|
||||
if (!mydive->selected) \
|
||||
continue; \
|
||||
\
|
||||
WHAT; \
|
||||
} \
|
||||
} while(0)
|
||||
#define EDIT_SELECTED_DIVES(WHAT) \
|
||||
do { \
|
||||
if (editMode == NONE) \
|
||||
return; \
|
||||
\
|
||||
for (int _i = 0; _i < dive_table.nr; _i++) { \
|
||||
struct dive *mydive = get_dive(_i); \
|
||||
if (!mydive) \
|
||||
continue; \
|
||||
if (!mydive->selected) \
|
||||
continue; \
|
||||
\
|
||||
WHAT; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void markChangedWidget(QWidget *w) {
|
||||
void markChangedWidget(QWidget *w)
|
||||
{
|
||||
QPalette p;
|
||||
qreal h, s, l, a;
|
||||
qApp->palette().color(QPalette::Text).getHslF(&h, &s, &l, &a);
|
||||
p.setBrush(QPalette::Base, ( l <= 0.3 ) ? QColor(Qt::yellow).lighter()
|
||||
:( l <= 0.6 ) ? QColor(Qt::yellow).light()
|
||||
:/* else */ QColor(Qt::yellow).darker(300)
|
||||
);
|
||||
p.setBrush(QPalette::Base, (l <= 0.3) ? QColor(Qt::yellow).lighter() : (l <= 0.6) ? QColor(Qt::yellow).light() : /* else */ QColor(Qt::yellow).darker(300));
|
||||
w->setPalette(p);
|
||||
}
|
||||
|
||||
void MainTab::on_buddy_textChanged()
|
||||
{
|
||||
QString text = ui.buddy->toPlainText().split(",", QString::SkipEmptyParts).join(", ");
|
||||
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->buddy, text) );
|
||||
EDIT_SELECTED_DIVES(EDIT_TEXT(mydive->buddy, text));
|
||||
markChangedWidget(ui.buddy);
|
||||
}
|
||||
|
||||
void MainTab::on_divemaster_textChanged()
|
||||
{
|
||||
QString text = ui.divemaster->toPlainText().split(",", QString::SkipEmptyParts).join(", ");
|
||||
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->divemaster, text) );
|
||||
EDIT_SELECTED_DIVES(EDIT_TEXT(mydive->divemaster, text));
|
||||
markChangedWidget(ui.divemaster);
|
||||
}
|
||||
|
||||
void MainTab::on_airtemp_textChanged(const QString& text)
|
||||
void MainTab::on_airtemp_textChanged(const QString &text)
|
||||
{
|
||||
EDIT_SELECTED_DIVES( select_dc(&mydive->dc)->airtemp.mkelvin = parseTemperatureToMkelvin(text) );
|
||||
EDIT_SELECTED_DIVES(select_dc(&mydive->dc)->airtemp.mkelvin = parseTemperatureToMkelvin(text));
|
||||
markChangedWidget(ui.airtemp);
|
||||
}
|
||||
|
||||
void MainTab::on_watertemp_textChanged(const QString& text)
|
||||
void MainTab::on_watertemp_textChanged(const QString &text)
|
||||
{
|
||||
EDIT_SELECTED_DIVES( select_dc(&mydive->dc)->watertemp.mkelvin = parseTemperatureToMkelvin(text) );
|
||||
EDIT_SELECTED_DIVES(select_dc(&mydive->dc)->watertemp.mkelvin = parseTemperatureToMkelvin(text));
|
||||
markChangedWidget(ui.watertemp);
|
||||
}
|
||||
|
||||
void MainTab::on_dateTimeEdit_dateTimeChanged(const QDateTime& datetime)
|
||||
void MainTab::on_dateTimeEdit_dateTimeChanged(const QDateTime &datetime)
|
||||
{
|
||||
QDateTime dateTimeUtc(datetime);
|
||||
dateTimeUtc.setTimeSpec(Qt::UTC);
|
||||
EDIT_SELECTED_DIVES( mydive->when = dateTimeUtc.toTime_t() );
|
||||
EDIT_SELECTED_DIVES(mydive->when = dateTimeUtc.toTime_t());
|
||||
markChangedWidget(ui.dateTimeEdit);
|
||||
}
|
||||
|
||||
void MainTab::saveTags()
|
||||
{
|
||||
EDIT_SELECTED_DIVES(
|
||||
QString tag;
|
||||
taglist_clear(mydive->tag_list);
|
||||
foreach (tag, ui.tagWidget->getBlockStringList())
|
||||
taglist_add_tag(mydive->tag_list, tag.toUtf8().data());
|
||||
);
|
||||
QString tag;
|
||||
taglist_clear(mydive->tag_list);
|
||||
foreach(tag, ui.tagWidget->getBlockStringList())
|
||||
taglist_add_tag(mydive->tag_list, tag.toUtf8().data()););
|
||||
}
|
||||
|
||||
void MainTab::on_tagWidget_textChanged()
|
||||
|
@ -885,7 +880,7 @@ void MainTab::on_tagWidget_textChanged()
|
|||
markChangedWidget(ui.tagWidget);
|
||||
}
|
||||
|
||||
void MainTab::on_location_textChanged(const QString& text)
|
||||
void MainTab::on_location_textChanged(const QString &text)
|
||||
{
|
||||
if (editMode == NONE)
|
||||
return;
|
||||
|
@ -896,14 +891,14 @@ void MainTab::on_location_textChanged(const QString& text)
|
|||
} else if (editMode == DIVE || editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
|
||||
if (!ui.coordinates->isModified() ||
|
||||
ui.coordinates->text().trimmed().isEmpty()) {
|
||||
struct dive* dive;
|
||||
struct dive *dive;
|
||||
int i = 0;
|
||||
for_each_dive(i, dive) {
|
||||
QString location(dive->location);
|
||||
if (location == text &&
|
||||
(dive->latitude.udeg || dive->longitude.udeg)) {
|
||||
EDIT_SELECTED_DIVES( mydive->latitude = dive->latitude );
|
||||
EDIT_SELECTED_DIVES( mydive->longitude = dive->longitude );
|
||||
EDIT_SELECTED_DIVES(mydive->latitude = dive->latitude);
|
||||
EDIT_SELECTED_DIVES(mydive->longitude = dive->longitude);
|
||||
//Don't use updateGpsCoordinates() since we don't want to set modified state yet
|
||||
ui.coordinates->setText(printGPSCoords(dive->latitude.udeg, dive->longitude.udeg));
|
||||
markChangedWidget(ui.coordinates);
|
||||
|
@ -911,15 +906,15 @@ void MainTab::on_location_textChanged(const QString& text)
|
|||
}
|
||||
}
|
||||
}
|
||||
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) );
|
||||
EDIT_SELECTED_DIVES(EDIT_TEXT(mydive->location, text));
|
||||
MainWindow::instance()->globe()->repopulateLabels();
|
||||
}
|
||||
markChangedWidget(ui.location);
|
||||
}
|
||||
|
||||
void MainTab::on_suit_textChanged(const QString& text)
|
||||
void MainTab::on_suit_textChanged(const QString &text)
|
||||
{
|
||||
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->suit, text) );
|
||||
EDIT_SELECTED_DIVES(EDIT_TEXT(mydive->suit, text));
|
||||
markChangedWidget(ui.suit);
|
||||
}
|
||||
|
||||
|
@ -932,14 +927,14 @@ void MainTab::on_notes_textChanged()
|
|||
dive_trip_t *currentTrip = *MainWindow::instance()->dive_list()->selectedTrips().begin();
|
||||
EDIT_TEXT(currentTrip->notes, ui.notes->toPlainText());
|
||||
} else if (editMode == DIVE || editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
|
||||
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui.notes->toPlainText()) );
|
||||
EDIT_SELECTED_DIVES(EDIT_TEXT(mydive->notes, ui.notes->toPlainText()));
|
||||
}
|
||||
markChangedWidget(ui.notes);
|
||||
}
|
||||
|
||||
#undef EDIT_TEXT
|
||||
|
||||
void MainTab::on_coordinates_textChanged(const QString& text)
|
||||
void MainTab::on_coordinates_textChanged(const QString &text)
|
||||
{
|
||||
bool gpsChanged = false;
|
||||
bool parsed = false;
|
||||
|
@ -955,15 +950,15 @@ void MainTab::on_coordinates_textChanged(const QString& text)
|
|||
|
||||
void MainTab::on_rating_valueChanged(int value)
|
||||
{
|
||||
EDIT_SELECTED_DIVES(mydive->rating = value );
|
||||
EDIT_SELECTED_DIVES(mydive->rating = value);
|
||||
}
|
||||
|
||||
void MainTab::on_visibility_valueChanged(int value)
|
||||
{
|
||||
EDIT_SELECTED_DIVES( mydive->visibility = value );
|
||||
EDIT_SELECTED_DIVES(mydive->visibility = value);
|
||||
}
|
||||
|
||||
void MainTab::editCylinderWidget(const QModelIndex& index)
|
||||
void MainTab::editCylinderWidget(const QModelIndex &index)
|
||||
{
|
||||
if (editMode == NONE)
|
||||
enableEdition();
|
||||
|
@ -972,7 +967,7 @@ void MainTab::editCylinderWidget(const QModelIndex& index)
|
|||
ui.cylinders->edit(index);
|
||||
}
|
||||
|
||||
void MainTab::editWeightWidget(const QModelIndex& index)
|
||||
void MainTab::editWeightWidget(const QModelIndex &index)
|
||||
{
|
||||
if (editMode == NONE)
|
||||
enableEdition();
|
||||
|
@ -985,7 +980,7 @@ QString MainTab::printGPSCoords(int lat, int lon)
|
|||
{
|
||||
unsigned int latdeg, londeg;
|
||||
unsigned int latmin, lonmin;
|
||||
double latsec, lonsec;
|
||||
double latsec, lonsec;
|
||||
QString lath, lonh, result;
|
||||
|
||||
if (!lat && !lon)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
class QCompleter;
|
||||
struct dive;
|
||||
|
||||
struct NotesBackup{
|
||||
struct NotesBackup {
|
||||
QString airtemp;
|
||||
QString watertemp;
|
||||
QString datetime;
|
||||
|
@ -34,10 +34,10 @@ struct NotesBackup{
|
|||
QString divemaster;
|
||||
QString tags;
|
||||
cylinder_t cylinders[MAX_CYLINDERS];
|
||||
weightsystem_t weightsystem[MAX_WEIGHTSYSTEMS ];
|
||||
weightsystem_t weightsystem[MAX_WEIGHTSYSTEMS];
|
||||
};
|
||||
|
||||
struct Completers{
|
||||
struct Completers {
|
||||
QCompleter *location;
|
||||
QCompleter *divemaster;
|
||||
QCompleter *buddy;
|
||||
|
@ -45,11 +45,16 @@ struct Completers{
|
|||
QCompleter *tags;
|
||||
};
|
||||
|
||||
class MainTab : public QTabWidget
|
||||
{
|
||||
class MainTab : public QTabWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum EditMode { NONE, DIVE, TRIP, ADD, MANUALLY_ADDED_DIVE };
|
||||
enum EditMode {
|
||||
NONE,
|
||||
DIVE,
|
||||
TRIP,
|
||||
ADD,
|
||||
MANUALLY_ADDED_DIVE
|
||||
};
|
||||
|
||||
MainTab(QWidget *parent);
|
||||
~MainTab();
|
||||
|
@ -57,42 +62,44 @@ public:
|
|||
void clearInfo();
|
||||
void clearEquipment();
|
||||
void reload();
|
||||
bool eventFilter(QObject* , QEvent*);
|
||||
bool eventFilter(QObject *, QEvent *);
|
||||
void initialUiSetup();
|
||||
bool isEditing();
|
||||
void updateCoordinatesText(qreal lat, qreal lon);
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void addCylinder_clicked();
|
||||
void addWeight_clicked();
|
||||
void updateDiveInfo(int dive = selected_dive);
|
||||
void acceptChanges();
|
||||
void rejectChanges();
|
||||
void on_location_textChanged(const QString& text);
|
||||
void on_coordinates_textChanged(const QString& text);
|
||||
void on_location_textChanged(const QString &text);
|
||||
void on_coordinates_textChanged(const QString &text);
|
||||
void on_divemaster_textChanged();
|
||||
void on_buddy_textChanged();
|
||||
void on_suit_textChanged(const QString& text);
|
||||
void on_suit_textChanged(const QString &text);
|
||||
void on_notes_textChanged();
|
||||
void on_airtemp_textChanged(const QString& text);
|
||||
void on_watertemp_textChanged(const QString& text);
|
||||
void on_dateTimeEdit_dateTimeChanged(const QDateTime& datetime);
|
||||
void on_airtemp_textChanged(const QString &text);
|
||||
void on_watertemp_textChanged(const QString &text);
|
||||
void on_dateTimeEdit_dateTimeChanged(const QDateTime &datetime);
|
||||
void on_rating_valueChanged(int value);
|
||||
void on_visibility_valueChanged(int value);
|
||||
void on_tagWidget_textChanged();
|
||||
void editCylinderWidget(const QModelIndex& index);
|
||||
void editWeightWidget(const QModelIndex& index);
|
||||
void editCylinderWidget(const QModelIndex &index);
|
||||
void editWeightWidget(const QModelIndex &index);
|
||||
void addDiveStarted();
|
||||
void addMessageAction(QAction* action);
|
||||
void addMessageAction(QAction *action);
|
||||
void hideMessage();
|
||||
void closeMessage();
|
||||
void displayMessage(QString str);
|
||||
void enableEdition(EditMode newEditMode = NONE);
|
||||
void toggleTriggeredColumn();
|
||||
|
||||
private:
|
||||
Ui::MainTab ui;
|
||||
WeightModel *weightModel;
|
||||
CylindersModel *cylindersModel;
|
||||
QMap<dive*, NotesBackup> notesBackup;
|
||||
QMap<dive *, NotesBackup> notesBackup;
|
||||
EditMode editMode;
|
||||
|
||||
BuddyCompletionModel buddyModel;
|
||||
|
|
|
@ -29,16 +29,33 @@ class MainTab;
|
|||
class ProfileGraphicsView;
|
||||
class QWebView;
|
||||
|
||||
enum MainWindowTitleFormat { MWTF_DEFAULT, MWTF_FILENAME };
|
||||
enum MainWindowTitleFormat {
|
||||
MWTF_DEFAULT,
|
||||
MWTF_FILENAME
|
||||
};
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum {COLLAPSED, EXPANDED};
|
||||
enum StackWidgetIndexes{ PROFILE, PLANNERPROFILE};
|
||||
enum InfoWidgetIndexes{ MAINTAB, PLANNERWIDGET};
|
||||
enum CurrentState{ VIEWALL, GLOBE_MAXIMIZED, INFO_MAXIMIZED, PROFILE_MAXIMIZED, LIST_MAXIMIZED};
|
||||
enum {
|
||||
COLLAPSED,
|
||||
EXPANDED
|
||||
};
|
||||
enum StackWidgetIndexes {
|
||||
PROFILE,
|
||||
PLANNERPROFILE
|
||||
};
|
||||
enum InfoWidgetIndexes {
|
||||
MAINTAB,
|
||||
PLANNERWIDGET
|
||||
};
|
||||
enum CurrentState {
|
||||
VIEWALL,
|
||||
GLOBE_MAXIMIZED,
|
||||
INFO_MAXIMIZED,
|
||||
PROFILE_MAXIMIZED,
|
||||
LIST_MAXIMIZED
|
||||
};
|
||||
|
||||
MainWindow();
|
||||
virtual ~MainWindow();
|
||||
|
@ -60,7 +77,8 @@ public:
|
|||
void importFiles(const QStringList importFiles);
|
||||
void cleanUpEmpty();
|
||||
QTabWidget *tabWidget();
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
/* file menu action */
|
||||
void recentFileTriggered(bool checked);
|
||||
void on_actionNew_triggered();
|
||||
|
@ -127,7 +145,8 @@ private slots:
|
|||
protected:
|
||||
void closeEvent(QCloseEvent *);
|
||||
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void readSettings();
|
||||
void refreshDisplay(bool recreateDiveList = true);
|
||||
void showProfile();
|
||||
|
@ -149,7 +168,7 @@ private:
|
|||
void beginChangeState(CurrentState s);
|
||||
void saveSplitterSizes();
|
||||
QString lastUsedDir();
|
||||
void updateLastUsedDir(const QString& s);
|
||||
void updateLastUsedDir(const QString &s);
|
||||
};
|
||||
|
||||
MainWindow *mainWindow();
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
#include <QAbstractItemView>
|
||||
#include <QApplication>
|
||||
|
||||
QSize DiveListDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
QSize DiveListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return QSize(50,22);
|
||||
return QSize(50, 22);
|
||||
}
|
||||
|
||||
// Gets the index of the model in the currentRow and column.
|
||||
|
@ -28,14 +28,12 @@ QSize DiveListDelegate::sizeHint(const QStyleOptionViewItem& option, const QMode
|
|||
#define IDX(_XX) mymodel->index(currCombo.currRow, (_XX))
|
||||
static bool keyboardFinished = false;
|
||||
|
||||
StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent):
|
||||
QStyledItemDelegate(parent),
|
||||
StarWidgetsDelegate::StarWidgetsDelegate(QWidget *parent) : QStyledItemDelegate(parent),
|
||||
parentWidget(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
void StarWidgetsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
if (!index.isValid())
|
||||
|
@ -46,7 +44,7 @@ void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
|
|||
return;
|
||||
|
||||
int rating = value.toInt();
|
||||
int deltaY = option.rect.height() / 2 - StarWidget::starActive().height() / 2 ;
|
||||
int deltaY = option.rect.height() / 2 - StarWidget::starActive().height() / 2;
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
for (int i = 0; i < rating; i++)
|
||||
|
@ -56,20 +54,20 @@ void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
|
|||
painter->restore();
|
||||
}
|
||||
|
||||
QSize StarWidgetsDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
QSize StarWidgetsDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return QSize(IMG_SIZE * TOTALSTARS + SPACING * (TOTALSTARS-1), IMG_SIZE);
|
||||
return QSize(IMG_SIZE * TOTALSTARS + SPACING * (TOTALSTARS - 1), IMG_SIZE);
|
||||
}
|
||||
|
||||
ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject* parent): QStyledItemDelegate(parent), model(model)
|
||||
ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject *parent) : QStyledItemDelegate(parent), model(model)
|
||||
{
|
||||
connect(this, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)),
|
||||
this, SLOT(revertModelData(QWidget*, QAbstractItemDelegate::EndEditHint)));
|
||||
connect(this, SIGNAL(closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint)),
|
||||
this, SLOT(revertModelData(QWidget *, QAbstractItemDelegate::EndEditHint)));
|
||||
}
|
||||
|
||||
void ComboBoxDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
||||
void ComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
QComboBox *c = qobject_cast<QComboBox*>(editor);
|
||||
QComboBox *c = qobject_cast<QComboBox *>(editor);
|
||||
QString data = index.model()->data(index, Qt::DisplayRole).toString();
|
||||
int i = c->findText(data);
|
||||
if (i != -1)
|
||||
|
@ -86,7 +84,7 @@ struct CurrSelected {
|
|||
bool ignoreSelection;
|
||||
} currCombo;
|
||||
|
||||
QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QComboBox *comboDelegate = new QComboBox(parent);
|
||||
comboDelegate->setModel(model);
|
||||
|
@ -95,14 +93,14 @@ QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewI
|
|||
comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
|
||||
comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion);
|
||||
comboDelegate->view()->setEditTriggers(QAbstractItemView::AllEditTriggers);
|
||||
comboDelegate->lineEdit()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this)));
|
||||
comboDelegate->view()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this)));
|
||||
comboDelegate->lineEdit()->installEventFilter(const_cast<QObject *>(qobject_cast<const QObject *>(this)));
|
||||
comboDelegate->view()->installEventFilter(const_cast<QObject *>(qobject_cast<const QObject *>(this)));
|
||||
connect(comboDelegate, SIGNAL(highlighted(QString)), this, SLOT(testActivation(QString)));
|
||||
connect(comboDelegate, SIGNAL(activated(QString)), this, SLOT(fakeActivation()));
|
||||
connect(this, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), this, SLOT(fixTabBehavior()));
|
||||
connect(this, SIGNAL(closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint)), this, SLOT(fixTabBehavior()));
|
||||
currCombo.comboEditor = comboDelegate;
|
||||
currCombo.currRow = index.row();
|
||||
currCombo.model = const_cast<QAbstractItemModel*>(index.model());
|
||||
currCombo.model = const_cast<QAbstractItemModel *>(index.model());
|
||||
keyboardFinished = false;
|
||||
|
||||
// Current display of things on Gnome3 looks like shit, so
|
||||
|
@ -122,14 +120,15 @@ QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewI
|
|||
* One thing is important, if the user writes a *new* cylinder or weight type, it will
|
||||
* be ADDED to the list, and the user will need to fill the other data.
|
||||
*/
|
||||
void ComboBoxDelegate::testActivation(const QString& currText)
|
||||
void ComboBoxDelegate::testActivation(const QString &currText)
|
||||
{
|
||||
currCombo.activeText = currText.isEmpty() ? currCombo.comboEditor->currentText() : currText;
|
||||
setModelData(currCombo.comboEditor, currCombo.model, QModelIndex());
|
||||
}
|
||||
|
||||
// HACK, send a fake event so Qt thinks we hit 'enter' on the line edit.
|
||||
void ComboBoxDelegate::fakeActivation() {
|
||||
void ComboBoxDelegate::fakeActivation()
|
||||
{
|
||||
/* this test is needed because as soon as I show the selector,
|
||||
* the first item gots selected, this sending an activated signal,
|
||||
* calling this fakeActivation code and setting as the current,
|
||||
|
@ -151,28 +150,28 @@ void ComboBoxDelegate::fakeActivation() {
|
|||
void ComboBoxDelegate::fixTabBehavior()
|
||||
{
|
||||
if (keyboardFinished) {
|
||||
setModelData(0,0,QModelIndex());
|
||||
setModelData(0, 0, QModelIndex());
|
||||
}
|
||||
}
|
||||
|
||||
bool ComboBoxDelegate::eventFilter(QObject* object, QEvent* event)
|
||||
bool ComboBoxDelegate::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
// Reacts on Key_UP and Key_DOWN to show the QComboBox - list of choices.
|
||||
if (event->type() == QEvent::KeyPress || event->type() == QEvent::ShortcutOverride) {
|
||||
if (object == currCombo.comboEditor) { // the 'LineEdit' part
|
||||
QKeyEvent *ev = static_cast<QKeyEvent*>(event);
|
||||
QKeyEvent *ev = static_cast<QKeyEvent *>(event);
|
||||
if (ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down) {
|
||||
currCombo.ignoreSelection = true;
|
||||
currCombo.comboEditor->showPopup();
|
||||
}
|
||||
if (ev->key() == Qt::Key_Tab || ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return) {
|
||||
currCombo.activeText = currCombo.comboEditor->currentText();
|
||||
currCombo.activeText = currCombo.comboEditor->currentText();
|
||||
keyboardFinished = true;
|
||||
}
|
||||
} else { // the 'Drop Down Menu' part.
|
||||
QKeyEvent *ev = static_cast<QKeyEvent*>(event);
|
||||
} else { // the 'Drop Down Menu' part.
|
||||
QKeyEvent *ev = static_cast<QKeyEvent *>(event);
|
||||
if (ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return ||
|
||||
ev->key() == Qt::Key_Tab || ev->key() == Qt::Key_Backtab ||
|
||||
ev->key() == Qt::Key_Tab || ev->key() == Qt::Key_Backtab ||
|
||||
ev->key() == Qt::Key_Escape) {
|
||||
// treat Qt as a silly little boy - pretending that the key_return nwas pressed on the combo,
|
||||
// instead of the list of choices. this can be extended later for
|
||||
|
@ -185,13 +184,13 @@ bool ComboBoxDelegate::eventFilter(QObject* object, QEvent* event)
|
|||
return QStyledItemDelegate::eventFilter(object, event);
|
||||
}
|
||||
|
||||
void ComboBoxDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
void ComboBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QRect defaultRect = option.rect;
|
||||
defaultRect.setX( defaultRect.x() -1);
|
||||
defaultRect.setY( defaultRect.y() -1);
|
||||
defaultRect.setWidth( defaultRect.width() + 2);
|
||||
defaultRect.setHeight( defaultRect.height() + 2);
|
||||
defaultRect.setX(defaultRect.x() - 1);
|
||||
defaultRect.setY(defaultRect.y() - 1);
|
||||
defaultRect.setWidth(defaultRect.width() + 2);
|
||||
defaultRect.setHeight(defaultRect.height() + 2);
|
||||
editor->setGeometry(defaultRect);
|
||||
}
|
||||
|
||||
|
@ -201,16 +200,16 @@ struct RevertCylinderData {
|
|||
int size;
|
||||
} currCylinderData;
|
||||
|
||||
void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const
|
||||
void TankInfoDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &thisindex) const
|
||||
{
|
||||
CylindersModel *mymodel = qobject_cast<CylindersModel *>(currCombo.model);
|
||||
TankInfoModel *tanks = TankInfoModel::instance();
|
||||
QModelIndexList matches = tanks->match(tanks->index(0,0), Qt::DisplayRole, currCombo.activeText);
|
||||
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, currCombo.activeText);
|
||||
int row;
|
||||
if (matches.isEmpty()) {
|
||||
// we need to add this
|
||||
tanks->insertRows(tanks->rowCount(), 1);
|
||||
tanks->setData(tanks->index(tanks->rowCount() -1, 0), currCombo.activeText);
|
||||
tanks->setData(tanks->index(tanks->rowCount() - 1, 0), currCombo.activeText);
|
||||
row = tanks->rowCount() - 1;
|
||||
} else {
|
||||
row = matches.first().row();
|
||||
|
@ -223,17 +222,17 @@ void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
|
|||
mymodel->passInData(IDX(CylindersModel::SIZE), tankSize);
|
||||
}
|
||||
|
||||
TankInfoDelegate::TankInfoDelegate(QObject* parent): ComboBoxDelegate(TankInfoModel::instance(), parent)
|
||||
TankInfoDelegate::TankInfoDelegate(QObject *parent) : ComboBoxDelegate(TankInfoModel::instance(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TankInfoDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint)
|
||||
void TankInfoDelegate::revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint)
|
||||
{
|
||||
if (
|
||||
#if !defined __APPLE__
|
||||
hint == QAbstractItemDelegate::NoHint ||
|
||||
hint == QAbstractItemDelegate::NoHint ||
|
||||
#endif
|
||||
hint == QAbstractItemDelegate::RevertModelCache) {
|
||||
hint == QAbstractItemDelegate::RevertModelCache) {
|
||||
CylindersModel *mymodel = qobject_cast<CylindersModel *>(currCombo.model);
|
||||
mymodel->setData(IDX(CylindersModel::TYPE), currCylinderData.type, Qt::EditRole);
|
||||
mymodel->passInData(IDX(CylindersModel::WORKINGPRESS), currCylinderData.pressure);
|
||||
|
@ -241,7 +240,7 @@ void TankInfoDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::E
|
|||
}
|
||||
}
|
||||
|
||||
QWidget* TankInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
QWidget *TankInfoDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
// ncreate editor needs to be called before because it will populate a few
|
||||
// things in the currCombo global var.
|
||||
|
@ -259,24 +258,24 @@ struct RevertWeightData {
|
|||
int weight;
|
||||
} currWeight;
|
||||
|
||||
void WSInfoDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint)
|
||||
void WSInfoDelegate::revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint)
|
||||
{
|
||||
if (
|
||||
#if !defined __APPLE__
|
||||
hint == QAbstractItemDelegate::NoHint ||
|
||||
hint == QAbstractItemDelegate::NoHint ||
|
||||
#endif
|
||||
hint == QAbstractItemDelegate::RevertModelCache) {
|
||||
hint == QAbstractItemDelegate::RevertModelCache) {
|
||||
WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model);
|
||||
mymodel->setData(IDX(WeightModel::TYPE), currWeight.type, Qt::EditRole);
|
||||
mymodel->passInData(IDX(WeightModel::WEIGHT), currWeight.weight);
|
||||
}
|
||||
}
|
||||
|
||||
void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const
|
||||
void WSInfoDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &thisindex) const
|
||||
{
|
||||
WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model);
|
||||
WSInfoModel *wsim = WSInfoModel::instance();
|
||||
QModelIndexList matches = wsim->match(wsim->index(0,0), Qt::DisplayRole, currCombo.activeText);
|
||||
QModelIndexList matches = wsim->match(wsim->index(0, 0), Qt::DisplayRole, currCombo.activeText);
|
||||
int row;
|
||||
if (matches.isEmpty()) {
|
||||
// we need to add this puppy
|
||||
|
@ -293,11 +292,11 @@ void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, co
|
|||
mymodel->passInData(IDX(WeightModel::WEIGHT), grams);
|
||||
}
|
||||
|
||||
WSInfoDelegate::WSInfoDelegate(QObject* parent): ComboBoxDelegate(WSInfoModel::instance(), parent)
|
||||
WSInfoDelegate::WSInfoDelegate(QObject *parent) : ComboBoxDelegate(WSInfoModel::instance(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget* WSInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
QWidget *WSInfoDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
/* First, call the combobox-create editor, it will setup our globals. */
|
||||
QWidget *editor = ComboBoxDelegate::createEditor(parent, option, index);
|
||||
|
@ -308,24 +307,23 @@ QWidget* WSInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewIte
|
|||
return editor;
|
||||
}
|
||||
|
||||
void AirTypesDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint)
|
||||
void AirTypesDelegate::revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint)
|
||||
{
|
||||
}
|
||||
|
||||
void AirTypesDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
|
||||
void AirTypesDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return;
|
||||
QComboBox *combo = qobject_cast<QComboBox*>(editor);
|
||||
QComboBox *combo = qobject_cast<QComboBox *>(editor);
|
||||
model->setData(index, QVariant(combo->currentText()));
|
||||
}
|
||||
|
||||
AirTypesDelegate::AirTypesDelegate(QObject* parent) : ComboBoxDelegate(GasSelectionModel::instance(), parent)
|
||||
AirTypesDelegate::AirTypesDelegate(QObject *parent) : ComboBoxDelegate(GasSelectionModel::instance(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
ProfilePrintDelegate::ProfilePrintDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
ProfilePrintDelegate::ProfilePrintDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -5,75 +5,83 @@
|
|||
class QComboBox;
|
||||
class QPainter;
|
||||
|
||||
class DiveListDelegate : public QStyledItemDelegate{
|
||||
class DiveListDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
explicit DiveListDelegate(QObject *parent = 0): QStyledItemDelegate(parent){}
|
||||
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
explicit DiveListDelegate(QObject *parent = 0)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
class StarWidgetsDelegate : public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StarWidgetsDelegate(QWidget* parent = 0);
|
||||
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
explicit StarWidgetsDelegate(QWidget *parent = 0);
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
private:
|
||||
QWidget *parentWidget;
|
||||
};
|
||||
|
||||
class ComboBoxDelegate : public QStyledItemDelegate{
|
||||
class ComboBoxDelegate : public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ComboBoxDelegate(QAbstractItemModel *model, QObject* parent = 0);
|
||||
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
virtual void setEditorData(QWidget* editor, const QModelIndex& index) const;
|
||||
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
virtual bool eventFilter(QObject* object, QEvent* event);
|
||||
public slots:
|
||||
void testActivation(const QString& currString = QString());
|
||||
explicit ComboBoxDelegate(QAbstractItemModel *model, QObject *parent = 0);
|
||||
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
virtual bool eventFilter(QObject *object, QEvent *event);
|
||||
public
|
||||
slots:
|
||||
void testActivation(const QString &currString = QString());
|
||||
//HACK: try to get rid of this in the future.
|
||||
void fakeActivation();
|
||||
void fixTabBehavior();
|
||||
virtual void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint) = 0;
|
||||
virtual void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) = 0;
|
||||
|
||||
protected:
|
||||
QAbstractItemModel *model;
|
||||
};
|
||||
|
||||
class TankInfoDelegate : public ComboBoxDelegate{
|
||||
class TankInfoDelegate : public ComboBoxDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TankInfoDelegate(QObject* parent = 0);
|
||||
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
|
||||
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
public slots:
|
||||
void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint);
|
||||
explicit TankInfoDelegate(QObject *parent = 0);
|
||||
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
public
|
||||
slots:
|
||||
void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint);
|
||||
};
|
||||
|
||||
class WSInfoDelegate : public ComboBoxDelegate{
|
||||
class WSInfoDelegate : public ComboBoxDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit WSInfoDelegate(QObject* parent = 0);
|
||||
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
|
||||
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
public slots:
|
||||
void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint);
|
||||
explicit WSInfoDelegate(QObject *parent = 0);
|
||||
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
public
|
||||
slots:
|
||||
void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint);
|
||||
};
|
||||
|
||||
class AirTypesDelegate : public ComboBoxDelegate{
|
||||
class AirTypesDelegate : public ComboBoxDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AirTypesDelegate(QObject* parent = 0);
|
||||
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
|
||||
public slots:
|
||||
void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint);
|
||||
explicit AirTypesDelegate(QObject *parent = 0);
|
||||
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||
public
|
||||
slots:
|
||||
void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint);
|
||||
};
|
||||
|
||||
/* ProfilePrintDelagate:
|
||||
* this delegate is used to modify the look of the table that is printed
|
||||
* bellow profiles.
|
||||
*/
|
||||
class ProfilePrintDelegate : public QStyledItemDelegate
|
||||
{
|
||||
class ProfilePrintDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
explicit ProfilePrintDelegate(QObject *parent = 0);
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
|
684
qt-ui/models.cpp
684
qt-ui/models.cpp
File diff suppressed because it is too large
Load diff
261
qt-ui/models.h
261
qt-ui/models.h
|
@ -19,14 +19,16 @@
|
|||
QFont defaultModelFont();
|
||||
|
||||
// Encapsulates Boilerplate.
|
||||
class CleanerTableModel : public QAbstractTableModel{
|
||||
class CleanerTableModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CleanerTableModel(QObject *parent = 0);
|
||||
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
|
||||
protected:
|
||||
void setHeaderDataStrings(const QStringList& headers);
|
||||
void setHeaderDataStrings(const QStringList &headers);
|
||||
|
||||
private:
|
||||
QStringList headers;
|
||||
};
|
||||
|
@ -34,21 +36,27 @@ private:
|
|||
/* Encapsulates the tank_info global variable
|
||||
* to show on Qt's Model View System.*/
|
||||
class TankInfoModel : public CleanerTableModel {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
static TankInfoModel* instance();
|
||||
static TankInfoModel *instance();
|
||||
|
||||
enum Column {DESCRIPTION, ML, BAR};
|
||||
enum Column {
|
||||
DESCRIPTION,
|
||||
ML,
|
||||
BAR
|
||||
};
|
||||
TankInfoModel();
|
||||
|
||||
/*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
/*reimp*/ bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
|
||||
/*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
const QString& biggerString() const;
|
||||
/*reimp*/ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
/*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
/*reimp*/ bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
||||
/*reimp*/ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
const QString &biggerString() const;
|
||||
void clear();
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void update();
|
||||
|
||||
private:
|
||||
int rows;
|
||||
QString biggerEntry;
|
||||
|
@ -56,21 +64,25 @@ private:
|
|||
|
||||
/* Encapsulate ws_info */
|
||||
class WSInfoModel : public CleanerTableModel {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
static WSInfoModel* instance();
|
||||
static WSInfoModel *instance();
|
||||
|
||||
enum Column {DESCRIPTION, GR};
|
||||
enum Column {
|
||||
DESCRIPTION,
|
||||
GR
|
||||
};
|
||||
WSInfoModel();
|
||||
|
||||
/*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
/*reimp*/ bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
|
||||
/*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
const QString& biggerString() const;
|
||||
/*reimp*/ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
/*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
/*reimp*/ bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
||||
/*reimp*/ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
const QString &biggerString() const;
|
||||
void clear();
|
||||
void update();
|
||||
void updateInfo();
|
||||
|
||||
private:
|
||||
int rows;
|
||||
QString biggerEntry;
|
||||
|
@ -79,27 +91,38 @@ private:
|
|||
/* Encapsulation of the Cylinder Model, that presents the
|
||||
* Current cylinders that are used on a dive. */
|
||||
class CylindersModel : public CleanerTableModel {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Column {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, /* DEPTH, */ COLUMNS};
|
||||
enum Column {
|
||||
REMOVE,
|
||||
TYPE,
|
||||
SIZE,
|
||||
WORKINGPRESS,
|
||||
START,
|
||||
END,
|
||||
O2,
|
||||
HE,
|
||||
/* DEPTH, */ COLUMNS
|
||||
};
|
||||
|
||||
explicit CylindersModel(QObject* parent = 0);
|
||||
explicit CylindersModel(QObject *parent = 0);
|
||||
static CylindersModel *instance();
|
||||
/*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
/*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
/*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
/*reimp*/ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
/*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
/*reimp*/ Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
/*reimp*/ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
|
||||
void passInData(const QModelIndex& index, const QVariant& value);
|
||||
void passInData(const QModelIndex &index, const QVariant &value);
|
||||
void add();
|
||||
void clear();
|
||||
void update();
|
||||
void setDive(struct dive *d);
|
||||
cylinder_t *cylinderAt(const QModelIndex& index);
|
||||
cylinder_t *cylinderAt(const QModelIndex &index);
|
||||
bool changed;
|
||||
|
||||
public slots:
|
||||
void remove(const QModelIndex& index);
|
||||
public
|
||||
slots:
|
||||
void remove(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
struct dive *current;
|
||||
|
@ -109,26 +132,31 @@ private:
|
|||
/* Encapsulation of the Weight Model, that represents
|
||||
* the current weights on a dive. */
|
||||
class WeightModel : public CleanerTableModel {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Column {REMOVE, TYPE, WEIGHT};
|
||||
enum Column {
|
||||
REMOVE,
|
||||
TYPE,
|
||||
WEIGHT
|
||||
};
|
||||
|
||||
explicit WeightModel(QObject *parent = 0);
|
||||
/*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
/*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
/*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
/*reimp*/ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
/*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
/*reimp*/ Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
/*reimp*/ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
|
||||
void passInData(const QModelIndex& index, const QVariant& value);
|
||||
void passInData(const QModelIndex &index, const QVariant &value);
|
||||
void add();
|
||||
void clear();
|
||||
void update();
|
||||
void setDive(struct dive *d);
|
||||
weightsystem_t *weightSystemAt(const QModelIndex& index);
|
||||
weightsystem_t *weightSystemAt(const QModelIndex &index);
|
||||
bool changed;
|
||||
|
||||
public slots:
|
||||
void remove(const QModelIndex& index);
|
||||
public
|
||||
slots:
|
||||
void remove(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
struct dive *current;
|
||||
|
@ -140,27 +168,43 @@ private:
|
|||
*/
|
||||
|
||||
struct TreeItem {
|
||||
Q_DECLARE_TR_FUNCTIONS (TreeItemDT);
|
||||
Q_DECLARE_TR_FUNCTIONS(TreeItemDT);
|
||||
|
||||
public:
|
||||
virtual ~TreeItem();
|
||||
TreeItem();
|
||||
virtual QVariant data (int column, int role) const;
|
||||
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
virtual QVariant data(int column, int role) const;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
int row() const;
|
||||
QList<TreeItem*> children;
|
||||
QList<TreeItem *> children;
|
||||
TreeItem *parent;
|
||||
};
|
||||
|
||||
struct DiveItem : public TreeItem {
|
||||
enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT,
|
||||
SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, COLUMNS };
|
||||
enum Column {
|
||||
NR,
|
||||
DATE,
|
||||
RATING,
|
||||
DEPTH,
|
||||
DURATION,
|
||||
TEMPERATURE,
|
||||
TOTALWEIGHT,
|
||||
SUIT,
|
||||
CYLINDER,
|
||||
NITROX,
|
||||
SAC,
|
||||
OTU,
|
||||
MAXCNS,
|
||||
LOCATION,
|
||||
COLUMNS
|
||||
};
|
||||
|
||||
virtual QVariant data(int column, int role) const;
|
||||
int diveId;
|
||||
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QString displayDate() const;
|
||||
QString displayDuration() const;
|
||||
QString displayDepth() const;
|
||||
|
@ -172,14 +216,13 @@ struct DiveItem : public TreeItem {
|
|||
|
||||
struct TripItem;
|
||||
|
||||
class TreeModel : public QAbstractItemModel
|
||||
{
|
||||
class TreeModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TreeModel(QObject *parent = 0);
|
||||
virtual ~TreeModel();
|
||||
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||
/*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
/*reimp*/ int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
/*reimp*/ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
|
@ -193,40 +236,72 @@ protected:
|
|||
class DiveTripModel : public TreeModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT,
|
||||
SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, COLUMNS };
|
||||
enum Column {
|
||||
NR,
|
||||
DATE,
|
||||
RATING,
|
||||
DEPTH,
|
||||
DURATION,
|
||||
TEMPERATURE,
|
||||
TOTALWEIGHT,
|
||||
SUIT,
|
||||
CYLINDER,
|
||||
NITROX,
|
||||
SAC,
|
||||
OTU,
|
||||
MAXCNS,
|
||||
LOCATION,
|
||||
COLUMNS
|
||||
};
|
||||
|
||||
enum ExtraRoles{STAR_ROLE = Qt::UserRole + 1, DIVE_ROLE, TRIP_ROLE, SORT_ROLE, DIVE_IDX};
|
||||
enum Layout{TREE, LIST, CURRENT};
|
||||
enum ExtraRoles {
|
||||
STAR_ROLE = Qt::UserRole + 1,
|
||||
DIVE_ROLE,
|
||||
TRIP_ROLE,
|
||||
SORT_ROLE,
|
||||
DIVE_IDX
|
||||
};
|
||||
enum Layout {
|
||||
TREE,
|
||||
LIST,
|
||||
CURRENT
|
||||
};
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
DiveTripModel(QObject* parent = 0);
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
DiveTripModel(QObject *parent = 0);
|
||||
Layout layout() const;
|
||||
void setLayout(Layout layout);
|
||||
|
||||
private:
|
||||
void setupModelData();
|
||||
QMap<dive_trip_t*, TripItem*> trips;
|
||||
QMap<dive_trip_t *, TripItem *> trips;
|
||||
Layout currentLayout;
|
||||
};
|
||||
|
||||
class DiveComputerModel : public CleanerTableModel
|
||||
{
|
||||
class DiveComputerModel : public CleanerTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum {REMOVE, MODEL, ID, NICKNAME};
|
||||
enum {
|
||||
REMOVE,
|
||||
MODEL,
|
||||
ID,
|
||||
NICKNAME
|
||||
};
|
||||
DiveComputerModel(QMultiMap<QString, DiveComputerNode> &dcMap, QObject *parent = 0);
|
||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
void update();
|
||||
void keepWorkingList();
|
||||
void dropWorkingList();
|
||||
|
||||
public slots:
|
||||
void remove(const QModelIndex& index);
|
||||
public
|
||||
slots:
|
||||
void remove(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
int numRows;
|
||||
QMultiMap<QString, DiveComputerNode> dcWorkingMap;
|
||||
|
@ -235,11 +310,27 @@ private:
|
|||
class YearlyStatisticsModel : public TreeModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum { YEAR,DIVES,TOTAL_TIME,AVERAGE_TIME,SHORTEST_TIME,LONGEST_TIME,AVG_DEPTH,MIN_DEPTH,
|
||||
MAX_DEPTH,AVG_SAC,MIN_SAC,MAX_SAC,AVG_TEMP,MIN_TEMP,MAX_TEMP,COLUMNS};
|
||||
enum {
|
||||
YEAR,
|
||||
DIVES,
|
||||
TOTAL_TIME,
|
||||
AVERAGE_TIME,
|
||||
SHORTEST_TIME,
|
||||
LONGEST_TIME,
|
||||
AVG_DEPTH,
|
||||
MIN_DEPTH,
|
||||
MAX_DEPTH,
|
||||
AVG_SAC,
|
||||
MIN_SAC,
|
||||
MAX_SAC,
|
||||
AVG_TEMP,
|
||||
MIN_TEMP,
|
||||
MAX_TEMP,
|
||||
COLUMNS
|
||||
};
|
||||
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
YearlyStatisticsModel(QObject* parent = 0);
|
||||
YearlyStatisticsModel(QObject *parent = 0);
|
||||
void update_yearly_stats();
|
||||
};
|
||||
|
||||
|
@ -262,8 +353,7 @@ struct TablePrintItem {
|
|||
unsigned int colorBackground;
|
||||
};
|
||||
|
||||
class TablePrintModel : public QAbstractTableModel
|
||||
{
|
||||
class TablePrintModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
@ -277,7 +367,7 @@ public:
|
|||
void insertRow(int index = -1);
|
||||
void callReset();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||
int rowCount(const QModelIndex &parent) const;
|
||||
int columnCount(const QModelIndex &parent) const;
|
||||
|
@ -287,8 +377,7 @@ public:
|
|||
* this model is used when printing a data table under a profile. it requires
|
||||
* some exact usage of setSpan(..) on the target QTableView widget.
|
||||
*/
|
||||
class ProfilePrintModel : public QAbstractTableModel
|
||||
{
|
||||
class ProfilePrintModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
@ -303,13 +392,14 @@ public:
|
|||
void setDive(struct dive *divePtr);
|
||||
};
|
||||
|
||||
class GasSelectionModel : public QStringListModel{
|
||||
class GasSelectionModel : public QStringListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static GasSelectionModel* instance();
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
virtual QVariant data(const QModelIndex& index, int role) const;
|
||||
public slots:
|
||||
static GasSelectionModel *instance();
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||
public
|
||||
slots:
|
||||
void repopulate();
|
||||
};
|
||||
|
||||
|
@ -317,11 +407,12 @@ public slots:
|
|||
class LanguageModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static LanguageModel* instance();
|
||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
static LanguageModel *instance();
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
private:
|
||||
LanguageModel(QObject* parent = 0);
|
||||
LanguageModel(QObject *parent = 0);
|
||||
|
||||
QStringList languages;
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <QMessageBox>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
PreferencesDialog* PreferencesDialog::instance()
|
||||
PreferencesDialog *PreferencesDialog::instance()
|
||||
{
|
||||
static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance());
|
||||
dialog->setAttribute(Qt::WA_QuitOnClose, false);
|
||||
|
@ -14,10 +14,10 @@ PreferencesDialog* PreferencesDialog::instance()
|
|||
return dialog;
|
||||
}
|
||||
|
||||
PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
|
||||
PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
|
||||
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
||||
connect(ui.gflow, SIGNAL(valueChanged(int)), this, SLOT(gflowChanged(int)));
|
||||
connect(ui.gfhigh, SIGNAL(valueChanged(int)), this, SLOT(gfhighChanged(int)));
|
||||
loadSettings();
|
||||
|
@ -25,7 +25,7 @@ PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : QDial
|
|||
rememberPrefs();
|
||||
}
|
||||
|
||||
#define DANGER_GF ( gf > 100 ) ? "* { color: red; }" : ""
|
||||
#define DANGER_GF (gf > 100) ? "* { color: red; }" : ""
|
||||
void PreferencesDialog::gflowChanged(int gf)
|
||||
{
|
||||
ui.gflow->setStyleSheet(DANGER_GF);
|
||||
|
@ -80,7 +80,7 @@ void PreferencesDialog::setUiFromPrefs()
|
|||
ui.fontsize->setValue(prefs.font_size);
|
||||
ui.defaultfilename->setText(prefs.default_filename);
|
||||
ui.default_cylinder->clear();
|
||||
for(int i=0; tank_info[i].name != NULL; i++) {
|
||||
for (int i = 0; tank_info[i].name != NULL; i++) {
|
||||
ui.default_cylinder->addItem(tank_info[i].name);
|
||||
if (prefs.default_cylinder && strcmp(tank_info[i].name, prefs.default_cylinder) == 0)
|
||||
ui.default_cylinder->setCurrentIndex(i);
|
||||
|
@ -101,7 +101,7 @@ void PreferencesDialog::setUiFromPrefs()
|
|||
s.beginGroup("Language");
|
||||
ui.languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool());
|
||||
QAbstractItemModel *m = ui.languageView->model();
|
||||
QModelIndexList languages = m->match( m->index(0,0), Qt::UserRole, s.value("UiLanguage").toString());
|
||||
QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString());
|
||||
if (languages.count())
|
||||
ui.languageView->setCurrentIndex(languages.first());
|
||||
}
|
||||
|
@ -120,47 +120,47 @@ void PreferencesDialog::rememberPrefs()
|
|||
#define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0))
|
||||
|
||||
|
||||
#define GET_UNIT(name, field, f, t) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
#define GET_UNIT(name, field, f, t) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.units.field = (v.toInt() == (t)) ? (t) : (f); \
|
||||
else \
|
||||
prefs.units.field = default_prefs.units.field
|
||||
else \
|
||||
prefs.units.field = default_prefs.units.field
|
||||
|
||||
#define GET_BOOL(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toInt() ? true : false; \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
#define GET_BOOL(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toInt() ? true : false; \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_DOUBLE(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toDouble(); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
#define GET_DOUBLE(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toDouble(); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_INT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toInt(); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
#define GET_INT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toInt(); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_TXT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = strdup(v.toString().toUtf8().constData()); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
#define GET_TXT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = strdup(v.toString().toUtf8().constData()); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_TXT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = strdup(v.toString().toUtf8().constData()); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
#define GET_TXT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = strdup(v.toString().toUtf8().constData()); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
void PreferencesDialog::syncSettings()
|
||||
{
|
||||
|
@ -288,7 +288,7 @@ void PreferencesDialog::loadSettings()
|
|||
s.endGroup();
|
||||
}
|
||||
|
||||
void PreferencesDialog::buttonClicked(QAbstractButton* button)
|
||||
void PreferencesDialog::buttonClicked(QAbstractButton *button)
|
||||
{
|
||||
switch (ui.buttonBox->standardButton(button)) {
|
||||
case QDialogButtonBox::Discard:
|
||||
|
@ -313,7 +313,7 @@ void PreferencesDialog::on_chooseFile_clicked()
|
|||
QFileInfo fi(system_default_filename());
|
||||
QString choosenFileName = QFileDialog::getOpenFileName(this, tr("Open Default Log File"), fi.absolutePath(), tr("Subsurface XML files (*.ssrf *.xml *.XML)"));
|
||||
|
||||
if(!choosenFileName.isEmpty())
|
||||
if (!choosenFileName.isEmpty())
|
||||
ui.defaultfilename->setText(choosenFileName);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,16 +9,17 @@
|
|||
|
||||
class QAbstractButton;
|
||||
|
||||
class PreferencesDialog :public QDialog{
|
||||
Q_OBJECT
|
||||
class PreferencesDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static PreferencesDialog* instance();
|
||||
void showEvent(QShowEvent* );
|
||||
static PreferencesDialog *instance();
|
||||
void showEvent(QShowEvent *);
|
||||
void emitSettingsChanged();
|
||||
signals:
|
||||
void settingsChanged();
|
||||
public slots:
|
||||
void buttonClicked(QAbstractButton* button);
|
||||
public
|
||||
slots:
|
||||
void buttonClicked(QAbstractButton *button);
|
||||
void on_chooseFile_clicked();
|
||||
void syncSettings();
|
||||
void loadSettings();
|
||||
|
@ -28,7 +29,7 @@ public slots:
|
|||
void gfhighChanged(int gf);
|
||||
|
||||
private:
|
||||
explicit PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
void setUiFromPrefs();
|
||||
Ui::PreferencesDialog ui;
|
||||
struct preferences oldPrefs;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
||||
{
|
||||
// options template (are we storing these in the settings?)
|
||||
struct options tempOptions = {options::PRETTY, 0, 2, false, 65, 15, 12};
|
||||
struct options tempOptions = { options::PRETTY, 0, 2, false, 65, 15, 12 };
|
||||
printOptions = tempOptions;
|
||||
|
||||
// create a print layout and pass the printer and options
|
||||
|
|
|
@ -11,7 +11,7 @@ class PrintLayout;
|
|||
|
||||
// should be based on a custom QPrintDialog class
|
||||
class PrintDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct options printOptions;
|
||||
|
@ -23,7 +23,8 @@ private:
|
|||
QProgressBar *progressBar;
|
||||
QPrinter printer;
|
||||
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
void previewClicked();
|
||||
void printClicked();
|
||||
void onPaintRequested(QPrinter *);
|
||||
|
|
|
@ -43,7 +43,7 @@ PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct op
|
|||
profilePrintColumnWidths.append(dw - 3);
|
||||
profilePrintColumnWidths.append(dw - 3);
|
||||
profilePrintColumnWidths.append(dw + 6); // fit to 100%
|
||||
const int sr = 12; // smallest row height in pixels
|
||||
const int sr = 12; // smallest row height in pixels
|
||||
profilePrintRowHeights.append(sr);
|
||||
profilePrintRowHeights.append(sr + 4);
|
||||
profilePrintRowHeights.append(sr);
|
||||
|
@ -84,8 +84,8 @@ void PrintLayout::setup()
|
|||
printerDpi = printer->resolution();
|
||||
pageRect = printer->pageRect();
|
||||
|
||||
scaleX = (qreal)printerDpi/(qreal)screenDpiX;
|
||||
scaleY = (qreal)printerDpi/(qreal)screenDpiY;
|
||||
scaleX = (qreal)printerDpi / (qreal)screenDpiX;
|
||||
scaleY = (qreal)printerDpi / (qreal)screenDpiY;
|
||||
|
||||
// a printer page scalled to screen DPI
|
||||
scaledPageW = pageRect.width() / scaleX;
|
||||
|
@ -114,7 +114,7 @@ int PrintLayout::estimateTotalDives() const
|
|||
* p is the padding between elements
|
||||
*/
|
||||
#define ESTIMATE_DIVE_DIM(S, n, p) \
|
||||
((S) - ((n) - 1) * (p)) / (n);
|
||||
((S) - ((n) - 1) * (p)) / (n);
|
||||
|
||||
void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
|
||||
{
|
||||
|
@ -220,7 +220,7 @@ QTableView *PrintLayout::createProfileTable(ProfilePrintModel *model, const int
|
|||
table->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
hHeader->setVisible(false);
|
||||
vHeader->setVisible(false);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
hHeader->setResizeMode(QHeaderView::Fixed);
|
||||
vHeader->setResizeMode(QHeaderView::Fixed);
|
||||
#else
|
||||
|
@ -269,8 +269,7 @@ QTableView *PrintLayout::createProfileTable(ProfilePrintModel *model, const int
|
|||
table->setShowGrid(false);
|
||||
table->setStyleSheet(
|
||||
"QTableView { border: none }"
|
||||
"QTableView::item { border: 0px; padding-left: 2px; padding-right: 2px; }"
|
||||
);
|
||||
"QTableView::item { border: 0px; padding-left: 2px; padding-right: 2px; }");
|
||||
// return
|
||||
return table;
|
||||
}
|
||||
|
@ -290,7 +289,7 @@ void PrintLayout::printTable()
|
|||
table.setFocusPolicy(Qt::NoFocus);
|
||||
table.horizontalHeader()->setVisible(false);
|
||||
table.verticalHeader()->setVisible(false);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
table.horizontalHeader()->setResizeMode(QHeaderView::Fixed);
|
||||
table.verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
#else
|
||||
|
@ -300,12 +299,11 @@ void PrintLayout::printTable()
|
|||
table.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
table.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
// fit table to one page initially
|
||||
table.resize(scaledPageW, scaledPageH);
|
||||
table.resize(scaledPageW, scaledPageH);
|
||||
|
||||
// don't show border
|
||||
table.setStyleSheet(
|
||||
"QTableView { border: none }"
|
||||
);
|
||||
"QTableView { border: none }");
|
||||
|
||||
// create and fill a table model
|
||||
TablePrintModel model;
|
||||
|
|
|
@ -43,7 +43,7 @@ private:
|
|||
void addTablePrintHeadingRow(TablePrintModel *model, int row) const;
|
||||
|
||||
signals:
|
||||
void signalProgress(int);
|
||||
void signalProgress(int);
|
||||
};
|
||||
|
||||
#endif // PRINTLAYOUT_H
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
// should be based on a custom QPrintDialog class
|
||||
class PrintOptions : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PrintOptions(QWidget *parent = 0, struct options *printOpt = 0);
|
||||
|
@ -23,7 +23,8 @@ private:
|
|||
struct options *printOptions;
|
||||
bool hasSetupSlots;
|
||||
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
void sliderPHeightMoved(int value);
|
||||
void sliderOHeightMoved(int value);
|
||||
void sliderNHeightMoved(int value);
|
||||
|
|
|
@ -2,37 +2,37 @@
|
|||
#include <QPropertyAnimation>
|
||||
#include <QPointF>
|
||||
|
||||
namespace Animations {
|
||||
|
||||
void hide(QObject* obj)
|
||||
namespace Animations
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
|
||||
animation->setStartValue(1);
|
||||
animation->setEndValue(0);
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
void animDelete(QObject* obj)
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
|
||||
obj->connect(animation, SIGNAL(finished()), SLOT(deleteLater()));
|
||||
animation->setStartValue(1);
|
||||
animation->setEndValue(0);
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
void hide(QObject *obj)
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
|
||||
animation->setStartValue(1);
|
||||
animation->setEndValue(0);
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
void moveTo(QObject* obj, qreal x, qreal y, int msecs)
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
|
||||
animation->setDuration(msecs);
|
||||
animation->setStartValue(obj->property("pos").toPointF());
|
||||
animation->setEndValue(QPointF(x, y));
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
void animDelete(QObject *obj)
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
|
||||
obj->connect(animation, SIGNAL(finished()), SLOT(deleteLater()));
|
||||
animation->setStartValue(1);
|
||||
animation->setEndValue(0);
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
void moveTo(QObject* obj, const QPointF& pos, int msecs)
|
||||
{
|
||||
moveTo(obj, pos.x(), pos.y(), msecs);
|
||||
}
|
||||
void moveTo(QObject *obj, qreal x, qreal y, int msecs)
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
|
||||
animation->setDuration(msecs);
|
||||
animation->setStartValue(obj->property("pos").toPointF());
|
||||
animation->setEndValue(QPointF(x, y));
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
void moveTo(QObject *obj, const QPointF &pos, int msecs)
|
||||
{
|
||||
moveTo(obj, pos.x(), pos.y(), msecs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
|
||||
class QObject;
|
||||
|
||||
namespace Animations{
|
||||
namespace Animations
|
||||
{
|
||||
void hide(QObject *obj);
|
||||
void moveTo(QObject *obj, qreal x, qreal y, int msecs = 500);
|
||||
void moveTo(QObject *obj, const QPointF& pos, int msecs = 500);
|
||||
void moveTo(QObject *obj, const QPointF &pos, int msecs = 500);
|
||||
void animDelete(QObject *obj);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
#include <QStyleOption>
|
||||
#include <QSettings>
|
||||
|
||||
static QPen gridPen(){
|
||||
static QPen gridPen()
|
||||
{
|
||||
QPen pen;
|
||||
pen.setColor(getColor(TIME_GRID));
|
||||
pen.setWidth(2);
|
||||
|
@ -50,7 +51,7 @@ void DiveCartesianAxis::setMinimum(double minimum)
|
|||
min = minimum;
|
||||
}
|
||||
|
||||
void DiveCartesianAxis::setTextColor(const QColor& color)
|
||||
void DiveCartesianAxis::setTextColor(const QColor &color)
|
||||
{
|
||||
textColor = color;
|
||||
}
|
||||
|
@ -73,7 +74,6 @@ DiveCartesianAxis::DiveCartesianAxis() : QObject(),
|
|||
|
||||
DiveCartesianAxis::~DiveCartesianAxis()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DiveCartesianAxis::setLineSize(qreal lineSize)
|
||||
|
@ -93,31 +93,33 @@ QColor DiveCartesianAxis::colorForValue(double value)
|
|||
|
||||
void DiveCartesianAxis::setTextVisible(bool arg1)
|
||||
{
|
||||
if(textVisibility == arg1){
|
||||
if (textVisibility == arg1) {
|
||||
return;
|
||||
}
|
||||
textVisibility = arg1;
|
||||
Q_FOREACH(DiveTextItem *item, labels){
|
||||
Q_FOREACH(DiveTextItem * item, labels) {
|
||||
item->setVisible(textVisibility);
|
||||
}
|
||||
}
|
||||
|
||||
void DiveCartesianAxis::setLinesVisible(bool arg1)
|
||||
{
|
||||
if(lineVisibility == arg1){
|
||||
if (lineVisibility == arg1) {
|
||||
return;
|
||||
}
|
||||
lineVisibility = arg1;
|
||||
Q_FOREACH(DiveLineItem *item, lines){
|
||||
item->setVisible(lineVisibility );
|
||||
lineVisibility = arg1;
|
||||
Q_FOREACH(DiveLineItem * item, lines) {
|
||||
item->setVisible(lineVisibility);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> void emptyList( QList<T*>& list, double steps){
|
||||
template <typename T>
|
||||
void emptyList(QList<T *> &list, double steps)
|
||||
{
|
||||
if (!list.isEmpty() && list.size() > steps) {
|
||||
while (list.size() > steps) {
|
||||
T *removedItem = list.takeLast();
|
||||
Animations::animDelete(removedItem);
|
||||
T *removedItem = list.takeLast();
|
||||
Animations::animDelete(removedItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +150,7 @@ void DiveCartesianAxis::updateTicks()
|
|||
} else if (orientation == BottomToTop) {
|
||||
begin = m.y2();
|
||||
stepSize = (m.y2() - m.y1());
|
||||
} else if (orientation == LeftToRight ) {
|
||||
} else if (orientation == LeftToRight) {
|
||||
begin = m.x1();
|
||||
stepSize = (m.x2() - m.x1());
|
||||
} else if (orientation == RightToLeft) {
|
||||
|
@ -159,11 +161,11 @@ void DiveCartesianAxis::updateTicks()
|
|||
|
||||
for (int i = 0, count = labels.size(); i < count; i++, currValueText += interval) {
|
||||
qreal childPos = (orientation == TopToBottom || orientation == LeftToRight) ?
|
||||
begin + i * stepSize :
|
||||
begin - i * stepSize;
|
||||
begin + i * stepSize :
|
||||
begin - i * stepSize;
|
||||
|
||||
labels[i]->setText(textForValue(currValueText));
|
||||
if ( orientation == LeftToRight || orientation == RightToLeft) {
|
||||
if (orientation == LeftToRight || orientation == RightToLeft) {
|
||||
labels[i]->animateMoveTo(childPos, m.y1() + tick_size);
|
||||
} else {
|
||||
labels[i]->animateMoveTo(m.x1() - tick_size, childPos);
|
||||
|
@ -172,10 +174,10 @@ void DiveCartesianAxis::updateTicks()
|
|||
|
||||
for (int i = 0, count = lines.size(); i < count; i++, currValueLine += interval) {
|
||||
qreal childPos = (orientation == TopToBottom || orientation == LeftToRight) ?
|
||||
begin + i * stepSize :
|
||||
begin - i * stepSize;
|
||||
begin + i * stepSize :
|
||||
begin - i * stepSize;
|
||||
|
||||
if ( orientation == LeftToRight || orientation == RightToLeft) {
|
||||
if (orientation == LeftToRight || orientation == RightToLeft) {
|
||||
lines[i]->animateMoveTo(childPos, m.y1());
|
||||
} else {
|
||||
lines[i]->animateMoveTo(m.x1(), childPos);
|
||||
|
@ -183,10 +185,10 @@ void DiveCartesianAxis::updateTicks()
|
|||
}
|
||||
|
||||
// Add's the rest of the needed Ticks / Text.
|
||||
for (int i = labels.size(); i < steps; i++, currValueText += interval) {
|
||||
for (int i = labels.size(); i < steps; i++, currValueText += interval) {
|
||||
qreal childPos;
|
||||
if (orientation == TopToBottom || orientation == LeftToRight) {
|
||||
childPos = begin + i * stepSize;
|
||||
childPos = begin + i * stepSize;
|
||||
} else {
|
||||
childPos = begin - i * stepSize;
|
||||
}
|
||||
|
@ -202,17 +204,17 @@ void DiveCartesianAxis::updateTicks()
|
|||
label->setPos(scene()->sceneRect().width() + 10, m.y1() + tick_size); // position it outside of the scene);
|
||||
label->animateMoveTo(childPos, m.y1() + tick_size);
|
||||
} else {
|
||||
label->setAlignment(Qt::AlignVCenter| Qt::AlignLeft);
|
||||
label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
|
||||
label->setPos(m.x1() - tick_size, scene()->sceneRect().height() + 10);
|
||||
label->animateMoveTo(m.x1() - tick_size, childPos);
|
||||
}
|
||||
}
|
||||
|
||||
// Add's the rest of the needed Ticks / Text.
|
||||
for (int i = lines.size(); i < steps; i++, currValueText += interval) {
|
||||
for (int i = lines.size(); i < steps; i++, currValueText += interval) {
|
||||
qreal childPos;
|
||||
if (orientation == TopToBottom || orientation == LeftToRight) {
|
||||
childPos = begin + i * stepSize;
|
||||
childPos = begin + i * stepSize;
|
||||
} else {
|
||||
childPos = begin - i * stepSize;
|
||||
}
|
||||
|
@ -225,7 +227,7 @@ void DiveCartesianAxis::updateTicks()
|
|||
line->setZValue(0);
|
||||
lines.push_back(line);
|
||||
if (orientation == RightToLeft || orientation == LeftToRight) {
|
||||
line->setLine(0,-line_size,0, 0);
|
||||
line->setLine(0, -line_size, 0, 0);
|
||||
line->animateMoveTo(childPos, m.y1());
|
||||
} else {
|
||||
QPointF p1 = mapFromScene(3, 0);
|
||||
|
@ -235,13 +237,13 @@ void DiveCartesianAxis::updateTicks()
|
|||
}
|
||||
}
|
||||
|
||||
Q_FOREACH(DiveTextItem *item, labels)
|
||||
item->setVisible(textVisibility);
|
||||
Q_FOREACH(DiveLineItem *item, lines)
|
||||
item->setVisible(lineVisibility);
|
||||
Q_FOREACH(DiveTextItem * item, labels)
|
||||
item->setVisible(textVisibility);
|
||||
Q_FOREACH(DiveLineItem * item, lines)
|
||||
item->setVisible(lineVisibility);
|
||||
}
|
||||
|
||||
void DiveCartesianAxis::animateChangeLine(const QLineF& newLine)
|
||||
void DiveCartesianAxis::animateChangeLine(const QLineF &newLine)
|
||||
{
|
||||
setLine(newLine);
|
||||
updateTicks();
|
||||
|
@ -263,15 +265,15 @@ void DiveCartesianAxis::setTickInterval(double i)
|
|||
interval = i;
|
||||
}
|
||||
|
||||
qreal DiveCartesianAxis::valueAt(const QPointF& p) const
|
||||
qreal DiveCartesianAxis::valueAt(const QPointF &p) const
|
||||
{
|
||||
QLineF m = line();
|
||||
QPointF relativePosition = p;
|
||||
relativePosition -= pos(); // normalize p based on the axis' offset on screen
|
||||
|
||||
double retValue = (orientation == LeftToRight || orientation == RightToLeft) ?
|
||||
max * (relativePosition.x() - m.x1()) / (m.x2() - m.x1()) :
|
||||
max * (relativePosition.y() - m.y1()) / (m.y2() - m.y1());
|
||||
double retValue = (orientation == LeftToRight || orientation == RightToLeft) ?
|
||||
max * (relativePosition.x() - m.x1()) / (m.x2() - m.x1()) :
|
||||
max * (relativePosition.y() - m.y1()) / (m.y2() - m.y1());
|
||||
return retValue;
|
||||
}
|
||||
|
||||
|
@ -283,12 +285,12 @@ qreal DiveCartesianAxis::posAtValue(qreal value)
|
|||
double size = max - min;
|
||||
// unused for now:
|
||||
// double distanceFromOrigin = value - min;
|
||||
double percent = IS_FP_SAME(min,max) ? 0.0 : (value - min) / size;
|
||||
double percent = IS_FP_SAME(min, max) ? 0.0 : (value - min) / size;
|
||||
|
||||
|
||||
double realSize = orientation == LeftToRight || orientation == RightToLeft?
|
||||
m.x2() - m.x1() :
|
||||
m.y2() - m.y1();
|
||||
double realSize = orientation == LeftToRight || orientation == RightToLeft ?
|
||||
m.x2() - m.x1() :
|
||||
m.y2() - m.y1();
|
||||
|
||||
// Inverted axis, just invert the percentage.
|
||||
if (orientation == RightToLeft || orientation == BottomToTop)
|
||||
|
@ -296,14 +298,14 @@ qreal DiveCartesianAxis::posAtValue(qreal value)
|
|||
|
||||
double retValue = realSize * percent;
|
||||
double adjusted =
|
||||
orientation == LeftToRight ? retValue + m.x1() + p.x() :
|
||||
orientation == RightToLeft ? retValue + m.x1() + p.x() :
|
||||
orientation == TopToBottom ? retValue + m.y1() + p.y() :
|
||||
/* entation == BottomToTop */ retValue + m.y1() + p.y() ;
|
||||
orientation == LeftToRight ? retValue + m.x1() + p.x() :
|
||||
orientation == RightToLeft ? retValue + m.x1() + p.x() :
|
||||
orientation == TopToBottom ? retValue + m.y1() + p.y() :
|
||||
/* entation == BottomToTop */ retValue + m.y1() + p.y();
|
||||
return adjusted;
|
||||
}
|
||||
|
||||
qreal DiveCartesianAxis::percentAt(const QPointF& p)
|
||||
qreal DiveCartesianAxis::percentAt(const QPointF &p)
|
||||
{
|
||||
qreal value = valueAt(p);
|
||||
double size = max - min;
|
||||
|
@ -326,7 +328,7 @@ double DiveCartesianAxis::fontLabelScale() const
|
|||
return labelScale;
|
||||
}
|
||||
|
||||
void DiveCartesianAxis::setColor(const QColor& color)
|
||||
void DiveCartesianAxis::setColor(const QColor &color)
|
||||
{
|
||||
QPen defaultPen(color);
|
||||
defaultPen.setJoinStyle(Qt::RoundJoin);
|
||||
|
@ -361,24 +363,24 @@ DepthAxis::DepthAxis() : showWithPPGraph(false)
|
|||
{
|
||||
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
|
||||
|
||||
// force the correct size of the line.
|
||||
// force the correct size of the line.
|
||||
showWithPPGraph = !isPPGraphEnabled();
|
||||
settingsChanged();
|
||||
}
|
||||
|
||||
void DepthAxis::settingsChanged()
|
||||
{
|
||||
// bool ppGraph = isPPGraphEnabled();
|
||||
// if ( ppGraph == showWithPPGraph){
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (ppGraph) {
|
||||
// animateChangeLine(shrinkedLine);
|
||||
// } else {
|
||||
// animateChangeLine(expandedLine);
|
||||
// }
|
||||
// showWithPPGraph = ppGraph;
|
||||
// bool ppGraph = isPPGraphEnabled();
|
||||
// if ( ppGraph == showWithPPGraph){
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (ppGraph) {
|
||||
// animateChangeLine(shrinkedLine);
|
||||
// } else {
|
||||
// animateChangeLine(expandedLine);
|
||||
// }
|
||||
// showWithPPGraph = ppGraph;
|
||||
}
|
||||
|
||||
QColor TimeAxis::colorForValue(double value)
|
||||
|
@ -390,16 +392,16 @@ QColor TimeAxis::colorForValue(double value)
|
|||
QString TimeAxis::textForValue(double value)
|
||||
{
|
||||
int nr = value / 60;
|
||||
if (maximum() < 600 )
|
||||
return QString("%1:%2").arg(nr).arg( (int)value%60, 2, 10, QChar('0'));
|
||||
return QString::number(nr);
|
||||
if (maximum() < 600)
|
||||
return QString("%1:%2").arg(nr).arg((int)value % 60, 2, 10, QChar('0'));
|
||||
return QString::number(nr);
|
||||
}
|
||||
|
||||
void TimeAxis::updateTicks()
|
||||
{
|
||||
DiveCartesianAxis::updateTicks();
|
||||
if (maximum() > 600){
|
||||
for(int i = 0; i < labels.count(); i++){
|
||||
if (maximum() > 600) {
|
||||
for (int i = 0; i < labels.count(); i++) {
|
||||
labels[i]->setVisible(i % 2);
|
||||
}
|
||||
}
|
||||
|
@ -407,7 +409,7 @@ void TimeAxis::updateTicks()
|
|||
|
||||
QString TemperatureAxis::textForValue(double value)
|
||||
{
|
||||
return QString::number(mkelvin_to_C( (int) value));
|
||||
return QString::number(mkelvin_to_C((int)value));
|
||||
}
|
||||
|
||||
PartialGasPressureAxis::PartialGasPressureAxis()
|
||||
|
@ -415,7 +417,7 @@ PartialGasPressureAxis::PartialGasPressureAxis()
|
|||
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(preferencesChanged()));
|
||||
}
|
||||
|
||||
void PartialGasPressureAxis::setModel(DivePlotDataModel* m)
|
||||
void PartialGasPressureAxis::setModel(DivePlotDataModel *m)
|
||||
{
|
||||
model = m;
|
||||
connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(preferencesChanged()));
|
||||
|
@ -435,8 +437,8 @@ void PartialGasPressureAxis::preferencesChanged()
|
|||
|
||||
double max = showPhe ? model->pheMax() : -1;
|
||||
if (showPn2 && model->pn2Max() > max)
|
||||
max = model->pn2Max();
|
||||
if( showPo2 && model->po2Max() > max)
|
||||
max = model->pn2Max();
|
||||
if (showPo2 && model->po2Max() > max)
|
||||
max = model->po2Max();
|
||||
|
||||
qreal pp = floor(max * 10.0) / 10.0 + 0.2;
|
||||
|
@ -444,6 +446,6 @@ void PartialGasPressureAxis::preferencesChanged()
|
|||
return;
|
||||
|
||||
setMaximum(pp);
|
||||
setTickInterval( pp > 4 ? 0.5 : 0.25 );
|
||||
setTickInterval(pp > 4 ? 0.5 : 0.25);
|
||||
updateTicks();
|
||||
}
|
||||
|
|
|
@ -9,14 +9,19 @@ class DiveTextItem;
|
|||
class DiveLineItem;
|
||||
class DivePlotDataModel;
|
||||
|
||||
class DiveCartesianAxis : public QObject, public QGraphicsLineItem{
|
||||
class DiveCartesianAxis : public QObject, public QGraphicsLineItem {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QLineF line WRITE setLine READ line)
|
||||
Q_PROPERTY(QPointF pos WRITE setPos READ pos)
|
||||
Q_PROPERTY(qreal x WRITE setX READ x)
|
||||
Q_PROPERTY(qreal y WRITE setY READ y)
|
||||
public:
|
||||
enum Orientation{TopToBottom, BottomToTop, LeftToRight, RightToLeft};
|
||||
enum Orientation {
|
||||
TopToBottom,
|
||||
BottomToTop,
|
||||
LeftToRight,
|
||||
RightToLeft
|
||||
};
|
||||
DiveCartesianAxis();
|
||||
virtual ~DiveCartesianAxis();
|
||||
void setMinimum(double minimum);
|
||||
|
@ -30,28 +35,30 @@ public:
|
|||
double tickInterval() const;
|
||||
double tickSize() const;
|
||||
double fontLabelScale() const;
|
||||
qreal valueAt(const QPointF& p) const;
|
||||
qreal percentAt(const QPointF& p);
|
||||
qreal valueAt(const QPointF &p) const;
|
||||
qreal percentAt(const QPointF &p);
|
||||
qreal posAtValue(qreal value);
|
||||
void setColor(const QColor& color);
|
||||
void setTextColor(const QColor& color);
|
||||
void animateChangeLine(const QLineF& newLine);
|
||||
void setColor(const QColor &color);
|
||||
void setTextColor(const QColor &color);
|
||||
void animateChangeLine(const QLineF &newLine);
|
||||
void setTextVisible(bool arg1);
|
||||
void setLinesVisible(bool arg1);
|
||||
void setLineSize(qreal lineSize);
|
||||
int unitSystem;
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
virtual void updateTicks();
|
||||
|
||||
signals:
|
||||
void sizeChanged();
|
||||
void maxChanged();
|
||||
|
||||
protected:
|
||||
virtual QString textForValue(double value);
|
||||
virtual QColor colorForValue(double value);
|
||||
Orientation orientation;
|
||||
QList<DiveTextItem*> labels;
|
||||
QList<DiveLineItem*> lines;
|
||||
QList<DiveTextItem *> labels;
|
||||
QList<DiveLineItem *> lines;
|
||||
double min;
|
||||
double max;
|
||||
double interval;
|
||||
|
@ -67,11 +74,14 @@ class DepthAxis : public DiveCartesianAxis {
|
|||
Q_OBJECT
|
||||
public:
|
||||
DepthAxis();
|
||||
|
||||
protected:
|
||||
QString textForValue(double value);
|
||||
QColor colorForValue(double value);
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
void settingsChanged();
|
||||
|
||||
private:
|
||||
bool showWithPPGraph;
|
||||
};
|
||||
|
@ -80,24 +90,27 @@ class TimeAxis : public DiveCartesianAxis {
|
|||
Q_OBJECT
|
||||
public:
|
||||
virtual void updateTicks();
|
||||
|
||||
protected:
|
||||
QString textForValue(double value);
|
||||
QColor colorForValue(double value);
|
||||
};
|
||||
|
||||
class TemperatureAxis : public DiveCartesianAxis{
|
||||
class TemperatureAxis : public DiveCartesianAxis {
|
||||
Q_OBJECT
|
||||
protected:
|
||||
QString textForValue(double value);
|
||||
};
|
||||
|
||||
class PartialGasPressureAxis : public DiveCartesianAxis{
|
||||
class PartialGasPressureAxis : public DiveCartesianAxis {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PartialGasPressureAxis();
|
||||
void setModel(DivePlotDataModel *model);
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void preferencesChanged();
|
||||
|
||||
private:
|
||||
DivePlotDataModel *model;
|
||||
};
|
||||
|
|
|
@ -6,26 +6,29 @@
|
|||
#include "dive.h"
|
||||
#include <QDebug>
|
||||
|
||||
DiveEventItem::DiveEventItem(QObject* parent): DivePixmapItem(parent),
|
||||
vAxis(NULL), hAxis(NULL), dataModel(NULL), internalEvent(NULL)
|
||||
DiveEventItem::DiveEventItem(QObject *parent) : DivePixmapItem(parent),
|
||||
vAxis(NULL),
|
||||
hAxis(NULL),
|
||||
dataModel(NULL),
|
||||
internalEvent(NULL)
|
||||
{
|
||||
setFlag(ItemIgnoresTransformations);
|
||||
}
|
||||
|
||||
|
||||
void DiveEventItem::setHorizontalAxis(DiveCartesianAxis* axis)
|
||||
void DiveEventItem::setHorizontalAxis(DiveCartesianAxis *axis)
|
||||
{
|
||||
hAxis = axis;
|
||||
recalculatePos(true);
|
||||
}
|
||||
|
||||
void DiveEventItem::setModel(DivePlotDataModel* model)
|
||||
void DiveEventItem::setModel(DivePlotDataModel *model)
|
||||
{
|
||||
dataModel = model;
|
||||
recalculatePos(true);
|
||||
}
|
||||
|
||||
void DiveEventItem::setVerticalAxis(DiveCartesianAxis* axis)
|
||||
void DiveEventItem::setVerticalAxis(DiveCartesianAxis *axis)
|
||||
{
|
||||
vAxis = axis;
|
||||
recalculatePos(true);
|
||||
|
@ -37,7 +40,7 @@ struct event *DiveEventItem::getEvent()
|
|||
return internalEvent;
|
||||
}
|
||||
|
||||
void DiveEventItem::setEvent(struct event* ev)
|
||||
void DiveEventItem::setEvent(struct event *ev)
|
||||
{
|
||||
if (!ev)
|
||||
return;
|
||||
|
@ -49,7 +52,7 @@ void DiveEventItem::setEvent(struct event* ev)
|
|||
|
||||
void DiveEventItem::setupPixmap()
|
||||
{
|
||||
#define EVENT_PIXMAP( PIX ) QPixmap(QString(PIX)).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation)
|
||||
#define EVENT_PIXMAP(PIX) QPixmap(QString(PIX)).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation)
|
||||
if (!internalEvent->name) {
|
||||
setPixmap(EVENT_PIXMAP(":warning"));
|
||||
} else if ((strcmp(internalEvent->name, "bookmark") == 0)) {
|
||||
|
@ -84,7 +87,7 @@ void DiveEventItem::setupToolTipString()
|
|||
else
|
||||
name += QString(tr("EAN%1")).arg(o2);
|
||||
} else if (name == "SP change") {
|
||||
name += QString(":%1").arg((double) value / 1000);
|
||||
name += QString(":%1").arg((double)value / 1000);
|
||||
} else {
|
||||
name += QString(":%1").arg(value);
|
||||
}
|
||||
|
@ -98,7 +101,7 @@ void DiveEventItem::setupToolTipString()
|
|||
setToolTip(name);
|
||||
}
|
||||
|
||||
void DiveEventItem::eventVisibilityChanged(const QString& eventName, bool visible)
|
||||
void DiveEventItem::eventVisibilityChanged(const QString &eventName, bool visible)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -107,7 +110,7 @@ void DiveEventItem::recalculatePos(bool instant)
|
|||
if (!vAxis || !hAxis || !internalEvent || !dataModel)
|
||||
return;
|
||||
|
||||
QModelIndexList result = dataModel->match(dataModel->index(0,DivePlotDataModel::TIME), Qt::DisplayRole, internalEvent->time.seconds );
|
||||
QModelIndexList result = dataModel->match(dataModel->index(0, DivePlotDataModel::TIME), Qt::DisplayRole, internalEvent->time.seconds);
|
||||
if (result.isEmpty()) {
|
||||
Q_ASSERT("can't find a spot in the dataModel");
|
||||
hide();
|
||||
|
@ -122,5 +125,5 @@ void DiveEventItem::recalculatePos(bool instant)
|
|||
if (!instant)
|
||||
Animations::moveTo(this, x, y, 500);
|
||||
else
|
||||
setPos(x,y);
|
||||
setPos(x, y);
|
||||
}
|
||||
|
|
|
@ -10,22 +10,24 @@ struct event;
|
|||
class DiveEventItem : public DivePixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiveEventItem(QObject* parent = 0);
|
||||
DiveEventItem(QObject *parent = 0);
|
||||
void setEvent(struct event *ev);
|
||||
struct event *getEvent();
|
||||
void eventVisibilityChanged(const QString& eventName, bool visible);
|
||||
void eventVisibilityChanged(const QString &eventName, bool visible);
|
||||
void setVerticalAxis(DiveCartesianAxis *axis);
|
||||
void setHorizontalAxis(DiveCartesianAxis *axis);
|
||||
void setModel(DivePlotDataModel *model);
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void recalculatePos(bool instant = false);
|
||||
|
||||
private:
|
||||
void setupToolTipString();
|
||||
void setupPixmap();
|
||||
DiveCartesianAxis *vAxis;
|
||||
DiveCartesianAxis *hAxis;
|
||||
DivePlotDataModel *dataModel;
|
||||
struct event* internalEvent;
|
||||
struct event *internalEvent;
|
||||
};
|
||||
|
||||
#endif // DIVEEVENTITEM_H
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
DiveLineItem::DiveLineItem(QGraphicsItem *parent) : QGraphicsLineItem(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DiveLineItem::animatedHide()
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "divepixmapitem.h"
|
||||
|
||||
DivePixmapItem::DivePixmapItem(QObject* parent): QObject(parent), QGraphicsPixmapItem()
|
||||
DivePixmapItem::DivePixmapItem(QObject *parent) : QObject(parent), QGraphicsPixmapItem()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
#include <QObject>
|
||||
#include <QGraphicsPixmapItem>
|
||||
|
||||
class DivePixmapItem : public QObject, public QGraphicsPixmapItem{
|
||||
class DivePixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity)
|
||||
Q_PROPERTY(QPointF pos WRITE setPos READ pos)
|
||||
Q_PROPERTY(qreal x WRITE setX READ x)
|
||||
Q_PROPERTY(qreal y WRITE setY READ y)
|
||||
public:
|
||||
DivePixmapItem(QObject* parent = 0);
|
||||
DivePixmapItem(QObject *parent = 0);
|
||||
};
|
||||
|
||||
#endif // DIVEPIXMAPITEM_H
|
||||
|
|
|
@ -8,60 +8,76 @@
|
|||
#include "divelist.h"
|
||||
#include <QDebug>
|
||||
|
||||
DivePlotDataModel::DivePlotDataModel(QObject* parent) : QAbstractTableModel(parent) , diveId(0)
|
||||
DivePlotDataModel::DivePlotDataModel(QObject *parent) : QAbstractTableModel(parent), diveId(0)
|
||||
{
|
||||
memset(&pInfo, 0, sizeof(pInfo));
|
||||
}
|
||||
|
||||
int DivePlotDataModel::columnCount(const QModelIndex& parent) const
|
||||
int DivePlotDataModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return COLUMNS;
|
||||
}
|
||||
|
||||
QVariant DivePlotDataModel::data(const QModelIndex& index, int role) const
|
||||
QVariant DivePlotDataModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if ((!index.isValid())||(index.row() >= pInfo.nr))
|
||||
if ((!index.isValid()) || (index.row() >= pInfo.nr))
|
||||
return QVariant();
|
||||
|
||||
plot_data item = pInfo.entry[index.row()];
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch (index.column()) {
|
||||
case DEPTH: return item.depth;
|
||||
case TIME: return item.sec;
|
||||
case PRESSURE: return item.pressure[0];
|
||||
case TEMPERATURE: return item.temperature;
|
||||
case COLOR: return item.velocity;
|
||||
case USERENTERED: return false;
|
||||
case CYLINDERINDEX: return item.cylinderindex;
|
||||
case SENSOR_PRESSURE: return item.pressure[0];
|
||||
case INTERPOLATED_PRESSURE: return item.pressure[1];
|
||||
case CEILING: return item.ceiling;
|
||||
case SAC: return item.sac;
|
||||
case PN2: return item.pn2;
|
||||
case PHE: return item.phe;
|
||||
case PO2: return item.po2;
|
||||
case HEARTBEAT: return item.heartbeat;
|
||||
case DEPTH:
|
||||
return item.depth;
|
||||
case TIME:
|
||||
return item.sec;
|
||||
case PRESSURE:
|
||||
return item.pressure[0];
|
||||
case TEMPERATURE:
|
||||
return item.temperature;
|
||||
case COLOR:
|
||||
return item.velocity;
|
||||
case USERENTERED:
|
||||
return false;
|
||||
case CYLINDERINDEX:
|
||||
return item.cylinderindex;
|
||||
case SENSOR_PRESSURE:
|
||||
return item.pressure[0];
|
||||
case INTERPOLATED_PRESSURE:
|
||||
return item.pressure[1];
|
||||
case CEILING:
|
||||
return item.ceiling;
|
||||
case SAC:
|
||||
return item.sac;
|
||||
case PN2:
|
||||
return item.pn2;
|
||||
case PHE:
|
||||
return item.phe;
|
||||
case PO2:
|
||||
return item.po2;
|
||||
case HEARTBEAT:
|
||||
return item.heartbeat;
|
||||
}
|
||||
}
|
||||
|
||||
if (role == Qt::DisplayRole && index.column() >= TISSUE_1 && index.column() <= TISSUE_16){
|
||||
return item.ceilings[ index.column() - TISSUE_1];
|
||||
if (role == Qt::DisplayRole && index.column() >= TISSUE_1 && index.column() <= TISSUE_16) {
|
||||
return item.ceilings[index.column() - TISSUE_1];
|
||||
}
|
||||
|
||||
if (role == Qt::BackgroundRole) {
|
||||
switch (index.column()) {
|
||||
case COLOR: return getColor((color_indice_t)(VELOCITY_COLORS_START_IDX + item.velocity));
|
||||
case COLOR:
|
||||
return getColor((color_indice_t)(VELOCITY_COLORS_START_IDX + item.velocity));
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const plot_info& DivePlotDataModel::data() const
|
||||
const plot_info &DivePlotDataModel::data() const
|
||||
{
|
||||
return pInfo;
|
||||
}
|
||||
|
||||
int DivePlotDataModel::rowCount(const QModelIndex& parent) const
|
||||
int DivePlotDataModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return pInfo.nr;
|
||||
}
|
||||
|
@ -75,22 +91,36 @@ QVariant DivePlotDataModel::headerData(int section, Qt::Orientation orientation,
|
|||
return QVariant();
|
||||
|
||||
switch (section) {
|
||||
case DEPTH: return tr("Depth");
|
||||
case TIME: return tr("Time");
|
||||
case PRESSURE: return tr("Pressure");
|
||||
case TEMPERATURE: return tr("Temperature");
|
||||
case COLOR: return tr("Color");
|
||||
case USERENTERED: return tr("User Entered");
|
||||
case CYLINDERINDEX: return tr("Cylinder Index");
|
||||
case SENSOR_PRESSURE: return tr("Pressure S");
|
||||
case INTERPOLATED_PRESSURE: return tr("Pressure I");
|
||||
case CEILING: return tr("Ceiling");
|
||||
case SAC: return tr("SAC");
|
||||
case PN2: return tr("PN2");
|
||||
case PHE: return tr("PHE");
|
||||
case PO2: return tr("PO2");
|
||||
case DEPTH:
|
||||
return tr("Depth");
|
||||
case TIME:
|
||||
return tr("Time");
|
||||
case PRESSURE:
|
||||
return tr("Pressure");
|
||||
case TEMPERATURE:
|
||||
return tr("Temperature");
|
||||
case COLOR:
|
||||
return tr("Color");
|
||||
case USERENTERED:
|
||||
return tr("User Entered");
|
||||
case CYLINDERINDEX:
|
||||
return tr("Cylinder Index");
|
||||
case SENSOR_PRESSURE:
|
||||
return tr("Pressure S");
|
||||
case INTERPOLATED_PRESSURE:
|
||||
return tr("Pressure I");
|
||||
case CEILING:
|
||||
return tr("Ceiling");
|
||||
case SAC:
|
||||
return tr("SAC");
|
||||
case PN2:
|
||||
return tr("PN2");
|
||||
case PHE:
|
||||
return tr("PHE");
|
||||
case PO2:
|
||||
return tr("PO2");
|
||||
}
|
||||
if (role == Qt::DisplayRole && section >= TISSUE_1 && section <= TISSUE_16){
|
||||
if (role == Qt::DisplayRole && section >= TISSUE_1 && section <= TISSUE_16) {
|
||||
return QString("Ceiling: %1").arg(section - TISSUE_1);
|
||||
}
|
||||
return QVariant();
|
||||
|
@ -107,14 +137,14 @@ void DivePlotDataModel::clear()
|
|||
}
|
||||
}
|
||||
|
||||
void DivePlotDataModel::setDive(dive* d, const plot_info& info)
|
||||
void DivePlotDataModel::setDive(dive *d, const plot_info &info)
|
||||
{
|
||||
clear();
|
||||
Q_ASSERT(d != NULL);
|
||||
diveId = d->id;
|
||||
dcNr = dc_number;
|
||||
pInfo = info;
|
||||
beginInsertRows(QModelIndex(), 0, pInfo.nr-1);
|
||||
beginInsertRows(QModelIndex(), 0, pInfo.nr - 1);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
|
@ -128,16 +158,16 @@ int DivePlotDataModel::dcShown() const
|
|||
return dcNr;
|
||||
}
|
||||
|
||||
#define MAX_PPGAS_FUNC( GAS, GASFUNC ) \
|
||||
double DivePlotDataModel::GASFUNC() \
|
||||
{ \
|
||||
double ret = -1; \
|
||||
for(int i = 0, count = rowCount(); i < count; i++){ \
|
||||
if (pInfo.entry[i].GAS > ret) \
|
||||
ret = pInfo.entry[i].GAS; \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
#define MAX_PPGAS_FUNC(GAS, GASFUNC) \
|
||||
double DivePlotDataModel::GASFUNC() \
|
||||
{ \
|
||||
double ret = -1; \
|
||||
for (int i = 0, count = rowCount(); i < count; i++) { \
|
||||
if (pInfo.entry[i].GAS > ret) \
|
||||
ret = pInfo.entry[i].GAS; \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
MAX_PPGAS_FUNC(phe, pheMax);
|
||||
MAX_PPGAS_FUNC(pn2, pn2Max);
|
||||
|
@ -156,5 +186,5 @@ void DivePlotDataModel::calculateDecompression()
|
|||
struct divecomputer *dc = select_dc(&d->dc);
|
||||
init_decompression(d);
|
||||
calculate_deco_information(d, dc, &pInfo, false);
|
||||
dataChanged(index(0, CEILING), index(pInfo.nr-1, TISSUE_16));
|
||||
dataChanged(index(0, CEILING), index(pInfo.nr - 1, TISSUE_16));
|
||||
}
|
||||
|
|
|
@ -9,20 +9,51 @@ struct dive;
|
|||
struct plot_data;
|
||||
struct plot_info;
|
||||
|
||||
class DivePlotDataModel : public QAbstractTableModel{
|
||||
Q_OBJECT
|
||||
class DivePlotDataModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum {DEPTH, TIME, PRESSURE, TEMPERATURE, USERENTERED, COLOR, CYLINDERINDEX, SENSOR_PRESSURE, INTERPOLATED_PRESSURE,
|
||||
SAC, CEILING, TISSUE_1,TISSUE_2,TISSUE_3,TISSUE_4,TISSUE_5,TISSUE_6,TISSUE_7,TISSUE_8,TISSUE_9,TISSUE_10,
|
||||
TISSUE_11,TISSUE_12,TISSUE_13,TISSUE_14,TISSUE_15,TISSUE_16, PN2,PHE,PO2, HEARTBEAT, COLUMNS};
|
||||
explicit DivePlotDataModel(QObject* parent = 0);
|
||||
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
enum {
|
||||
DEPTH,
|
||||
TIME,
|
||||
PRESSURE,
|
||||
TEMPERATURE,
|
||||
USERENTERED,
|
||||
COLOR,
|
||||
CYLINDERINDEX,
|
||||
SENSOR_PRESSURE,
|
||||
INTERPOLATED_PRESSURE,
|
||||
SAC,
|
||||
CEILING,
|
||||
TISSUE_1,
|
||||
TISSUE_2,
|
||||
TISSUE_3,
|
||||
TISSUE_4,
|
||||
TISSUE_5,
|
||||
TISSUE_6,
|
||||
TISSUE_7,
|
||||
TISSUE_8,
|
||||
TISSUE_9,
|
||||
TISSUE_10,
|
||||
TISSUE_11,
|
||||
TISSUE_12,
|
||||
TISSUE_13,
|
||||
TISSUE_14,
|
||||
TISSUE_15,
|
||||
TISSUE_16,
|
||||
PN2,
|
||||
PHE,
|
||||
PO2,
|
||||
HEARTBEAT,
|
||||
COLUMNS
|
||||
};
|
||||
explicit DivePlotDataModel(QObject *parent = 0);
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
virtual int rowCount(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 clear();
|
||||
void setDive(struct dive *d, const plot_info& pInfo);
|
||||
const plot_info& data() const;
|
||||
void setDive(struct dive *d, const plot_info &pInfo);
|
||||
const plot_info &data() const;
|
||||
int id() const;
|
||||
int dcShown() const;
|
||||
double pheMax();
|
||||
|
@ -30,6 +61,7 @@ public:
|
|||
double po2Max();
|
||||
void emitDataChanged();
|
||||
void calculateDecompression();
|
||||
|
||||
private:
|
||||
plot_info pInfo;
|
||||
int diveId;
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
#include <QGraphicsItem>
|
||||
#include <QSettings>
|
||||
|
||||
AbstractProfilePolygonItem::AbstractProfilePolygonItem(): QObject(), QGraphicsPolygonItem(),
|
||||
hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1)
|
||||
AbstractProfilePolygonItem::AbstractProfilePolygonItem() : QObject(), QGraphicsPolygonItem(), hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1)
|
||||
{
|
||||
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(preferencesChanged()));
|
||||
}
|
||||
|
@ -27,7 +26,7 @@ void AbstractProfilePolygonItem::preferencesChanged()
|
|||
{
|
||||
}
|
||||
|
||||
void AbstractProfilePolygonItem::setHorizontalAxis(DiveCartesianAxis* horizontal)
|
||||
void AbstractProfilePolygonItem::setHorizontalAxis(DiveCartesianAxis *horizontal)
|
||||
{
|
||||
hAxis = horizontal;
|
||||
connect(hAxis, SIGNAL(sizeChanged()), this, SLOT(modelDataChanged()));
|
||||
|
@ -40,22 +39,22 @@ void AbstractProfilePolygonItem::setHorizontalDataColumn(int column)
|
|||
modelDataChanged();
|
||||
}
|
||||
|
||||
void AbstractProfilePolygonItem::setModel(DivePlotDataModel* model)
|
||||
void AbstractProfilePolygonItem::setModel(DivePlotDataModel *model)
|
||||
{
|
||||
dataModel = model;
|
||||
connect(dataModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelDataChanged(QModelIndex, QModelIndex)));
|
||||
connect(dataModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex, int, int)));
|
||||
connect(dataModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(modelDataChanged(QModelIndex, QModelIndex)));
|
||||
connect(dataModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex, int, int)));
|
||||
modelDataChanged();
|
||||
}
|
||||
|
||||
void AbstractProfilePolygonItem::modelDataRemoved(const QModelIndex& parent, int from, int to)
|
||||
void AbstractProfilePolygonItem::modelDataRemoved(const QModelIndex &parent, int from, int to)
|
||||
{
|
||||
setPolygon(QPolygonF());
|
||||
qDeleteAll(texts);
|
||||
texts.clear();
|
||||
}
|
||||
|
||||
void AbstractProfilePolygonItem::setVerticalAxis(DiveCartesianAxis* vertical)
|
||||
void AbstractProfilePolygonItem::setVerticalAxis(DiveCartesianAxis *vertical)
|
||||
{
|
||||
vAxis = vertical;
|
||||
connect(vAxis, SIGNAL(sizeChanged()), this, SLOT(modelDataChanged()));
|
||||
|
@ -69,7 +68,7 @@ void AbstractProfilePolygonItem::setVerticalDataColumn(int column)
|
|||
modelDataChanged();
|
||||
}
|
||||
|
||||
bool AbstractProfilePolygonItem::shouldCalculateStuff(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||
bool AbstractProfilePolygonItem::shouldCalculateStuff(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
if (!hAxis || !vAxis)
|
||||
return false;
|
||||
|
@ -77,16 +76,16 @@ bool AbstractProfilePolygonItem::shouldCalculateStuff(const QModelIndex& topLeft
|
|||
return false;
|
||||
if (hDataColumn == -1 || vDataColumn == -1)
|
||||
return false;
|
||||
if ( topLeft.isValid() && bottomRight.isValid()){
|
||||
if ((topLeft.column() >= vDataColumn || topLeft.column() >= hDataColumn ) &&
|
||||
(bottomRight.column() <= vDataColumn || topLeft.column() <= hDataColumn )){
|
||||
if (topLeft.isValid() && bottomRight.isValid()) {
|
||||
if ((topLeft.column() >= vDataColumn || topLeft.column() >= hDataColumn) &&
|
||||
(bottomRight.column() <= vDataColumn || topLeft.column() <= hDataColumn)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbstractProfilePolygonItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||
void AbstractProfilePolygonItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
// We don't have enougth data to calculate things, quit.
|
||||
|
||||
|
@ -99,7 +98,7 @@ void AbstractProfilePolygonItem::modelDataChanged(const QModelIndex& topLeft, co
|
|||
for (int i = 0, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) {
|
||||
qreal horizontalValue = dataModel->index(i, hDataColumn).data().toReal();
|
||||
qreal verticalValue = dataModel->index(i, vDataColumn).data().toReal();
|
||||
QPointF point( hAxis->posAtValue(horizontalValue), vAxis->posAtValue(verticalValue));
|
||||
QPointF point(hAxis->posAtValue(horizontalValue), vAxis->posAtValue(verticalValue));
|
||||
poly.append(point);
|
||||
}
|
||||
setPolygon(poly);
|
||||
|
@ -110,12 +109,12 @@ void AbstractProfilePolygonItem::modelDataChanged(const QModelIndex& topLeft, co
|
|||
|
||||
DiveProfileItem::DiveProfileItem() : show_reported_ceiling(0), reported_ceiling_in_red(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
|
||||
void DiveProfileItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
if(polygon().isEmpty())
|
||||
if (polygon().isEmpty())
|
||||
return;
|
||||
|
||||
// This paints the Polygon + Background. I'm setting the pen to QPen() so we don't get a black line here,
|
||||
|
@ -134,13 +133,13 @@ void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
|
|||
QModelIndex colorIndex = dataModel->index(i, DivePlotDataModel::COLOR);
|
||||
pen.setBrush(QBrush(colorIndex.data(Qt::BackgroundRole).value<QColor>()));
|
||||
painter->setPen(pen);
|
||||
painter->drawLine(poly[i-1],poly[i]);
|
||||
painter->drawLine(poly[i - 1], poly[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void DiveProfileItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||
void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
if(!shouldCalculateStuff(topLeft, bottomRight))
|
||||
if (!shouldCalculateStuff(topLeft, bottomRight))
|
||||
return;
|
||||
|
||||
AbstractProfilePolygonItem::modelDataChanged(topLeft, bottomRight);
|
||||
|
@ -153,7 +152,7 @@ void DiveProfileItem::modelDataChanged(const QModelIndex& topLeft, const QModelI
|
|||
/* Show any ceiling we may have encountered */
|
||||
if (prefs.profile_dc_ceiling && !prefs.profile_red_ceiling) {
|
||||
QPolygonF p = polygon();
|
||||
plot_data *entry = dataModel->data().entry + dataModel->rowCount()-1;
|
||||
plot_data *entry = dataModel->data().entry + dataModel->rowCount() - 1;
|
||||
for (int i = dataModel->rowCount() - 1; i >= 0; i--, entry--) {
|
||||
if (!entry->in_deco) {
|
||||
/* not in deco implies this is a safety stop, no ceiling */
|
||||
|
@ -167,7 +166,7 @@ void DiveProfileItem::modelDataChanged(const QModelIndex& topLeft, const QModelI
|
|||
setPolygon(p);
|
||||
}
|
||||
|
||||
// This is the blueish gradient that the Depth Profile should have.
|
||||
// This is the blueish gradient that the Depth Profile should have.
|
||||
// It's a simple QLinearGradient with 2 stops, starting from top to bottom.
|
||||
QLinearGradient pat(0, polygon().boundingRect().top(), 0, polygon().boundingRect().bottom());
|
||||
pat.setColorAt(1, getColor(DEPTH_BOTTOM));
|
||||
|
@ -175,9 +174,9 @@ void DiveProfileItem::modelDataChanged(const QModelIndex& topLeft, const QModelI
|
|||
setBrush(QBrush(pat));
|
||||
|
||||
int last = -1;
|
||||
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
|
||||
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
|
||||
|
||||
struct plot_data *entry = dataModel->data().entry+i;
|
||||
struct plot_data *entry = dataModel->data().entry + i;
|
||||
if (entry->depth < 2000)
|
||||
continue;
|
||||
|
||||
|
@ -201,10 +200,10 @@ void DiveProfileItem::preferencesChanged()
|
|||
//TODO: Only modelDataChanged() here if we need to rebuild the graph ( for instance,
|
||||
// if the prefs.profile_dc_ceiling are enabled, but prefs.profile_red_ceiling is disabled
|
||||
// and only if it changed something. let's not waste cpu cycles repoloting something we don't need to.
|
||||
modelDataChanged();
|
||||
modelDataChanged();
|
||||
}
|
||||
|
||||
void DiveProfileItem::plot_depth_sample(struct plot_data *entry,QFlags<Qt::AlignmentFlag> flags,const QColor& color)
|
||||
void DiveProfileItem::plot_depth_sample(struct plot_data *entry, QFlags<Qt::AlignmentFlag> flags, const QColor &color)
|
||||
{
|
||||
int decimals;
|
||||
double d = get_depth_units(entry->depth, &decimals, NULL);
|
||||
|
@ -231,7 +230,7 @@ void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QMode
|
|||
struct {
|
||||
int sec;
|
||||
int hr;
|
||||
} hist[3] = {0};
|
||||
} hist[3] = { 0 };
|
||||
|
||||
// We don't have enougth data to calculate things, quit.
|
||||
if (!shouldCalculateStuff(topLeft, bottomRight))
|
||||
|
@ -246,7 +245,7 @@ void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QMode
|
|||
if (!hr)
|
||||
continue;
|
||||
sec = dataModel->index(i, hDataColumn).data().toInt();
|
||||
QPointF point( hAxis->posAtValue(sec), vAxis->posAtValue(hr));
|
||||
QPointF point(hAxis->posAtValue(sec), vAxis->posAtValue(hr));
|
||||
poly.append(point);
|
||||
if (hr == hist[2].hr)
|
||||
// same as last one, no point in looking at printing
|
||||
|
@ -276,7 +275,7 @@ void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QMode
|
|||
}
|
||||
setPolygon(poly);
|
||||
|
||||
if( texts.count())
|
||||
if (texts.count())
|
||||
texts.last()->setAlignment(Qt::AlignLeft | Qt::AlignBottom);
|
||||
}
|
||||
|
||||
|
@ -291,9 +290,9 @@ void DiveHeartrateItem::createTextItem(int sec, int hr)
|
|||
texts.append(text);
|
||||
}
|
||||
|
||||
void DiveHeartrateItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
void DiveHeartrateItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
if(polygon().isEmpty())
|
||||
if (polygon().isEmpty())
|
||||
return;
|
||||
painter->setPen(pen());
|
||||
painter->drawPolyline(polygon());
|
||||
|
@ -308,7 +307,7 @@ DiveTemperatureItem::DiveTemperatureItem()
|
|||
setPen(pen);
|
||||
}
|
||||
|
||||
void DiveTemperatureItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||
void DiveTemperatureItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
int last = -300, last_printed_temp = 0, sec = 0, last_valid_temp = 0;
|
||||
// We don't have enougth data to calculate things, quit.
|
||||
|
@ -325,7 +324,7 @@ void DiveTemperatureItem::modelDataChanged(const QModelIndex& topLeft, const QMo
|
|||
continue;
|
||||
last_valid_temp = mkelvin;
|
||||
sec = dataModel->index(i, hDataColumn).data().toInt();
|
||||
QPointF point( hAxis->posAtValue(sec), vAxis->posAtValue(mkelvin));
|
||||
QPointF point(hAxis->posAtValue(sec), vAxis->posAtValue(mkelvin));
|
||||
poly.append(point);
|
||||
|
||||
/* don't print a temperature
|
||||
|
@ -338,7 +337,7 @@ void DiveTemperatureItem::modelDataChanged(const QModelIndex& topLeft, const QMo
|
|||
continue;
|
||||
last = sec;
|
||||
if (mkelvin > 200000)
|
||||
createTextItem(sec,mkelvin);
|
||||
createTextItem(sec, mkelvin);
|
||||
last_printed_temp = mkelvin;
|
||||
}
|
||||
setPolygon(poly);
|
||||
|
@ -350,7 +349,7 @@ void DiveTemperatureItem::modelDataChanged(const QModelIndex& topLeft, const QMo
|
|||
((abs(last_valid_temp - last_printed_temp) > 500) || ((double)last / (double)sec < 0.75))) {
|
||||
createTextItem(sec, last_valid_temp);
|
||||
}
|
||||
if( texts.count())
|
||||
if (texts.count())
|
||||
texts.last()->setAlignment(Qt::AlignLeft | Qt::AlignBottom);
|
||||
}
|
||||
|
||||
|
@ -369,15 +368,15 @@ void DiveTemperatureItem::createTextItem(int sec, int mkelvin)
|
|||
texts.append(text);
|
||||
}
|
||||
|
||||
void DiveTemperatureItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
void DiveTemperatureItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
if(polygon().isEmpty())
|
||||
if (polygon().isEmpty())
|
||||
return;
|
||||
painter->setPen(pen());
|
||||
painter->drawPolyline(polygon());
|
||||
}
|
||||
|
||||
void DiveGasPressureItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||
void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
// We don't have enougth data to calculate things, quit.
|
||||
if (!shouldCalculateStuff(topLeft, bottomRight))
|
||||
|
@ -387,7 +386,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex& topLeft, const QMo
|
|||
polygons.clear();
|
||||
|
||||
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
|
||||
plot_data* entry = dataModel->data().entry + i;
|
||||
plot_data *entry = dataModel->data().entry + i;
|
||||
int mbar = GET_PRESSURE(entry);
|
||||
|
||||
if (entry->cylinderindex != last_index) {
|
||||
|
@ -399,7 +398,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex& topLeft, const QMo
|
|||
}
|
||||
|
||||
QPointF point(hAxis->posAtValue(entry->sec), vAxis->posAtValue(mbar));
|
||||
boundingPoly.push_back(point); // The BoundingRect
|
||||
boundingPoly.push_back(point); // The BoundingRect
|
||||
polygons.last().push_back(point); // The polygon thta will be plotted.
|
||||
}
|
||||
setPolygon(boundingPoly);
|
||||
|
@ -425,8 +424,8 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex& topLeft, const QMo
|
|||
if (!seen_cyl[cyl]) {
|
||||
plot_pressure_value(mbar, entry->sec, Qt::AlignRight | Qt::AlignTop);
|
||||
plot_gas_value(mbar, entry->sec, Qt::AlignRight | Qt::AlignBottom,
|
||||
get_o2(&dive->cylinder[cyl].gasmix),
|
||||
get_he(&dive->cylinder[cyl].gasmix));
|
||||
get_o2(&dive->cylinder[cyl].gasmix),
|
||||
get_he(&dive->cylinder[cyl].gasmix));
|
||||
seen_cyl[cyl] = true;
|
||||
}
|
||||
}
|
||||
|
@ -446,7 +445,7 @@ void DiveGasPressureItem::plot_pressure_value(int mbar, int sec, QFlags<Qt::Alig
|
|||
const char *unit;
|
||||
int pressure = get_pressure_units(mbar, &unit);
|
||||
DiveTextItem *text = new DiveTextItem(this);
|
||||
text->setPos(hAxis->posAtValue(sec), vAxis->posAtValue(mbar)-0.5);
|
||||
text->setPos(hAxis->posAtValue(sec), vAxis->posAtValue(mbar) - 0.5);
|
||||
text->setText(QString("%1 %2").arg(pressure).arg(unit));
|
||||
text->setAlignment(flags);
|
||||
text->setBrush(getColor(PRESSURE_TEXT));
|
||||
|
@ -455,9 +454,9 @@ void DiveGasPressureItem::plot_pressure_value(int mbar, int sec, QFlags<Qt::Alig
|
|||
|
||||
void DiveGasPressureItem::plot_gas_value(int mbar, int sec, QFlags<Qt::AlignmentFlag> flags, int o2, int he)
|
||||
{
|
||||
QString gas = (is_air(o2, he)) ? tr("air") :
|
||||
(he == 0) ? QString(tr("EAN%1")).arg((o2 + 5) / 10) :
|
||||
QString("%1/%2").arg((o2 + 5) / 10).arg((he + 5) / 10);
|
||||
QString gas = (is_air(o2, he)) ? tr("air") :
|
||||
(he == 0) ? QString(tr("EAN%1")).arg((o2 + 5) / 10) :
|
||||
QString("%1/%2").arg((o2 + 5) / 10).arg((he + 5) / 10);
|
||||
DiveTextItem *text = new DiveTextItem(this);
|
||||
text->setPos(hAxis->posAtValue(sec), vAxis->posAtValue(mbar));
|
||||
text->setText(gas);
|
||||
|
@ -466,9 +465,9 @@ void DiveGasPressureItem::plot_gas_value(int mbar, int sec, QFlags<Qt::Alignment
|
|||
texts.push_back(text);
|
||||
}
|
||||
|
||||
void DiveGasPressureItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
void DiveGasPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
if(polygon().isEmpty())
|
||||
if (polygon().isEmpty())
|
||||
return;
|
||||
QPen pen;
|
||||
pen.setCosmetic(true);
|
||||
|
@ -477,11 +476,11 @@ void DiveGasPressureItem::paint(QPainter* painter, const QStyleOptionGraphicsIte
|
|||
if (!d)
|
||||
return;
|
||||
struct plot_data *entry = dataModel->data().entry;
|
||||
Q_FOREACH(const QPolygonF& poly, polygons) {
|
||||
Q_FOREACH(const QPolygonF & poly, polygons) {
|
||||
for (int i = 1, count = poly.count(); i < count; i++, entry++) {
|
||||
pen.setBrush(getSacColor(entry->sac, d->sac));
|
||||
painter->setPen(pen);
|
||||
painter->drawLine(poly[i-1],poly[i]);
|
||||
painter->drawLine(poly[i - 1], poly[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -494,7 +493,7 @@ DiveCalculatedCeiling::DiveCalculatedCeiling() : is3mIncrement(false), gradientF
|
|||
preferencesChanged();
|
||||
}
|
||||
|
||||
void DiveCalculatedCeiling::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||
void DiveCalculatedCeiling::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
// We don't have enougth data to calculate things, quit.
|
||||
if (!shouldCalculateStuff(topLeft, bottomRight))
|
||||
|
@ -514,16 +513,16 @@ void DiveCalculatedCeiling::modelDataChanged(const QModelIndex& topLeft, const Q
|
|||
QLinearGradient pat(0, polygon().boundingRect().top(), 0, polygon().boundingRect().bottom());
|
||||
pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW));
|
||||
pat.setColorAt(1, getColor(CALC_CEILING_DEEP));
|
||||
setPen(QPen(QBrush(Qt::NoBrush),0));
|
||||
setPen(QPen(QBrush(Qt::NoBrush), 0));
|
||||
setBrush(pat);
|
||||
|
||||
gradientFactor->setX(poly.boundingRect().width()/2 + poly.boundingRect().x());
|
||||
gradientFactor->setX(poly.boundingRect().width() / 2 + poly.boundingRect().x());
|
||||
gradientFactor->setText(QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh));
|
||||
}
|
||||
|
||||
void DiveCalculatedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
void DiveCalculatedCeiling::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
if(polygon().isEmpty())
|
||||
if (polygon().isEmpty())
|
||||
return;
|
||||
QGraphicsPolygonItem::paint(painter, option, widget);
|
||||
}
|
||||
|
@ -540,9 +539,9 @@ void DiveCalculatedTissue::preferencesChanged()
|
|||
setVisible(s.value("calcalltissues").toBool() && s.value("calcceiling").toBool());
|
||||
}
|
||||
|
||||
void DiveReportedCeiling::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||
void DiveReportedCeiling::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
if(!shouldCalculateStuff(topLeft, bottomRight))
|
||||
if (!shouldCalculateStuff(topLeft, bottomRight))
|
||||
return;
|
||||
|
||||
QPolygonF p;
|
||||
|
@ -563,7 +562,7 @@ void DiveReportedCeiling::modelDataChanged(const QModelIndex& topLeft, const QMo
|
|||
QLinearGradient pat(0, p.boundingRect().top(), 0, p.boundingRect().bottom());
|
||||
pat.setColorAt(0, getColor(CEILING_SHALLOW));
|
||||
pat.setColorAt(1, getColor(CEILING_DEEP));
|
||||
setPen(QPen(QBrush(Qt::NoBrush),0));
|
||||
setPen(QPen(QBrush(Qt::NoBrush), 0));
|
||||
setBrush(pat);
|
||||
}
|
||||
|
||||
|
@ -573,7 +572,7 @@ void DiveCalculatedCeiling::preferencesChanged()
|
|||
s.beginGroup("TecDetails");
|
||||
|
||||
bool shouldShow3mIncrement = s.value("calcceiling3m").toBool();
|
||||
if ( dataModel && is3mIncrement != shouldShow3mIncrement){
|
||||
if (dataModel && is3mIncrement != shouldShow3mIncrement) {
|
||||
// recalculate that part.
|
||||
dataModel->calculateDecompression();
|
||||
}
|
||||
|
@ -588,9 +587,9 @@ void DiveReportedCeiling::preferencesChanged()
|
|||
setVisible(s.value("redceiling").toBool());
|
||||
}
|
||||
|
||||
void DiveReportedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
void DiveReportedCeiling::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
if(polygon().isEmpty())
|
||||
if (polygon().isEmpty())
|
||||
return;
|
||||
QGraphicsPolygonItem::paint(painter, option, widget);
|
||||
}
|
||||
|
@ -619,18 +618,18 @@ void MeanDepthLine::setMeanDepth(int value)
|
|||
meanDepth = value;
|
||||
}
|
||||
|
||||
void MeanDepthLine::setAxis(DiveCartesianAxis* a)
|
||||
void MeanDepthLine::setAxis(DiveCartesianAxis *a)
|
||||
{
|
||||
connect(a, SIGNAL(sizeChanged()), this, SLOT(axisLineChanged()));
|
||||
}
|
||||
|
||||
void MeanDepthLine::axisLineChanged()
|
||||
{
|
||||
DiveCartesianAxis *axis = qobject_cast<DiveCartesianAxis*>(sender());
|
||||
animateMoveTo(x(),axis->posAtValue(meanDepth));
|
||||
DiveCartesianAxis *axis = qobject_cast<DiveCartesianAxis *>(sender());
|
||||
animateMoveTo(x(), axis->posAtValue(meanDepth));
|
||||
}
|
||||
|
||||
void PartialPressureGasItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||
void PartialPressureGasItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
//AbstractProfilePolygonItem::modelDataChanged();
|
||||
if (!shouldCalculateStuff(topLeft, bottomRight))
|
||||
|
@ -642,11 +641,11 @@ void PartialPressureGasItem::modelDataChanged(const QModelIndex& topLeft, const
|
|||
QSettings s;
|
||||
s.beginGroup("TecDetails");
|
||||
double threshould = s.value(threshouldKey).toDouble();
|
||||
for(int i = 0; i < dataModel->rowCount(); i++, entry++){
|
||||
for (int i = 0; i < dataModel->rowCount(); i++, entry++) {
|
||||
double value = dataModel->index(i, vDataColumn).data().toDouble();
|
||||
int time = dataModel->index(i, hDataColumn).data().toInt();
|
||||
QPointF point(hAxis->posAtValue(time), vAxis->posAtValue(value));
|
||||
poly.push_back( point );
|
||||
poly.push_back(point);
|
||||
if (value >= threshould)
|
||||
alertPoly.push_back(point);
|
||||
}
|
||||
|
@ -656,7 +655,7 @@ void PartialPressureGasItem::modelDataChanged(const QModelIndex& topLeft, const
|
|||
*/
|
||||
}
|
||||
|
||||
void PartialPressureGasItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
void PartialPressureGasItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
painter->setPen(normalColor);
|
||||
painter->drawPolyline(polygon());
|
||||
|
@ -664,7 +663,7 @@ void PartialPressureGasItem::paint(QPainter* painter, const QStyleOptionGraphics
|
|||
painter->drawPolyline(alertPoly);
|
||||
}
|
||||
|
||||
void PartialPressureGasItem::setThreshouldSettingsKey(const QString& threshouldSettingsKey)
|
||||
void PartialPressureGasItem::setThreshouldSettingsKey(const QString &threshouldSettingsKey)
|
||||
{
|
||||
threshouldKey = threshouldSettingsKey;
|
||||
}
|
||||
|
@ -677,15 +676,15 @@ void PartialPressureGasItem::preferencesChanged()
|
|||
{
|
||||
QSettings s;
|
||||
s.beginGroup("TecDetails");
|
||||
setVisible( s.value(visibilityKey).toBool() );
|
||||
setVisible(s.value(visibilityKey).toBool());
|
||||
}
|
||||
|
||||
void PartialPressureGasItem::setVisibilitySettingsKey(const QString& key)
|
||||
void PartialPressureGasItem::setVisibilitySettingsKey(const QString &key)
|
||||
{
|
||||
visibilityKey = key;
|
||||
}
|
||||
|
||||
void PartialPressureGasItem::setColors(const QColor& normal, const QColor& alert)
|
||||
void PartialPressureGasItem::setColors(const QColor &normal, const QColor &alert)
|
||||
{
|
||||
normalColor = normal;
|
||||
alertColor = alert;
|
||||
|
|
|
@ -28,7 +28,7 @@ class DiveCartesianAxis;
|
|||
class QAbstractTableModel;
|
||||
struct plot_data;
|
||||
|
||||
class AbstractProfilePolygonItem : public QObject, public QGraphicsPolygonItem{
|
||||
class AbstractProfilePolygonItem : public QObject, public QGraphicsPolygonItem {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QPointF pos WRITE setPos READ pos)
|
||||
Q_PROPERTY(qreal x WRITE setX READ x)
|
||||
|
@ -40,12 +40,16 @@ public:
|
|||
void setModel(DivePlotDataModel *model);
|
||||
void setHorizontalDataColumn(int column);
|
||||
void setVerticalDataColumn(int column);
|
||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) = 0;
|
||||
virtual void clear(){}
|
||||
public slots:
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) = 0;
|
||||
virtual void clear()
|
||||
{
|
||||
}
|
||||
public
|
||||
slots:
|
||||
virtual void preferencesChanged();
|
||||
virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
|
||||
virtual void modelDataRemoved(const QModelIndex& parent, int from, int to);
|
||||
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
|
||||
virtual void modelDataRemoved(const QModelIndex &parent, int from, int to);
|
||||
|
||||
protected:
|
||||
/* when the model emits a 'datachanged' signal, this method below should be used to check if the
|
||||
* modified data affects this particular item ( for example, when setting the '3m increment'
|
||||
|
@ -54,36 +58,38 @@ protected:
|
|||
* into consideration when returning 'true' for "yes, continue the calculation', and 'false' for
|
||||
* 'do not recalculate, we already have the right data.
|
||||
*/
|
||||
bool shouldCalculateStuff(const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||
bool shouldCalculateStuff(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||
|
||||
DiveCartesianAxis *hAxis;
|
||||
DiveCartesianAxis *vAxis;
|
||||
DivePlotDataModel *dataModel;
|
||||
int hDataColumn;
|
||||
int vDataColumn;
|
||||
QList<DiveTextItem*> texts;
|
||||
QList<DiveTextItem *> texts;
|
||||
};
|
||||
|
||||
class DiveProfileItem : public AbstractProfilePolygonItem{
|
||||
class DiveProfileItem : public AbstractProfilePolygonItem {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DiveProfileItem();
|
||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
||||
virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
|
||||
virtual void preferencesChanged();
|
||||
void plot_depth_sample(struct plot_data *entry,QFlags<Qt::AlignmentFlag> flags,const QColor& color);
|
||||
void plot_depth_sample(struct plot_data *entry, QFlags<Qt::AlignmentFlag> flags, const QColor &color);
|
||||
|
||||
private:
|
||||
unsigned int show_reported_ceiling;
|
||||
unsigned int reported_ceiling_in_red;
|
||||
};
|
||||
|
||||
class DiveTemperatureItem : public AbstractProfilePolygonItem{
|
||||
class DiveTemperatureItem : public AbstractProfilePolygonItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiveTemperatureItem();
|
||||
virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
|
||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
||||
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
|
||||
private:
|
||||
void createTextItem(int seconds, int mkelvin);
|
||||
};
|
||||
|
@ -94,41 +100,44 @@ public:
|
|||
DiveHeartrateItem();
|
||||
virtual void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
|
||||
private:
|
||||
void createTextItem(int seconds, int hr);
|
||||
};
|
||||
|
||||
class DiveGasPressureItem : public AbstractProfilePolygonItem{
|
||||
class DiveGasPressureItem : public AbstractProfilePolygonItem {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
|
||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
||||
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
|
||||
private:
|
||||
void plot_pressure_value(int mbar, int sec, QFlags<Qt::AlignmentFlag> align);
|
||||
void plot_gas_value(int mbar, int sec, QFlags<Qt::AlignmentFlag> align, int o2, int he);
|
||||
QVector<QPolygonF> polygons;
|
||||
};
|
||||
|
||||
class DiveCalculatedCeiling : public AbstractProfilePolygonItem{
|
||||
class DiveCalculatedCeiling : public AbstractProfilePolygonItem {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DiveCalculatedCeiling();
|
||||
virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
|
||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
||||
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
virtual void preferencesChanged();
|
||||
|
||||
private:
|
||||
bool is3mIncrement;
|
||||
DiveTextItem *gradientFactor;
|
||||
};
|
||||
|
||||
class DiveReportedCeiling : public AbstractProfilePolygonItem{
|
||||
class DiveReportedCeiling : public AbstractProfilePolygonItem {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
|
||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
||||
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
virtual void preferencesChanged();
|
||||
};
|
||||
|
||||
|
@ -146,24 +155,27 @@ public:
|
|||
void setMeanDepth(int value);
|
||||
void setLine(qreal x1, qreal y1, qreal x2, qreal y2);
|
||||
void setAxis(DiveCartesianAxis *a);
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void axisLineChanged();
|
||||
|
||||
private:
|
||||
int meanDepth;
|
||||
DiveTextItem *leftText;
|
||||
DiveTextItem *rightText;
|
||||
};
|
||||
|
||||
class PartialPressureGasItem : public AbstractProfilePolygonItem{
|
||||
class PartialPressureGasItem : public AbstractProfilePolygonItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PartialPressureGasItem();
|
||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
||||
virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
|
||||
virtual void preferencesChanged();
|
||||
void setThreshouldSettingsKey(const QString& threshouldSettingsKey);
|
||||
void setVisibilitySettingsKey(const QString& setVisibilitySettingsKey);
|
||||
void setColors(const QColor& normalColor, const QColor& alertColor);
|
||||
void setThreshouldSettingsKey(const QString &threshouldSettingsKey);
|
||||
void setVisibilitySettingsKey(const QString &setVisibilitySettingsKey);
|
||||
void setColors(const QColor &normalColor, const QColor &alertColor);
|
||||
|
||||
private:
|
||||
QPolygonF alertPoly;
|
||||
QString threshouldKey;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "diverectitem.h"
|
||||
|
||||
DiveRectItem::DiveRectItem(QObject* parent, QGraphicsItem* parentItem): QObject(parent), QGraphicsRectItem(parentItem )
|
||||
DiveRectItem::DiveRectItem(QObject *parent, QGraphicsItem *parentItem) : QObject(parent), QGraphicsRectItem(parentItem)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QObject>
|
||||
#include <QGraphicsRectItem>
|
||||
|
||||
class DiveRectItem : public QObject, public QGraphicsRectItem{
|
||||
class DiveRectItem : public QObject, public QGraphicsRectItem {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QRectF rect WRITE setRect READ rect)
|
||||
Q_PROPERTY(QPointF pos WRITE setPos READ pos)
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <QPen>
|
||||
#include <QDebug>
|
||||
|
||||
DiveTextItem::DiveTextItem(QGraphicsItem* parent): QGraphicsItemGroup(parent),
|
||||
DiveTextItem::DiveTextItem(QGraphicsItem *parent) : QGraphicsItemGroup(parent),
|
||||
internalAlignFlags(Qt::AlignHCenter | Qt::AlignVCenter),
|
||||
textBackgroundItem(NULL),
|
||||
textItem(NULL),
|
||||
|
@ -25,7 +25,7 @@ void DiveTextItem::setAlignment(int alignFlags)
|
|||
updateText();
|
||||
}
|
||||
|
||||
void DiveTextItem::setBrush(const QBrush& b)
|
||||
void DiveTextItem::setBrush(const QBrush &b)
|
||||
{
|
||||
brush = b;
|
||||
updateText();
|
||||
|
@ -36,13 +36,13 @@ void DiveTextItem::setScale(double newscale)
|
|||
scale = newscale;
|
||||
}
|
||||
|
||||
void DiveTextItem::setText(const QString& t)
|
||||
void DiveTextItem::setText(const QString &t)
|
||||
{
|
||||
internalText = t;
|
||||
updateText();
|
||||
}
|
||||
|
||||
const QString& DiveTextItem::text()
|
||||
const QString &DiveTextItem::text()
|
||||
{
|
||||
return internalText;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ void DiveTextItem::updateText()
|
|||
textItem = NULL;
|
||||
delete textBackgroundItem;
|
||||
textBackgroundItem = NULL;
|
||||
if(internalText.isEmpty()){
|
||||
if (internalText.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -75,14 +75,14 @@ void DiveTextItem::updateText()
|
|||
|
||||
QRectF rect = fm.boundingRect(internalText);
|
||||
yPos = (internalAlignFlags & Qt::AlignTop) ? 0 :
|
||||
(internalAlignFlags & Qt::AlignBottom) ? +rect.height() :
|
||||
/*(internalAlignFlags & Qt::AlignVCenter ? */ +rect.height() / 4;
|
||||
(internalAlignFlags & Qt::AlignBottom) ? +rect.height() :
|
||||
/*(internalAlignFlags & Qt::AlignVCenter ? */ +rect.height() / 4;
|
||||
|
||||
xPos = (internalAlignFlags & Qt::AlignLeft ) ? -rect.width() :
|
||||
(internalAlignFlags & Qt::AlignHCenter) ? -rect.width()/2 :
|
||||
/* (internalAlignFlags & Qt::AlignRight) */ 0;
|
||||
xPos = (internalAlignFlags & Qt::AlignLeft) ? -rect.width() :
|
||||
(internalAlignFlags & Qt::AlignHCenter) ? -rect.width() / 2 :
|
||||
/* (internalAlignFlags & Qt::AlignRight) */ 0;
|
||||
|
||||
textPath.addText( xPos, yPos, fnt, internalText);
|
||||
textPath.addText(xPos, yPos, fnt, internalText);
|
||||
QPainterPathStroker stroker;
|
||||
stroker.setWidth(3);
|
||||
textBackgroundItem = new QGraphicsPathItem(stroker.createStroke(textPath), this);
|
||||
|
|
|
@ -7,19 +7,20 @@
|
|||
#include <QBrush>
|
||||
|
||||
/* A Line Item that has animated-properties. */
|
||||
class DiveTextItem :public QObject, public QGraphicsItemGroup{
|
||||
class DiveTextItem : public QObject, public QGraphicsItemGroup {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
|
||||
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
|
||||
public:
|
||||
DiveTextItem(QGraphicsItem* parent = 0);
|
||||
void setText(const QString& text);
|
||||
DiveTextItem(QGraphicsItem *parent = 0);
|
||||
void setText(const QString &text);
|
||||
void setAlignment(int alignFlags);
|
||||
void setScale(double newscale);
|
||||
void setBrush(const QBrush& brush);
|
||||
void setBrush(const QBrush &brush);
|
||||
void animatedHide();
|
||||
void animateMoveTo(qreal x, qreal y);
|
||||
const QString& text();
|
||||
const QString &text();
|
||||
|
||||
private:
|
||||
void updateText();
|
||||
int internalAlignFlags;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "display.h"
|
||||
#endif
|
||||
|
||||
void ToolTipItem::addToolTip(const QString& toolTip, const QIcon& icon)
|
||||
void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon)
|
||||
{
|
||||
QGraphicsPixmapItem *iconItem = 0;
|
||||
double yValue = title->boundingRect().height() + SPACING;
|
||||
|
@ -25,7 +25,7 @@ void ToolTipItem::addToolTip(const QString& toolTip, const QIcon& icon)
|
|||
yValue += t.second->boundingRect().height();
|
||||
}
|
||||
if (!icon.isNull()) {
|
||||
iconItem = new QGraphicsPixmapItem(icon.pixmap(ICON_SMALL,ICON_SMALL), this);
|
||||
iconItem = new QGraphicsPixmapItem(icon.pixmap(ICON_SMALL, ICON_SMALL), this);
|
||||
iconItem->setPos(SPACING, yValue);
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,8 @@ void ToolTipItem::refresh(struct graphics_context *gc, QPointF pos)
|
|||
addToolTip(QString::fromUtf8(mb.buffer, mb.len));
|
||||
free_buffer(&mb);
|
||||
|
||||
QList<QGraphicsItem*> items = scene()->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder, transform());
|
||||
Q_FOREACH(QGraphicsItem *item, items) {
|
||||
QList<QGraphicsItem *> items = scene()->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder, transform());
|
||||
Q_FOREACH(QGraphicsItem * item, items) {
|
||||
if (!item->toolTip().isEmpty())
|
||||
addToolTip(item->toolTip());
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ void ToolTipItem::clear()
|
|||
toolTips.clear();
|
||||
}
|
||||
|
||||
void ToolTipItem::setRect(const QRectF& r)
|
||||
void ToolTipItem::setRect(const QRectF &r)
|
||||
{
|
||||
// qDeleteAll(childItems());
|
||||
delete background;
|
||||
|
@ -74,8 +74,8 @@ void ToolTipItem::setRect(const QRectF& r)
|
|||
|
||||
// Creates a 2pixels border
|
||||
QPainterPath border;
|
||||
border.addRoundedRect(-4, -4, rectangle.width() + 8, rectangle.height() + 10, 3, 3);
|
||||
border.addRoundedRect(-1, -1, rectangle.width() + 3, rectangle.height() + 4, 3, 3);
|
||||
border.addRoundedRect(-4, -4, rectangle.width() + 8, rectangle.height() + 10, 3, 3);
|
||||
border.addRoundedRect(-1, -1, rectangle.width() + 3, rectangle.height() + 4, 3, 3);
|
||||
setPath(border);
|
||||
|
||||
QPainterPath bg;
|
||||
|
@ -119,10 +119,10 @@ void ToolTipItem::expand()
|
|||
height += t.second->boundingRect().height();
|
||||
}
|
||||
/* Left padding, Icon Size, space, right padding */
|
||||
width += SPACING + ICON_SMALL + SPACING + SPACING;
|
||||
width += SPACING + ICON_SMALL + SPACING + SPACING;
|
||||
|
||||
if (width < title->boundingRect().width() + SPACING*2)
|
||||
width = title->boundingRect().width() + SPACING*2;
|
||||
if (width < title->boundingRect().width() + SPACING * 2)
|
||||
width = title->boundingRect().width() + SPACING * 2;
|
||||
|
||||
if (height < ICON_SMALL)
|
||||
height = ICON_SMALL;
|
||||
|
@ -139,7 +139,7 @@ void ToolTipItem::expand()
|
|||
status = EXPANDED;
|
||||
}
|
||||
|
||||
ToolTipItem::ToolTipItem(QGraphicsItem* parent) : QGraphicsPathItem(parent),
|
||||
ToolTipItem::ToolTipItem(QGraphicsItem *parent) : QGraphicsPathItem(parent),
|
||||
background(0),
|
||||
separator(new QGraphicsLineItem(this)),
|
||||
title(new QGraphicsSimpleTextItem(tr("Information"), this)),
|
||||
|
@ -161,21 +161,21 @@ ToolTipItem::~ToolTipItem()
|
|||
|
||||
void ToolTipItem::updateTitlePosition()
|
||||
{
|
||||
if (rectangle.width() < title->boundingRect().width() + SPACING*4) {
|
||||
if (rectangle.width() < title->boundingRect().width() + SPACING * 4) {
|
||||
QRectF newRect = rectangle;
|
||||
newRect.setWidth(title->boundingRect().width() + SPACING*4);
|
||||
newRect.setWidth(title->boundingRect().width() + SPACING * 4);
|
||||
newRect.setHeight((newRect.height() && isExpanded()) ? newRect.height() : ICON_SMALL);
|
||||
setRect(newRect);
|
||||
}
|
||||
|
||||
title->setPos(boundingRect().width()/2 - title->boundingRect().width()/2 -1, 0);
|
||||
title->setPos(boundingRect().width() / 2 - title->boundingRect().width() / 2 - 1, 0);
|
||||
title->setFlag(ItemIgnoresTransformations);
|
||||
title->setPen(QPen(Qt::white, 1));
|
||||
title->setBrush(Qt::white);
|
||||
|
||||
if (toolTips.size() > 0) {
|
||||
double x1 = 3;
|
||||
double y1 = title->pos().y() + SPACING/2 + title->boundingRect().height();
|
||||
double y1 = title->pos().y() + SPACING / 2 + title->boundingRect().height();
|
||||
double x2 = boundingRect().width() - 10;
|
||||
double y2 = y1;
|
||||
|
||||
|
@ -188,11 +188,12 @@ void ToolTipItem::updateTitlePosition()
|
|||
}
|
||||
}
|
||||
|
||||
bool ToolTipItem::isExpanded() const {
|
||||
bool ToolTipItem::isExpanded() const
|
||||
{
|
||||
return status == EXPANDED;
|
||||
}
|
||||
|
||||
void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
|
||||
void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
persistPos();
|
||||
QGraphicsPathItem::mouseReleaseEvent(event);
|
||||
|
@ -212,27 +213,26 @@ void ToolTipItem::readPos()
|
|||
QSettings s;
|
||||
s.beginGroup("ProfileMap");
|
||||
QPointF value = scene()->views().at(0)->mapToScene(
|
||||
s.value("tooltip_position").toPoint()
|
||||
);
|
||||
s.value("tooltip_position").toPoint());
|
||||
if (!scene()->sceneRect().contains(value)) {
|
||||
value = QPointF(0,0);
|
||||
value = QPointF(0, 0);
|
||||
}
|
||||
setPos(value);
|
||||
}
|
||||
|
||||
void ToolTipItem::setPlotInfo(const plot_info& plot)
|
||||
void ToolTipItem::setPlotInfo(const plot_info &plot)
|
||||
{
|
||||
pInfo = plot;
|
||||
}
|
||||
|
||||
void ToolTipItem::setTimeAxis(DiveCartesianAxis* axis)
|
||||
void ToolTipItem::setTimeAxis(DiveCartesianAxis *axis)
|
||||
{
|
||||
timeAxis = axis;
|
||||
}
|
||||
|
||||
void ToolTipItem::refresh(const QPointF& pos)
|
||||
void ToolTipItem::refresh(const QPointF &pos)
|
||||
{
|
||||
int time = timeAxis->valueAt( pos );
|
||||
int time = timeAxis->valueAt(pos);
|
||||
if (time == lastTime)
|
||||
return;
|
||||
|
||||
|
@ -244,8 +244,8 @@ void ToolTipItem::refresh(const QPointF& pos)
|
|||
addToolTip(QString::fromUtf8(mb.buffer, mb.len));
|
||||
free_buffer(&mb);
|
||||
|
||||
QList<QGraphicsItem*> items = scene()->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder, scene()->views().first()->transform());
|
||||
Q_FOREACH(QGraphicsItem *item, items) {
|
||||
QList<QGraphicsItem *> items = scene()->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder, scene()->views().first()->transform());
|
||||
Q_FOREACH(QGraphicsItem * item, items) {
|
||||
if (!item->toolTip().isEmpty())
|
||||
addToolTip(item->toolTip());
|
||||
}
|
||||
|
|
|
@ -17,36 +17,44 @@ struct graphics_context;
|
|||
/* To use a tooltip, simply ->setToolTip on the QGraphicsItem that you want
|
||||
* or, if it's a "global" tooltip, set it on the mouseMoveEvent of the ProfileGraphicsView.
|
||||
*/
|
||||
class ToolTipItem :public QObject, public QGraphicsPathItem
|
||||
{
|
||||
class ToolTipItem : public QObject, public QGraphicsPathItem {
|
||||
Q_OBJECT
|
||||
void updateTitlePosition();
|
||||
Q_PROPERTY(QRectF rect READ boundingRect WRITE setRect)
|
||||
|
||||
public:
|
||||
enum Status{COLLAPSED, EXPANDED};
|
||||
enum {ICON_SMALL = 16, ICON_MEDIUM = 24, ICON_BIG = 32, SPACING=4};
|
||||
enum Status {
|
||||
COLLAPSED,
|
||||
EXPANDED
|
||||
};
|
||||
enum {
|
||||
ICON_SMALL = 16,
|
||||
ICON_MEDIUM = 24,
|
||||
ICON_BIG = 32,
|
||||
SPACING = 4
|
||||
};
|
||||
|
||||
explicit ToolTipItem(QGraphicsItem* parent = 0);
|
||||
explicit ToolTipItem(QGraphicsItem *parent = 0);
|
||||
virtual ~ToolTipItem();
|
||||
|
||||
void collapse();
|
||||
void expand();
|
||||
void clear();
|
||||
void addToolTip(const QString& toolTip, const QIcon& icon = QIcon());
|
||||
void refresh(struct graphics_context* gc, QPointF pos);
|
||||
void refresh(const QPointF& pos);
|
||||
void addToolTip(const QString &toolTip, const QIcon &icon = QIcon());
|
||||
void refresh(struct graphics_context *gc, QPointF pos);
|
||||
void refresh(const QPointF &pos);
|
||||
bool isExpanded() const;
|
||||
void persistPos();
|
||||
void readPos();
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
void setTimeAxis(DiveCartesianAxis *axis);
|
||||
void setPlotInfo(const plot_info& plot);
|
||||
public slots:
|
||||
void setRect(const QRectF& rect);
|
||||
void setPlotInfo(const plot_info &plot);
|
||||
public
|
||||
slots:
|
||||
void setRect(const QRectF &rect);
|
||||
|
||||
private:
|
||||
typedef QPair<QGraphicsPixmapItem*, QGraphicsSimpleTextItem*> ToolTip;
|
||||
typedef QPair<QGraphicsPixmapItem *, QGraphicsSimpleTextItem *> ToolTip;
|
||||
QVector<ToolTip> toolTips;
|
||||
QGraphicsPathItem *background;
|
||||
QGraphicsLineItem *separator;
|
||||
|
|
|
@ -35,15 +35,15 @@
|
|||
* hard coding the item on the scene with a random
|
||||
* value.
|
||||
*/
|
||||
static struct _ItemPos{
|
||||
struct _Pos{
|
||||
static struct _ItemPos {
|
||||
struct _Pos {
|
||||
QPointF on;
|
||||
QPointF off;
|
||||
};
|
||||
struct _Axis{
|
||||
_Pos pos;
|
||||
QLineF shrinked;
|
||||
QLineF expanded;
|
||||
struct _Axis {
|
||||
_Pos pos;
|
||||
QLineF shrinked;
|
||||
QLineF expanded;
|
||||
};
|
||||
_Pos background;
|
||||
_Pos dcLabel;
|
||||
|
@ -55,12 +55,11 @@ static struct _ItemPos{
|
|||
_Axis heartBeat;
|
||||
} itemPos;
|
||||
|
||||
ProfileWidget2::ProfileWidget2(QWidget *parent) :
|
||||
QGraphicsView(parent),
|
||||
ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
|
||||
dataModel(new DivePlotDataModel(this)),
|
||||
currentState(INVALID),
|
||||
zoomLevel(0),
|
||||
background (new DivePixmapItem()),
|
||||
background(new DivePixmapItem()),
|
||||
toolTipItem(new ToolTipItem()),
|
||||
profileYAxis(new DepthAxis()),
|
||||
gasYAxis(new PartialGasPressureAxis()),
|
||||
|
@ -74,9 +73,9 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
|
|||
diveComputerText(new DiveTextItem()),
|
||||
diveCeiling(new DiveCalculatedCeiling()),
|
||||
reportedCeiling(new DiveReportedCeiling()),
|
||||
pn2GasItem( new PartialPressureGasItem()),
|
||||
pheGasItem( new PartialPressureGasItem()),
|
||||
po2GasItem( new PartialPressureGasItem()),
|
||||
pn2GasItem(new PartialPressureGasItem()),
|
||||
pheGasItem(new PartialPressureGasItem()),
|
||||
po2GasItem(new PartialPressureGasItem()),
|
||||
heartBeatAxis(new DiveCartesianAxis()),
|
||||
heartBeatItem(new DiveHeartrateItem()),
|
||||
isPlotZoomed(prefs.zoomed_plot),
|
||||
|
@ -123,7 +122,7 @@ void ProfileWidget2::addItemsToScene()
|
|||
scene()->addItem(rulerItem);
|
||||
scene()->addItem(rulerItem->sourceNode());
|
||||
scene()->addItem(rulerItem->destNode());
|
||||
Q_FOREACH(DiveCalculatedTissue *tissue, allTissues){
|
||||
Q_FOREACH(DiveCalculatedTissue * tissue, allTissues) {
|
||||
scene()->addItem(tissue);
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +134,7 @@ void ProfileWidget2::setupItemOnScene()
|
|||
|
||||
profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom);
|
||||
profileYAxis->setMinimum(0);
|
||||
profileYAxis->setTickInterval(M_OR_FT(10,30));
|
||||
profileYAxis->setTickInterval(M_OR_FT(10, 30));
|
||||
profileYAxis->setTickSize(1);
|
||||
profileYAxis->setLineSize(96);
|
||||
|
||||
|
@ -163,7 +162,7 @@ void ProfileWidget2::setupItemOnScene()
|
|||
cylinderPressureAxis->setTickSize(2);
|
||||
cylinderPressureAxis->setTickInterval(30000);
|
||||
|
||||
meanDepth->setLine(0,0,96,0);
|
||||
meanDepth->setLine(0, 0, 96, 0);
|
||||
meanDepth->setX(3);
|
||||
meanDepth->setPen(QPen(QBrush(Qt::red), 0, Qt::SolidLine));
|
||||
meanDepth->setZValue(1);
|
||||
|
@ -176,9 +175,9 @@ void ProfileWidget2::setupItemOnScene()
|
|||
|
||||
setupItem(reportedCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1);
|
||||
setupItem(diveCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1);
|
||||
for(int i = 0; i < 16; i++){
|
||||
for (int i = 0; i < 16; i++) {
|
||||
DiveCalculatedTissue *tissueItem = new DiveCalculatedTissue();
|
||||
setupItem(tissueItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::TISSUE_1 + i, DivePlotDataModel::TIME, 1+i);
|
||||
setupItem(tissueItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::TISSUE_1 + i, DivePlotDataModel::TIME, 1 + i);
|
||||
allTissues.append(tissueItem);
|
||||
}
|
||||
setupItem(gasPressureItem, timeAxis, cylinderPressureAxis, dataModel, DivePlotDataModel::TEMPERATURE, DivePlotDataModel::TIME, 1);
|
||||
|
@ -186,17 +185,17 @@ void ProfileWidget2::setupItemOnScene()
|
|||
setupItem(heartBeatItem, timeAxis, heartBeatAxis, dataModel, DivePlotDataModel::HEARTBEAT, DivePlotDataModel::TIME, 1);
|
||||
setupItem(diveProfileItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::DEPTH, DivePlotDataModel::TIME, 0);
|
||||
|
||||
#define CREATE_PP_GAS( ITEM, VERTICAL_COLUMN, COLOR, COLOR_ALERT, THRESHOULD_SETTINGS, VISIBILITY_SETTINGS ) \
|
||||
#define CREATE_PP_GAS(ITEM, VERTICAL_COLUMN, COLOR, COLOR_ALERT, THRESHOULD_SETTINGS, VISIBILITY_SETTINGS) \
|
||||
setupItem(ITEM, timeAxis, gasYAxis, dataModel, DivePlotDataModel::VERTICAL_COLUMN, DivePlotDataModel::TIME, 0); \
|
||||
ITEM->setThreshouldSettingsKey(THRESHOULD_SETTINGS); \
|
||||
ITEM->setVisibilitySettingsKey(VISIBILITY_SETTINGS); \
|
||||
ITEM->setColors(getColor(COLOR), getColor(COLOR_ALERT)); \
|
||||
ITEM->preferencesChanged(); \
|
||||
ITEM->setThreshouldSettingsKey(THRESHOULD_SETTINGS); \
|
||||
ITEM->setVisibilitySettingsKey(VISIBILITY_SETTINGS); \
|
||||
ITEM->setColors(getColor(COLOR), getColor(COLOR_ALERT)); \
|
||||
ITEM->preferencesChanged(); \
|
||||
ITEM->setZValue(99);
|
||||
|
||||
CREATE_PP_GAS( pn2GasItem, PN2, PN2, PN2_ALERT, "pn2threshold", "pn2graph");
|
||||
CREATE_PP_GAS( pheGasItem, PHE, PHE, PHE_ALERT, "phethreshold", "phegraph");
|
||||
CREATE_PP_GAS( po2GasItem, PO2, PO2, PO2_ALERT, "po2threshold", "po2graph");
|
||||
CREATE_PP_GAS(pn2GasItem, PN2, PN2, PN2_ALERT, "pn2threshold", "pn2graph");
|
||||
CREATE_PP_GAS(pheGasItem, PHE, PHE, PHE_ALERT, "phethreshold", "phegraph");
|
||||
CREATE_PP_GAS(po2GasItem, PO2, PO2, PO2_ALERT, "po2threshold", "po2graph");
|
||||
#undef CREATE_PP_GAS
|
||||
|
||||
temperatureAxis->setTextVisible(false);
|
||||
|
@ -205,7 +204,7 @@ void ProfileWidget2::setupItemOnScene()
|
|||
cylinderPressureAxis->setLinesVisible(false);
|
||||
timeAxis->setLinesVisible(true);
|
||||
profileYAxis->setLinesVisible(true);
|
||||
gasYAxis->setZValue(timeAxis->zValue()+1);
|
||||
gasYAxis->setZValue(timeAxis->zValue() + 1);
|
||||
heartBeatAxis->setTextVisible(true);
|
||||
heartBeatAxis->setLinesVisible(true);
|
||||
}
|
||||
|
@ -229,51 +228,51 @@ void ProfileWidget2::setupItemSizes()
|
|||
itemPos.depth.pos.on.setY(3);
|
||||
itemPos.depth.pos.off.setX(-2);
|
||||
itemPos.depth.pos.off.setY(3);
|
||||
itemPos.depth.expanded.setP1(QPointF(0,0));
|
||||
itemPos.depth.expanded.setP2(QPointF(0,86));
|
||||
itemPos.depth.shrinked.setP1(QPointF(0,0));
|
||||
itemPos.depth.shrinked.setP2(QPointF(0,60));
|
||||
itemPos.depth.expanded.setP1(QPointF(0, 0));
|
||||
itemPos.depth.expanded.setP2(QPointF(0, 86));
|
||||
itemPos.depth.shrinked.setP1(QPointF(0, 0));
|
||||
itemPos.depth.shrinked.setP2(QPointF(0, 60));
|
||||
|
||||
// Time Axis Config
|
||||
itemPos.time.pos.on.setX(3);
|
||||
itemPos.time.pos.on.setY(95);
|
||||
itemPos.time.pos.off.setX(3);
|
||||
itemPos.time.pos.off.setY(110);
|
||||
itemPos.time.expanded.setP1(QPointF(0,0));
|
||||
itemPos.time.expanded.setP2(QPointF(94,0));
|
||||
itemPos.time.expanded.setP1(QPointF(0, 0));
|
||||
itemPos.time.expanded.setP2(QPointF(94, 0));
|
||||
|
||||
// Partial Gas Axis Config
|
||||
itemPos.partialPressure.pos.on.setX(97);
|
||||
itemPos.partialPressure.pos.on.setY(65);
|
||||
itemPos.partialPressure.pos.off.setX(110);
|
||||
itemPos.partialPressure.pos.off.setY(63);
|
||||
itemPos.partialPressure.expanded.setP1(QPointF(0,0));
|
||||
itemPos.partialPressure.expanded.setP2(QPointF(0,30));
|
||||
itemPos.partialPressure.expanded.setP1(QPointF(0, 0));
|
||||
itemPos.partialPressure.expanded.setP2(QPointF(0, 30));
|
||||
|
||||
// cylinder axis config
|
||||
itemPos.cylinder.pos.on.setX(3);
|
||||
itemPos.cylinder.pos.on.setY(20);
|
||||
itemPos.cylinder.pos.off.setX(-10);
|
||||
itemPos.cylinder.pos.off.setY(20);
|
||||
itemPos.cylinder.expanded.setP1(QPointF(0,15));
|
||||
itemPos.cylinder.expanded.setP2(QPointF(0,50));
|
||||
itemPos.cylinder.shrinked.setP1(QPointF(0,0));
|
||||
itemPos.cylinder.shrinked.setP2(QPointF(0,20));
|
||||
itemPos.cylinder.expanded.setP1(QPointF(0, 15));
|
||||
itemPos.cylinder.expanded.setP2(QPointF(0, 50));
|
||||
itemPos.cylinder.shrinked.setP1(QPointF(0, 0));
|
||||
itemPos.cylinder.shrinked.setP2(QPointF(0, 20));
|
||||
|
||||
// Temperature axis config
|
||||
itemPos.temperature.pos.on.setX(3);
|
||||
itemPos.temperature.pos.on.setY(40);
|
||||
itemPos.temperature.pos.off.setX(-10);
|
||||
itemPos.temperature.pos.off.setY(40);
|
||||
itemPos.temperature.expanded.setP1(QPointF(0,30));
|
||||
itemPos.temperature.expanded.setP2(QPointF(0,50));
|
||||
itemPos.temperature.shrinked.setP1(QPointF(0,5));
|
||||
itemPos.temperature.shrinked.setP2(QPointF(0,15));
|
||||
itemPos.temperature.expanded.setP1(QPointF(0, 30));
|
||||
itemPos.temperature.expanded.setP2(QPointF(0, 50));
|
||||
itemPos.temperature.shrinked.setP1(QPointF(0, 5));
|
||||
itemPos.temperature.shrinked.setP2(QPointF(0, 15));
|
||||
|
||||
itemPos.heartBeat.pos.on.setX(3);
|
||||
itemPos.heartBeat.pos.on.setY(60);
|
||||
itemPos.heartBeat.expanded.setP1(QPointF(0,0));
|
||||
itemPos.heartBeat.expanded.setP2(QPointF(0,20));
|
||||
itemPos.heartBeat.expanded.setP1(QPointF(0, 0));
|
||||
itemPos.heartBeat.expanded.setP2(QPointF(0, 20));
|
||||
|
||||
itemPos.dcLabel.on.setX(3);
|
||||
itemPos.dcLabel.on.setY(100);
|
||||
|
@ -281,7 +280,7 @@ void ProfileWidget2::setupItemSizes()
|
|||
itemPos.dcLabel.off.setY(100);
|
||||
}
|
||||
|
||||
void ProfileWidget2::setupItem(AbstractProfilePolygonItem* item, DiveCartesianAxis* hAxis, DiveCartesianAxis* vAxis, DivePlotDataModel* model, int vData, int hData, int zValue)
|
||||
void ProfileWidget2::setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis, DivePlotDataModel *model, int vData, int hData, int zValue)
|
||||
{
|
||||
item->setHorizontalAxis(hAxis);
|
||||
item->setVerticalAxis(vAxis);
|
||||
|
@ -306,7 +305,7 @@ void ProfileWidget2::setupSceneAndFlags()
|
|||
}
|
||||
|
||||
// Currently just one dive, but the plan is to enable All of the selected dives.
|
||||
void ProfileWidget2::plotDives(QList<dive*> dives)
|
||||
void ProfileWidget2::plotDives(QList<dive *> dives)
|
||||
{
|
||||
// I Know that it's a list, but currently we are
|
||||
// using just the first.
|
||||
|
@ -368,7 +367,7 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
|
|||
timeAxis->setMaximum(maxtime);
|
||||
rulerItem->setPlotInfo(pInfo);
|
||||
int i, incr;
|
||||
static int increments[8] = { 10, 20, 30, 60, 5*60, 10*60, 15*60, 30*60 };
|
||||
static int increments[8] = { 10, 20, 30, 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60 };
|
||||
/* Time markers: at most every 10 seconds, but no more than 12 markers.
|
||||
* We start out with 10 seconds and increment up to 30 minutes,
|
||||
* depending on the dive time.
|
||||
|
@ -387,7 +386,7 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
|
|||
cylinderPressureAxis->setMinimum(pInfo.minpressure);
|
||||
cylinderPressureAxis->setMaximum(pInfo.maxpressure);
|
||||
meanDepth->setMeanDepth(pInfo.meandepth);
|
||||
meanDepth->setLine(0,0,timeAxis->posAtValue(d->duration.seconds),0);
|
||||
meanDepth->setLine(0, 0, timeAxis->posAtValue(d->duration.seconds), 0);
|
||||
meanDepth->animateMoveTo(3, profileYAxis->posAtValue(pInfo.meandepth));
|
||||
|
||||
dataModel->emitDataChanged();
|
||||
|
@ -409,7 +408,7 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
|
|||
event = event->next;
|
||||
}
|
||||
// Only set visible the ones that should be visible, but how?
|
||||
Q_FOREACH(DiveEventItem *event, eventItems){
|
||||
Q_FOREACH(DiveEventItem * event, eventItems) {
|
||||
event->setVisible(true);
|
||||
// qDebug() << event->getEvent()->name << "@" << event->getEvent()->time.seconds;
|
||||
}
|
||||
|
@ -420,35 +419,35 @@ void ProfileWidget2::settingsChanged()
|
|||
{
|
||||
QSettings s;
|
||||
s.beginGroup("TecDetails");
|
||||
if(s.value("phegraph").toBool()|| s.value("po2graph").toBool()|| s.value("pn2graph").toBool()){
|
||||
if (s.value("phegraph").toBool() || s.value("po2graph").toBool() || s.value("pn2graph").toBool()) {
|
||||
profileYAxis->animateChangeLine(itemPos.depth.shrinked);
|
||||
temperatureAxis->animateChangeLine(itemPos.temperature.shrinked);
|
||||
cylinderPressureAxis->animateChangeLine(itemPos.cylinder.shrinked);
|
||||
}else{
|
||||
} else {
|
||||
profileYAxis->animateChangeLine(itemPos.depth.expanded);
|
||||
temperatureAxis->animateChangeLine(itemPos.temperature.expanded);
|
||||
cylinderPressureAxis->animateChangeLine(itemPos.cylinder.expanded);
|
||||
}
|
||||
if(s.value("zoomed_plot").toBool() != isPlotZoomed){
|
||||
if (s.value("zoomed_plot").toBool() != isPlotZoomed) {
|
||||
isPlotZoomed = s.value("zoomed_plot").toBool();
|
||||
int diveId = dataModel->id();
|
||||
dataModel->clear();
|
||||
plotDives(QList<dive*>() << getDiveById(diveId));
|
||||
plotDives(QList<dive *>() << getDiveById(diveId));
|
||||
}
|
||||
|
||||
if(currentState == PROFILE){
|
||||
if (currentState == PROFILE) {
|
||||
bool rulerVisible = s.value("rulergraph", false).toBool();
|
||||
rulerItem->setVisible(rulerVisible);
|
||||
rulerItem->destNode()->setVisible(rulerVisible );
|
||||
rulerItem->sourceNode()->setVisible(rulerVisible );
|
||||
}else{
|
||||
rulerItem->destNode()->setVisible(rulerVisible);
|
||||
rulerItem->sourceNode()->setVisible(rulerVisible);
|
||||
} else {
|
||||
rulerItem->setVisible(false);
|
||||
rulerItem->destNode()->setVisible(false);
|
||||
rulerItem->sourceNode()->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ProfileWidget2::resizeEvent(QResizeEvent* event)
|
||||
void ProfileWidget2::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QGraphicsView::resizeEvent(event);
|
||||
fitInView(sceneRect(), Qt::IgnoreAspectRatio);
|
||||
|
@ -457,10 +456,10 @@ void ProfileWidget2::resizeEvent(QResizeEvent* event)
|
|||
|
||||
void ProfileWidget2::fixBackgroundPos()
|
||||
{
|
||||
if(currentState != EMPTY)
|
||||
if (currentState != EMPTY)
|
||||
return;
|
||||
QPixmap toBeScaled;
|
||||
if (!backgrounds.keys().contains(backgroundFile)){
|
||||
if (!backgrounds.keys().contains(backgroundFile)) {
|
||||
backgrounds[backgroundFile] = QPixmap(backgroundFile);
|
||||
}
|
||||
toBeScaled = backgrounds[backgroundFile];
|
||||
|
@ -470,7 +469,7 @@ void ProfileWidget2::fixBackgroundPos()
|
|||
background->setX(mapToScene(x, 0).x());
|
||||
}
|
||||
|
||||
void ProfileWidget2::wheelEvent(QWheelEvent* event)
|
||||
void ProfileWidget2::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
QPoint toolTipPos = mapFromScene(toolTipItem->pos());
|
||||
double scaleFactor = 1.15;
|
||||
|
@ -486,9 +485,9 @@ void ProfileWidget2::wheelEvent(QWheelEvent* event)
|
|||
toolTipItem->setPos(mapToScene(toolTipPos));
|
||||
}
|
||||
|
||||
void ProfileWidget2::scrollViewTo(const QPoint& pos)
|
||||
void ProfileWidget2::scrollViewTo(const QPoint &pos)
|
||||
{
|
||||
/* since we cannot use translate() directly on the scene we hack on
|
||||
/* since we cannot use translate() directly on the scene we hack on
|
||||
* the scroll bars (hidden) functionality */
|
||||
if (!zoomLevel)
|
||||
return;
|
||||
|
@ -500,7 +499,7 @@ void ProfileWidget2::scrollViewTo(const QPoint& pos)
|
|||
hs->setValue(xRat * hs->maximum());
|
||||
}
|
||||
|
||||
void ProfileWidget2::mouseMoveEvent(QMouseEvent* event)
|
||||
void ProfileWidget2::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
toolTipItem->refresh(mapToScene(event->pos()));
|
||||
QPoint toolTipPos = mapFromScene(toolTipItem->pos());
|
||||
|
@ -514,8 +513,8 @@ void ProfileWidget2::mouseMoveEvent(QMouseEvent* event)
|
|||
|
||||
bool ProfileWidget2::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
QGraphicsScene *s = qobject_cast<QGraphicsScene*>(object);
|
||||
if (s && event->type() == QEvent::GraphicsSceneHelp){
|
||||
QGraphicsScene *s = qobject_cast<QGraphicsScene *>(object);
|
||||
if (s && event->type() == QEvent::GraphicsSceneHelp) {
|
||||
event->ignore();
|
||||
return true;
|
||||
}
|
||||
|
@ -529,13 +528,13 @@ void ProfileWidget2::setEmptyState()
|
|||
return;
|
||||
|
||||
dataModel->clear();
|
||||
backgroundFile = QString(":poster%1").arg( rand()%3 +1);
|
||||
backgroundFile = QString(":poster%1").arg(rand() % 3 + 1);
|
||||
currentState = EMPTY;
|
||||
fixBackgroundPos();
|
||||
profileYAxis->setPos(itemPos.depth.pos.off);
|
||||
gasYAxis->setPos(itemPos.partialPressure.pos.off);
|
||||
timeAxis->setPos(itemPos.time.pos.off);
|
||||
background->setY( itemPos.background.on.y());
|
||||
background->setY(itemPos.background.on.y());
|
||||
background->setVisible(true);
|
||||
toolTipItem->setVisible(false);
|
||||
temperatureAxis->setPos(itemPos.temperature.pos.off);
|
||||
|
@ -547,10 +546,10 @@ void ProfileWidget2::setEmptyState()
|
|||
rulerItem->setVisible(false);
|
||||
rulerItem->destNode()->setVisible(false);
|
||||
rulerItem->sourceNode()->setVisible(false);
|
||||
Q_FOREACH(DiveCalculatedTissue *tissue, allTissues){
|
||||
Q_FOREACH(DiveCalculatedTissue * tissue, allTissues) {
|
||||
tissue->setVisible(false);
|
||||
}
|
||||
Q_FOREACH(DiveEventItem *event, eventItems){
|
||||
Q_FOREACH(DiveEventItem * event, eventItems) {
|
||||
event->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
@ -570,11 +569,11 @@ void ProfileWidget2::setProfileState()
|
|||
profileYAxis->setPos(itemPos.depth.pos.on);
|
||||
QSettings s;
|
||||
s.beginGroup("TecDetails");
|
||||
if(s.value("phegraph").toBool()|| s.value("po2graph").toBool()|| s.value("pn2graph").toBool()){
|
||||
if (s.value("phegraph").toBool() || s.value("po2graph").toBool() || s.value("pn2graph").toBool()) {
|
||||
profileYAxis->setLine(itemPos.depth.shrinked);
|
||||
temperatureAxis->setLine(itemPos.temperature.shrinked);
|
||||
cylinderPressureAxis->setLine(itemPos.cylinder.shrinked);
|
||||
}else{
|
||||
} else {
|
||||
profileYAxis->setLine(itemPos.depth.expanded);
|
||||
temperatureAxis->setLine(itemPos.temperature.expanded);
|
||||
cylinderPressureAxis->setLine(itemPos.cylinder.expanded);
|
||||
|
@ -598,23 +597,23 @@ void ProfileWidget2::setProfileState()
|
|||
diveCeiling->setVisible(s.value("calcceiling").toBool());
|
||||
reportedCeiling->setVisible(s.value("dcceiling").toBool());
|
||||
|
||||
if(s.value("calcalltissues").toBool()){
|
||||
Q_FOREACH(DiveCalculatedTissue *tissue, allTissues){
|
||||
if (s.value("calcalltissues").toBool()) {
|
||||
Q_FOREACH(DiveCalculatedTissue * tissue, allTissues) {
|
||||
tissue->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
bool rulerVisible = s.value("rulergraph", false).toBool();
|
||||
rulerItem->setVisible(rulerVisible);
|
||||
rulerItem->destNode()->setVisible(rulerVisible );
|
||||
rulerItem->sourceNode()->setVisible(rulerVisible );
|
||||
rulerItem->destNode()->setVisible(rulerVisible);
|
||||
rulerItem->sourceNode()->setVisible(rulerVisible);
|
||||
}
|
||||
|
||||
extern struct ev_select *ev_namelist;
|
||||
extern int evn_allocated;
|
||||
extern int evn_used;
|
||||
|
||||
void ProfileWidget2::contextMenuEvent(QContextMenuEvent* event)
|
||||
void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
if (selected_dive == -1)
|
||||
return;
|
||||
|
@ -625,26 +624,26 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent* event)
|
|||
int rowCount = model->rowCount();
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
QAction *action = new QAction(&m);
|
||||
action->setText( model->data(model->index(i, 0),Qt::DisplayRole).toString());
|
||||
action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString());
|
||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas()));
|
||||
action->setData(event->globalPos());
|
||||
gasChange->addAction(action);
|
||||
}
|
||||
QAction *action = m.addAction(tr("Add Bookmark"), this, SLOT(addBookmark()));
|
||||
action->setData(event->globalPos());
|
||||
QList<QGraphicsItem*> itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos())));
|
||||
Q_FOREACH(QGraphicsItem *i, itemsAtPos) {
|
||||
EventItem *item = dynamic_cast<EventItem*>(i);
|
||||
QList<QGraphicsItem *> itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos())));
|
||||
Q_FOREACH(QGraphicsItem * i, itemsAtPos) {
|
||||
EventItem *item = dynamic_cast<EventItem *>(i);
|
||||
if (!item)
|
||||
continue;
|
||||
action = new QAction(&m);
|
||||
action->setText(tr("Remove Event"));
|
||||
action->setData(QVariant::fromValue<void*>(item)); // so we know what to remove.
|
||||
action->setData(QVariant::fromValue<void *>(item)); // so we know what to remove.
|
||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(removeEvent()));
|
||||
m.addAction(action);
|
||||
action = new QAction(&m);
|
||||
action->setText(tr("Hide similar events"));
|
||||
action->setData(QVariant::fromValue<void*>(item));
|
||||
action->setData(QVariant::fromValue<void *>(item));
|
||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(hideEvents()));
|
||||
m.addAction(action);
|
||||
break;
|
||||
|
@ -665,7 +664,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent* event)
|
|||
|
||||
void ProfileWidget2::changeGas()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction*>(sender());
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
|
||||
QString gas = action->text();
|
||||
// backup the things on the dataModel, since we will clear that out.
|
||||
|
@ -684,5 +683,5 @@ void ProfileWidget2::changeGas()
|
|||
// force the redraw of the dive.
|
||||
//TODO: find a way to make this do not need a full redraw
|
||||
dataModel->clear();
|
||||
plotDives(QList<dive*>() << getDiveById(diveId));
|
||||
plotDives(QList<dive *>() << getDiveById(diveId));
|
||||
}
|
||||
|
|
|
@ -44,32 +44,50 @@ class AbstractProfilePolygonItem;
|
|||
class ProfileWidget2 : public QGraphicsView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum State{ EMPTY, PROFILE, EDIT, ADD, PLAN, INVALID };
|
||||
enum Items{BACKGROUND, PROFILE_Y_AXIS, GAS_Y_AXIS, TIME_AXIS, DEPTH_CONTROLLER, TIME_CONTROLLER, COLUMNS};
|
||||
enum State {
|
||||
EMPTY,
|
||||
PROFILE,
|
||||
EDIT,
|
||||
ADD,
|
||||
PLAN,
|
||||
INVALID
|
||||
};
|
||||
enum Items {
|
||||
BACKGROUND,
|
||||
PROFILE_Y_AXIS,
|
||||
GAS_Y_AXIS,
|
||||
TIME_AXIS,
|
||||
DEPTH_CONTROLLER,
|
||||
TIME_CONTROLLER,
|
||||
COLUMNS
|
||||
};
|
||||
|
||||
ProfileWidget2(QWidget *parent);
|
||||
void plotDives(QList<dive*> dives);
|
||||
virtual bool eventFilter(QObject*, QEvent*);
|
||||
void setupItem( AbstractProfilePolygonItem *item, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis, DivePlotDataModel *model, int vData, int hData, int zValue);
|
||||
void plotDives(QList<dive *> dives);
|
||||
virtual bool eventFilter(QObject *, QEvent *);
|
||||
void setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis, DivePlotDataModel *model, int vData, int hData, int zValue);
|
||||
|
||||
public slots: // Necessary to call from QAction's signals.
|
||||
public
|
||||
slots: // Necessary to call from QAction's signals.
|
||||
void settingsChanged();
|
||||
void setEmptyState();
|
||||
void setProfileState();
|
||||
void changeGas();
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent* event);
|
||||
virtual void wheelEvent(QWheelEvent* event);
|
||||
virtual void mouseMoveEvent(QMouseEvent* event);
|
||||
virtual void contextMenuEvent(QContextMenuEvent* event);
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
virtual void wheelEvent(QWheelEvent *event);
|
||||
virtual void mouseMoveEvent(QMouseEvent *event);
|
||||
virtual void contextMenuEvent(QContextMenuEvent *event);
|
||||
|
||||
private: /*methods*/
|
||||
void fixBackgroundPos();
|
||||
void scrollViewTo(const QPoint& pos);
|
||||
void scrollViewTo(const QPoint &pos);
|
||||
void setupSceneAndFlags();
|
||||
void setupItemSizes();
|
||||
void addItemsToScene();
|
||||
void setupItemOnScene();
|
||||
|
||||
private:
|
||||
DivePlotDataModel *dataModel;
|
||||
State currentState;
|
||||
|
@ -92,10 +110,10 @@ private:
|
|||
DiveCartesianAxis *cylinderPressureAxis;
|
||||
DiveGasPressureItem *gasPressureItem;
|
||||
MeanDepthLine *meanDepth;
|
||||
QList<DiveEventItem*> eventItems;
|
||||
QList<DiveEventItem *> eventItems;
|
||||
DiveTextItem *diveComputerText;
|
||||
DiveCalculatedCeiling *diveCeiling;
|
||||
QList<DiveCalculatedTissue*> allTissues;
|
||||
QList<DiveCalculatedTissue *> allTissues;
|
||||
DiveReportedCeiling *reportedCeiling;
|
||||
PartialPressureGasItem *pn2GasItem;
|
||||
PartialPressureGasItem *pheGasItem;
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
#include "profile.h"
|
||||
#include "display.h"
|
||||
|
||||
RulerNodeItem2::RulerNodeItem2(struct plot_info& info) : pInfo(info), entry(NULL) , ruler(NULL)
|
||||
RulerNodeItem2::RulerNodeItem2(struct plot_info &info) : pInfo(info), entry(NULL), ruler(NULL)
|
||||
{
|
||||
setRect(QRect(QPoint(-8,8),QPoint(8,-8)));
|
||||
setRect(QRect(QPoint(-8, 8), QPoint(8, -8)));
|
||||
setBrush(QColor(0xff, 0, 0, 127));
|
||||
setPen(QColor("#FF0000"));
|
||||
setFlag(QGraphicsItem::ItemIsMovable);
|
||||
|
@ -30,7 +30,7 @@ void RulerNodeItem2::setRuler(RulerItem2 *r)
|
|||
|
||||
void RulerNodeItem2::recalculate()
|
||||
{
|
||||
struct plot_data *data = pInfo.entry+(pInfo.nr-1);
|
||||
struct plot_data *data = pInfo.entry + (pInfo.nr - 1);
|
||||
uint16_t count = 0;
|
||||
if (x() < 0) {
|
||||
setPos(0, y());
|
||||
|
@ -38,13 +38,13 @@ void RulerNodeItem2::recalculate()
|
|||
setPos(timeAxis->posAtValue(data->sec), y());
|
||||
} else {
|
||||
data = pInfo.entry;
|
||||
count=0;
|
||||
count = 0;
|
||||
while (timeAxis->posAtValue(data->sec) < x() && count < pInfo.nr) {
|
||||
data = pInfo.entry+count;
|
||||
data = pInfo.entry + count;
|
||||
count++;
|
||||
}
|
||||
setPos(timeAxis->posAtValue(data->sec), depthAxis->posAtValue(data->depth));
|
||||
entry=data;
|
||||
entry = data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,7 @@ QVariant RulerNodeItem2::itemChange(GraphicsItemChange change, const QVariant &v
|
|||
return QGraphicsEllipseItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
RulerItem2::RulerItem2():
|
||||
timeAxis(NULL),
|
||||
RulerItem2::RulerItem2() : timeAxis(NULL),
|
||||
depthAxis(NULL),
|
||||
source(new RulerNodeItem2(pInfo)),
|
||||
dest(new RulerNodeItem2(pInfo)),
|
||||
|
@ -112,7 +111,6 @@ void RulerItem2::recalculate()
|
|||
textItem->resetTransform();
|
||||
textItem->setPos(startPoint);
|
||||
textItem->rotate(globalLine.angle() * -1);
|
||||
|
||||
}
|
||||
|
||||
RulerNodeItem2 *RulerItem2::sourceNode() const
|
||||
|
@ -147,7 +145,7 @@ QPainterPath RulerItem2::shape() const
|
|||
QLineF line_n = line.normalVector();
|
||||
line_n.setLength(height);
|
||||
if (paint_direction == 1)
|
||||
line_n.setAngle(line_n.angle()+180);
|
||||
line_n.setAngle(line_n.angle() + 180);
|
||||
path.moveTo(startPoint);
|
||||
path.lineTo(line_n.p2());
|
||||
path.lineTo(line_n.p2() + QPointF(line.dx(), line.dy()));
|
||||
|
@ -164,7 +162,7 @@ void RulerItem2::setPlotInfo(plot_info info)
|
|||
source->recalculate();
|
||||
}
|
||||
|
||||
void RulerItem2::setAxis(DiveCartesianAxis* time, DiveCartesianAxis* depth)
|
||||
void RulerItem2::setAxis(DiveCartesianAxis *time, DiveCartesianAxis *depth)
|
||||
{
|
||||
timeAxis = time;
|
||||
depthAxis = depth;
|
||||
|
|
|
@ -10,37 +10,36 @@
|
|||
struct plot_data;
|
||||
class RulerItem2;
|
||||
|
||||
class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem
|
||||
{
|
||||
class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem {
|
||||
Q_OBJECT
|
||||
friend class RulerItem2;
|
||||
|
||||
public:
|
||||
explicit RulerNodeItem2(struct plot_info& info);
|
||||
explicit RulerNodeItem2(struct plot_info &info);
|
||||
void setRuler(RulerItem2 *r);
|
||||
void recalculate();
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant & value );
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
private:
|
||||
struct plot_info &pInfo;
|
||||
struct plot_data *entry;
|
||||
RulerItem2* ruler;
|
||||
RulerItem2 *ruler;
|
||||
DiveCartesianAxis *timeAxis;
|
||||
DiveCartesianAxis *depthAxis;
|
||||
};
|
||||
|
||||
class RulerItem2 : public QGraphicsObject
|
||||
{
|
||||
class RulerItem2 : public QGraphicsObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RulerItem2();
|
||||
void recalculate();
|
||||
|
||||
void setPlotInfo(struct plot_info pInfo);
|
||||
RulerNodeItem2* sourceNode() const;
|
||||
RulerNodeItem2* destNode() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0);
|
||||
RulerNodeItem2 *sourceNode() const;
|
||||
RulerNodeItem2 *destNode() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
QRectF boundingRect() const;
|
||||
QPainterPath shape() const;
|
||||
void setAxis(DiveCartesianAxis *time, DiveCartesianAxis *depth);
|
||||
|
|
|
@ -43,12 +43,15 @@ extern struct ev_select *ev_namelist;
|
|||
extern int evn_allocated;
|
||||
extern int evn_used;
|
||||
|
||||
#define TOOLBAR_POS \
|
||||
QPoint(viewport()->geometry().width() - toolBarProxy->boundingRect().width(), \
|
||||
viewport()->geometry().height() - toolBarProxy->boundingRect().height() )
|
||||
#define TOOLBAR_POS QPoint(viewport()->geometry().width() - toolBarProxy->boundingRect().width(), \
|
||||
viewport()->geometry().height() - toolBarProxy->boundingRect().height())
|
||||
|
||||
ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent),
|
||||
toolTip(0) , diveId(0), diveDC(0), rulerItem(0), toolBarProxy(0)
|
||||
ProfileGraphicsView::ProfileGraphicsView(QWidget *parent) : QGraphicsView(parent),
|
||||
toolTip(0),
|
||||
diveId(0),
|
||||
diveDC(0),
|
||||
rulerItem(0),
|
||||
toolBarProxy(0)
|
||||
{
|
||||
printMode = false;
|
||||
isGrayscale = false;
|
||||
|
@ -68,8 +71,8 @@ ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent
|
|||
defaultPen.setWidth(2);
|
||||
defaultPen.setCosmetic(true);
|
||||
|
||||
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
}
|
||||
|
||||
/* since we cannot use translate() directly on the scene we hack on
|
||||
|
@ -91,7 +94,7 @@ void ProfileGraphicsView::scrollViewTo(const QPoint pos)
|
|||
hs->setValue(xRat * (hMax - hMin) + hMin * 0.9);
|
||||
}
|
||||
|
||||
void ProfileGraphicsView::wheelEvent(QWheelEvent* event)
|
||||
void ProfileGraphicsView::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (!toolTip)
|
||||
return;
|
||||
|
@ -122,7 +125,7 @@ void ProfileGraphicsView::wheelEvent(QWheelEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event)
|
||||
void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
if (selected_dive == -1)
|
||||
return;
|
||||
|
@ -133,26 +136,26 @@ void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event)
|
|||
int rowCount = model->rowCount();
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
QAction *action = new QAction(&m);
|
||||
action->setText( model->data(model->index(i, 0),Qt::DisplayRole).toString());
|
||||
action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString());
|
||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas()));
|
||||
action->setData(event->globalPos());
|
||||
gasChange->addAction(action);
|
||||
}
|
||||
QAction *action = m.addAction(tr("Add Bookmark"), this, SLOT(addBookmark()));
|
||||
action->setData(event->globalPos());
|
||||
QList<QGraphicsItem*> itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos())));
|
||||
Q_FOREACH(QGraphicsItem *i, itemsAtPos) {
|
||||
EventItem *item = dynamic_cast<EventItem*>(i);
|
||||
QList<QGraphicsItem *> itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos())));
|
||||
Q_FOREACH(QGraphicsItem * i, itemsAtPos) {
|
||||
EventItem *item = dynamic_cast<EventItem *>(i);
|
||||
if (!item)
|
||||
continue;
|
||||
action = new QAction(&m);
|
||||
action->setText(tr("Remove Event"));
|
||||
action->setData(QVariant::fromValue<void*>(item)); // so we know what to remove.
|
||||
action->setData(QVariant::fromValue<void *>(item)); // so we know what to remove.
|
||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(removeEvent()));
|
||||
m.addAction(action);
|
||||
action = new QAction(&m);
|
||||
action->setText(tr("Hide similar events"));
|
||||
action->setData(QVariant::fromValue<void*>(item));
|
||||
action->setData(QVariant::fromValue<void *>(item));
|
||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(hideEvents()));
|
||||
m.addAction(action);
|
||||
break;
|
||||
|
@ -173,7 +176,7 @@ void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event)
|
|||
|
||||
void ProfileGraphicsView::addBookmark()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction*>(sender());
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
QPoint globalPos = action->data().toPoint();
|
||||
QPoint viewPos = mapFromGlobal(globalPos);
|
||||
QPointF scenePos = mapToScene(viewPos);
|
||||
|
@ -185,7 +188,7 @@ void ProfileGraphicsView::addBookmark()
|
|||
|
||||
void ProfileGraphicsView::changeGas()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction*>(sender());
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
QPoint globalPos = action->data().toPoint();
|
||||
QPoint viewPos = mapFromGlobal(globalPos);
|
||||
QPointF scenePos = mapToScene(viewPos);
|
||||
|
@ -203,17 +206,17 @@ void ProfileGraphicsView::changeGas()
|
|||
|
||||
void ProfileGraphicsView::hideEvents()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction*>(sender());
|
||||
EventItem *item = static_cast<EventItem*>(action->data().value<void*>());
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
EventItem *item = static_cast<EventItem *>(action->data().value<void *>());
|
||||
struct event *event = item->ev;
|
||||
|
||||
if (QMessageBox::question(MainWindow::instance(), TITLE_OR_TEXT(
|
||||
tr("Hide events"),
|
||||
tr("Hide all %1 events?").arg(event->name)),
|
||||
tr("Hide events"),
|
||||
tr("Hide all %1 events?").arg(event->name)),
|
||||
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
|
||||
if (event->name) {
|
||||
for (int i = 0; i < evn_used; i++) {
|
||||
if (! strcmp(event->name, ev_namelist[i].ev_name)) {
|
||||
if (!strcmp(event->name, ev_namelist[i].ev_name)) {
|
||||
ev_namelist[i].plot_ev = false;
|
||||
break;
|
||||
}
|
||||
|
@ -233,15 +236,13 @@ void ProfileGraphicsView::unhideEvents()
|
|||
|
||||
void ProfileGraphicsView::removeEvent()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction*>(sender());
|
||||
EventItem *item = static_cast<EventItem*>(action->data().value<void*>());
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
EventItem *item = static_cast<EventItem *>(action->data().value<void *>());
|
||||
struct event *event = item->ev;
|
||||
|
||||
if (QMessageBox::question(MainWindow::instance(), TITLE_OR_TEXT(
|
||||
tr("Remove the selected event?"),
|
||||
tr("%1 @ %2:%3").arg(event->name)
|
||||
.arg(event->time.seconds / 60)
|
||||
.arg(event->time.seconds % 60, 2, 10, QChar('0'))),
|
||||
tr("Remove the selected event?"),
|
||||
tr("%1 @ %2:%3").arg(event->name).arg(event->time.seconds / 60).arg(event->time.seconds % 60, 2, 10, QChar('0'))),
|
||||
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
|
||||
struct event **ep = ¤t_dc->events;
|
||||
while (ep && *ep != event)
|
||||
|
@ -256,12 +257,12 @@ void ProfileGraphicsView::removeEvent()
|
|||
}
|
||||
|
||||
|
||||
void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
|
||||
void ProfileGraphicsView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!toolTip)
|
||||
return;
|
||||
|
||||
toolTip->refresh(&gc, mapToScene(event->pos()));
|
||||
toolTip->refresh(&gc, mapToScene(event->pos()));
|
||||
QPoint toolTipPos = mapFromScene(toolTip->pos());
|
||||
scrollViewTo(event->pos());
|
||||
|
||||
|
@ -273,7 +274,7 @@ void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
bool ProfileGraphicsView::eventFilter(QObject* obj, QEvent* event)
|
||||
bool ProfileGraphicsView::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::Leave) {
|
||||
if (toolTip && toolTip->isExpanded())
|
||||
|
@ -306,7 +307,7 @@ static void plot_set_scale(scale_mode_t scale)
|
|||
}
|
||||
#endif
|
||||
|
||||
void ProfileGraphicsView::showEvent(QShowEvent* event)
|
||||
void ProfileGraphicsView::showEvent(QShowEvent *event)
|
||||
{
|
||||
// Program just opened,
|
||||
// but the dive was not ploted.
|
||||
|
@ -339,7 +340,7 @@ void ProfileGraphicsView::clear()
|
|||
rulerItem->destNode()->deleteLater();
|
||||
rulerItem->sourceNode()->deleteLater();
|
||||
rulerItem->deleteLater();
|
||||
rulerItem=0;
|
||||
rulerItem = 0;
|
||||
}
|
||||
scene()->clear();
|
||||
}
|
||||
|
@ -382,7 +383,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
|
|||
|
||||
// best place to put the focus stealer code.
|
||||
setFocusProxy(MainWindow::instance()->dive_list());
|
||||
scene()->setSceneRect(0,0, viewport()->width()-50, viewport()->height()-50);
|
||||
scene()->setSceneRect(0, 0, viewport()->width() - 50, viewport()->height() - 50);
|
||||
|
||||
toolTip = new ToolTipItem();
|
||||
installEventFilter(toolTip);
|
||||
|
@ -404,7 +405,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
|
|||
if (nick.isEmpty())
|
||||
nick = tr("unknown divecomputer");
|
||||
|
||||
if ( tr("unknown divecomputer") == nick) {
|
||||
if (tr("unknown divecomputer") == nick) {
|
||||
mode = PLAN;
|
||||
} else {
|
||||
mode = DIVE;
|
||||
|
@ -432,16 +433,16 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
|
|||
|
||||
/* Depth profile */
|
||||
plot_depth_profile(); // TODO: PARTIALLY PORTED.
|
||||
plot_events(dc); // PORTED
|
||||
plot_events(dc); // PORTED
|
||||
|
||||
if (rulerEnabled && !printMode) // TODO: NOT PORTED.
|
||||
create_ruler();
|
||||
|
||||
/* Temperature profile */
|
||||
plot_temperature_profile(); // PORTED
|
||||
plot_temperature_profile(); // PORTED
|
||||
|
||||
/* Cylinder pressure plot */
|
||||
plot_cylinder_pressure(); // PORTED
|
||||
plot_cylinder_pressure(); // PORTED
|
||||
|
||||
/* Text on top of all graphs.. */ // TODO: NOT PORTED, ANY TEXT.
|
||||
plot_temperature_text();
|
||||
|
@ -451,10 +452,12 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
|
|||
|
||||
// NOT PORTED.
|
||||
/* Put the dive computer name in the lower left corner */
|
||||
gc.leftx = 0; gc.rightx = 1.0;
|
||||
gc.topy = 0; gc.bottomy = 1.0;
|
||||
gc.leftx = 0;
|
||||
gc.rightx = 1.0;
|
||||
gc.topy = 0;
|
||||
gc.bottomy = 1.0;
|
||||
|
||||
text_render_options_t computer = {DC_TEXT_SIZE, TIME_TEXT, LEFT, TOP};
|
||||
text_render_options_t computer = { DC_TEXT_SIZE, TIME_TEXT, LEFT, TOP };
|
||||
diveComputer = plot_text(&computer, QPointF(gc.leftx, gc.bottomy), nick);
|
||||
// The Time ruler should be right after the DiveComputer:
|
||||
timeMarkers->setPos(0, diveComputer->y());
|
||||
|
@ -477,7 +480,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
|
|||
#endif
|
||||
|
||||
QRectF r = scene()->itemsBoundingRect();
|
||||
scene()->setSceneRect(r.x() - 15, r.y() -15, r.width() + 30, r.height() + 30);
|
||||
scene()->setSceneRect(r.x() - 15, r.y() - 15, r.width() + 30, r.height() + 30);
|
||||
if (zoomLevel == 0) {
|
||||
fitInView(sceneRect());
|
||||
}
|
||||
|
@ -485,7 +488,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
|
|||
|
||||
if (mode == PLAN) {
|
||||
timeEditor = new GraphicsTextEditor();
|
||||
timeEditor->setPlainText(d->duration.seconds ? QString::number(d->duration.seconds/60) : tr("Set Duration: 10 minutes"));
|
||||
timeEditor->setPlainText(d->duration.seconds ? QString::number(d->duration.seconds / 60) : tr("Set Duration: 10 minutes"));
|
||||
timeEditor->setPos(profile_grid_area.width() - timeEditor->boundingRect().width(), timeMarkers->y());
|
||||
timeEditor->document();
|
||||
connect(timeEditor, SIGNAL(editingFinished(QString)), this, SLOT(edit_dive_time(QString)));
|
||||
|
@ -504,12 +507,13 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
|
|||
void ProfileGraphicsView::plot_depth_scale()
|
||||
{
|
||||
int i, maxdepth, marker;
|
||||
static text_render_options_t tro = {DEPTH_TEXT_SIZE, SAMPLE_DEEP, RIGHT, MIDDLE};
|
||||
static text_render_options_t tro = { DEPTH_TEXT_SIZE, SAMPLE_DEEP, RIGHT, MIDDLE };
|
||||
|
||||
/* Depth markers: every 30 ft or 10 m*/
|
||||
maxdepth = get_maxdepth(&gc.pi);
|
||||
gc.topy = 0; gc.bottomy = maxdepth;
|
||||
marker = M_OR_FT(10,30);
|
||||
gc.topy = 0;
|
||||
gc.bottomy = maxdepth;
|
||||
marker = M_OR_FT(10, 30);
|
||||
|
||||
/* don't write depth labels all the way to the bottom as
|
||||
* there may be other graphs below the depth plot (like
|
||||
|
@ -557,7 +561,7 @@ void ProfileGraphicsView::plot_pp_text()
|
|||
{
|
||||
double pp, dpp, m;
|
||||
int hpos;
|
||||
static text_render_options_t tro = {PP_TEXT_SIZE, PP_LINES, LEFT, -0.75};
|
||||
static text_render_options_t tro = { PP_TEXT_SIZE, PP_LINES, LEFT, -0.75 };
|
||||
QGraphicsRectItem *pressureMarkers = new QGraphicsRectItem();
|
||||
|
||||
setup_pp_limits(&gc);
|
||||
|
@ -571,7 +575,7 @@ void ProfileGraphicsView::plot_pp_text()
|
|||
QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, m), SCALEGC(hpos, m));
|
||||
QPen pen(defaultPen);
|
||||
pen.setColor(c);
|
||||
if ( IS_FP_SAME(QString::number(m).toDouble(), QString::number(m).toInt())) {
|
||||
if (IS_FP_SAME(QString::number(m).toDouble(), QString::number(m).toInt())) {
|
||||
pen.setStyle(Qt::DashLine);
|
||||
pen.setWidthF(1.2);
|
||||
}
|
||||
|
@ -606,7 +610,7 @@ void ProfileGraphicsView::plot_pp_gas_profile()
|
|||
setup_pp_limits(&gc);
|
||||
QColor c;
|
||||
QPointF from, to;
|
||||
QPointF legendPos = QPointF(scene()->sceneRect().width() * 0.4, scene()->sceneRect().height() - scene()->sceneRect().height()*0.02);
|
||||
QPointF legendPos = QPointF(scene()->sceneRect().width() * 0.4, scene()->sceneRect().height() - scene()->sceneRect().height() * 0.02);
|
||||
|
||||
if (prefs.pp_graphs.pn2) {
|
||||
c = getColor(PN2);
|
||||
|
@ -630,7 +634,7 @@ void ProfileGraphicsView::plot_pp_gas_profile()
|
|||
else
|
||||
from = QPointF(SCALEGC(entry->sec, entry->pn2));
|
||||
}
|
||||
createPPLegend(trUtf8("pN" UTF8_SUBSCRIPT_2),getColor(PN2), legendPos);
|
||||
createPPLegend(trUtf8("pN" UTF8_SUBSCRIPT_2), getColor(PN2), legendPos);
|
||||
}
|
||||
|
||||
if (prefs.pp_graphs.phe) {
|
||||
|
@ -656,7 +660,7 @@ void ProfileGraphicsView::plot_pp_gas_profile()
|
|||
else
|
||||
from = QPointF(SCALEGC(entry->sec, entry->phe));
|
||||
}
|
||||
createPPLegend(trUtf8("pHe"),getColor(PHE), legendPos);
|
||||
createPPLegend(trUtf8("pHe"), getColor(PHE), legendPos);
|
||||
}
|
||||
if (prefs.pp_graphs.po2) {
|
||||
c = getColor(PO2);
|
||||
|
@ -677,27 +681,27 @@ void ProfileGraphicsView::plot_pp_gas_profile()
|
|||
entry++;
|
||||
if (entry->po2 >= prefs.pp_graphs.po2_threshold)
|
||||
plot_add_line(entry->sec, entry->po2, c, from);
|
||||
else
|
||||
else
|
||||
from = QPointF(SCALEGC(entry->sec, entry->po2));
|
||||
}
|
||||
createPPLegend(trUtf8("pO" UTF8_SUBSCRIPT_2),getColor(PO2), legendPos);
|
||||
createPPLegend(trUtf8("pO" UTF8_SUBSCRIPT_2), getColor(PO2), legendPos);
|
||||
}
|
||||
}
|
||||
|
||||
void ProfileGraphicsView::createPPLegend(QString title, const QColor& c, QPointF& legendPos)
|
||||
void ProfileGraphicsView::createPPLegend(QString title, const QColor &c, QPointF &legendPos)
|
||||
{
|
||||
QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, scene()->sceneRect().width() * 0.01, scene()->sceneRect().width() * 0.01);
|
||||
rect->setBrush(QBrush(c));
|
||||
rect->setPos(legendPos);
|
||||
rect->setPen(QPen(QColor(Qt::transparent)));
|
||||
QGraphicsSimpleTextItem *text = new QGraphicsSimpleTextItem(title);
|
||||
text->setPos(legendPos.x() + rect->boundingRect().width() + 5, legendPos.y() );
|
||||
text->setPos(legendPos.x() + rect->boundingRect().width() + 5, legendPos.y());
|
||||
scene()->addItem(rect);
|
||||
scene()->addItem(text);
|
||||
legendPos.setX(text->pos().x() + text->boundingRect().width() + 20);
|
||||
if (printMode) {
|
||||
QFont f = text->font();
|
||||
f.setPointSizeF( f.pointSizeF() * 0.7);
|
||||
f.setPointSizeF(f.pointSizeF() * 0.7);
|
||||
text->setFont(f);
|
||||
}
|
||||
}
|
||||
|
@ -707,7 +711,7 @@ void ProfileGraphicsView::plot_deco_text()
|
|||
if (prefs.profile_calc_ceiling) {
|
||||
float x = gc.leftx + (gc.rightx - gc.leftx) / 2;
|
||||
float y = gc.topy = 1.0;
|
||||
static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, CENTER, BOTTOM};
|
||||
static text_render_options_t tro = { PRESSURE_TEXT_SIZE, PRESSURE_TEXT, CENTER, BOTTOM };
|
||||
gc.bottomy = 0.0;
|
||||
plot_text(&tro, QPointF(x, y), QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh));
|
||||
}
|
||||
|
@ -740,8 +744,8 @@ void ProfileGraphicsView::plot_cylinder_pressure_text()
|
|||
if (!seen_cyl[cyl]) {
|
||||
plot_pressure_value(mbar, entry->sec, LEFT, BOTTOM);
|
||||
plot_gas_value(mbar, entry->sec, LEFT, TOP,
|
||||
get_o2(&dive->cylinder[cyl].gasmix),
|
||||
get_he(&dive->cylinder[cyl].gasmix));
|
||||
get_o2(&dive->cylinder[cyl].gasmix),
|
||||
get_he(&dive->cylinder[cyl].gasmix));
|
||||
seen_cyl[cyl] = true;
|
||||
}
|
||||
}
|
||||
|
@ -762,7 +766,7 @@ void ProfileGraphicsView::plot_pressure_value(int mbar, int sec, double xalign,
|
|||
const char *unit;
|
||||
|
||||
pressure = get_pressure_units(mbar, &unit);
|
||||
static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, xalign, yalign};
|
||||
static text_render_options_t tro = { PRESSURE_TEXT_SIZE, PRESSURE_TEXT, xalign, yalign };
|
||||
plot_text(&tro, QPointF(sec, mbar), QString("%1 %2").arg(pressure).arg(unit));
|
||||
}
|
||||
|
||||
|
@ -775,9 +779,8 @@ void ProfileGraphicsView::plot_gas_value(int mbar, int sec, double xalign, doubl
|
|||
gas = QString(tr("EAN%1")).arg((o2 + 5) / 10);
|
||||
else
|
||||
gas = QString("%1/%2").arg((o2 + 5) / 10).arg((he + 5) / 10);
|
||||
static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, xalign, yalign};
|
||||
static text_render_options_t tro = { PRESSURE_TEXT_SIZE, PRESSURE_TEXT, xalign, yalign };
|
||||
plot_text(&tro, QPointF(sec, mbar), gas);
|
||||
|
||||
}
|
||||
|
||||
void ProfileGraphicsView::plot_depth_text()
|
||||
|
@ -788,20 +791,22 @@ void ProfileGraphicsView::plot_depth_text()
|
|||
maxtime = get_maxtime(&gc.pi);
|
||||
maxdepth = get_maxdepth(&gc.pi);
|
||||
|
||||
gc.leftx = 0; gc.rightx = maxtime;
|
||||
gc.topy = 0; gc.bottomy = maxdepth;
|
||||
gc.leftx = 0;
|
||||
gc.rightx = maxtime;
|
||||
gc.topy = 0;
|
||||
gc.bottomy = maxdepth;
|
||||
|
||||
plot_text_samples();
|
||||
}
|
||||
|
||||
void ProfileGraphicsView::plot_text_samples()
|
||||
{
|
||||
static text_render_options_t deep = {14, SAMPLE_DEEP, CENTER, TOP};
|
||||
static text_render_options_t shallow = {14, SAMPLE_SHALLOW, CENTER, BOTTOM};
|
||||
static text_render_options_t deep = { 14, SAMPLE_DEEP, CENTER, TOP };
|
||||
static text_render_options_t shallow = { 14, SAMPLE_SHALLOW, CENTER, BOTTOM };
|
||||
int i;
|
||||
int last = -1;
|
||||
|
||||
struct plot_info* pi = &gc.pi;
|
||||
struct plot_info *pi = &gc.pi;
|
||||
|
||||
for (i = 0; i < pi->nr; i++) {
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
|
@ -824,7 +829,7 @@ void ProfileGraphicsView::plot_text_samples()
|
|||
}
|
||||
}
|
||||
|
||||
void ProfileGraphicsView::plot_depth_sample(struct plot_data *entry,text_render_options_t *tro)
|
||||
void ProfileGraphicsView::plot_depth_sample(struct plot_data *entry, text_render_options_t *tro)
|
||||
{
|
||||
int sec = entry->sec, decimals;
|
||||
double d;
|
||||
|
@ -845,7 +850,7 @@ void ProfileGraphicsView::plot_temperature_text()
|
|||
return;
|
||||
|
||||
for (i = 0; i < pi->nr; i++) {
|
||||
struct plot_data *entry = pi->entry+i;
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
int mkelvin = entry->temperature;
|
||||
sec = entry->sec;
|
||||
|
||||
|
@ -862,7 +867,7 @@ void ProfileGraphicsView::plot_temperature_text()
|
|||
continue;
|
||||
last = sec;
|
||||
if (mkelvin > 200000)
|
||||
plot_single_temp_text(sec,mkelvin);
|
||||
plot_single_temp_text(sec, mkelvin);
|
||||
last_printed_temp = mkelvin;
|
||||
}
|
||||
/* it would be nice to print the end temperature, if it's
|
||||
|
@ -877,7 +882,7 @@ void ProfileGraphicsView::plot_single_temp_text(int sec, int mkelvin)
|
|||
{
|
||||
double deg;
|
||||
const char *unit;
|
||||
static text_render_options_t tro = {TEMP_TEXT_SIZE, TEMP_TEXT, LEFT, TOP};
|
||||
static text_render_options_t tro = { TEMP_TEXT_SIZE, TEMP_TEXT, LEFT, TOP };
|
||||
deg = get_temp_units(mkelvin, &unit);
|
||||
plot_text(&tro, QPointF(sec, mkelvin), QString("%1%2").arg(deg, 0, 'f', 1).arg(unit)); //"%.2g%s"
|
||||
}
|
||||
|
@ -917,7 +922,7 @@ void ProfileGraphicsView::plot_cylinder_pressure()
|
|||
int prev_pr;
|
||||
prev_pr = GET_PRESSURE(entry - 1);
|
||||
|
||||
QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC((entry-1)->sec, prev_pr), SCALEGC(entry->sec, mbar));
|
||||
QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC((entry - 1)->sec, prev_pr), SCALEGC(entry->sec, mbar));
|
||||
QPen pen(defaultPen);
|
||||
pen.setColor(c);
|
||||
item->setPen(pen);
|
||||
|
@ -965,9 +970,9 @@ void ProfileGraphicsView::plot_events(struct divecomputer *dc)
|
|||
{
|
||||
struct event *event = dc->events;
|
||||
|
||||
// if (gc->printer) {
|
||||
// return;
|
||||
// }
|
||||
// if (gc->printer) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
while (event) {
|
||||
plot_one_event(event);
|
||||
|
@ -984,7 +989,7 @@ void ProfileGraphicsView::plot_one_event(struct event *ev)
|
|||
/* is plotting of this event disabled? */
|
||||
if (ev->name) {
|
||||
for (i = 0; i < evn_used; i++) {
|
||||
if (! strcmp(ev->name, ev_namelist[i].ev_name)) {
|
||||
if (!strcmp(ev->name, ev_namelist[i].ev_name)) {
|
||||
if (ev_namelist[i].plot_ev)
|
||||
break;
|
||||
else
|
||||
|
@ -1018,7 +1023,7 @@ void ProfileGraphicsView::plot_one_event(struct event *ev)
|
|||
item->setPos(x, y);
|
||||
scene()->addItem(item);
|
||||
|
||||
if (ev->type == 123){
|
||||
if (ev->type == 123) {
|
||||
QPixmap picture;
|
||||
picture.load(ev->name);
|
||||
scene()->addPixmap(picture.scaledToHeight(100, Qt::SmoothTransformation))->setPos(x, y + 10);
|
||||
|
@ -1041,7 +1046,7 @@ void ProfileGraphicsView::plot_one_event(struct event *ev)
|
|||
name += QString(tr("EAN%1")).arg((o2 + 5) / 10);
|
||||
|
||||
} else if (ev->name && !strcmp(ev->name, "SP change")) {
|
||||
name += QString(":%1").arg((double) ev->value / 1000);
|
||||
name += QString(":%1").arg((double)ev->value / 1000);
|
||||
} else {
|
||||
name += QString(":%1").arg(ev->value);
|
||||
}
|
||||
|
@ -1049,7 +1054,7 @@ void ProfileGraphicsView::plot_one_event(struct event *ev)
|
|||
name += "\n" + tr("Bailing out to OC");
|
||||
} else {
|
||||
name += ev->flags == SAMPLE_FLAGS_BEGIN ? tr(" begin", "Starts with space!") :
|
||||
ev->flags == SAMPLE_FLAGS_END ? tr(" end", "Starts with space!") : "";
|
||||
ev->flags == SAMPLE_FLAGS_END ? tr(" end", "Starts with space!") : "";
|
||||
}
|
||||
|
||||
//item->setToolTipController(toolTip);
|
||||
|
@ -1059,7 +1064,7 @@ void ProfileGraphicsView::plot_one_event(struct event *ev)
|
|||
|
||||
void ProfileGraphicsView::create_ruler()
|
||||
{
|
||||
int x,y;
|
||||
int x, y;
|
||||
struct plot_info *pi = &gc.pi;
|
||||
struct plot_data *data = pi->entry;
|
||||
|
||||
|
@ -1069,13 +1074,13 @@ void ProfileGraphicsView::create_ruler()
|
|||
x = SCALEXGC(data->sec);
|
||||
y = data->depth;
|
||||
|
||||
first->setPos(x,y);
|
||||
first->setPos(x, y);
|
||||
|
||||
data = pi->entry+(pi->nr-1);
|
||||
data = pi->entry + (pi->nr - 1);
|
||||
x = SCALEXGC(data->sec);
|
||||
y = data->depth;
|
||||
|
||||
second->setPos(x,y);
|
||||
second->setPos(x, y);
|
||||
//Make sure that both points already have their entries
|
||||
first->recalculate();
|
||||
second->recalculate();
|
||||
|
@ -1087,7 +1092,7 @@ void ProfileGraphicsView::create_ruler()
|
|||
|
||||
void ProfileGraphicsView::add_ruler()
|
||||
{
|
||||
if (! scene()->items().contains(rulerItem)) {
|
||||
if (!scene()->items().contains(rulerItem)) {
|
||||
scene()->addItem(rulerItem->sourceNode());
|
||||
scene()->addItem(rulerItem->destNode());
|
||||
scene()->addItem(rulerItem);
|
||||
|
@ -1113,7 +1118,7 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
int sec, depth;
|
||||
struct plot_data *entry;
|
||||
int maxtime, maxdepth, marker, maxline;
|
||||
int increments[8] = { 10, 20, 30, 60, 5*60, 10*60, 15*60, 30*60 };
|
||||
int increments[8] = { 10, 20, 30, 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60 };
|
||||
|
||||
/* Get plot scaling limits */
|
||||
maxtime = get_maxtime(&gc.pi);
|
||||
|
@ -1135,8 +1140,10 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
while (maxtime / incr > 12)
|
||||
incr *= 2;
|
||||
|
||||
gc.leftx = 0; gc.rightx = maxtime;
|
||||
gc.topy = 0; gc.bottomy = 1.0;
|
||||
gc.leftx = 0;
|
||||
gc.rightx = maxtime;
|
||||
gc.topy = 0;
|
||||
gc.bottomy = 1.0;
|
||||
|
||||
last_gc = gc;
|
||||
|
||||
|
@ -1151,23 +1158,25 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
|
||||
timeMarkers = new QGraphicsRectItem();
|
||||
/* now the text on the time markers */
|
||||
struct text_render_options tro = {DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, LINE_DOWN};
|
||||
struct text_render_options tro = { DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, LINE_DOWN };
|
||||
if (maxtime < 600) {
|
||||
/* Be a bit more verbose with shorter dives */
|
||||
for (i = incr; i < maxtime; i += incr)
|
||||
plot_text(&tro, QPointF(i, 0), QString("%1:%2").arg(i/60).arg(i%60, 2, 10, QChar('0')), timeMarkers);
|
||||
plot_text(&tro, QPointF(i, 0), QString("%1:%2").arg(i / 60).arg(i % 60, 2, 10, QChar('0')), timeMarkers);
|
||||
} else {
|
||||
/* Only render the time on every second marker for normal dives */
|
||||
for (i = incr; i < maxtime; i += 2 * incr)
|
||||
plot_text(&tro, QPointF(i, 0), QString("%1").arg(QString::number(i/60)), timeMarkers);
|
||||
plot_text(&tro, QPointF(i, 0), QString("%1").arg(QString::number(i / 60)), timeMarkers);
|
||||
}
|
||||
timeMarkers->setPos(0,0);
|
||||
timeMarkers->setPos(0, 0);
|
||||
scene()->addItem(timeMarkers);
|
||||
|
||||
/* Depth markers: every 30 ft or 10 m*/
|
||||
gc.leftx = 0; gc.rightx = 1.0;
|
||||
gc.topy = 0; gc.bottomy = maxdepth;
|
||||
marker = M_OR_FT(10,30);
|
||||
gc.leftx = 0;
|
||||
gc.rightx = 1.0;
|
||||
gc.topy = 0;
|
||||
gc.bottomy = maxdepth;
|
||||
marker = M_OR_FT(10, 30);
|
||||
maxline = qMax(gc.pi.maxdepth + marker, maxdepth * 2 / 3);
|
||||
|
||||
c = getColor(DEPTH_GRID);
|
||||
|
@ -1180,11 +1189,12 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
scene()->addItem(item);
|
||||
}
|
||||
|
||||
gc.leftx = 0; gc.rightx = maxtime;
|
||||
gc.leftx = 0;
|
||||
gc.rightx = maxtime;
|
||||
c = getColor(MEAN_DEPTH);
|
||||
|
||||
/* Show mean depth */
|
||||
if (! gc.printer) {
|
||||
if (!gc.printer) {
|
||||
QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, gc.pi.meandepth),
|
||||
SCALEGC(gc.pi.entry[gc.pi.nr - 1].sec, gc.pi.meandepth));
|
||||
QPen pen(defaultPen);
|
||||
|
@ -1192,7 +1202,7 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
item->setPen(pen);
|
||||
scene()->addItem(item);
|
||||
|
||||
struct text_render_options depth_tro = {DEPTH_TEXT_SIZE, MEAN_DEPTH, LEFT, TOP};
|
||||
struct text_render_options depth_tro = { DEPTH_TEXT_SIZE, MEAN_DEPTH, LEFT, TOP };
|
||||
QString depthLabel = get_depth_string(gc.pi.meandepth, true, true);
|
||||
plot_text(&depth_tro, QPointF(gc.leftx, gc.pi.meandepth), depthLabel, item);
|
||||
tro.hpos = RIGHT;
|
||||
|
@ -1211,12 +1221,13 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
#endif
|
||||
|
||||
/* Do the depth profile for the neat fill */
|
||||
gc.topy = 0; gc.bottomy = maxdepth;
|
||||
gc.topy = 0;
|
||||
gc.bottomy = maxdepth;
|
||||
|
||||
entry = gc.pi.entry;
|
||||
|
||||
QPolygonF p;
|
||||
QLinearGradient pat(0.0,0.0,0.0,scene()->height());
|
||||
QLinearGradient pat(0.0, 0.0, 0.0, scene()->height());
|
||||
QGraphicsPolygonItem *neatFill = NULL;
|
||||
|
||||
p.append(QPointF(SCALEGC(0, 0)));
|
||||
|
@ -1242,7 +1253,7 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
neatFill = new QGraphicsPolygonItem();
|
||||
neatFill->setPolygon(p);
|
||||
neatFill->setBrush(QBrush(pat));
|
||||
neatFill->setPen(QPen(QBrush(Qt::transparent),0));
|
||||
neatFill->setPen(QPen(QBrush(Qt::transparent), 0));
|
||||
scene()->addItem(neatFill);
|
||||
|
||||
|
||||
|
@ -1271,7 +1282,7 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
neatFill = new QGraphicsPolygonItem();
|
||||
neatFill->setBrush(QBrush(pat));
|
||||
neatFill->setPolygon(p);
|
||||
neatFill->setPen(QPen(QBrush(Qt::NoBrush),0));
|
||||
neatFill->setPen(QPen(QBrush(Qt::NoBrush), 0));
|
||||
scene()->addItem(neatFill);
|
||||
}
|
||||
|
||||
|
@ -1289,10 +1300,10 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
else
|
||||
p.append(QPointF(SCALEGC(entry->sec, 0)));
|
||||
}
|
||||
p.append(QPointF(SCALEGC((entry-1)->sec, 0)));
|
||||
p.append(QPointF(SCALEGC((entry - 1)->sec, 0)));
|
||||
neatFill = new QGraphicsPolygonItem();
|
||||
neatFill->setPolygon(p);
|
||||
neatFill->setPen(QPen(QBrush(Qt::NoBrush),0));
|
||||
neatFill->setPen(QPen(QBrush(Qt::NoBrush), 0));
|
||||
neatFill->setBrush(pat);
|
||||
scene()->addItem(neatFill);
|
||||
}
|
||||
|
@ -1300,7 +1311,7 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
/* plot the calculated ceiling for all tissues */
|
||||
if (prefs.profile_calc_ceiling && prefs.calc_all_tissues) {
|
||||
int k;
|
||||
for (k=0; k<16; k++) {
|
||||
for (k = 0; k < 16; k++) {
|
||||
pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW));
|
||||
pat.setColorAt(1, QColor(100, 100, 100, 50));
|
||||
|
||||
|
@ -1313,7 +1324,7 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
else
|
||||
p.append(QPointF(SCALEGC(entry->sec, 0)));
|
||||
}
|
||||
p.append(QPointF(SCALEGC((entry-1)->sec, 0)));
|
||||
p.append(QPointF(SCALEGC((entry - 1)->sec, 0)));
|
||||
neatFill = new QGraphicsPolygonItem();
|
||||
neatFill->setPolygon(p);
|
||||
neatFill->setBrush(pat);
|
||||
|
@ -1332,7 +1343,7 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
for (i = 0; i < gc.pi.nr; i++, entry++)
|
||||
p.append(QPointF(SCALEGC(entry->sec, entry->depth)));
|
||||
|
||||
for (i-- , entry--; i >= 0; i--, entry--) {
|
||||
for (i--, entry--; i >= 0; i--, entry--) {
|
||||
if (entry->in_deco && entry->stopdepth > entry->depth) {
|
||||
p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth)));
|
||||
} else {
|
||||
|
@ -1342,7 +1353,7 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
}
|
||||
neatFill = new QGraphicsPolygonItem();
|
||||
neatFill->setPolygon(p);
|
||||
neatFill->setPen(QPen(QBrush(Qt::NoBrush),0));
|
||||
neatFill->setPen(QPen(QBrush(Qt::NoBrush), 0));
|
||||
neatFill->setBrush(QBrush(pat));
|
||||
scene()->addItem(neatFill);
|
||||
|
||||
|
@ -1363,7 +1374,7 @@ void ProfileGraphicsView::plot_depth_profile()
|
|||
}
|
||||
}
|
||||
|
||||
QGraphicsItemGroup *ProfileGraphicsView::plot_text(text_render_options_t *tro,const QPointF& pos, const QString& text, QGraphicsItem *parent)
|
||||
QGraphicsItemGroup *ProfileGraphicsView::plot_text(text_render_options_t *tro, const QPointF &pos, const QString &text, QGraphicsItem *parent)
|
||||
{
|
||||
QFont fnt(font());
|
||||
QFontMetrics fm(fnt);
|
||||
|
@ -1439,7 +1450,7 @@ void ProfileGraphicsView::plot_temperature_profile()
|
|||
}
|
||||
}
|
||||
|
||||
void ProfileGraphicsView::edit_dive_time(const QString& time)
|
||||
void ProfileGraphicsView::edit_dive_time(const QString &time)
|
||||
{
|
||||
// this should set the full time of the dive.
|
||||
refresh();
|
||||
|
@ -1462,18 +1473,18 @@ QColor EventItem::getColor(const color_indice_t i)
|
|||
return profile_color[i].at((isGrayscale) ? 1 : 0);
|
||||
}
|
||||
|
||||
EventItem::EventItem(struct event *ev, QGraphicsItem* parent, bool grayscale): QGraphicsPixmapItem(parent), ev(ev), isGrayscale(grayscale)
|
||||
EventItem::EventItem(struct event *ev, QGraphicsItem *parent, bool grayscale) : QGraphicsPixmapItem(parent), ev(ev), isGrayscale(grayscale)
|
||||
{
|
||||
if (ev->name && (strcmp(ev->name, "bookmark") == 0 || strcmp(ev->name, "heading") == 0)) {
|
||||
setPixmap( QPixmap(QString(":flag")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
setPixmap(QPixmap(QString(":flag")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
} else {
|
||||
setPixmap( QPixmap(QString(":warning")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
setPixmap(QPixmap(QString(":warning")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
}
|
||||
}
|
||||
|
||||
RulerNodeItem::RulerNodeItem(QGraphicsItem *parent, graphics_context context) : QGraphicsEllipseItem(parent), gc(context), entry(NULL) , ruler(NULL)
|
||||
RulerNodeItem::RulerNodeItem(QGraphicsItem *parent, graphics_context context) : QGraphicsEllipseItem(parent), gc(context), entry(NULL), ruler(NULL)
|
||||
{
|
||||
setRect(QRect(QPoint(-8,8),QPoint(8,-8)));
|
||||
setRect(QRect(QPoint(-8, 8), QPoint(8, -8)));
|
||||
setBrush(QColor(0xff, 0, 0, 127));
|
||||
setPen(QColor("#FF0000"));
|
||||
setFlag(QGraphicsItem::ItemIsMovable);
|
||||
|
@ -1489,7 +1500,7 @@ void RulerNodeItem::setRuler(RulerItem *r)
|
|||
void RulerNodeItem::recalculate()
|
||||
{
|
||||
struct plot_info *pi = &gc.pi;
|
||||
struct plot_data *data = pi->entry+(pi->nr-1);
|
||||
struct plot_data *data = pi->entry + (pi->nr - 1);
|
||||
uint16_t count = 0;
|
||||
if (x() < 0) {
|
||||
setPos(0, y());
|
||||
|
@ -1497,13 +1508,13 @@ void RulerNodeItem::recalculate()
|
|||
setPos(SCALEXGC(data->sec), y());
|
||||
} else {
|
||||
data = pi->entry;
|
||||
count=0;
|
||||
count = 0;
|
||||
while (SCALEXGC(data->sec) < x() && count < pi->nr) {
|
||||
data = pi->entry+count;
|
||||
data = pi->entry + count;
|
||||
count++;
|
||||
}
|
||||
setPos(SCALEGC(data->sec, data->depth));
|
||||
entry=data;
|
||||
entry = data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1548,7 +1559,7 @@ void RulerItem::recalculate()
|
|||
compare_samples(source->entry, dest->entry, buffer, 500, 1);
|
||||
text = QString(buffer);
|
||||
|
||||
QRect r = fm.boundingRect(QRect(QPoint(10,-1*INT_MAX), QPoint(line.length()-10, 0)), Qt::TextWordWrap, text);
|
||||
QRect r = fm.boundingRect(QRect(QPoint(10, -1 * INT_MAX), QPoint(line.length() - 10, 0)), Qt::TextWordWrap, text);
|
||||
if (r.height() < 10)
|
||||
height = 10;
|
||||
else
|
||||
|
@ -1559,7 +1570,7 @@ void RulerItem::recalculate()
|
|||
if (scene()) {
|
||||
/* Determine whether we draw down or upwards */
|
||||
if (scene()->sceneRect().contains(line_n.p2()) &&
|
||||
scene()->sceneRect().contains(endPoint+QPointF(line_n.dx(),line_n.dy())))
|
||||
scene()->sceneRect().contains(endPoint + QPointF(line_n.dx(), line_n.dy())))
|
||||
paint_direction = -1;
|
||||
else
|
||||
paint_direction = 1;
|
||||
|
@ -1585,7 +1596,7 @@ void RulerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||
line_n.setLength(height);
|
||||
|
||||
if (paint_direction == 1)
|
||||
line_n.setAngle(line_n.angle()+180);
|
||||
line_n.setAngle(line_n.angle() + 180);
|
||||
painter->drawLine(line);
|
||||
painter->drawLine(line_n);
|
||||
painter->drawLine(line_n.p1() + QPointF(line.dx(), line.dy()), line_n.p2() + QPointF(line.dx(), line.dy()));
|
||||
|
@ -1593,11 +1604,11 @@ void RulerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||
//Draw Text
|
||||
painter->save();
|
||||
painter->translate(startPoint.x(), startPoint.y());
|
||||
painter->rotate(line.angle()*-1);
|
||||
painter->rotate(line.angle() * -1);
|
||||
if (paint_direction == 1)
|
||||
painter->translate(0, height);
|
||||
painter->setPen(Qt::black);
|
||||
painter->drawText(QRectF(QPointF(10,-1*height), QPointF(line.length()-10, 0)), Qt::TextWordWrap, text);
|
||||
painter->drawText(QRectF(QPointF(10, -1 * height), QPointF(line.length() - 10, 0)), Qt::TextWordWrap, text);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
@ -1613,7 +1624,7 @@ QPainterPath RulerItem::shape() const
|
|||
QLineF line_n = line.normalVector();
|
||||
line_n.setLength(height);
|
||||
if (paint_direction == 1)
|
||||
line_n.setAngle(line_n.angle()+180);
|
||||
line_n.setAngle(line_n.angle() + 180);
|
||||
path.moveTo(startPoint);
|
||||
path.lineTo(line_n.p2());
|
||||
path.lineTo(line_n.p2() + QPointF(line.dx(), line.dy()));
|
||||
|
@ -1622,25 +1633,25 @@ QPainterPath RulerItem::shape() const
|
|||
return path;
|
||||
}
|
||||
|
||||
GraphicsTextEditor::GraphicsTextEditor(QGraphicsItem* parent): QGraphicsTextItem(parent)
|
||||
GraphicsTextEditor::GraphicsTextEditor(QGraphicsItem *parent) : QGraphicsTextItem(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void GraphicsTextEditor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
|
||||
void GraphicsTextEditor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
// Remove the proxy filter so we can focus here.
|
||||
MainWindow::instance()->graphics()->setFocusProxy(0);
|
||||
setTextInteractionFlags(Qt::TextEditorInteraction | Qt::TextEditable);
|
||||
}
|
||||
|
||||
void GraphicsTextEditor::keyReleaseEvent(QKeyEvent* event)
|
||||
void GraphicsTextEditor::keyReleaseEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
|
||||
setTextInteractionFlags(Qt::NoTextInteraction);
|
||||
emit editingFinished( toPlainText() );
|
||||
emit editingFinished(toPlainText());
|
||||
MainWindow::instance()->graphics()->setFocusProxy(MainWindow::instance()->dive_list());
|
||||
return;
|
||||
}
|
||||
emit textChanged( toPlainText() );
|
||||
emit textChanged(toPlainText());
|
||||
QGraphicsTextItem::keyReleaseEvent(event);
|
||||
}
|
||||
|
|
|
@ -15,36 +15,35 @@ struct plot_info;
|
|||
class RulerItem;
|
||||
class ToolTipItem;
|
||||
|
||||
class RulerNodeItem : public QObject, public QGraphicsEllipseItem
|
||||
{
|
||||
class RulerNodeItem : public QObject, public QGraphicsEllipseItem {
|
||||
Q_OBJECT
|
||||
friend class RulerItem;
|
||||
|
||||
public:
|
||||
explicit RulerNodeItem(QGraphicsItem* parent, graphics_context gc);
|
||||
explicit RulerNodeItem(QGraphicsItem *parent, graphics_context gc);
|
||||
void setRuler(RulerItem *r);
|
||||
void recalculate();
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant & value );
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
private:
|
||||
graphics_context gc;
|
||||
struct plot_data *entry;
|
||||
RulerItem* ruler;
|
||||
RulerItem *ruler;
|
||||
};
|
||||
|
||||
class RulerItem : public QGraphicsObject
|
||||
{
|
||||
class RulerItem : public QGraphicsObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RulerItem(QGraphicsItem* parent,
|
||||
explicit RulerItem(QGraphicsItem *parent,
|
||||
RulerNodeItem *sourceMarker,
|
||||
RulerNodeItem *destMarker);
|
||||
void recalculate();
|
||||
|
||||
RulerNodeItem* sourceNode() const;
|
||||
RulerNodeItem* destNode() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0);
|
||||
RulerNodeItem *sourceNode() const;
|
||||
RulerNodeItem *destNode() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
QRectF boundingRect() const;
|
||||
QPainterPath shape() const;
|
||||
|
||||
|
@ -56,11 +55,10 @@ private:
|
|||
int paint_direction;
|
||||
};
|
||||
|
||||
class EventItem : public QGraphicsPixmapItem
|
||||
{
|
||||
class EventItem : public QGraphicsPixmapItem {
|
||||
public:
|
||||
explicit EventItem(struct event *ev, QGraphicsItem* parent = 0, bool grayscale = false);
|
||||
struct event* ev;
|
||||
explicit EventItem(struct event *ev, QGraphicsItem *parent = 0, bool grayscale = false);
|
||||
struct event *ev;
|
||||
|
||||
private:
|
||||
QString text;
|
||||
|
@ -69,42 +67,45 @@ private:
|
|||
QColor getColor(const color_indice_t i);
|
||||
};
|
||||
|
||||
class GraphicsTextEditor : public QGraphicsTextItem{
|
||||
class GraphicsTextEditor : public QGraphicsTextItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GraphicsTextEditor(QGraphicsItem* parent = 0);
|
||||
GraphicsTextEditor(QGraphicsItem *parent = 0);
|
||||
|
||||
protected:
|
||||
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
|
||||
virtual void keyReleaseEvent(QKeyEvent* event);
|
||||
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void keyReleaseEvent(QKeyEvent *event);
|
||||
|
||||
signals:
|
||||
void textChanged(const QString& text);
|
||||
void editingFinished(const QString& text);
|
||||
void textChanged(const QString &text);
|
||||
void editingFinished(const QString &text);
|
||||
};
|
||||
|
||||
class ProfileGraphicsView : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
class ProfileGraphicsView : public QGraphicsView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Mode{DIVE, PLAN};
|
||||
enum Mode {
|
||||
DIVE,
|
||||
PLAN
|
||||
};
|
||||
|
||||
ProfileGraphicsView(QWidget* parent = 0);
|
||||
ProfileGraphicsView(QWidget *parent = 0);
|
||||
void plot(struct dive *d, bool forceRedraw = false);
|
||||
bool eventFilter(QObject* obj, QEvent* event);
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
void clear();
|
||||
void setPrintMode(bool mode, bool grayscale = false);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent* event);
|
||||
void wheelEvent(QWheelEvent* event);
|
||||
void showEvent(QShowEvent* event);
|
||||
void contextMenuEvent(QContextMenuEvent* event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
void showEvent(QShowEvent *event);
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void refresh();
|
||||
void edit_dive_time(const QString& time);
|
||||
void edit_dive_time(const QString &time);
|
||||
void on_rulerAction();
|
||||
void on_scaleAction();
|
||||
void changeGas();
|
||||
|
@ -112,9 +113,10 @@ public slots:
|
|||
void unhideEvents();
|
||||
void removeEvent();
|
||||
void addBookmark();
|
||||
|
||||
private:
|
||||
void plot_depth_profile();
|
||||
QGraphicsItemGroup *plot_text(text_render_options_t *tro, const QPointF& pos, const QString &text, QGraphicsItem *parent = 0);
|
||||
QGraphicsItemGroup *plot_text(text_render_options_t *tro, const QPointF &pos, const QString &text, QGraphicsItem *parent = 0);
|
||||
void plot_events(struct divecomputer *dc);
|
||||
void plot_one_event(struct event *event);
|
||||
void plot_temperature_profile();
|
||||
|
@ -123,7 +125,7 @@ private:
|
|||
void plot_single_temp_text(int sec, int mkelvin);
|
||||
void plot_depth_text();
|
||||
void plot_text_samples();
|
||||
void plot_depth_sample(plot_data* entry, text_render_options_t* tro);
|
||||
void plot_depth_sample(plot_data *entry, text_render_options_t *tro);
|
||||
void plot_cylinder_pressure_text();
|
||||
void plot_pressure_value(int mbar, int sec, double xalign, double yalign);
|
||||
void plot_gas_value(int mbar, int sec, double xalign, double yalign, int o2, int he);
|
||||
|
@ -143,7 +145,7 @@ private:
|
|||
QColor getColor(const color_indice_t i);
|
||||
QColor get_sac_color(int sac, int avg_sac);
|
||||
void scrollViewTo(const QPoint pos);
|
||||
void createPPLegend(QString tr, const QColor& c, QPointF& legendPos);
|
||||
void createPPLegend(QString tr, const QColor &c, QPointF &legendPos);
|
||||
|
||||
QPen defaultPen;
|
||||
QBrush defaultBrush;
|
||||
|
@ -158,10 +160,10 @@ private:
|
|||
bool isGrayscale;
|
||||
|
||||
// Top Level Items.
|
||||
QGraphicsItem* profileGrid;
|
||||
QGraphicsItem* timeMarkers;
|
||||
QGraphicsItem* depthMarkers;
|
||||
QGraphicsItem* diveComputer;
|
||||
QGraphicsItem *profileGrid;
|
||||
QGraphicsItem *timeMarkers;
|
||||
QGraphicsItem *depthMarkers;
|
||||
QGraphicsItem *diveComputer;
|
||||
RulerItem *rulerItem;
|
||||
QGraphicsProxyWidget *toolBarProxy;
|
||||
|
||||
|
|
|
@ -25,15 +25,16 @@ public:
|
|||
QLabel *minIco, *minValue;
|
||||
QLabel *maxIco, *maxValue;
|
||||
|
||||
MinMaxAvgWidgetPrivate(MinMaxAvgWidget *owner) {
|
||||
MinMaxAvgWidgetPrivate(MinMaxAvgWidget *owner)
|
||||
{
|
||||
avgIco = new QLabel(owner);
|
||||
avgIco->setPixmap(QIcon(":/average").pixmap(16,16));
|
||||
avgIco->setPixmap(QIcon(":/average").pixmap(16, 16));
|
||||
avgIco->setToolTip(QObject::tr("Average"));
|
||||
minIco = new QLabel(owner);
|
||||
minIco->setPixmap(QIcon(":/minimum").pixmap(16,16));
|
||||
minIco->setPixmap(QIcon(":/minimum").pixmap(16, 16));
|
||||
minIco->setToolTip(QObject::tr("Minimum"));
|
||||
maxIco = new QLabel(owner);
|
||||
maxIco->setPixmap(QIcon(":/maximum").pixmap(16,16));
|
||||
maxIco->setPixmap(QIcon(":/maximum").pixmap(16, 16));
|
||||
maxIco->setToolTip(QObject::tr("Maximum"));
|
||||
avgValue = new QLabel(owner);
|
||||
minValue = new QLabel(owner);
|
||||
|
@ -64,9 +65,8 @@ double MinMaxAvgWidget::minimum() const
|
|||
return d->minValue->text().toDouble();
|
||||
}
|
||||
|
||||
MinMaxAvgWidget::MinMaxAvgWidget(QWidget* parent) : d(new MinMaxAvgWidgetPrivate(this))
|
||||
MinMaxAvgWidget::MinMaxAvgWidget(QWidget *parent) : d(new MinMaxAvgWidgetPrivate(this))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MinMaxAvgWidget::~MinMaxAvgWidget()
|
||||
|
@ -94,28 +94,28 @@ void MinMaxAvgWidget::setMinimum(double minimum)
|
|||
d->minValue->setText(QString::number(minimum));
|
||||
}
|
||||
|
||||
void MinMaxAvgWidget::setAverage(const QString& average)
|
||||
void MinMaxAvgWidget::setAverage(const QString &average)
|
||||
{
|
||||
d->avgValue->setText(average);
|
||||
}
|
||||
|
||||
void MinMaxAvgWidget::setMaximum(const QString& maximum)
|
||||
void MinMaxAvgWidget::setMaximum(const QString &maximum)
|
||||
{
|
||||
d->maxValue->setText(maximum);
|
||||
}
|
||||
|
||||
void MinMaxAvgWidget::setMinimum(const QString& minimum)
|
||||
void MinMaxAvgWidget::setMinimum(const QString &minimum)
|
||||
{
|
||||
d->minValue->setText(minimum);
|
||||
}
|
||||
|
||||
RenumberDialog* RenumberDialog::instance()
|
||||
RenumberDialog *RenumberDialog::instance()
|
||||
{
|
||||
static RenumberDialog* self = new RenumberDialog(MainWindow::instance());
|
||||
static RenumberDialog *self = new RenumberDialog(MainWindow::instance());
|
||||
return self;
|
||||
}
|
||||
|
||||
void RenumberDialog::buttonClicked(QAbstractButton* button)
|
||||
void RenumberDialog::buttonClicked(QAbstractButton *button)
|
||||
{
|
||||
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
|
||||
qDebug() << "Renumbering.";
|
||||
|
@ -123,19 +123,19 @@ void RenumberDialog::buttonClicked(QAbstractButton* button)
|
|||
}
|
||||
}
|
||||
|
||||
RenumberDialog::RenumberDialog(QWidget *parent): QDialog(parent)
|
||||
RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
|
||||
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
||||
}
|
||||
|
||||
ShiftTimesDialog* ShiftTimesDialog::instance()
|
||||
ShiftTimesDialog *ShiftTimesDialog::instance()
|
||||
{
|
||||
static ShiftTimesDialog* self = new ShiftTimesDialog(MainWindow::instance());
|
||||
static ShiftTimesDialog *self = new ShiftTimesDialog(MainWindow::instance());
|
||||
return self;
|
||||
}
|
||||
|
||||
void ShiftTimesDialog::buttonClicked(QAbstractButton* button)
|
||||
void ShiftTimesDialog::buttonClicked(QAbstractButton *button)
|
||||
{
|
||||
int amount;
|
||||
|
||||
|
@ -155,19 +155,18 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton* button)
|
|||
}
|
||||
}
|
||||
|
||||
ShiftTimesDialog::ShiftTimesDialog(QWidget *parent): QDialog(parent)
|
||||
ShiftTimesDialog::ShiftTimesDialog(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
|
||||
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
||||
}
|
||||
|
||||
void ShiftImageTimesDialog::buttonClicked(QAbstractButton* button)
|
||||
void ShiftImageTimesDialog::buttonClicked(QAbstractButton *button)
|
||||
{
|
||||
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
|
||||
m_amount = ui.timeEdit->time().hour() * 3600 + ui.timeEdit->time().minute() * 60;
|
||||
if (ui.backwards->isChecked())
|
||||
m_amount *= -1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,13 +186,13 @@ void ShiftImageTimesDialog::syncCameraClicked()
|
|||
|
||||
picture.load(fileNames.at(0));
|
||||
ui.displayDC->setEnabled(true);
|
||||
QGraphicsScene *scene = new QGraphicsScene (this);
|
||||
QGraphicsScene *scene = new QGraphicsScene(this);
|
||||
|
||||
scene->addPixmap(picture.scaled(ui.DCImage->size()));
|
||||
ui.DCImage->setScene(scene);
|
||||
if (readfile(fileNames.at(0).toUtf8().data(), &mem) <= 0)
|
||||
return;
|
||||
retval = exiv.parseFrom((const unsigned char *) mem.buffer, (unsigned) mem.size);
|
||||
retval = exiv.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
|
||||
free(mem.buffer);
|
||||
if (retval != PARSE_EXIF_SUCCESS)
|
||||
return;
|
||||
|
@ -228,12 +227,12 @@ void ShiftImageTimesDialog::dcDateTimeChanged(const QDateTime &newDateTime)
|
|||
setOffset(newDateTime.toTime_t() - dcImageEpoch);
|
||||
}
|
||||
|
||||
ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent): QDialog(parent), m_amount(0)
|
||||
ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent) : QDialog(parent), m_amount(0)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
|
||||
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
||||
connect(ui.syncCamera, SIGNAL(clicked()), this, SLOT(syncCameraClicked()));
|
||||
dcImageEpoch = (time_t) 0;
|
||||
dcImageEpoch = (time_t)0;
|
||||
}
|
||||
|
||||
time_t ShiftImageTimesDialog::amount() const
|
||||
|
@ -260,7 +259,7 @@ bool isGnome3Session()
|
|||
if (qApp->style()->objectName() != "gtk+")
|
||||
return false;
|
||||
QProcess p;
|
||||
p.start("pidof", QStringList() << "gnome-shell" );
|
||||
p.start("pidof", QStringList() << "gnome-shell");
|
||||
p.waitForFinished(-1);
|
||||
QString p_stdout = p.readAllStandardOutput();
|
||||
return !p_stdout.isEmpty();
|
||||
|
|
|
@ -12,7 +12,7 @@ class QAbstractButton;
|
|||
#include "ui_shiftimagetimes.h"
|
||||
#include "exif.h"
|
||||
|
||||
class MinMaxAvgWidget : public QWidget{
|
||||
class MinMaxAvgWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
|
||||
Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
|
||||
|
@ -26,10 +26,11 @@ public:
|
|||
void setMinimum(double minimum);
|
||||
void setMaximum(double maximum);
|
||||
void setAverage(double average);
|
||||
void setMinimum(const QString& minimum);
|
||||
void setMaximum(const QString& maximum);
|
||||
void setAverage(const QString& average);
|
||||
void setMinimum(const QString &minimum);
|
||||
void setMaximum(const QString &maximum);
|
||||
void setAverage(const QString &average);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
QScopedPointer<MinMaxAvgWidgetPrivate> d;
|
||||
};
|
||||
|
@ -38,8 +39,10 @@ class RenumberDialog : public QDialog {
|
|||
Q_OBJECT
|
||||
public:
|
||||
static RenumberDialog *instance();
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
void buttonClicked(QAbstractButton *button);
|
||||
|
||||
private:
|
||||
explicit RenumberDialog(QWidget *parent);
|
||||
Ui::RenumberDialog ui;
|
||||
|
@ -49,8 +52,10 @@ class ShiftTimesDialog : public QDialog {
|
|||
Q_OBJECT
|
||||
public:
|
||||
static ShiftTimesDialog *instance();
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
void buttonClicked(QAbstractButton *button);
|
||||
|
||||
private:
|
||||
explicit ShiftTimesDialog(QWidget *parent);
|
||||
Ui::ShiftTimesDialog ui;
|
||||
|
@ -63,10 +68,12 @@ public:
|
|||
time_t amount() const;
|
||||
void setOffset(time_t offset);
|
||||
time_t epochFromExiv(EXIFInfo *exif);
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
void buttonClicked(QAbstractButton *button);
|
||||
void syncCameraClicked();
|
||||
void dcDateTimeChanged(const QDateTime &);
|
||||
|
||||
private:
|
||||
Ui::ShiftImageTimesDialog ui;
|
||||
time_t m_amount;
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#include <QStyle>
|
||||
#include <QStyleOption>
|
||||
|
||||
QPixmap* StarWidget::activeStar = 0;
|
||||
QPixmap* StarWidget::inactiveStar = 0;
|
||||
QPixmap *StarWidget::activeStar = 0;
|
||||
QPixmap *StarWidget::inactiveStar = 0;
|
||||
|
||||
QPixmap StarWidget::starActive()
|
||||
{
|
||||
|
@ -26,7 +26,7 @@ int StarWidget::currentStars() const
|
|||
return current;
|
||||
}
|
||||
|
||||
void StarWidget::mouseReleaseEvent(QMouseEvent* event)
|
||||
void StarWidget::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (readOnly) {
|
||||
return;
|
||||
|
@ -45,14 +45,14 @@ void StarWidget::mouseReleaseEvent(QMouseEvent* event)
|
|||
update();
|
||||
}
|
||||
|
||||
void StarWidget::paintEvent(QPaintEvent* event)
|
||||
void StarWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter p(this);
|
||||
|
||||
for(int i = 0; i < current; i++)
|
||||
for (int i = 0; i < current; i++)
|
||||
p.drawPixmap(i * IMG_SIZE + SPACING, 0, starActive());
|
||||
|
||||
for(int i = current; i < TOTALSTARS; i++)
|
||||
for (int i = current; i < TOTALSTARS; i++)
|
||||
p.drawPixmap(i * IMG_SIZE + SPACING, 0, starInactive());
|
||||
|
||||
if (hasFocus()) {
|
||||
|
@ -70,8 +70,7 @@ void StarWidget::setCurrentStars(int value)
|
|||
Q_EMIT valueChanged(current);
|
||||
}
|
||||
|
||||
StarWidget::StarWidget(QWidget* parent, Qt::WindowFlags f):
|
||||
QWidget(parent, f),
|
||||
StarWidget::StarWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f),
|
||||
current(0),
|
||||
readOnly(false)
|
||||
{
|
||||
|
@ -93,7 +92,7 @@ StarWidget::StarWidget(QWidget* parent, Qt::WindowFlags f):
|
|||
setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
QPixmap StarWidget::grayImage(QPixmap* coloredImg)
|
||||
QPixmap StarWidget::grayImage(QPixmap *coloredImg)
|
||||
{
|
||||
QImage img = coloredImg->toImage();
|
||||
for (int i = 0; i < img.width(); ++i) {
|
||||
|
@ -113,7 +112,7 @@ QPixmap StarWidget::grayImage(QPixmap* coloredImg)
|
|||
|
||||
QSize StarWidget::sizeHint() const
|
||||
{
|
||||
return QSize(IMG_SIZE * TOTALSTARS + SPACING * (TOTALSTARS-1), IMG_SIZE);
|
||||
return QSize(IMG_SIZE * TOTALSTARS + SPACING * (TOTALSTARS - 1), IMG_SIZE);
|
||||
}
|
||||
|
||||
void StarWidget::setReadOnly(bool r)
|
||||
|
@ -121,27 +120,27 @@ void StarWidget::setReadOnly(bool r)
|
|||
readOnly = r;
|
||||
}
|
||||
|
||||
void StarWidget::focusInEvent(QFocusEvent* event)
|
||||
void StarWidget::focusInEvent(QFocusEvent *event)
|
||||
{
|
||||
setFocus();
|
||||
QWidget::focusInEvent(event);
|
||||
}
|
||||
|
||||
void StarWidget::focusOutEvent(QFocusEvent* event)
|
||||
void StarWidget::focusOutEvent(QFocusEvent *event)
|
||||
{
|
||||
QWidget::focusOutEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void StarWidget::keyPressEvent(QKeyEvent* event)
|
||||
void StarWidget::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Right) {
|
||||
if (currentStars() < TOTALSTARS) {
|
||||
setCurrentStars( currentStars()+1);
|
||||
setCurrentStars(currentStars() + 1);
|
||||
}
|
||||
} else if (event->key() == Qt::Key_Down || event->key() == Qt::Key_Left) {
|
||||
if (currentStars() > 0) {
|
||||
setCurrentStars( currentStars()-1);
|
||||
setCurrentStars(currentStars() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,16 @@
|
|||
|
||||
#include <QWidget>
|
||||
|
||||
enum StarConfig {SPACING = 2, IMG_SIZE = 16, TOTALSTARS = 5};
|
||||
enum StarConfig {
|
||||
SPACING = 2,
|
||||
IMG_SIZE = 16,
|
||||
TOTALSTARS = 5
|
||||
};
|
||||
|
||||
class StarWidget : public QWidget
|
||||
{
|
||||
class StarWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StarWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
explicit StarWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
int currentStars() const;
|
||||
|
||||
/*reimp*/ QSize sizeHint() const;
|
||||
|
@ -20,22 +23,24 @@ public:
|
|||
signals:
|
||||
void valueChanged(int stars);
|
||||
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void setCurrentStars(int value);
|
||||
void setReadOnly( bool readOnly);
|
||||
void setReadOnly(bool readOnly);
|
||||
|
||||
protected:
|
||||
/*reimp*/ void mouseReleaseEvent(QMouseEvent* );
|
||||
/*reimp*/ void paintEvent(QPaintEvent* );
|
||||
/*reimp*/ void focusInEvent(QFocusEvent*);
|
||||
/*reimp*/ void focusOutEvent(QFocusEvent*);
|
||||
/*reimp*/ void keyPressEvent(QKeyEvent*);
|
||||
/*reimp*/ void mouseReleaseEvent(QMouseEvent *);
|
||||
/*reimp*/ void paintEvent(QPaintEvent *);
|
||||
/*reimp*/ void focusInEvent(QFocusEvent *);
|
||||
/*reimp*/ void focusOutEvent(QFocusEvent *);
|
||||
/*reimp*/ void keyPressEvent(QKeyEvent *);
|
||||
|
||||
private:
|
||||
int current;
|
||||
bool readOnly;
|
||||
|
||||
static QPixmap* activeStar;
|
||||
static QPixmap* inactiveStar;
|
||||
static QPixmap *activeStar;
|
||||
static QPixmap *inactiveStar;
|
||||
QPixmap grayImage(QPixmap *coloredImg);
|
||||
};
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
#include "../divelist.h"
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
# include <unistd.h> // for dup(2)
|
||||
#include <unistd.h> // for dup(2)
|
||||
#endif
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||
# include <QUrlQuery>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
#include <QUrlQuery>
|
||||
#endif
|
||||
|
||||
struct dive_table gps_location_table;
|
||||
|
@ -32,13 +32,13 @@ static bool merge_locations_into_dives(void);
|
|||
static bool is_automatic_fix(struct dive *gpsfix)
|
||||
{
|
||||
if (gpsfix && gpsfix->location &&
|
||||
(!strcmp(gpsfix->location, "automatic fix") ||
|
||||
!strcmp(gpsfix->location, "Auto-created dive")))
|
||||
(!strcmp(gpsfix->location, "automatic fix") ||
|
||||
!strcmp(gpsfix->location, "Auto-created dive")))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
#define SAME_GROUP 6 * 3600 // six hours
|
||||
#define SAME_GROUP 6 * 3600 // six hours
|
||||
|
||||
static bool merge_locations_into_dives(void)
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ static bool merge_locations_into_dives(void)
|
|||
utc_mkdate(gpsfix->when, &tm);
|
||||
printf("found dive named %s @ %04d-%02d-%02d %02d:%02d:%02d\n",
|
||||
gpsfix->location,
|
||||
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
|
||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
|
||||
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
#endif
|
||||
changed++;
|
||||
|
@ -85,7 +85,7 @@ static bool merge_locations_into_dives(void)
|
|||
#if DEBUG_WEBSERVICE
|
||||
printf("didn't find dive matching gps fix named %s @ %04d-%02d-%02d %02d:%02d:%02d\n",
|
||||
gpsfix->location,
|
||||
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
|
||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
|
||||
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
#endif
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
|
|||
char buffer[1024];
|
||||
zip_error_to_str(buffer, sizeof buffer, error_code, errno);
|
||||
*errorMsg = tr("failed to create zip file for upload: %1")
|
||||
.arg(QString::fromLocal8Bit(buffer));
|
||||
.arg(QString::fromLocal8Bit(buffer));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
|
|||
free((void *)membuf);
|
||||
|
||||
transformed = xsltApplyStylesheet(xslt, doc, NULL);
|
||||
xmlDocDumpMemory(transformed, (xmlChar **) &membuf, &streamsize);
|
||||
xmlDocDumpMemory(transformed, (xmlChar **)&membuf, &streamsize);
|
||||
xmlFreeDoc(doc);
|
||||
xmlFreeDoc(transformed);
|
||||
|
||||
|
@ -209,11 +209,10 @@ error_close_zip:
|
|||
return false;
|
||||
}
|
||||
|
||||
WebServices::WebServices(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f)
|
||||
, reply(0)
|
||||
WebServices::WebServices(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), reply(0)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
|
||||
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
||||
connect(ui.download, SIGNAL(clicked(bool)), this, SLOT(startDownload()));
|
||||
connect(ui.upload, SIGNAL(clicked(bool)), this, SLOT(startUpload()));
|
||||
connect(&timeout, SIGNAL(timeout()), this, SLOT(downloadTimedOut()));
|
||||
|
@ -286,8 +285,8 @@ void WebServices::connectSignalsForDownload(QNetworkReply *reply)
|
|||
connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished()));
|
||||
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
|
||||
this, SLOT(downloadError(QNetworkReply::NetworkError)));
|
||||
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this,
|
||||
SLOT(updateProgress(qint64,qint64)));
|
||||
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this,
|
||||
SLOT(updateProgress(qint64, qint64)));
|
||||
|
||||
timeout.start(30000); // 30s
|
||||
}
|
||||
|
@ -299,7 +298,7 @@ void WebServices::resetState()
|
|||
ui.userID->setEnabled(true);
|
||||
ui.password->setEnabled(true);
|
||||
ui.progressBar->reset();
|
||||
ui.progressBar->setRange(0,1);
|
||||
ui.progressBar->setRange(0, 1);
|
||||
ui.status->setText(QString());
|
||||
ui.buttonBox->button(QDialogButtonBox::Apply)->setText(defaultApplyText);
|
||||
}
|
||||
|
@ -310,18 +309,18 @@ void WebServices::resetState()
|
|||
// #
|
||||
// #
|
||||
|
||||
SubsurfaceWebServices::SubsurfaceWebServices(QWidget* parent, Qt::WindowFlags f) : WebServices(parent, f)
|
||||
SubsurfaceWebServices::SubsurfaceWebServices(QWidget *parent, Qt::WindowFlags f) : WebServices(parent, f)
|
||||
{
|
||||
QSettings s;
|
||||
ui.userID->setText(s.value("subsurface_webservice_uid").toString().toUpper());
|
||||
hidePassword();
|
||||
hideUpload();
|
||||
ui.progressBar->setFormat("Enter User ID and click Download");
|
||||
ui.progressBar->setRange(0,1);
|
||||
ui.progressBar->setRange(0, 1);
|
||||
ui.progressBar->setValue(-1);
|
||||
}
|
||||
|
||||
void SubsurfaceWebServices::buttonClicked(QAbstractButton* button)
|
||||
void SubsurfaceWebServices::buttonClicked(QAbstractButton *button)
|
||||
{
|
||||
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
|
||||
switch (ui.buttonBox->buttonRole(button)) {
|
||||
|
@ -345,8 +344,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button)
|
|||
hide();
|
||||
close();
|
||||
resetState();
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case QDialogButtonBox::RejectRole:
|
||||
if (reply != NULL && reply->isOpen()) {
|
||||
reply->abort();
|
||||
|
@ -366,7 +364,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button)
|
|||
void SubsurfaceWebServices::startDownload()
|
||||
{
|
||||
QUrl url("http://api.hohndel.org/api/dive/get/");
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
url.addQueryItem("login", ui.userID->text().toUpper());
|
||||
#else
|
||||
QUrlQuery query;
|
||||
|
@ -380,7 +378,7 @@ void SubsurfaceWebServices::startDownload()
|
|||
reply = manager()->get(request);
|
||||
ui.status->setText(tr("Connecting..."));
|
||||
ui.progressBar->setEnabled(true);
|
||||
ui.progressBar->setRange(0,0); // this makes the progressbar do an 'infinite spin'
|
||||
ui.progressBar->setRange(0, 0); // this makes the progressbar do an 'infinite spin'
|
||||
ui.download->setEnabled(false);
|
||||
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
|
||||
connectSignalsForDownload(reply);
|
||||
|
@ -391,7 +389,7 @@ void SubsurfaceWebServices::downloadFinished()
|
|||
if (!reply)
|
||||
return;
|
||||
|
||||
ui.progressBar->setRange(0,1);
|
||||
ui.progressBar->setRange(0, 1);
|
||||
ui.progressBar->setValue(1);
|
||||
ui.progressBar->setFormat("%p%");
|
||||
downloadedData = reply->readAll();
|
||||
|
@ -420,10 +418,18 @@ void SubsurfaceWebServices::setStatusText(int status)
|
|||
{
|
||||
QString text;
|
||||
switch (status) {
|
||||
case DD_STATUS_ERROR_CONNECT: text = tr("Connection Error: "); break;
|
||||
case DD_STATUS_ERROR_ID: text = tr("Invalid user identifier!"); break;
|
||||
case DD_STATUS_ERROR_PARSE: text = tr("Cannot parse response!"); break;
|
||||
case DD_STATUS_OK: text = tr("Download Success!"); break;
|
||||
case DD_STATUS_ERROR_CONNECT:
|
||||
text = tr("Connection Error: ");
|
||||
break;
|
||||
case DD_STATUS_ERROR_ID:
|
||||
text = tr("Invalid user identifier!");
|
||||
break;
|
||||
case DD_STATUS_ERROR_PARSE:
|
||||
text = tr("Cannot parse response!");
|
||||
break;
|
||||
case DD_STATUS_OK:
|
||||
text = tr("Download Success!");
|
||||
break;
|
||||
}
|
||||
ui.status->setText(text);
|
||||
}
|
||||
|
@ -434,17 +440,17 @@ void SubsurfaceWebServices::download_dialog_traverse_xml(xmlNodePtr node, unsign
|
|||
xmlNodePtr cur_node;
|
||||
for (cur_node = node; cur_node; cur_node = cur_node->next) {
|
||||
if ((!strcmp((const char *)cur_node->name, (const char *)"download")) &&
|
||||
(!strcmp((const char *)xmlNodeGetContent(cur_node), (const char *)"ok"))) {
|
||||
(!strcmp((const char *)xmlNodeGetContent(cur_node), (const char *)"ok"))) {
|
||||
*download_status = DD_STATUS_OK;
|
||||
return;
|
||||
} else if (!strcmp((const char *)cur_node->name, (const char *)"error")) {
|
||||
} else if (!strcmp((const char *)cur_node->name, (const char *)"error")) {
|
||||
*download_status = DD_STATUS_ERROR_ID;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int SubsurfaceWebServices::download_dialog_parse_response(const QByteArray& xml)
|
||||
unsigned int SubsurfaceWebServices::download_dialog_parse_response(const QByteArray &xml)
|
||||
{
|
||||
xmlNodePtr root;
|
||||
xmlDocPtr doc = xmlParseMemory(xml.data(), xml.length());
|
||||
|
@ -470,8 +476,7 @@ end:
|
|||
// #
|
||||
// #
|
||||
|
||||
struct DiveListResult
|
||||
{
|
||||
struct DiveListResult {
|
||||
QString errorCondition;
|
||||
QString errorDetails;
|
||||
QByteArray idList; // comma-separated, suitable to be sent in the fetch request
|
||||
|
@ -497,8 +502,8 @@ static DiveListResult parseDiveLogsDeDiveList(const QByteArray &xmlData)
|
|||
if (reader.readNextStartElement() && reader.name() != "DiveDateReader") {
|
||||
result.errorCondition = invalidXmlError;
|
||||
result.errorDetails =
|
||||
DivelogsDeWebServices::tr("Expected XML tag 'DiveDateReader', got instead '%1")
|
||||
.arg(reader.name().toString());
|
||||
DivelogsDeWebServices::tr("Expected XML tag 'DiveDateReader', got instead '%1")
|
||||
.arg(reader.name().toString());
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
@ -551,12 +556,13 @@ out:
|
|||
// if there was an XML error, overwrite the result or other error conditions
|
||||
result.errorCondition = invalidXmlError;
|
||||
result.errorDetails = DivelogsDeWebServices::tr("Malformed XML response. Line %1: %2")
|
||||
.arg(reader.lineNumber()).arg(reader.errorString());
|
||||
.arg(reader.lineNumber())
|
||||
.arg(reader.errorString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
DivelogsDeWebServices* DivelogsDeWebServices::instance()
|
||||
DivelogsDeWebServices *DivelogsDeWebServices::instance()
|
||||
{
|
||||
static DivelogsDeWebServices *self = new DivelogsDeWebServices(MainWindow::instance());
|
||||
self->setAttribute(Qt::WA_QuitOnClose, false);
|
||||
|
@ -617,7 +623,7 @@ void DivelogsDeWebServices::uploadDives(QIODevice *dldContent)
|
|||
}
|
||||
}
|
||||
|
||||
DivelogsDeWebServices::DivelogsDeWebServices(QWidget* parent, Qt::WindowFlags f) : WebServices(parent, f), uploadMode(false)
|
||||
DivelogsDeWebServices::DivelogsDeWebServices(QWidget *parent, Qt::WindowFlags f) : WebServices(parent, f), uploadMode(false)
|
||||
{
|
||||
QSettings s;
|
||||
ui.userID->setText(s.value("divelogde_user").toString());
|
||||
|
@ -633,7 +639,7 @@ void DivelogsDeWebServices::startUpload()
|
|||
s.sync();
|
||||
|
||||
ui.status->setText(tr("Uploading dive list..."));
|
||||
ui.progressBar->setRange(0,0); // this makes the progressbar do an 'infinite spin'
|
||||
ui.progressBar->setRange(0, 0); // this makes the progressbar do an 'infinite spin'
|
||||
ui.upload->setEnabled(false);
|
||||
ui.userID->setEnabled(false);
|
||||
ui.password->setEnabled(false);
|
||||
|
@ -655,8 +661,8 @@ void DivelogsDeWebServices::startUpload()
|
|||
connect(reply, SIGNAL(finished()), this, SLOT(uploadFinished()));
|
||||
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this,
|
||||
SLOT(uploadError(QNetworkReply::NetworkError)));
|
||||
connect(reply, SIGNAL(uploadProgress(qint64,qint64)), this,
|
||||
SLOT(updateProgress(qint64,qint64)));
|
||||
connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this,
|
||||
SLOT(updateProgress(qint64, qint64)));
|
||||
|
||||
timeout.start(30000); // 30s
|
||||
}
|
||||
|
@ -664,7 +670,7 @@ void DivelogsDeWebServices::startUpload()
|
|||
void DivelogsDeWebServices::startDownload()
|
||||
{
|
||||
ui.status->setText(tr("Downloading dive list..."));
|
||||
ui.progressBar->setRange(0,0); // this makes the progressbar do an 'infinite spin'
|
||||
ui.progressBar->setRange(0, 0); // this makes the progressbar do an 'infinite spin'
|
||||
ui.download->setEnabled(false);
|
||||
ui.userID->setEnabled(false);
|
||||
ui.password->setEnabled(false);
|
||||
|
@ -674,7 +680,7 @@ void DivelogsDeWebServices::startDownload()
|
|||
request.setRawHeader("Accept", "text/xml, application/xml");
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
QUrl body;
|
||||
body.addQueryItem("user", ui.userID->text());
|
||||
body.addQueryItem("pass", ui.password->text());
|
||||
|
@ -718,7 +724,7 @@ void DivelogsDeWebServices::listDownloadFinished()
|
|||
request.setRawHeader("Accept", "application/zip, */*");
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
QUrl body;
|
||||
body.addQueryItem("user", ui.userID->text());
|
||||
body.addQueryItem("pass", ui.password->text());
|
||||
|
@ -788,7 +794,7 @@ void DivelogsDeWebServices::uploadFinished()
|
|||
if (!reply)
|
||||
return;
|
||||
|
||||
ui.progressBar->setRange(0,1);
|
||||
ui.progressBar->setRange(0, 1);
|
||||
ui.upload->setEnabled(true);
|
||||
ui.userID->setEnabled(true);
|
||||
ui.password->setEnabled(true);
|
||||
|
@ -823,7 +829,6 @@ void DivelogsDeWebServices::uploadFinished()
|
|||
|
||||
void DivelogsDeWebServices::setStatusText(int status)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DivelogsDeWebServices::downloadError(QNetworkReply::NetworkError)
|
||||
|
@ -839,7 +844,7 @@ void DivelogsDeWebServices::uploadError(QNetworkReply::NetworkError error)
|
|||
downloadError(error);
|
||||
}
|
||||
|
||||
void DivelogsDeWebServices::buttonClicked(QAbstractButton* button)
|
||||
void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
|
||||
{
|
||||
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
|
||||
switch (ui.buttonBox->buttonRole(button)) {
|
||||
|
@ -869,8 +874,7 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton* button)
|
|||
hide();
|
||||
close();
|
||||
resetState();
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case QDialogButtonBox::RejectRole:
|
||||
// these two seem to be causing a crash:
|
||||
// reply->deleteLater();
|
||||
|
|
|
@ -13,23 +13,25 @@ class QAbstractButton;
|
|||
class QNetworkReply;
|
||||
class QHttpMultiPart;
|
||||
|
||||
class WebServices : public QDialog{
|
||||
class WebServices : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit WebServices(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
explicit WebServices(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
void hidePassword();
|
||||
void hideUpload();
|
||||
void hideDownload();
|
||||
|
||||
static QNetworkAccessManager *manager();
|
||||
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
virtual void startDownload() = 0;
|
||||
virtual void startUpload() = 0;
|
||||
virtual void buttonClicked(QAbstractButton* button) = 0;
|
||||
virtual void buttonClicked(QAbstractButton *button) = 0;
|
||||
virtual void downloadTimedOut();
|
||||
|
||||
protected slots:
|
||||
protected
|
||||
slots:
|
||||
void updateProgress(qint64 current, qint64 total);
|
||||
|
||||
protected:
|
||||
|
@ -47,30 +49,34 @@ protected:
|
|||
class SubsurfaceWebServices : public WebServices {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SubsurfaceWebServices(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
explicit SubsurfaceWebServices(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
void startDownload();
|
||||
void buttonClicked(QAbstractButton* button);
|
||||
void buttonClicked(QAbstractButton *button);
|
||||
void downloadFinished();
|
||||
void downloadError(QNetworkReply::NetworkError error);
|
||||
void startUpload(){} /*no op*/
|
||||
void startUpload()
|
||||
{
|
||||
} /*no op*/
|
||||
private:
|
||||
void setStatusText(int status);
|
||||
void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status);
|
||||
unsigned int download_dialog_parse_response(const QByteArray& length);
|
||||
unsigned int download_dialog_parse_response(const QByteArray &length);
|
||||
};
|
||||
|
||||
class DivelogsDeWebServices : public WebServices {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static DivelogsDeWebServices * instance();
|
||||
static DivelogsDeWebServices *instance();
|
||||
void downloadDives();
|
||||
void prepareDivesForUpload();
|
||||
|
||||
private slots:
|
||||
private
|
||||
slots:
|
||||
void startDownload();
|
||||
void buttonClicked(QAbstractButton* button);
|
||||
void buttonClicked(QAbstractButton *button);
|
||||
void saveToZipFile();
|
||||
void listDownloadFinished();
|
||||
void downloadFinished();
|
||||
|
@ -78,13 +84,14 @@ private slots:
|
|||
void downloadError(QNetworkReply::NetworkError error);
|
||||
void uploadError(QNetworkReply::NetworkError error);
|
||||
void startUpload();
|
||||
|
||||
private:
|
||||
void uploadDives(QIODevice *dldContent);
|
||||
explicit DivelogsDeWebServices (QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
explicit DivelogsDeWebServices(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
void setStatusText(int status);
|
||||
bool prepare_dives_for_divelogs(const QString &filename, bool selected, QString *errorMsg);
|
||||
void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status);
|
||||
unsigned int download_dialog_parse_response(const QByteArray& length);
|
||||
unsigned int download_dialog_parse_response(const QByteArray &length);
|
||||
|
||||
QHttpMultiPart *multipart;
|
||||
QTemporaryFile zipFile;
|
||||
|
|
|
@ -21,7 +21,7 @@ TableView::TableView(QWidget *parent) : QWidget(parent)
|
|||
plusBtn = new QPushButton(plusIcon, QString(), ui.groupBox);
|
||||
plusBtn->setFlat(true);
|
||||
plusBtn->setToolTip(tr("Add Cylinder"));
|
||||
plusBtn->setIconSize(QSize(16,16));
|
||||
plusBtn->setIconSize(QSize(16, 16));
|
||||
connect(plusBtn, SIGNAL(clicked(bool)), this, SIGNAL(addButtonClicked()));
|
||||
}
|
||||
|
||||
|
@ -35,12 +35,12 @@ TableView::~TableView()
|
|||
s.endGroup();
|
||||
}
|
||||
|
||||
void TableView::setBtnToolTip(const QString& tooltip)
|
||||
void TableView::setBtnToolTip(const QString &tooltip)
|
||||
{
|
||||
plusBtn->setToolTip(tooltip);
|
||||
}
|
||||
|
||||
void TableView::setTitle(const QString& title)
|
||||
void TableView::setTitle(const QString &title)
|
||||
{
|
||||
ui.groupBox->setTitle(title);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ void TableView::setModel(QAbstractItemModel *model)
|
|||
s.beginGroup(objectName());
|
||||
const int columnCount = ui.tableView->model()->columnCount();
|
||||
for (int i = 0; i < columnCount; i++) {
|
||||
QVariant width = s.value(QString("colwidth%1").arg(i), i == CylindersModel::REMOVE ? 30 : 80 );
|
||||
QVariant width = s.value(QString("colwidth%1").arg(i), i == CylindersModel::REMOVE ? 30 : 80);
|
||||
ui.tableView->setColumnWidth(i, width.toInt());
|
||||
}
|
||||
s.endGroup();
|
||||
|
@ -65,23 +65,23 @@ void TableView::setModel(QAbstractItemModel *model)
|
|||
|
||||
void TableView::fixPlusPosition()
|
||||
{
|
||||
plusBtn->setGeometry(ui.groupBox->contentsRect().width() - 30, 2, 24,24);
|
||||
plusBtn->setGeometry(ui.groupBox->contentsRect().width() - 30, 2, 24, 24);
|
||||
}
|
||||
|
||||
// We need to manually position the 'plus' on cylinder and weight.
|
||||
void TableView::resizeEvent(QResizeEvent* event)
|
||||
void TableView::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
fixPlusPosition();
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
void TableView::showEvent(QShowEvent* event)
|
||||
void TableView::showEvent(QShowEvent *event)
|
||||
{
|
||||
QWidget::showEvent(event);
|
||||
fixPlusPosition();
|
||||
}
|
||||
|
||||
void TableView::edit(const QModelIndex& index)
|
||||
void TableView::edit(const QModelIndex &index)
|
||||
{
|
||||
ui.tableView->edit(index);
|
||||
}
|
||||
|
|
|
@ -15,23 +15,24 @@ class QModelIndex;
|
|||
class QTableView;
|
||||
|
||||
class TableView : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
TableView(QWidget *parent = 0);
|
||||
virtual ~TableView();
|
||||
void setTitle(const QString& title);
|
||||
void setTitle(const QString &title);
|
||||
/* The model is expected to have a 'remove' slot, that takes a QModelIndex as parameter.
|
||||
* It's also expected to have the column '1' as a trash icon. I most probably should create a
|
||||
* proxy model and add that column, will mark that as TODO. see? marked.
|
||||
*/
|
||||
void setModel(QAbstractItemModel* model);
|
||||
void setBtnToolTip(const QString& tooltip);
|
||||
void setModel(QAbstractItemModel *model);
|
||||
void setBtnToolTip(const QString &tooltip);
|
||||
void fixPlusPosition();
|
||||
void edit(const QModelIndex& index);
|
||||
void edit(const QModelIndex &index);
|
||||
QTableView *view();
|
||||
|
||||
protected:
|
||||
virtual void showEvent(QShowEvent* );
|
||||
virtual void resizeEvent(QResizeEvent* );
|
||||
virtual void showEvent(QShowEvent *);
|
||||
virtual void resizeEvent(QResizeEvent *);
|
||||
|
||||
signals:
|
||||
void addButtonClicked();
|
||||
|
|
|
@ -14,18 +14,18 @@ TagWidget::TagWidget(QWidget *parent) : GroupedLineEdit(parent), m_completer(NUL
|
|||
qreal h, s, l, a;
|
||||
textColor.getHslF(&h, &s, &l, &a);
|
||||
// I use dark themes
|
||||
if (l <= 0.3 ) { // very dark text. get a brigth background
|
||||
addColor( QColor(Qt::red).lighter(120) );
|
||||
addColor( QColor(Qt::green).lighter(120) );
|
||||
addColor( QColor(Qt::blue).lighter(120) );
|
||||
} else if ( l <= 0.6 ) { // moderated dark text. get a somewhat brigth background
|
||||
addColor( QColor(Qt::red).lighter(60) );
|
||||
addColor( QColor(Qt::green).lighter(60) );
|
||||
addColor( QColor(Qt::blue).lighter(60) );
|
||||
if (l <= 0.3) { // very dark text. get a brigth background
|
||||
addColor(QColor(Qt::red).lighter(120));
|
||||
addColor(QColor(Qt::green).lighter(120));
|
||||
addColor(QColor(Qt::blue).lighter(120));
|
||||
} else if (l <= 0.6) { // moderated dark text. get a somewhat brigth background
|
||||
addColor(QColor(Qt::red).lighter(60));
|
||||
addColor(QColor(Qt::green).lighter(60));
|
||||
addColor(QColor(Qt::blue).lighter(60));
|
||||
} else {
|
||||
addColor( QColor(Qt::red).darker(120) );
|
||||
addColor( QColor(Qt::green).darker(120) );
|
||||
addColor( QColor(Qt::blue).darker(120) );
|
||||
addColor(QColor(Qt::red).darker(120));
|
||||
addColor(QColor(Qt::green).darker(120));
|
||||
addColor(QColor(Qt::blue).darker(120));
|
||||
} // light text. get a dark background.
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
@ -38,13 +38,14 @@ void TagWidget::setCompleter(QCompleter *completer)
|
|||
connect(m_completer, SIGNAL(highlighted(QString)), this, SLOT(completionSelected(QString)));
|
||||
}
|
||||
|
||||
QPair<int,int> TagWidget::getCursorTagPosition() {
|
||||
QPair<int, int> TagWidget::getCursorTagPosition()
|
||||
{
|
||||
int i = 0, start = 0, end = 0;
|
||||
/* Parse string near cursor */
|
||||
i = cursorPosition();
|
||||
while (--i > 0) {
|
||||
if (text().at(i) == ',') {
|
||||
if (i > 0 && text().at(i-1) != '\\') {
|
||||
if (i > 0 && text().at(i - 1) != '\\') {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
|
@ -53,7 +54,7 @@ QPair<int,int> TagWidget::getCursorTagPosition() {
|
|||
start = i;
|
||||
while (++i < text().length()) {
|
||||
if (text().at(i) == ',') {
|
||||
if (i > 0 && text().at(i-1) != '\\')
|
||||
if (i > 0 && text().at(i - 1) != '\\')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -62,24 +63,28 @@ QPair<int,int> TagWidget::getCursorTagPosition() {
|
|||
start = 0;
|
||||
end = 0;
|
||||
}
|
||||
return qMakePair(start,end);
|
||||
return qMakePair(start, end);
|
||||
}
|
||||
|
||||
enum ParseState {FINDSTART, FINDEND};
|
||||
enum ParseState {
|
||||
FINDSTART,
|
||||
FINDEND
|
||||
};
|
||||
|
||||
void TagWidget::highlight() {
|
||||
void TagWidget::highlight()
|
||||
{
|
||||
int i = 0, start = 0, end = 0;
|
||||
ParseState state = FINDEND;
|
||||
removeAllBlocks();
|
||||
|
||||
while(i < text().length()) {
|
||||
while (i < text().length()) {
|
||||
if (text().at(i) == ',') {
|
||||
if (state == FINDSTART) {
|
||||
/* Detect empty tags */
|
||||
} else if (state == FINDEND) {
|
||||
/* Found end of tag */
|
||||
if (i > 1) {
|
||||
if (text().at(i-1) != '\\') {
|
||||
if (text().at(i - 1) != '\\') {
|
||||
addBlock(start, end);
|
||||
state = FINDSTART;
|
||||
}
|
||||
|
@ -102,7 +107,7 @@ void TagWidget::highlight() {
|
|||
}
|
||||
if (state == FINDEND) {
|
||||
if (end < start)
|
||||
end = text().length()-1;
|
||||
end = text().length() - 1;
|
||||
if (text().length() > 0)
|
||||
addBlock(start, end);
|
||||
}
|
||||
|
@ -111,10 +116,10 @@ void TagWidget::highlight() {
|
|||
void TagWidget::reparse()
|
||||
{
|
||||
highlight();
|
||||
QPair<int,int> pos = getCursorTagPosition();
|
||||
QPair<int, int> pos = getCursorTagPosition();
|
||||
QString currentText;
|
||||
if (pos.first >= 0 && pos.second > 0)
|
||||
currentText = text().mid(pos.first, pos.second-pos.first).trimmed();
|
||||
currentText = text().mid(pos.first, pos.second - pos.first).trimmed();
|
||||
else
|
||||
currentText = "";
|
||||
if (m_completer) {
|
||||
|
@ -133,12 +138,13 @@ void TagWidget::reparse()
|
|||
}
|
||||
}
|
||||
|
||||
void TagWidget::completionSelected(QString completion) {
|
||||
QPair <int,int> pos;
|
||||
void TagWidget::completionSelected(QString completion)
|
||||
{
|
||||
QPair<int, int> pos;
|
||||
pos = getCursorTagPosition();
|
||||
if (pos.first >= 0 && pos.second > 0) {
|
||||
setText(text().remove(pos.first, pos.second-pos.first).insert(pos.first, completion));
|
||||
setCursorPosition(pos.first+completion.length());
|
||||
setText(text().remove(pos.first, pos.second - pos.first).insert(pos.first, completion));
|
||||
setCursorPosition(pos.first + completion.length());
|
||||
} else {
|
||||
setText(completion.append(", "));
|
||||
setCursorPosition(text().length());
|
||||
|
@ -146,26 +152,30 @@ void TagWidget::completionSelected(QString completion) {
|
|||
emit(textChanged());
|
||||
}
|
||||
|
||||
void TagWidget::setCursorPosition(int position) {
|
||||
void TagWidget::setCursorPosition(int position)
|
||||
{
|
||||
blockSignals(true);
|
||||
GroupedLineEdit::setCursorPosition(position);
|
||||
blockSignals(false);
|
||||
}
|
||||
|
||||
void TagWidget::setText(QString text) {
|
||||
void TagWidget::setText(QString text)
|
||||
{
|
||||
blockSignals(true);
|
||||
GroupedLineEdit::setText(text);
|
||||
blockSignals(false);
|
||||
highlight();
|
||||
}
|
||||
|
||||
void TagWidget::clear() {
|
||||
void TagWidget::clear()
|
||||
{
|
||||
blockSignals(true);
|
||||
GroupedLineEdit::clear();
|
||||
blockSignals(false);
|
||||
}
|
||||
|
||||
void TagWidget::keyPressEvent(QKeyEvent *e) {
|
||||
void TagWidget::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Return:
|
||||
case Qt::Key_Enter:
|
||||
|
@ -188,7 +198,8 @@ void TagWidget::keyPressEvent(QKeyEvent *e) {
|
|||
}
|
||||
}
|
||||
|
||||
void TagWidget::wheelEvent(QWheelEvent *event) {
|
||||
void TagWidget::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (hasFocus()) {
|
||||
GroupedLineEdit::wheelEvent(event);
|
||||
}
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
#include <QCompleter>
|
||||
#include <QPair>
|
||||
|
||||
class TagWidget : public GroupedLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
class TagWidget : public GroupedLineEdit {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TagWidget(QWidget *parent = 0);
|
||||
explicit TagWidget(QWidget *parent = 0);
|
||||
void setCompleter(QCompleter *completer);
|
||||
QPair<int, int> getCursorTagPosition();
|
||||
void highlight();
|
||||
|
@ -17,11 +16,14 @@ public:
|
|||
void clear();
|
||||
void setCursorPosition(int position);
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
public slots:
|
||||
public
|
||||
slots:
|
||||
void reparse();
|
||||
void completionSelected(QString);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
|
||||
private:
|
||||
QCompleter *m_completer;
|
||||
};
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
|
||||
#include "../helpers.h"
|
||||
|
||||
UserManual::UserManual(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
UserManual::UserManual(QWidget *parent) : QMainWindow(parent),
|
||||
ui(new Ui::UserManual)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
@ -56,14 +55,15 @@ void UserManual::hideSearchPanel()
|
|||
|
||||
void UserManual::search(QString text, QWebPage::FindFlags flags = 0)
|
||||
{
|
||||
if (ui->webView->findText(text, QWebPage::FindWrapsAroundDocument|flags) || text.length() == 0) {
|
||||
if (ui->webView->findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) {
|
||||
ui->searchEdit->setStyleSheet("");
|
||||
} else {
|
||||
ui->searchEdit->setStyleSheet("QLineEdit{background: red;}");
|
||||
}
|
||||
}
|
||||
|
||||
void UserManual::searchTextChanged(QString text) {
|
||||
void UserManual::searchTextChanged(QString text)
|
||||
{
|
||||
bool hasText = text.length() > 0;
|
||||
|
||||
ui->findPrev->setEnabled(hasText);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue