Bläddra i källkod

Missing file from previous commit

Neal Wilson 11 år sedan
förälder
incheckning
4b9527342a
1 ändrade filer med 80 tillägg och 9 borttagningar
  1. 80
    9
      src/typica.w

+ 80
- 9
src/typica.w Visa fil

@@ -837,6 +837,7 @@ generated file empty.
837 837
 @<FreeAnnotationConfWidget implementation@>@/
838 838
 @<RateOfChange implementation@>@/
839 839
 @<SettingsWindow implementation@>@/
840
+@<GraphSettingsWidget implementation@>@/
840 841
 
841 842
 @ A few headers are required for various parts of \pn{}. These allow the use of
842 843
 various Qt modules.
@@ -6686,7 +6687,7 @@ class LinearCalibrator : public QObject@/
6686 6687
 		void setMappedUpper(double upper);
6687 6688
 		void setClosedRange(bool closed);
6688 6689
 		void setSensitivity(double sensitivity);
6689
-		void newMeasurement(Measurement measure);
6690
+		Measurement newMeasurement(Measurement measure);
6690 6691
 	@t\4@>@[signals:@]@;
6691 6692
 		void measurement(Measurement measure);
6692 6693
 	private:@/
@@ -6717,7 +6718,7 @@ This method also handles any rounding needed if there has been a call to
6717 6718
 |setSensitivity()|.
6718 6719
 
6719 6720
 @<LinearCalibrator Implementation@>=
6720
-void LinearCalibrator::newMeasurement(Measurement measure)
6721
+Measurement LinearCalibrator::newMeasurement(Measurement measure)
6721 6722
 {
6722 6723
 	double outval = Lo1 + (measure.temperature() - Lo2) * (Up1 - Lo1)/(Up2 - Lo2);
6723 6724
 	if(clamp)
@@ -6738,6 +6739,7 @@ void LinearCalibrator::newMeasurement(Measurement measure)
6738 6739
 	}
6739 6740
 	Measurement adjusted(outval, measure.time(), measure.scale());
6740 6741
 	emit measurement(adjusted);
6742
+	return adjusted;
6741 6743
 }
6742 6744
 
6743 6745
 @ The rest of the class consists of trivial accessor methods.
@@ -6861,7 +6863,7 @@ class LinearSplineInterpolator : public QObject
6861 6863
 		LinearSplineInterpolator(QObject *parent = NULL);
6862 6864
 		@[Q_INVOKABLE@]@, void add_pair(double source, double destination);
6863 6865
 	@[public slots@]:@/
6864
-		void newMeasurement(Measurement measure);
6866
+		Measurement newMeasurement(Measurement measure);
6865 6867
 	@[signals@]:@/
6866 6868
 		void newData(Measurement measure);
6867 6869
 	private:@/
@@ -6916,7 +6918,7 @@ LinearSplineInterpolator::LinearSplineInterpolator(QObject *parent) :
6916 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 6923
 	QMap<double, double>::const_iterator i = pairs->constBegin();
6922 6924
 	int index = -1;
@@ -6939,8 +6941,9 @@ void LinearSplineInterpolator::newMeasurement(Measurement measure)
6939 6941
 	}
6940 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 6949
 @ This is exposed to the scripting environment as usual.
@@ -7254,7 +7257,8 @@ void MeasurementTimeOffset::newMeasurement(Measurement measure)@t\2\2@>@/
7254 7257
 		}
7255 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 7262
 			emit measurement(rel);
7259 7263
 		}
7260 7264
 	}
@@ -7278,7 +7282,8 @@ if(newTime.hour() > 0)
7278 7282
 {
7279 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 7287
 emit measurement(rel);
7283 7288
 
7284 7289
 @ The rest of the code handles updating and reporting the reference time.
@@ -7655,7 +7660,9 @@ class GraphView : public QGraphicsView@/
7655 7660
 	QMap<int, double> *translations;
7656 7661
 	QList<QGraphicsItem *> *gridLinesF;
7657 7662
 	QList<QGraphicsItem *> *gridLinesC;
7658
-	QList<QGraphicsItem *> *relativeGridLines;@/
7663
+	QList<QGraphicsItem *> *relativeGridLines;
7664
+	bool relativeEnabled;
7665
+	LinearSplineInterpolator *relativeAdjuster;@/
7659 7666
 	public:@/
7660 7667
 		GraphView(QWidget *parent = NULL);
7661 7668
 		void removeSeries(int column);@/
@@ -7698,13 +7705,15 @@ GraphView::GraphView(QWidget *parent) : QGraphicsView(parent),
7698 7705
 	translations(new QMap<int, double>),
7699 7706
 	gridLinesF(new QList<QGraphicsItem *>),
7700 7707
 	gridLinesC(new QList<QGraphicsItem *>),
7701
-	relativeGridLines(new QList<QGraphicsItem *>)@/
7708
+	relativeGridLines(new QList<QGraphicsItem *>),
7709
+	relativeEnabled(false)@/
7702 7710
 {
7703 7711
 	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
7704 7712
 	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
7705 7713
 	setScene(theScene);
7706 7714
 	setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
7707 7715
 	@<Draw temperature axis and grid lines@>;
7716
+	@<Draw secondary axes@>@;
7708 7717
 	@<Draw time axis and ticks@>;
7709 7718
 	fitInView(theScene->sceneRect().adjusted(-50,-50,50,50));
7710 7719
 }
@@ -7753,6 +7762,58 @@ for(int degC = 50; degC <= 250; degC += 50)
7753 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 7817
 @ Two slots are used to switch between the different sets of grid lines.
7757 7818
 
7758 7819
 @<GraphView Implementation@>=
@@ -7815,12 +7876,22 @@ considered. In the case of the first measurement, no drawing occurs. A |QList|
7815 7876
 of line items is initialized when the second measurement is taken. Subsequent
7816 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 7882
 @<GraphView Implementation@>=
7819 7883
 #define FULLTIMETOINT(t) (t.msec() + (t.second() * 1000) +  (t.minute() * 60 * 1000))
7820 7884
 
7821 7885
 void GraphView::newMeasurement(Measurement measure, int tempcolumn)@/
7822 7886
 {@/
7823 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 7895
 	if(translations->contains(tempcolumn))
7825 7896
 	{
7826 7897
 		offset = translations->value(tempcolumn);

Laddar…
Avbryt
Spara