Переглянути джерело

Initial work toward adding support for relative measurements to ZoomLog.

Neal Wilson 11 роки тому
джерело
коміт
09a72381c9
2 змінених файлів з 127 додано та 44 видалено
  1. 32
    36
      src/typica.w
  2. 95
    8
      src/units.w

+ 32
- 36
src/typica.w Переглянути файл

@@ -8166,10 +8166,8 @@ void ZoomLog::newMeasurement(Measurement measure, int tempcolumn)
8166 8166
 		if(measure.time().second() !=
8167 8167
 			lastMeasurement.value(tempcolumn).time().second())
8168 8168
 		{
8169
-			Measurement adjusted(measure.temperature(),
8170
-									QTime(0, measure.time().minute(),
8171
-											measure.time().second(), 0),
8172
-									measure.scale());
8169
+			Measurement adjusted = measure;
8170
+			adjusted.setTime(QTime(0, measure.time().minute(), measure.time().second(), 0));
8173 8171
 			model_1s->newMeasurement(adjusted, tempcolumn);
8174 8172
 			if(adjusted.time().second() % 5 == 0)
8175 8173
 			{
@@ -8238,7 +8236,9 @@ if(lastMeasurement[tempcolumn].time() < measure.time())
8238 8236
 	}
8239 8237
 	for(int i = 0; i < timelist.size(); i++)
8240 8238
 	{
8241
-		newMeasurement(Measurement(measure.temperature(), timelist[i], measure.scale()), tempcolumn);
8239
+		Measurement synthesized = measure;
8240
+		synthesized.setTime(timelist[i]);
8241
+		newMeasurement(synthesized, tempcolumn);
8242 8242
 	}
8243 8243
 }
8244 8244
 
@@ -8279,12 +8279,13 @@ if(currentColumnSet.contains(tempcolumn))
8279 8279
 			{
8280 8280
 				if(measure.time() > lastMeasurement.value(replicationcolumn).time())
8281 8281
 				{
8282
-					Measurement synthetic(lastMeasurement.value(replicationcolumn).temperature(),
8283
-                                          measure.time());
8282
+					Measurement synthetic = lastMeasurement.value(replicationcolumn);
8283
+					synthetic.setTime(measure.time());
8284 8284
 					model_ms->newMeasurement(synthetic, replicationcolumn);
8285 8285
 					if(synthetic.time().second() != lastMeasurement.value(replicationcolumn).time().second())
8286 8286
 					{
8287
-						Measurement adjusted(synthetic.temperature(), QTime(0, synthetic.time().minute(), synthetic.time().second(), 0));
8287
+						Measurement adjusted = synthetic;
8288
+						synthetic.setTime(QTime(0, synthetic.time().minute(), synthetic.time().second(), 0));
8288 8289
 						model_1s->newMeasurement(adjusted, replicationcolumn);
8289 8290
 						if(adjusted.time().second() % 5 == 0)
8290 8291
 						{
@@ -9052,7 +9053,7 @@ if((*i)->size() < tempcolumn + 1)
9052 9053
 		(*i)->append(QVariant());
9053 9054
 	}
9054 9055
 }
9055
-(*i)->replace(tempcolumn, measure.temperature());
9056
+(*i)->replace(tempcolumn, measure);
9056 9057
 lastInsertion = i;
9057 9058
 emit dataChanged(createIndex(insertion, tempcolumn),
9058 9059
 					createIndex(insertion, tempcolumn));
@@ -9070,7 +9071,7 @@ for(int j = 0; j < tempcolumn + 1; j++)
9070 9071
 {
9071 9072
 	newEntry->append(QVariant());
9072 9073
 }
9073
-newEntry->replace(tempcolumn, measure.temperature());
9074
+newEntry->replace(tempcolumn, measure);
9074 9075
 lastInsertion = entries->insert(i, newEntry);
9075 9076
 endInsertRows();
9076 9077
 lastTemperature->insert(tempcolumn, insertion);
@@ -9161,6 +9162,13 @@ recording a stream of measurements, either from the |DAQ| or when loading saved
9161 9162
 data, there are also cases where we'@q'@>d like to edit the data in the model
9162 9163
 directly from the table view. For this, we need to reimplement |setData()|.
9163 9164
 
9165
+Note that editing from the |ZoomLog| has never been supported. While stream
9166
+inserted data currently preserves all properties of inserted measurements,
9167
+using |setData| it is possible to insert a numeric value as if it were a
9168
+measurement. Such an entry will not have any additional information associated
9169
+and cannot be expected to exhibit behavior implemented through the use of that
9170
+extra information.
9171
+
9164 9172
 Very little input checking is done here. Editable views may want to place
9165 9173
 delegates\nfnote{Qt 4.4: Delegate Classes\par\indent\hbox{%
9166 9174
 \pdfURL{http://doc.trolltech.com/4.4/model-view-delegate.html}{%
@@ -9409,33 +9417,21 @@ QVariant MeasurementModel::data(const QModelIndex &index, int role) const@/
9409 9417
 				{
9410 9418
 					return QVariant();
9411 9419
 				}
9412
-				if(controlColumns->contains(index.column()))
9420
+				Measurement v = row->at(index.column());
9421
+				if(v.scale() == Units::Unitless)
9413 9422
 				{
9414
-					if(controlColumns->value(index.column()) == true)
9415
-					{
9416
-						return QVariant(QString("%1").arg(QVariant(row->at(index.column()).toInt()).toString()));
9417
-					}
9423
+					return QVariant(QString("%1").arg(v.temperature()));
9418 9424
 				}
9419
-				switch(unit)
9425
+				else
9420 9426
 				{
9421
-					case Units::Fahrenheit:
9422
-						return QVariant(row->at(index.column()).toString());
9423
-						break;
9424
-					case Units::Celsius:
9425
-						return QVariant((row->at(index.column()).toDouble() -
9426
-						                32) * 5 / 9);
9427
-						break;
9428
-					case Units::Kelvin:
9429
-						return QVariant((row->at(index.column()).toDouble() +
9430
-						                459.67) * 5 / 9);
9431
-						break;
9432
-					case Units::Rankine:
9433
-						return QVariant(row->at(index.column()).toDouble() +
9434
-						                459.67);
9435
-						break;
9436
-					default:
9437
-						return QVariant(row->at(index.column()).toString());
9438
-						break;
9427
+					if(v.contains("relative"))
9428
+					{
9429
+						if(v.value("relative") == true)
9430
+						{
9431
+							return QVariant(QString("%1").arg(Units::convertRelativeTemperature(v.temperature(), v.scale, unit)));
9432
+						}
9433
+					}
9434
+					return QVariant(QString("%1").arg(Units::convertTemperature(v.temperature(), v.scale(), unit)));
9439 9435
 				}
9440 9436
 			}
9441 9437
 			return QVariant(row->at(index.column()).toString());
@@ -9468,7 +9464,7 @@ an index. In the case of this model, each index is treated in the same way.
9468 9464
 
9469 9465
 It may be a good idea to extend the model class to allow models that can be
9470 9466
 edited through the view such as the table view presented in the |LogEditWindow|
9471
-and models that probably shouldn't be edited in the view, such as the models
9467
+and models that probably shouldn'@q'@>t be edited in the view, such as the models
9472 9468
 managed by |ZoomLog|. This could be done by subclassing and only reimplementing
9473 9469
 this method. Otherwise, a new method to specify that the user should not edit
9474 9470
 the model could be provided and a flag would be checked here.
@@ -9484,7 +9480,7 @@ Qt::ItemFlags MeasurementModel::flags(const QModelIndex &index) const@/
9484 9480
 	return 0;
9485 9481
 }
9486 9482
 
9487
-@ Much of the way models are interacted with in Qt's model view architecture is
9483
+@ Much of the way models are interacted with in Qt'@q'@>s model view architecture is
9488 9484
 through model indices. The model is responsible for creating these indices from
9489 9485
 row column pairs.
9490 9486
 

+ 95
- 8
src/units.w Переглянути файл

@@ -25,6 +25,7 @@ class Units: public QObject
25 25
 			Rankine = 10145
26 26
 		};
27 27
 		static double convertTemperature(double value, Unit fromUnit, Unit toUnit);
28
+		static double convertRelativeTemperature(double value, Unit fromUnit, Unit toUnit);
28 29
 		static bool isTemperatureUnit(Unit unit);
29 30
 };
30 31
 
@@ -83,10 +84,10 @@ double Units::convertTemperature(double value, Unit fromUnit, Unit toUnit)
83 84
 					return value;
84 85
 					break;
85 86
 				case Celsius:
86
-					return (value - 32) * 5 / 9;
87
+					return (value - 32.0) * 5.0 / 9.0;
87 88
 					break;
88 89
 				case Kelvin:
89
-					return (value + 459.67) * 5 / 9;
90
+					return (value + 459.67) * 5.0 / 9.0;
90 91
 					break;
91 92
 				case Rankine:
92 93
 					return value + 459.67;
@@ -97,7 +98,7 @@ double Units::convertTemperature(double value, Unit fromUnit, Unit toUnit)
97 98
 			switch(toUnit)
98 99
 			{
99 100
 				case Fahrenheit:
100
-					return value * 9 / 5 + 32;
101
+					return value * 9.0 / 5.0 + 32.0;
101 102
 					break;
102 103
 				case Celsius:
103 104
 					return value;
@@ -106,7 +107,7 @@ double Units::convertTemperature(double value, Unit fromUnit, Unit toUnit)
106 107
 					return value + 273.15;
107 108
 					break;
108 109
 				case Rankine:
109
-					return (value + 273.15) * 9 / 5;
110
+					return (value + 273.15) * 9.0 / 5.0;
110 111
 					break;
111 112
 			}
112 113
 			break;
@@ -114,7 +115,7 @@ double Units::convertTemperature(double value, Unit fromUnit, Unit toUnit)
114 115
 			switch(toUnit)
115 116
 			{
116 117
 				case Fahrenheit:
117
-					return value * 5 / 9 - 459.67;
118
+					return value * 5.0 / 9.0 - 459.67;
118 119
 					break;
119 120
 				case Celsius:
120 121
 					return value - 273.15;
@@ -123,7 +124,7 @@ double Units::convertTemperature(double value, Unit fromUnit, Unit toUnit)
123 124
 					return value;
124 125
 					break;
125 126
 				case Rankine:
126
-					return value * 9 / 5;
127
+					return value * 9.0 / 5.0;
127 128
 					break;
128 129
 			}
129 130
 			break;
@@ -134,10 +135,96 @@ double Units::convertTemperature(double value, Unit fromUnit, Unit toUnit)
134 135
 					return value - 457.67;
135 136
 					break;
136 137
 				case Celsius:
137
-					return (value - 491.67) * 5 / 9;
138
+					return (value - 491.67) * 5.0 / 9.0;
138 139
 					break;
139 140
 				case Kelvin:
140
-					return value * 5 / 9;
141
+					return value * 5.0 / 9.0;
142
+					break;
143
+				case Rankine:
144
+					return value;
145
+					break;
146
+			}
147
+			break;
148
+		default:
149
+			return 0;
150
+			break;
151
+	}
152
+	return 0;
153
+}
154
+
155
+@ Conversions are also provided for relative temperature measurements.
156
+
157
+@(units.cpp@>=
158
+double Units::convertRelativeTemperature(double value, Unit fromUnit, Unit toUnit)
159
+{
160
+	if(isTemperatureUnit(fromUnit) && isTemperatureUnit(toUnit) == false)
161
+	{
162
+		return 0;
163
+	}
164
+	switch(fromUnit)
165
+	{
166
+		case Fahrenheit:
167
+			switch(toUnit)
168
+			{
169
+				case Fahrenheit:
170
+					return value;
171
+					break;
172
+				case Celsius:
173
+					return value * (5.0 / 9.0);
174
+					break;
175
+				case Kelvin:
176
+					return value * (5.0 / 9.0);
177
+					break;
178
+				case Rankine:
179
+					return value;
180
+					break;
181
+			}
182
+			break;
183
+		case Celsius:
184
+			switch(toUnit)
185
+			{
186
+				case Fahrenheit:
187
+					return value * (9.0 / 5.0);
188
+					break;
189
+				case Celsius:
190
+					return value;
191
+					break;
192
+				case Kelvin:
193
+					return value;
194
+					break;
195
+				case Rankine:
196
+					return value * (9.0 / 5.0);
197
+					break;
198
+			}
199
+			break;
200
+		case Kelvin:
201
+			switch(toUnit)
202
+			{
203
+				case Fahrenheit:
204
+					return value * (5.0 / 9.0);
205
+					break;
206
+				case Celsius:
207
+					return value;
208
+					break;
209
+				case Kelvin:
210
+					return value;
211
+					break;
212
+				case Rankine:
213
+					return value * (9.0 / 5.0);
214
+					break;
215
+			}
216
+			break;
217
+		case Rankine:
218
+			switch(toUnit)
219
+			{
220
+				case Fahrenheit:
221
+					return value;
222
+					break;
223
+				case Celsius:
224
+					return value * (5.0 / 9.0);
225
+					break;
226
+				case Kelvin:
227
+					return value * (5.0 / 9.0);
141 228
 					break;
142 229
 				case Rankine:
143 230
 					return value;

Завантаження…
Відмінити
Зберегти