\o/

On Mon, Aug 25, 2014 at 5:01 PM, Tomaz Canabrava <[email protected]> wrote:

> so, this whole set of patches does: almost nothing, it's the beginning of
> the work for the new statistics pane.
> It's *safe* to merge, won't break anything, it will actually clear quite a
> bit of code.
> the new white part of the statistics widget is the new one that I'm
> working with, the bottom part is the old one.
>
>
>
From cfdb2f7c24ec6a42d303c7ffd53bcd5c09301e48 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Mon, 25 Aug 2014 17:48:32 -0300
Subject: [PATCH 10/12] Add stub of the "YearlyStatisticsItem" on the new
 Statistics

This YearlyStatisticsItem is the concentration of information
for a single year, and inside of it there will be informations
for months. Everything is a stub now - so the graphics are
still blank.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/statistics/statisticswidget.cpp | 12 ++++++++++++
 qt-ui/statistics/statisticswidget.h   |  3 +++
 qt-ui/statistics/yearstatistics.cpp   | 10 ++++++++++
 qt-ui/statistics/yearstatistics.h     | 18 ++++++++++++++++++
 4 files changed, 43 insertions(+)

diff --git a/qt-ui/statistics/statisticswidget.cpp b/qt-ui/statistics/statisticswidget.cpp
index 4adb122..294cb07 100644
--- a/qt-ui/statistics/statisticswidget.cpp
+++ b/qt-ui/statistics/statisticswidget.cpp
@@ -1,5 +1,6 @@
 #include "statisticswidget.h"
 #include "models.h"
+#include "yearstatistics.h"
 #include <QModelIndex>
 
 YearlyStatisticsWidget::YearlyStatisticsWidget(QWidget *parent): QGraphicsView(parent)
@@ -30,6 +31,17 @@ void YearlyStatisticsWidget::setModel(YearlyStatisticsModel *m)
 
 void YearlyStatisticsWidget::modelRowsInserted(const QModelIndex &index, int first, int last)
 {
+	for(int i = 0; i < m_model->rowCount(); i++){
+		QModelIndex yearIndex = m_model->index(i,0);
+		YearlyStatisticsItem *year = new YearlyStatisticsItem(m_model, i, this);
+		scene()->addItem(year);
+	}
+	doLayout();
+}
+
+void YearlyStatisticsWidget::doLayout()
+{
+	// correctly place the items on screen, animating them.
 	// stub
 }
 
diff --git a/qt-ui/statistics/statisticswidget.h b/qt-ui/statistics/statisticswidget.h
index ae98829..b862ccc 100644
--- a/qt-ui/statistics/statisticswidget.h
+++ b/qt-ui/statistics/statisticswidget.h
@@ -5,9 +5,11 @@
 
 class YearlyStatisticsModel;
 class QModelIndex;
+class YearStatisticsItem;
 
 class YearlyStatisticsWidget : public QGraphicsView {
 	Q_OBJECT
+	void doLayout();
 public:
 	YearlyStatisticsWidget(QWidget *parent = 0);
 	void setModel(YearlyStatisticsModel *m);
@@ -18,6 +20,7 @@ public slots:
 	void modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
 private:
 	YearlyStatisticsModel *m_model;
+	QList<YearStatisticsItem*> m_years;
 };
 
 #endif
\ No newline at end of file
diff --git a/qt-ui/statistics/yearstatistics.cpp b/qt-ui/statistics/yearstatistics.cpp
index e69de29..db04889 100644
--- a/qt-ui/statistics/yearstatistics.cpp
+++ b/qt-ui/statistics/yearstatistics.cpp
@@ -0,0 +1,10 @@
+#include "yearstatistics.h"
+#include "statisticswidget.h"
+#include "models.h"
+
+YearlyStatisticsItem::YearlyStatisticsItem(YearlyStatisticsModel *m, int row, YearlyStatisticsWidget *parent) :
+	QObject(parent),
+	model(m),
+	row(row)
+{
+}
diff --git a/qt-ui/statistics/yearstatistics.h b/qt-ui/statistics/yearstatistics.h
index e69de29..24e1eb1 100644
--- a/qt-ui/statistics/yearstatistics.h
+++ b/qt-ui/statistics/yearstatistics.h
@@ -0,0 +1,18 @@
+#ifndef YEARLYSTATISTICSITEM_H
+#define YEARLYSTATISTICSITEM_H
+
+#include <QGraphicsRectItem>
+
+class YearlyStatisticsModel;
+class YearlyStatisticsWidget;
+
+class YearlyStatisticsItem : public QObject, public QGraphicsRectItem {
+	Q_OBJECT
+public:
+	explicit YearlyStatisticsItem(YearlyStatisticsModel *m, int row, YearlyStatisticsWidget *parent = 0);
+private:
+	YearlyStatisticsModel *model;
+	int row;
+};
+
+#endif
\ No newline at end of file
-- 
2.1.0

From fe0c4c651221033b36be08a183271af1f86c40d5 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Mon, 25 Aug 2014 18:26:13 -0300
Subject: [PATCH 11/12] Prepare the data to be displayed

This commit I add the fetching of the data, it's not yet
visible, that will start in the next commit.
This commit I prepare all data in the model to be used
in  "years" and "months". There's one issue with this code:
The last model is by trips, so I'll need to come with a better way for that.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/statistics/yearstatistics.cpp | 40 +++++++++++++++++++++++++++++++++++++
 qt-ui/statistics/yearstatistics.h   | 20 +++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/qt-ui/statistics/yearstatistics.cpp b/qt-ui/statistics/yearstatistics.cpp
index db04889..ade918c 100644
--- a/qt-ui/statistics/yearstatistics.cpp
+++ b/qt-ui/statistics/yearstatistics.cpp
@@ -7,4 +7,44 @@ YearlyStatisticsItem::YearlyStatisticsItem(YearlyStatisticsModel *m, int row, Ye
 	model(m),
 	row(row)
 {
+	// Full View
+	time.min = m->index(row, YearlyStatisticsModel::SHORTEST_TIME).data().toInt();
+	time.avg = m->index(row, YearlyStatisticsModel::AVERAGE_TIME).data().toInt();
+	time.max = m->index(row, YearlyStatisticsModel::LONGEST_TIME).data().toInt();
+
+	depth.min = m->index(row, YearlyStatisticsModel::MIN_DEPTH).data().toInt();
+	depth.avg = m->index(row, YearlyStatisticsModel::AVG_DEPTH).data().toInt();
+	depth.max = m->index(row, YearlyStatisticsModel::MAX_DEPTH).data().toInt();
+
+	sac.min = m->index(row, YearlyStatisticsModel::MIN_SAC).data().toInt();
+	sac.avg = m->index(row, YearlyStatisticsModel::AVG_SAC).data().toInt();
+	sac.max = m->index(row, YearlyStatisticsModel::MAX_SAC).data().toInt();
+
+	temp.min = m->index(row, YearlyStatisticsModel::MIN_TEMP).data().toInt();
+	temp.avg = m->index(row, YearlyStatisticsModel::AVG_TEMP).data().toInt();
+	temp.max = m->index(row, YearlyStatisticsModel::MAX_TEMP).data().toInt();
+
+	// Create the detailed view.
+	for(int i = 0; i < 12; i++){ // months.
+		Value time2, depth2, sac2, temp2;
+		time2.min = m->index(row, YearlyStatisticsModel::SHORTEST_TIME).data().toInt();
+		time2.avg = m->index(row, YearlyStatisticsModel::AVERAGE_TIME).data().toInt();
+		time2.max = m->index(row, YearlyStatisticsModel::LONGEST_TIME).data().toInt();
+		monthsTime.push_back(time2);
+
+		depth2.min = m->index(row, YearlyStatisticsModel::MIN_DEPTH).data().toInt();
+		depth2.avg = m->index(row, YearlyStatisticsModel::AVG_DEPTH).data().toInt();
+		depth2.max = m->index(row, YearlyStatisticsModel::MAX_DEPTH).data().toInt();
+		monthsDepth.push_back(depth2);
+
+		sac2.min = m->index(row, YearlyStatisticsModel::MIN_SAC).data().toInt();
+		sac2.avg = m->index(row, YearlyStatisticsModel::AVG_SAC).data().toInt();
+		sac2.max = m->index(row, YearlyStatisticsModel::MAX_SAC).data().toInt();
+		monthsSac.push_back(sac2);
+
+		temp2.min = m->index(row, YearlyStatisticsModel::MIN_TEMP).data().toInt();
+		temp2.avg = m->index(row, YearlyStatisticsModel::AVG_TEMP).data().toInt();
+		temp2.max = m->index(row, YearlyStatisticsModel::MAX_TEMP).data().toInt();
+		monthsTemp.push_back(temp2);
+	}
 }
diff --git a/qt-ui/statistics/yearstatistics.h b/qt-ui/statistics/yearstatistics.h
index 24e1eb1..1b2f8a4 100644
--- a/qt-ui/statistics/yearstatistics.h
+++ b/qt-ui/statistics/yearstatistics.h
@@ -6,6 +6,16 @@
 class YearlyStatisticsModel;
 class YearlyStatisticsWidget;
 
+class PercentageBarItem : public QGraphicsItemGroup {
+
+};
+
+struct Value{
+	int min;
+	int avg;
+	int max;
+};
+
 class YearlyStatisticsItem : public QObject, public QGraphicsRectItem {
 	Q_OBJECT
 public:
@@ -13,6 +23,16 @@ public:
 private:
 	YearlyStatisticsModel *model;
 	int row;
+
+	Value depth;
+	Value sac;
+	Value temp;
+	Value time;
+
+	QVector<Value> monthsDepth;
+	QVector<Value> monthsSac;
+	QVector<Value> monthsTemp;
+	QVector<Value> monthsTime;
 };
 
 #endif
\ No newline at end of file
-- 
2.1.0

From fb9832173d2b50a06fd5ce1dd421be2103c3d1fc Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Mon, 25 Aug 2014 18:45:01 -0300
Subject: [PATCH 12/12] Separate the Trip / Year statistics, get the right
 data.

I was forgetting to use the index on the months / trips.
also, added a new item that can have more than 12 entries.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/statistics/statisticswidget.cpp |  5 ++++-
 qt-ui/statistics/yearstatistics.cpp   | 40 +++++++++++++++++++++++------------
 qt-ui/statistics/yearstatistics.h     | 10 ++++++++-
 3 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/qt-ui/statistics/statisticswidget.cpp b/qt-ui/statistics/statisticswidget.cpp
index 294cb07..7d33d82 100644
--- a/qt-ui/statistics/statisticswidget.cpp
+++ b/qt-ui/statistics/statisticswidget.cpp
@@ -31,11 +31,14 @@ void YearlyStatisticsWidget::setModel(YearlyStatisticsModel *m)
 
 void YearlyStatisticsWidget::modelRowsInserted(const QModelIndex &index, int first, int last)
 {
-	for(int i = 0; i < m_model->rowCount(); i++){
+	// Last row is not month-based, but trip based.
+	for(int i = 0; i < m_model->rowCount() -1 ; i++){
 		QModelIndex yearIndex = m_model->index(i,0);
 		YearlyStatisticsItem *year = new YearlyStatisticsItem(m_model, i, this);
 		scene()->addItem(year);
 	}
+	TripStatisticsItem *trips = new TripStatisticsItem(m_model, m_model->rowCount()-1, this);
+	scene()->addItem(trips);
 	doLayout();
 }
 
diff --git a/qt-ui/statistics/yearstatistics.cpp b/qt-ui/statistics/yearstatistics.cpp
index ade918c..25b346e 100644
--- a/qt-ui/statistics/yearstatistics.cpp
+++ b/qt-ui/statistics/yearstatistics.cpp
@@ -24,27 +24,39 @@ YearlyStatisticsItem::YearlyStatisticsItem(YearlyStatisticsModel *m, int row, Ye
 	temp.avg = m->index(row, YearlyStatisticsModel::AVG_TEMP).data().toInt();
 	temp.max = m->index(row, YearlyStatisticsModel::MAX_TEMP).data().toInt();
 
-	// Create the detailed view.
-	for(int i = 0; i < 12; i++){ // months.
+	rowCount = 12; // Montly based;
+}
+
+TripStatisticsItem::TripStatisticsItem(YearlyStatisticsModel *m, int row, YearlyStatisticsWidget *parent)
+	: YearlyStatisticsItem(m,row,parent)
+{
+	rowCount = m->rowCount(m->index(row, 0)); // trip based.
+}
+
+void YearlyStatisticsItem::createChildren()
+{
+	QModelIndex parent = model->index(row, 0);
+	for(int i = 0; i < rowCount; i++){ // months.
 		Value time2, depth2, sac2, temp2;
-		time2.min = m->index(row, YearlyStatisticsModel::SHORTEST_TIME).data().toInt();
-		time2.avg = m->index(row, YearlyStatisticsModel::AVERAGE_TIME).data().toInt();
-		time2.max = m->index(row, YearlyStatisticsModel::LONGEST_TIME).data().toInt();
+		time2.min = model->index(row, YearlyStatisticsModel::SHORTEST_TIME, parent).data().toInt();
+		time2.avg = model->index(row, YearlyStatisticsModel::AVERAGE_TIME, parent).data().toInt();
+		time2.max = model->index(row, YearlyStatisticsModel::LONGEST_TIME, parent).data().toInt();
 		monthsTime.push_back(time2);
 
-		depth2.min = m->index(row, YearlyStatisticsModel::MIN_DEPTH).data().toInt();
-		depth2.avg = m->index(row, YearlyStatisticsModel::AVG_DEPTH).data().toInt();
-		depth2.max = m->index(row, YearlyStatisticsModel::MAX_DEPTH).data().toInt();
+		depth2.min = model->index(row, YearlyStatisticsModel::MIN_DEPTH, parent).data().toInt();
+		depth2.avg = model->index(row, YearlyStatisticsModel::AVG_DEPTH, parent).data().toInt();
+		depth2.max = model->index(row, YearlyStatisticsModel::MAX_DEPTH, parent).data().toInt();
 		monthsDepth.push_back(depth2);
 
-		sac2.min = m->index(row, YearlyStatisticsModel::MIN_SAC).data().toInt();
-		sac2.avg = m->index(row, YearlyStatisticsModel::AVG_SAC).data().toInt();
-		sac2.max = m->index(row, YearlyStatisticsModel::MAX_SAC).data().toInt();
+		sac2.min = model->index(row, YearlyStatisticsModel::MIN_SAC, parent).data().toInt();
+		sac2.avg = model->index(row, YearlyStatisticsModel::AVG_SAC, parent).data().toInt();
+		sac2.max = model->index(row, YearlyStatisticsModel::MAX_SAC, parent).data().toInt();
 		monthsSac.push_back(sac2);
 
-		temp2.min = m->index(row, YearlyStatisticsModel::MIN_TEMP).data().toInt();
-		temp2.avg = m->index(row, YearlyStatisticsModel::AVG_TEMP).data().toInt();
-		temp2.max = m->index(row, YearlyStatisticsModel::MAX_TEMP).data().toInt();
+		temp2.min = model->index(row, YearlyStatisticsModel::MIN_TEMP, parent).data().toInt();
+		temp2.avg = model->index(row, YearlyStatisticsModel::AVG_TEMP, parent).data().toInt();
+		temp2.max = model->index(row, YearlyStatisticsModel::MAX_TEMP, parent).data().toInt();
 		monthsTemp.push_back(temp2);
 	}
+
 }
diff --git a/qt-ui/statistics/yearstatistics.h b/qt-ui/statistics/yearstatistics.h
index 1b2f8a4..8b21c43 100644
--- a/qt-ui/statistics/yearstatistics.h
+++ b/qt-ui/statistics/yearstatistics.h
@@ -20,9 +20,11 @@ class YearlyStatisticsItem : public QObject, public QGraphicsRectItem {
 	Q_OBJECT
 public:
 	explicit YearlyStatisticsItem(YearlyStatisticsModel *m, int row, YearlyStatisticsWidget *parent = 0);
-private:
+	void createChildren();
+protected:
 	YearlyStatisticsModel *model;
 	int row;
+	int rowCount;
 
 	Value depth;
 	Value sac;
@@ -35,4 +37,10 @@ private:
 	QVector<Value> monthsTime;
 };
 
+class TripStatisticsItem : public YearlyStatisticsItem {
+	Q_OBJECT
+public:
+	explicit TripStatisticsItem(YearlyStatisticsModel *m, int row, YearlyStatisticsWidget *parent = 0);
+};
+
 #endif
\ No newline at end of file
-- 
2.1.0

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

Reply via email to