30 #include <QDomDocument>
33 #include <QMessageBox>
36 #include <QSignalMapper>
42 , importedObjects(NULL)
49 setWindowTitle(tr(
"Import Summary"));
51 ui->importSummaryList->setColumnCount(3);
52 ui->importSummaryList->setRowCount(0);
55 header.append(
"Name");
56 header.append(
"Status");
57 ui->importSummaryList->setHorizontalHeaderLabels(header);
58 ui->progressBar->setValue(0);
60 connect(ui->closeButton, SIGNAL(clicked()),
this, SLOT(reject()));
61 connect(ui->btnSaveToFlash, SIGNAL(clicked()),
this, SLOT(doTheApplySaving()));
64 QSignalMapper *signalMapper =
new QSignalMapper(
this);
66 connect(ui->btnSelectAll, SIGNAL(clicked()), signalMapper, SLOT(map()));
67 connect(ui->btnSelectNone, SIGNAL(clicked()), signalMapper, SLOT(map()));
69 signalMapper->setMapping(ui->btnSelectAll, 1);
70 signalMapper->setMapping(ui->btnSelectNone, 0);
72 connect(signalMapper, SIGNAL(mapped(
int)),
this, SLOT(setCheckedState(
int)));
75 connect(ui->helpButton, SIGNAL(clicked()),
this, SLOT(openHelp()));
81 delete importedObjects;
89 importedObjects = objs;
95 void ImportSummaryDialog::openHelp()
97 QDesktopServices::openUrl(
98 QUrl(
"https://github.com/d-ronin/dRonin/wiki/OnlineHelp:-UAV-Settings-import-export",
108 ui->importSummaryList->setRowCount(ui->importSummaryList->rowCount() + 1);
109 int row = ui->importSummaryList->rowCount() - 1;
110 ui->importSummaryList->setCellWidget(row, 0,
new QCheckBox(ui->importSummaryList));
111 QTableWidgetItem *objName =
new QTableWidgetItem(uavObjectName);
112 ui->importSummaryList->setItem(row, 1, objName);
113 QCheckBox *box =
dynamic_cast<QCheckBox *
>(ui->importSummaryList->cellWidget(row, 0));
114 ui->importSummaryList->setItem(row, 2,
new QTableWidgetItem(text));
117 ui->importSummaryList->item(row, 1)->setFlags(Qt::NoItemFlags);
118 ui->importSummaryList->item(row, 2)->setFlags(Qt::NoItemFlags);
121 box->setChecked(
true);
123 box->setChecked(
false);
124 box->setEnabled(
false);
133 return ui->importSummaryList->rowCount();
139 void ImportSummaryDialog::setCheckedState(
int state)
141 for (
int i = 0;
i < ui->importSummaryList->rowCount();
i++) {
142 QCheckBox *box =
dynamic_cast<QCheckBox *
>(ui->importSummaryList->cellWidget(
i, 0));
143 if (box->isEnabled())
144 box->setChecked((state == 1 ?
true :
false));
151 void ImportSummaryDialog::doTheApplySaving()
153 if (!importedObjects)
160 connect(utilManager, SIGNAL(saveCompleted(
int,
bool)),
this, SLOT(
updateCompletion()));
162 for (
int i = 0;
i < ui->importSummaryList->rowCount();
i++) {
163 QCheckBox *box =
dynamic_cast<QCheckBox *
>(ui->importSummaryList->cellWidget(
i, 0));
164 if (box->isChecked()) {
172 ui->btnSaveToFlash->setEnabled(
false);
173 ui->closeButton->setEnabled(
false);
175 ui->progressBar->setMaximum(itemCount + 1);
176 ui->progressBar->setValue(1);
177 for (
int i = 0;
i < ui->importSummaryList->rowCount();
i++) {
178 QString uavObjectName = ui->importSummaryList->item(
i, 1)->text();
179 QCheckBox *box =
dynamic_cast<QCheckBox *
>(ui->importSummaryList->cellWidget(
i, 0));
180 if (box->isChecked()) {
185 importedObj->
pack(data);
191 utilManager->saveObjectToFlash(boardObj);
201 QMessageBox msgBox(
this);
203 msgBox.setText(tr(
"Settings saved to flash."));
205 msgBox.setInformativeText(tr(
"You must power cycle the flight controller to apply settings "
206 "and continue configuration."));
208 msgBox.setStandardButtons(QMessageBox::Ok);
217 ui->progressBar->setValue(ui->progressBar->value() + 1);
218 if (ui->progressBar->value() == ui->progressBar->maximum()) {
219 ui->btnSaveToFlash->setEnabled(
true);
220 ui->closeButton->setEnabled(
true);
226 QDialog::changeEvent(e);
228 case QEvent::LanguageChange:
229 ui->retranslateUi(
this);
239 ui->importSummaryList->resizeColumnsToContents();
240 int width = ui->importSummaryList->width()
241 - (ui->importSummaryList->columnWidth(0) + ui->importSummaryList->columnWidth(2));
242 ui->importSummaryList->setColumnWidth(1, width - 15);
qint32 unpack(const quint8 *dataIn)
qint32 pack(quint8 *dataOut)
Core plugin system that manages the plugins, their life cycle and their registered objects...
ImportSummaryDialog(QWidget *parent=nullptr, bool quiet=false)
void setUAVOSettings(UAVObjectManager *obj)
void changeEvent(QEvent *e)
void showEvent(QShowEvent *event)
void addLine(QString objectName, QString text, bool status)
UAVObject * getObject(const QString &name, quint32 instId=0)