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) | ||||
| { | ||||
| 	// 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")); | ||||
| 	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.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int))); | ||||
| 	connect(DivePlannerPointsModel::instance(), SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime))); | ||||
| 
 | ||||
| 	// Creating (and canceling) the plan
 | ||||
| 	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())); | ||||
| 
 | ||||
| 	/* set defaults. */ | ||||
| 	ui.startTime->setTime(QTime(1, 0)); | ||||
| 	ui.ATMPressure->setValue(1013); | ||||
| 	ui.atmHeight->setValue(0); | ||||
| 
 | ||||
|  | @ -294,6 +311,12 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg | |||
| 	setMinimumHeight(0); | ||||
| } | ||||
| 
 | ||||
| void DivePlannerWidget::setupStartTime(QDateTime startTime) | ||||
| { | ||||
| 	ui.startTime->setTime(startTime.time()); | ||||
| 	ui.dateEdit->setDate(startTime.date()); | ||||
| } | ||||
| 
 | ||||
| void DivePlannerWidget::settingsChanged() | ||||
| { | ||||
| 	// 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(&backupDive, 0, sizeof(backupDive)); | ||||
| 	startTime = QDateTime::currentDateTimeUtc(); | ||||
| } | ||||
| 
 | ||||
| DivePlannerPointsModel *DivePlannerPointsModel::instance() | ||||
|  | @ -690,9 +714,17 @@ void DivePlannerPointsModel::setDropStoneMode(bool value) | |||
| 	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) | ||||
| { | ||||
| 	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)); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ | |||
| 
 | ||||
| #include <QGraphicsPathItem> | ||||
| #include <QAbstractTableModel> | ||||
| #include <QDateTime> | ||||
| 
 | ||||
| #include "dive.h" | ||||
| 
 | ||||
|  | @ -37,6 +38,7 @@ public: | |||
| 	void setPlanMode(Mode mode); | ||||
| 	bool isPlanner(); | ||||
| 	void createSimpleDive(); | ||||
| 	void setupStartTime(); | ||||
| 	void clear(); | ||||
| 	Mode currentMode() const; | ||||
| 	bool setRecalc(bool recalc); | ||||
|  | @ -69,6 +71,7 @@ slots: | |||
| 	void setBottomSac(int sac); | ||||
| 	void setDecoSac(int sac); | ||||
| 	void setStartTime(const QTime &t); | ||||
| 	void setStartDate(const QDate &date); | ||||
| 	void setLastStop6m(bool value); | ||||
| 	void setDropStoneMode(bool value); | ||||
| 	void setVerbatim(bool value); | ||||
|  | @ -88,6 +91,7 @@ signals: | |||
| 	void planCreated(); | ||||
| 	void planCanceled(); | ||||
| 	void cylinderModelEdited(); | ||||
| 	void startTimeChanged(QDateTime); | ||||
| 
 | ||||
| private: | ||||
| 	explicit DivePlannerPointsModel(QObject *parent = 0); | ||||
|  | @ -103,6 +107,7 @@ private: | |||
| 	struct dive *stagingDive; | ||||
| 	QVector<QPair<int, int> > oldGases; | ||||
| 	bool drop_stone_mode; | ||||
| 	QDateTime startTime; | ||||
| }; | ||||
| 
 | ||||
| class DiveHandler : public QObject, public QGraphicsEllipseItem { | ||||
|  | @ -129,9 +134,9 @@ class DivePlannerWidget : public QWidget { | |||
| 	Q_OBJECT | ||||
| public: | ||||
| 	explicit DivePlannerWidget(QWidget *parent = 0, Qt::WindowFlags f = 0); | ||||
| 
 | ||||
| public | ||||
| slots: | ||||
| 	void setupStartTime(QDateTime startTime); | ||||
| 	void settingsChanged(); | ||||
| 	void atmPressureChanged(const int pressure); | ||||
| 	void heightChanged(const int height); | ||||
|  |  | |||
|  | @ -95,13 +95,12 @@ | |||
|            <height>50</height> | ||||
|           </size> | ||||
|          </property> | ||||
|          <zorder>label_2</zorder> | ||||
|         </widget> | ||||
|        </item> | ||||
|        <item row="0" column="0"> | ||||
|         <widget class="QLabel" name="label"> | ||||
|          <property name="text"> | ||||
|           <string>Start Time</string> | ||||
|           <string>Planned Dive Time</string> | ||||
|          </property> | ||||
|         </widget> | ||||
|        </item> | ||||
|  | @ -113,8 +112,19 @@ | |||
|         </widget> | ||||
|        </item> | ||||
|        <item row="1" column="0"> | ||||
|         <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 row="2" column="0"> | ||||
|         <widget class="QLabel" name="label_7"> | ||||
|          <property name="text"> | ||||
|  | @ -165,6 +175,12 @@ | |||
|    <header>tableview.h</header> | ||||
|    <container>1</container> | ||||
|   </customwidget> | ||||
|   <customwidget> | ||||
|    <class>DateWidget</class> | ||||
|    <extends>QWidget</extends> | ||||
|    <header>simplewidgets.h</header> | ||||
|    <container>1</container> | ||||
|   </customwidget> | ||||
|  </customwidgets> | ||||
|  <tabstops> | ||||
|   <tabstop>startTime</tabstop> | ||||
|  |  | |||
|  | @ -483,6 +483,7 @@ void MainWindow::on_actionDivePlanner_triggered() | |||
| 	DivePlannerPointsModel::instance()->setupCylinders(); | ||||
| 
 | ||||
| 	// create a simple starting dive, using the first gas from the just copied cylidners
 | ||||
| 	DivePlannerPointsModel::instance()->setupStartTime(); | ||||
| 	createFakeDiveForAddAndPlan(); | ||||
| 	DivePlannerPointsModel::instance()->createSimpleDive(); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue