More three to the spree.
This adds the grid on the canvas

( I thought I had committed this yesterday.)
People,

This is safe to merge on master since it doesn't breaks anything, but
instead, adds two new widgets on debug mode, and one widget on release
mode. it's a 30 commit - step - by - step code on how I envision the new
profile system.

there are , of course a lot of new things to do here till it's feature -
pair with the old profile, but I really think that it's easier to work on
this new profile regarding adding or removing functionality than the old
one.

Tomaz
From 5f614535e988f704e8a5709e4f3531381004f4b8 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 15 Jan 2014 18:03:58 -0200
Subject: [PATCH 31/33] Use the same methods than the old profile to discover
 the boundaries.

This method gather information about the max and minimum sizes of
the cartesian axis that we should plot. It's still a bit cumberstone
for my taste, but this shouldn't be a problem. I think we need to
rework the 'Zoomed' version of it, since zoom or without zoom,
we should be good to go using the QGraphicsView.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/profilewidget2.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 68b42f1..8646e24 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -250,10 +250,12 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
 	 * shown.
 	 */
 	struct plot_info pInfo = calculate_max_limits_new(d, currentdc);
+	int maxtime = get_maxtime(&pInfo);
+	int maxdepth = get_maxdepth(&pInfo);
 
-	profileYAxis->setMaximum(pInfo.maxdepth);
+	profileYAxis->setMaximum(qMax<long>(pInfo.maxdepth + M_OR_FT(10,30), maxdepth * 2 / 3));
 	profileYAxis->updateTicks();
-	timeAxis->setMaximum(pInfo.maxtime);
+	timeAxis->setMaximum(maxtime);
 	timeAxis->updateTicks();
 	dataModel->setDive(current_dive, pInfo);
 
-- 
1.8.5.3

From 1f707a7496f7e8c9e90f0e7c75711dea30901b13 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 15 Jan 2014 18:13:20 -0200
Subject: [PATCH 32/33] The plot-profile method was being called too many
 times.

There was a bug in the old implementation where we needed to
trigger a repaint of the profile almost everywhere. this isn't
needed anymore on the new one, so do not use the same method
that will be killed when I finish this.e

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/mainwindow.cpp             | 11 ++++++-----
 qt-ui/profile/profilewidget2.cpp | 14 ++++++++------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 10f2355..4b25640 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -92,18 +92,19 @@ void MainWindow::current_dive_changed(int divenr)
 		ui.globe->centerOn(get_dive(selected_dive));
 	}
 	redrawProfile();
-	ui.InfoWidget->updateDiveInfo(divenr);
-}
 
-void MainWindow::redrawProfile()
-{
-	ui.ProfileWidget->refresh();
 	/* It looks like it's a bit too cumberstone to send *one* dive using a QList,
 	 * but this is just futureproofness, it's the best way in the future to show more than
 	 * a single profile plot on the canvas. I know that we are using only one right now,
 	 * but let's keep like this so it's easy to change when we need? :)
 	 */
 	ui.graphicsView->plotDives( QList<dive*>() << (current_dive) );
+	ui.InfoWidget->updateDiveInfo(divenr);
+}
+
+void MainWindow::redrawProfile()
+{
+	ui.ProfileWidget->refresh();
 }
 
 void MainWindow::on_actionNew_triggered()
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 8646e24..ef6ec71 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -12,6 +12,7 @@
 #include <QPropertyAnimation>
 #include <QMenu>
 #include <QContextMenuEvent>
+#include <QDebug>
 
 #ifndef QT_NO_DEBUG
 #include <QTableView>
@@ -235,6 +236,7 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
 	if(!d)
 		return;
 
+	qDebug() << "Calling";
 	// Here we need to probe for the limits of the dive.
 	// There's already a function that does exactly that,
 	// but it's using the graphics context, and I need to
@@ -296,12 +298,12 @@ void ProfileWidget2::resizeEvent(QResizeEvent* event)
 	QGraphicsView::resizeEvent(event);
 	fitInView(sceneRect(), Qt::IgnoreAspectRatio);
 
-	if(!stateMachine->configuration().count())
-		return;
-
-	if ((*stateMachine->configuration().begin())->objectName() == "Empty State"){
-		fixBackgroundPos();
-	}
+// 	if(!stateMachine->configuration().count())
+// 		return;
+//
+// 	if ((*stateMachine->configuration().begin())->objectName() == "Empty State"){
+// 		fixBackgroundPos();
+// 	}
 }
 
 void ProfileWidget2::fixBackgroundPos()
-- 
1.8.5.3

From dd2e8a2f9d4002dd700145bb303cc8a2b901c319 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 15 Jan 2014 20:16:31 -0200
Subject: [PATCH 33/33] Started the code for a Grid that knows how to handle
 itself

The code for this item is a bit too big to be just the grid
of the dives and I know that, don't bully me. :)
The main idea of this grid is that it knows when it should be
updated. this is a bit different than the old code where all
the painting happened on the same method. This is bad because
it's more code, but it's better because if I break the grid,
only the grid will be broken, and it's easyer to spot the breakage.

in the old code if I did the wrong thing with the graphics context,
the whole graph gots messed out.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/divecartesianaxis.cpp | 85 ++++++++++++++++++++++++++++++++++++-
 qt-ui/profile/divecartesianaxis.h   | 26 ++++++++++++
 qt-ui/profile/profilewidget2.cpp    | 12 +++++-
 qt-ui/profile/profilewidget2.h      |  2 +
 4 files changed, 122 insertions(+), 3 deletions(-)

diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp
index a121754..187ff25 100644
--- a/qt-ui/profile/divecartesianaxis.cpp
+++ b/qt-ui/profile/divecartesianaxis.cpp
@@ -13,11 +13,13 @@
 void DiveCartesianAxis::setMaximum(double maximum)
 {
 	max = maximum;
+	emit sizeChanged();
 }
 
 void DiveCartesianAxis::setMinimum(double minimum)
 {
 	min = minimum;
+	emit sizeChanged();
 }
 
 void DiveCartesianAxis::setTextColor(const QColor& color)
@@ -187,4 +189,85 @@ QString DepthAxis::textForValue(double value)
 QString TimeAxis::textForValue(double value)
 {
     return QString::number(value / 60);
-}
\ No newline at end of file
+}
+
+void DiveCartesianPlane::setLeftAxis(DiveCartesianAxis* axis)
+{
+	leftAxis = axis;
+	connect(leftAxis, SIGNAL(sizeChanged()), this, SLOT(setup()));
+	if(bottomAxis)
+		setup();
+}
+
+void DiveCartesianPlane::setBottomAxis(DiveCartesianAxis* axis)
+{
+	bottomAxis = axis;
+	connect(bottomAxis, SIGNAL(sizeChanged()), this, SLOT(setup()));
+	if(leftAxis)
+		setup();
+}
+
+QLineF DiveCartesianPlane::horizontalLine() const
+{
+	return (bottomAxis) ? bottomAxis->line() : QLineF() ;
+}
+
+void DiveCartesianPlane::setHorizontalLine(QLineF line)
+{
+	if( horizontalSize == line.length())
+		return;
+	horizontalSize = line.length();
+	setup();
+}
+
+void DiveCartesianPlane::setVerticalLine(QLineF line)
+{
+	if(verticalSize == line.length())
+		return;
+	verticalSize = line.length();
+	setup();
+}
+
+QLineF DiveCartesianPlane::verticalLine() const
+{
+	return (leftAxis) ? leftAxis->line() : QLineF() ;
+}
+
+void DiveCartesianPlane::setup()
+{
+	if(!leftAxis || !bottomAxis || !scene())
+		return;
+
+	// This creates a Grid around the axis, creating the cartesian plane.
+	const int top = leftAxis->posAtValue(leftAxis->minimum());
+	const int bottom = leftAxis->posAtValue(leftAxis->maximum());
+	const int left = bottomAxis->posAtValue(bottomAxis->minimum());
+	const int right = bottomAxis->posAtValue(bottomAxis->maximum());
+
+	setRect(0, 0, horizontalSize, verticalSize);
+	setPos(left, top);
+
+	qDeleteAll(horizontalLines);
+	qDeleteAll(verticalLines);
+	horizontalLines.clear();
+	verticalLines.clear();
+
+	// DEPTH is M_OR_FEET(10,30), Minutes are 600, per line.
+	for(int i = leftAxis->minimum(), max = leftAxis->maximum(); i < max; i += M_OR_FT(10,30)){
+		DiveLineItem *line = new DiveLineItem();
+		line->setLine(0, 0, horizontalSize, 0);
+		line->setPos(left,leftAxis->posAtValue(i));
+		line->setZValue(-1);
+		horizontalLines.push_back(line);
+		scene()->addItem(line);
+	}
+
+	for(int i = bottomAxis->minimum(), max = bottomAxis->maximum(); i < max; i += 600){ // increments by 10 minutes.
+		DiveLineItem *line = new DiveLineItem();
+		line->setLine(0, 0, 0, verticalSize);
+		line->setPos(bottomAxis->posAtValue(i), top);
+		line->setZValue(-1);
+		verticalLines.push_back(line);
+		scene()->addItem(line);
+	}
+}
diff --git a/qt-ui/profile/divecartesianaxis.h b/qt-ui/profile/divecartesianaxis.h
index d6a60d3..01e4a68 100644
--- a/qt-ui/profile/divecartesianaxis.h
+++ b/qt-ui/profile/divecartesianaxis.h
@@ -29,6 +29,8 @@ public:
 	void setColor(const QColor& color);
 	void setTextColor(const QColor& color);
 	int unitSystem;
+signals:
+	void sizeChanged();
 
 protected:
 	virtual QString textForValue(double value);
@@ -52,4 +54,28 @@ class TimeAxis : public DiveCartesianAxis {
 protected:
     QString textForValue(double value);
 };
+
+// This is a try. Maybe the CartesianPlane should have the X and Y
+// axis and handle things internally?
+class DiveCartesianPlane :public QObject, public QGraphicsRectItem{
+	Q_OBJECT
+	Q_PROPERTY(QLineF verticalLine READ verticalLine WRITE setVerticalLine)
+	Q_PROPERTY(QLineF horizontalLine READ horizontalLine WRITE setHorizontalLine)
+public:
+	void setLeftAxis(DiveCartesianAxis *axis);
+	void setBottomAxis(DiveCartesianAxis *axis);
+	void setHorizontalLine(QLineF line);
+	void setVerticalLine(QLineF line);
+	QLineF horizontalLine() const;
+	QLineF verticalLine() const;
+public slots:
+	void setup();
+private:
+	DiveCartesianAxis *leftAxis;
+	DiveCartesianAxis *bottomAxis;
+	QList<DiveLineItem*> verticalLines;
+	QList<DiveLineItem*> horizontalLines;
+	qreal verticalSize;
+	qreal horizontalSize;
+};
 #endif
\ No newline at end of file
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index ef6ec71..0462e91 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -30,7 +30,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
 	timeAxis(new TimeAxis()),
 	depthController(new DiveRectItem()),
 	timeController(new DiveRectItem()),
-	diveProfileItem(new DiveProfileItem())
+	diveProfileItem(new DiveProfileItem()),
+	cartesianPlane(new DiveCartesianPlane())
 {
 	setScene(new QGraphicsScene());
 	scene()->setSceneRect(0, 0, 100, 100);
@@ -65,6 +66,10 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
 	timeController->setRect(0, 0, 10, 5);
 	timeController->setX(sceneRect().width() - timeController->boundingRect().width()); // Position it on the right spot.
 
+	cartesianPlane->setBottomAxis(timeAxis);
+	cartesianPlane->setLeftAxis(profileYAxis);
+	scene()->addItem(cartesianPlane);
+
 	// insert in the same way it's declared on the Enum. This is needed so we don't use an map.
 	QList<QGraphicsItem*> stateItems; stateItems << background << profileYAxis << gasYAxis
 		<< timeAxis << depthController << timeController;
@@ -155,6 +160,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
 	profileState->assignProperty(timeAxis, "y", timeAxisOnCanvas);
 	profileState->assignProperty(depthController, "y", depthControllerOffCanvas);
 	profileState->assignProperty(timeController, "y", timeControllerOffCanvas);
+	profileState->assignProperty(cartesianPlane, "verticalLine", profileYAxisExpanded);
+	profileState->assignProperty(cartesianPlane, "horizontalLine", timeAxis->line());
 
 	// Edit, everything but the background and gasYAxis are shown.
 	editState->assignProperty(this, "backgroundBrush", QBrush(Qt::darkGray));
@@ -236,7 +243,6 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
 	if(!d)
 		return;
 
-	qDebug() << "Calling";
 	// Here we need to probe for the limits of the dive.
 	// There's already a function that does exactly that,
 	// but it's using the graphics context, and I need to
@@ -273,6 +279,8 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
 	diveProfileItem->setVerticalDataColumn(DivePlotDataModel::DEPTH);
 	diveProfileItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
 	scene()->addItem(diveProfileItem);
+
+	cartesianPlane->setup();
 	emit startProfileState();
 }
 
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index eaad66f..edc5caa 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -23,6 +23,7 @@ struct DiveProfileItem;
 struct TimeAxis;
 struct dive;
 struct QStateMachine;
+struct DiveCartesianPlane;
 
 class ProfileWidget2 : public QGraphicsView {
 	Q_OBJECT
@@ -55,6 +56,7 @@ private:
 	State currentState;
 	QStateMachine *stateMachine;
 
+	DiveCartesianPlane *cartesianPlane;
 	DivePixmapItem *background ;
 	DepthAxis *profileYAxis ;
 	DiveCartesianAxis *gasYAxis;
-- 
1.8.5.3

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

Reply via email to