dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
savepage.cpp
Go to the documentation of this file.
1 
13 /*
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.
18  *
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.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include <QMessageBox>
29 #include "savepage.h"
30 #include "ui_savepage.h"
31 #include "setupwizard.h"
33 
34 SavePage::SavePage(SetupWizard *wizard, QWidget *parent)
35  : AbstractWizardPage(wizard, parent)
36  , ui(new Ui::SavePage)
37  , m_successfulWrite(false)
38 {
39  ui->setupUi(this);
40  connect(ui->saveButton, &QAbstractButton::clicked, this, &SavePage::writeToController);
41 }
42 
44 {
45  delete ui;
46 }
47 
49 {
50  return true;
51 }
52 
54 {
55  return m_successfulWrite;
56 }
57 
58 void SavePage::writeToController()
59 {
60  if (!getWizard()->getConnectionManager()->isConnected()) {
61  QMessageBox msgBox(this);
62  msgBox.setText(tr("An OpenPilot controller must be connected to your computer to save the "
63  "configuration.\nPlease connect your OpenPilot controller to your "
64  "computer and try again."));
65  msgBox.setStandardButtons(QMessageBox::Ok);
66  msgBox.setDefaultButton(QMessageBox::Ok);
67  msgBox.exec();
68  return;
69  }
70 
71  enableButtons(false);
73  connect(&helper, &VehicleConfigurationHelper::saveProgress, this, &SavePage::saveProgress);
74 
75  m_successfulWrite = helper.setupVehicle();
76 
77  disconnect(&helper, &VehicleConfigurationHelper::saveProgress, this, &SavePage::saveProgress);
78  ui->saveProgressLabel->setText(
79  QString("<font color='%1'>%2</font>")
80  .arg(m_successfulWrite ? "green" : "red", ui->saveProgressLabel->text()));
81  enableButtons(true);
82 
83  emit completeChanged();
84 }
85 
86 void SavePage::enableButtons(bool enable)
87 {
88  ui->saveButton->setEnabled(enable);
89  getWizard()->button(QWizard::NextButton)->setEnabled(enable);
90  getWizard()->button(QWizard::CancelButton)->setEnabled(enable);
91  getWizard()->button(QWizard::BackButton)->setEnabled(enable);
92  getWizard()->button(QWizard::CustomButton1)->setEnabled(enable);
93  QApplication::processEvents();
94 }
95 
96 void SavePage::saveProgress(int total, int current, QString description)
97 {
98  qDebug() << "Progress " << current << "(" << total << ")";
99  if (ui->saveProgressBar->maximum() != total) {
100  ui->saveProgressBar->setMaximum(total);
101  }
102  if (ui->saveProgressBar->value() != current) {
103  ui->saveProgressBar->setValue(current);
104  }
105  if (ui->saveProgressLabel->text() != description) {
106  ui->saveProgressLabel->setText(description);
107  }
108 }
The SetupWizard class is the main interface to the setup wizard. It provides selects the sequence of ...
Definition: setupwizard.h:47
SetupWizard * getWizard() const
bool isComplete() const
Definition: savepage.cpp:53
bool validatePage()
Definition: savepage.cpp:48
~SavePage()
Definition: savepage.cpp:43
void saveProgress(int total, int current, QString description)
The VehicleConfigurationHelper class provides an interface between the settings selected in the wizar...
SavePage(SetupWizard *wizard, QWidget *parent=nullptr)
Definition: savepage.cpp:34