30 #include "ui_waypoint_dialog.h"
33 QItemSelectionModel *selection)
34 : QDialog(parent, Qt::Window)
35 , ui(new Ui_waypoint_dialog)
37 , itemSelection(selection)
40 connect(ui->cbMode, QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
41 &WaypointDialog::setupModeWidgets);
44 connect(ui->pushButtonOK, &QAbstractButton::clicked,
this, &WaypointDialog::onOkButton_clicked);
45 connect(ui->pushButtonCancel, &QAbstractButton::clicked,
this,
46 &WaypointDialog::onCancelButton_clicked);
47 connect(ui->pushButtonPrevious, &QAbstractButton::clicked,
this,
48 &WaypointDialog::onPreviousButton_clicked);
49 connect(ui->pushButtonNext, &QAbstractButton::clicked,
this,
50 &WaypointDialog::onNextButton_clicked);
52 mapper =
new QDataWidgetMapper(
this);
57 mapper->setItemDelegate(delegate);
58 connect(mapper, &QDataWidgetMapper::currentIndexChanged,
this,
59 &WaypointDialog::currentIndexChanged);
60 mapper->setModel(model);
61 mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
75 connect(ui->checkBoxLocked, &QCheckBox::stateChanged, mapper, &QDataWidgetMapper::submit);
77 mapper->setCurrentIndex(selection->currentIndex().row());
81 connect(model, &QAbstractItemModel::dataChanged,
this, &WaypointDialog::enableEditWidgets);
85 connect(model, &QAbstractItemModel::dataChanged, mapper, &QDataWidgetMapper::revert);
87 connect(itemSelection, &QItemSelectionModel::currentRowChanged,
this,
88 &WaypointDialog::currentRowChanged);
98 void WaypointDialog::currentIndexChanged(
int index)
100 ui->lbNumber->setText(QString::number(index + 1));
101 QModelIndex
idx = mapper->model()->index(index, 0);
102 if (index == itemSelection->currentIndex().row())
104 itemSelection->clear();
105 itemSelection->setCurrentIndex(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
117 void WaypointDialog::setupModeWidgets()
119 int mode = ui->cbMode->itemData(ui->cbMode->currentIndex()).toInt();
121 case Waypoint::MODE_CIRCLERIGHT:
122 case Waypoint::MODE_CIRCLELEFT:
123 ui->modeParams->setVisible(
true);
124 ui->modeParams->setText(tr(
"Radius"));
125 ui->dsb_modeParams->setVisible(
true);
128 ui->modeParams->setVisible(
false);
129 ui->dsb_modeParams->setVisible(
false);
144 if (!isActiveWindow())
147 setFocus(Qt::OtherFocusReason);
148 mapper->setCurrentIndex(number);
152 void WaypointDialog::onOkButton_clicked()
159 void WaypointDialog::onCancelButton_clicked()
166 void WaypointDialog::onPreviousButton_clicked()
168 mapper->toPrevious();
172 void WaypointDialog::onNextButton_clicked()
182 void WaypointDialog::currentRowChanged(QModelIndex current, QModelIndex previous)
186 mapper->setCurrentIndex(current.row());
194 void WaypointDialog::enableEditWidgets()
196 int row = itemSelection->currentIndex().row();
199 foreach (QWidget *obj, this->findChildren<QWidget *>()) {
200 w = qobject_cast<QComboBox *>(obj);
202 w->setEnabled(!value);
203 w = qobject_cast<QLineEdit *>(obj);
205 w->setEnabled(!value);
206 w = qobject_cast<QDoubleSpinBox *>(obj);
208 w->setEnabled(!value);
209 w = qobject_cast<QSpinBox *>(obj);
211 w->setEnabled(!value);
void loadComboBox(QComboBox *combo) const
Populate the selections in the mode combo box.
The WaypointDelegate class is used to handle updating the values in the mode combo box to the data mo...
void editWaypoint(int number)
Edit the requested waypoint, show dialog if it is not showing.
WaypointDialog(QWidget *parent, QAbstractItemModel *model, QItemSelectionModel *selection)