2 ******************************************************************************
4 * @file importsummary.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015
6 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011
7 * @addtogroup GCSPlugins GCS Plugins
9 * @addtogroup UAVSettingsImportExport UAVSettings Import/Export Plugin
11 * @brief UAVSettings Import/Export Plugin
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
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
28 #include "importsummary.h"
31 #include <QDesktopServices>
34 ImportSummaryDialog::ImportSummaryDialog(QWidget
*parent
) :
36 ui(new Ui::ImportSummaryDialog
)
39 setWindowTitle(tr("Import Summary"));
41 ui
->importSummaryList
->setColumnCount(3);
42 ui
->importSummaryList
->setRowCount(0);
44 header
.append("Save");
45 header
.append("Name");
46 header
.append("Status");
47 ui
->importSummaryList
->setHorizontalHeaderLabels(header
);
48 ui
->progressBar
->setValue(0);
50 connect(ui
->closeButton
, SIGNAL(clicked()), this, SLOT(close()));
51 connect(ui
->saveToFlash
, SIGNAL(clicked()), this, SLOT(doTheSaving()));
53 // Connect the help button
54 connect(ui
->helpButton
, SIGNAL(clicked()), this, SLOT(openHelp()));
57 ImportSummaryDialog::~ImportSummaryDialog()
63 Open the right page on the wiki
65 void ImportSummaryDialog::openHelp()
67 QDesktopServices::openUrl(QUrl(QString(WIKI_URL_ROOT
) + QString("UAV+Settings+Import-Export"),
72 Adds a new line about a UAVObject along with its status
73 (whether it got saved OK or not)
75 void ImportSummaryDialog::addLine(QString uavObjectName
, QString text
, bool status
)
77 ui
->importSummaryList
->setRowCount(ui
->importSummaryList
->rowCount() + 1);
78 int row
= ui
->importSummaryList
->rowCount() - 1;
79 ui
->importSummaryList
->setCellWidget(row
, 0, new QCheckBox(ui
->importSummaryList
));
80 QTableWidgetItem
*objName
= new QTableWidgetItem(uavObjectName
);
81 ui
->importSummaryList
->setItem(row
, 1, objName
);
82 QCheckBox
*box
= dynamic_cast<QCheckBox
*>(ui
->importSummaryList
->cellWidget(row
, 0));
83 ui
->importSummaryList
->setItem(row
, 2, new QTableWidgetItem(text
));
85 // Disable editability and selectability in table elements
86 ui
->importSummaryList
->item(row
, 1)->setFlags(ui
->importSummaryList
->item(row
, 1)->flags() &= ~Qt::ItemIsEditable
);
87 ui
->importSummaryList
->item(row
, 2)->setFlags(ui
->importSummaryList
->item(row
, 2)->flags() &= ~Qt::ItemIsEditable
);
90 box
->setChecked(true);
92 box
->setChecked(false);
93 box
->setEnabled(false);
97 this->showEvent(NULL
);
101 Saves every checked UAVObjet in the list to Flash
103 void ImportSummaryDialog::doTheSaving()
106 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
107 UAVObjectManager
*objManager
= pm
->getObject
<UAVObjectManager
>();
108 UAVObjectUtilManager
*utilManager
= pm
->getObject
<UAVObjectUtilManager
>();
110 connect(utilManager
, SIGNAL(saveCompleted(int, bool)), this, SLOT(updateSaveCompletion()));
112 for (int i
= 0; i
< ui
->importSummaryList
->rowCount(); i
++) {
113 QCheckBox
*box
= dynamic_cast<QCheckBox
*>(ui
->importSummaryList
->cellWidget(i
, 0));
114 if (box
->isChecked()) {
118 if (itemCount
== 0) {
121 ui
->progressBar
->setMaximum(itemCount
+ 1);
122 ui
->progressBar
->setValue(1);
123 for (int i
= 0; i
< ui
->importSummaryList
->rowCount(); i
++) {
124 QString uavObjectName
= ui
->importSummaryList
->item(i
, 1)->text();
125 QCheckBox
*box
= dynamic_cast<QCheckBox
*>(ui
->importSummaryList
->cellWidget(i
, 0));
126 if (box
->isChecked()) {
127 UAVObject
*obj
= objManager
->getObject(uavObjectName
);
128 utilManager
->saveObjectToSD(obj
);
133 ui
->saveToFlash
->setEnabled(false);
134 ui
->closeButton
->setEnabled(false);
138 void ImportSummaryDialog::updateSaveCompletion()
140 ui
->progressBar
->setValue(ui
->progressBar
->value() + 1);
141 if (ui
->progressBar
->value() == ui
->progressBar
->maximum()) {
142 ui
->saveToFlash
->setEnabled(true);
143 ui
->closeButton
->setEnabled(true);
147 void ImportSummaryDialog::changeEvent(QEvent
*e
)
149 QDialog::changeEvent(e
);
152 case QEvent::LanguageChange
:
153 ui
->retranslateUi(this);
160 void ImportSummaryDialog::showEvent(QShowEvent
*event
)
163 ui
->importSummaryList
->resizeColumnsToContents();
164 int width
= ui
->importSummaryList
->width() - (ui
->importSummaryList
->columnWidth(0) +
165 ui
->importSummaryList
->columnWidth(2));
166 ui
->importSummaryList
->setColumnWidth(1, width
- 15);