Skip to content

Commit c941963

Browse files
authored
Qtfred ships dialog direct edit (#7369)
* fix some issues and convert to direct edit * fix some comments * some fixes * var clash * loops * re add missing warning
1 parent abb9dfb commit c941963

16 files changed

Lines changed: 885 additions & 818 deletions

qtfred/src/mission/dialogs/ShipEditor/ShipEditorDialogModel.cpp

Lines changed: 610 additions & 523 deletions
Large diffs are not rendered by default.

qtfred/src/mission/dialogs/ShipEditor/ShipEditorDialogModel.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@ class ShipEditorDialogModel : public AbstractDialogModel {
4444

4545
void set_modified();
4646

47-
bool update_ship(int ship);
48-
bool update_data();
49-
5047
void ship_alt_name_close(int base_ship);
5148
void ship_callsign_close(int base_ship);
5249

5350
static int make_ship_list(int* arr);
5451

52+
int computeArrivalMinDist() const;
53+
5554
bool enable = true;
5655
int player_count;
5756
int ship_count;

qtfred/src/ui/dialogs/FictionViewerDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void FictionViewerDialog::accept()
3939
if (_model->apply()) {
4040
QDialog::accept();
4141
}
42-
// else: validation failed, dont close
42+
// else: validation failed, don't close
4343
}
4444

4545
void FictionViewerDialog::reject()

qtfred/src/ui/dialogs/MissionSpecs/CustomDataDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void CustomDataDialog::accept()
4242
if (_model->apply()) {
4343
QDialog::accept();
4444
}
45-
// else: validation failed, dont close
45+
// else: validation failed, don't close
4646
}
4747

4848
void CustomDataDialog::reject()

qtfred/src/ui/dialogs/MissionSpecs/CustomStringsDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void CustomStringsDialog::accept()
4242
if (_model->apply()) {
4343
QDialog::accept();
4444
}
45-
// else: validation failed, dont close
45+
// else: validation failed, don't close
4646
}
4747

4848
void CustomStringsDialog::reject()

qtfred/src/ui/dialogs/ReinforcementsEditorDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void ReinforcementsDialog::accept()
2727
if (_model->apply()) {
2828
QDialog::accept();
2929
}
30-
// else: validation failed, dont close
30+
// else: validation failed, don't close
3131
}
3232

3333
void ReinforcementsDialog::reject()

qtfred/src/ui/dialogs/ShieldSystemDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void ShieldSystemDialog::accept()
2929
if (_model->apply()) {
3030
QDialog::accept();
3131
}
32-
// else: validation failed, dont close
32+
// else: validation failed, don't close
3333
}
3434

3535
void ShieldSystemDialog::reject()

qtfred/src/ui/dialogs/ShipEditor/ShipAltShipClass.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void ShipAltShipClass::accept()
2525
if (_model->apply()) {
2626
QDialog::accept();
2727
}
28-
// else: validation failed, dont close
28+
// else: validation failed, don't close
2929
}
3030

3131
void ShipAltShipClass::reject()
@@ -210,7 +210,6 @@ void ShipAltShipClass::initUI()
210210
void ShipAltShipClass::updateUI()
211211
{
212212
util::SignalBlockers blockers(this); // block signals while we set up the UI
213-
QModelIndexList* list;
214213
auto current = ui->classList->currentIndex();
215214
auto ship_class = -1;
216215
auto variable = -1;
@@ -223,32 +222,36 @@ void ShipAltShipClass::updateUI()
223222
if (ui->variableCombo->model()->rowCount() <= 1) {
224223
dynamic_cast<InverseSortFilterProxyModel*>(ui->shipCombo->model())->setFilterFixedString("Set From Variable");
225224
}
226-
list = new QModelIndexList(
227-
ui->shipCombo->model()->match(ui->shipCombo->model()->index(0, 0), Qt::UserRole, ship_class));
228-
if (!list->empty()) {
229-
ui->shipCombo->setCurrentIndex(list->first().row());
230-
} else {
231-
if (ui->classList->model()->rowCount() != 0 && ship_class != -1) {
232-
_viewport->dialogProvider->showButtonDialog(DialogType::Error,
233-
"Error",
234-
"Illegal ship class.\n Resetting to -1",
235-
{DialogButton::Ok});
225+
{
226+
QModelIndexList shipMatches =
227+
ui->shipCombo->model()->match(ui->shipCombo->model()->index(0, 0), Qt::UserRole, ship_class);
228+
if (!shipMatches.empty()) {
229+
ui->shipCombo->setCurrentIndex(shipMatches.first().row());
230+
} else {
231+
if (ui->classList->model()->rowCount() != 0 && ship_class != -1) {
232+
_viewport->dialogProvider->showButtonDialog(DialogType::Error,
233+
"Error",
234+
"Illegal ship class.\n Resetting to -1",
235+
{DialogButton::Ok});
236+
}
237+
ui->shipCombo->setCurrentIndex(0);
236238
}
237-
ui->shipCombo->setCurrentIndex(0);
238239
}
239240

240-
auto varlist = new QModelIndexList(
241-
ui->variableCombo->model()->match(ui->variableCombo->model()->index(0, 0), Qt::UserRole, variable));
242-
if (!varlist->empty()) {
243-
ui->variableCombo->setCurrentIndex(varlist->first().row());
244-
} else {
245-
if (ui->classList->model()->rowCount() != 0) {
246-
_viewport->dialogProvider->showButtonDialog(DialogType::Error,
247-
"Error",
248-
"Illegal variable index.\n Resetting to -1",
249-
{DialogButton::Ok});
241+
{
242+
QModelIndexList varMatches =
243+
ui->variableCombo->model()->match(ui->variableCombo->model()->index(0, 0), Qt::UserRole, variable);
244+
if (!varMatches.empty()) {
245+
ui->variableCombo->setCurrentIndex(varMatches.first().row());
246+
} else {
247+
if (ui->classList->model()->rowCount() != 0) {
248+
_viewport->dialogProvider->showButtonDialog(DialogType::Error,
249+
"Error",
250+
"Illegal variable index.\n Resetting to -1",
251+
{DialogButton::Ok});
252+
}
253+
ui->variableCombo->setCurrentIndex(0);
250254
}
251-
ui->variableCombo->setCurrentIndex(0);
252255
}
253256

254257
if (ui->variableCombo->model()->rowCount() <= 1) {

qtfred/src/ui/dialogs/ShipEditor/ShipCustomWarpDialog.cpp

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,14 @@ void ShipCustomWarpDialog::on_comboBoxType_currentIndexChanged(int index)
8080
_model->setType(index);
8181
}
8282
void ShipCustomWarpDialog::on_lineEditStartSound_editingFinished()
83-
{ // String wrangling reqired in order to avoid crashes when directly converting from Qstring to std::string on some
84-
// enviroments
85-
QString temp(ui->lineEditStartSound->text());
86-
if (!temp.isEmpty()) {
87-
_model->setStartSound(temp.toLatin1().constData());
88-
} else {
89-
_model->setStartSound("");
90-
}
83+
{
84+
SCP_string startSound = ui->lineEditStartSound->text().toUtf8().constData();
85+
_model->setStartSound(startSound);
9186
}
9287
void ShipCustomWarpDialog::on_lineEditEndSound_editingFinished()
93-
{ // String wrangling reqired in order to avoid crashes when directly converting from Qstring to std::string on some
94-
// enviroments
95-
QString temp(ui->lineEditEndSound->text());
96-
if (!temp.isEmpty()) {
97-
_model->setEndSound(temp.toLatin1().constData());
98-
} else {
99-
_model->setEndSound("");
100-
}
88+
{
89+
SCP_string endSound = ui->lineEditEndSound->text().toUtf8().constData();
90+
_model->setEndSound(endSound);
10191
}
10292
void ShipCustomWarpDialog::on_doubleSpinBoxEngage_valueChanged(double value)
10393
{
@@ -120,14 +110,9 @@ void ShipCustomWarpDialog::on_doubleSpinBoxRadius_valueChanged(double value)
120110
_model->setRadius(value);
121111
}
122112
void ShipCustomWarpDialog::on_lineEditAnim_editingFinished()
123-
{ // String wrangling reqired in order to avoid crashes when directly converting from Qstring to std::string on some
124-
// enviroments
125-
QString temp(ui->lineEditAnim->text());
126-
if (!temp.isEmpty()) {
127-
_model->setAnim(temp.toLatin1().constData());
128-
} else {
129-
_model->setAnim("");
130-
}
113+
{
114+
SCP_string anim = ui->lineEditAnim->text().toUtf8().constData();
115+
_model->setAnim(anim);
131116
}
132117
void ShipCustomWarpDialog::on_checkBoxSupercap_toggled(bool state)
133118
{

qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ ShipEditorDialog::ShipEditorDialog(FredView* parent, EditorViewport* viewport)
3232
ui->callsignCombo->lineEdit()->setMaxLength(CALLSIGN_LEN);
3333

3434
connect(_model.get(), &AbstractDialogModel::modelChanged, this, [this] { updateUI(false); });
35-
connect(this, &QDialog::accepted, _model.get(), &ShipEditorDialogModel::apply);
3635
connect(viewport->editor, &Editor::currentObjectChanged, this, &ShipEditorDialog::update);
3736
connect(viewport->editor, &Editor::objectMarkingChanged, this, &ShipEditorDialog::update);
3837

@@ -69,8 +68,6 @@ bool ShipEditorDialog::getIfMultipleShips() const
6968

7069
void ShipEditorDialog::closeEvent(QCloseEvent* e)
7170
{
72-
util::SignalBlockers blockers(this);
73-
_model->apply();
7471
_viewport->editor->autosave("ship editor");
7572
QDialog::closeEvent(e);
7673
}
@@ -118,9 +115,6 @@ void ShipEditorDialog::on_tblInfoButton_clicked()
118115
void ShipEditorDialog::update()
119116
{
120117
if (this->isVisible()) {
121-
if (_model->getNumSelectedObjects() && _model->query_modified()) {
122-
_model->apply();
123-
}
124118
_model->initializeData();
125119
updateUI(true);
126120
}
@@ -206,10 +200,11 @@ void ShipEditorDialog::updateColumnOne(bool overwrite)
206200
for (auto j = 0; j < Mission_alt_type_count; j++) {
207201
ui->altNameCombo->addItem(Mission_alt_types[j]);
208202
}
209-
if (ui->altNameCombo->findText(QString(altname.c_str()))) {
210-
ui->altNameCombo->setCurrentIndex(ui->altNameCombo->findText(QString(altname.c_str())));
203+
int altNameIdx = ui->altNameCombo->findText(QString(altname.c_str()));
204+
if (altNameIdx >= 0) {
205+
ui->altNameCombo->setCurrentIndex(altNameIdx);
211206
} else {
212-
ui->altNameCombo->setCurrentIndex(ui->altNameCombo->findText("<none>"));
207+
ui->altNameCombo->setEditText("<none>");
213208
}
214209
}
215210
}
@@ -218,19 +213,19 @@ void ShipEditorDialog::updateColumnOne(bool overwrite)
218213
if (_model->getIfMultipleShips()) {
219214
ui->callsignCombo->setEnabled(false);
220215
} else {
221-
ui->callsignCombo->clear();
222216
auto callsign = _model->getCallsign();
223217
ui->callsignCombo->setEnabled(true);
224218
if (overwrite) {
219+
ui->callsignCombo->clear();
225220
ui->callsignCombo->addItem("<none>");
226221
for (auto j = 0; j < Mission_callsign_count; j++) {
227222
ui->callsignCombo->addItem(Mission_callsigns[j], QVariant(Mission_callsigns[j]));
228223
}
229-
230-
if (ui->callsignCombo->findText(QString(callsign.c_str()))) {
231-
ui->callsignCombo->setCurrentIndex(ui->callsignCombo->findText(QString(callsign.c_str())));
224+
int callsignIdx = ui->callsignCombo->findText(QString(callsign.c_str()));
225+
if (callsignIdx >= 0) {
226+
ui->callsignCombo->setCurrentIndex(callsignIdx);
232227
} else {
233-
ui->altNameCombo->setCurrentIndex(ui->callsignCombo->findText("<none>"));
228+
ui->callsignCombo->setEditText("<none>");
234229
}
235230
}
236231
}
@@ -863,32 +858,32 @@ void ShipEditorDialog::on_departureLocationCombo_currentIndexChanged(int index)
863858
auto depLocationIdx = ui->departureLocationCombo->itemData(index).toInt();
864859
_model->setDepartureLocationIndex(depLocationIdx);
865860
}
866-
void fred::dialogs::ShipEditorDialog::on_departureTargetCombo_currentIndexChanged(int index)
861+
void ShipEditorDialog::on_departureTargetCombo_currentIndexChanged(int index)
867862
{
868863
auto depLocationIdx = ui->departureTargetCombo->itemData(index).toInt();
869864
_model->setDepartureTarget(depLocationIdx);
870865
}
871-
void fred::dialogs::ShipEditorDialog::on_departureDelaySpinBox_valueChanged(int value)
866+
void ShipEditorDialog::on_departureDelaySpinBox_valueChanged(int value)
872867
{
873868
_model->setDepartureDelay(value);
874869
}
875-
void fred::dialogs::ShipEditorDialog::on_updateDepartureCueCheckBox_toggled(bool value)
870+
void ShipEditorDialog::on_updateDepartureCueCheckBox_toggled(bool value)
876871
{
877872
_model->setDepartureCue(value);
878873
}
879-
void fred::dialogs::ShipEditorDialog::on_departureTree_rootNodeFormulaChanged(int old, int node)
874+
void ShipEditorDialog::on_departureTree_rootNodeFormulaChanged(int old, int node)
880875
{
881876
_model->setDepartureFormula(old, node);
882877
}
883-
void fred::dialogs::ShipEditorDialog::on_departureTree_helpChanged(const QString& help)
878+
void ShipEditorDialog::on_departureTree_helpChanged(const QString& help)
884879
{
885880
ui->helpText->setPlainText(help);
886881
}
887-
void fred::dialogs::ShipEditorDialog::on_departureTree_miniHelpChanged(const QString& help)
882+
void ShipEditorDialog::on_departureTree_miniHelpChanged(const QString& help)
888883
{
889884
ui->HelpTitle->setText(help);
890885
}
891-
void fred::dialogs::ShipEditorDialog::on_noDepartureWarpCheckBox_toggled(bool value)
886+
void ShipEditorDialog::on_noDepartureWarpCheckBox_toggled(bool value)
892887
{
893888
_model->setNoDepartureWarp(value);
894889
}

0 commit comments

Comments
 (0)