Browse Source

Integrate scale measurements to New Batch window. Fixes #55.

Neal Wilson 11 years ago
parent
commit
543c0f47a5
4 changed files with 62 additions and 5 deletions
  1. 17
    2
      config/Windows/newbatch.xml
  2. 4
    2
      src/Typica.pro
  3. 40
    0
      src/scales.w
  4. 1
    1
      src/typica.w

+ 17
- 2
config/Windows/newbatch.xml View File

55
         </layout>
55
         </layout>
56
     </layout>
56
     </layout>
57
 	<layout type="vertical">
57
 	<layout type="vertical">
58
+		<label>Connected Scales</label>
58
 		<layout type="vertical" id="scales" />
59
 		<layout type="vertical" id="scales" />
59
 		<stretch />
60
 		<stretch />
60
 	</layout>
61
 	</layout>
88
 			if(navigationwindow.loggingWindow.scales.length > 0) {
89
 			if(navigationwindow.loggingWindow.scales.length > 0) {
89
 				for(var i = 0; i < navigationwindow.loggingWindow.scales.length; i++) {
90
 				for(var i = 0; i < navigationwindow.loggingWindow.scales.length; i++) {
90
 					var scale = navigationwindow.loggingWindow.scales[i];
91
 					var scale = navigationwindow.loggingWindow.scales[i];
91
-					var label = new QLabel(" ");
92
+					var label = new DragLabel();
92
 					var weighButton = new QPushButton();
93
 					var weighButton = new QPushButton();
93
 					weighButton.text = "Weigh";
94
 					weighButton.text = "Weigh";
94
 					weighButton.clicked.connect(scale.weigh);
95
 					weighButton.clicked.connect(scale.weigh);
95
 					label.updateMeasurement = function(m, u) {
96
 					label.updateMeasurement = function(m, u) {
96
-						this.text = Units.convertWeight(m, u, Units.Pound) + " lb";
97
+						switch(unitBox.currentIndex) {
98
+							case 0:
99
+								this.text = Units.convertWeight(m, u, Units.Gram).toFixed(1);
100
+								break;
101
+							case 1:
102
+								this.text = Units.convertWeight(m, u, Units.Kilogram).toFixed(4);
103
+								break;
104
+							case 2:
105
+								this.text = Units.convertWeight(m, u, Units.Ounce).toFixed(3);
106
+								break;
107
+							case 3:
108
+								this.text = Units.convertWeight(m, u, Units.Pound).toFixed(4);
109
+								break;
110
+						}
97
 					};
111
 					};
98
 					scalesLayout.addWidget(label);
112
 					scalesLayout.addWidget(label);
99
 					scalesLayout.addWidget(weighButton);
113
 					scalesLayout.addWidget(weighButton);
101
 						label.updateMeasurement(m, u);
115
 						label.updateMeasurement(m, u);
102
 					});
116
 					});
103
 					scale.weigh();
117
 					scale.weigh();
118
+					unitBox['currentIndexChanged(int)'].connect(scale.weigh);
104
 				}
119
 				}
105
 			}
120
 			}
106
 			model.dataChanged.connect(function() {
121
 			model.dataChanged.connect(function() {

+ 4
- 2
src/Typica.pro View File

22
     units.h \
22
     units.h \
23
     webview.h \
23
     webview.h \
24
     webelement.h \
24
     webelement.h \
25
-    scale.h
25
+    scale.h \
26
+    draglabel.h
26
 SOURCES += typica.cpp \
27
 SOURCES += typica.cpp \
27
     helpmenu.cpp \
28
     helpmenu.cpp \
28
     abouttypica.cpp \
29
     abouttypica.cpp \
29
     units.cpp \
30
     units.cpp \
30
     webview.cpp \
31
     webview.cpp \
31
     webelement.cpp \
32
     webelement.cpp \
32
-    scale.cpp
33
+    scale.cpp \
34
+    draglabel.cpp
33
 
35
 
34
 RESOURCES += \
36
 RESOURCES += \
35
     resources.qrc
37
     resources.qrc

+ 40
- 0
src/scales.w View File

56
 	}
56
 	}
57
 }
57
 }
58
 
58
 
59
+@ We require the ability to create these labels from the host environment.
60
+First we include the appropriate header.
61
+
62
+@<Header files to include@>=
63
+#include "draglabel.h"
64
+
65
+@ Next, a pair of function prototypes.
66
+
67
+@<Function prototypes for scripting@>=
68
+QScriptValue constructDragLabel(QScriptContext *context, QScriptEngine *engine);
69
+void setDragLabelProperties(QScriptValue value, QScriptEngine *engine);
70
+
71
+@ These are made known to the host environment as usual.
72
+
73
+@<Set up the scripting engine@>=
74
+constructor = engine->newFunction(constructDragLabel);
75
+value = engine->newQMetaObject(&DragLabel::staticMetaObject, constructor);
76
+engine->globalObject().setProperty("DragLabel", value);
77
+
78
+@ The implementation is trivial.
79
+
80
+@<Functions for scripting@>=
81
+QScriptValue constructDragLabel(QScriptContext *context, QScriptEngine *engine)
82
+{
83
+	QScriptValue object;
84
+	QString labelText = "";
85
+	if(context->argumentCount() == 1)
86
+	{
87
+		labelText = argument<QString>(0, context);
88
+	}
89
+	object = engine->newQObject(new DragLabel(labelText));
90
+	setDragLabelProperties(object, engine);
91
+	return object;
92
+}
93
+
94
+void setDragLabelProperties(QScriptValue value, QScriptEngine *engine)
95
+{
96
+	setQLabelProperties(value, engine);
97
+}
98
+
59
 @ An object is also required to communicate with a scale. This is responsible
99
 @ An object is also required to communicate with a scale. This is responsible
60
 for setting up a connection over a serial port, sending commands out to the
100
 for setting up a connection over a serial port, sending commands out to the
61
 scale, buffering and interpreting the response, and signaling new measurements.
101
 scale, buffering and interpreting the response, and signaling new measurements.

+ 1
- 1
src/typica.w View File

12130
 	@<Check that the SaltModel index is valid@>@;
12130
 	@<Check that the SaltModel index is valid@>@;
12131
 	if(valid)
12131
 	if(valid)
12132
 	{
12132
 	{
12133
-		return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
12133
+		return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled;
12134
 	}
12134
 	}
12135
 	return 0;
12135
 	return 0;
12136
 }
12136
 }

Loading…
Cancel
Save