Browse Source

Native control outputs point description, basic plotting works.

Neal Wilson 11 years ago
parent
commit
444d8cd010
4 changed files with 48 additions and 21 deletions
  1. 17
    14
      main.cpp
  2. 17
    4
      newpointcontrol.cpp
  3. 8
    3
      newpointcontrol.h
  4. 6
    0
      qml/BrewPlot/main.qml

+ 17
- 14
main.cpp View File

10
 public:
10
 public:
11
     QmlWindow(QWidget *parent = NULL);
11
     QmlWindow(QWidget *parent = NULL);
12
     Q_INVOKABLE QAction *addMenuItem(QString menu, QString item);
12
     Q_INVOKABLE QAction *addMenuItem(QString menu, QString item);
13
+signals:
14
+    void newPoint(QVariantMap pointDescription);
13
 private:
15
 private:
14
     QHash<QString,QMenu *> menus;
16
     QHash<QString,QMenu *> menus;
15
 };
17
 };
16
 
18
 
17
 QmlWindow::QmlWindow(QWidget *parent) : QMainWindow(parent)
19
 QmlWindow::QmlWindow(QWidget *parent) : QMainWindow(parent)
18
 {
20
 {
19
-
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)));
20
 }
36
 }
21
 
37
 
22
 QAction *QmlWindow::addMenuItem(QString menu, QString item)
38
 QAction *QmlWindow::addMenuItem(QString menu, QString item)
45
 
61
 
46
     QmlWindow *window = new QmlWindow(NULL);
62
     QmlWindow *window = new QmlWindow(NULL);
47
     window->setWindowTitle("BrewPlot");
63
     window->setWindowTitle("BrewPlot");
48
-    QmlApplicationViewer *viewer = new QmlApplicationViewer;
49
-    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
50
-    viewer->rootContext()->setContextProperty("window", window);
51
-    viewer->setSource(QUrl("qrc:/qml/qml/BrewPlot/main.qml"));
52
-    app.connect(viewer->engine(), SIGNAL(quit()), SLOT(quit()));
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);
60
-    viewer->setMinimumSize(viewer->sizeHint());
61
     window->show();
64
     window->show();
62
 
65
 
63
     return app.exec();
66
     return app.exec();

+ 17
- 4
newpointcontrol.cpp View File

5
 #include "newpointcontrol.h"
5
 #include "newpointcontrol.h"
6
 
6
 
7
 NewPointControl::NewPointControl(QWidget *parent) :
7
 NewPointControl::NewPointControl(QWidget *parent) :
8
-    QWidget(parent)
8
+    QWidget(parent), groundsMass(new QLineEdit), brewMass(new QLineEdit),
9
+    tds(new QLineEdit)
9
 {
10
 {
10
     QVBoxLayout *layout = new QVBoxLayout;
11
     QVBoxLayout *layout = new QVBoxLayout;
11
     QFormLayout *flayout = new QFormLayout;
12
     QFormLayout *flayout = new QFormLayout;
12
-    QLineEdit *groundsMass = new QLineEdit;
13
-    QLineEdit *brewMass = new QLineEdit;
14
-    QLineEdit *tds = new QLineEdit;
15
     QPushButton *plot = new QPushButton(tr("Plot"));
13
     QPushButton *plot = new QPushButton(tr("Plot"));
16
     flayout->addRow(tr("Mass of ground coffee:"), groundsMass);
14
     flayout->addRow(tr("Mass of ground coffee:"), groundsMass);
17
     flayout->addRow(tr("Mass of brewed coffee:"), brewMass);
15
     flayout->addRow(tr("Mass of brewed coffee:"), brewMass);
20
     layout->addWidget(plot);
18
     layout->addWidget(plot);
21
     layout->addStretch();
19
     layout->addStretch();
22
     setLayout(layout);
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);
23
 }
36
 }

+ 8
- 3
newpointcontrol.h View File

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

+ 6
- 0
qml/BrewPlot/main.qml View File

69
             graph.setFitVisible(showLeastSquares.checked);
69
             graph.setFitVisible(showLeastSquares.checked);
70
             lsfrow.visible = showLeastSquares.checked;
70
             lsfrow.visible = showLeastSquares.checked;
71
         });
71
         });
72
+        window.newPoint.connect(function(pointDescription) {
73
+            graph.plotPoint(pointDescription.extraction,
74
+                            pointDescription.ptds / 100,
75
+                            pointDescription.color)
76
+            dataviewModel.append(pointDescription)
77
+        });
72
     }
78
     }
73
 }
79
 }

Loading…
Cancel
Save