Quellcode durchsuchen

Native control outputs point description, basic plotting works.

Neal Wilson vor 12 Jahren
Ursprung
Commit
444d8cd010
4 geänderte Dateien mit 48 neuen und 21 gelöschten Zeilen
  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 Datei anzeigen

@@ -10,13 +10,29 @@ class QmlWindow : public QMainWindow
10 10
 public:
11 11
     QmlWindow(QWidget *parent = NULL);
12 12
     Q_INVOKABLE QAction *addMenuItem(QString menu, QString item);
13
+signals:
14
+    void newPoint(QVariantMap pointDescription);
13 15
 private:
14 16
     QHash<QString,QMenu *> menus;
15 17
 };
16 18
 
17 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 38
 QAction *QmlWindow::addMenuItem(QString menu, QString item)
@@ -45,19 +61,6 @@ int main(int argc, char *argv[])
45 61
 
46 62
     QmlWindow *window = new QmlWindow(NULL);
47 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 64
     window->show();
62 65
 
63 66
     return app.exec();

+ 17
- 4
newpointcontrol.cpp Datei anzeigen

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

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

+ 6
- 0
qml/BrewPlot/main.qml Datei anzeigen

@@ -69,5 +69,11 @@ Rectangle {
69 69
             graph.setFitVisible(showLeastSquares.checked);
70 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
 }

Laden…
Abbrechen
Speichern