mainwindow.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "mainwindow.hpp"
  2. QtMainWindow::QtMainWindow():QMainWindow(){
  3. input=nullptr;
  4. view_solution=nullptr;
  5. //Actions
  6. new_act=new QAction("New input",this);
  7. load_act=new QAction("Load input",this);
  8. exit_act=new QAction("Exit",this);
  9. //Menu bar
  10. input_menu=menuBar()->addMenu("File");
  11. input_menu->addAction(new_act);
  12. input_menu->addAction(load_act);
  13. input_menu->addAction(exit_act);
  14. connect(new_act,&QAction::triggered,this,&QtMainWindow::new_input);
  15. connect(load_act,&QAction::triggered,this,&QtMainWindow::load_input);
  16. connect(exit_act,&QAction::triggered,this,&QtMainWindow::exit);
  17. }
  18. QtMainWindow::QtMainWindow(string filename):QtMainWindow(){
  19. input=new QtInput(QString::fromStdString(filename));
  20. run_input();
  21. }
  22. QtMainWindow::~QtMainWindow(){
  23. }
  24. void
  25. QtMainWindow::new_input(){
  26. input=new QtInput;
  27. setCentralWidget(input);
  28. connect(input,&QtInput::run_signal,this,&QtMainWindow::run_input);
  29. connect(input,&QtInput::exit_signal,this,&QtMainWindow::exit_input);
  30. new_act->setEnabled(false);
  31. load_act->setEnabled(false);
  32. }
  33. void
  34. QtMainWindow::run_input(){
  35. /*disconnect(input,nullptr,nullptr,nullptr);
  36. new_act->setEnabled(false);
  37. load_act->setEnabled(false);
  38. kernel=new Kernel(input->getPhysics(),input->getTime(),input->getGeometry());
  39. delete input;
  40. input=nullptr;
  41. view_solution=new QtViewSolution(kernel);
  42. setCentralWidget(view_solution);*/
  43. }
  44. void
  45. QtMainWindow::exit_input(){
  46. disconnect(input,nullptr,nullptr,nullptr);
  47. delete input;
  48. input=nullptr;
  49. setCentralWidget(nullptr);
  50. new_act->setEnabled(true);
  51. load_act->setEnabled(true);
  52. }
  53. void
  54. QtMainWindow::load_input(){
  55. QString filename=QFileDialog::getOpenFileName(this,"Load input","inputs/","QT input file (*.input)");
  56. input=new QtInput(filename);
  57. //input=new QtInput;
  58. setCentralWidget(input);
  59. connect(input,&QtInput::run_signal,this,&QtMainWindow::run_input);
  60. connect(input,&QtInput::exit_signal,this,&QtMainWindow::exit_input);
  61. new_act->setEnabled(false);
  62. load_act->setEnabled(false);
  63. }
  64. void
  65. QtMainWindow::exit(){
  66. QApplication::quit();
  67. }