mainwindow.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. void
  23. QtMainWindow::new_input(){
  24. input=new QtInput;
  25. setCentralWidget(input);
  26. connect(input,&QtInput::run_signal,this,&QtMainWindow::run_input);
  27. connect(input,&QtInput::exit_signal,this,&QtMainWindow::exit_input);
  28. new_act->setEnabled(false);
  29. load_act->setEnabled(false);
  30. }
  31. void
  32. QtMainWindow::run_input(){
  33. /*disconnect(input,nullptr,nullptr,nullptr);
  34. new_act->setEnabled(false);
  35. load_act->setEnabled(false);
  36. kernel=new Kernel(input->getPhysics(),input->getTime(),input->getGeometry());
  37. delete input;
  38. input=nullptr;
  39. view_solution=new QtViewSolution(kernel);
  40. setCentralWidget(view_solution);*/
  41. }
  42. void
  43. QtMainWindow::exit_input(){
  44. disconnect(input,nullptr,nullptr,nullptr);
  45. delete input;
  46. input=nullptr;
  47. setCentralWidget(nullptr);
  48. new_act->setEnabled(true);
  49. load_act->setEnabled(true);
  50. }
  51. void
  52. QtMainWindow::load_input(){
  53. QString filename=QFileDialog::getOpenFileName(this,"Load input","inputs/","QT input file (*.input)");
  54. input=new QtInput(filename);
  55. //input=new QtInput;
  56. setCentralWidget(input);
  57. connect(input,&QtInput::run_signal,this,&QtMainWindow::run_input);
  58. connect(input,&QtInput::exit_signal,this,&QtMainWindow::exit_input);
  59. new_act->setEnabled(false);
  60. load_act->setEnabled(false);
  61. }
  62. void
  63. QtMainWindow::exit(){
  64. QApplication::quit();
  65. }