Browse Source

Display native controls for adding points.

Neal Wilson 11 years ago
parent
commit
a9ae40fc33
3 changed files with 28 additions and 194 deletions
  1. 8
    1
      main.cpp
  2. 2
    0
      newpointcontrol.cpp
  3. 18
    193
      qml/BrewPlot/main.qml

+ 8
- 1
main.cpp View File

@@ -2,6 +2,7 @@
2 2
 #include <QtDeclarative>
3 3
 #include "qmlapplicationviewer.h"
4 4
 #include "qmllineitem.h"
5
+#include "newpointcontrol.h"
5 6
 
6 7
 class QmlWindow : public QMainWindow
7 8
 {
@@ -49,7 +50,13 @@ int main(int argc, char *argv[])
49 50
     viewer->rootContext()->setContextProperty("window", window);
50 51
     viewer->setSource(QUrl("qrc:/qml/qml/BrewPlot/main.qml"));
51 52
     app.connect(viewer->engine(), SIGNAL(quit()), SLOT(quit()));
52
-    window->setCentralWidget(viewer);
53
+    QWidget *central = new QWidget;
54
+    QHBoxLayout *layout = new QHBoxLayout;
55
+    NewPointControl *control = new NewPointControl;
56
+    layout->addWidget(control);
57
+    layout->addWidget(viewer);
58
+    central->setLayout(layout);
59
+    window->setCentralWidget(central);
53 60
     viewer->setMinimumSize(viewer->sizeHint());
54 61
     window->show();
55 62
 

+ 2
- 0
newpointcontrol.cpp View File

@@ -18,4 +18,6 @@ NewPointControl::NewPointControl(QWidget *parent) :
18 18
     flayout->addRow(tr("% total dissolved solids:"), tds);
19 19
     layout->addLayout(flayout);
20 20
     layout->addWidget(plot);
21
+    layout->addStretch();
22
+    setLayout(layout);
21 23
 }

+ 18
- 193
qml/BrewPlot/main.qml View File

@@ -19,204 +19,29 @@ Rectangle {
19 19
         width: 450; height: 600
20 20
         anchors {right: parent.right; rightMargin: 20; top: parent.top; topMargin: 20}
21 21
     }
22
-    Item {
23
-        anchors {left: parent.left; leftMargin: 10; top: parent.top; topMargin: 10}
24
-
25
-        Column {
26
-            spacing: 8
27
-
28
-            Row {
29
-                spacing: 5
30
-
31
-                Text {
32
-                    text: "Mass of ground coffee: "
33
-                }
34
-                TextInput {
35
-                    id: groundMass
36
-
37
-                    width: 30
38
-                    validator: DoubleValidator {
39
-                        bottom: 0
40
-                        decimals: 2
41
-                        notation: DoubleValidator.StandardNotation
42
-                    }
43
-                    KeyNavigation.tab: brewedMass
44
-
45
-                    Line {
46
-                        x1: -3; y1: groundMass.height
47
-                        x2: 33; y2: y1
48
-                        penWidth: 1
49
-                        color: "black"
50
-                    }
51
-                }
52
-            }
53
-            Row {
54
-                spacing: 5
55
-
56
-                Text {
57
-                    text: "Mass of brewed coffee:"
58
-                }
59
-                TextInput {
60
-                    id: brewedMass
61
-
62
-                    width: 30
63
-                    validator: DoubleValidator {
64
-                        bottom: 0
65
-                        decimals: 2
66
-                        notation: DoubleValidator.StandardNotation
67
-                    }
68
-                    KeyNavigation.backtab: groundMass
69
-                    KeyNavigation.tab: ptds
70
-
71
-                    Line {
72
-                        x1: -3; y1: brewedMass.height
73
-                        x2: 33; y2: y1
74
-                        penWidth: 1
75
-                        color: "black"
76
-                    }
77
-                }
78
-            }
79
-            Row {
80
-                spacing: 56
81
-
82
-                Text {
83
-                    text: "Percent TDS:"
84
-                }
85
-                TextInput {
86
-                    id: ptds
87
-
88
-                    width: 30
89
-                    validator: DoubleValidator {
90
-                        bottom: 0
91
-                        top: 100
92
-                        decimals: 2
93
-                        notation: DoubleValidator.StandardNotation
94
-                    }
95
-                    KeyNavigation.backtab: brewedMass
96
-
97
-                    Line {
98
-                        x1: -3; y1: ptds.height
99
-                        x2: 33; y2: y1
100
-                        penWidth: 1
101
-                        color: "black"
102
-                    }
103
-                }
104
-            }
105
-            Row {
106
-                spacing: 87
107
-
108
-                Text {
109
-                    id: colorlabel
110
-
111
-                    text: "Color:"
112
-                }
113
-                ColorPicker {
114
-                    id: colorpicker
22
+    ListView {
23
+        spacing: 3
24
+        height: 400
25
+        width: 100
26
+        z: -1
27
+        contentHeight: dataViewModel.count * 35
28
+
29
+        model: ListModel {
30
+            id: dataViewModel
31
+        }
32
+        delegate: Row {
33
+            spacing: 3
115 34
 
116
-                    width: 37; height: colorlabel.height
117
-                }
35
+            Rectangle {
36
+                width: 30; height: 30
37
+                color: dataViewModel.get(index).color
118 38
             }
119
-            Row {
120
-                id: lsfrow
121
-
122
-                visible: false
123
-                spacing: 1
124
-
39
+            Column {
125 40
                 Text {
126
-                    id: fitcolorlabel
127
-
128
-                    text: "Least Squares Fit Color:"
129
-                }
130
-                ColorPicker {
131
-                    id: fitcolorpicker
132
-
133
-                    width: 37; height: colorlabel.height
134
-
135
-                    onColorChanged: {
136
-                        graph.setFitColor(color)
137
-                    }
41
+                    text: "Strength: " + dataViewModel.get(index).ptds + "% TDS"
138 42
                 }
139
-            }
140
-            Rectangle {
141
-                id: plotButton
142
-
143
-                z: 0
144
-                anchors.horizontalCenter: parent.horizontalCenter
145
-                height: buttonText.height + 20; width: buttonText.width + 40
146
-                border.color: "black"
147
-                radius: 10
148
-
149 43
                 Text {
150
-                    id: buttonText
151
-
152
-                    text: "Plot This Brew"
153
-                    anchors {horizontalCenter: parent.horizontalCenter; verticalCenter: parent.verticalCenter}
154
-                }
155
-                MouseArea {
156
-                    anchors.fill: parent
157
-
158
-                    onClicked: {
159
-                        var extraction = (brewedMass.text * (ptds.text / 100)) / groundMass.text
160
-                        graph.plotPoint(extraction, (ptds.text / 100), colorpicker.color)
161
-                        dataViewModel.append({"color": colorpicker.color, "ptds": ptds.text, "extraction": extraction})
162
-                        root.n += 1
163
-                        root.sumy += (ptds.text / 100)
164
-                        root.sumx += extraction
165
-                        root.sumxy += ((ptds.text / 100) * extraction)
166
-                        root.sumxsq += Math.pow(extraction, 2)
167
-                        if(root.n > 1) {
168
-                            var a = ((root.sumy * root.sumxsq)-(root.sumx * root.sumxy))/((root.n * root.sumxsq)-Math.pow(root.sumx, 2))
169
-                            var b = ((root.n * root.sumxy)-(root.sumx * root.sumy))/((root.n * root.sumxsq) - Math.pow(root.sumx, 2))
170
-                            var x1 = 0.14
171
-                            var x2 = 0.26
172
-                            var y1 = a + (b * x1)
173
-                            var y2 = a + (b * x2)
174
-                            if(y1 < 0.008) {
175
-                                x1 = (0.008 - a) / b
176
-                                y1 = 0.008
177
-                            }
178
-                            if(y2 < 0.008) {
179
-                                x2 = (0.008 - a) / b
180
-                                y2 = 0.008
181
-                            }
182
-                            if(y1 > 0.016) {
183
-                                x1 = (0.016 - a) / b
184
-                                y1 = 0.016
185
-                            }
186
-                            if(y2 > 0.016) {
187
-                                x2 = (0.016 - a) / b
188
-                                y2 = 0.016
189
-                            }
190
-                            graph.setFit(x1, y1, x2, y2);
191
-                        }
192
-                    }
193
-                }
194
-            }
195
-            ListView {
196
-                spacing: 3
197
-                height: 400
198
-                width: 100
199
-                z: -1
200
-                contentHeight: dataViewModel.count * 35
201
-
202
-                model: ListModel {
203
-                    id: dataViewModel
204
-                }
205
-                delegate: Row {
206
-                    spacing: 3
207
-
208
-                    Rectangle {
209
-                        width: 30; height: 30
210
-                        color: dataViewModel.get(index).color
211
-                    }
212
-                    Column {
213
-                        Text {
214
-                            text: "Strength: " + dataViewModel.get(index).ptds + "% TDS"
215
-                        }
216
-                        Text {
217
-                            text: "Extraction: " + Number(dataViewModel.get(index).extraction * 100).toFixed(2) + "%"
218
-                        }
219
-                    }
44
+                    text: "Extraction: " + Number(dataViewModel.get(index).extraction * 100).toFixed(2) + "%"
220 45
                 }
221 46
             }
222 47
         }

Loading…
Cancel
Save