Browse Source

Control column support. Fixes #45. Fixes #44.

Neal Wilson 11 years ago
parent
commit
817b49e4bb
1 changed files with 115 additions and 16 deletions
  1. 115
    16
      src/typica.w

+ 115
- 16
src/typica.w View File

8026
 							int annotationcolumn);
8026
 							int annotationcolumn);
8027
 		void clear();
8027
 		void clear();
8028
 		void addOutputTemperatureColumn(int column);
8028
 		void addOutputTemperatureColumn(int column);
8029
+		void addOutputControlColumn(int column);
8029
 		void addOutputAnnotationColumn(int column);
8030
 		void addOutputAnnotationColumn(int column);
8030
 		void clearOutputColumns();
8031
 		void clearOutputColumns();
8031
 		void setDisplayUnits(Units::Unit scale);
8032
 		void setDisplayUnits(Units::Unit scale);
8052
 QHash<int, Measurement> lastMeasurement;
8053
 QHash<int, Measurement> lastMeasurement;
8053
 MeasurementModel *currentModel;
8054
 MeasurementModel *currentModel;
8054
 QList<int> saveTempCols;
8055
 QList<int> saveTempCols;
8056
+QList<int> saveControlCols;
8055
 QList<int> saveNoteCols;
8057
 QList<int> saveNoteCols;
8056
 QList<int> currentColumnSet;
8058
 QList<int> currentColumnSet;
8057
 
8059
 
8083
 		{
8085
 		{
8084
 			Measurement adjusted(measure.temperature(),
8086
 			Measurement adjusted(measure.temperature(),
8085
 									QTime(0, measure.time().minute(),
8087
 									QTime(0, measure.time().minute(),
8086
-											measure.time().second(), 0));
8088
+											measure.time().second(), 0),
8089
+									measure.scale());
8087
 			model_1s->newMeasurement(adjusted, tempcolumn);
8090
 			model_1s->newMeasurement(adjusted, tempcolumn);
8088
 			if(adjusted.time().second() % 5 == 0)
8091
 			if(adjusted.time().second() % 5 == 0)
8089
 			{
8092
 			{
8294
 	}
8297
 	}
8295
 	lastMeasurement.clear();
8298
 	lastMeasurement.clear();
8296
 	saveTempCols.clear();
8299
 	saveTempCols.clear();
8300
+	saveControlCols.clear();
8297
 	saveNoteCols.clear();
8301
 	saveNoteCols.clear();
8298
 }
8302
 }
8299
 
8303
 
8339
 		writer.addTemperatureColumn(model_ms->headerData(c, Qt::Horizontal).
8343
 		writer.addTemperatureColumn(model_ms->headerData(c, Qt::Horizontal).
8340
 		                                      toString(), c);
8344
 		                                      toString(), c);
8341
 	}
8345
 	}
8346
+	foreach(c, saveControlCols)
8347
+	{
8348
+		writer.addControlColumn(model_ms->headerData(c, Qt::Horizontal).
8349
+		                                  toString(), c);
8350
+	}
8342
 	foreach(c, saveNoteCols)
8351
 	foreach(c, saveNoteCols)
8343
 	{
8352
 	{
8344
 		writer.addAnnotationColumn(model_ms->headerData(c, Qt::Horizontal).
8353
 		writer.addAnnotationColumn(model_ms->headerData(c, Qt::Horizontal).
8365
 		writer.addTemperatureColumn(model_ms->headerData(c, Qt::Horizontal).
8374
 		writer.addTemperatureColumn(model_ms->headerData(c, Qt::Horizontal).
8366
 		                                                 toString(), c);
8375
 		                                                 toString(), c);
8367
 	}
8376
 	}
8377
+	foreach(c, saveControlCols)
8378
+	{
8379
+		writer.addControlColumn(model_ms->headerData(c, Qt::Horizontal).
8380
+		                                             toString(), c);
8381
+	}
8368
 	foreach(c, saveNoteCols)
8382
 	foreach(c, saveNoteCols)
8369
 	{
8383
 	{
8370
 		writer.addAnnotationColumn(model_ms->headerData(c, Qt::Horizontal).
8384
 		writer.addAnnotationColumn(model_ms->headerData(c, Qt::Horizontal).
8494
 1.0.8. The main difference is that it is now possible to save multiple data
8508
 1.0.8. The main difference is that it is now possible to save multiple data
8495
 series to the same output document.
8509
 series to the same output document.
8496
 
8510
 
8511
+Starting in version 1.6 it is possible to save control columns. These should
8512
+contain unitless data which should remain unaffected by the current displayed
8513
+unit.
8514
+
8497
 @<ZoomLog Implementation@>=
8515
 @<ZoomLog Implementation@>=
8498
 void ZoomLog::addOutputTemperatureColumn(int column)
8516
 void ZoomLog::addOutputTemperatureColumn(int column)
8499
 {
8517
 {
8500
 	saveTempCols.append(column);
8518
 	saveTempCols.append(column);
8501
 }
8519
 }
8502
 
8520
 
8521
+void ZoomLog::addOutputControlColumn(int column)
8522
+{
8523
+	saveControlCols.append(column);
8524
+}
8525
+
8503
 void ZoomLog::addOutputAnnotationColumn(int column)
8526
 void ZoomLog::addOutputAnnotationColumn(int column)
8504
 {
8527
 {
8505
 	saveNoteCols.append(column);
8528
 	saveNoteCols.append(column);
8508
 void ZoomLog::clearOutputColumns()
8531
 void ZoomLog::clearOutputColumns()
8509
 {
8532
 {
8510
 	saveTempCols.clear();
8533
 	saveTempCols.clear();
8534
+	saveControlCols.clear();
8511
 	saveNoteCols.clear();
8535
 	saveNoteCols.clear();
8512
 }
8536
 }
8513
 
8537
 
8719
 	int colcount;
8743
 	int colcount;
8720
 	QHash<int, int> *lastTemperature;
8744
 	QHash<int, int> *lastTemperature;
8721
 	QList<MeasurementList *>::iterator@, lastInsertion;
8745
 	QList<MeasurementList *>::iterator@, lastInsertion;
8746
+	QHash<int, bool> *controlColumns;
8722
 	public:@/
8747
 	public:@/
8723
 		MeasurementModel(QObject *parent = NULL);
8748
 		MeasurementModel(QObject *parent = NULL);
8724
 		~MeasurementModel();
8749
 		~MeasurementModel();
8793
 @<MeasurementModel Implementation@>=
8818
 @<MeasurementModel Implementation@>=
8794
 void MeasurementModel::newMeasurement(Measurement measure, int tempcolumn)
8819
 void MeasurementModel::newMeasurement(Measurement measure, int tempcolumn)
8795
 {
8820
 {
8821
+	if(measure.scale() == Units::Unitless)
8822
+	{
8823
+		controlColumns->insert(tempcolumn, true);
8824
+	}
8825
+	else
8826
+	{
8827
+		controlColumns->insert(tempcolumn, false);
8828
+	}
8796
 	MeasurementList *temp;
8829
 	MeasurementList *temp;
8797
 	temp = new MeasurementList;
8830
 	temp = new MeasurementList;
8798
 	temp->append(QVariant(measure.time()));
8831
 	temp->append(QVariant(measure.time()));
8924
 	}@t\2@>@/
8957
 	}@t\2@>@/
8925
 }
8958
 }
8926
 
8959
 
8927
-@ If the chosen insertion point is at an existing time, we don't need to worry
8928
-about inserting rows. There may be a need to increase the size of the
8960
+@ If the chosen insertion point is at an existing time, we don'@q'@>t need to
8961
+worry about inserting rows. There may be a need to increase the size of the
8929
 measurement list to accept an entry in a new data series.
8962
 measurement list to accept an entry in a new data series.
8930
 
8963
 
8931
 @<Insert a new measurement at an existing time@>=
8964
 @<Insert a new measurement at an existing time@>=
8968
 insertion = entries->size();@/
9001
 insertion = entries->size();@/
8969
 @<Insert a new measurement somewhere else@>
9002
 @<Insert a new measurement somewhere else@>
8970
 
9003
 
8971
-@ The other bit of code that's a little bit more complicated than other parts of
8972
-the class handles adding annotations to the data. Two signals are emitted in
8973
-this method. The |dataChanged| signal is expected by view classes that can use
8974
-this model. The |rowChanged| signal is used by |ZoomLog| to scroll the view to
8975
-the row the annotation has been added to. This is mainly useful when loading a
8976
-target profile and entering the first annotation prior to starting the batch.
9004
+@ The other bit of code that'@q'@>s a little bit more complicated than other
9005
+parts of the class handles adding annotations to the data. Two signals are
9006
+emitted in this method. The |dataChanged| signal is expected by view classes
9007
+that can use this model. The |rowChanged| signal is used by |ZoomLog| to scroll
9008
+the view to the row the annotation has been added to. This is mainly useful
9009
+when loading a target profile and entering the first annotation prior to
9010
+starting the batch.
8977
 
9011
 
8978
 @<MeasurementModel Implementation@>=
9012
 @<MeasurementModel Implementation@>=
8979
 void MeasurementModel::newAnnotation(QString annotation, int tempcolumn,@|
9013
 void MeasurementModel::newAnnotation(QString annotation, int tempcolumn,@|
9041
 
9075
 
9042
 @ While these methods for adding measurements and annotations are fine when
9076
 @ While these methods for adding measurements and annotations are fine when
9043
 recording a stream of measurements, either from the |DAQ| or when loading saved
9077
 recording a stream of measurements, either from the |DAQ| or when loading saved
9044
-data, there are also cases where we'd like to edit the data in the model
9078
+data, there are also cases where we'@q'@>d like to edit the data in the model
9045
 directly from the table view. For this, we need to reimplement |setData()|.
9079
 directly from the table view. For this, we need to reimplement |setData()|.
9046
 
9080
 
9047
 Very little input checking is done here. Editable views may want to place
9081
 Very little input checking is done here. Editable views may want to place
9079
 	return true;@t\2@>@/
9113
 	return true;@t\2@>@/
9080
 }
9114
 }
9081
 
9115
 
9082
-@ There is no sense in attempting to edit the data if there isn't any data
9116
+@ There is no sense in attempting to edit the data if there isn'@q'@>t any data
9083
 available to edit. This check is also used when retrieving data from the model.
9117
 available to edit. This check is also used when retrieving data from the model.
9084
 
9118
 
9085
 @<Check that the index is valid@>=
9119
 @<Check that the index is valid@>=
9151
 @<MeasurementModel Implementation@>=
9185
 @<MeasurementModel Implementation@>=
9152
 MeasurementModel::MeasurementModel(QObject *parent) : QAbstractItemModel(parent),
9186
 MeasurementModel::MeasurementModel(QObject *parent) : QAbstractItemModel(parent),
9153
 	unit(Units::Fahrenheit), hData(new QStringList),
9187
 	unit(Units::Fahrenheit), hData(new QStringList),
9154
-	lastTemperature(new QHash<int, int>)@/
9188
+	lastTemperature(new QHash<int, int>),
9189
+	controlColumns(new QHash<int, bool>)@/
9155
 {
9190
 {
9156
 	colcount = 1;
9191
 	colcount = 1;
9157
 	entries = new QList<MeasurementList *>;
9192
 	entries = new QList<MeasurementList *>;
9171
 
9206
 
9172
 @ A pair of functions are used to determine the number of rows and columns the
9207
 @ A pair of functions are used to determine the number of rows and columns the
9173
 model provides. No entries in the model have children, so the parent should
9208
 model provides. No entries in the model have children, so the parent should
9174
-always be the invisible root object. If it isn't, we should return 0.
9209
+always be the invisible root object. If it isn'@q'@>t, we should return 0.
9175
 
9210
 
9176
 @<MeasurementModel Implementation@>=
9211
 @<MeasurementModel Implementation@>=
9177
 int MeasurementModel::rowCount(const QModelIndex &parent) const
9212
 int MeasurementModel::rowCount(const QModelIndex &parent) const
9193
 }
9228
 }
9194
 
9229
 
9195
 @ The model maintains a set of header data. At present, it only supports header
9230
 @ The model maintains a set of header data. At present, it only supports header
9196
-data at the top of the model due to the author's preference to not have row
9231
+data at the top of the model due to the author'@q'@>s preference to not have row
9197
 numbers littering the left of the table (the time column is sufficient to
9232
 numbers littering the left of the table (the time column is sufficient to
9198
 identify the row for the user).
9233
 identify the row for the user).
9199
 
9234
 
9291
 				{
9326
 				{
9292
 					return QVariant();
9327
 					return QVariant();
9293
 				}
9328
 				}
9329
+				if(controlColumns->contains(index.column()))
9330
+				{
9331
+					if(controlColumns->value(index.column()) == true)
9332
+					{
9333
+						return QVariant(QString("%1").arg(QVariant(row->at(index.column()).toInt()).toString()));
9334
+					}
9335
+				}
9294
 				switch(unit)
9336
 				switch(unit)
9295
 				{
9337
 				{
9296
 					case Units::Fahrenheit:
9338
 					case Units::Fahrenheit:
10902
 	QIODevice *out;
10944
 	QIODevice *out;
10903
 	int time;
10945
 	int time;
10904
 	QMap<int, QString> temperatureColumns;
10946
 	QMap<int, QString> temperatureColumns;
10947
+	QMap<int, QString> controlColumns;
10905
 	QMap<int, QString> annotationColumns;
10948
 	QMap<int, QString> annotationColumns;
10906
 	public:@/
10949
 	public:@/
10907
 		XMLOutput(MeasurementModel *model, QIODevice *device, int timec = 0);
10950
 		XMLOutput(MeasurementModel *model, QIODevice *device, int timec = 0);
10908
 		void addTemperatureColumn(const QString &series, int column);
10951
 		void addTemperatureColumn(const QString &series, int column);
10952
+		void addControlColumn(const QString &series, int column);
10909
 		void addAnnotationColumn(const QString &series, int column);
10953
 		void addAnnotationColumn(const QString &series, int column);
10910
 		void setModel(MeasurementModel *model);
10954
 		void setModel(MeasurementModel *model);
10911
 		void setTimeColumn(int column);
10955
 		void setTimeColumn(int column);
10926
 	}@/
10970
 	}@/
10927
 	QXmlStreamWriter xmlout(out);
10971
 	QXmlStreamWriter xmlout(out);
10928
 	xmlout.writeStartDocument("1.0");
10972
 	xmlout.writeStartDocument("1.0");
10929
-	xmlout.writeDTD("<!DOCTYPE roastlog2.0>");
10973
+	xmlout.writeDTD("<!DOCTYPE roastlog3.0>");
10930
 	xmlout.writeStartElement("roastlog");
10974
 	xmlout.writeStartElement("roastlog");
10931
 	@<Output the column declarations@>@;
10975
 	@<Output the column declarations@>@;
10932
 	xmlout.writeStartElement("roast");
10976
 	xmlout.writeStartElement("roast");
10957
 	xmlout.writeAttribute("name", temperatureColumns.value(c));
11001
 	xmlout.writeAttribute("name", temperatureColumns.value(c));
10958
 	xmlout.writeEndElement();
11002
 	xmlout.writeEndElement();
10959
 }
11003
 }
11004
+foreach(int c, controlColumns.keys())
11005
+{
11006
+	xmlout.writeStartElement("controlseries");
11007
+	xmlout.writeAttribute("name", controlColumns.value(c));
11008
+	xmlout.writeEndElement();
11009
+}
10960
 foreach(int c, annotationColumns.keys())
11010
 foreach(int c, annotationColumns.keys())
10961
 {
11011
 {
10962
 	xmlout.writeStartElement("noteseries");
11012
 	xmlout.writeStartElement("noteseries");
10980
 		break;@t\2@>@/
11030
 		break;@t\2@>@/
10981
 	}@t\2@>@/
11031
 	}@t\2@>@/
10982
 }@/
11032
 }@/
11033
+foreach(int c, controlColumns.keys())
11034
+{
11035
+	if(data->data(data->index(i, c), Qt::DisplayRole).isValid() &&
11036
+	         !(data->data(data->index(i, c), Qt::DisplayRole).toString().isEmpty()))
11037
+	{
11038
+		oresult = true;
11039
+		break;
11040
+	}
11041
+}
10983
 if(oresult == false)@/
11042
 if(oresult == false)@/
10984
 {@t\1@>@/
11043
 {@t\1@>@/
10985
 	foreach(int c, annotationColumns.keys())@/
11044
 	foreach(int c, annotationColumns.keys())@/
11015
 		xmlout.writeEndElement();
11074
 		xmlout.writeEndElement();
11016
 	}
11075
 	}
11017
 }
11076
 }
11077
+foreach(int c, controlColumns.keys())
11078
+{
11079
+	if(data->data(data->index(i, c), Qt::DisplayRole).isValid() &&
11080
+	         !(data->data(data->index(i, c), Qt::DisplayRole).toString().isEmpty()))
11081
+	{
11082
+		xmlout.writeStartElement("control");
11083
+		xmlout.writeAttribute("series", controlColumns.value(c));
11084
+		xmlout.writeCharacters(data->data(data->index(i, c), Qt::DisplayRole).toString());
11085
+		xmlout.writeEndElement();
11086
+	}
11087
+}
11018
 foreach(int c, annotationColumns.keys())@/
11088
 foreach(int c, annotationColumns.keys())@/
11019
 {
11089
 {
11020
 	if(data->data(data->index(i, c), Qt::DisplayRole).isValid() &&
11090
 	if(data->data(data->index(i, c), Qt::DisplayRole).isValid() &&
11066
 	temperatureColumns.insert(column, series);
11136
 	temperatureColumns.insert(column, series);
11067
 }
11137
 }
11068
 
11138
 
11139
+void XMLOutput::addControlColumn(const QString &series, int column)
11140
+{
11141
+	controlColumns.insert(column, series);
11142
+}
11143
+
11069
 void XMLOutput::addAnnotationColumn(const QString &series, int column)
11144
 void XMLOutput::addAnnotationColumn(const QString &series, int column)
11070
 {
11145
 {
11071
 	annotationColumns.insert(column, series);
11146
 	annotationColumns.insert(column, series);
11179
 {
11254
 {
11180
 	if(xmlin.isStartElement())
11255
 	if(xmlin.isStartElement())
11181
 	{
11256
 	{
11182
-		if(xmlin.name() == "tempseries")
11257
+		if((xmlin.name() == "tempseries") || (xmlin.name() == "controlseries"))
11183
 		{
11258
 		{
11184
 			temperatureColumns.insert(xmlin.attributes().value("name").
11259
 			temperatureColumns.insert(xmlin.attributes().value("name").
11185
 									                     toString(),
11260
 									                     toString(),
11255
 	Measurement measurement(tempval, timeval);
11330
 	Measurement measurement(tempval, timeval);
11256
 	emit measure(measurement, column);
11331
 	emit measure(measurement, column);
11257
 }
11332
 }
11333
+else if(xmlin.name() == "control")
11334
+{
11335
+	column = xmlin.attributes().value("series").toString().isEmpty() ?
11336
+	         firstc : temperatureColumns.value(xmlin.attributes().
11337
+	                                                   value("series").toString());
11338
+	tempval = xmlin.readElementText().toDouble();
11339
+	Measurement measurement(tempval, timeval, Units::Unitless);
11340
+	emit measure(measurement, column);
11341
+}
11258
 else if(xmlin.name() == "annotation")
11342
 else if(xmlin.name() == "annotation")
11259
 {
11343
 {
11260
 	column = xmlin.attributes().value("series").toString().isEmpty() ?
11344
 	column = xmlin.attributes().value("series").toString().isEmpty() ?
11338
 	QIODevice *out;
11422
 	QIODevice *out;
11339
 	int time;
11423
 	int time;
11340
 	QMap<int, QString> temperatureColumns;
11424
 	QMap<int, QString> temperatureColumns;
11425
+	QMap<int, QString> controlColumns;
11341
 	QMap<int, QString> annotationColumns;@/
11426
 	QMap<int, QString> annotationColumns;@/
11342
 	public:@/
11427
 	public:@/
11343
 		CSVOutput(MeasurementModel *model, QIODevice *device, int timec = 0);
11428
 		CSVOutput(MeasurementModel *model, QIODevice *device, int timec = 0);
11344
 		void addTemperatureColumn(const QString &series, int column);
11429
 		void addTemperatureColumn(const QString &series, int column);
11430
+		void addControlColumn(const QString &series, int column);
11345
 		void addAnnotationColumn(const QString &series, int column);
11431
 		void addAnnotationColumn(const QString &series, int column);
11346
 		void setModel(MeasurementModel *model);
11432
 		void setModel(MeasurementModel *model);
11347
 		void setTimeColumn(int column);
11433
 		void setTimeColumn(int column);
11388
 {
11474
 {
11389
 	output << ',' << temperatureColumns.value(c);
11475
 	output << ',' << temperatureColumns.value(c);
11390
 }
11476
 }
11477
+foreach(int c, controlColumns.keys())
11478
+{
11479
+	output << ',' << controlColumns.value(c);
11480
+}
11391
 foreach(int c, annotationColumns.keys())
11481
 foreach(int c, annotationColumns.keys())
11392
 {
11482
 {
11393
 	output << ',' << annotationColumns.value(c);
11483
 	output << ',' << annotationColumns.value(c);
11409
 {
11499
 {
11410
 	output << ',' << data->data(data->index(i, c), Qt::DisplayRole).toString();
11500
 	output << ',' << data->data(data->index(i, c), Qt::DisplayRole).toString();
11411
 }
11501
 }
11502
+foreach(int c, controlColumns.keys())
11503
+{
11504
+	output << ',' << data->data(data->index(i, c), Qt::DisplayRole).toString();
11505
+}
11412
 foreach(int c, annotationColumns.keys())
11506
 foreach(int c, annotationColumns.keys())
11413
 {
11507
 {
11414
 	output << ',' << data->data(data->index(i, c), Qt::DisplayRole).toString();
11508
 	output << ',' << data->data(data->index(i, c), Qt::DisplayRole).toString();
11440
 	temperatureColumns.insert(column, series);
11534
 	temperatureColumns.insert(column, series);
11441
 }
11535
 }
11442
 
11536
 
11537
+void CSVOutput::addControlColumn(const QString &series, int column)
11538
+{
11539
+	controlColumns.insert(column, series);
11540
+}
11541
+
11443
 void CSVOutput::addAnnotationColumn(const QString &series, int column)
11542
 void CSVOutput::addAnnotationColumn(const QString &series, int column)
11444
 {
11543
 {
11445
 	annotationColumns.insert(column, series);
11544
 	annotationColumns.insert(column, series);

Loading…
Cancel
Save