Browse Source

Missing file from previous commit

Neal Wilson 11 years ago
parent
commit
4b9527342a
1 changed files with 80 additions and 9 deletions
  1. 80
    9
      src/typica.w

+ 80
- 9
src/typica.w View File

837
 @<FreeAnnotationConfWidget implementation@>@/
837
 @<FreeAnnotationConfWidget implementation@>@/
838
 @<RateOfChange implementation@>@/
838
 @<RateOfChange implementation@>@/
839
 @<SettingsWindow implementation@>@/
839
 @<SettingsWindow implementation@>@/
840
+@<GraphSettingsWidget implementation@>@/
840
 
841
 
841
 @ A few headers are required for various parts of \pn{}. These allow the use of
842
 @ A few headers are required for various parts of \pn{}. These allow the use of
842
 various Qt modules.
843
 various Qt modules.
6686
 		void setMappedUpper(double upper);
6687
 		void setMappedUpper(double upper);
6687
 		void setClosedRange(bool closed);
6688
 		void setClosedRange(bool closed);
6688
 		void setSensitivity(double sensitivity);
6689
 		void setSensitivity(double sensitivity);
6689
-		void newMeasurement(Measurement measure);
6690
+		Measurement newMeasurement(Measurement measure);
6690
 	@t\4@>@[signals:@]@;
6691
 	@t\4@>@[signals:@]@;
6691
 		void measurement(Measurement measure);
6692
 		void measurement(Measurement measure);
6692
 	private:@/
6693
 	private:@/
6717
 |setSensitivity()|.
6718
 |setSensitivity()|.
6718
 
6719
 
6719
 @<LinearCalibrator Implementation@>=
6720
 @<LinearCalibrator Implementation@>=
6720
-void LinearCalibrator::newMeasurement(Measurement measure)
6721
+Measurement LinearCalibrator::newMeasurement(Measurement measure)
6721
 {
6722
 {
6722
 	double outval = Lo1 + (measure.temperature() - Lo2) * (Up1 - Lo1)/(Up2 - Lo2);
6723
 	double outval = Lo1 + (measure.temperature() - Lo2) * (Up1 - Lo1)/(Up2 - Lo2);
6723
 	if(clamp)
6724
 	if(clamp)
6738
 	}
6739
 	}
6739
 	Measurement adjusted(outval, measure.time(), measure.scale());
6740
 	Measurement adjusted(outval, measure.time(), measure.scale());
6740
 	emit measurement(adjusted);
6741
 	emit measurement(adjusted);
6742
+	return adjusted;
6741
 }
6743
 }
6742
 
6744
 
6743
 @ The rest of the class consists of trivial accessor methods.
6745
 @ The rest of the class consists of trivial accessor methods.
6861
 		LinearSplineInterpolator(QObject *parent = NULL);
6863
 		LinearSplineInterpolator(QObject *parent = NULL);
6862
 		@[Q_INVOKABLE@]@, void add_pair(double source, double destination);
6864
 		@[Q_INVOKABLE@]@, void add_pair(double source, double destination);
6863
 	@[public slots@]:@/
6865
 	@[public slots@]:@/
6864
-		void newMeasurement(Measurement measure);
6866
+		Measurement newMeasurement(Measurement measure);
6865
 	@[signals@]:@/
6867
 	@[signals@]:@/
6866
 		void newData(Measurement measure);
6868
 		void newData(Measurement measure);
6867
 	private:@/
6869
 	private:@/
6916
 	/* Nothing needs to be done here. */
6918
 	/* Nothing needs to be done here. */
6917
 }
6919
 }
6918
 
6920
 
6919
-void LinearSplineInterpolator::newMeasurement(Measurement measure)
6921
+Measurement LinearSplineInterpolator::newMeasurement(Measurement measure)
6920
 {
6922
 {
6921
 	QMap<double, double>::const_iterator i = pairs->constBegin();
6923
 	QMap<double, double>::const_iterator i = pairs->constBegin();
6922
 	int index = -1;
6924
 	int index = -1;
6939
 	}
6941
 	}
6940
 	if(interpolators->at(index) != NULL)
6942
 	if(interpolators->at(index) != NULL)
6941
 	{
6943
 	{
6942
-		interpolators->at(index)->newMeasurement(measure);
6944
+		return interpolators->at(index)->newMeasurement(measure);
6943
 	}
6945
 	}
6946
+	return Measurement();
6944
 }
6947
 }
6945
 
6948
 
6946
 @ This is exposed to the scripting environment as usual.
6949
 @ This is exposed to the scripting environment as usual.
7254
 		}
7257
 		}
7255
 		else@/
7258
 		else@/
7256
 		{
7259
 		{
7257
-			Measurement rel(measure.temperature(), QTime(0, 0, 0, 0), measure.scale());
7260
+			Measurement rel = measure;
7261
+			rel.setTime(QTime(0, 0, 0, 0));
7258
 			emit measurement(rel);
7262
 			emit measurement(rel);
7259
 		}
7263
 		}
7260
 	}
7264
 	}
7278
 {
7282
 {
7279
 	newTime.setHMS(0, newTime.minute(), newTime.second(), newTime.msec());
7283
 	newTime.setHMS(0, newTime.minute(), newTime.second(), newTime.msec());
7280
 }
7284
 }
7281
-Measurement rel(measure.temperature(), newTime, measure.scale());
7285
+Measurement rel = measure;
7286
+rel.setTime(newTime);
7282
 emit measurement(rel);
7287
 emit measurement(rel);
7283
 
7288
 
7284
 @ The rest of the code handles updating and reporting the reference time.
7289
 @ The rest of the code handles updating and reporting the reference time.
7655
 	QMap<int, double> *translations;
7660
 	QMap<int, double> *translations;
7656
 	QList<QGraphicsItem *> *gridLinesF;
7661
 	QList<QGraphicsItem *> *gridLinesF;
7657
 	QList<QGraphicsItem *> *gridLinesC;
7662
 	QList<QGraphicsItem *> *gridLinesC;
7658
-	QList<QGraphicsItem *> *relativeGridLines;@/
7663
+	QList<QGraphicsItem *> *relativeGridLines;
7664
+	bool relativeEnabled;
7665
+	LinearSplineInterpolator *relativeAdjuster;@/
7659
 	public:@/
7666
 	public:@/
7660
 		GraphView(QWidget *parent = NULL);
7667
 		GraphView(QWidget *parent = NULL);
7661
 		void removeSeries(int column);@/
7668
 		void removeSeries(int column);@/
7698
 	translations(new QMap<int, double>),
7705
 	translations(new QMap<int, double>),
7699
 	gridLinesF(new QList<QGraphicsItem *>),
7706
 	gridLinesF(new QList<QGraphicsItem *>),
7700
 	gridLinesC(new QList<QGraphicsItem *>),
7707
 	gridLinesC(new QList<QGraphicsItem *>),
7701
-	relativeGridLines(new QList<QGraphicsItem *>)@/
7708
+	relativeGridLines(new QList<QGraphicsItem *>),
7709
+	relativeEnabled(false)@/
7702
 {
7710
 {
7703
 	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
7711
 	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
7704
 	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
7712
 	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
7705
 	setScene(theScene);
7713
 	setScene(theScene);
7706
 	setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
7714
 	setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
7707
 	@<Draw temperature axis and grid lines@>;
7715
 	@<Draw temperature axis and grid lines@>;
7716
+	@<Draw secondary axes@>@;
7708
 	@<Draw time axis and ticks@>;
7717
 	@<Draw time axis and ticks@>;
7709
 	fitInView(theScene->sceneRect().adjusted(-50,-50,50,50));
7718
 	fitInView(theScene->sceneRect().adjusted(-50,-50,50,50));
7710
 }
7719
 }
7753
 	gridLinesC->append(label);
7762
 	gridLinesC->append(label);
7754
 }
7763
 }
7755
 
7764
 
7765
+@ If we are going to plot relative temperature measurements, we must obtain
7766
+information on how we wish to do that from settings. We take advantage of the
7767
+fact that iterating over the keys in a |QMap| produces results in sorted order.
7768
+
7769
+While drawing the grid lines we also set up the |relativeAdjuster| that will be
7770
+used to transform incoming measurements to our coordinate system.
7771
+
7772
+@<Draw secondary axes@>=
7773
+QSettings settings;
7774
+if(settings.contains("settings/graph/relative/enable"))
7775
+{
7776
+	if(settings.value("settings/graph/relative/enable").toBool())
7777
+	{
7778
+		relativeEnabled = true;
7779
+		QColor relativeColor = QColor(settings.value("settings/graph/relative/color").toString());
7780
+		QString unit = QString(settings.value("settings/graph/relative/unit").toInt() == 0 ? "F" : "C");
7781
+		QMap<double, QString> relativeAxisPairs;
7782
+		QStringList relativeAxisLabels = settings.value("settings/graph/relative/grid").toString().split(QRegExp("[\\s,]+"), QString::SkipEmptyParts);
7783
+		foreach(QString item, relativeAxisLabels)
7784
+		{
7785
+			relativeAxisPairs.insert(item.toDouble(), item);
7786
+		}
7787
+		if(relativeAxisPairs.size() > 1)
7788
+		{
7789
+			double skip = 500.0 / (relativeAxisPairs.size() - 1);
7790
+			double y = 0;
7791
+			foreach(double key, relativeAxisPairs.keys())
7792
+			{
7793
+				gridLine = new QGraphicsLineItem;
7794
+				gridLine->setLine(0, y, 1205, y);
7795
+				gridLine->setPen(QPen(relativeColor));
7796
+				theScene->addItem(gridLine);
7797
+				relativeGridLines->append(gridLine);
7798
+				label = new QGraphicsTextItem;
7799
+				label->setHtml(QString("%1&deg;%2").arg(relativeAxisPairs.value(key)).arg(unit));
7800
+				label->setPos(1210, y - (label->boundingRect().height() / 2));
7801
+				theScene->addItem(label);
7802
+				relativeGridLines->append(label);
7803
+				if(unit == "F")
7804
+				{
7805
+					relativeAdjuster->add_pair(key, y);
7806
+				}
7807
+				else
7808
+				{
7809
+					relativeAdjuster->add_pair(key * (9.0/5.0), y);
7810
+				}
7811
+				y -= skip;
7812
+			}
7813
+		}
7814
+	}
7815
+}
7816
+
7756
 @ Two slots are used to switch between the different sets of grid lines.
7817
 @ Two slots are used to switch between the different sets of grid lines.
7757
 
7818
 
7758
 @<GraphView Implementation@>=
7819
 @<GraphView Implementation@>=
7815
 of line items is initialized when the second measurement is taken. Subsequent
7876
 of line items is initialized when the second measurement is taken. Subsequent
7816
 measurements are able to simply append new line segments to the list.
7877
 measurements are able to simply append new line segments to the list.
7817
 
7878
 
7879
+Relative measurements are first converted to the coordinate system of the
7880
+appropriate secondary axis.
7881
+
7818
 @<GraphView Implementation@>=
7882
 @<GraphView Implementation@>=
7819
 #define FULLTIMETOINT(t) (t.msec() + (t.second() * 1000) +  (t.minute() * 60 * 1000))
7883
 #define FULLTIMETOINT(t) (t.msec() + (t.second() * 1000) +  (t.minute() * 60 * 1000))
7820
 
7884
 
7821
 void GraphView::newMeasurement(Measurement measure, int tempcolumn)@/
7885
 void GraphView::newMeasurement(Measurement measure, int tempcolumn)@/
7822
 {@/
7886
 {@/
7823
 	double offset = 0;
7887
 	double offset = 0;
7888
+	if(measure.contains("relative"))
7889
+	{
7890
+		if(measure.value("relative").toBool())
7891
+		{
7892
+			measure.setTemperature(relativeAdjuster->newMeasurement(measure).temperature());
7893
+		}
7894
+	}
7824
 	if(translations->contains(tempcolumn))
7895
 	if(translations->contains(tempcolumn))
7825
 	{
7896
 	{
7826
 		offset = translations->value(tempcolumn);
7897
 		offset = translations->value(tempcolumn);

Loading…
Cancel
Save