VPTissue Reference Manual
ExportActions.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "ExportActions.h"
21 
22 #include <QAction>
23 #include <QFileDialog>
24 #include <QMessageBox>
25 
26 using namespace std;
27 
28 namespace SimShell {
29 namespace Gui {
30 namespace ProjectActions {
31 
32 ExportActions::ExportActions(
33  const shared_ptr<Ws::IProject>& project,
34  const Session::ISession::ExportersType& exporters,
35  QWidget* parent)
36  : m_project(project), m_parent(parent)
37 {
38  for (auto& exporter : exporters) {
39  QAction* a = new QAction(QString::fromStdString(exporter.first) + " ...", this);
40  m_actions.push_back(a);
41  m_callback_map[a] = exporter;
42  connect(a, SIGNAL(triggered()), this, SLOT(SLOT_Trigger()));
43  }
44 }
45 
46 ExportActions::~ExportActions()
47 {
48 }
49 
50 const vector<QAction*>& ExportActions::GetActions() const
51 {
52  return m_actions;
53 }
54 
55 void ExportActions::SLOT_Trigger()
56 {
57  auto& exp = m_callback_map[sender()];
58  auto& exp_name = exp.first;
59  auto& exp_extension = exp.second.extension;
60  auto& exp_callback = exp.second.callback;
61 
62  QString dir = QString::fromStdString(m_project->GetPath());
63  QString filters = QString::fromStdString(exp_name) + " (*."
64  + QString::fromStdString(exp_extension) + ");;All Files (*)";
65  QFileDialog* fd = new QFileDialog(m_parent, "Export " + QString::fromStdString(exp_name),
66  dir, filters);
67  fd->setFileMode(QFileDialog::AnyFile);
68  fd->setAcceptMode(QFileDialog::AcceptSave);
69 
70  if (fd->exec() == QDialog::Accepted) {
71  QString path;
72  QStringList paths = fd->selectedFiles();
73  if (!paths.empty()) {
74  path = paths.first();
75  } else {
76  QMessageBox::warning(m_parent, "Error", "No filename given!");
77  emit static_cast<QAction*>(sender())->trigger();
78  return;
79  }
80 
81  // extract extension from filename
82  QFileInfo fi(path);
83  QString extension = fi.suffix();
84  if (extension.isEmpty()) {
85  extension = QString::fromStdString(exp_extension);
86  path += ".";
87  path += extension;
88  }
89 
90  // Perform export action
91  (exp_callback)(path.toStdString());
92  }
93 }
94 
95 } // namespace
96 } // namespace
97 } // namespace
STL namespace.
ExportActions header.
see the online Qt documentation
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32