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,6 +55,7 @@
55 55
         </layout>
56 56
     </layout>
57 57
 	<layout type="vertical">
58
+		<label>Connected Scales</label>
58 59
 		<layout type="vertical" id="scales" />
59 60
 		<stretch />
60 61
 	</layout>
@@ -88,12 +89,25 @@
88 89
 			if(navigationwindow.loggingWindow.scales.length > 0) {
89 90
 				for(var i = 0; i < navigationwindow.loggingWindow.scales.length; i++) {
90 91
 					var scale = navigationwindow.loggingWindow.scales[i];
91
-					var label = new QLabel(" ");
92
+					var label = new DragLabel();
92 93
 					var weighButton = new QPushButton();
93 94
 					weighButton.text = "Weigh";
94 95
 					weighButton.clicked.connect(scale.weigh);
95 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 112
 					scalesLayout.addWidget(label);
99 113
 					scalesLayout.addWidget(weighButton);
@@ -101,6 +115,7 @@
101 115
 						label.updateMeasurement(m, u);
102 116
 					});
103 117
 					scale.weigh();
118
+					unitBox['currentIndexChanged(int)'].connect(scale.weigh);
104 119
 				}
105 120
 			}
106 121
 			model.dataChanged.connect(function() {

+ 4
- 2
src/Typica.pro View File

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

+ 40
- 0
src/scales.w View File

@@ -56,6 +56,46 @@ void DragLabel::mousePressEvent(QMouseEvent *event)
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 99
 @ An object is also required to communicate with a scale. This is responsible
60 100
 for setting up a connection over a serial port, sending commands out to the
61 101
 scale, buffering and interpreting the response, and signaling new measurements.

+ 1
- 1
src/typica.w View File

@@ -12130,7 +12130,7 @@ Qt::ItemFlags SaltModel::flags(const QModelIndex &index) const
12130 12130
 	@<Check that the SaltModel index is valid@>@;
12131 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 12135
 	return 0;
12136 12136
 }

Loading…
Cancel
Save