27 #include <QGridLayout>
28 #include <QHBoxLayout>
36 NewProjectDialog::NewProjectDialog(
const shared_ptr<IWorkspaceFactory>& f,
QWidget* parent)
38 m_workspace_model(f->CreateWorkspace(f->GetWorkspaceTemplatePath()))
40 setWindowTitle(
"New Project");
45 QVBoxLayout* layout =
new QVBoxLayout;
47 QHBoxLayout* layout_name =
new QHBoxLayout;
48 QLabel* label_name =
new QLabel(
"Name:");
49 m_edit_name =
new QLineEdit;
50 m_edit_name->setText(
"untitled");
51 m_edit_name->selectAll();
52 label_name->setBuddy(m_edit_name);
53 layout_name->addWidget(label_name);
54 layout_name->addWidget(m_edit_name);
55 layout->addLayout(layout_name);
57 QLabel* label_info =
new QLabel(
"Please specify a file to initialize project with:");
58 layout->addWidget(label_info);
60 QVBoxLayout* layout_f =
new QVBoxLayout;
61 QHBoxLayout* layout_default =
new QHBoxLayout;
62 m_radio_default =
new QRadioButton(
"Copy project from template workspace:");
63 m_radio_default->setChecked(
true);
64 m_combo_models =
new QComboBox;
65 vector<string> project_list;
66 for (
auto& project : *m_workspace_model) {
67 project_list.push_back(project.first);
69 for (vector<string>::const_iterator it = project_list.begin(); it != project_list.end(); it++) {
70 m_combo_models->addItem(it->c_str());
72 layout_default->addWidget(m_radio_default);
73 layout_default->addWidget(m_combo_models);
74 layout_f->addLayout(layout_default);
75 QHBoxLayout* layout_custom =
new QHBoxLayout;
76 m_radio_custom =
new QRadioButton(
"Use the following file:");
77 m_edit_custom =
new QLineEdit;
78 m_edit_custom->setEnabled(
false);
79 QPushButton* button_browse =
new QPushButton(
"Browse...");
80 button_browse->setEnabled(
false);
81 layout_custom->addWidget(m_radio_custom);
82 layout_custom->addWidget(m_edit_custom);
83 layout_custom->addWidget(button_browse);
84 layout_f->addLayout(layout_custom);
85 layout->addLayout(layout_f);
89 QHBoxLayout* layout_buttons =
new QHBoxLayout;
90 m_button_ok =
new QPushButton(
"OK");
91 m_button_ok->setDefault(
true);
92 m_button_cancel =
new QPushButton(
"Cancel");
93 layout_buttons->addStretch();
94 layout_buttons->addWidget(m_button_cancel);
95 layout_buttons->addWidget(m_button_ok);
96 layout->addLayout(layout_buttons);
100 connect(m_edit_name, SIGNAL(textChanged(
const QString &)),
this, SLOT(ProjectNameChanged(
const QString &)));
101 connect(m_radio_custom, SIGNAL(toggled(
bool)), m_edit_custom, SLOT(setEnabled(
bool)));
102 connect(m_radio_custom, SIGNAL(toggled(
bool)), button_browse, SLOT(setEnabled(
bool)));
103 connect(m_radio_default, SIGNAL(toggled(
bool)),
this, SLOT(FileChanged(
bool)));
104 connect(m_edit_custom, SIGNAL(textChanged(
const QString &)),
this, SLOT(FileChanged(
const QString &)));
105 connect(button_browse, SIGNAL(clicked()),
this, SLOT(ShowBrowseDialog()));
106 connect(m_button_ok, SIGNAL(clicked()),
this, SLOT(Ok()));
107 connect(m_button_cancel, SIGNAL(clicked()),
this, SLOT(Cancel()));
109 project_name_ok =
true;
113 void NewProjectDialog::Cancel()
118 string NewProjectDialog::GetSrcPath()
const
120 return m_edit_custom->text().toStdString();
123 IWorkspace::ConstProjectIterator NewProjectDialog::GetSrcProject()
const
125 std::string project_name = m_combo_models->currentText().toStdString();
126 return m_workspace_model->Find(project_name);
129 string NewProjectDialog::GetProjectName()
const
131 return m_edit_name->text().toStdString();
134 void NewProjectDialog::FileChanged(
bool use_default)
136 file_ok = use_default || m_edit_custom->text().length();
140 void NewProjectDialog::FileChanged(QString
const& f)
142 file_ok = m_radio_default->isChecked() || f.length();
146 bool NewProjectDialog::IsCopyProject()
const
148 return m_radio_default->isChecked();
151 void NewProjectDialog::ProjectNameChanged(QString
const& name)
153 project_name_ok = name.length();
157 void NewProjectDialog::Ok()
162 void NewProjectDialog::ShowBrowseDialog()
167 m_dialog =
new QFileDialog(
this,
"Browse", QDir::homePath(),
"XML files (*.xml)");
168 m_dialog->setAcceptMode(QFileDialog::AcceptOpen);
169 m_dialog->setFileMode(QFileDialog::ExistingFile);
170 connect(m_dialog, SIGNAL(fileSelected(
const QString &)), m_edit_custom, SLOT(setText(
const QString &)));
175 void NewProjectDialog::ValidateForm()
177 m_button_ok->setEnabled(project_name_ok && file_ok);
Interface for NewProjectDialog.
Interface for IWorkspaceFactory.
Interface for IWorkspace.
see the online Qt documentation
Namespace for generic graphical shell for simulators.
see the online Qt documentation