input_tank.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "input_tank.hpp"
  2. QtInputTank::QtInputTank(InitialState* _initial_state):QFrame(){
  3. initial_state=_initial_state;
  4. tank=initial_state->addTank();
  5. saturation_widget=new QWidget;
  6. left_right_widget=new QWidget;
  7. bottom_top_widget=new QWidget;
  8. main_layout=new QVBoxLayout;
  9. saturation_layout=new QHBoxLayout;
  10. left_right_layout=new QHBoxLayout;
  11. bottom_top_layout=new QHBoxLayout;
  12. saturation_label=new QLabel("Saturation: ");
  13. saturation_input=new QLineEdit(QString::number(tank->saturation));
  14. saturation_layout->addWidget(saturation_label);
  15. saturation_layout->addWidget(saturation_input);
  16. saturation_widget->setLayout(saturation_layout);
  17. left_label=new QLabel("Left: ");
  18. delta_left_label=new QLabel(" Left delta: ");
  19. left_input=new QLineEdit(QString::number(tank->left));
  20. delta_left_input=new QLineEdit(QString::number(tank->delta_left));
  21. right_label=new QLabel(" Right: ");
  22. delta_right_label=new QLabel(" Right delta: ");
  23. right_input=new QLineEdit(QString::number(tank->right));
  24. delta_right_input=new QLineEdit(QString::number(tank->delta_right));
  25. left_right_layout->addWidget(left_label);
  26. left_right_layout->addWidget(left_input,1);
  27. left_right_layout->addWidget(delta_left_label);
  28. left_right_layout->addWidget(delta_left_input,1);
  29. left_right_layout->addWidget(right_label);
  30. left_right_layout->addWidget(right_input,1);
  31. left_right_layout->addWidget(delta_right_label);
  32. left_right_layout->addWidget(delta_right_input,1);
  33. left_right_widget->setLayout(left_right_layout);
  34. bottom_label=new QLabel("Bottom: ");
  35. delta_bottom_label=new QLabel(" Bottom delta: ");
  36. bottom_input=new QLineEdit(QString::number(tank->bottom));
  37. delta_bottom_input=new QLineEdit(QString::number(tank->delta_bottom));
  38. top_label=new QLabel(" Top: ");
  39. delta_top_label=new QLabel(" Top delta: ");
  40. top_input=new QLineEdit(QString::number(tank->top));
  41. delta_top_input=new QLineEdit(QString::number(tank->delta_top));
  42. bottom_top_layout->addWidget(bottom_label);
  43. bottom_top_layout->addWidget(bottom_input,1);
  44. bottom_top_layout->addWidget(delta_bottom_label);
  45. bottom_top_layout->addWidget(delta_bottom_input,1);
  46. bottom_top_layout->addWidget(top_label);
  47. bottom_top_layout->addWidget(top_input,1);
  48. bottom_top_layout->addWidget(delta_top_label);
  49. bottom_top_layout->addWidget(delta_top_input,1);
  50. bottom_top_widget->setLayout(bottom_top_layout);
  51. remove_button=new QPushButton("Remove",this);
  52. main_layout->addWidget(saturation_widget);
  53. main_layout->addWidget(left_right_widget);
  54. main_layout->addWidget(bottom_top_widget);
  55. main_layout->addWidget(remove_button);
  56. double_validator=new QDoubleValidator;
  57. double_validator->setBottom(0);
  58. double_validator->setTop(1);
  59. saturation_input->setValidator(double_validator);
  60. left_input->setValidator(double_validator);
  61. right_input->setValidator(double_validator);
  62. bottom_input->setValidator(double_validator);
  63. top_input->setValidator(double_validator);
  64. delta_left_input->setValidator(double_validator);
  65. delta_right_input->setValidator(double_validator);
  66. delta_bottom_input->setValidator(double_validator);
  67. delta_top_input->setValidator(double_validator);
  68. setLayout(main_layout);
  69. setFrameShape(QFrame::Box);
  70. connect(remove_button,&QPushButton::clicked,this,&QtInputTank::emitRemove);
  71. }
  72. QWidget*
  73. QtInputTank::validate(){
  74. if(not saturation_input->hasAcceptableInput()) return saturation_input;
  75. if(not left_input->hasAcceptableInput()) return left_input;
  76. if(not right_input->hasAcceptableInput()) return right_input;
  77. if(not bottom_input->hasAcceptableInput()) return bottom_input;
  78. if(not top_input->hasAcceptableInput()) return top_input;
  79. if(not delta_left_input->hasAcceptableInput()) return delta_left_input;
  80. if(not delta_right_input->hasAcceptableInput()) return delta_right_input;
  81. if(not delta_bottom_input->hasAcceptableInput()) return delta_bottom_input;
  82. if(not delta_top_input->hasAcceptableInput()) return delta_top_input;
  83. double s,l,r,t,b,sl,sr,st,sb;
  84. s=saturation_input->text().toDouble();
  85. l=left_input->text().toDouble();
  86. r=right_input->text().toDouble();
  87. t=top_input->text().toDouble();
  88. b=bottom_input->text().toDouble();
  89. if(l>=r) return right_input;
  90. if(b>=t) return top_input;
  91. sl=delta_left_input->text().toDouble();
  92. sr=delta_right_input->text().toDouble();
  93. st=delta_top_input->text().toDouble();
  94. sb=delta_bottom_input->text().toDouble();
  95. tank->saturation=s;
  96. tank->left=l;
  97. tank->right=r;
  98. tank->bottom=b;
  99. tank->top=t;
  100. tank->delta_left=sl;
  101. tank->delta_right=sr;
  102. tank->delta_bottom=sb;
  103. tank->delta_top=st;
  104. return nullptr;
  105. }