26 #include <QCloseEvent>
27 #include <QDockWidget>
29 #include <QMessageBox>
38 namespace Controller {
40 AppController::AppController(
const shared_ptr<Gui::IFactory>& f,
QWidget* p)
43 m_settings(QString::fromStdString(f->GetOrganizationName()), QString::fromStdString(f->GetApplicationName())),
44 m_workspace_controller(f->CreateWorkspaceFactory(),
this)
52 AppController::~AppController()
56 void AppController::closeEvent(QCloseEvent* event)
58 if (m_workspace_controller) {
59 m_workspace_controller->SetUserData(
"recently_opened.project",
60 ptree(m_workspace_controller.Project().GetOpenedProjectName()));
61 m_workspace_controller->SetUserData(
"recently_opened.file",
62 ptree(m_workspace_controller.Project().GetOpenedFileName()));
63 m_settings.setValue(
"workspace", QString::fromStdString(m_workspace_controller->GetPath()));
65 m_settings.remove(
"workspace");
68 if (m_workspace_controller.PromptClose()) {
75 ptree AppController::GetPTreeState()
const
78 state.put_child(
"workspace_controller", m_workspace_controller.GetPTreeState());
79 state.put_child(
"workspace_preferences_dock", PTreeQtState::GetDockWidgetArea(
this, m_workspace_controller.GetPreferencesDock()));
80 state.put_child(
"project_parameters_dock", PTreeQtState::GetDockWidgetArea(
this, m_workspace_controller.Project().GetParametersDock()));
81 state.put_child(
"project_preferences_dock", PTreeQtState::GetDockWidgetArea(
this, m_workspace_controller.Project().GetPreferencesDock()));
82 state.put_child(
"widget", PTreeQtState::GetWidgetState(
this));
86 AppController::Timings AppController::GetTimings()
const
88 return m_workspace_controller.Project().GetTimings();
91 void AppController::InitMenu()
93 auto menu = menuBar();
96 auto menu_file = menu->addMenu(
"&File");
97 menu_file->addAction(m_workspace_controller.GetActionNewProject());
98 menu_file->addSeparator();
99 menu_file->addAction(m_workspace_controller.GetView()->GetOpenAction());
100 menu_file->addAction(m_workspace_controller.GetView()->GetRenameAction());
101 menu_file->addAction(m_workspace_controller.GetView()->GetRemoveAction());
102 menu_file->addSeparator();
103 menu_file->addMenu(m_workspace_controller.Project().GetExportMenu());
104 menu_file->addSeparator();
105 menu_file->addAction(m_workspace_controller.GetActionRefreshWorkspace());
106 menu_file->addAction(
"Switch Workspace...",
this, SLOT(SLOT_WorkspaceWizard()));
107 menu_file->addSeparator();
108 menu_file->addAction(m_workspace_controller.Project().GetActionClose());
109 auto action_exit = menu_file->addAction(
"E&xit",
this, SLOT(close()));
110 action_exit->setShortcut(QKeySequence(
"Ctrl+Q"));
113 auto menu_edit = menu->addMenu(
"&Edit");
114 menu_edit->addMenu(m_workspace_controller.Project().GetParametersMenu());
115 menu_edit->addSeparator();
116 menu_edit->addMenu(m_workspace_controller.Project().GetPreferencesMenu());
117 menu_edit->addMenu(m_workspace_controller.GetPreferencesMenu());
120 menu->addMenu(m_workspace_controller.Project().GetViewersMenu());
123 menu->addMenu(m_workspace_controller.Project().GetSimulationMenu());
126 auto menu_help = menu->addMenu(
"&Help");
127 menu_help->addAction(
"About",
this, SLOT(SLOT_AboutDialog()));
130 void AppController::InitProject()
132 if (m_workspace_controller) {
133 auto p = m_workspace_controller->Find(
134 m_workspace_controller->GetUserData(
"recently_opened.project").get_value<
string>());
135 if (p != m_workspace_controller->end()) {
136 auto project = p->second.Project();
137 auto f = project->Find(
138 m_workspace_controller->GetUserData(
"recently_opened.file").get_value<
string>());
139 if (f != project->end()) {
141 m_workspace_controller.Project().Set(p->first, project);
147 void AppController::InitWidgets()
149 setWindowTitle(QString::fromStdString(m_factory->GetApplicationName()));
150 setCentralWidget(m_workspace_controller.GetView());
152 m_log_dock =
new LogWindow(
this);
153 addDockWidget(Qt::BottomDockWidgetArea, m_log_dock);
155 auto workspace_preferences_dock = m_workspace_controller.GetPreferencesDock();
156 addDockWidget(Qt::RightDockWidgetArea, workspace_preferences_dock);
157 workspace_preferences_dock->hide();
159 auto project_preferences_dock = m_workspace_controller.Project().GetPreferencesDock();
160 addDockWidget(Qt::RightDockWidgetArea, project_preferences_dock);
161 project_preferences_dock->hide();
163 auto project_parameters_dock = m_workspace_controller.Project().GetParametersDock();
164 addDockWidget(Qt::RightDockWidgetArea, project_parameters_dock);
167 void AppController::InitWorkspace()
169 const string workspace = m_settings.value(
"workspace").toString().toStdString();
170 m_workspace_controller.Open(workspace);
171 SetWorkspaceWindowTitle(workspace);
173 if (!m_workspace_controller) {
174 SLOT_WorkspaceWizard();
178 void AppController::Log(
const string& s)
180 m_log_dock->AddLine(s);
183 void AppController::SetPTreeState(
const ptree& state)
185 auto widget_state = state.get_child_optional(
"widget");
187 PTreeQtState::SetWidgetState(
this, widget_state.get());
190 auto workspace_preferences_dock_state = state.get_child_optional(
"workspace_preferences_dock");
191 if (workspace_preferences_dock_state) {
192 PTreeQtState::SetDockWidgetArea(
this,
193 m_workspace_controller.GetPreferencesDock(), workspace_preferences_dock_state.get());
196 auto project_parameters_dock_state = state.get_child_optional(
"project_parameters_dock");
197 if (project_parameters_dock_state) {
198 PTreeQtState::SetDockWidgetArea(
this,
199 m_workspace_controller.Project().GetParametersDock(), project_parameters_dock_state.get());
202 auto project_preferences_dock_state = state.get_child_optional(
"project_preferences_dock");
203 if (project_preferences_dock_state) {
204 PTreeQtState::SetDockWidgetArea(
this,
205 m_workspace_controller.Project().GetPreferencesDock(), project_preferences_dock_state.get());
208 auto workspace_controller_state = state.get_child_optional(
"workspace_controller");
209 if (workspace_controller_state) {
210 m_workspace_controller.SetPTreeState(workspace_controller_state.get());
214 void AppController::SetWorkspaceWindowTitle(
const string& d)
216 setWindowTitle(QString::fromStdString(m_factory->GetApplicationName() +
": " + d));
219 void AppController::SLOT_AboutDialog()
221 QMessageBox::about(
this,
222 QString::fromStdString(m_factory->GetApplicationName()),
223 QString::fromStdString(m_factory->GetAbout()));
226 void AppController::SLOT_WorkspaceWizard()
228 auto& p = m_workspace_controller.Project();
232 WorkspaceWizard w(m_factory->CreateWorkspaceFactory());
233 if (w.exec() == QDialog::Accepted) {
234 m_workspace_controller.Open(w.GetWorkspaceDir());
235 SetWorkspaceWindowTitle(w.GetWorkspaceDir());
Interface for WorkspaceWizard.
Interface for PTreeQtState.
see the online Qt documentation
Interface for WorkspaceView.
see the online Qt documentation
Namespace for generic graphical shell for simulators.