瀏覽代碼

Merge branch 'native-control'

Neal Wilson 11 年之前
父節點
當前提交
6d104f2fd3
共有 5 個文件被更改,包括 154 次插入217 次删除
  1. 38
    36
      BrewPlot.pro
  2. 18
    8
      main.cpp
  3. 36
    0
      newpointcontrol.cpp
  4. 23
    0
      newpointcontrol.h
  5. 39
    173
      qml/BrewPlot/main.qml

+ 38
- 36
BrewPlot.pro 查看文件

@@ -1,36 +1,38 @@
1
-# Add more folders to ship with the application, here
2
-folder_01.source = qml/BrewPlot
3
-folder_01.target = qml
4
-DEPLOYMENTFOLDERS = folder_01
5
-
6
-# Additional import path used to resolve QML modules in Creator's code model
7
-QML_IMPORT_PATH =
8
-
9
-symbian:TARGET.UID3 = 0xE41BFE6C
10
-
11
-# Allow network access on Symbian
12
-symbian:TARGET.CAPABILITY += NetworkServices
13
-
14
-# Define QMLJSDEBUGGER to allow debugging of QML in debug builds
15
-# (This might significantly increase build time)
16
-# DEFINES += QMLJSDEBUGGER
17
-
18
-# If your application uses the Qt Mobility libraries, uncomment
19
-# the following lines and add the respective components to the 
20
-# MOBILITY variable. 
21
-# CONFIG += mobility
22
-# MOBILITY +=
23
-
24
-# The .cpp file which was generated for your project. Feel free to hack it.
25
-SOURCES += main.cpp \
26
-    qmllineitem.cpp
27
-
28
-# Please do not modify the following two lines. Required for deployment.
29
-include(qmlapplicationviewer/qmlapplicationviewer.pri)
30
-qtcAddDeployment()
31
-
32
-HEADERS += \
33
-    qmllineitem.h
34
-
35
-RESOURCES += \
36
-    qmlfiles.qrc
1
+# Add more folders to ship with the application, here
2
+folder_01.source = qml/BrewPlot
3
+folder_01.target = qml
4
+DEPLOYMENTFOLDERS = folder_01
5
+
6
+# Additional import path used to resolve QML modules in Creator's code model
7
+QML_IMPORT_PATH =
8
+
9
+symbian:TARGET.UID3 = 0xE41BFE6C
10
+
11
+# Allow network access on Symbian
12
+symbian:TARGET.CAPABILITY += NetworkServices
13
+
14
+# Define QMLJSDEBUGGER to allow debugging of QML in debug builds
15
+# (This might significantly increase build time)
16
+# DEFINES += QMLJSDEBUGGER
17
+
18
+# If your application uses the Qt Mobility libraries, uncomment
19
+# the following lines and add the respective components to the 
20
+# MOBILITY variable. 
21
+# CONFIG += mobility
22
+# MOBILITY +=
23
+
24
+# The .cpp file which was generated for your project. Feel free to hack it.
25
+SOURCES += main.cpp \
26
+    qmllineitem.cpp \
27
+    newpointcontrol.cpp
28
+
29
+# Please do not modify the following two lines. Required for deployment.
30
+include(qmlapplicationviewer/qmlapplicationviewer.pri)
31
+qtcAddDeployment()
32
+
33
+HEADERS += \
34
+    qmllineitem.h \
35
+    newpointcontrol.h
36
+
37
+RESOURCES += \
38
+    qmlfiles.qrc

+ 18
- 8
main.cpp 查看文件

@@ -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
 {
@@ -9,13 +10,29 @@ class QmlWindow : public QMainWindow
9 10
 public:
10 11
     QmlWindow(QWidget *parent = NULL);
11 12
     Q_INVOKABLE QAction *addMenuItem(QString menu, QString item);
13
+signals:
14
+    void newPoint(QVariantMap pointDescription);
12 15
 private:
13 16
     QHash<QString,QMenu *> menus;
14 17
 };
15 18
 
16 19
 QmlWindow::QmlWindow(QWidget *parent) : QMainWindow(parent)
17 20
 {
18
-
21
+    QmlApplicationViewer *viewer = new QmlApplicationViewer;
22
+    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
23
+    viewer->rootContext()->setContextProperty("window", this);
24
+    viewer->setSource(QUrl("qrc:/qml/qml/BrewPlot/main.qml"));
25
+    qApp->connect(viewer->engine(), SIGNAL(quit()), SLOT(quit()));
26
+    QWidget *central = new QWidget;
27
+    QHBoxLayout *layout = new QHBoxLayout;
28
+    NewPointControl *control = new NewPointControl;
29
+    layout->addWidget(control);
30
+    layout->addWidget(viewer);
31
+    central->setLayout(layout);
32
+    setCentralWidget(central);
33
+    viewer->setMinimumSize(viewer->sizeHint());
34
+    connect(control, SIGNAL(newPoint(QVariantMap)),
35
+            this, SIGNAL(newPoint(QVariantMap)));
19 36
 }
20 37
 
21 38
 QAction *QmlWindow::addMenuItem(QString menu, QString item)
@@ -44,13 +61,6 @@ int main(int argc, char *argv[])
44 61
 
45 62
     QmlWindow *window = new QmlWindow(NULL);
46 63
     window->setWindowTitle("BrewPlot");
47
-    QmlApplicationViewer *viewer = new QmlApplicationViewer;
48
-    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
49
-    viewer->rootContext()->setContextProperty("window", window);
50
-    viewer->setSource(QUrl("qrc:/qml/qml/BrewPlot/main.qml"));
51
-    app.connect(viewer->engine(), SIGNAL(quit()), SLOT(quit()));
52
-    window->setCentralWidget(viewer);
53
-    viewer->setMinimumSize(viewer->sizeHint());
54 64
     window->show();
55 65
 
56 66
     return app.exec();

+ 36
- 0
newpointcontrol.cpp 查看文件

@@ -0,0 +1,36 @@
1
+#include <QBoxLayout>
2
+#include <QFormLayout>
3
+#include <QLineEdit>
4
+#include <QPushButton>
5
+#include "newpointcontrol.h"
6
+
7
+NewPointControl::NewPointControl(QWidget *parent) :
8
+    QWidget(parent), groundsMass(new QLineEdit), brewMass(new QLineEdit),
9
+    tds(new QLineEdit)
10
+{
11
+    QVBoxLayout *layout = new QVBoxLayout;
12
+    QFormLayout *flayout = new QFormLayout;
13
+    QPushButton *plot = new QPushButton(tr("Plot"));
14
+    flayout->addRow(tr("Mass of ground coffee:"), groundsMass);
15
+    flayout->addRow(tr("Mass of brewed coffee:"), brewMass);
16
+    flayout->addRow(tr("% total dissolved solids:"), tds);
17
+    layout->addLayout(flayout);
18
+    layout->addWidget(plot);
19
+    layout->addStretch();
20
+    setLayout(layout);
21
+    connect(plot, SIGNAL(clicked()), this, SLOT(plotButtonClicked()));
22
+}
23
+
24
+void NewPointControl::plotButtonClicked()
25
+{
26
+    QVariantMap pointDescription;
27
+    pointDescription.insert("groundMass", groundsMass->text());
28
+    pointDescription.insert("brewedMass", brewMass->text());
29
+    pointDescription.insert("ptds", tds->text());
30
+    pointDescription.insert("color", "red");
31
+    double extraction = (brewMass->text().toDouble() *
32
+            (tds->text().toDouble() / 100)) /
33
+            groundsMass->text().toDouble();
34
+    pointDescription.insert("extraction", extraction);
35
+    emit newPoint(pointDescription);
36
+}

+ 23
- 0
newpointcontrol.h 查看文件

@@ -0,0 +1,23 @@
1
+#ifndef NEWPOINTCONTROL_H
2
+#define NEWPOINTCONTROL_H
3
+
4
+#include <QWidget>
5
+#include <QVariant>
6
+#include <QLineEdit>
7
+
8
+class NewPointControl : public QWidget
9
+{
10
+    Q_OBJECT
11
+public:
12
+    explicit NewPointControl(QWidget *parent = 0);
13
+signals:
14
+    void newPoint(QVariantMap pointDescription);
15
+public slots:
16
+    void plotButtonClicked();
17
+private:
18
+    QLineEdit *groundsMass;
19
+    QLineEdit *brewMass;
20
+    QLineEdit *tds;
21
+};
22
+
23
+#endif // NEWPOINTCONTROL_H

+ 39
- 173
qml/BrewPlot/main.qml 查看文件

@@ -10,8 +10,7 @@ Rectangle {
10 10
     property real sumxy : 0
11 11
     property int n : 0
12 12
 
13
-    width: 720
14
-    height: 680
13
+    width: 720; height: 680
15 14
 
16 15
     BrewingControlChart {
17 16
         id: graph
@@ -25,178 +24,9 @@ Rectangle {
25 24
         Column {
26 25
             spacing: 8
27 26
 
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
115
-
116
-                    width: 37; height: colorlabel.height
117
-                }
118
-            }
119
-            Row {
120
-                id: lsfrow
121
-
122
-                visible: false
123
-                spacing: 1
124
-
125
-                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
-                    }
138
-                }
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
-                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 27
             ListView {
196 28
                 spacing: 3
197
-                height: 400
198
-                width: 100
199
-                z: -1
29
+                height: 600; width: 100
200 30
                 contentHeight: dataViewModel.count * 35
201 31
 
202 32
                 model: ListModel {
@@ -221,6 +51,7 @@ Rectangle {
221 51
             }
222 52
         }
223 53
     }
54
+
224 55
     Component.onCompleted: {
225 56
         var quitItem = window.addMenuItem("File", "Quit");
226 57
         quitItem.shortcut = "Ctrl+Q";
@@ -242,7 +73,42 @@ Rectangle {
242 73
         showLeastSquares.checkable = true;
243 74
         showLeastSquares.triggered.connect(function() {
244 75
             graph.setFitVisible(showLeastSquares.checked);
245
-            lsfrow.visible = showLeastSquares.checked;
76
+        });
77
+        window.newPoint.connect(function(pointDescription) {
78
+            graph.plotPoint(pointDescription.extraction,
79
+                            pointDescription.ptds / 100,
80
+                            pointDescription.color)
81
+            dataViewModel.append(pointDescription)
82
+            root.n += 1
83
+            root.sumy += pointDescription.ptds / 100
84
+            root.sumx += pointDescription.extraction
85
+            root.sumxy += ((pointDescription.ptds / 100) * pointDescription.extraction)
86
+            root.sumxsq += Math.pow(pointDescription.extraction, 2)
87
+            if(root.n > 1) {
88
+                var a = ((root.sumy * root.sumxsq)-(root.sumx * root.sumxy))/((root.n * root.sumxsq)-Math.pow(root.sumx, 2))
89
+                var b = ((root.n * root.sumxy)-(root.sumx * root.sumy))/((root.n * root.sumxsq) - Math.pow(root.sumx, 2))
90
+                var x1 = 0.14
91
+                var x2 = 0.26
92
+                var y1 = a + (b * x1)
93
+                var y2 = a + (b * x2)
94
+                if(y1 < 0.008) {
95
+                    x1 = (0.008 - a) / b
96
+                    y1 = 0.008
97
+                }
98
+                if(y2 < 0.008) {
99
+                    x2 = (0.008 - a) / b
100
+                    y2 = 0.008
101
+                }
102
+                if(y1 > 0.016) {
103
+                    x1 = (0.016 - a) / b
104
+                    y2 = 0.016
105
+                }
106
+                if(y2 > 0.016) {
107
+                    x2 = (0.016 - a) / b
108
+                    y2 = 0.016
109
+                }
110
+                graph.setFit(x1, y1, x2, y2)
111
+            }
246 112
         });
247 113
     }
248 114
 }

Loading…
取消
儲存