LP-311 Remove basic/advanced stabilization tab auto-switch (autotune/txpid lock issues)
[librepilot.git] / ground / gcs / src / libs / utils / projectintropage.cpp
blob4cf4c43daba2d5f3a3fc3bb0cb74229c8fb700c1
1 /**
2 ******************************************************************************
4 * @file projectintropage.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @brief
8 * @see The GNU Public License (GPL) Version 3
9 * @defgroup
10 * @{
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "projectintropage.h"
30 #include "filewizardpage.h"
31 #include "ui_projectintropage.h"
33 #include <QMessageBox>
34 #include <QtCore/QDir>
35 #include <QtCore/QFileInfo>
37 namespace Utils {
38 struct ProjectIntroPagePrivate {
39 ProjectIntroPagePrivate();
40 Ui::ProjectIntroPage m_ui;
41 bool m_complete;
42 // Status label style sheets
43 const QString m_errorStyleSheet;
44 const QString m_warningStyleSheet;
45 const QString m_hintStyleSheet;
48 ProjectIntroPagePrivate::ProjectIntroPagePrivate() :
49 m_complete(false),
50 m_errorStyleSheet(QLatin1String("background : red;")),
51 m_warningStyleSheet(QLatin1String("background : yellow;")),
52 m_hintStyleSheet()
55 ProjectIntroPage::ProjectIntroPage(QWidget *parent) :
56 QWizardPage(parent),
57 m_d(new ProjectIntroPagePrivate)
59 m_d->m_ui.setupUi(this);
60 hideStatusLabel();
61 m_d->m_ui.nameLineEdit->setInitialText(tr("<Enter_Name>"));
62 m_d->m_ui.nameLineEdit->setFocus(Qt::TabFocusReason);
63 connect(m_d->m_ui.pathChooser, SIGNAL(changed(QString)), this, SLOT(slotChanged()));
64 connect(m_d->m_ui.nameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotChanged()));
65 connect(m_d->m_ui.pathChooser, SIGNAL(returnPressed()), this, SLOT(slotActivated()));
66 connect(m_d->m_ui.nameLineEdit, SIGNAL(validReturnPressed()), this, SLOT(slotActivated()));
69 void ProjectIntroPage::insertControl(int row, QWidget *label, QWidget *control)
71 m_d->m_ui.formLayout->insertRow(row, label, control);
74 ProjectIntroPage::~ProjectIntroPage()
76 delete m_d;
79 QString ProjectIntroPage::name() const
81 return m_d->m_ui.nameLineEdit->text();
84 QString ProjectIntroPage::path() const
86 return m_d->m_ui.pathChooser->path();
89 void ProjectIntroPage::setPath(const QString &path)
91 m_d->m_ui.pathChooser->setPath(path);
94 void ProjectIntroPage::setName(const QString &name)
96 m_d->m_ui.nameLineEdit->setText(name);
99 QString ProjectIntroPage::description() const
101 return m_d->m_ui.descriptionLabel->text();
104 void ProjectIntroPage::setDescription(const QString &description)
106 m_d->m_ui.descriptionLabel->setText(description);
109 void ProjectIntroPage::changeEvent(QEvent *e)
111 QWizardPage::changeEvent(e);
113 switch (e->type()) {
114 case QEvent::LanguageChange:
115 m_d->m_ui.retranslateUi(this);
116 break;
117 default:
118 break;
122 bool ProjectIntroPage::isComplete() const
124 return m_d->m_complete;
127 bool ProjectIntroPage::validate()
129 // Validate and display status
130 if (!m_d->m_ui.pathChooser->isValid()) {
131 displayStatusMessage(Error, m_d->m_ui.pathChooser->errorMessage());
132 return false;
135 // Name valid? Ignore 'DisplayingInitialText' state.
136 bool nameValid = false;
137 switch (m_d->m_ui.nameLineEdit->state()) {
138 case BaseValidatingLineEdit::Invalid:
139 displayStatusMessage(Error, m_d->m_ui.nameLineEdit->errorMessage());
140 return false;
142 case BaseValidatingLineEdit::DisplayingInitialText:
143 break;
144 case BaseValidatingLineEdit::Valid:
145 nameValid = true;
146 break;
149 // Check existence of the directory
150 QString projectDir = path();
151 projectDir += QDir::separator();
152 projectDir += m_d->m_ui.nameLineEdit->text();
153 const QFileInfo projectDirFile(projectDir);
154 if (!projectDirFile.exists()) { // All happy
155 hideStatusLabel();
156 return nameValid;
159 if (projectDirFile.isDir()) {
160 displayStatusMessage(Warning, tr("The project already exists."));
161 return nameValid;;
163 // Not a directory, but something else, likely causing directory creation to fail
164 displayStatusMessage(Error, tr("A file with that name already exists."));
165 return false;
168 void ProjectIntroPage::slotChanged()
170 const bool newComplete = validate();
172 if (newComplete != m_d->m_complete) {
173 m_d->m_complete = newComplete;
174 emit completeChanged();
178 void ProjectIntroPage::slotActivated()
180 if (m_d->m_complete) {
181 emit activated();
185 bool ProjectIntroPage::validateProjectDirectory(const QString &name, QString *errorMessage)
187 return ProjectNameValidatingLineEdit::validateProjectName(name, errorMessage);
190 void ProjectIntroPage::displayStatusMessage(StatusLabelMode m, const QString &s)
192 switch (m) {
193 case Error:
194 m_d->m_ui.stateLabel->setStyleSheet(m_d->m_errorStyleSheet);
195 break;
196 case Warning:
197 m_d->m_ui.stateLabel->setStyleSheet(m_d->m_warningStyleSheet);
198 break;
199 case Hint:
200 m_d->m_ui.stateLabel->setStyleSheet(m_d->m_hintStyleSheet);
201 break;
203 m_d->m_ui.stateLabel->setText(s);
206 void ProjectIntroPage::hideStatusLabel()
208 displayStatusMessage(Hint, QString());
210 } // namespace Utils