Scatter plots, a duct can be placed in a system, which runs in mainwindow

This commit is contained in:
Anne de Jong 2016-12-16 07:05:46 +01:00
parent ff398f4602
commit e261b5c009
7 changed files with 57 additions and 14 deletions

View File

@ -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);

View File

@ -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; }
};

View File

@ -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());
}
}
//////////////////////////////////////////////////////////////////////

View File

@ -10,6 +10,7 @@
#define MAINWINDOW_H
#include "tasmet_config.h"
#include <QMainWindow>
#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();
};

View File

@ -233,7 +233,7 @@
<item row="2" column="1">
<widget class="QLineEdit" name="name">
<property name="text">
<string>Unnamed segment</string>
<string/>
</property>
</widget>
</item>

View File

@ -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];

View File

@ -19,6 +19,6 @@ message System {
required double p0 = 5;
required double T0 = 6;
repeated Duct ducts = 7;
map<uint32,Duct> ducts = 7;
}