2013-04-14 03:44:02 +00:00
/*
* maintab . cpp
*
* classes for the " notebook " area of the main window of Subsurface
*
*/
2013-04-07 22:20:43 +00:00
# include "maintab.h"
2013-05-19 03:09:36 +00:00
# include "mainwindow.h"
2013-05-07 03:36:37 +00:00
# include "../helpers.h"
# include "../statistics.h"
2013-05-19 03:09:36 +00:00
# include "divelistview.h"
2013-05-22 17:11:49 +00:00
# include "modeldelegates.h"
2013-06-05 02:39:40 +00:00
# include "globe.h"
2013-09-19 04:33:39 +00:00
# include "diveplanner.h"
2013-11-19 22:16:33 +00:00
# include "divelist.h"
2013-10-05 16:48:26 +00:00
# include "qthelper.h"
2014-03-07 15:42:13 +00:00
# include "display.h"
2014-06-02 22:50:42 +00:00
# include "divepicturewidget.h"
2013-04-13 13:17:59 +00:00
# include <QLabel>
2013-08-13 13:49:59 +00:00
# include <QCompleter>
2013-05-18 23:42:59 +00:00
# include <QDebug>
2013-06-14 16:17:46 +00:00
# include <QSet>
2013-11-28 11:17:30 +00:00
# include <QSettings>
2013-09-02 19:21:08 +00:00
# include <QTableView>
2013-08-16 18:38:18 +00:00
# include <QPalette>
2013-12-12 01:08:56 +00:00
# include <QScrollBar>
2014-06-03 22:29:28 +00:00
# include <QShortcut>
2014-06-04 01:01:00 +00:00
# include <QMessageBox>
2014-06-27 12:17:33 +00:00
# include <QDesktopServices>
2013-04-07 22:20:43 +00:00
MainTab : : MainTab ( QWidget * parent ) : QTabWidget ( parent ) ,
2014-02-28 04:09:57 +00:00
weightModel ( new WeightModel ( this ) ) ,
cylindersModel ( CylindersModel : : instance ( ) ) ,
2014-06-02 22:50:42 +00:00
editMode ( NONE ) ,
2014-06-03 22:04:50 +00:00
divePictureModel ( DivePictureModel : : instance ( ) )
2013-04-07 22:20:43 +00:00
{
2013-10-03 18:54:25 +00:00
ui . setupUi ( this ) ;
2014-02-09 18:49:15 +00:00
2014-07-02 18:50:28 +00:00
memset ( & displayed_dive , 0 , sizeof ( displayed_dive ) ) ;
2014-02-09 18:49:15 +00:00
2013-10-03 18:54:25 +00:00
ui . cylinders - > setModel ( cylindersModel ) ;
ui . weights - > setModel ( weightModel ) ;
2014-06-02 22:50:42 +00:00
ui . photosView - > setModel ( divePictureModel ) ;
2014-06-27 12:17:33 +00:00
connect ( ui . photosView , SIGNAL ( photoDoubleClicked ( QString ) ) , this , SLOT ( photoDoubleClicked ( QString ) ) ) ;
2013-12-03 20:44:48 +00:00
closeMessage ( ) ;
2013-09-26 20:02:27 +00:00
2013-12-02 17:33:00 +00:00
QAction * action = new QAction ( tr ( " Save " ) , this ) ;
connect ( action , SIGNAL ( triggered ( bool ) ) , this , SLOT ( acceptChanges ( ) ) ) ;
2013-12-03 20:44:48 +00:00
addMessageAction ( action ) ;
2013-12-02 17:33:00 +00:00
action = new QAction ( tr ( " Cancel " ) , this ) ;
connect ( action , SIGNAL ( triggered ( bool ) ) , this , SLOT ( rejectChanges ( ) ) ) ;
2014-06-03 22:29:28 +00:00
QShortcut * closeKey = new QShortcut ( QKeySequence ( Qt : : Key_Escape ) , this ) ;
connect ( closeKey , SIGNAL ( activated ( ) ) , this , SLOT ( escDetected ( ) ) ) ;
2013-12-03 20:44:48 +00:00
addMessageAction ( action ) ;
2013-12-02 17:33:00 +00:00
2013-09-26 20:02:27 +00:00
if ( qApp - > style ( ) - > objectName ( ) = = " oxygen " )
2013-09-26 19:51:11 +00:00
setDocumentMode ( true ) ;
2013-09-26 20:02:27 +00:00
else
setDocumentMode ( false ) ;
2013-05-20 00:38:20 +00:00
// we start out with the fields read-only; once things are
// filled from a dive, they are made writeable
2013-09-19 00:56:53 +00:00
setEnabled ( false ) ;
2013-05-19 14:45:01 +00:00
2013-10-03 18:54:25 +00:00
ui . location - > installEventFilter ( this ) ;
ui . coordinates - > installEventFilter ( this ) ;
ui . divemaster - > installEventFilter ( this ) ;
ui . buddy - > installEventFilter ( this ) ;
ui . suit - > installEventFilter ( this ) ;
ui . notes - > viewport ( ) - > installEventFilter ( this ) ;
ui . rating - > installEventFilter ( this ) ;
ui . visibility - > installEventFilter ( this ) ;
ui . airtemp - > installEventFilter ( this ) ;
ui . watertemp - > installEventFilter ( this ) ;
2014-06-19 16:52:34 +00:00
ui . dateEdit - > installEventFilter ( this ) ;
2014-06-26 17:54:16 +00:00
ui . timeEdit - > installEventFilter ( this ) ;
2013-11-02 01:20:02 +00:00
ui . tagWidget - > installEventFilter ( this ) ;
2013-10-03 18:54:25 +00:00
QList < QObject * > statisticsTabWidgets = ui . statisticsTab - > children ( ) ;
2014-05-22 18:40:22 +00:00
Q_FOREACH ( QObject * obj , statisticsTabWidgets ) {
2014-02-28 04:09:57 +00:00
QLabel * label = qobject_cast < QLabel * > ( obj ) ;
2013-05-10 22:56:05 +00:00
if ( label )
label - > setAlignment ( Qt : : AlignHCenter ) ;
}
2013-10-03 18:54:25 +00:00
ui . cylinders - > setTitle ( tr ( " Cylinders " ) ) ;
ui . cylinders - > setBtnToolTip ( tr ( " Add Cylinder " ) ) ;
connect ( ui . cylinders , SIGNAL ( addButtonClicked ( ) ) , this , SLOT ( addCylinder_clicked ( ) ) ) ;
ui . weights - > setTitle ( tr ( " Weights " ) ) ;
ui . weights - > setBtnToolTip ( tr ( " Add Weight System " ) ) ;
connect ( ui . weights , SIGNAL ( addButtonClicked ( ) ) , this , SLOT ( addWeight_clicked ( ) ) ) ;
connect ( ui . cylinders - > view ( ) , SIGNAL ( clicked ( QModelIndex ) ) , this , SLOT ( editCylinderWidget ( QModelIndex ) ) ) ;
2013-10-03 23:04:51 +00:00
connect ( ui . weights - > view ( ) , SIGNAL ( clicked ( QModelIndex ) ) , this , SLOT ( editWeightWidget ( QModelIndex ) ) ) ;
2013-10-03 18:54:25 +00:00
2014-01-15 17:52:42 +00:00
ui . cylinders - > view ( ) - > setItemDelegateForColumn ( CylindersModel : : TYPE , new TankInfoDelegate ( this ) ) ;
ui . weights - > view ( ) - > setItemDelegateForColumn ( WeightModel : : TYPE , new WSInfoDelegate ( this ) ) ;
2014-03-22 14:13:58 +00:00
ui . cylinders - > view ( ) - > setColumnHidden ( CylindersModel : : DEPTH , true ) ;
2014-02-11 17:46:14 +00:00
completers . buddy = new QCompleter ( & buddyModel , ui . buddy ) ;
completers . divemaster = new QCompleter ( & diveMasterModel , ui . divemaster ) ;
completers . location = new QCompleter ( & locationModel , ui . location ) ;
completers . suit = new QCompleter ( & suitModel , ui . suit ) ;
completers . tags = new QCompleter ( & tagModel , ui . tagWidget ) ;
2014-01-06 22:00:10 +00:00
completers . buddy - > setCaseSensitivity ( Qt : : CaseInsensitive ) ;
completers . divemaster - > setCaseSensitivity ( Qt : : CaseInsensitive ) ;
completers . location - > setCaseSensitivity ( Qt : : CaseInsensitive ) ;
completers . suit - > setCaseSensitivity ( Qt : : CaseInsensitive ) ;
2013-11-15 00:39:02 +00:00
completers . tags - > setCaseSensitivity ( Qt : : CaseInsensitive ) ;
2013-10-03 18:54:25 +00:00
ui . buddy - > setCompleter ( completers . buddy ) ;
ui . divemaster - > setCompleter ( completers . divemaster ) ;
ui . location - > setCompleter ( completers . location ) ;
ui . suit - > setCompleter ( completers . suit ) ;
2013-11-02 01:20:02 +00:00
ui . tagWidget - > setCompleter ( completers . tags ) ;
2013-09-26 21:14:09 +00:00
setMinimumHeight ( 0 ) ;
setMinimumWidth ( 0 ) ;
2013-09-27 15:52:01 +00:00
// Current display of things on Gnome3 looks like shit, so
// let`s fix that.
if ( isGnome3Session ( ) ) {
QPalette p ;
p . setColor ( QPalette : : Window , QColor ( Qt : : white ) ) ;
2013-10-03 18:54:25 +00:00
ui . scrollArea - > viewport ( ) - > setPalette ( p ) ;
ui . scrollArea_2 - > viewport ( ) - > setPalette ( p ) ;
ui . scrollArea_3 - > viewport ( ) - > setPalette ( p ) ;
ui . scrollArea_4 - > viewport ( ) - > setPalette ( p ) ;
2013-12-04 20:24:37 +00:00
// GroupBoxes in Gnome3 looks like I'v drawn them...
static const QString gnomeCss (
" QGroupBox { "
" background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, "
" stop: 0 #E0E0E0, stop: 1 #FFFFFF); "
" border: 2px solid gray; "
" border-radius: 5px; "
" margin-top: 1ex; "
" } "
" QGroupBox::title { "
" subcontrol-origin: margin; "
" subcontrol-position: top center; "
" padding: 0 3px; "
" background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, "
2013-12-07 16:13:55 +00:00
" stop: 0 #E0E0E0, stop: 1 #FFFFFF); "
2013-12-04 20:24:37 +00:00
" } " ) ;
2014-05-22 18:40:22 +00:00
Q_FOREACH ( QGroupBox * box , findChildren < QGroupBox * > ( ) ) {
2013-12-04 20:24:37 +00:00
box - > setStyleSheet ( gnomeCss ) ;
}
2013-09-27 15:52:01 +00:00
}
2013-11-28 11:17:30 +00:00
ui . cylinders - > view ( ) - > horizontalHeader ( ) - > setContextMenuPolicy ( Qt : : ActionsContextMenu ) ;
QSettings s ;
s . beginGroup ( " cylinders_dialog " ) ;
2014-02-28 04:09:57 +00:00
for ( int i = 0 ; i < CylindersModel : : COLUMNS ; i + + ) {
2013-11-28 11:17:30 +00:00
if ( ( i = = CylindersModel : : REMOVE ) | | ( i = = CylindersModel : : TYPE ) )
2014-02-28 04:09:57 +00:00
continue ;
2013-11-28 11:17:30 +00:00
bool checked = s . value ( QString ( " column%1_hidden " ) . arg ( i ) ) . toBool ( ) ;
2014-02-12 14:07:32 +00:00
action = new QAction ( cylindersModel - > headerData ( i , Qt : : Horizontal , Qt : : DisplayRole ) . toString ( ) , ui . cylinders - > view ( ) ) ;
2013-11-28 11:17:30 +00:00
action - > setCheckable ( true ) ;
action - > setData ( i ) ;
action - > setChecked ( ! checked ) ;
connect ( action , SIGNAL ( triggered ( bool ) ) , this , SLOT ( toggleTriggeredColumn ( ) ) ) ;
ui . cylinders - > view ( ) - > setColumnHidden ( i , checked ) ;
ui . cylinders - > view ( ) - > horizontalHeader ( ) - > addAction ( action ) ;
}
}
MainTab : : ~ MainTab ( )
{
QSettings s ;
s . beginGroup ( " cylinders_dialog " ) ;
2014-02-28 04:09:57 +00:00
for ( int i = 0 ; i < CylindersModel : : COLUMNS ; i + + ) {
2013-11-28 11:17:30 +00:00
if ( ( i = = CylindersModel : : REMOVE ) | | ( i = = CylindersModel : : TYPE ) )
2014-02-28 04:09:57 +00:00
continue ;
2013-11-28 11:17:30 +00:00
s . setValue ( QString ( " column%1_hidden " ) . arg ( i ) , ui . cylinders - > view ( ) - > isColumnHidden ( i ) ) ;
}
}
void MainTab : : toggleTriggeredColumn ( )
{
2014-02-28 04:09:57 +00:00
QAction * action = qobject_cast < QAction * > ( sender ( ) ) ;
2013-11-28 11:17:30 +00:00
int col = action - > data ( ) . toInt ( ) ;
QTableView * view = ui . cylinders - > view ( ) ;
2014-01-16 04:50:56 +00:00
if ( action - > isChecked ( ) ) {
2013-11-28 11:17:30 +00:00
view - > showColumn ( col ) ;
2014-01-16 04:50:56 +00:00
if ( view - > columnWidth ( col ) < = 15 )
2013-11-28 11:17:30 +00:00
view - > setColumnWidth ( col , 80 ) ;
2014-02-28 04:09:57 +00:00
} else
2013-11-28 11:17:30 +00:00
view - > hideColumn ( col ) ;
2013-06-27 12:33:43 +00:00
}
2013-05-22 12:17:18 +00:00
2013-09-19 04:33:39 +00:00
void MainTab : : addDiveStarted ( )
{
2013-12-27 16:18:53 +00:00
enableEdition ( ADD ) ;
2013-09-19 04:33:39 +00:00
}
2014-02-28 04:09:57 +00:00
void MainTab : : addMessageAction ( QAction * action )
2013-12-03 20:44:48 +00:00
{
ui . diveEquipmentMessage - > addAction ( action ) ;
ui . diveNotesMessage - > addAction ( action ) ;
ui . diveInfoMessage - > addAction ( action ) ;
ui . diveStatisticsMessage - > addAction ( action ) ;
}
void MainTab : : hideMessage ( )
{
ui . diveNotesMessage - > animatedHide ( ) ;
ui . diveEquipmentMessage - > animatedHide ( ) ;
ui . diveInfoMessage - > animatedHide ( ) ;
ui . diveStatisticsMessage - > animatedHide ( ) ;
2014-04-05 16:03:45 +00:00
updateTextLabels ( false ) ;
2013-12-03 20:44:48 +00:00
}
void MainTab : : closeMessage ( )
{
hideMessage ( ) ;
ui . diveNotesMessage - > setCloseButtonVisible ( false ) ;
ui . diveEquipmentMessage - > setCloseButtonVisible ( false ) ;
ui . diveInfoMessage - > setCloseButtonVisible ( false ) ;
ui . diveStatisticsMessage - > setCloseButtonVisible ( false ) ;
}
void MainTab : : displayMessage ( QString str )
{
ui . diveNotesMessage - > setText ( str ) ;
ui . diveNotesMessage - > animatedShow ( ) ;
ui . diveEquipmentMessage - > setText ( str ) ;
ui . diveEquipmentMessage - > animatedShow ( ) ;
ui . diveInfoMessage - > setText ( str ) ;
ui . diveInfoMessage - > animatedShow ( ) ;
ui . diveStatisticsMessage - > setText ( str ) ;
ui . diveStatisticsMessage - > animatedShow ( ) ;
2014-04-05 16:03:45 +00:00
updateTextLabels ( ) ;
2014-03-11 03:49:08 +00:00
}
void MainTab : : updateTextLabels ( bool showUnits )
{
2014-04-05 16:03:45 +00:00
if ( showUnits ) {
2014-03-17 21:52:42 +00:00
ui . airTempLabel - > setText ( tr ( " Air temp [%1] " ) . arg ( get_temp_unit ( ) ) ) ;
ui . waterTempLabel - > setText ( tr ( " Water temp [%1] " ) . arg ( get_temp_unit ( ) ) ) ;
2014-03-11 03:49:08 +00:00
} else {
2014-03-17 21:52:42 +00:00
ui . airTempLabel - > setText ( tr ( " Air temp " ) ) ;
ui . waterTempLabel - > setText ( tr ( " Water temp " ) ) ;
2014-03-11 03:49:08 +00:00
}
2013-12-03 20:44:48 +00:00
}
2013-11-01 15:48:34 +00:00
void MainTab : : enableEdition ( EditMode newEditMode )
2013-08-13 11:34:04 +00:00
{
2013-12-27 16:18:53 +00:00
if ( current_dive = = NULL | | editMode ! = NONE )
2013-08-13 11:34:04 +00:00
return ;
2013-12-27 16:18:53 +00:00
if ( ( newEditMode = = DIVE | | newEditMode = = NONE ) & &
2014-01-03 12:49:17 +00:00
current_dive - > dc . model & &
2013-12-27 16:18:53 +00:00
strcmp ( current_dive - > dc . model , " manually added dive " ) = = 0 ) {
// editCurrentDive will call enableEdition with newEditMode == MANUALLY_ADDED_DIVE
// so exit this function here after editCurrentDive() returns
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > editCurrentDive ( ) ;
2013-12-27 16:18:53 +00:00
return ;
}
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > dive_list ( ) - > setEnabled ( false ) ;
2014-05-01 17:47:52 +00:00
if ( amount_selected = = 1 )
2014-05-07 21:01:05 +00:00
MainWindow : : instance ( ) - > globe ( ) - > prepareForGetDiveCoordinates ( ) ;
2014-02-12 14:22:54 +00:00
if ( MainWindow : : instance ( ) & & MainWindow : : instance ( ) - > dive_list ( ) - > selectedTrips ( ) . count ( ) = = 1 ) {
2013-09-19 00:56:53 +00:00
// we are editing trip location and notes
2013-12-03 20:44:48 +00:00
displayMessage ( tr ( " This trip is being edited. " ) ) ;
2014-07-02 18:50:28 +00:00
displayed_dive . location = current_dive - > divetrip - > location ;
displayed_dive . notes = current_dive - > divetrip - > notes ;
2014-06-19 16:52:34 +00:00
ui . dateEdit - > setEnabled ( false ) ;
2013-09-19 00:56:53 +00:00
editMode = TRIP ;
} else {
2013-11-05 06:57:24 +00:00
if ( amount_selected > 1 ) {
2013-12-03 20:44:48 +00:00
displayMessage ( tr ( " Multiple dives are being edited. " ) ) ;
2013-11-05 06:57:24 +00:00
} else {
2013-12-03 20:44:48 +00:00
displayMessage ( tr ( " This dive is being edited. " ) ) ;
2013-11-05 06:57:24 +00:00
}
2014-06-12 20:34:57 +00:00
// editedDive already contains the current dive (we set this up in updateDiveInfo),
// so all we need to do is update the editMode if necessary
2013-11-01 15:48:34 +00:00
editMode = newEditMode ! = NONE ? newEditMode : DIVE ;
2013-09-19 00:56:53 +00:00
}
2013-08-13 11:34:04 +00:00
}
2014-02-28 04:09:57 +00:00
bool MainTab : : eventFilter ( QObject * object , QEvent * event )
2013-05-19 14:45:01 +00:00
{
2013-12-19 21:45:54 +00:00
if ( ! isEnabled ( ) )
return false ;
if ( editMode ! = NONE )
return false ;
2014-06-03 22:29:28 +00:00
2014-06-19 16:52:34 +00:00
// for the dateEdit widget we need to ignore Wheel events as well (as long as we aren't editing)
if ( object - > objectName ( ) = = " dateEdit " & &
2013-12-14 05:15:07 +00:00
( event - > type ( ) = = QEvent : : FocusIn | | event - > type ( ) = = QEvent : : Wheel ) )
return true ;
2014-06-19 16:52:34 +00:00
// MouseButtonPress in any widget (not all will ever get this), KeyPress in the dateEdit,
2013-12-14 05:15:07 +00:00
// FocusIn for the starWidgets or RequestSoftwareInputPanel for tagWidget start the editing
2013-12-19 21:45:54 +00:00
if ( ( event - > type ( ) = = QEvent : : MouseButtonPress ) | |
2014-06-19 16:52:34 +00:00
( event - > type ( ) = = QEvent : : KeyPress & & object = = ui . dateEdit ) | |
2014-01-19 17:36:51 +00:00
( event - > type ( ) = = QEvent : : FocusIn & & ( object = = ui . rating | | object = = ui . visibility | | object = = ui . buddy | | object = = ui . tagWidget | | object | | ui . divemaster ) ) ) {
2013-09-19 01:38:38 +00:00
tabBar ( ) - > setTabIcon ( currentIndex ( ) , QIcon ( " :warning " ) ) ;
2013-08-13 11:34:04 +00:00
enableEdition ( ) ;
2013-05-19 14:45:01 +00:00
}
2013-08-13 11:34:04 +00:00
return false ; // don't "eat" the event.
2013-05-19 14:45:01 +00:00
}
2013-04-13 13:17:59 +00:00
void MainTab : : clearEquipment ( )
{
2013-10-10 08:16:32 +00:00
cylindersModel - > clear ( ) ;
weightModel - > clear ( ) ;
2013-04-13 13:17:59 +00:00
}
2014-05-16 06:12:46 +00:00
void MainTab : : nextInputField ( QKeyEvent * event )
{
keyPressEvent ( event ) ;
}
2013-04-13 13:17:59 +00:00
void MainTab : : clearInfo ( )
{
2013-10-03 18:54:25 +00:00
ui . sacText - > clear ( ) ;
ui . otuText - > clear ( ) ;
ui . oxygenHeliumText - > clear ( ) ;
ui . gasUsedText - > clear ( ) ;
ui . dateText - > clear ( ) ;
ui . diveTimeText - > clear ( ) ;
ui . surfaceIntervalText - > clear ( ) ;
ui . maximumDepthText - > clear ( ) ;
ui . averageDepthText - > clear ( ) ;
ui . waterTemperatureText - > clear ( ) ;
ui . airTemperatureText - > clear ( ) ;
ui . airPressureText - > clear ( ) ;
2013-10-10 08:16:32 +00:00
ui . salinityText - > clear ( ) ;
2013-11-02 01:20:02 +00:00
ui . tagWidget - > clear ( ) ;
2013-04-13 13:17:59 +00:00
}
void MainTab : : clearStats ( )
{
2013-10-03 18:54:25 +00:00
ui . depthLimits - > clear ( ) ;
ui . sacLimits - > clear ( ) ;
ui . divesAllText - > clear ( ) ;
ui . tempLimits - > clear ( ) ;
ui . totalTimeAllText - > clear ( ) ;
ui . timeLimits - > clear ( ) ;
2013-04-13 13:17:59 +00:00
}
2014-02-28 04:09:57 +00:00
# define UPDATE_TEXT(d, field) \
if ( ! d | | ! d - > field ) \
ui . field - > setText ( " " ) ; \
else \
ui . field - > setText ( d - > field )
2013-05-06 17:16:16 +00:00
2014-02-28 04:09:57 +00:00
# define UPDATE_TEMP(d, field) \
if ( ! d | | d - > field . mkelvin = = 0 ) \
ui . field - > setText ( " " ) ; \
else \
ui . field - > setText ( get_temperature_string ( d - > field , true ) )
2013-09-20 23:41:42 +00:00
2013-11-10 21:23:18 +00:00
bool MainTab : : isEditing ( )
{
return editMode ! = NONE ;
}
2013-05-06 16:23:14 +00:00
void MainTab : : updateDiveInfo ( int dive )
{
2014-05-26 22:17:34 +00:00
// don't execute this while adding / planning a dive
if ( editMode = = ADD | | editMode = = MANUALLY_ADDED_DIVE | | MainWindow : : instance ( ) - > graphics ( ) - > isPlanner ( ) )
2013-11-12 07:33:27 +00:00
return ;
2013-09-22 15:19:05 +00:00
if ( ! isEnabled ( ) & & dive ! = - 1 )
2013-09-19 00:56:53 +00:00
setEnabled ( true ) ;
2013-09-22 15:19:05 +00:00
if ( isEnabled ( ) & & dive = = - 1 )
setEnabled ( false ) ;
2013-08-16 16:31:52 +00:00
editMode = NONE ;
2013-06-14 16:17:46 +00:00
// This method updates ALL tabs whenever a new dive or trip is
// selected.
// If exactly one trip has been selected, we show the location / notes
// for the trip in the Info tab, otherwise we show the info of the
// selected_dive
2013-05-20 05:42:24 +00:00
temperature_t temp ;
2013-05-19 15:08:29 +00:00
struct dive * prevd ;
2013-05-06 16:23:14 +00:00
struct dive * d = get_dive ( dive ) ;
2013-12-28 01:26:22 +00:00
char buf [ 1024 ] ;
2013-05-19 15:08:29 +00:00
2013-05-20 05:42:24 +00:00
process_selected_dives ( ) ;
2013-05-19 15:08:29 +00:00
process_all_dives ( d , & prevd ) ;
2013-08-16 16:31:52 +00:00
2014-06-02 22:50:42 +00:00
divePictureModel - > updateDivePictures ( dive ) ;
2013-05-06 17:16:16 +00:00
UPDATE_TEXT ( d , notes ) ;
UPDATE_TEXT ( d , location ) ;
UPDATE_TEXT ( d , suit ) ;
UPDATE_TEXT ( d , divemaster ) ;
UPDATE_TEXT ( d , buddy ) ;
2013-09-20 23:41:42 +00:00
UPDATE_TEMP ( d , airtemp ) ;
UPDATE_TEMP ( d , watertemp ) ;
2013-05-08 19:08:00 +00:00
if ( d ) {
2013-11-11 23:21:45 +00:00
updateGpsCoordinates ( d ) ;
2014-06-26 23:05:48 +00:00
QDateTime localTime = QDateTime : : fromTime_t ( d - > when - gettimezoneoffset ( ) ) ;
ui . dateEdit - > setDate ( localTime . date ( ) ) ;
ui . timeEdit - > setTime ( localTime . time ( ) ) ;
2014-02-12 14:22:54 +00:00
if ( MainWindow : : instance ( ) & & MainWindow : : instance ( ) - > dive_list ( ) - > selectedTrips ( ) . count ( ) = = 1 ) {
2013-11-25 19:05:09 +00:00
setTabText ( 0 , tr ( " Trip Notes " ) ) ;
2013-06-14 16:17:46 +00:00
// only use trip relevant fields
2013-10-03 18:54:25 +00:00
ui . coordinates - > setVisible ( false ) ;
2013-11-04 19:28:03 +00:00
ui . CoordinatedLabel - > setVisible ( false ) ;
2013-10-03 18:54:25 +00:00
ui . divemaster - > setVisible ( false ) ;
ui . DivemasterLabel - > setVisible ( false ) ;
ui . buddy - > setVisible ( false ) ;
ui . BuddyLabel - > setVisible ( false ) ;
ui . suit - > setVisible ( false ) ;
ui . SuitLabel - > setVisible ( false ) ;
ui . rating - > setVisible ( false ) ;
ui . RatingLabel - > setVisible ( false ) ;
ui . visibility - > setVisible ( false ) ;
ui . visibilityLabel - > setVisible ( false ) ;
2013-11-04 19:28:03 +00:00
ui . tagWidget - > setVisible ( false ) ;
ui . TagLabel - > setVisible ( false ) ;
2013-11-30 10:13:40 +00:00
ui . airTempLabel - > setVisible ( false ) ;
2013-11-07 03:38:35 +00:00
ui . airtemp - > setVisible ( false ) ;
2013-11-30 10:13:40 +00:00
ui . waterTempLabel - > setVisible ( false ) ;
2013-11-07 03:38:35 +00:00
ui . watertemp - > setVisible ( false ) ;
2013-06-14 16:17:46 +00:00
// rename the remaining fields and fill data from selected trip
2014-02-12 14:22:54 +00:00
dive_trip_t * currentTrip = * MainWindow : : instance ( ) - > dive_list ( ) - > selectedTrips ( ) . begin ( ) ;
2013-10-03 18:54:25 +00:00
ui . LocationLabel - > setText ( tr ( " Trip Location " ) ) ;
ui . location - > setText ( currentTrip - > location ) ;
ui . NotesLabel - > setText ( tr ( " Trip Notes " ) ) ;
ui . notes - > setText ( currentTrip - > notes ) ;
2013-12-28 01:26:22 +00:00
clearEquipment ( ) ;
ui . equipmentTab - > setEnabled ( false ) ;
2013-06-14 16:17:46 +00:00
} else {
2013-11-25 19:05:09 +00:00
setTabText ( 0 , tr ( " Dive Notes " ) ) ;
2013-06-14 16:17:46 +00:00
// make all the fields visible writeable
2013-10-03 18:54:25 +00:00
ui . coordinates - > setVisible ( true ) ;
2013-11-04 19:28:03 +00:00
ui . CoordinatedLabel - > setVisible ( true ) ;
2013-10-03 18:54:25 +00:00
ui . divemaster - > setVisible ( true ) ;
ui . buddy - > setVisible ( true ) ;
ui . suit - > setVisible ( true ) ;
ui . SuitLabel - > setVisible ( true ) ;
ui . rating - > setVisible ( true ) ;
ui . RatingLabel - > setVisible ( true ) ;
ui . visibility - > setVisible ( true ) ;
ui . visibilityLabel - > setVisible ( true ) ;
ui . BuddyLabel - > setVisible ( true ) ;
ui . DivemasterLabel - > setVisible ( true ) ;
2013-11-04 19:28:03 +00:00
ui . TagLabel - > setVisible ( true ) ;
ui . tagWidget - > setVisible ( true ) ;
2013-11-30 10:13:40 +00:00
ui . airTempLabel - > setVisible ( true ) ;
2013-11-07 03:38:35 +00:00
ui . airtemp - > setVisible ( true ) ;
2013-11-30 10:13:40 +00:00
ui . waterTempLabel - > setVisible ( true ) ;
2013-11-07 03:38:35 +00:00
ui . watertemp - > setVisible ( true ) ;
2013-06-14 16:17:46 +00:00
/* and fill them from the dive */
2013-10-03 18:54:25 +00:00
ui . rating - > setCurrentStars ( d - > rating ) ;
ui . visibility - > setCurrentStars ( d - > visibility ) ;
2013-06-14 16:17:46 +00:00
// reset labels in case we last displayed trip notes
2013-10-03 18:54:25 +00:00
ui . LocationLabel - > setText ( tr ( " Location " ) ) ;
ui . NotesLabel - > setText ( tr ( " Notes " ) ) ;
2013-12-28 01:26:22 +00:00
ui . equipmentTab - > setEnabled ( true ) ;
2014-07-02 18:50:28 +00:00
// now copy the current dive over to dieplayed_dive and use THAT to show the
2014-06-12 20:34:57 +00:00
// cylinder and weight model (this way edits on the equipment tab happen in the
2014-07-02 18:50:28 +00:00
// displayed_dive and not on the real data (until the user hits save)
// all this will of course be redone in the next commit... one step at a time :-)
displayed_dive = * d ;
cylindersModel - > setDive ( & displayed_dive ) ;
weightModel - > setDive ( & displayed_dive ) ;
2013-12-28 01:26:22 +00:00
taglist_get_tagstring ( d - > tag_list , buf , 1024 ) ;
ui . tagWidget - > setText ( QString ( buf ) ) ;
2013-06-14 16:17:46 +00:00
}
2014-01-15 08:30:42 +00:00
ui . maximumDepthText - > setText ( get_depth_string ( d - > maxdepth , true ) ) ;
ui . averageDepthText - > setText ( get_depth_string ( d - > meandepth , true ) ) ;
2013-10-03 18:54:25 +00:00
ui . otuText - > setText ( QString ( " %1 " ) . arg ( d - > otu ) ) ;
2014-01-15 08:30:42 +00:00
ui . waterTemperatureText - > setText ( get_temperature_string ( d - > watertemp , true ) ) ;
ui . airTemperatureText - > setText ( get_temperature_string ( d - > airtemp , true ) ) ;
2013-12-09 21:37:49 +00:00
volume_t gases [ MAX_CYLINDERS ] = { } ;
2013-11-19 23:29:32 +00:00
get_gas_used ( d , gases ) ;
2014-01-15 08:30:42 +00:00
QString volumes = get_volume_string ( gases [ 0 ] , true ) ;
2013-11-20 06:50:02 +00:00
int mean [ MAX_CYLINDERS ] , duration [ MAX_CYLINDERS ] ;
2014-03-17 15:19:09 +00:00
per_cylinder_mean_depth ( d , select_dc ( d ) , mean , duration ) ;
2013-11-20 06:50:02 +00:00
volume_t sac ;
QString SACs ;
if ( mean [ 0 ] & & duration [ 0 ] ) {
2014-02-11 21:08:29 +00:00
sac . mliter = gases [ 0 ] . mliter / ( depth_to_atm ( mean [ 0 ] , d ) * duration [ 0 ] / 60.0 ) ;
2014-01-15 08:30:42 +00:00
SACs = get_volume_string ( sac , true ) . append ( tr ( " /min " ) ) ;
2013-11-20 06:50:02 +00:00
} else {
SACs = QString ( tr ( " unknown " ) ) ;
}
2014-02-28 04:09:57 +00:00
for ( int i = 1 ; i < MAX_CYLINDERS & & gases [ i ] . mliter ! = 0 ; i + + ) {
2014-01-15 08:30:42 +00:00
volumes . append ( " \n " + get_volume_string ( gases [ i ] , true ) ) ;
2013-11-20 06:50:02 +00:00
if ( duration [ i ] ) {
2014-02-11 21:08:29 +00:00
sac . mliter = gases [ i ] . mliter / ( depth_to_atm ( mean [ i ] , d ) * duration [ i ] / 60 ) ;
2014-01-15 08:30:42 +00:00
SACs . append ( " \n " + get_volume_string ( sac , true ) . append ( tr ( " /min " ) ) ) ;
2013-11-20 06:50:02 +00:00
} else {
SACs . append ( " \n " ) ;
}
}
2013-11-19 23:29:32 +00:00
ui . gasUsedText - > setText ( volumes ) ;
2013-10-03 18:54:25 +00:00
ui . oxygenHeliumText - > setText ( get_gaslist ( d ) ) ;
ui . dateText - > setText ( get_short_dive_date_string ( d - > when ) ) ;
ui . diveTimeText - > setText ( QString : : number ( ( int ) ( ( d - > duration . seconds + 30 ) / 60 ) ) ) ;
2013-05-19 15:08:29 +00:00
if ( prevd )
2013-10-03 18:54:25 +00:00
ui . surfaceIntervalText - > setText ( get_time_string ( d - > when - ( prevd - > when + prevd - > duration . seconds ) , 4 ) ) ;
2013-11-14 10:36:41 +00:00
else
ui . surfaceIntervalText - > clear ( ) ;
2013-11-20 06:50:02 +00:00
if ( mean [ 0 ] )
ui . sacText - > setText ( SACs ) ;
2013-05-08 19:08:00 +00:00
else
2013-10-03 18:54:25 +00:00
ui . sacText - > clear ( ) ;
2013-05-08 19:08:00 +00:00
if ( d - > surface_pressure . mbar )
/* this is ALWAYS displayed in mbar */
2013-10-03 18:54:25 +00:00
ui . airPressureText - > setText ( QString ( " %1mbar " ) . arg ( d - > surface_pressure . mbar ) ) ;
2013-05-08 19:08:00 +00:00
else
2013-10-03 18:54:25 +00:00
ui . airPressureText - > clear ( ) ;
2013-10-10 08:16:32 +00:00
if ( d - > salinity )
2014-02-28 04:09:57 +00:00
ui . salinityText - > setText ( QString ( " %1g/l " ) . arg ( d - > salinity / 10.0 ) ) ;
2013-10-10 08:16:32 +00:00
else
ui . salinityText - > clear ( ) ;
2014-01-15 08:30:42 +00:00
ui . depthLimits - > setMaximum ( get_depth_string ( stats_selection . max_depth , true ) ) ;
ui . depthLimits - > setMinimum ( get_depth_string ( stats_selection . min_depth , true ) ) ;
2014-06-10 03:32:44 +00:00
// the overall average depth is really confusing when listed between the
// deepest and shallowest dive - let's just not set it
// ui.depthLimits->setAverage(get_depth_string(stats_selection.avg_depth, true));
2014-06-19 15:25:08 +00:00
ui . depthLimits - > overrideMaxToolTipText ( tr ( " Deepest Dive " ) ) ;
ui . depthLimits - > overrideMinToolTipText ( tr ( " Shallowest Dive " ) ) ;
2014-01-15 08:30:42 +00:00
ui . sacLimits - > setMaximum ( get_volume_string ( stats_selection . max_sac , true ) . append ( tr ( " /min " ) ) ) ;
ui . sacLimits - > setMinimum ( get_volume_string ( stats_selection . min_sac , true ) . append ( tr ( " /min " ) ) ) ;
ui . sacLimits - > setAverage ( get_volume_string ( stats_selection . avg_sac , true ) . append ( tr ( " /min " ) ) ) ;
2013-10-03 18:54:25 +00:00
ui . divesAllText - > setText ( QString : : number ( stats_selection . selection_size ) ) ;
2013-05-20 05:42:24 +00:00
temp . mkelvin = stats_selection . max_temp ;
2014-01-15 08:30:42 +00:00
ui . tempLimits - > setMaximum ( get_temperature_string ( temp , true ) ) ;
2013-05-20 05:42:24 +00:00
temp . mkelvin = stats_selection . min_temp ;
2014-01-15 08:30:42 +00:00
ui . tempLimits - > setMinimum ( get_temperature_string ( temp , true ) ) ;
2013-05-20 05:42:24 +00:00
if ( stats_selection . combined_temp & & stats_selection . combined_count ) {
const char * unit ;
get_temp_units ( 0 , & unit ) ;
2013-10-03 18:54:25 +00:00
ui . tempLimits - > setAverage ( QString ( " %1%2 " ) . arg ( stats_selection . combined_temp / stats_selection . combined_count , 0 , ' f ' , 1 ) . arg ( unit ) ) ;
2013-05-20 05:42:24 +00:00
}
2013-10-03 18:54:25 +00:00
ui . totalTimeAllText - > setText ( get_time_string ( stats_selection . total_time . seconds , 0 ) ) ;
2013-05-20 05:42:24 +00:00
int seconds = stats_selection . total_time . seconds ;
if ( stats_selection . selection_size )
seconds / = stats_selection . selection_size ;
2013-10-03 18:54:25 +00:00
ui . timeLimits - > setAverage ( get_time_string ( seconds , 0 ) ) ;
ui . timeLimits - > setMaximum ( get_time_string ( stats_selection . longest_time . seconds , 0 ) ) ;
ui . timeLimits - > setMinimum ( get_time_string ( stats_selection . shortest_time . seconds , 0 ) ) ;
2014-06-10 05:45:44 +00:00
// now let's get some gas use statistics
QVector < QPair < QString , int > > gasUsed ;
QString gasUsedString ;
volume_t vol ;
selectedDivesGasUsed ( gasUsed ) ;
2014-06-10 18:45:20 +00:00
for ( int j = 0 ; j < 20 ; j + + ) {
2014-06-10 05:45:44 +00:00
if ( gasUsed . isEmpty ( ) )
break ;
QPair < QString , int > gasPair = gasUsed . last ( ) ;
gasUsed . pop_back ( ) ;
vol . mliter = gasPair . second ;
gasUsedString . append ( gasPair . first ) . append ( " : " ) . append ( get_volume_string ( vol , true ) ) . append ( " \n " ) ;
}
if ( ! gasUsed . isEmpty ( ) )
gasUsedString . append ( " ... " ) ;
2014-06-29 18:01:56 +00:00
volume_t o2_tot = { } , he_tot = { } ;
selected_dives_gas_parts ( & o2_tot , & he_tot ) ;
gasUsedString . append ( QString ( " These gases could be \n mixed from Air and using: \n He: %1 and O2: %2 \n " ) . arg ( get_volume_string ( he_tot , true ) ) . arg ( get_volume_string ( o2_tot , true ) ) ) ;
2014-06-10 05:45:44 +00:00
ui . gasConsumption - > setText ( gasUsedString ) ;
2013-05-08 19:08:00 +00:00
} else {
2013-05-20 00:38:20 +00:00
/* clear the fields */
2013-10-10 08:16:32 +00:00
clearInfo ( ) ;
clearStats ( ) ;
clearEquipment ( ) ;
2013-10-03 18:54:25 +00:00
ui . rating - > setCurrentStars ( 0 ) ;
ui . coordinates - > clear ( ) ;
ui . visibility - > setCurrentStars ( 0 ) ;
2013-05-08 19:08:00 +00:00
}
2013-05-06 16:23:14 +00:00
}
2013-05-22 12:40:26 +00:00
void MainTab : : addCylinder_clicked ( )
2013-04-13 13:17:59 +00:00
{
2014-01-16 04:50:56 +00:00
if ( editMode = = NONE )
2013-09-25 18:05:48 +00:00
enableEdition ( ) ;
2013-05-22 17:52:38 +00:00
cylindersModel - > add ( ) ;
2013-04-13 13:17:59 +00:00
}
2013-05-22 12:40:26 +00:00
void MainTab : : addWeight_clicked ( )
2013-05-01 21:30:34 +00:00
{
2014-01-16 04:50:56 +00:00
if ( editMode = = NONE )
2013-09-25 18:05:48 +00:00
enableEdition ( ) ;
2013-05-22 17:52:38 +00:00
weightModel - > add ( ) ;
2013-05-01 21:30:34 +00:00
}
2013-04-13 13:17:59 +00:00
void MainTab : : reload ( )
{
2014-02-11 17:46:14 +00:00
suitModel . updateModel ( ) ;
buddyModel . updateModel ( ) ;
locationModel . updateModel ( ) ;
diveMasterModel . updateModel ( ) ;
tagModel . updateModel ( ) ;
2013-04-07 22:20:43 +00:00
}
2013-05-18 23:42:59 +00:00
2014-05-07 20:00:33 +00:00
// tricky little macro to edit all the selected dives
// loop over all dives, for each selected dive do WHAT, but do it
// last for the current dive; this is required in case the invocation
// wants to compare things to the original value in current_dive like it should
2014-07-02 18:50:28 +00:00
# define MODIFY_SELECTED_DIVES(WHAT) \
2014-05-07 20:00:33 +00:00
do { \
struct dive * mydive = NULL ; \
2014-05-19 21:37:19 +00:00
int _i ; \
for_each_dive ( _i , mydive ) { \
2014-06-03 01:13:50 +00:00
if ( ! mydive - > selected | | mydive = = cd ) \
2014-05-07 20:00:33 +00:00
continue ; \
\
WHAT ; \
} \
2014-06-03 01:13:50 +00:00
mydive = cd ; \
2014-05-07 20:00:33 +00:00
WHAT ; \
2014-06-03 01:13:50 +00:00
mark_divelist_changed ( true ) ; \
2014-05-07 20:00:33 +00:00
} while ( 0 )
2014-06-03 01:13:50 +00:00
# define EDIT_TEXT(what) \
if ( same_string ( mydive - > what , cd - > what ) ) { \
2014-05-07 20:00:33 +00:00
free ( mydive - > what ) ; \
2014-07-02 18:50:28 +00:00
mydive - > what = strdup ( displayed_dive . what ) ; \
2014-05-07 20:00:33 +00:00
}
2014-06-03 01:13:50 +00:00
# define EDIT_VALUE(what) \
if ( mydive - > what = = cd - > what ) { \
2014-07-02 18:50:28 +00:00
mydive - > what = displayed_dive . what ; \
2014-05-07 20:00:33 +00:00
}
2013-09-19 00:56:53 +00:00
void MainTab : : acceptChanges ( )
2013-05-18 23:42:59 +00:00
{
2014-06-03 01:13:50 +00:00
int i ;
struct dive * d ;
2013-09-19 01:38:38 +00:00
tabBar ( ) - > setTabIcon ( 0 , QIcon ( ) ) ; // Notes
tabBar ( ) - > setTabIcon ( 1 , QIcon ( ) ) ; // Equipment
2013-12-03 20:44:48 +00:00
hideMessage ( ) ;
2013-12-28 01:26:22 +00:00
ui . equipmentTab - > setEnabled ( true ) ;
2013-09-19 00:56:53 +00:00
/* now figure out if things have changed */
2014-02-12 14:22:54 +00:00
if ( MainWindow : : instance ( ) & & MainWindow : : instance ( ) - > dive_list ( ) - > selectedTrips ( ) . count ( ) = = 1 ) {
2014-07-02 18:50:28 +00:00
if ( ! same_string ( displayed_dive . notes , current_dive - > divetrip - > notes ) ) {
current_dive - > divetrip - > notes = strdup ( displayed_dive . notes ) ;
2014-06-03 01:13:50 +00:00
mark_divelist_changed ( true ) ;
}
2014-07-02 18:50:28 +00:00
if ( ! same_string ( displayed_dive . location , current_dive - > divetrip - > location ) ) {
current_dive - > divetrip - > location = strdup ( displayed_dive . location ) ;
2014-01-15 08:30:42 +00:00
mark_divelist_changed ( true ) ;
2014-06-03 01:13:50 +00:00
}
2014-06-19 16:52:34 +00:00
ui . dateEdit - > setEnabled ( true ) ;
2013-05-19 16:00:57 +00:00
} else {
2014-06-03 01:13:50 +00:00
struct dive * cd = current_dive ;
2013-09-19 16:37:44 +00:00
//Reset coordinates field, in case it contains garbage.
2014-07-02 18:50:28 +00:00
updateGpsCoordinates ( & displayed_dive ) ;
2014-06-03 01:13:50 +00:00
// now check if something has changed and if yes, edit the selected dives that
// were identical with the master dive shown (and mark the divelist as changed)
2014-07-02 18:50:28 +00:00
if ( ! same_string ( displayed_dive . buddy , cd - > buddy ) )
MODIFY_SELECTED_DIVES ( EDIT_TEXT ( buddy ) ) ;
if ( ! same_string ( displayed_dive . suit , cd - > suit ) )
MODIFY_SELECTED_DIVES ( EDIT_TEXT ( suit ) ) ;
if ( ! same_string ( displayed_dive . notes , cd - > notes ) )
MODIFY_SELECTED_DIVES ( EDIT_TEXT ( notes ) ) ;
if ( ! same_string ( displayed_dive . divemaster , cd - > divemaster ) )
MODIFY_SELECTED_DIVES ( EDIT_TEXT ( divemaster ) ) ;
if ( displayed_dive . rating ! = cd - > rating )
MODIFY_SELECTED_DIVES ( EDIT_VALUE ( rating ) ) ;
if ( displayed_dive . visibility ! = cd - > visibility )
MODIFY_SELECTED_DIVES ( EDIT_VALUE ( visibility ) ) ;
if ( displayed_dive . airtemp . mkelvin ! = cd - > airtemp . mkelvin )
MODIFY_SELECTED_DIVES ( EDIT_VALUE ( airtemp . mkelvin ) ) ;
if ( displayed_dive . watertemp . mkelvin ! = cd - > watertemp . mkelvin )
MODIFY_SELECTED_DIVES ( EDIT_VALUE ( watertemp . mkelvin ) ) ;
if ( displayed_dive . when ! = cd - > when ) {
time_t offset = current_dive - > when - displayed_dive . when ;
MODIFY_SELECTED_DIVES ( mydive - > when - = offset ; ) ;
2013-09-20 23:41:42 +00:00
}
2014-07-02 18:50:28 +00:00
if ( ! same_string ( displayed_dive . location , cd - > location ) ) {
MODIFY_SELECTED_DIVES ( EDIT_TEXT ( location ) ) ;
2014-05-07 20:00:33 +00:00
// if we have a location text and haven't edited the coordinates, try to fill the coordinates
// from the existing dives
2014-06-03 01:13:50 +00:00
if ( ! same_string ( cd - > location , " " ) & &
2014-05-07 20:00:33 +00:00
( ! ui . coordinates - > isModified ( ) | |
ui . coordinates - > text ( ) . trimmed ( ) . isEmpty ( ) ) ) {
struct dive * dive ;
int i = 0 ;
2014-05-22 18:40:22 +00:00
for_each_dive ( i , dive ) {
2014-05-07 20:00:33 +00:00
QString location ( dive - > location ) ;
if ( location = = ui . location - > text ( ) & &
( dive - > latitude . udeg | | dive - > longitude . udeg ) ) {
2014-07-02 18:50:28 +00:00
MODIFY_SELECTED_DIVES ( if ( same_string ( mydive - > location , dive - > location ) ) {
2014-05-07 20:00:33 +00:00
mydive - > latitude = dive - > latitude ;
mydive - > longitude = dive - > longitude ;
} ) ;
2014-06-03 01:13:50 +00:00
MainWindow : : instance ( ) - > globe ( ) - > reload ( ) ;
2014-05-07 20:00:33 +00:00
break ;
}
}
}
}
2014-07-02 18:50:28 +00:00
if ( displayed_dive . latitude . udeg ! = current_dive - > latitude . udeg | |
displayed_dive . longitude . udeg ! = current_dive - > longitude . udeg ) {
MODIFY_SELECTED_DIVES ( gpsHasChanged ( mydive , cd , ui . coordinates - > text ( ) , 0 ) ) ;
2013-06-14 16:17:46 +00:00
}
2014-07-02 18:50:28 +00:00
if ( tagsChanged ( & displayed_dive , cd ) )
2013-11-02 01:20:02 +00:00
saveTags ( ) ;
2013-11-14 09:36:21 +00:00
if ( editMode = = MANUALLY_ADDED_DIVE ) {
2014-06-03 01:13:50 +00:00
DivePlannerPointsModel : : instance ( ) - > copyCylinders ( cd ) ;
2013-11-14 09:36:21 +00:00
} else if ( editMode ! = ADD & & cylindersModel - > changed ) {
2014-01-15 08:30:42 +00:00
mark_divelist_changed ( true ) ;
2014-07-02 18:50:28 +00:00
MODIFY_SELECTED_DIVES (
2013-09-25 17:59:11 +00:00
for ( int i = 0 ; i < MAX_CYLINDERS ; i + + ) {
2014-06-03 01:13:50 +00:00
if ( mydive ! = cd ) {
if ( same_string ( mydive - > cylinder [ i ] . type . description , cd - > cylinder [ i ] . type . description ) )
// only copy the cylinder type, none of the other values
2014-07-02 18:50:28 +00:00
mydive - > cylinder [ i ] . type = displayed_dive . cylinder [ i ] . type ;
2014-06-03 01:13:50 +00:00
} else {
2014-07-02 18:50:28 +00:00
mydive - > cylinder [ i ] = displayed_dive . cylinder [ i ] ;
2014-06-03 01:13:50 +00:00
}
2013-09-25 17:57:41 +00:00
}
2014-06-03 01:13:50 +00:00
) ;
2014-03-24 18:15:19 +00:00
MainWindow : : instance ( ) - > graphics ( ) - > replot ( ) ;
2013-09-25 17:57:41 +00:00
}
if ( weightModel - > changed ) {
2014-01-15 08:30:42 +00:00
mark_divelist_changed ( true ) ;
2014-07-02 18:50:28 +00:00
MODIFY_SELECTED_DIVES (
2013-10-01 13:52:23 +00:00
for ( int i = 0 ; i < MAX_WEIGHTSYSTEMS ; i + + ) {
2014-06-03 01:13:50 +00:00
if ( same_string ( mydive - > weightsystem [ i ] . description , cd - > weightsystem [ i ] . description ) )
2014-07-02 18:50:28 +00:00
mydive - > weightsystem [ i ] = displayed_dive . weightsystem [ i ] ;
2013-09-25 17:57:41 +00:00
}
2014-06-03 01:13:50 +00:00
) ;
}
// 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
for_each_dive ( i , d ) {
if ( d - > selected )
fixup_dive ( d ) ;
2013-09-25 17:57:41 +00:00
}
2013-05-19 14:45:01 +00:00
}
2013-11-19 22:16:33 +00:00
if ( current_dive - > divetrip ) {
current_dive - > divetrip - > when = current_dive - > when ;
find_new_trip_start_time ( current_dive - > divetrip ) ;
}
2013-11-01 15:48:34 +00:00
if ( editMode = = ADD | | editMode = = MANUALLY_ADDED_DIVE ) {
2013-09-19 04:33:39 +00:00
// clean up the dive data (get duration, depth information from samples)
2014-07-01 17:20:06 +00:00
// remove the pressures from the samples (as those prevent the user from
// being able to manually set the start and end pressure)
struct sample * sample = current_dc - > sample ;
for ( int i = 0 ; i < current_dc - > samples ; i + + , sample + + )
sample - > cylinderpressure . mbar = 0 ;
for ( int i = 0 ; i < MAX_CYLINDERS ; i + + ) {
cylinder_t * cyl = & current_dive - > cylinder [ i ] ;
cyl - > start . mbar = cyl - > sample_start . mbar ;
cyl - > end . mbar = cyl - > sample_end . mbar ;
cyl - > sample_end . mbar = cyl - > sample_start . mbar = 0 ;
}
2013-09-19 04:33:39 +00:00
fixup_dive ( current_dive ) ;
2013-09-22 14:00:14 +00:00
if ( dive_table . nr = = 1 )
current_dive - > number = 1 ;
2013-11-12 05:21:50 +00:00
else if ( selected_dive = = dive_table . nr - 1 & & get_dive ( dive_table . nr - 2 ) - > number )
2013-09-20 12:14:25 +00:00
current_dive - > number = get_dive ( dive_table . nr - 2 ) - > number + 1 ;
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > showProfile ( ) ;
2014-01-15 08:30:42 +00:00
mark_divelist_changed ( true ) ;
2013-11-09 00:09:46 +00:00
DivePlannerPointsModel : : instance ( ) - > setPlanMode ( DivePlannerPointsModel : : NOTHING ) ;
2013-09-19 04:33:39 +00:00
}
2014-02-12 14:22:54 +00:00
int scrolledBy = MainWindow : : instance ( ) - > dive_list ( ) - > verticalScrollBar ( ) - > sliderPosition ( ) ;
2013-09-25 17:36:59 +00:00
resetPallete ( ) ;
2014-01-16 04:50:56 +00:00
if ( editMode = = ADD | | editMode = = MANUALLY_ADDED_DIVE ) {
2014-04-03 17:11:39 +00:00
// it's tricky to keep the right dive selected;
// first remember which one is selected in the current sort order
// and unselect all dives
int rememberSelected = selected_dive ;
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > dive_list ( ) - > unselectDives ( ) ;
2014-04-03 17:11:39 +00:00
struct dive * d = get_dive ( rememberSelected ) ;
// mark the previously selected dive as remembered (abusing the selected flag)
2013-12-10 05:17:15 +00:00
// and then clear that flag out on the other side of the sort_table()
2013-12-03 22:34:05 +00:00
d - > selected = true ;
sort_table ( & dive_table ) ;
2014-05-22 18:40:22 +00:00
for_each_dive ( rememberSelected , d ) {
2013-12-10 05:17:15 +00:00
if ( d - > selected ) {
d - > selected = false ;
break ;
}
2013-12-03 22:34:05 +00:00
}
2014-04-03 17:11:39 +00:00
// refreshDisplay() will select the top dive if no dive was
// selected - but that may not be the right one, so select the one
// we remembered instead
MainWindow : : instance ( ) - > dive_list ( ) - > selectDive ( rememberSelected , true ) ;
2013-12-03 23:25:20 +00:00
editMode = NONE ;
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > refreshDisplay ( ) ;
2014-03-09 13:59:31 +00:00
MainWindow : : instance ( ) - > graphics ( ) - > replot ( ) ;
2014-05-21 23:34:06 +00:00
emit addDiveFinished ( ) ;
2013-12-10 05:17:15 +00:00
} else {
2013-12-03 23:25:20 +00:00
editMode = NONE ;
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > dive_list ( ) - > rememberSelection ( ) ;
2013-12-03 22:34:05 +00:00
sort_table ( & dive_table ) ;
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > refreshDisplay ( ) ;
MainWindow : : instance ( ) - > dive_list ( ) - > restoreSelection ( ) ;
2013-12-03 22:34:05 +00:00
}
2014-06-03 01:13:50 +00:00
updateDiveInfo ( ) ;
2014-02-19 17:43:34 +00:00
DivePlannerPointsModel : : instance ( ) - > setPlanMode ( DivePlannerPointsModel : : NOTHING ) ;
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > dive_list ( ) - > verticalScrollBar ( ) - > setSliderPosition ( scrolledBy ) ;
MainWindow : : instance ( ) - > dive_list ( ) - > setFocus ( ) ;
2013-09-25 17:36:59 +00:00
}
void MainTab : : resetPallete ( )
{
2013-08-16 18:38:18 +00:00
QPalette p ;
2013-10-03 18:54:25 +00:00
ui . buddy - > setPalette ( p ) ;
ui . notes - > setPalette ( p ) ;
ui . location - > setPalette ( p ) ;
ui . coordinates - > setPalette ( p ) ;
ui . divemaster - > setPalette ( p ) ;
ui . suit - > setPalette ( p ) ;
ui . airtemp - > setPalette ( p ) ;
ui . watertemp - > setPalette ( p ) ;
2014-06-19 16:52:34 +00:00
ui . dateEdit - > setPalette ( p ) ;
2014-06-26 17:54:16 +00:00
ui . timeEdit - > setPalette ( p ) ;
2013-11-02 01:20:02 +00:00
ui . tagWidget - > setPalette ( p ) ;
2013-05-18 23:42:59 +00:00
}
2014-02-28 04:09:57 +00:00
# define EDIT_TEXT2(what, text) \
2013-12-16 22:50:42 +00:00
textByteArray = text . toUtf8 ( ) ; \
2014-02-28 04:09:57 +00:00
free ( what ) ; \
2013-08-16 16:31:52 +00:00
what = strdup ( textByteArray . data ( ) ) ;
2014-07-02 18:50:28 +00:00
# define FREE_IF_DIFFERENT(what) \
if ( displayed_dive . what ! = cd - > what ) \
free ( displayed_dive . what )
2014-06-04 01:12:24 +00:00
2013-09-19 00:56:53 +00:00
void MainTab : : rejectChanges ( )
2013-05-18 23:42:59 +00:00
{
2013-11-12 05:41:29 +00:00
EditMode lastMode = editMode ;
2014-07-02 18:50:28 +00:00
if ( lastMode ! = NONE & & current_dive & & memcmp ( & displayed_dive , current_dive , sizeof ( struct dive ) ) ) {
2014-06-04 01:01:00 +00:00
if ( QMessageBox : : warning ( MainWindow : : instance ( ) , TITLE_OR_TEXT ( tr ( " Discard the Changes? " ) ,
tr ( " You are about to discard your changes. " ) ) ,
QMessageBox : : Discard | QMessageBox : : Cancel , QMessageBox : : Discard ) ! = QMessageBox : : Discard ) {
return ;
}
}
2014-05-28 03:31:18 +00:00
editMode = NONE ;
2013-09-19 01:38:38 +00:00
tabBar ( ) - > setTabIcon ( 0 , QIcon ( ) ) ; // Notes
tabBar ( ) - > setTabIcon ( 1 , QIcon ( ) ) ; // Equipment
2013-09-19 02:23:04 +00:00
2014-06-03 01:13:50 +00:00
if ( MainWindow : : instance ( ) & & MainWindow : : instance ( ) - > dive_list ( ) - > selectedTrips ( ) . count ( ) ! = 1 ) {
2013-11-12 05:41:29 +00:00
if ( lastMode = = ADD ) {
2013-09-24 19:32:18 +00:00
// clean up
DivePlannerPointsModel : : instance ( ) - > cancelPlan ( ) ;
2014-05-28 22:03:10 +00:00
hideMessage ( ) ;
resetPallete ( ) ;
return ;
2014-02-28 04:09:57 +00:00
} else if ( lastMode = = MANUALLY_ADDED_DIVE ) {
2013-11-18 19:55:56 +00:00
// 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 ( ) ;
2013-11-01 18:06:03 +00:00
}
2013-11-06 01:15:19 +00:00
if ( selected_dive > = 0 ) {
2014-07-02 18:50:28 +00:00
displayed_dive = * get_dive ( selected_dive ) ;
cylindersModel - > setDive ( & displayed_dive ) ;
weightModel - > setDive ( & displayed_dive ) ;
2013-10-09 06:24:44 +00:00
} else {
cylindersModel - > clear ( ) ;
weightModel - > clear ( ) ;
2013-11-13 13:23:59 +00:00
setEnabled ( false ) ;
2013-10-09 06:24:44 +00:00
}
2013-06-14 16:17:46 +00:00
}
2014-06-04 01:12:24 +00:00
// now let's avoid memory leaks
2014-06-28 20:42:38 +00:00
if ( MainWindow : : instance ( ) & & MainWindow : : instance ( ) - > dive_list ( ) - > selectedTrips ( ) . count ( ) = = 1 ) {
2014-07-02 18:50:28 +00:00
if ( displayed_dive . location ! = current_dive - > divetrip - > location )
free ( displayed_dive . location ) ;
if ( displayed_dive . notes ! = current_dive - > divetrip - > notes )
free ( displayed_dive . notes ) ;
2014-06-28 20:42:38 +00:00
} else {
struct dive * cd = current_dive ;
FREE_IF_DIFFERENT ( tag_list ) ;
FREE_IF_DIFFERENT ( location ) ;
FREE_IF_DIFFERENT ( buddy ) ;
FREE_IF_DIFFERENT ( divemaster ) ;
FREE_IF_DIFFERENT ( notes ) ;
FREE_IF_DIFFERENT ( suit ) ;
}
2013-12-03 20:44:48 +00:00
hideMessage ( ) ;
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > dive_list ( ) - > setEnabled ( true ) ;
2014-06-19 16:52:34 +00:00
ui . dateEdit - > setEnabled ( true ) ;
2013-09-25 17:36:59 +00:00
resetPallete ( ) ;
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > globe ( ) - > reload ( ) ;
2014-05-28 22:03:10 +00:00
if ( lastMode = = MANUALLY_ADDED_DIVE ) {
2013-09-24 19:32:18 +00:00
// more clean up
updateDiveInfo ( selected_dive ) ;
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > showProfile ( ) ;
2013-11-14 08:52:03 +00:00
// we already reloaded the divelist above, so don't recreate it or we'll lose the selection
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > refreshDisplay ( false ) ;
2013-09-20 03:58:53 +00:00
}
2014-02-12 14:22:54 +00:00
MainWindow : : instance ( ) - > dive_list ( ) - > setFocus ( ) ;
2014-05-02 04:26:18 +00:00
// the user could have edited the location and then canceled the edit
// let's get the correct location back in view
2014-05-07 20:58:07 +00:00
MainWindow : : instance ( ) - > globe ( ) - > centerOnCurrentDive ( ) ;
2014-05-28 23:50:01 +00:00
DivePlannerPointsModel : : instance ( ) - > setPlanMode ( DivePlannerPointsModel : : NOTHING ) ;
2014-06-03 01:13:50 +00:00
updateDiveInfo ( ) ;
2013-05-18 23:42:59 +00:00
}
2013-08-16 16:31:52 +00:00
# undef EDIT_TEXT2
2013-08-16 18:52:40 +00:00
2014-02-28 04:09:57 +00:00
void markChangedWidget ( QWidget * w )
{
2013-08-16 18:38:18 +00:00
QPalette p ;
2013-12-24 11:49:38 +00:00
qreal h , s , l , a ;
qApp - > palette ( ) . color ( QPalette : : Text ) . getHslF ( & h , & s , & l , & a ) ;
2014-02-28 04:09:57 +00:00
p . setBrush ( QPalette : : Base , ( l < = 0.3 ) ? QColor ( Qt : : yellow ) . lighter ( ) : ( l < = 0.6 ) ? QColor ( Qt : : yellow ) . light ( ) : /* else */ QColor ( Qt : : yellow ) . darker ( 300 ) ) ;
2013-08-16 18:52:40 +00:00
w - > setPalette ( p ) ;
}
2013-05-18 23:42:59 +00:00
2014-01-15 20:35:14 +00:00
void MainTab : : on_buddy_textChanged ( )
2013-05-18 23:42:59 +00:00
{
2014-06-03 01:13:50 +00:00
if ( editMode = = NONE )
return ;
2014-03-26 20:09:01 +00:00
QStringList text_list = ui . buddy - > toPlainText ( ) . split ( " , " , QString : : SkipEmptyParts ) ;
for ( int i = 0 ; i < text_list . size ( ) ; i + + )
text_list [ i ] = text_list [ i ] . trimmed ( ) ;
QString text = text_list . join ( " , " ) ;
2014-07-02 18:50:28 +00:00
displayed_dive . buddy = strdup ( text . toUtf8 ( ) . data ( ) ) ;
2013-10-03 18:54:25 +00:00
markChangedWidget ( ui . buddy ) ;
2013-05-18 23:42:59 +00:00
}
2014-01-19 17:30:47 +00:00
void MainTab : : on_divemaster_textChanged ( )
2013-05-18 23:42:59 +00:00
{
2014-06-03 01:13:50 +00:00
if ( editMode = = NONE )
return ;
2014-03-26 20:09:01 +00:00
QStringList text_list = ui . divemaster - > toPlainText ( ) . split ( " , " , QString : : SkipEmptyParts ) ;
for ( int i = 0 ; i < text_list . size ( ) ; i + + )
text_list [ i ] = text_list [ i ] . trimmed ( ) ;
QString text = text_list . join ( " , " ) ;
2014-07-02 18:50:28 +00:00
displayed_dive . divemaster = strdup ( text . toUtf8 ( ) . data ( ) ) ;
2013-10-03 18:54:25 +00:00
markChangedWidget ( ui . divemaster ) ;
2013-05-18 23:42:59 +00:00
}
2014-02-28 04:09:57 +00:00
void MainTab : : on_airtemp_textChanged ( const QString & text )
2013-09-20 23:41:42 +00:00
{
2014-06-03 01:13:50 +00:00
if ( editMode = = NONE )
return ;
2014-07-02 18:50:28 +00:00
displayed_dive . airtemp . mkelvin = parseTemperatureToMkelvin ( text ) ;
2013-10-03 18:54:25 +00:00
markChangedWidget ( ui . airtemp ) ;
2014-04-13 16:19:15 +00:00
validate_temp_field ( ui . airtemp , text ) ;
2013-09-20 23:41:42 +00:00
}
2014-02-28 04:09:57 +00:00
void MainTab : : on_watertemp_textChanged ( const QString & text )
2013-09-20 23:41:42 +00:00
{
2014-06-03 01:13:50 +00:00
if ( editMode = = NONE )
return ;
2014-07-02 18:50:28 +00:00
displayed_dive . watertemp . mkelvin = parseTemperatureToMkelvin ( text ) ;
2013-10-03 18:54:25 +00:00
markChangedWidget ( ui . watertemp ) ;
2014-04-13 16:19:15 +00:00
validate_temp_field ( ui . watertemp , text ) ;
2013-09-20 23:41:42 +00:00
}
2014-05-22 18:40:22 +00:00
void MainTab : : validate_temp_field ( QLineEdit * tempField , const QString & text )
2014-04-13 16:19:15 +00:00
{
static bool missing_unit = false ;
static bool missing_precision = false ;
if ( ! text . contains ( QRegExp ( " ^[-+]{0,1}[0-9]+([,.][0-9]+){0,1}(°[CF]){0,1}$ " ) ) & &
! text . isEmpty ( ) & &
! text . contains ( QRegExp ( " ^[-+]$ " ) ) ) {
if ( text . contains ( QRegExp ( " ^[-+]{0,1}[0-9]+([,.][0-9]+){0,1}(°)$ " ) ) & & ! missing_unit ) {
if ( ! missing_unit ) {
missing_unit = true ;
return ;
}
}
if ( text . contains ( QRegExp ( " ^[-+]{0,1}[0-9]+([,.]){0,1}(°[CF]){0,1}$ " ) ) & & ! missing_precision ) {
if ( ! missing_precision ) {
missing_precision = true ;
return ;
}
}
QPalette p ;
p . setBrush ( QPalette : : Base , QColor ( Qt : : red ) . lighter ( ) ) ;
tempField - > setPalette ( p ) ;
} else {
missing_unit = false ;
missing_precision = false ;
}
}
2014-05-06 20:56:46 +00:00
2014-06-26 17:57:25 +00:00
void MainTab : : on_dateEdit_dateChanged ( const QDate & date )
2013-09-20 23:41:42 +00:00
{
2014-06-03 01:13:50 +00:00
if ( editMode = = NONE )
return ;
2014-07-02 18:50:28 +00:00
QDateTime dateTime = QDateTime : : fromTime_t ( displayed_dive . when ) ;
2014-06-26 17:57:25 +00:00
dateTime . setTimeSpec ( Qt : : UTC ) ;
dateTime . setDate ( date ) ;
2014-07-02 18:50:28 +00:00
displayed_dive . when = dateTime . toTime_t ( ) ;
2014-06-19 16:52:34 +00:00
markChangedWidget ( ui . dateEdit ) ;
2013-09-20 23:41:42 +00:00
}
2014-06-26 17:54:16 +00:00
void MainTab : : on_timeEdit_timeChanged ( const QTime & time )
{
if ( editMode = = NONE )
return ;
2014-07-02 18:50:28 +00:00
QDateTime dateTime = QDateTime : : fromTime_t ( displayed_dive . when ) ;
2014-06-26 17:57:25 +00:00
dateTime . setTimeSpec ( Qt : : UTC ) ;
2014-06-26 17:54:16 +00:00
dateTime . setTime ( time ) ;
2014-07-02 18:50:28 +00:00
displayed_dive . when = dateTime . toTime_t ( ) ;
2014-06-26 17:54:16 +00:00
markChangedWidget ( ui . timeEdit ) ;
}
2014-06-03 01:13:50 +00:00
bool MainTab : : tagsChanged ( dive * a , dive * b )
{
char bufA [ 1024 ] , bufB [ 1024 ] ;
taglist_get_tagstring ( a - > tag_list , bufA , sizeof ( bufA ) ) ;
taglist_get_tagstring ( b - > tag_list , bufB , sizeof ( bufB ) ) ;
QString tagStringA ( bufA ) ;
QString tagStringB ( bufB ) ;
QStringList text_list = tagStringA . split ( " , " , QString : : SkipEmptyParts ) ;
for ( int i = 0 ; i < text_list . size ( ) ; i + + )
text_list [ i ] = text_list [ i ] . trimmed ( ) ;
QString textA = text_list . join ( " , " ) ;
text_list = tagStringB . split ( " , " , QString : : SkipEmptyParts ) ;
for ( int i = 0 ; i < text_list . size ( ) ; i + + )
text_list [ i ] = text_list [ i ] . trimmed ( ) ;
QString textB = text_list . join ( " , " ) ;
return textA ! = textB ;
}
2014-05-06 20:56:46 +00:00
// changing the tags on multiple dives is semantically strange - what's the right thing to do?
2013-11-02 01:20:02 +00:00
void MainTab : : saveTags ( )
{
2014-06-03 01:13:50 +00:00
struct dive * cd = current_dive ;
2014-07-02 18:50:28 +00:00
MODIFY_SELECTED_DIVES (
2014-05-22 18:40:22 +00:00
QString tag ;
taglist_free ( mydive - > tag_list ) ;
mydive - > tag_list = NULL ;
2014-06-03 01:13:50 +00:00
Q_FOREACH ( tag , ui . tagWidget - > getBlockStringList ( ) )
2014-05-22 18:40:22 +00:00
taglist_add_tag ( & mydive - > tag_list , tag . toUtf8 ( ) . data ( ) ) ; ) ;
2013-11-02 01:20:02 +00:00
}
void MainTab : : on_tagWidget_textChanged ( )
{
2014-06-03 01:13:50 +00:00
if ( editMode = = NONE )
return ;
QString tag ;
2014-07-02 18:50:28 +00:00
if ( displayed_dive . tag_list ! = current_dive - > tag_list )
taglist_free ( displayed_dive . tag_list ) ;
displayed_dive . tag_list = NULL ;
2014-06-03 01:13:50 +00:00
Q_FOREACH ( tag , ui . tagWidget - > getBlockStringList ( ) )
2014-07-02 18:50:28 +00:00
taglist_add_tag ( & displayed_dive . tag_list , tag . toUtf8 ( ) . data ( ) ) ;
if ( tagsChanged ( & displayed_dive , current_dive ) )
2014-06-03 01:13:50 +00:00
markChangedWidget ( ui . tagWidget ) ;
2013-11-02 01:20:02 +00:00
}
2014-02-28 04:09:57 +00:00
void MainTab : : on_location_textChanged ( const QString & text )
2013-05-18 23:42:59 +00:00
{
2014-05-07 21:51:39 +00:00
if ( editMode = = NONE )
return ;
2014-07-02 18:50:28 +00:00
displayed_dive . location = strdup ( ui . location - > text ( ) . toUtf8 ( ) . data ( ) ) ;
2013-10-03 18:54:25 +00:00
markChangedWidget ( ui . location ) ;
2013-05-18 23:42:59 +00:00
}
2014-02-28 04:09:57 +00:00
void MainTab : : on_suit_textChanged ( const QString & text )
2013-05-18 23:42:59 +00:00
{
2014-06-03 01:13:50 +00:00
if ( editMode = = NONE )
return ;
2014-07-02 18:50:28 +00:00
displayed_dive . suit = strdup ( text . toUtf8 ( ) . data ( ) ) ;
2013-10-03 18:54:25 +00:00
markChangedWidget ( ui . suit ) ;
2013-05-18 23:42:59 +00:00
}
void MainTab : : on_notes_textChanged ( )
{
2013-08-16 16:31:52 +00:00
if ( editMode = = NONE )
return ;
2014-07-02 18:50:28 +00:00
displayed_dive . notes = strdup ( ui . notes - > toPlainText ( ) . toUtf8 ( ) . data ( ) ) ;
2013-10-03 18:54:25 +00:00
markChangedWidget ( ui . notes ) ;
2013-05-18 23:42:59 +00:00
}
2014-02-28 04:09:57 +00:00
void MainTab : : on_coordinates_textChanged ( const QString & text )
2013-09-17 19:50:15 +00:00
{
2014-06-03 01:13:50 +00:00
if ( editMode = = NONE )
return ;
2013-12-23 22:56:40 +00:00
bool gpsChanged = false ;
bool parsed = false ;
2014-05-07 22:14:01 +00:00
QPalette p ;
ui . coordinates - > setPalette ( p ) ; // reset palette
2014-07-02 18:50:28 +00:00
gpsChanged = gpsHasChanged ( & displayed_dive , current_dive , text , & parsed ) ;
2014-05-07 22:14:01 +00:00
if ( gpsChanged )
markChangedWidget ( ui . coordinates ) ; // marks things yellow
if ( ! parsed ) {
2013-09-19 16:37:44 +00:00
p . setBrush ( QPalette : : Base , QColor ( Qt : : red ) . lighter ( ) ) ;
2014-05-07 22:14:01 +00:00
ui . coordinates - > setPalette ( p ) ; // marks things red
2013-09-19 16:37:44 +00:00
}
2013-09-17 19:50:15 +00:00
}
2013-05-18 23:42:59 +00:00
void MainTab : : on_rating_valueChanged ( int value )
{
2014-07-02 18:50:28 +00:00
displayed_dive . rating = value ;
2013-05-18 23:42:59 +00:00
}
2013-05-20 13:25:16 +00:00
void MainTab : : on_visibility_valueChanged ( int value )
{
2014-07-02 18:50:28 +00:00
displayed_dive . visibility = value ;
2013-05-20 13:25:16 +00:00
}
2013-06-16 17:36:23 +00:00
2014-07-02 18:50:28 +00:00
# undef MODIFY_SELECTED_DIVESVES
2014-05-06 20:56:46 +00:00
# undef EDIT_TEXT
# undef EDIT_VALUE
2014-02-28 04:09:57 +00:00
void MainTab : : editCylinderWidget ( const QModelIndex & index )
2013-07-17 15:13:04 +00:00
{
2014-07-01 17:18:21 +00:00
// we need a local copy or bad things happen when enableEdition() is called
QModelIndex editIndex = index ;
2014-03-15 22:14:59 +00:00
if ( cylindersModel - > changed & & editMode = = NONE ) {
2013-09-25 17:11:38 +00:00
enableEdition ( ) ;
2014-03-15 22:14:59 +00:00
return ;
}
2014-07-01 17:18:21 +00:00
if ( editIndex . isValid ( ) & & editIndex . column ( ) ! = CylindersModel : : REMOVE ) {
2014-03-15 22:14:59 +00:00
if ( editMode = = NONE )
enableEdition ( ) ;
2014-07-01 17:18:21 +00:00
ui . cylinders - > edit ( editIndex ) ;
2014-03-15 22:14:59 +00:00
}
2013-07-17 15:13:04 +00:00
}
2014-02-28 04:09:57 +00:00
void MainTab : : editWeightWidget ( const QModelIndex & index )
2013-07-17 15:13:04 +00:00
{
2013-09-25 17:11:38 +00:00
if ( editMode = = NONE )
enableEdition ( ) ;
2013-09-02 19:21:08 +00:00
if ( index . isValid ( ) & & index . column ( ) ! = WeightModel : : REMOVE )
2013-10-03 18:54:25 +00:00
ui . weights - > edit ( index ) ;
2013-06-16 17:36:23 +00:00
}
2013-10-07 18:48:14 +00:00
2013-11-19 12:12:31 +00:00
void MainTab : : updateCoordinatesText ( qreal lat , qreal lon )
{
int ulat = rint ( lat * 1000000 ) ;
int ulon = rint ( lon * 1000000 ) ;
ui . coordinates - > setText ( printGPSCoords ( ulat , ulon ) ) ;
}
2013-11-11 23:21:45 +00:00
void MainTab : : updateGpsCoordinates ( const struct dive * dive )
{
2013-11-13 13:23:59 +00:00
if ( dive ) {
ui . coordinates - > setText ( printGPSCoords ( dive - > latitude . udeg , dive - > longitude . udeg ) ) ;
ui . coordinates - > setModified ( dive - > latitude . udeg | | dive - > longitude . udeg ) ;
} else {
ui . coordinates - > clear ( ) ;
}
2013-11-11 23:21:45 +00:00
}
2014-05-07 22:12:45 +00:00
QString MainTab : : trHemisphere ( const char * orig )
{
return tr ( orig ) ;
}
2014-06-03 22:29:28 +00:00
void MainTab : : escDetected ( )
{
if ( editMode ! = NONE )
rejectChanges ( ) ;
}
2014-06-27 12:17:33 +00:00
void MainTab : : photoDoubleClicked ( const QString filePath )
{
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( filePath ) ) ;
}