From e261b5c009ef67259b7b70f9a854c9f8cef7f4b6 Mon Sep 17 00:00:00 2001 From: Anne de Jong Date: Fri, 16 Dec 2016 07:05:46 +0100 Subject: [PATCH] Scatter plots, a duct can be placed in a system, which runs in mainwindow --- src/gui/add_duct_dialog.cpp | 9 ++++---- src/gui/add_duct_dialog.h | 9 +++++--- src/gui/mainwindow.cpp | 44 +++++++++++++++++++++++++++++++++---- src/gui/mainwindow.h | 4 ++++ src/gui/mainwindow.ui | 2 +- src/protobuf/duct.proto | 1 - src/protobuf/system.proto | 2 +- 7 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/gui/add_duct_dialog.cpp b/src/gui/add_duct_dialog.cpp index 54005a4..0ba9459 100644 --- a/src/gui/add_duct_dialog.cpp +++ b/src/gui/add_duct_dialog.cpp @@ -23,7 +23,7 @@ DECLARE_ENUM(PreviewShow,CSArea,Porosity,HydraulicRadius,SolidTemperatureFunctio -AddDuctDialog::AddDuctDialog(const us id,const std::string& name,QWidget* parent): +AddDuctDialog::AddDuctDialog(const std::string& name,QWidget* parent): QDialog(parent), _dialog(new Ui::add_duct_dialog), _duct(pb::Duct::default_instance()) @@ -32,7 +32,6 @@ AddDuctDialog::AddDuctDialog(const us id,const std::string& name,QWidget* parent _blocked = true; _dialog->setupUi(this); - _duct.set_id(id); _duct.set_name(name); QString title = "Add/edit duct segment '"; @@ -93,11 +92,13 @@ AddDuctDialog::AddDuctDialog(const us id,const std::string& name,QWidget* parent _dialog->gridtype->setCurrentIndex(0); // create a single graph in the QCP + QCPScatterStyle scatter; + scatter.setShape(QCPScatterStyle::ssDiamond); _plot->addGraph(); - + _plot->graph(0)->setLineStyle(QCPGraph::lsLine); + _plot->graph(0)->setScatterStyle(scatter); _duct.set_length(constants::default_L); - _duct.set_name("Unnamed"); _duct.set_dxb(0.01); _duct.set_dxmid(0.1); _duct.set_gridtype(pb::Linear); diff --git a/src/gui/add_duct_dialog.h b/src/gui/add_duct_dialog.h index 676ad0c..eb3c0a2 100644 --- a/src/gui/add_duct_dialog.h +++ b/src/gui/add_duct_dialog.h @@ -27,8 +27,12 @@ class AddDuctDialog: public QDialog { pb::Duct _duct; bool _blocked = false; public: - AddDuctDialog(const us id,const std::string& name,QWidget* parent = nullptr); + AddDuctDialog(const std::string& name,QWidget* parent = nullptr); ~AddDuctDialog(); + + void set(const pb::Duct&); + const pb::Duct& get() const {return _duct; } + private slots: void accept(); void reject(); @@ -50,11 +54,10 @@ private slots: void on_stempmodel_currentIndexChanged(int) {changed();} void on_previewshow_currentIndexChanged(int) {changed();} + private: // Called whenever the user changes a field void changed(); - void set(const pb::Duct&); - const pb::Duct& get() const {return _duct; } }; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index fb934a1..a806245 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -18,6 +18,8 @@ #include "tasmet_tracer.h" #include "add_duct_dialog.h" +const QString default_name = "Unnamed segment"; + TaSMETMainWindow::TaSMETMainWindow(): window(new Ui::MainWindow()) { @@ -48,8 +50,7 @@ TaSMETMainWindow::TaSMETMainWindow(): window->p0->setValidator(new QDoubleValidator(constants::min_p0, constants::max_p0, constants::field_decimals)); - - + window->name->setText(default_name); } TaSMETMainWindow::~TaSMETMainWindow(){ @@ -68,9 +69,44 @@ void TaSMETMainWindow::closeEvent(QCloseEvent *event) { } void TaSMETMainWindow::on_addsegment_clicked() { - AddDuctDialog dialog(0,"hola",this); + us id = window->segmentid_add->value(); + string name = window->name->text().toStdString(); + VARTRACE(15,name); + bool edit = false; - int rv = dialog.exec(); + AddDuctDialog dialog(name,this); + auto& ductmap = *_system.mutable_ducts(); + if(ductmap.find(id) != ductmap.end()) { + dialog.set(ductmap[id]); + } + + int code = dialog.exec(); + if(code == QDialog::Accepted) { + + VARTRACE(15,dialog.get().name()); + ductmap[id] = dialog.get(); + window->segmentid_add->setValue(id+1); + + } + + +} +void TaSMETMainWindow::on_segmentid_add_valueChanged(int id) { + + auto& ductmap = *_system.mutable_ducts(); + if(ductmap.find(id) != ductmap.end()) { + window->name->setText(QString::fromStdString(ductmap[id].name())); + } +} +void TaSMETMainWindow::on_name_textEdited() { + + auto& ductmap = *_system.mutable_ducts(); + int id = window->segmentid_add->value(); + + if(ductmap.find(id) != ductmap.end()) { + ductmap[id].set_name(window->name->text().toStdString()); + + } } ////////////////////////////////////////////////////////////////////// diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index f7fe063..44ca38f 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -10,6 +10,7 @@ #define MAINWINDOW_H #include "tasmet_config.h" #include +#include "protobuf/system.pb.h" namespace Ui{ class MainWindow; @@ -18,12 +19,15 @@ namespace Ui{ class TaSMETMainWindow: public QMainWindow { Q_OBJECT Ui::MainWindow *window; + pb::System _system; public: TaSMETMainWindow(); ~TaSMETMainWindow(); private slots: void closeEvent(QCloseEvent *event); void on_addsegment_clicked(); + void on_segmentid_add_valueChanged(int i); + void on_name_textEdited(); }; diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 49e11a5..22507d0 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -233,7 +233,7 @@ - Unnamed segment + diff --git a/src/protobuf/duct.proto b/src/protobuf/duct.proto index fb1befd..11e1045 100644 --- a/src/protobuf/duct.proto +++ b/src/protobuf/duct.proto @@ -30,7 +30,6 @@ enum SolidTemperatureModel { } message Duct { - required uint32 id = 1; required string name = 2; required double length = 3 [default = 1]; optional uint32 ngp = 4 [default = 100]; diff --git a/src/protobuf/system.proto b/src/protobuf/system.proto index d7a4348..99349fe 100644 --- a/src/protobuf/system.proto +++ b/src/protobuf/system.proto @@ -19,6 +19,6 @@ message System { required double p0 = 5; required double T0 = 6; - repeated Duct ducts = 7; + map ducts = 7; }