Browse Source

Initial work toward adding support for relative measurements to ZoomLog.

Neal Wilson 11 years ago
parent
commit
09a72381c9
2 changed files with 127 additions and 44 deletions
  1. 32
    36
      src/typica.w
  2. 95
    8
      src/units.w

+ 32
- 36
src/typica.w View File

8166
 		if(measure.time().second() !=
8166
 		if(measure.time().second() !=
8167
 			lastMeasurement.value(tempcolumn).time().second())
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
 			model_1s->newMeasurement(adjusted, tempcolumn);
8171
 			model_1s->newMeasurement(adjusted, tempcolumn);
8174
 			if(adjusted.time().second() % 5 == 0)
8172
 			if(adjusted.time().second() % 5 == 0)
8175
 			{
8173
 			{
8238
 	}
8236
 	}
8239
 	for(int i = 0; i < timelist.size(); i++)
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
 			{
8279
 			{
8280
 				if(measure.time() > lastMeasurement.value(replicationcolumn).time())
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
 					model_ms->newMeasurement(synthetic, replicationcolumn);
8284
 					model_ms->newMeasurement(synthetic, replicationcolumn);
8285
 					if(synthetic.time().second() != lastMeasurement.value(replicationcolumn).time().second())
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
 						model_1s->newMeasurement(adjusted, replicationcolumn);
8289
 						model_1s->newMeasurement(adjusted, replicationcolumn);
8289
 						if(adjusted.time().second() % 5 == 0)
8290
 						if(adjusted.time().second() % 5 == 0)
8290
 						{
8291
 						{
9052
 		(*i)->append(QVariant());
9053
 		(*i)->append(QVariant());
9053
 	}
9054
 	}
9054
 }
9055
 }
9055
-(*i)->replace(tempcolumn, measure.temperature());
9056
+(*i)->replace(tempcolumn, measure);
9056
 lastInsertion = i;
9057
 lastInsertion = i;
9057
 emit dataChanged(createIndex(insertion, tempcolumn),
9058
 emit dataChanged(createIndex(insertion, tempcolumn),
9058
 					createIndex(insertion, tempcolumn));
9059
 					createIndex(insertion, tempcolumn));
9070
 {
9071
 {
9071
 	newEntry->append(QVariant());
9072
 	newEntry->append(QVariant());
9072
 }
9073
 }
9073
-newEntry->replace(tempcolumn, measure.temperature());
9074
+newEntry->replace(tempcolumn, measure);
9074
 lastInsertion = entries->insert(i, newEntry);
9075
 lastInsertion = entries->insert(i, newEntry);
9075
 endInsertRows();
9076
 endInsertRows();
9076
 lastTemperature->insert(tempcolumn, insertion);
9077
 lastTemperature->insert(tempcolumn, insertion);
9161
 data, there are also cases where we'@q'@>d like to edit the data in the model
9162
 data, there are also cases where we'@q'@>d like to edit the data in the model
9162
 directly from the table view. For this, we need to reimplement |setData()|.
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
 Very little input checking is done here. Editable views may want to place
9172
 Very little input checking is done here. Editable views may want to place
9165
 delegates\nfnote{Qt 4.4: Delegate Classes\par\indent\hbox{%
9173
 delegates\nfnote{Qt 4.4: Delegate Classes\par\indent\hbox{%
9166
 \pdfURL{http://doc.trolltech.com/4.4/model-view-delegate.html}{%
9174
 \pdfURL{http://doc.trolltech.com/4.4/model-view-delegate.html}{%
9409
 				{
9417
 				{
9410
 					return QVariant();
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
 			return QVariant(row->at(index.column()).toString());
9437
 			return QVariant(row->at(index.column()).toString());
9468
 
9464
 
9469
 It may be a good idea to extend the model class to allow models that can be
9465
 It may be a good idea to extend the model class to allow models that can be
9470
 edited through the view such as the table view presented in the |LogEditWindow|
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
 managed by |ZoomLog|. This could be done by subclassing and only reimplementing
9468
 managed by |ZoomLog|. This could be done by subclassing and only reimplementing
9473
 this method. Otherwise, a new method to specify that the user should not edit
9469
 this method. Otherwise, a new method to specify that the user should not edit
9474
 the model could be provided and a flag would be checked here.
9470
 the model could be provided and a flag would be checked here.
9484
 	return 0;
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
 through model indices. The model is responsible for creating these indices from
9484
 through model indices. The model is responsible for creating these indices from
9489
 row column pairs.
9485
 row column pairs.
9490
 
9486
 

+ 95
- 8
src/units.w View File

25
 			Rankine = 10145
25
 			Rankine = 10145
26
 		};
26
 		};
27
 		static double convertTemperature(double value, Unit fromUnit, Unit toUnit);
27
 		static double convertTemperature(double value, Unit fromUnit, Unit toUnit);
28
+		static double convertRelativeTemperature(double value, Unit fromUnit, Unit toUnit);
28
 		static bool isTemperatureUnit(Unit unit);
29
 		static bool isTemperatureUnit(Unit unit);
29
 };
30
 };
30
 
31
 
83
 					return value;
84
 					return value;
84
 					break;
85
 					break;
85
 				case Celsius:
86
 				case Celsius:
86
-					return (value - 32) * 5 / 9;
87
+					return (value - 32.0) * 5.0 / 9.0;
87
 					break;
88
 					break;
88
 				case Kelvin:
89
 				case Kelvin:
89
-					return (value + 459.67) * 5 / 9;
90
+					return (value + 459.67) * 5.0 / 9.0;
90
 					break;
91
 					break;
91
 				case Rankine:
92
 				case Rankine:
92
 					return value + 459.67;
93
 					return value + 459.67;
97
 			switch(toUnit)
98
 			switch(toUnit)
98
 			{
99
 			{
99
 				case Fahrenheit:
100
 				case Fahrenheit:
100
-					return value * 9 / 5 + 32;
101
+					return value * 9.0 / 5.0 + 32.0;
101
 					break;
102
 					break;
102
 				case Celsius:
103
 				case Celsius:
103
 					return value;
104
 					return value;
106
 					return value + 273.15;
107
 					return value + 273.15;
107
 					break;
108
 					break;
108
 				case Rankine:
109
 				case Rankine:
109
-					return (value + 273.15) * 9 / 5;
110
+					return (value + 273.15) * 9.0 / 5.0;
110
 					break;
111
 					break;
111
 			}
112
 			}
112
 			break;
113
 			break;
114
 			switch(toUnit)
115
 			switch(toUnit)
115
 			{
116
 			{
116
 				case Fahrenheit:
117
 				case Fahrenheit:
117
-					return value * 5 / 9 - 459.67;
118
+					return value * 5.0 / 9.0 - 459.67;
118
 					break;
119
 					break;
119
 				case Celsius:
120
 				case Celsius:
120
 					return value - 273.15;
121
 					return value - 273.15;
123
 					return value;
124
 					return value;
124
 					break;
125
 					break;
125
 				case Rankine:
126
 				case Rankine:
126
-					return value * 9 / 5;
127
+					return value * 9.0 / 5.0;
127
 					break;
128
 					break;
128
 			}
129
 			}
129
 			break;
130
 			break;
134
 					return value - 457.67;
135
 					return value - 457.67;
135
 					break;
136
 					break;
136
 				case Celsius:
137
 				case Celsius:
137
-					return (value - 491.67) * 5 / 9;
138
+					return (value - 491.67) * 5.0 / 9.0;
138
 					break;
139
 					break;
139
 				case Kelvin:
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
 					break;
228
 					break;
142
 				case Rankine:
229
 				case Rankine:
143
 					return value;
230
 					return value;

Loading…
Cancel
Save