mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Merge branch 'fixPlannerStartTime'
This commit is contained in:
		
						commit
						d25e31525c
					
				
					 4 changed files with 60 additions and 6 deletions
				
			
		|  | @ -82,6 +82,22 @@ void DivePlannerPointsModel::createSimpleDive() | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void DivePlannerPointsModel::setupStartTime() | ||||||
|  | { | ||||||
|  | 	// if the latest dive is in the future, then start an hour after it ends
 | ||||||
|  | 	// otherwise start an hour from now
 | ||||||
|  | 	startTime = QDateTime::currentDateTimeUtc().addSecs(3600 + gettimezoneoffset()); | ||||||
|  | 	if (dive_table.nr) { | ||||||
|  | 		struct dive *d = get_dive(dive_table.nr - 1); | ||||||
|  | 		time_t ends = d->when + d->duration.seconds; | ||||||
|  | 		time_t diff = ends - startTime.toTime_t(); | ||||||
|  | 		if (diff > 0) { | ||||||
|  | 			startTime = startTime.addSecs(diff + 3600); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	emit startTimeChanged(startTime); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void DivePlannerPointsModel::loadFromDive(dive *d) | void DivePlannerPointsModel::loadFromDive(dive *d) | ||||||
| { | { | ||||||
| 	// We need to make a copy, because as soon as the model is modified, it will
 | 	// We need to make a copy, because as soon as the model is modified, it will
 | ||||||
|  | @ -276,8 +292,10 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg | ||||||
| 
 | 
 | ||||||
| 	ui.tableWidget->setBtnToolTip(tr("add dive data point")); | 	ui.tableWidget->setBtnToolTip(tr("add dive data point")); | ||||||
| 	connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime))); | 	connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime))); | ||||||
|  | 	connect(ui.dateEdit, SIGNAL(dateChanged(QDate)), plannerModel, SLOT(setStartDate(QDate))); | ||||||
| 	connect(ui.ATMPressure, SIGNAL(valueChanged(int)), this, SLOT(atmPressureChanged(int))); | 	connect(ui.ATMPressure, SIGNAL(valueChanged(int)), this, SLOT(atmPressureChanged(int))); | ||||||
| 	connect(ui.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int))); | 	connect(ui.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int))); | ||||||
|  | 	connect(DivePlannerPointsModel::instance(), SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime))); | ||||||
| 
 | 
 | ||||||
| 	// Creating (and canceling) the plan
 | 	// Creating (and canceling) the plan
 | ||||||
| 	connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan())); | 	connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan())); | ||||||
|  | @ -286,7 +304,6 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg | ||||||
| 	connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan())); | 	connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan())); | ||||||
| 
 | 
 | ||||||
| 	/* set defaults. */ | 	/* set defaults. */ | ||||||
| 	ui.startTime->setTime(QTime(1, 0)); |  | ||||||
| 	ui.ATMPressure->setValue(1013); | 	ui.ATMPressure->setValue(1013); | ||||||
| 	ui.atmHeight->setValue(0); | 	ui.atmHeight->setValue(0); | ||||||
| 
 | 
 | ||||||
|  | @ -294,6 +311,12 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg | ||||||
| 	setMinimumHeight(0); | 	setMinimumHeight(0); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void DivePlannerWidget::setupStartTime(QDateTime startTime) | ||||||
|  | { | ||||||
|  | 	ui.startTime->setTime(startTime.time()); | ||||||
|  | 	ui.dateEdit->setDate(startTime.date()); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void DivePlannerWidget::settingsChanged() | void DivePlannerWidget::settingsChanged() | ||||||
| { | { | ||||||
| 	// right now there's nothing special we do when settings change
 | 	// right now there's nothing special we do when settings change
 | ||||||
|  | @ -595,6 +618,7 @@ DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTable | ||||||
| { | { | ||||||
| 	memset(&diveplan, 0, sizeof(diveplan)); | 	memset(&diveplan, 0, sizeof(diveplan)); | ||||||
| 	memset(&backupDive, 0, sizeof(backupDive)); | 	memset(&backupDive, 0, sizeof(backupDive)); | ||||||
|  | 	startTime = QDateTime::currentDateTimeUtc(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| DivePlannerPointsModel *DivePlannerPointsModel::instance() | DivePlannerPointsModel *DivePlannerPointsModel::instance() | ||||||
|  | @ -690,9 +714,17 @@ void DivePlannerPointsModel::setDropStoneMode(bool value) | ||||||
| 	emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1)); | 	emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void DivePlannerPointsModel::setStartDate(const QDate &date) | ||||||
|  | { | ||||||
|  | 	startTime.setDate(date); | ||||||
|  | 	diveplan.when = startTime.toTime_t(); | ||||||
|  | 	emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1)); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void DivePlannerPointsModel::setStartTime(const QTime &t) | void DivePlannerPointsModel::setStartTime(const QTime &t) | ||||||
| { | { | ||||||
| 	diveplan.when = (t.msec() + QDateTime::currentMSecsSinceEpoch()) / 1000 - gettimezoneoffset(); | 	startTime.setTime(t); | ||||||
|  | 	diveplan.when = startTime.toTime_t(); | ||||||
| 	emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1)); | 	emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ | ||||||
| 
 | 
 | ||||||
| #include <QGraphicsPathItem> | #include <QGraphicsPathItem> | ||||||
| #include <QAbstractTableModel> | #include <QAbstractTableModel> | ||||||
|  | #include <QDateTime> | ||||||
| 
 | 
 | ||||||
| #include "dive.h" | #include "dive.h" | ||||||
| 
 | 
 | ||||||
|  | @ -37,6 +38,7 @@ public: | ||||||
| 	void setPlanMode(Mode mode); | 	void setPlanMode(Mode mode); | ||||||
| 	bool isPlanner(); | 	bool isPlanner(); | ||||||
| 	void createSimpleDive(); | 	void createSimpleDive(); | ||||||
|  | 	void setupStartTime(); | ||||||
| 	void clear(); | 	void clear(); | ||||||
| 	Mode currentMode() const; | 	Mode currentMode() const; | ||||||
| 	bool setRecalc(bool recalc); | 	bool setRecalc(bool recalc); | ||||||
|  | @ -69,6 +71,7 @@ slots: | ||||||
| 	void setBottomSac(int sac); | 	void setBottomSac(int sac); | ||||||
| 	void setDecoSac(int sac); | 	void setDecoSac(int sac); | ||||||
| 	void setStartTime(const QTime &t); | 	void setStartTime(const QTime &t); | ||||||
|  | 	void setStartDate(const QDate &date); | ||||||
| 	void setLastStop6m(bool value); | 	void setLastStop6m(bool value); | ||||||
| 	void setDropStoneMode(bool value); | 	void setDropStoneMode(bool value); | ||||||
| 	void setVerbatim(bool value); | 	void setVerbatim(bool value); | ||||||
|  | @ -88,6 +91,7 @@ signals: | ||||||
| 	void planCreated(); | 	void planCreated(); | ||||||
| 	void planCanceled(); | 	void planCanceled(); | ||||||
| 	void cylinderModelEdited(); | 	void cylinderModelEdited(); | ||||||
|  | 	void startTimeChanged(QDateTime); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
| 	explicit DivePlannerPointsModel(QObject *parent = 0); | 	explicit DivePlannerPointsModel(QObject *parent = 0); | ||||||
|  | @ -103,6 +107,7 @@ private: | ||||||
| 	struct dive *stagingDive; | 	struct dive *stagingDive; | ||||||
| 	QVector<QPair<int, int> > oldGases; | 	QVector<QPair<int, int> > oldGases; | ||||||
| 	bool drop_stone_mode; | 	bool drop_stone_mode; | ||||||
|  | 	QDateTime startTime; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class DiveHandler : public QObject, public QGraphicsEllipseItem { | class DiveHandler : public QObject, public QGraphicsEllipseItem { | ||||||
|  | @ -129,9 +134,9 @@ class DivePlannerWidget : public QWidget { | ||||||
| 	Q_OBJECT | 	Q_OBJECT | ||||||
| public: | public: | ||||||
| 	explicit DivePlannerWidget(QWidget *parent = 0, Qt::WindowFlags f = 0); | 	explicit DivePlannerWidget(QWidget *parent = 0, Qt::WindowFlags f = 0); | ||||||
| 
 |  | ||||||
| public | public | ||||||
| slots: | slots: | ||||||
|  | 	void setupStartTime(QDateTime startTime); | ||||||
| 	void settingsChanged(); | 	void settingsChanged(); | ||||||
| 	void atmPressureChanged(const int pressure); | 	void atmPressureChanged(const int pressure); | ||||||
| 	void heightChanged(const int height); | 	void heightChanged(const int height); | ||||||
|  |  | ||||||
|  | @ -95,13 +95,12 @@ | ||||||
|            <height>50</height> |            <height>50</height> | ||||||
|           </size> |           </size> | ||||||
|          </property> |          </property> | ||||||
|          <zorder>label_2</zorder> |  | ||||||
|         </widget> |         </widget> | ||||||
|        </item> |        </item> | ||||||
|        <item row="0" column="0"> |        <item row="0" column="0"> | ||||||
|         <widget class="QLabel" name="label"> |         <widget class="QLabel" name="label"> | ||||||
|          <property name="text"> |          <property name="text"> | ||||||
|           <string>Start Time</string> |           <string>Planned Dive Time</string> | ||||||
|          </property> |          </property> | ||||||
|         </widget> |         </widget> | ||||||
|        </item> |        </item> | ||||||
|  | @ -113,7 +112,18 @@ | ||||||
|         </widget> |         </widget> | ||||||
|        </item> |        </item> | ||||||
|        <item row="1" column="0"> |        <item row="1" column="0"> | ||||||
|         <widget class="QTimeEdit" name="startTime"/> |         <layout class="QHBoxLayout" name="dateAndTime"> | ||||||
|  |          <item> | ||||||
|  |           <widget class="DateWidget" name="dateEdit" native="true"> | ||||||
|  |            <property name="focusPolicy"> | ||||||
|  |             <enum>Qt::StrongFocus</enum> | ||||||
|  |            </property> | ||||||
|  |           </widget> | ||||||
|  |          </item> | ||||||
|  |          <item> | ||||||
|  |           <widget class="QTimeEdit" name="startTime"/> | ||||||
|  |          </item> | ||||||
|  |         </layout> | ||||||
|        </item> |        </item> | ||||||
|        <item row="2" column="0"> |        <item row="2" column="0"> | ||||||
|         <widget class="QLabel" name="label_7"> |         <widget class="QLabel" name="label_7"> | ||||||
|  | @ -165,6 +175,12 @@ | ||||||
|    <header>tableview.h</header> |    <header>tableview.h</header> | ||||||
|    <container>1</container> |    <container>1</container> | ||||||
|   </customwidget> |   </customwidget> | ||||||
|  |   <customwidget> | ||||||
|  |    <class>DateWidget</class> | ||||||
|  |    <extends>QWidget</extends> | ||||||
|  |    <header>simplewidgets.h</header> | ||||||
|  |    <container>1</container> | ||||||
|  |   </customwidget> | ||||||
|  </customwidgets> |  </customwidgets> | ||||||
|  <tabstops> |  <tabstops> | ||||||
|   <tabstop>startTime</tabstop> |   <tabstop>startTime</tabstop> | ||||||
|  |  | ||||||
|  | @ -483,6 +483,7 @@ void MainWindow::on_actionDivePlanner_triggered() | ||||||
| 	DivePlannerPointsModel::instance()->setupCylinders(); | 	DivePlannerPointsModel::instance()->setupCylinders(); | ||||||
| 
 | 
 | ||||||
| 	// create a simple starting dive, using the first gas from the just copied cylidners
 | 	// create a simple starting dive, using the first gas from the just copied cylidners
 | ||||||
|  | 	DivePlannerPointsModel::instance()->setupStartTime(); | ||||||
| 	createFakeDiveForAddAndPlan(); | 	createFakeDiveForAddAndPlan(); | ||||||
| 	DivePlannerPointsModel::instance()->createSimpleDive(); | 	DivePlannerPointsModel::instance()->createSimpleDive(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue