27 #include <QHBoxLayout>
29 #include <QMessageBox>
30 #include <QPushButton>
33 #include <QWizardPage>
45 WorkspaceWizard::WorkspaceWizard(
const shared_ptr<IWorkspaceFactory>& f,
QWidget* parent)
46 :
QWizard(parent), m_workspace_factory(f)
48 setPage(Page_Path,
new PathPage(m_workspace_factory));
49 setPage(Page_Existing,
new ExistingPage(m_workspace_factory));
50 setPage(Page_Init,
new InitPage(m_workspace_factory));
51 setPage(Page_Done,
new DonePage(m_workspace_factory));
52 setWindowTitle(
"Workspace Setup");
57 if (field(
"workspace_path").isValid()) {
58 return field(
"workspace_path").toString().toStdString();
64 WorkspaceWizard::PathPage::PathPage(
const shared_ptr<IWorkspaceFactory>& f)
65 : m_workspace_factory(f)
67 setTitle(
"Workspace Setup");
68 setSubTitle(
"Please specify a workspace path.");
72 QLabel* label =
new QLabel(
"Path");
73 QLineEdit* edit_path =
new QLineEdit;
74 edit_path->setText(QDir::homePath() +
'/' + QString::fromStdString(m_workspace_factory->GetDefaultWorkspaceName()));
75 label->setBuddy(edit_path);
76 QPushButton* button_browse =
new QPushButton(
"Browse...");
78 QHBoxLayout* layout =
new QHBoxLayout;
79 layout->addWidget(label);
80 layout->addWidget(edit_path);
81 layout->addWidget(button_browse);
84 registerField(
"workspace_path", edit_path);
85 connect(button_browse, SIGNAL(clicked()),
this, SLOT(showBrowseDialog()));
88 int WorkspaceWizard::PathPage::nextId()
const
92 string workspace_path = field(
"workspace_path").toString().toStdString();
94 m_workspace_factory->CreateWorkspace(workspace_path);
100 catch(std::exception
const& e) {
108 void WorkspaceWizard::PathPage::showBrowseDialog()
113 dialog =
new QFileDialog(
this,
"Browse", QDir::homePath());
114 dialog->setAcceptMode(QFileDialog::AcceptOpen);
115 dialog->setFileMode(QFileDialog::Directory);
116 dialog->setOptions(QFileDialog::ShowDirsOnly);
117 connect(dialog, SIGNAL(fileSelected(
const QString &)),
this, SLOT(pathSelected(
const QString &)));
122 void WorkspaceWizard::PathPage::pathSelected(
const QString& path)
124 setField(
"workspace_path", path);
127 WorkspaceWizard::ExistingPage::ExistingPage(
const shared_ptr<IWorkspaceFactory>& f)
128 : m_workspace_factory(f)
130 setTitle(
"Existing workspace");
131 QLabel* label =
new QLabel(
"This workspace contains the following projects:");
132 projects =
new QListWidget;
133 QVBoxLayout* layout =
new QVBoxLayout;
134 layout->addWidget(label);
135 layout->addWidget(projects);
139 void WorkspaceWizard::ExistingPage::initializePage()
141 string workspace_path = field(
"workspace_path").toString().toStdString();
143 auto workspace = m_workspace_factory->CreateWorkspace(workspace_path);
145 for (
auto& project : *workspace) {
146 projects->addItem(QString::fromStdString(project.first));
148 setSubTitle(workspace_path.c_str());
154 int WorkspaceWizard::ExistingPage::nextId()
const
159 WorkspaceWizard::InitPage::InitPage(
const shared_ptr<IWorkspaceFactory>& f)
160 : m_workspace_factory(f)
162 setTitle(
"New workspace");
163 directory_label =
new QLabel(
"Given path is not an existing directory. Directory will be created for you.");
164 QVBoxLayout* layout =
new QVBoxLayout;
165 layout->addWidget(
new QLabel(
"A new workspace will be created at the given path."));
166 layout->addWidget(directory_label);
170 void WorkspaceWizard::InitPage::initializePage()
172 QString workspace_path = field(
"workspace_path").toString();
173 setSubTitle(workspace_path);
174 QDir d(workspace_path);
175 directory_label->setVisible(!d.exists());
178 int WorkspaceWizard::InitPage::nextId()
const
183 bool WorkspaceWizard::InitPage::validatePage()
187 QString workspace_path = field(
"workspace_path").toString();
188 QDir d(workspace_path);
190 if (!d.mkpath(workspace_path)) {
191 QMessageBox::warning(
this,
"Error",
"Could not create directory.");
196 m_workspace_factory->InitWorkspace(workspace_path.toStdString());
198 QMessageBox::warning(
this,
"Error", QString(
"Could not initialize workspace: ") + e.
what());
204 WorkspaceWizard::DonePage::DonePage(
const shared_ptr<IWorkspaceFactory>& f)
205 : m_workspace_factory(f)
207 setTitle(
"All Done!");
208 check_default =
new QCheckBox(
"Remember as default workspace.");
209 check_default->setChecked(
true);
210 QVBoxLayout* layout =
new QVBoxLayout;
211 layout->addWidget(check_default);
215 void WorkspaceWizard::DonePage::initializePage()
217 QString workspace_path = field(
"workspace_path").toString();
218 setSubTitle(workspace_path);
221 int WorkspaceWizard::DonePage::nextId()
const
226 bool WorkspaceWizard::DonePage::validatePage()
228 QString workspace_path = field(
"workspace_path").toString();
229 if (check_default->isChecked()) {
231 settings.setValue(
"workspace", workspace_path);
Interface for WorkspaceWizard.
std::string GetWorkspaceDir() const
After WorkspaceWizard::exec() returns QDialog::Accepted, this function will return workspace director...
Namespace for miscellaneous utilities.
virtual const char * what() const noexcept
Return error message.
Extremely simple Exception root class.
Interface for IWorkspaceFactory.
see the online Qt documentation
Interface for IWorkspace.
see the online Qt documentation
Header file for Exception class.
Namespace for generic graphical shell for simulators.