Atdtode, Dirk:

This series of patches makes the new profile somewhat workable as an
'Add Dive', there are lots of bugs ( handlers don't move for  instance
), but you can actually add the dive stops and save the dive.

nothing else.

I'm going to sleep now, as it's midnight, but if anyone wanna lend me
a hand, please.
all code inside an #if 0 on the diveplanner.cpp means that needs to be
moved to the new profile.  so, if anyone wanna help, there's a few
quite easy to move around.
From dbd06eee1468a721e9e898c9fc3d35d8661a1233 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 21 May 2014 21:18:10 -0300
Subject: [PATCH 12/16] Moved two necessary functions for the Planner behavior
 to the Profile code.

Those two functions are important and necessary for the Planner, it
creates and removes the little balls that acts as handlers so the
profile can be edited by the mouse.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/profilewidget2.cpp | 28 ++++++++++++++++++++++++++++
 qt-ui/profile/profilewidget2.h   | 10 +++++++++-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 45df8b1..ce10903 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -920,3 +920,31 @@ void ProfileWidget2::editName()
 	replot();
 }
 
+void ProfileWidget2::pointInserted(const QModelIndex &parent, int start, int end)
+{
+	DiveHandler *item = new DiveHandler();
+	scene()->addItem(item);
+	handles << item;
+
+	QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem();
+	scene()->addItem(gasChooseBtn);
+	gasChooseBtn->setZValue(10);
+	gasChooseBtn->setFlag(QGraphicsItem::ItemIgnoresTransformations);
+	gases << gasChooseBtn;
+	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+	if (plannerModel->recalcQ())
+		replot();
+}
+
+void ProfileWidget2::pointsRemoved(const QModelIndex &, int start, int end)
+{ // start and end are inclusive.
+	int num = (end - start) + 1;
+	for (int i = num; i != 0; i--) {
+		delete handles.back();
+		handles.pop_back();
+		delete gases.back();
+		gases.pop_back();
+	}
+	scene()->clearSelection();
+	replot();
+}
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index 1ba6e57..46c1ee0 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -40,6 +40,9 @@ class DiveCalculatedTissue;
 class PartialPressureGasItem;
 class PartialGasPressureAxis;
 class AbstractProfilePolygonItem;
+class DiveHandler;
+class QGraphicsSimpleTextItem;
+class QModelIndex;
 
 class ProfileWidget2 : public QGraphicsView {
 	Q_OBJECT
@@ -85,6 +88,8 @@ slots: // Necessary to call from QAction's signals.
 	void removeEvent();
 	void editName();
 	void makeFirstDC();
+	void pointInserted(const QModelIndex &parent, int start, int end);
+	void pointsRemoved(const QModelIndex &, int start, int end);
 
 protected:
 	virtual void resizeEvent(QResizeEvent *event);
@@ -100,7 +105,6 @@ private: /*methods*/
 	void setupItemSizes();
 	void addItemsToScene();
 	void setupItemOnScene();
-
 private:
 	DivePlotDataModel *dataModel;
 	int zoomLevel;
@@ -135,6 +139,10 @@ private:
 	RulerItem2 *rulerItem;
 	bool isGrayscale;
 	bool printMode;
+
+	//specifics for ADD and PLAN
+	QList<DiveHandler *> handles;
+	QList<QGraphicsSimpleTextItem *> gases;
 };
 
 #endif // PROFILEWIDGET2_H
-- 
1.9.3

From 83ae5e868aeba6008b78e1c71851a226ff53ad0b Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 21 May 2014 21:23:19 -0300
Subject: [PATCH 13/16] Disconnect temporary connections on the Profile.

This code adds the disconnections of temporaries. A temporary
connection is a connection that should be active only on a
certain state, and we need to clean that for the new state
that will enter after.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/profilewidget2.cpp | 16 ++++++++++++++++
 qt-ui/profile/profilewidget2.h   |  4 +++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index ce10903..934ed6a 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -606,6 +606,7 @@ void ProfileWidget2::setEmptyState()
 	if (currentState == EMPTY)
 		return;
 
+	disconnectTemporaryConnections();
 	setBackgroundBrush(getColor(::BACKGROUND, isGrayscale));
 	dataModel->clear();
 	currentState = EMPTY;
@@ -648,6 +649,7 @@ void ProfileWidget2::setProfileState()
 		return;
 	}
 
+	disconnectTemporaryConnections();
 	currentState = PROFILE;
 	MainWindow::instance()->setToolButtonsEnabled(true);
 	toolTipItem->readPos();
@@ -707,6 +709,7 @@ void ProfileWidget2::setAddState()
 	if (currentState == ADD)
 		return;
 
+	disconnectTemporaryConnections();
 	/* show the same stuff that the profile shows. */
 	currentState = ADD; /* enable the add state. */
 	setBackgroundBrush(QColor(Qt::blue).light());
@@ -717,6 +720,7 @@ void ProfileWidget2::setPlanState()
 	if (currentState == PLAN)
 		return;
 
+	disconnectTemporaryConnections();
 	/* show the same stuff that the profile shows. */
 	currentState = PLAN; /* enable the add state. */
 	setBackgroundBrush(QColor(Qt::green).light());
@@ -920,6 +924,18 @@ void ProfileWidget2::editName()
 	replot();
 }
 
+void ProfileWidget2::disconnectTemporaryConnections()
+{
+	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+	disconnect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot()));
+	disconnect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(replot()));
+
+	disconnect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+		this, SLOT(pointInserted(const QModelIndex &, int, int)));
+	disconnect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
+		this, SLOT(pointsRemoved(const QModelIndex &, int, int)));
+}
+
 void ProfileWidget2::pointInserted(const QModelIndex &parent, int start, int end)
 {
 	DiveHandler *item = new DiveHandler();
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index 46c1ee0..2ba1cd0 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -67,7 +67,6 @@ public:
 
 	ProfileWidget2(QWidget *parent = 0);
 	void plotDives(QList<dive *> dives);
-	void replot();
 	virtual bool eventFilter(QObject *, QEvent *);
 	void setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis, DivePlotDataModel *model, int vData, int hData, int zValue);
 	void setPrintMode(bool mode, bool grayscale = false);
@@ -90,6 +89,7 @@ slots: // Necessary to call from QAction's signals.
 	void makeFirstDC();
 	void pointInserted(const QModelIndex &parent, int start, int end);
 	void pointsRemoved(const QModelIndex &, int start, int end);
+	void replot();
 
 protected:
 	virtual void resizeEvent(QResizeEvent *event);
@@ -105,6 +105,8 @@ private: /*methods*/
 	void setupItemSizes();
 	void addItemsToScene();
 	void setupItemOnScene();
+	void disconnectTemporaryConnections();
+
 private:
 	DivePlotDataModel *dataModel;
 	int zoomLevel;
-- 
1.9.3

From 4b37ac174453588ab0172d1764be6641b7c5902f Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 21 May 2014 21:38:26 -0300
Subject: [PATCH 14/16] Code Cleanup: connections can be made between signals.

A signal can connect to another signal, so I removed a slot
that the sole purpose was to call another signal and replace
d by a direct call.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/diveplanner.cpp | 11 +++--------
 qt-ui/diveplanner.h   |  1 -
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index aabd331..f4f3d50 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -982,11 +982,11 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
 	connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
 		GasSelectionModel::instance(), SLOT(repopulate()));
 	connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
-		plannerModel, SLOT(emitCylinderModelEdited()));
+		plannerModel, SIGNAL(cylinderModelEdited()));
 	connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
-		plannerModel, SLOT(emitCylinderModelEdited()));
+		plannerModel, SIGNAL(cylinderModelEdited()));
 	connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
-		plannerModel, SLOT(emitCylinderModelEdited()));
+		plannerModel, SIGNAL(cylinderModelEdited()));
 
 	ui.tableWidget->setBtnToolTip(tr("add dive data point"));
 	connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
@@ -1067,11 +1067,6 @@ bool DivePlannerPointsModel::recalcQ()
 	return recalc;
 }
 
-void DivePlannerPointsModel::emitCylinderModelEdited()
-{
-	cylinderModelEdited();
-}
-
 int DivePlannerPointsModel::columnCount(const QModelIndex &parent) const
 {
 	return COLUMNS;
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 5069532..94fcdeb 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -80,7 +80,6 @@ slots:
 	void deleteTemporaryPlan();
 	void loadFromDive(dive *d);
 	void restoreBackupDive();
-	void emitCylinderModelEdited();
 
 signals:
 	void planCreated();
-- 
1.9.3

From 643e18efc9d009dd98cf917dfc27533c91393024 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 21 May 2014 23:31:26 -0300
Subject: [PATCH 15/16] Profile now correctly display the Planned Dive.

But doesn't move the handlers yet, and when you confirm it
you also must click on the dive to select it or the profile
will show garbage.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/diveplanner.cpp            | 26 +-----------------
 qt-ui/diveplanner.h              |  5 +++-
 qt-ui/mainwindow.cpp             |  3 ++-
 qt-ui/profile/profilewidget2.cpp | 57 +++++++++++++++++++++++++++++++++++-----
 qt-ui/profile/profilewidget2.h   |  1 +
 5 files changed, 58 insertions(+), 34 deletions(-)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index f4f3d50..08b172c 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -150,13 +150,6 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent
 	ADD_ACTION(Qt::Key_Right, keyRightAction());
 #undef ADD_ACTION
 
-	connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(drawProfile()));
-	connect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(drawProfile()));
-
-	connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
-		this, SLOT(pointInserted(const QModelIndex &, int, int)));
-	connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
-		this, SLOT(pointsRemoved(const QModelIndex &, int, int)));
 	setRenderHint(QPainter::Antialiasing);
 }
 
@@ -504,23 +497,6 @@ void DivePlannerGraphics::drawProfile()
 		depthLine->updateTicks();
 	}
 
-	// Re-position the user generated dive handlers
-	int last = 0;
-	for (int i = 0; i < plannerModel->rowCount(); i++) {
-		struct divedatapoint datapoint = plannerModel->at(i);
-		if (datapoint.time == 0) // those are the magic entries for tanks
-			continue;
-		DiveHandler *h = handles.at(i);
-		h->setPos(timeLine->posAtValue(datapoint.time / 60), depthLine->posAtValue(datapoint.depth));
-		QPointF p1 = (last == i) ? QPointF(timeLine->posAtValue(0), depthLine->posAtValue(0)) : handles[last]->pos();
-		QPointF p2 = handles[i]->pos();
-		QLineF line(p1, p2);
-		QPointF pos = line.pointAt(0.5);
-		gases[i]->setPos(pos);
-		gases[i]->setText(dpGasToStr(plannerModel->at(i)));
-		last = i;
-	}
-
 	// (re-) create the profile with different colors for segments that were
 	// entered vs. segments that were calculated
 	double lastx = timeLine->posAtValue(0);
@@ -1379,7 +1355,7 @@ void DivePlannerPointsModel::remove(const QModelIndex &index)
 	endRemoveRows();
 }
 
-struct diveplan DivePlannerPointsModel::getDiveplan()
+struct diveplan& DivePlannerPointsModel::getDiveplan()\
 {
 	return diveplan;
 }
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 94fcdeb..a61f952 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -55,7 +55,7 @@ public:
 	void editStop(int row, divedatapoint newData);
 	divedatapoint at(int row);
 	int size();
-	struct diveplan getDiveplan();
+	struct diveplan& getDiveplan();
 	QStringList &getGasList();
 	QVector<QPair<int, int> > collectGases(dive *d);
 	int lastEnteredPoint();
@@ -276,4 +276,7 @@ private:
 	Ui::DivePlanner ui;
 };
 
+QString gasToStr(const int o2Permille, const int hePermille);
+QString dpGasToStr(const divedatapoint &p);
+
 #endif // DIVEPLANNER_H
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 33946f3..9b00db2 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -410,10 +410,11 @@ void MainWindow::on_actionAddDive_triggered()
 	ui.InfoWidget->updateDiveInfo(selected_dive);
 	ui.InfoWidget->addDiveStarted();
 	ui.infoPane->setCurrentIndex(MAINTAB);
+
+	ui.newProfile->setAddState();
 	DivePlannerPointsModel::instance()->clear();
 	DivePlannerPointsModel::instance()->createSimpleDive();
 	ui.ListWidget->reload(DiveTripModel::CURRENT);
-	ui.newProfile->setAddState();
 }
 
 void MainWindow::on_actionRenumber_triggered()
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 934ed6a..8596082 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -138,7 +138,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);
 	}
 }
@@ -343,6 +343,19 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
 	if (!d)
 		return;
 
+	//TODO: This is a temporary hack to help me understand the Planner.
+	// It seems that each time the 'createTemporaryPlan' runs, a new
+	// dive is created, and thus, we can plot that. hm...
+	if (currentState == ADD){
+		DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+		plannerModel->createTemporaryPlan();
+		if (!plannerModel->getDiveplan().dp) {
+			plannerModel->deleteTemporaryPlan();
+			return;
+		}
+	}
+	//END
+
 	int animSpeedBackup = -1;
 	if (firstCall && MainWindow::instance()->filesFromCommandLine()) {
 		animSpeedBackup = prefs.animation;
@@ -478,6 +491,12 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
 	if (MainWindow::instance()->filesFromCommandLine() && animSpeedBackup != -1) {
 		prefs.animation = animSpeedBackup;
 	}
+
+	if (currentState == ADD){ // TODO: figure a way to move this from here.
+		repositionDiveHandlers();
+		DivePlannerPointsModel *model = DivePlannerPointsModel::instance();
+		model->deleteTemporaryPlan();
+	}
 }
 
 void ProfileWidget2::settingsChanged()
@@ -644,11 +663,6 @@ void ProfileWidget2::setProfileState()
 	if (currentState == PROFILE)
 		return;
 
-	if (dive_table.nr == 0) { // oops, called to plot something with zero dives. bail out.
-		setEmptyState();
-		return;
-	}
-
 	disconnectTemporaryConnections();
 	currentState = PROFILE;
 	MainWindow::instance()->setToolButtonsEnabled(true);
@@ -709,7 +723,15 @@ void ProfileWidget2::setAddState()
 	if (currentState == ADD)
 		return;
 
+	setProfileState();
 	disconnectTemporaryConnections();
+	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+	connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot()));
+	connect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(replot()));
+	connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+		this, SLOT(pointInserted(const QModelIndex &, int, int)));
+	connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
+		this, SLOT(pointsRemoved(const QModelIndex &, int, int)));
 	/* show the same stuff that the profile shows. */
 	currentState = ADD; /* enable the add state. */
 	setBackgroundBrush(QColor(Qt::blue).light());
@@ -719,7 +741,7 @@ void ProfileWidget2::setPlanState()
 {
 	if (currentState == PLAN)
 		return;
-
+	setProfileState();
 	disconnectTemporaryConnections();
 	/* show the same stuff that the profile shows. */
 	currentState = PLAN; /* enable the add state. */
@@ -964,3 +986,24 @@ void ProfileWidget2::pointsRemoved(const QModelIndex &, int start, int end)
 	scene()->clearSelection();
 	replot();
 }
+
+void ProfileWidget2::repositionDiveHandlers()
+{
+	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+	// Re-position the user generated dive handlers
+	int last = 0;
+	for (int i = 0; i < plannerModel->rowCount(); i++) {
+		struct divedatapoint datapoint = plannerModel->at(i);
+		if (datapoint.time == 0) // those are the magic entries for tanks
+			continue;
+		DiveHandler *h = handles.at(i);
+		h->setPos(timeAxis->posAtValue(datapoint.time), profileYAxis->posAtValue(datapoint.depth));
+		QPointF p1 = (last == i) ? QPointF(timeAxis->posAtValue(0), profileYAxis->posAtValue(0)) : handles[last]->pos();
+		QPointF p2 = handles[i]->pos();
+		QLineF line(p1, p2);
+		QPointF pos = line.pointAt(0.5);
+		gases[i]->setPos(pos);
+		gases[i]->setText(dpGasToStr(plannerModel->at(i)));
+		last = i;
+	}
+}
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index 2ba1cd0..9b9802e 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -145,6 +145,7 @@ private:
 	//specifics for ADD and PLAN
 	QList<DiveHandler *> handles;
 	QList<QGraphicsSimpleTextItem *> gases;
+	void repositionDiveHandlers();
 };
 
 #endif // PROFILEWIDGET2_H
-- 
1.9.3

From 8983e329d0a2943dcfb750eeca647ff8db6dd595 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 21 May 2014 23:49:17 -0300
Subject: [PATCH 16/16] Good code cleanup on the old DivePlanner code.

All code that was removed already is working on the New Profile,
The code that's behind #if 0 means that it still need to be ported
and because of some removal, it was not possible to keep it
compiling ( mostly the removal of the Ruler class, that is the
Axis, on the new profile. )

The rest of the code that's untouched - most probably will keep
that way. the DivePlannerPointsModel is correct and well done,
no need to change that, only the Graphics part.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/diveplanner.cpp | 341 ++++----------------------------------------------
 qt-ui/diveplanner.h   |  37 ------
 2 files changed, 27 insertions(+), 351 deletions(-)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 08b172c..ec6d598 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -48,7 +48,6 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent
 	horizontalLine(new QGraphicsLineItem(fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(100, Qt::Horizontal), fromPercent(0, Qt::Vertical))),
 	activeDraggedHandler(0),
 	diveBg(new QGraphicsPolygonItem()),
-	timeLine(new Ruler()),
 	timeString(new QGraphicsSimpleTextItem()),
 	depthString(new QGraphicsSimpleTextItem()),
 	depthHandler(new ExpanderGraphics()),
@@ -68,36 +67,6 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent
 	horizontalLine->setPen(QPen(Qt::DotLine));
 	scene()->addItem(horizontalLine);
 
-	timeLine->setMinimum(0);
-	timeLine->setMaximum(TIME_INITIAL_MAX);
-	timeLine->setTickInterval(10);
-	timeLine->setColor(getColor(TIME_GRID));
-	timeLine->setLine(fromPercent(10, Qt::Horizontal),
-			  fromPercent(85, Qt::Vertical),
-			  fromPercent(90, Qt::Horizontal),
-			  fromPercent(85, Qt::Vertical));
-	timeLine->setOrientation(Qt::Horizontal);
-	timeLine->setTickSize(fromPercent(1, Qt::Vertical));
-	timeLine->setTextColor(getColor(TIME_TEXT));
-	timeLine->updateTicks();
-	scene()->addItem(timeLine);
-
-	depthLine = new Ruler();
-	depthLine->setMinimum(0);
-	depthLine->setMaximum(M_OR_FT(40, 120));
-	depthLine->setTickInterval(M_OR_FT(10, 30));
-	depthLine->setLine(fromPercent(10, Qt::Horizontal),
-			   fromPercent(10, Qt::Vertical),
-			   fromPercent(10, Qt::Horizontal),
-			   fromPercent(85, Qt::Vertical));
-	depthLine->setOrientation(Qt::Vertical);
-	depthLine->setTickSize(fromPercent(1, Qt::Horizontal));
-	depthLine->setColor(getColor(DEPTH_GRID));
-	depthLine->setTextColor(getColor(SAMPLE_DEEP));
-	depthLine->updateTicks();
-	depthLine->unitSystem = prefs.units.length;
-	scene()->addItem(depthLine);
-
 	timeString->setFlag(QGraphicsItem::ItemIgnoresTransformations);
 	timeString->setBrush(profile_color[TIME_TEXT].at(0));
 	scene()->addItem(timeString);
@@ -155,31 +124,11 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent
 
 void DivePlannerGraphics::settingsChanged()
 {
-	if (depthLine->unitSystem == prefs.units.length)
-		return;
-
-	depthLine->setTickInterval(M_OR_FT(10, 30));
-	depthLine->updateTicks();
-	depthLine->unitSystem = prefs.units.length;
-}
-
-void DivePlannerGraphics::pointInserted(const QModelIndex &parent, int start, int end)
-{
-	DiveHandler *item = new DiveHandler();
-	scene()->addItem(item);
-	handles << item;
-
-	QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem();
-	scene()->addItem(gasChooseBtn);
-	gasChooseBtn->setZValue(10);
-	gasChooseBtn->setFlag(QGraphicsItem::ItemIgnoresTransformations);
-	gases << gasChooseBtn;
-	if (plannerModel->recalcQ())
-		drawProfile();
 }
 
 void DivePlannerGraphics::keyDownAction()
 {
+#if 0
 	Q_FOREACH(QGraphicsItem * i, scene()->selectedItems()) {
 		if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
 			int row = handles.indexOf(handler);
@@ -191,10 +140,12 @@ void DivePlannerGraphics::keyDownAction()
 			plannerModel->editStop(row, dp);
 		}
 	}
+#endif
 }
 
 void DivePlannerGraphics::keyUpAction()
 {
+#if 0
 	Q_FOREACH(QGraphicsItem * i, scene()->selectedItems()) {
 		if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
 			int row = handles.indexOf(handler);
@@ -208,10 +159,12 @@ void DivePlannerGraphics::keyUpAction()
 		}
 	}
 	drawProfile();
+#endif
 }
 
 void DivePlannerGraphics::keyLeftAction()
 {
+#if 0
 	Q_FOREACH(QGraphicsItem * i, scene()->selectedItems()) {
 		if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
 			int row = handles.indexOf(handler);
@@ -237,10 +190,12 @@ void DivePlannerGraphics::keyLeftAction()
 			plannerModel->editStop(row, dp);
 		}
 	}
+#endif
 }
 
 void DivePlannerGraphics::keyRightAction()
 {
+#if 0
 	Q_FOREACH(QGraphicsItem * i, scene()->selectedItems()) {
 		if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
 			int row = handles.indexOf(handler);
@@ -265,10 +220,12 @@ void DivePlannerGraphics::keyRightAction()
 			plannerModel->editStop(row, dp);
 		}
 	}
+#endif
 }
 
 void DivePlannerGraphics::keyDeleteAction()
 {
+#if 0
 	int selCount = scene()->selectedItems().count();
 	if (selCount) {
 		QVector<int> selectedIndexes;
@@ -279,20 +236,9 @@ void DivePlannerGraphics::keyDeleteAction()
 		}
 		plannerModel->removeSelectedPoints(selectedIndexes);
 	}
+#endif
 }
 
-void DivePlannerGraphics::pointsRemoved(const QModelIndex &, int start, int end)
-{ // start and end are inclusive.
-	int num = (end - start) + 1;
-	for (int i = num; i != 0; i--) {
-		delete handles.back();
-		handles.pop_back();
-		delete gases.back();
-		gases.pop_back();
-	}
-	scene()->clearSelection();
-	drawProfile();
-}
 
 bool intLessThan(int a, int b)
 {
@@ -329,24 +275,29 @@ qreal DivePlannerGraphics::fromPercent(qreal percent, Qt::Orientation orientatio
 
 void DivePlannerGraphics::increaseDepth()
 {
+#if 0
 	if (depthLine->maximum() + M_OR_FT(10, 30) > MAX_DEPTH)
 		return;
 	minDepth += M_OR_FT(10, 30);
 	depthLine->setMaximum(minDepth);
 	depthLine->updateTicks();
 	drawProfile();
+#endif
 }
 
 void DivePlannerGraphics::increaseTime()
 {
+#if 0
 	minMinutes += 10;
 	timeLine->setMaximum(minMinutes);
 	timeLine->updateTicks();
 	drawProfile();
+#endif
 }
 
 void DivePlannerGraphics::decreaseDepth()
 {
+#if 0
 	if (depthLine->maximum() - M_OR_FT(10, 30) < MIN_DEPTH)
 		return;
 
@@ -363,10 +314,12 @@ void DivePlannerGraphics::decreaseDepth()
 	depthLine->setMaximum(minDepth);
 	depthLine->updateTicks();
 	drawProfile();
+#endif
 }
 
 void DivePlannerGraphics::decreaseTime()
 {
+#if 0
 	if (timeLine->maximum() - 10 < TIME_INITIAL_MAX || timeLine->maximum() - 10 < dpMaxTime)
 		return;
 
@@ -374,17 +327,7 @@ void DivePlannerGraphics::decreaseTime()
 	timeLine->setMaximum(timeLine->maximum() - 10);
 	timeLine->updateTicks();
 	drawProfile();
-}
-
-void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent *event)
-{
-	QPointF mappedPos = mapToScene(event->pos());
-	if (isPointOutOfBoundaries(mappedPos))
-		return;
-
-	int minutes = rint(timeLine->valueAt(mappedPos));
-	int milimeters = rint(depthLine->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
-	plannerModel->addStop(milimeters, minutes * 60, -1, 0, 0, true);
+#endif
 }
 
 void DivePlannerPointsModel::createSimpleDive()
@@ -465,85 +408,13 @@ void DivePlannerPointsModel::removeDeco()
 
 void DivePlannerGraphics::drawProfile()
 {
-	if (!plannerModel->recalcQ())
-		return;
-	qDeleteAll(lines);
-	lines.clear();
-
-	plannerModel->createTemporaryPlan();
-	struct diveplan diveplan = plannerModel->getDiveplan();
-	struct divedatapoint *dp = diveplan.dp;
-	unsigned int max_depth = 0;
-
-	if (!dp) {
-		plannerModel->deleteTemporaryPlan();
-		return;
-	}
-	//TODO: divedatapoint_list_get_max_depth on C - code?
-	while (dp->next) {
-		if (dp->time && dp->depth > max_depth)
-			max_depth = dp->depth;
-		dp = dp->next;
-	}
-
-	if (!activeDraggedHandler && (timeLine->maximum() < dp->time / 60.0 + 5 || dp->time / 60.0 + 15 < timeLine->maximum())) {
-		minMinutes = fmax(dp->time / 60.0 + 5, minMinutes);
-		timeLine->setMaximum(minMinutes);
-		timeLine->updateTicks();
-	}
-	if (!activeDraggedHandler && (depthLine->maximum() < max_depth + M_OR_FT(10, 30) || max_depth + M_OR_FT(10, 30) < depthLine->maximum())) {
-		minDepth = fmax(max_depth + M_OR_FT(10, 30), minDepth);
-		depthLine->setMaximum(minDepth);
-		depthLine->updateTicks();
-	}
-
-	// (re-) create the profile with different colors for segments that were
-	// entered vs. segments that were calculated
-	double lastx = timeLine->posAtValue(0);
-	double lasty = depthLine->posAtValue(0);
-
-	QPolygonF poly;
-	poly.append(QPointF(lastx, lasty));
-
+	// Code ported to the new profile is deleted. This part that I left here
+	// is because I didn't fully understood the reason of the magic with
+	// the plannerModel.
 	bool oldRecalc = plannerModel->setRecalc(false);
 	plannerModel->removeDeco();
-
-	unsigned int lastdepth = 0;
-	for (dp = diveplan.dp; dp != NULL; dp = dp->next) {
-		if (dp->time == 0) // magic entry for available tank
-			continue;
-		double xpos = timeLine->posAtValue(dp->time / 60.0);
-		double ypos = depthLine->posAtValue(dp->depth);
-		if (!dp->entered) {
-			QGraphicsLineItem *item = new QGraphicsLineItem(lastx, lasty, xpos, ypos);
-			item->setPen(QPen(QBrush(Qt::red), 0));
-
-			scene()->addItem(item);
-			lines << item;
-			if (dp->depth) {
-				if (dp->depth == lastdepth || dp->o2 != dp->next->o2 || dp->he != dp->next->he)
-					plannerModel->addStop(dp->depth, dp->time, dp->next->o2, dp->next->he, 0, false);
-				lastdepth = dp->depth;
-			}
-		}
-		lastx = xpos;
-		lasty = ypos;
-		poly.append(QPointF(lastx, lasty));
-	}
+	// Here we plotted the old planner profile. why there's the magic with the plannerModel here?
 	plannerModel->setRecalc(oldRecalc);
-
-	diveBg->setPolygon(poly);
-	QRectF b = poly.boundingRect();
-	QLinearGradient pat(
-	    b.x(),
-	    b.y(),
-	    b.x(),
-	    b.height() + b.y());
-
-	pat.setColorAt(1, profile_color[DEPTH_BOTTOM].first());
-	pat.setColorAt(0, profile_color[DEPTH_TOP].first());
-	diveBg->setBrush(pat);
-
 	plannerModel->deleteTemporaryPlan();
 }
 
@@ -559,11 +430,12 @@ void DivePlannerGraphics::showEvent(QShowEvent *event)
 	fitInView(sceneRect(), Qt::IgnoreAspectRatio);
 }
 
+
 void DivePlannerGraphics::mouseMoveEvent(QMouseEvent *event)
 {
 	QPointF mappedPos = mapToScene(event->pos());
 
-
+#if 0
 	double xpos = timeLine->valueAt(mappedPos);
 	double ypos = depthLine->valueAt(mappedPos);
 
@@ -605,10 +477,12 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent *event)
 		verticalLine->setPen(QPen(Qt::DotLine));
 		horizontalLine->setPen(QPen(Qt::DotLine));
 	}
+#endif
 }
 
 void DivePlannerGraphics::moveActiveHandler(const QPointF &mappedPos, const int pos)
 {
+#if 0
 	divedatapoint data = plannerModel->at(pos);
 	int mintime = 0, maxtime = (timeLine->maximum() + 10) * 60;
 	if (pos > 0)
@@ -633,20 +507,7 @@ void DivePlannerGraphics::moveActiveHandler(const QPointF &mappedPos, const int
 	qDeleteAll(lines);
 	lines.clear();
 	drawProfile();
-}
-
-bool DivePlannerGraphics::isPointOutOfBoundaries(const QPointF &point)
-{
-	double xpos = timeLine->valueAt(point);
-	double ypos = depthLine->valueAt(point);
-
-	if (xpos > timeLine->maximum() ||
-	    xpos < timeLine->minimum() ||
-	    ypos > depthLine->maximum() ||
-	    ypos < depthLine->minimum()) {
-		return true;
-	}
-	return false;
+#endif
 }
 
 void DivePlannerGraphics::mousePressEvent(QMouseEvent *event)
@@ -743,154 +604,6 @@ void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
 	ungrabKeyboard();
 }
 
-void Ruler::setMaximum(double maximum)
-{
-	max = maximum;
-}
-
-void Ruler::setMinimum(double minimum)
-{
-	min = minimum;
-}
-
-void Ruler::setTextColor(const QColor &color)
-{
-	textColor = color;
-}
-
-void Ruler::eraseAll()
-{
-	qDeleteAll(ticks);
-	ticks.clear();
-	qDeleteAll(labels);
-	labels.clear();
-}
-
-Ruler::Ruler() : unitSystem(0),
-	orientation(Qt::Horizontal),
-	min(0),
-	max(0),
-	interval(0),
-	tickSize(0)
-{
-}
-
-Ruler::~Ruler()
-{
-	eraseAll();
-}
-
-void Ruler::setOrientation(Qt::Orientation o)
-{
-	orientation = o;
-	// position the elements on the screen.
-	setMinimum(minimum());
-	setMaximum(maximum());
-}
-
-void Ruler::updateTicks()
-{
-	eraseAll();
-
-	QLineF m = line();
-	QGraphicsLineItem *item = NULL;
-	QGraphicsSimpleTextItem *label = NULL;
-
-	double steps = (max - min) / interval;
-	qreal pos;
-	double currValue = min;
-
-	if (orientation == Qt::Horizontal) {
-		double stepSize = (m.x2() - m.x1()) / steps;
-		for (pos = m.x1(); pos <= m.x2(); pos += stepSize, currValue += interval) {
-			item = new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this);
-			item->setPen(pen());
-			ticks.push_back(item);
-
-			label = new QGraphicsSimpleTextItem(QString::number(currValue), this);
-			label->setBrush(QBrush(textColor));
-			label->setFlag(ItemIgnoresTransformations);
-			label->setPos(pos - label->boundingRect().width() / 2, m.y1() + tickSize + 5);
-			labels.push_back(label);
-		}
-	} else {
-		double stepSize = (m.y2() - m.y1()) / steps;
-		for (pos = m.y1(); pos <= m.y2(); pos += stepSize, currValue += interval) {
-			item = new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this);
-			item->setPen(pen());
-			ticks.push_back(item);
-
-			label = new QGraphicsSimpleTextItem(get_depth_string(currValue, false, false), this);
-			label->setBrush(QBrush(textColor));
-			label->setFlag(ItemIgnoresTransformations);
-			label->setPos(m.x2() - 80, pos);
-			labels.push_back(label);
-		}
-	}
-}
-
-void Ruler::setTickSize(qreal size)
-{
-	tickSize = size;
-}
-
-void Ruler::setTickInterval(double i)
-{
-	interval = i;
-}
-
-qreal Ruler::valueAt(const QPointF &p)
-{
-	QLineF m = line();
-	double retValue = orientation == Qt::Horizontal ?
-			      max * (p.x() - m.x1()) / (m.x2() - m.x1()) :
-			      max * (p.y() - m.y1()) / (m.y2() - m.y1());
-	return retValue;
-}
-
-qreal Ruler::posAtValue(qreal value)
-{
-	QLineF m = line();
-	double size = max - min;
-	double percent = value / size;
-	double realSize = orientation == Qt::Horizontal ?
-			      m.x2() - m.x1() :
-			      m.y2() - m.y1();
-	double retValue = realSize * percent;
-	retValue = (orientation == Qt::Horizontal) ?
-		       retValue + m.x1() :
-		       retValue + m.y1();
-	return retValue;
-}
-
-qreal Ruler::percentAt(const QPointF &p)
-{
-	qreal value = valueAt(p);
-	double size = max - min;
-	double percent = value / size;
-	return percent;
-}
-
-double Ruler::maximum() const
-{
-	return max;
-}
-
-double Ruler::minimum() const
-{
-	return min;
-}
-
-void Ruler::setColor(const QColor &color)
-{
-	QPen defaultPen(color);
-	defaultPen.setJoinStyle(Qt::RoundJoin);
-	defaultPen.setCapStyle(Qt::RoundCap);
-	defaultPen.setWidth(2);
-	defaultPen.setCosmetic(true);
-	setPen(defaultPen);
-}
-
 Button::Button(QObject *parent, QGraphicsItem *itemParent) : QObject(parent),
 	QGraphicsRectItem(itemParent),
 	icon(new QGraphicsPixmapItem(this)),
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index a61f952..24f01c6 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -150,45 +150,12 @@ slots:
 	void changeGas();
 };
 
-class Ruler : public QGraphicsLineItem {
-public:
-	Ruler();
-	~Ruler();
-	void setMinimum(double minimum);
-	void setMaximum(double maximum);
-	void setTickInterval(double interval);
-	void setOrientation(Qt::Orientation orientation);
-	void setTickSize(qreal size);
-	void updateTicks();
-	double minimum() const;
-	double maximum() const;
-	qreal valueAt(const QPointF &p);
-	qreal percentAt(const QPointF &p);
-	qreal posAtValue(qreal value);
-	void setColor(const QColor &color);
-	void setTextColor(const QColor &color);
-	int unitSystem;
-
-private:
-	void eraseAll();
-
-	Qt::Orientation orientation;
-	QList<QGraphicsLineItem *> ticks;
-	QList<QGraphicsSimpleTextItem *> labels;
-	double min;
-	double max;
-	double interval;
-	double tickSize;
-	QColor textColor;
-};
-
 class DivePlannerGraphics : public QGraphicsView {
 	Q_OBJECT
 public:
 	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);
@@ -212,8 +179,6 @@ slots:
 	void decreaseTime();
 	void decreaseDepth();
 	void drawProfile();
-	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);
@@ -240,11 +205,9 @@ private:
 	QGraphicsPolygonItem *diveBg;
 
 	/* This is the bottom ruler - the x axis, and it's associated text */
-	Ruler *timeLine;
 	QGraphicsSimpleTextItem *timeString;
 
 	/* this is the left ruler, the y axis, and it's associated text. */
-	Ruler *depthLine;
 	QGraphicsSimpleTextItem *depthString;
 
 	/* Buttons */
-- 
1.9.3

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to