From 104847c4bdf2b67f600eac23541936616ccc2b8f Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:19:40 +0000 Subject: [PATCH 01/18] Apply #6457 and #6458 to Ship sub-editors --- .../mission/dialogs/AbstractDialogModel.cpp | 14 ++++- .../src/mission/dialogs/AbstractDialogModel.h | 23 ++++++++ .../ShipEditor/PlayerOrdersDialogModel.cpp | 11 ---- .../ShipEditor/PlayerOrdersDialogModel.h | 18 ------ .../ShipEditor/ShipCustomWarpDialogModel.cpp | 11 ---- .../ShipEditor/ShipCustomWarpDialogModel.h | 22 -------- .../ShipEditor/ShipFlagsDialogModel.cpp | 11 ---- .../dialogs/ShipEditor/ShipFlagsDialogModel.h | 17 ------ .../ShipEditor/ShipGoalsDialogModel.cpp | 10 ---- .../dialogs/ShipEditor/ShipGoalsDialogModel.h | 16 +----- .../ShipInitialStatusDialogModel.cpp | 11 ---- .../ShipEditor/ShipInitialStatusDialogModel.h | 14 ----- .../ShipEditor/ShipPathsDialogModel.cpp | 4 -- .../dialogs/ShipEditor/ShipPathsDialogModel.h | 2 - .../ShipSpecialStatsDialogModel.cpp | 9 --- .../ShipEditor/ShipSpecialStatsDialogModel.h | 14 ----- .../ShipTextureReplacementDialogModel.cpp | 11 ---- .../ShipTextureReplacementDialogModel.h | 15 ----- qtfred/src/mission/util.cpp | 29 ++++++++++ qtfred/src/mission/util.h | 8 ++- .../src/ui/dialogs/AsteroidEditorDialog.cpp | 2 + .../dialogs/ShipEditor/PlayerOrdersDialog.cpp | 41 ++++---------- .../dialogs/ShipEditor/PlayerOrdersDialog.h | 7 +-- .../ShipEditor/ShipCustomWarpDialog.cpp | 49 +++------------- .../dialogs/ShipEditor/ShipEditorDialog.cpp | 56 +++++++++---------- .../ui/dialogs/ShipEditor/ShipEditorDialog.h | 16 ------ .../ui/dialogs/ShipEditor/ShipFlagsDialog.cpp | 34 +++-------- .../ui/dialogs/ShipEditor/ShipFlagsDialog.h | 3 +- .../ui/dialogs/ShipEditor/ShipGoalsDialog.cpp | 52 ++++------------- .../ui/dialogs/ShipEditor/ShipGoalsDialog.h | 10 +--- .../ShipEditor/ShipInitialStatusDialog.cpp | 42 ++++---------- .../ShipEditor/ShipInitialStatusDialog.h | 7 +-- .../ui/dialogs/ShipEditor/ShipPathsDialog.cpp | 50 ++--------------- .../ShipEditor/ShipSpecialStatsDialog.cpp | 34 +++-------- .../ShipEditor/ShipSpecialStatsDialog.h | 3 +- .../ui/dialogs/ShipEditor/ShipTBLViewer.cpp | 13 +---- .../src/ui/dialogs/ShipEditor/ShipTBLViewer.h | 7 +-- .../ShipTextureReplacementDialog.cpp | 41 +++++--------- .../ShipEditor/ShipTextureReplacementDialog.h | 7 +-- qtfred/ui/PlayerOrdersDialog.ui | 23 -------- qtfred/ui/ShipFlagsDialog.ui | 18 +----- qtfred/ui/ShipGoalsDialog.ui | 20 +------ qtfred/ui/ShipInitialStatus.ui | 16 ------ qtfred/ui/ShipSpecialStatsDialog.ui | 20 +------ qtfred/ui/ShipTextureReplacementDialog.ui | 16 ------ 45 files changed, 199 insertions(+), 658 deletions(-) diff --git a/qtfred/src/mission/dialogs/AbstractDialogModel.cpp b/qtfred/src/mission/dialogs/AbstractDialogModel.cpp index 94fec79e209..40a9bf4354f 100644 --- a/qtfred/src/mission/dialogs/AbstractDialogModel.cpp +++ b/qtfred/src/mission/dialogs/AbstractDialogModel.cpp @@ -6,13 +6,23 @@ namespace fso { namespace fred { namespace dialogs { - - AbstractDialogModel::AbstractDialogModel(QObject* parent, EditorViewport* viewport) : QObject(parent), _editor(viewport->editor), _viewport(viewport) { } +bool AbstractDialogModel::query_modified() const +{ + return _modified; +} + +void AbstractDialogModel::set_modified() +{ + if (!_modified) { + _modified = true; + } +} + } } } diff --git a/qtfred/src/mission/dialogs/AbstractDialogModel.h b/qtfred/src/mission/dialogs/AbstractDialogModel.h index b3d2e575d87..f39014391e0 100644 --- a/qtfred/src/mission/dialogs/AbstractDialogModel.h +++ b/qtfred/src/mission/dialogs/AbstractDialogModel.h @@ -25,6 +25,15 @@ class AbstractDialogModel: public QObject { Editor* _editor = nullptr; EditorViewport* _viewport = nullptr; + template + /** + * @brief Copies rvalue to the lvalue while setting the modified variable. + */ + void modify(T& a, const T& b); + + bool _modified = false; + void set_modified(); + public: AbstractDialogModel(QObject* parent, EditorViewport* viewport); @@ -42,6 +51,10 @@ class AbstractDialogModel: public QObject { */ virtual void reject() = 0; + + bool query_modified() const; + + signals: /** * @brief Signal emitted when the model has changed caused by an update operation @@ -51,6 +64,16 @@ class AbstractDialogModel: public QObject { void modelChanged(); }; +template +inline void AbstractDialogModel::modify(T& a, const T& b) +{ + if (a != b) { + a = b; + set_modified(); + modelChanged(); + } +} + } } } diff --git a/qtfred/src/mission/dialogs/ShipEditor/PlayerOrdersDialogModel.cpp b/qtfred/src/mission/dialogs/ShipEditor/PlayerOrdersDialogModel.cpp index 644fe6b9d64..c0161d79a0b 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/PlayerOrdersDialogModel.cpp +++ b/qtfred/src/mission/dialogs/ShipEditor/PlayerOrdersDialogModel.cpp @@ -53,11 +53,6 @@ namespace fso { { } - bool PlayerOrdersDialogModel::query_modified() const - { - return _modified; - } - SCP_vector PlayerOrdersDialogModel::getAcceptedOrders() const { return acceptedOrders; @@ -156,12 +151,6 @@ namespace fso { } modelChanged(); } - void PlayerOrdersDialogModel::set_modified() - { - if (!_modified) { - _modified = true; - } - } } } } \ No newline at end of file diff --git a/qtfred/src/mission/dialogs/ShipEditor/PlayerOrdersDialogModel.h b/qtfred/src/mission/dialogs/ShipEditor/PlayerOrdersDialogModel.h index fe4833a215f..dfed5632c2b 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/PlayerOrdersDialogModel.h +++ b/qtfred/src/mission/dialogs/ShipEditor/PlayerOrdersDialogModel.h @@ -9,13 +9,6 @@ namespace fso { class PlayerOrdersDialogModel : public AbstractDialogModel { private: - template - void modify(T& a, const T& b); - - bool _modified = false; - - void set_modified(); - bool m_multi; int m_num_checks_active; @@ -31,22 +24,11 @@ namespace fso { bool apply() override; void reject() override; - bool query_modified() const; - SCP_vector getAcceptedOrders() const; SCP_vector getOrderNames() const; SCP_vector getCurrentOrders() const; void setCurrentOrder(const int, const size_t); }; - template - inline void PlayerOrdersDialogModel::modify(T& a, const T& b) - { - if (a != b) { - a = b; - set_modified(); - modelChanged(); - } - } } } } \ No newline at end of file diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipCustomWarpDialogModel.cpp b/qtfred/src/mission/dialogs/ShipEditor/ShipCustomWarpDialogModel.cpp index 25567dbb63d..7766a6c3cdc 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipCustomWarpDialogModel.cpp +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipCustomWarpDialogModel.cpp @@ -207,17 +207,6 @@ void ShipCustomWarpDialogModel::initializeData() } } -void ShipCustomWarpDialogModel::set_modified() -{ - if (!_modified) { - _modified = true; - } -} - -bool ShipCustomWarpDialogModel::query_modified() const -{ - return _modified; -} void ShipCustomWarpDialogModel::setType(const int index) { modify(_m_warp_type, index); diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipCustomWarpDialogModel.h b/qtfred/src/mission/dialogs/ShipEditor/ShipCustomWarpDialogModel.h index 1fa27fa4afd..1b94dc3a295 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipCustomWarpDialogModel.h +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipCustomWarpDialogModel.h @@ -10,12 +10,6 @@ class ShipCustomWarpDialogModel : public AbstractDialogModel { * @brief Initialises data for the model */ void initializeData(); - template - /** - * @brief Copies rvalue to the lvalue while setting the modified variable. - */ - void modify(T& a, const T& b); - bool _modified = false; bool _m_departure; int _m_warp_type; @@ -34,7 +28,6 @@ class ShipCustomWarpDialogModel : public AbstractDialogModel { /** * @brief Marks the model as modifed */ - void set_modified(); public: /** @@ -113,11 +106,6 @@ class ShipCustomWarpDialogModel : public AbstractDialogModel { * @return If the model is working on a player. */ bool isPlayer() const; - /** - * @brief Getter - * @return If the model has been modified. - */ - bool query_modified() const; // Setters void setType(const int index); @@ -133,14 +121,4 @@ class ShipCustomWarpDialogModel : public AbstractDialogModel { void setPlayerSpeed(const double); }; -template -inline void ShipCustomWarpDialogModel::modify(T& a, const T& b) -{ - if (a != b) { - a = b; - set_modified(); - modelChanged(); - } -} - } // namespace dialogs \ No newline at end of file diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipFlagsDialogModel.cpp b/qtfred/src/mission/dialogs/ShipEditor/ShipFlagsDialogModel.cpp index 4a5ae85b032..c705f223791 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipFlagsDialogModel.cpp +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipFlagsDialogModel.cpp @@ -12,12 +12,6 @@ namespace fso { namespace fred { namespace dialogs { -void ShipFlagsDialogModel::set_modified() -{ - if (!_modified) { - _modified = true; - } -} int ShipFlagsDialogModel::tristate_set(int val, int cur_state) { if (val) { @@ -1127,11 +1121,6 @@ int ShipFlagsDialogModel::getNoSelfDestruct() const return m_no_disabled_self_destruct; } -bool ShipFlagsDialogModel::query_modified() -{ - return _modified; -} - void ShipFlagsDialogModel::initializeData() { object* objp; diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipFlagsDialogModel.h b/qtfred/src/mission/dialogs/ShipEditor/ShipFlagsDialogModel.h index 20c26a7f7b6..504d5d3beb4 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipFlagsDialogModel.h +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipFlagsDialogModel.h @@ -9,11 +9,6 @@ namespace dialogs { class ShipFlagsDialogModel : public AbstractDialogModel { private: - template - void modify(T& a, const T& b); - - bool _modified = false; - int m_red_alert_carry; int m_scannable; int m_reinforcement; @@ -61,7 +56,6 @@ class ShipFlagsDialogModel : public AbstractDialogModel { int m_escort_value; int m_respawn_priority; - void set_modified(); static int tristate_set(const int val, const int cur_state); void update_ship(const int); @@ -205,18 +199,7 @@ class ShipFlagsDialogModel : public AbstractDialogModel { void setNoSelfDestruct(const int); int getNoSelfDestruct() const; - bool query_modified(); }; - -template -inline void ShipFlagsDialogModel::modify(T& a, const T& b) -{ - if (a != b) { - a = b; - set_modified(); - modelChanged(); - } -} } // namespace dialogs } // namespace fred } // namespace fso \ No newline at end of file diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipGoalsDialogModel.cpp b/qtfred/src/mission/dialogs/ShipEditor/ShipGoalsDialogModel.cpp index d40c9749b4c..ee507a95ae1 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipGoalsDialogModel.cpp +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipGoalsDialogModel.cpp @@ -618,16 +618,6 @@ namespace fso { m_object[i] = data[i]; } } - void ShipGoalsDialogModel::set_modified() - { - if (!_modified) { - _modified = true; - } - } - bool ShipGoalsDialogModel::query_modified() - { - return _modified; - } void ShipGoalsDialogModel::setShip(const int ship) { self_ship = ship; diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipGoalsDialogModel.h b/qtfred/src/mission/dialogs/ShipEditor/ShipGoalsDialogModel.h index 3e6f822c0f9..8696216550d 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipGoalsDialogModel.h +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipGoalsDialogModel.h @@ -25,12 +25,7 @@ class ShipGoalsDialogModel : public AbstractDialogModel { void initialize(ai_goal* goals, int ship); void initialize_multi(); - template - void modify(T& a, const T& b); - bool _modified = false; - - void set_modified(); int self_ship, self_wing; int m_behavior[ED_MAX_GOALS]; @@ -53,7 +48,6 @@ class ShipGoalsDialogModel : public AbstractDialogModel { void initializeData(bool multi, int self_ship, int self_wing); bool apply() override; void reject() override; - bool query_modified(); void setShip(const int); int getShip() const; @@ -85,15 +79,7 @@ class ShipGoalsDialogModel : public AbstractDialogModel { void setPriority(const int, const int); int getPriority(const int) const; }; -template -inline void ShipGoalsDialogModel::modify(T& a, const T& b) -{ - if (a != b) { - a = b; - set_modified(); - modelChanged(); - } -} + } // namespace dialogs } // namespace fred } // namespace fso \ No newline at end of file diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipInitialStatusDialogModel.cpp b/qtfred/src/mission/dialogs/ShipEditor/ShipInitialStatusDialogModel.cpp index c517e79ff6f..651bd8dcc0d 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipInitialStatusDialogModel.cpp +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipInitialStatusDialogModel.cpp @@ -633,17 +633,6 @@ bool ShipInitialStatusDialogModel::apply() void ShipInitialStatusDialogModel::reject() {} -void ShipInitialStatusDialogModel::set_modified() -{ - if (!_modified) { - _modified = true; - } -} - - bool ShipInitialStatusDialogModel::query_modified() -{ - return _modified; -} void ShipInitialStatusDialogModel::setVelocity(const int value) { diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipInitialStatusDialogModel.h b/qtfred/src/mission/dialogs/ShipEditor/ShipInitialStatusDialogModel.h index 786cb50b326..a96449a0b24 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipInitialStatusDialogModel.h +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipInitialStatusDialogModel.h @@ -19,10 +19,7 @@ bool set_cue_to_false(int* cue); class ShipInitialStatusDialogModel : public AbstractDialogModel { private: - template - void modify(T& a, const T& b); - bool _modified = false; int m_ship; int cur_subsys = -1; @@ -48,7 +45,6 @@ class ShipInitialStatusDialogModel : public AbstractDialogModel { dockpoint_information* dockpoint_array; - void set_modified(); void update_docking_info(); void undock(object*, object*); @@ -72,7 +68,6 @@ class ShipInitialStatusDialogModel : public AbstractDialogModel { bool apply() override; void reject() override; - bool query_modified(); void setVelocity(const int); int getVelocity() const; @@ -146,15 +141,6 @@ static void handle_inconsistent_flag(flagset& flags, T flag, int value) flags.remove(flag); } } -template -inline void ShipInitialStatusDialogModel::modify(T& a, const T& b) -{ - if (a != b) { - a = b; - set_modified(); - modelChanged(); - } -} } // namespace dialogs } // namespace fred } // namespace fso \ No newline at end of file diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipPathsDialogModel.cpp b/qtfred/src/mission/dialogs/ShipEditor/ShipPathsDialogModel.cpp index 8b1d1a59a4e..a76cdb37602 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipPathsDialogModel.cpp +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipPathsDialogModel.cpp @@ -76,10 +76,6 @@ bool ShipPathsDialogModel::modify(const int index, const bool value) return false; } } -bool ShipPathsDialogModel::query_modified() const -{ - return _modified; -} SCP_vector ShipPathsDialogModel::getPathList() const { return m_path_list; diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipPathsDialogModel.h b/qtfred/src/mission/dialogs/ShipEditor/ShipPathsDialogModel.h index 9e1e5a149ea..55b71cb48d9 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipPathsDialogModel.h +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipPathsDialogModel.h @@ -13,7 +13,6 @@ class ShipPathsDialogModel : public AbstractDialogModel { SCP_vector m_path_list; int m_path_mask; int m_ship; - bool _modified = false; public: ShipPathsDialogModel(QObject* parent, EditorViewport* viewport, @@ -22,7 +21,6 @@ class ShipPathsDialogModel : public AbstractDialogModel { bool apply() override; void reject() override; bool modify(const int, const bool); - bool query_modified() const; SCP_vector getPathList() const; polymodel* getModel() const; }; diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipSpecialStatsDialogModel.cpp b/qtfred/src/mission/dialogs/ShipEditor/ShipSpecialStatsDialogModel.cpp index 48835bc7ebe..f3f82ad0292 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipSpecialStatsDialogModel.cpp +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipSpecialStatsDialogModel.cpp @@ -207,15 +207,6 @@ namespace fso { void ShipSpecialStatsDialogModel::reject() { } - void ShipSpecialStatsDialogModel::set_modified() - { - if (!_modified) { - _modified = true; - } - } - bool ShipSpecialStatsDialogModel::query_modified() { - return _modified; - } bool ShipSpecialStatsDialogModel::getSpecialExp() const { return m_special_exp; diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipSpecialStatsDialogModel.h b/qtfred/src/mission/dialogs/ShipEditor/ShipSpecialStatsDialogModel.h index e39112ab8f4..0656c4f0783 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipSpecialStatsDialogModel.h +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipSpecialStatsDialogModel.h @@ -7,9 +7,6 @@ namespace fso { namespace dialogs { class ShipSpecialStatsDialogModel : public AbstractDialogModel { private: - template - void modify(T& a, const T& b); - bool _modified = false; int m_ship; int num_selected_ships; @@ -31,14 +28,12 @@ namespace fso { int m_shields; int m_hull; - void set_modified(); public: ShipSpecialStatsDialogModel(QObject* parent, EditorViewport* viewport); void initializeData(); bool apply() override; void reject() override; - bool query_modified(); //Exp Get/Setters bool getSpecialExp() const; @@ -70,15 +65,6 @@ namespace fso { int getHull() const; void setHull(const int); }; - template - inline void ShipSpecialStatsDialogModel::modify(T& a, const T& b) - { - if (a != b) { - a = b; - set_modified(); - modelChanged(); - } - } } } } \ No newline at end of file diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipTextureReplacementDialogModel.cpp b/qtfred/src/mission/dialogs/ShipEditor/ShipTextureReplacementDialogModel.cpp index 1ef2cab98e0..c935d602d6e 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipTextureReplacementDialogModel.cpp +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipTextureReplacementDialogModel.cpp @@ -627,17 +627,6 @@ namespace fso { Assert(index < currentTextures.size()); modify(inheritMap[index][type], state); } - void ShipTextureReplacementDialogModel::set_modified() - { - if (!_modified) { - _modified = true; - } - } - - bool ShipTextureReplacementDialogModel::query_modified() const - { - return _modified;; - } } } } \ No newline at end of file diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipTextureReplacementDialogModel.h b/qtfred/src/mission/dialogs/ShipEditor/ShipTextureReplacementDialogModel.h index f15f397370e..d8a4ca4cf45 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipTextureReplacementDialogModel.h +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipTextureReplacementDialogModel.h @@ -10,11 +10,6 @@ namespace fso { private: void initSubTypes(polymodel* model, int); - template - void modify(T& a, const T& b); - bool _modified = false; - void set_modified(); - bool m_multi; //Used to dermeine what type of texutre a map has. SCP_vector> subTypesAvailable; @@ -50,18 +45,8 @@ namespace fso { void setReplace(const size_t index, const SCP_string& type, const bool state); void setInherit(const size_t index, const SCP_string& type, const bool state); - bool query_modified() const; }; - template - inline void ShipTextureReplacementDialogModel::modify(T& a, const T& b) - { - if (a != b) { - a = b; - set_modified(); - modelChanged(); - } - } } } } \ No newline at end of file diff --git a/qtfred/src/mission/util.cpp b/qtfred/src/mission/util.cpp index 3dfb5101cc0..87ef8542904 100644 --- a/qtfred/src/mission/util.cpp +++ b/qtfred/src/mission/util.cpp @@ -92,3 +92,32 @@ void time_to_mission_info_string(const std::tm* src, char* dest, size_t dest_max { std::strftime(dest, dest_max_len, "%x at %X", src); } + +bool rejectOrCloseHandler(QDialog* dialog, + fso::fred::dialogs::AbstractDialogModel* model, + fso::fred::EditorViewport* viewport) +{ + if (model->query_modified()) { + auto button = viewport->dialogProvider->showButtonDialog(fso::fred::DialogType::Question, + "Changes detected", + "Do you want to keep your changes?", + {fso::fred::DialogButton::Yes, fso::fred::DialogButton::No, fso::fred::DialogButton::Cancel}); + + if (button == fso::fred::DialogButton::Cancel) { + return false; + } + + if (button == fso::fred::DialogButton::Yes) { + model->apply(); + return true; + } + if (button == fso::fred::DialogButton::No) { + model->reject(); + return true; + } + return false; + } else { + model->reject(); + return true; + } +} \ No newline at end of file diff --git a/qtfred/src/mission/util.h b/qtfred/src/mission/util.h index c4ddd5ae818..3eb8400daaf 100644 --- a/qtfred/src/mission/util.h +++ b/qtfred/src/mission/util.h @@ -1,5 +1,7 @@ #pragma once - +#include +#include "dialogs/AbstractDialogModel.h" +#include "EditorViewport.h" void stuff_special_arrival_anchor_name(char *buf, int iff_index, int restrict_to_players, int retail_format); @@ -10,3 +12,7 @@ void generate_weaponry_usage_list_team(int team, int *arr); void generate_weaponry_usage_list_wing(int wing_num, int *arr); void time_to_mission_info_string(const std::tm* src, char* dest, size_t dest_max_len); + +bool rejectOrCloseHandler(QDialog* dialog, + fso::fred::dialogs::AbstractDialogModel* model, + fso::fred::EditorViewport* viewport); \ No newline at end of file diff --git a/qtfred/src/ui/dialogs/AsteroidEditorDialog.cpp b/qtfred/src/ui/dialogs/AsteroidEditorDialog.cpp index 10a3b4eef7c..39760412e82 100644 --- a/qtfred/src/ui/dialogs/AsteroidEditorDialog.cpp +++ b/qtfred/src/ui/dialogs/AsteroidEditorDialog.cpp @@ -331,6 +331,8 @@ void AsteroidEditorDialog::updateUI() ui->lineEdit_ibox_maxZ->setText(_model->AsteroidEditorDialogModel::getBoxText(AsteroidEditorDialogModel::_I_MAX_Z)); } + + void AsteroidEditorDialog::done(int r) { if(QDialog::Accepted == r) // ok was pressed diff --git a/qtfred/src/ui/dialogs/ShipEditor/PlayerOrdersDialog.cpp b/qtfred/src/ui/dialogs/ShipEditor/PlayerOrdersDialog.cpp index 0c128a41d66..fa8fed317de 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/PlayerOrdersDialog.cpp +++ b/qtfred/src/ui/dialogs/ShipEditor/PlayerOrdersDialog.cpp @@ -2,24 +2,20 @@ #include "ui_PlayerOrdersDialog.h" #include - +#include "mission/util.h" #include namespace fso { namespace fred { namespace dialogs { - PlayerOrdersDialog::PlayerOrdersDialog(QDialog* parent, EditorViewport* viewport) - : QDialog(parent), ui(new Ui::PlayerOrdersDialog()), + PlayerOrdersDialog::PlayerOrdersDialog(QDialog* parent, EditorViewport* viewport, bool editMultiple) + : QDialog(parent), ui(new Ui::PlayerOrdersDialog()), + _model(new PlayerOrdersDialogModel(this, viewport, editMultiple)), _viewport(viewport) { - parentDialog = dynamic_cast(parent); - Assert(parentDialog); - _model = std::unique_ptr(new PlayerOrdersDialogModel(this, - viewport, - parentDialog->getIfMultipleShips())); ui->setupUi(this); connect(this, &QDialog::accepted, _model.get(), &PlayerOrdersDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &PlayerOrdersDialogModel::reject); + connect(ui->cancelButton, &QPushButton::clicked, this, &PlayerOrdersDialog::rejectHandler); for (size_t i = 0; i < _model->getAcceptedOrders().size(); i++) { //i == 0 check added to avoid culling first entry where getAcceptedOrders returns 0 if (_model->getAcceptedOrders()[i] || i == 0) { @@ -43,30 +39,15 @@ namespace fso { resize(QDialog::sizeHint()); } PlayerOrdersDialog::~PlayerOrdersDialog() = default; - void PlayerOrdersDialog::closeEvent(QCloseEvent* event) + void PlayerOrdersDialog::closeEvent(QCloseEvent* e) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, "Changes detected", "Do you want to keep your changes?", - { DialogButton::Yes, DialogButton::No, DialogButton::Cancel }); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - } - - QDialog::closeEvent(event); + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; } - void PlayerOrdersDialog::showEvent(QShowEvent* e) + void PlayerOrdersDialog::rejectHandler() { - _model->initialiseData(parentDialog->getIfMultipleShips()); - - QDialog::showEvent(e); + this->close(); } void PlayerOrdersDialog::updateUI() { diff --git a/qtfred/src/ui/dialogs/ShipEditor/PlayerOrdersDialog.h b/qtfred/src/ui/dialogs/ShipEditor/PlayerOrdersDialog.h index 345de00fd34..d3f7d0403bc 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/PlayerOrdersDialog.h +++ b/qtfred/src/ui/dialogs/ShipEditor/PlayerOrdersDialog.h @@ -4,7 +4,6 @@ #include #include -#include namespace fso { namespace fred { @@ -13,24 +12,22 @@ namespace fso { namespace Ui { class PlayerOrdersDialog; } - class ShipEditorDialog; class PlayerOrdersDialog : public QDialog { Q_OBJECT public: - explicit PlayerOrdersDialog(QDialog* parent, EditorViewport* viewport); + explicit PlayerOrdersDialog(QDialog* parent, EditorViewport* viewport, bool editMultiple); ~PlayerOrdersDialog() override; protected: void closeEvent(QCloseEvent*) override; - void showEvent(QShowEvent*) override; + void rejectHandler(); private: std::unique_ptr ui; std::unique_ptr _model; EditorViewport* _viewport; - ShipEditorDialog* parentDialog; void updateUI(); diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipCustomWarpDialog.cpp b/qtfred/src/ui/dialogs/ShipEditor/ShipCustomWarpDialog.cpp index 7f8c86ebc80..478f08612c1 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipCustomWarpDialog.cpp +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipCustomWarpDialog.cpp @@ -2,6 +2,8 @@ #include "ui_ShipCustomWarpDialog.h" +#include "mission/util.h" + #include #include @@ -67,26 +69,9 @@ ShipCustomWarpDialog::ShipCustomWarpDialog(QDialog* parent, EditorViewport* view ShipCustomWarpDialog::~ShipCustomWarpDialog() = default; void ShipCustomWarpDialog::closeEvent(QCloseEvent* e) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, - "Changes detected", - "Do you want to keep your changes?", - {DialogButton::Yes, DialogButton::No, DialogButton::Cancel}); - - if (button == DialogButton::Cancel) { - e->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - if (button == DialogButton::No) { - _model->reject(); - } - } - QDialog::closeEvent(e); + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; } void ShipCustomWarpDialog::updateUI(const bool firstrun) { @@ -153,29 +138,9 @@ void ShipCustomWarpDialog::updateUI(const bool firstrun) } void ShipCustomWarpDialog::rejectHandler() { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, - "Changes detected", - "Do you want to keep your changes?", - {DialogButton::Yes, DialogButton::No, DialogButton::Cancel}); - - if (button == DialogButton::Cancel) { - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - if (button == DialogButton::No) { - _model->reject(); - QDialog::reject(); - } - } else { - _model->reject(); - QDialog::reject(); - } + this->close(); } + void ShipCustomWarpDialog::startSoundChanged() { // String wrangling reqired in order to avoid crashes when directly converting from Qstring to std::string on some diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.cpp b/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.cpp index f06c39ea12c..15fff8905f8 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.cpp +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.cpp @@ -174,35 +174,30 @@ void ShipEditorDialog::showEvent(QShowEvent* e) { void ShipEditorDialog::on_miscButton_clicked() { - if (!flagsDialog) { - flagsDialog = std::unique_ptr(new dialogs::ShipFlagsDialog(this, _viewport)); - } - flagsDialog->show(); + auto dialog = new dialogs::ShipFlagsDialog(this, _viewport); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void ShipEditorDialog::on_initialStatusButton_clicked() { - if (!initialStatusDialog) { - initialStatusDialog = - std::unique_ptr(new dialogs::ShipInitialStatusDialog(this, _viewport)); - } - initialStatusDialog->show(); + auto dialog = new dialogs::ShipInitialStatusDialog(this, _viewport, getIfMultipleShips()); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void ShipEditorDialog::on_initialOrdersButton_clicked() { - if (!GoalsDialog) { - GoalsDialog = std::unique_ptr(new dialogs::ShipGoalsDialog(this, _viewport)); - } - GoalsDialog->show(); + auto dialog = new dialogs::ShipGoalsDialog(this, _viewport, getIfMultipleShips(), Ships[getSingleShip()].objnum, -1); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void ShipEditorDialog::on_tblInfoButton_clicked() { - if (!TBLViewer) { - TBLViewer = std::unique_ptr(new dialogs::ShipTBLViewer(this, _viewport)); - } - TBLViewer->show(); + auto dialog = new dialogs::ShipTBLViewer(this, _viewport, getShipClass()); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void ShipEditorDialog::update() @@ -801,11 +796,9 @@ void ShipEditorDialog::DepartureCueChanged(const bool value) void ShipEditorDialog::on_textureReplacementButton_clicked() { - if (!TextureReplacementDialog) { - TextureReplacementDialog = - std::unique_ptr(new dialogs::ShipTextureReplacementDialog(this, _viewport)); - } - TextureReplacementDialog->show(); + auto dialog = new dialogs::ShipTextureReplacementDialog(this, _viewport, getIfMultipleShips()); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void ShipEditorDialog::on_playerShipButton_clicked() @@ -838,18 +831,15 @@ void ShipEditorDialog::on_weaponsButton_clicked() } void ShipEditorDialog::on_playerOrdersButton_clicked() { - if (!playerOrdersDialog) { - playerOrdersDialog = std::unique_ptr(new dialogs::PlayerOrdersDialog(this, _viewport)); - } - playerOrdersDialog->show(); + auto dialog = new dialogs::PlayerOrdersDialog(this, _viewport, getIfMultipleShips()); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void ShipEditorDialog::on_specialStatsButton_clicked() { - if (!specialStatsDialog) { - specialStatsDialog = - std::unique_ptr(new dialogs::ShipSpecialStatsDialog(this, _viewport)); - } - specialStatsDialog->show(); + auto dialog = new dialogs::ShipSpecialStatsDialog(this, _viewport); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void ShipEditorDialog::on_hideCuesButton_clicked() { @@ -873,6 +863,7 @@ void ShipEditorDialog::on_restrictArrivalPathsButton_clicked() { int target_class = Ships[_model->getArrivalTarget()].ship_info_index; auto dialog = new dialogs::ShipPathsDialog(this, _viewport, _model->getSingleShip(), target_class, false); + dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); @@ -880,17 +871,20 @@ void ShipEditorDialog::on_restrictArrivalPathsButton_clicked() void ShipEditorDialog::on_customWarpinButton_clicked() { auto dialog = new dialogs::ShipCustomWarpDialog(this, _viewport, false); + dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } void ShipEditorDialog::on_restrictDeparturePathsButton_clicked() { int target_class = Ships[_model->getDepartureTarget()].ship_info_index; auto dialog = new dialogs::ShipPathsDialog(this, _viewport, _model->getSingleShip(), target_class, true); + dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } void ShipEditorDialog::on_customWarpoutButton_clicked() { auto dialog = new dialogs::ShipCustomWarpDialog(this, _viewport, true); + dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } } // namespace dialogs diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.h b/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.h index 03dc286a238..39869539d36 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.h +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.h @@ -15,7 +15,6 @@ #include "ShipCustomWarpDialog.h" #include -#include namespace fso { @@ -26,13 +25,6 @@ namespace Ui { class ShipEditorDialog; } -class ShipTBLViewer; -class ShipGoalsDialog; -class ShipInitialStatusDialog; -class ShipFlagsDialog; -class ShipTextureReplacementDialog; -class PlayerOrdersDialog; - /** * @brief QTFred's Ship Editor */ @@ -137,14 +129,6 @@ class ShipEditorDialog : public QDialog, public SexpTreeEditorInterface { void departureDelayChanged(const int); void departureWarpChanged(const bool); void DepartureCueChanged(const bool); - - std::unique_ptr GoalsDialog = nullptr; - std::unique_ptr initialStatusDialog = nullptr; - std::unique_ptr flagsDialog = nullptr; - std::unique_ptr TextureReplacementDialog = nullptr; - std::unique_ptr playerOrdersDialog = nullptr; - std::unique_ptr specialStatsDialog = nullptr; - std::unique_ptr TBLViewer = nullptr; }; } // namespace dialogs } // namespace fred diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipFlagsDialog.cpp b/qtfred/src/ui/dialogs/ShipEditor/ShipFlagsDialog.cpp index d4bac2bad24..7272df4816c 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipFlagsDialog.cpp +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipFlagsDialog.cpp @@ -3,7 +3,7 @@ #include "ui_ShipFlagsDialog.h" #include - +#include #include namespace fso { @@ -17,6 +17,7 @@ ShipFlagsDialog::ShipFlagsDialog(QWidget* parent, EditorViewport* viewport) ui->setupUi(this); connect(this, &QDialog::accepted, _model.get(), &ShipFlagsDialogModel::apply); + connect(ui->cancelButton, &QPushButton::clicked, this, &ShipFlagsDialog::rejectHandler); connect(this, &QDialog::rejected, _model.get(), &ShipFlagsDialogModel::reject); @@ -100,35 +101,16 @@ ShipFlagsDialog::ShipFlagsDialog(QWidget* parent, EditorViewport* viewport) ShipFlagsDialog::~ShipFlagsDialog() = default; -void ShipFlagsDialog::closeEvent(QCloseEvent* event) +void ShipFlagsDialog::closeEvent(QCloseEvent* e) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, - "Changes detected", - "Do you want to keep your changes?", - {DialogButton::Yes, DialogButton::No, DialogButton::Cancel}); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - } - - QDialog::closeEvent(event); + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; } - -void ShipFlagsDialog::showEvent(QShowEvent* event) +void ShipFlagsDialog::rejectHandler() { - _model->initializeData(); - - QDialog::showEvent(event); + this->close(); } - void ShipFlagsDialog::updateUI() { util::SignalBlockers blockers(this); diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipFlagsDialog.h b/qtfred/src/ui/dialogs/ShipEditor/ShipFlagsDialog.h index 2c88ed6a802..8a828457195 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipFlagsDialog.h +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipFlagsDialog.h @@ -21,7 +21,8 @@ class ShipFlagsDialog : public QDialog { protected: void closeEvent(QCloseEvent*) override; - void showEvent(QShowEvent*) override; + + void rejectHandler(); private: std::unique_ptr ui; diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipGoalsDialog.cpp b/qtfred/src/ui/dialogs/ShipEditor/ShipGoalsDialog.cpp index 7534cd1ce40..9691479537c 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipGoalsDialog.cpp +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipGoalsDialog.cpp @@ -5,14 +5,15 @@ #include #include #include - +#include "mission/util.h" #include namespace fso { namespace fred { namespace dialogs { -ShipGoalsDialog::ShipGoalsDialog(QWidget* parent, EditorViewport* viewport) - : QDialog(parent), ui(new Ui::ShipGoalsDialog()), +ShipGoalsDialog::ShipGoalsDialog(QWidget* parent, EditorViewport* viewport, bool editMultiple, int shipID, int wingID) + : QDialog(parent), ui(new Ui::ShipGoalsDialog()), _model(new ShipGoalsDialogModel(this, + viewport, editMultiple, shipID, wingID)), _viewport(viewport) { ui->setupUi(this); @@ -71,18 +72,7 @@ ShipGoalsDialog::ShipGoalsDialog(QWidget* parent, EditorViewport* viewport) priority[8] = ui->prioritySpinBox9; priority[9] = ui->prioritySpinBox10; connect(this, &QDialog::accepted, _model.get(), &ShipGoalsDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &ShipGoalsDialogModel::reject); - parentDialog = dynamic_cast(parent); - if (parentDialog == nullptr) { - //TODO: Add wing editor Here - WingMode = true; - } else { - _model = std::unique_ptr(new ShipGoalsDialogModel(this, - viewport, - parentDialog->getIfMultipleShips(), - Ships[parentDialog->getSingleShip()].objnum, - -1)); - } + connect(ui->cancelButton, &QPushButton::clicked, this, &ShipGoalsDialog::rejectHandler); connect(_model.get(), &AbstractDialogModel::modelChanged, this, &ShipGoalsDialog::updateUI); for (int i = 0; i < ED_MAX_GOALS; i++) { @@ -116,35 +106,15 @@ ShipGoalsDialog::ShipGoalsDialog(QWidget* parent, EditorViewport* viewport) ShipGoalsDialog::~ShipGoalsDialog() = default; -void ShipGoalsDialog::showEvent(QShowEvent* e) +void ShipGoalsDialog::closeEvent(QCloseEvent* e) { - if (!WingMode) { - _model->initializeData(parentDialog->getIfMultipleShips(), Ships[parentDialog->getSingleShip()].objnum, -1); - } - - QDialog::showEvent(e); + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; } - -void ShipGoalsDialog::closeEvent(QCloseEvent* event) +void ShipGoalsDialog::rejectHandler() { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, - "Changes detected", - "Do you want to keep your changes?", - {DialogButton::Yes, DialogButton::No, DialogButton::Cancel}); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - } - - QDialog::closeEvent(event); + this->close(); } void ShipGoalsDialog::updateUI() diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipGoalsDialog.h b/qtfred/src/ui/dialogs/ShipEditor/ShipGoalsDialog.h index a767e20b25f..02bbe8dab43 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipGoalsDialog.h +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipGoalsDialog.h @@ -7,25 +7,23 @@ #include #include -#include "ShipEditorDialog.h" - namespace fso { namespace fred { namespace dialogs { namespace Ui { class ShipGoalsDialog; } -class ShipEditorDialog; class ShipGoalsDialog : public QDialog { Q_OBJECT public: - explicit ShipGoalsDialog(QWidget* parent, EditorViewport* viewport); + explicit ShipGoalsDialog(QWidget* parent, EditorViewport* viewport, bool editMultiple, int shipID, int wingID); ~ShipGoalsDialog() override; protected: void closeEvent(QCloseEvent*) override; - void showEvent(QShowEvent* e) override; + + void rejectHandler(); private: std::unique_ptr ui; @@ -39,8 +37,6 @@ class ShipGoalsDialog : public QDialog { QSpinBox* priority[ED_MAX_GOALS]; void updateUI(); - bool WingMode; - ShipEditorDialog* parentDialog = nullptr; }; } // namespace dialogs } // namespace fred diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipInitialStatusDialog.cpp b/qtfred/src/ui/dialogs/ShipEditor/ShipInitialStatusDialog.cpp index b4e3ec887da..47595309037 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipInitialStatusDialog.cpp +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipInitialStatusDialog.cpp @@ -9,24 +9,21 @@ #include #include #include - +#include "mission/util.h" #include namespace fso { namespace fred { namespace dialogs { - ShipInitialStatusDialog::ShipInitialStatusDialog(QDialog* parent, EditorViewport* viewport) - : QDialog(parent), ui(new Ui::ShipInitialStatusDialog()), _viewport(viewport) + ShipInitialStatusDialog::ShipInitialStatusDialog(QDialog* parent, EditorViewport* viewport, bool editMultiple) + : QDialog(parent), ui(new Ui::ShipInitialStatusDialog()), + _model(new ShipInitialStatusDialogModel(this, viewport, editMultiple)), _viewport(viewport) { ui->setupUi(this); - parentDialog = dynamic_cast(parent); - Assert(parentDialog); - _model = std::unique_ptr(new ShipInitialStatusDialogModel(this, - viewport, parentDialog->getIfMultipleShips())); connect(this, &QDialog::accepted, _model.get(), &ShipInitialStatusDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &ShipInitialStatusDialogModel::reject); + connect(ui->cancelPushButton, &QPushButton::clicked, this, &ShipInitialStatusDialog::rejectHandler); connect(_model.get(), &AbstractDialogModel::modelChanged, this, &ShipInitialStatusDialog::updateUI); // Velocity @@ -84,30 +81,15 @@ namespace fso { ShipInitialStatusDialog::~ShipInitialStatusDialog() = default; - void ShipInitialStatusDialog::closeEvent(QCloseEvent* event) + void ShipInitialStatusDialog::closeEvent(QCloseEvent* e) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, - "Changes detected", - "Do you want to keep your changes?", - { DialogButton::Yes, DialogButton::No, DialogButton::Cancel }); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - } - - QDialog::closeEvent(event); + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; } - void ShipInitialStatusDialog::showEvent(QShowEvent* event) { - _model->initializeData(parentDialog->getIfMultipleShips()); - QDialog::showEvent(event); + void ShipInitialStatusDialog::rejectHandler() + { + this->close(); } void ShipInitialStatusDialog::updateUI() { diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipInitialStatusDialog.h b/qtfred/src/ui/dialogs/ShipEditor/ShipInitialStatusDialog.h index 67fa0df219a..b0b4420492c 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipInitialStatusDialog.h +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipInitialStatusDialog.h @@ -2,7 +2,6 @@ #define SHIPINITIALSTATUSDIALOG_H #include -#include "ShipEditorDialog.h" #include #include @@ -13,24 +12,22 @@ namespace dialogs { namespace Ui { class ShipInitialStatusDialog; } -class ShipEditorDialog; class ShipInitialStatusDialog : public QDialog { Q_OBJECT public: - explicit ShipInitialStatusDialog(QDialog* parent, EditorViewport* viewport); + explicit ShipInitialStatusDialog(QDialog* parent, EditorViewport* viewport, bool editMultiple); ~ShipInitialStatusDialog() override; protected: void closeEvent(QCloseEvent*) override; - void showEvent(QShowEvent*) override; + void rejectHandler(); private: std::unique_ptr ui; std::unique_ptr _model; EditorViewport* _viewport; - ShipEditorDialog* parentDialog; void updateUI(); void updateFlags(); diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipPathsDialog.cpp b/qtfred/src/ui/dialogs/ShipEditor/ShipPathsDialog.cpp index 948eac6aca8..62e151db8ed 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipPathsDialog.cpp +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipPathsDialog.cpp @@ -3,6 +3,7 @@ #include #include +#include namespace fso { namespace fred { namespace dialogs { @@ -29,53 +30,14 @@ ShipPathsDialog::ShipPathsDialog(QWidget* parent, resize(QDialog::sizeHint()); } ShipPathsDialog::~ShipPathsDialog() = default; -void ShipPathsDialog::closeEvent(QCloseEvent* event) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, - "Changes detected", - "Do you want to keep your changes?", - {DialogButton::Yes, DialogButton::No, DialogButton::Cancel}); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - if (button == DialogButton::No) { - _model->reject(); - } - } - - QDialog::closeEvent(event); +void ShipPathsDialog::closeEvent(QCloseEvent* e) { + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; } void ShipPathsDialog::rejectHandler() { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, - "Changes detected", - "Do you want to keep your changes?", - {DialogButton::Yes, DialogButton::No, DialogButton::Cancel}); - - if (button == DialogButton::Cancel) { - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - if (button == DialogButton::No) { - _model->reject(); - QDialog::reject(); - } - } else { - _model->reject(); - QDialog::reject(); - } + this->close(); } void ShipPathsDialog::updateUI() { util::SignalBlockers blockers(this); diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipSpecialStatsDialog.cpp b/qtfred/src/ui/dialogs/ShipEditor/ShipSpecialStatsDialog.cpp index 5d1fe5186ea..b6d570805bd 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipSpecialStatsDialog.cpp +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipSpecialStatsDialog.cpp @@ -3,7 +3,7 @@ #include "ui_ShipSpecialStatsDialog.h" #include - +#include #include namespace fso { @@ -17,7 +17,7 @@ namespace fso { ui->setupUi(this); connect(this, &QDialog::accepted, _model.get(), &ShipSpecialStatsDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &ShipSpecialStatsDialogModel::reject); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ShipSpecialStatsDialog::rejectHandler); connect(_model.get(), &AbstractDialogModel::modelChanged, this, &ShipSpecialStatsDialog::updateUI); connect(ui->explodeCheckBox, &QCheckBox::toggled, _model.get(), &ShipSpecialStatsDialogModel::setSpecialExp); @@ -43,32 +43,16 @@ namespace fso { ShipSpecialStatsDialog::~ShipSpecialStatsDialog() = default; - void ShipSpecialStatsDialog::closeEvent(QCloseEvent* event) + void ShipSpecialStatsDialog::closeEvent(QCloseEvent* e) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, - "Changes detected", - "Do you want to keep your changes?", - { DialogButton::Yes, DialogButton::No, DialogButton::Cancel }); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - } - - QDialog::closeEvent(event); + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; } - void ShipSpecialStatsDialog::showEvent(QShowEvent* event) { - _model->initializeData(); - - QDialog::showEvent(event); + void ShipSpecialStatsDialog::rejectHandler() + { + this->close(); } void ShipSpecialStatsDialog::updateUI() diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipSpecialStatsDialog.h b/qtfred/src/ui/dialogs/ShipEditor/ShipSpecialStatsDialog.h index 1762678235e..94b7ddc2810 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipSpecialStatsDialog.h +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipSpecialStatsDialog.h @@ -21,7 +21,8 @@ namespace fso { protected: void closeEvent(QCloseEvent*) override; - void showEvent(QShowEvent*) override; + + void rejectHandler(); private: std::unique_ptr ui; diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipTBLViewer.cpp b/qtfred/src/ui/dialogs/ShipEditor/ShipTBLViewer.cpp index 4e54dbadb33..47351dd9edb 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipTBLViewer.cpp +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipTBLViewer.cpp @@ -9,12 +9,10 @@ namespace fso { namespace fred { namespace dialogs { -ShipTBLViewer::ShipTBLViewer(QWidget* parent, EditorViewport* viewport) - : QDialog(parent), ui(new Ui::ShipTBLViewer()), _viewport(viewport) +ShipTBLViewer::ShipTBLViewer(QWidget* parent, EditorViewport* viewport, int shipClass) + : QDialog(parent), ui(new Ui::ShipTBLViewer()), _model(new ShipTBLViewerModel(this, viewport, shipClass)), + _viewport(viewport) { - parentDialog = dynamic_cast(parent); - Assert(parentDialog); - _model = std::unique_ptr(new ShipTBLViewerModel(this, viewport, parentDialog->getShipClass())); ui->setupUi(this); @@ -31,11 +29,6 @@ void ShipTBLViewer::closeEvent(QCloseEvent* event) { QDialog::closeEvent(event); } -void ShipTBLViewer::showEvent(QShowEvent* e) { - _model->initializeData(parentDialog->getShipClass()); - - QDialog::showEvent(e); -} void ShipTBLViewer::updateUI() { util::SignalBlockers blockers(this); diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipTBLViewer.h b/qtfred/src/ui/dialogs/ShipEditor/ShipTBLViewer.h index b49fbf611f9..db314988ce2 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipTBLViewer.h +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipTBLViewer.h @@ -3,7 +3,6 @@ #include #include -#include "ShipEditorDialog.h" namespace fso { namespace fred { @@ -12,25 +11,21 @@ namespace dialogs { namespace Ui { class ShipTBLViewer; } -class ShipEditorDialog; class ShipTBLViewer : public QDialog { Q_OBJECT public: - explicit ShipTBLViewer(QWidget* parent, EditorViewport* viewport); + explicit ShipTBLViewer(QWidget* parent, EditorViewport* viewport, int shipClass); ~ShipTBLViewer() override; protected: void closeEvent(QCloseEvent*) override; - void showEvent(QShowEvent* e) override; private: std::unique_ptr ui; std::unique_ptr _model; EditorViewport* _viewport; - ShipEditorDialog* parentDialog = nullptr; - int sc; void updateUI(); diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipTextureReplacementDialog.cpp b/qtfred/src/ui/dialogs/ShipEditor/ShipTextureReplacementDialog.cpp index d108d9b06c6..e2440afc66e 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipTextureReplacementDialog.cpp +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipTextureReplacementDialog.cpp @@ -4,6 +4,7 @@ #include #include +#include namespace fso { namespace fred { namespace dialogs { @@ -35,19 +36,18 @@ namespace fso { } - ShipTextureReplacementDialog::ShipTextureReplacementDialog(QDialog* parent, EditorViewport* viewport) + ShipTextureReplacementDialog::ShipTextureReplacementDialog(QDialog* parent, EditorViewport* viewport, bool multiEdit) : QDialog(parent), ui(new Ui::ShipTextureReplacementDialog()), - _viewport(viewport) + _model(new ShipTextureReplacementDialogModel(this, viewport, multiEdit)), _viewport(viewport) { ui->setupUi(this); - parentDialog = dynamic_cast(parent); - Assert(parentDialog); - _model = std::unique_ptr(new ShipTextureReplacementDialogModel(this, - viewport, parentDialog->getIfMultipleShips())); connect(this, &QDialog::accepted, _model.get(), &ShipTextureReplacementDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &ShipTextureReplacementDialogModel::reject); + connect(ui->buttonBox, + &QDialogButtonBox::rejected, + this, + &ShipTextureReplacementDialog::rejectHandler); listmodel = new MapModel(_model.get(), this); ui->TexturesList->setModel(listmodel); QItemSelectionModel* selectionModel = ui->TexturesList->selectionModel(); @@ -89,29 +89,16 @@ namespace fso { } ShipTextureReplacementDialog::~ShipTextureReplacementDialog() = default; - void ShipTextureReplacementDialog::closeEvent(QCloseEvent* event) + void ShipTextureReplacementDialog::closeEvent(QCloseEvent* e) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, "Changes detected", "Do you want to keep your changes?", - { DialogButton::Yes, DialogButton::No, DialogButton::Cancel }); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - } - - QDialog::closeEvent(event); + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; } - void ShipTextureReplacementDialog::showEvent(QShowEvent* event) { - _model->initialiseData(parentDialog->getIfMultipleShips()); - QDialog::showEvent(event); + void ShipTextureReplacementDialog::rejectHandler() + { + this->close(); } void ShipTextureReplacementDialog::updateUI() diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipTextureReplacementDialog.h b/qtfred/src/ui/dialogs/ShipEditor/ShipTextureReplacementDialog.h index a4aecf6802f..7b16eef07f8 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipTextureReplacementDialog.h +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipTextureReplacementDialog.h @@ -3,7 +3,6 @@ #include #include #include -#include "ShipEditorDialog.h" #include namespace fso { @@ -13,7 +12,6 @@ namespace fso { namespace Ui { class ShipTextureReplacementDialog; } - class ShipEditorDialog; //Model for mapping data to listview in Texture Replace dialog class MapModel : public QAbstractListModel { @@ -30,20 +28,19 @@ namespace fso { Q_OBJECT public: - explicit ShipTextureReplacementDialog(QDialog* parent, EditorViewport* viewport); + explicit ShipTextureReplacementDialog(QDialog* parent, EditorViewport* viewport, bool multiEdit); ~ShipTextureReplacementDialog() override; protected: void closeEvent(QCloseEvent*) override; - void showEvent(QShowEvent*) override; private: std::unique_ptr ui; std::unique_ptr _model; EditorViewport* _viewport; - ShipEditorDialog* parentDialog; int row = 0; MapModel* listmodel; void updateUI(); void updateUIFull(); + void rejectHandler(); void setMain(); void setMisc(); diff --git a/qtfred/ui/PlayerOrdersDialog.ui b/qtfred/ui/PlayerOrdersDialog.ui index 0e37290f780..41a3918113d 100644 --- a/qtfred/ui/PlayerOrdersDialog.ui +++ b/qtfred/ui/PlayerOrdersDialog.ui @@ -54,13 +54,6 @@ - - - fso::fred::ShipFlagCheckbox - QCheckBox -
ui/widgets/ShipFlagCheckbox.h
-
-
@@ -81,21 +74,5 @@ - - cancelButton - clicked() - fso::fred::dialogs::PlayerOrdersDialog - reject() - - - 147 - 159 - - - 97 - 118 - - -
diff --git a/qtfred/ui/ShipFlagsDialog.ui b/qtfred/ui/ShipFlagsDialog.ui index fbaeae46940..9ddb627b582 100644 --- a/qtfred/ui/ShipFlagsDialog.ui +++ b/qtfred/ui/ShipFlagsDialog.ui @@ -7,7 +7,7 @@ 0 0 421 - 664 + 745 @@ -709,21 +709,5 @@ - - cancelButton - clicked() - fso::fred::dialogs::ShipFlagsDialog - reject() - - - 389 - 563 - - - 375 - 515 - - -
diff --git a/qtfred/ui/ShipGoalsDialog.ui b/qtfred/ui/ShipGoalsDialog.ui index e4568b56a4e..4608e38d05a 100644 --- a/qtfred/ui/ShipGoalsDialog.ui +++ b/qtfred/ui/ShipGoalsDialog.ui @@ -7,7 +7,7 @@ 0 0 597 - 344 + 374 @@ -322,7 +322,7 @@ - + okButton clicked() @@ -339,21 +339,5 @@ - - cancelButton - clicked() - fso::fred::dialogs::ShipGoalsDialog - reject() - - - 628 - 19 - - - 357 - 297 - - -
diff --git a/qtfred/ui/ShipInitialStatus.ui b/qtfred/ui/ShipInitialStatus.ui index 1e07aa395c9..e84c7639183 100644 --- a/qtfred/ui/ShipInitialStatus.ui +++ b/qtfred/ui/ShipInitialStatus.ui @@ -421,21 +421,5 @@ - - cancelPushButton - clicked() - fso::fred::dialogs::ShipInitialStatusDialog - reject() - - - 389 - 563 - - - 375 - 515 - - -
diff --git a/qtfred/ui/ShipSpecialStatsDialog.ui b/qtfred/ui/ShipSpecialStatsDialog.ui index d8f0b095305..423fda8bc0a 100644 --- a/qtfred/ui/ShipSpecialStatsDialog.ui +++ b/qtfred/ui/ShipSpecialStatsDialog.ui @@ -6,8 +6,8 @@ 0 0 - 518 - 287 + 542 + 322 @@ -320,21 +320,5 @@ - - buttonBox - rejected() - fso::fred::dialogs::ShipSpecialStatsDialog - reject() - - - 20 - 20 - - - 20 - 20 - - -
diff --git a/qtfred/ui/ShipTextureReplacementDialog.ui b/qtfred/ui/ShipTextureReplacementDialog.ui index 2e82a1b08ab..957e0cb00f6 100644 --- a/qtfred/ui/ShipTextureReplacementDialog.ui +++ b/qtfred/ui/ShipTextureReplacementDialog.ui @@ -253,21 +253,5 @@ - - buttonBox - rejected() - fso::fred::dialogs::ShipTextureReplacementDialog - reject() - - - 296 - 179 - - - 200 - 100 - - -
From 2a7806d69093e283555f9e59819034bb36276de4 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:32:08 +0000 Subject: [PATCH 02/18] Slightly off topic but remove C style casts from selection dialog --- qtfred/src/mission/dialogs/SelectionDialogModel.cpp | 9 +++++---- qtfred/src/mission/dialogs/SelectionDialogModel.h | 4 ++-- qtfred/src/ui/dialogs/SelectionDialog.cpp | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/qtfred/src/mission/dialogs/SelectionDialogModel.cpp b/qtfred/src/mission/dialogs/SelectionDialogModel.cpp index d0dd4430c70..26c5a1cf12d 100644 --- a/qtfred/src/mission/dialogs/SelectionDialogModel.cpp +++ b/qtfred/src/mission/dialogs/SelectionDialogModel.cpp @@ -263,13 +263,14 @@ void SelectionDialogModel::setFilterWaypoints(bool filter_waypoints) { } } -bool SelectionDialogModel::isFilterIFFTeam(int team) const { - Assertion(team >= 0 && team < (int)Iff_info.size(), "Team index %d is invalid!", team); +bool SelectionDialogModel::isFilterIFFTeam(size_t team) const { + Assertion(team >= 0 && team < Iff_info.size(), "Team index %d is invalid!", team); return _filter_iff[team]; } -void SelectionDialogModel::setFilterIFFTeam(int team, bool filter) { - Assertion(team >= 0 && team < (int)Iff_info.size(), "Team index %d is invalid!", team); +void SelectionDialogModel::setFilterIFFTeam(size_t team, bool filter) +{ + Assertion(team >= 0 && team < Iff_info.size(), "Team index %d is invalid!", team); if (filter != _filter_iff[team]) { _filter_iff[team] = filter; diff --git a/qtfred/src/mission/dialogs/SelectionDialogModel.h b/qtfred/src/mission/dialogs/SelectionDialogModel.h index f686101eb88..48fb4e04f58 100644 --- a/qtfred/src/mission/dialogs/SelectionDialogModel.h +++ b/qtfred/src/mission/dialogs/SelectionDialogModel.h @@ -72,8 +72,8 @@ class SelectionDialogModel : public AbstractDialogModel { bool isFilterWaypoints() const; void setFilterWaypoints(bool filter_waypoints); - bool isFilterIFFTeam(int team) const; - void setFilterIFFTeam(int team, bool filter); + bool isFilterIFFTeam(size_t team) const; + void setFilterIFFTeam(size_t team, bool filter); /** * @brief Updates the selection status of the objects in the list diff --git a/qtfred/src/ui/dialogs/SelectionDialog.cpp b/qtfred/src/ui/dialogs/SelectionDialog.cpp index bf8ee8fe4dc..c1af891e5c2 100644 --- a/qtfred/src/ui/dialogs/SelectionDialog.cpp +++ b/qtfred/src/ui/dialogs/SelectionDialog.cpp @@ -38,7 +38,7 @@ SelectionDialog::SelectionDialog(FredView* parent, EditorViewport* viewport) : [this](int state) { _model->setFilterStarts(state == Qt::Checked); }); // Initialize IFF check boxes - for (auto i = 0; i < (int)Iff_info.size(); ++i) { + for (size_t i = 0; i < Iff_info.size(); ++i) { auto checkbox = new QCheckBox(QString::fromUtf8(Iff_info[i].iff_name), this); _iffCheckBoxes.push_back(checkbox); ui->iffSelectionContainer->addWidget(checkbox); @@ -73,7 +73,7 @@ void SelectionDialog::updateUI() { ui->checkPlayerStarts->setChecked(_model->isFilterStarts()); ui->checkWaypoints->setChecked(_model->isFilterWaypoints()); ui->checkShips->setChecked(_model->isFilterShips()); - for (auto i = 0; i < (int)Iff_info.size(); ++i) { + for (size_t i = 0; i < Iff_info.size(); ++i) { _iffCheckBoxes[i]->setChecked(_model->isFilterIFFTeam(i)); _iffCheckBoxes[i]->setEnabled(_model->isFilterShips()); } From a26d52dcea7fceccdd6237088c86165185c49f22 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:07:11 +0000 Subject: [PATCH 03/18] Revert "Slightly off topic but remove C style casts from selection dialog" This reverts commit 2a7806d69093e283555f9e59819034bb36276de4. --- qtfred/src/mission/dialogs/SelectionDialogModel.cpp | 9 ++++----- qtfred/src/mission/dialogs/SelectionDialogModel.h | 4 ++-- qtfred/src/ui/dialogs/SelectionDialog.cpp | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/qtfred/src/mission/dialogs/SelectionDialogModel.cpp b/qtfred/src/mission/dialogs/SelectionDialogModel.cpp index 26c5a1cf12d..d0dd4430c70 100644 --- a/qtfred/src/mission/dialogs/SelectionDialogModel.cpp +++ b/qtfred/src/mission/dialogs/SelectionDialogModel.cpp @@ -263,14 +263,13 @@ void SelectionDialogModel::setFilterWaypoints(bool filter_waypoints) { } } -bool SelectionDialogModel::isFilterIFFTeam(size_t team) const { - Assertion(team >= 0 && team < Iff_info.size(), "Team index %d is invalid!", team); +bool SelectionDialogModel::isFilterIFFTeam(int team) const { + Assertion(team >= 0 && team < (int)Iff_info.size(), "Team index %d is invalid!", team); return _filter_iff[team]; } -void SelectionDialogModel::setFilterIFFTeam(size_t team, bool filter) -{ - Assertion(team >= 0 && team < Iff_info.size(), "Team index %d is invalid!", team); +void SelectionDialogModel::setFilterIFFTeam(int team, bool filter) { + Assertion(team >= 0 && team < (int)Iff_info.size(), "Team index %d is invalid!", team); if (filter != _filter_iff[team]) { _filter_iff[team] = filter; diff --git a/qtfred/src/mission/dialogs/SelectionDialogModel.h b/qtfred/src/mission/dialogs/SelectionDialogModel.h index 48fb4e04f58..f686101eb88 100644 --- a/qtfred/src/mission/dialogs/SelectionDialogModel.h +++ b/qtfred/src/mission/dialogs/SelectionDialogModel.h @@ -72,8 +72,8 @@ class SelectionDialogModel : public AbstractDialogModel { bool isFilterWaypoints() const; void setFilterWaypoints(bool filter_waypoints); - bool isFilterIFFTeam(size_t team) const; - void setFilterIFFTeam(size_t team, bool filter); + bool isFilterIFFTeam(int team) const; + void setFilterIFFTeam(int team, bool filter); /** * @brief Updates the selection status of the objects in the list diff --git a/qtfred/src/ui/dialogs/SelectionDialog.cpp b/qtfred/src/ui/dialogs/SelectionDialog.cpp index c1af891e5c2..bf8ee8fe4dc 100644 --- a/qtfred/src/ui/dialogs/SelectionDialog.cpp +++ b/qtfred/src/ui/dialogs/SelectionDialog.cpp @@ -38,7 +38,7 @@ SelectionDialog::SelectionDialog(FredView* parent, EditorViewport* viewport) : [this](int state) { _model->setFilterStarts(state == Qt::Checked); }); // Initialize IFF check boxes - for (size_t i = 0; i < Iff_info.size(); ++i) { + for (auto i = 0; i < (int)Iff_info.size(); ++i) { auto checkbox = new QCheckBox(QString::fromUtf8(Iff_info[i].iff_name), this); _iffCheckBoxes.push_back(checkbox); ui->iffSelectionContainer->addWidget(checkbox); @@ -73,7 +73,7 @@ void SelectionDialog::updateUI() { ui->checkPlayerStarts->setChecked(_model->isFilterStarts()); ui->checkWaypoints->setChecked(_model->isFilterWaypoints()); ui->checkShips->setChecked(_model->isFilterShips()); - for (size_t i = 0; i < Iff_info.size(); ++i) { + for (auto i = 0; i < (int)Iff_info.size(); ++i) { _iffCheckBoxes[i]->setChecked(_model->isFilterIFFTeam(i)); _iffCheckBoxes[i]->setEnabled(_model->isFilterShips()); } From 24590dd548b355fefff0bf8bca615b6242a829da Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:09:04 +0000 Subject: [PATCH 04/18] Update Fiction Viewer --- .../dialogs/FictionViewerDialogModel.h | 11 ------- qtfred/src/ui/FredView.cpp | 5 ++-- qtfred/src/ui/dialogs/FictionViewerDialog.cpp | 30 +++++++------------ qtfred/src/ui/dialogs/FictionViewerDialog.h | 1 + qtfred/ui/FictionViewerDialog.ui | 16 ---------- 5 files changed, 14 insertions(+), 49 deletions(-) diff --git a/qtfred/src/mission/dialogs/FictionViewerDialogModel.h b/qtfred/src/mission/dialogs/FictionViewerDialogModel.h index 9247d723b16..21c9350a33c 100644 --- a/qtfred/src/mission/dialogs/FictionViewerDialogModel.h +++ b/qtfred/src/mission/dialogs/FictionViewerDialogModel.h @@ -47,8 +47,6 @@ class FictionViewerDialogModel: public AbstractDialogModel { private: void initializeData(); - template - void modify(T &a, const T &b); SCP_string _storyFile; SCP_string _fontFile; @@ -59,15 +57,6 @@ class FictionViewerDialogModel: public AbstractDialogModel { int _maxStoryFileLength, _maxFontFileLength, _maxVoiceFileLength; }; - -template -inline void FictionViewerDialogModel::modify(T &a, const T &b) { - if (a != b) { - a = b; - modelChanged(); - } -} - } } } diff --git a/qtfred/src/ui/FredView.cpp b/qtfred/src/ui/FredView.cpp index dd51ff204e4..63df4bdbe64 100644 --- a/qtfred/src/ui/FredView.cpp +++ b/qtfred/src/ui/FredView.cpp @@ -1144,8 +1144,9 @@ void FredView::on_actionMission_Objectives_triggered(bool) { } void FredView::on_actionFiction_Viewer_triggered(bool) { - dialogs::FictionViewerDialog dialog(this, _viewport); - dialog.exec(); + auto dialog = new dialogs::FictionViewerDialog(this, _viewport); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } } // namespace fred diff --git a/qtfred/src/ui/dialogs/FictionViewerDialog.cpp b/qtfred/src/ui/dialogs/FictionViewerDialog.cpp index 9d2a99978ba..3bf84192e3c 100644 --- a/qtfred/src/ui/dialogs/FictionViewerDialog.cpp +++ b/qtfred/src/ui/dialogs/FictionViewerDialog.cpp @@ -3,7 +3,7 @@ #include "ui/dialogs/FictionViewerDialog.h" #include "ui/util/SignalBlockers.h" #include "ui_FictionViewerDialog.h" - +#include "mission/util.h" namespace fso { namespace fred { namespace dialogs { @@ -23,7 +23,7 @@ FictionViewerDialog::FictionViewerDialog(FredView* parent, EditorViewport* viewp ui->voiceFileEdit->setMaxLength(_model->getMaxVoiceFileLength()); connect(this, &QDialog::accepted, _model.get(), &FictionViewerDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &FictionViewerDialogModel::reject); + connect(ui->dialogButtonBox, &QDialogButtonBox::rejected, this, &FictionViewerDialog::rejectHandler); connect(_model.get(), &AbstractDialogModel::modelChanged, this, &FictionViewerDialog::updateUI); @@ -109,25 +109,15 @@ void FictionViewerDialog::keyPressEvent(QKeyEvent* event) { QDialog::keyPressEvent(event); } -void FictionViewerDialog::closeEvent(QCloseEvent* event) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, "Changes detected", "Do you want to keep your changes?", - { DialogButton::Yes, DialogButton::No, DialogButton::Cancel }); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - } - - QDialog::closeEvent(event); +void FictionViewerDialog::closeEvent(QCloseEvent* e) { + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; +} +void FictionViewerDialog::rejectHandler() +{ + this->close(); } - } } } diff --git a/qtfred/src/ui/dialogs/FictionViewerDialog.h b/qtfred/src/ui/dialogs/FictionViewerDialog.h index ebadd07d490..09fcfd5ef09 100644 --- a/qtfred/src/ui/dialogs/FictionViewerDialog.h +++ b/qtfred/src/ui/dialogs/FictionViewerDialog.h @@ -29,6 +29,7 @@ class FictionViewerDialog : public QDialog { protected: void keyPressEvent(QKeyEvent* event) override; void closeEvent(QCloseEvent*) override; + void rejectHandler(); private: void updateMusicComboBox(); diff --git a/qtfred/ui/FictionViewerDialog.ui b/qtfred/ui/FictionViewerDialog.ui index 2e6384d9a9d..7d65057be29 100644 --- a/qtfred/ui/FictionViewerDialog.ui +++ b/qtfred/ui/FictionViewerDialog.ui @@ -100,21 +100,5 @@ - - dialogButtonBox - rejected() - fso::fred::dialogs::FictionViewerDialog - reject() - - - 138 - 134 - - - 114 - 78 - - -
From 5b23d9d3b8aa84efd2109248e7c238fc99429615 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:10:41 +0000 Subject: [PATCH 05/18] Update loadout dialog --- .../dialogs/LoadoutEditorDialogModel.cpp | 22 ++++++++++--------- qtfred/src/ui/FredView.cpp | 1 + qtfred/src/ui/dialogs/LoadoutDialog.cpp | 17 ++++++++++++-- qtfred/src/ui/dialogs/LoadoutDialog.h | 10 ++++++++- qtfred/ui/LoadoutDialog.ui | 16 -------------- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/qtfred/src/mission/dialogs/LoadoutEditorDialogModel.cpp b/qtfred/src/mission/dialogs/LoadoutEditorDialogModel.cpp index ddc367241d8..13c1b883306 100644 --- a/qtfred/src/mission/dialogs/LoadoutEditorDialogModel.cpp +++ b/qtfred/src/mission/dialogs/LoadoutEditorDialogModel.cpp @@ -233,6 +233,7 @@ void LoadoutDialogModel::setPlayerEntryDelay(float delay) { _playerEntryDelay = delay; modelChanged(); + set_modified(); } @@ -721,7 +722,7 @@ void LoadoutDialogModel::setShipEnabled(const SCP_vector& list, bool } } } - + set_modified(); buildCurrentLists(); } @@ -754,7 +755,7 @@ void LoadoutDialogModel::setShipVariableEnabled(const SCP_vector& li item); } } - + set_modified(); buildCurrentLists(); } @@ -780,7 +781,7 @@ void LoadoutDialogModel::setWeaponEnabled(const SCP_vector& list, bo } } } - + set_modified(); buildCurrentLists(); } @@ -813,7 +814,7 @@ void LoadoutDialogModel::setWeaponVariableEnabled(const SCP_vector& item); } } - + set_modified(); buildCurrentLists(); } @@ -828,7 +829,7 @@ void LoadoutDialogModel::setExtraAllocatedShipCount(const SCP_vector } } } - + set_modified(); buildCurrentLists(); } @@ -842,7 +843,7 @@ void LoadoutDialogModel::setExtraAllocatedForShipVariablesCount(const SCP_vector } } } - + set_modified(); buildCurrentLists(); } @@ -856,7 +857,7 @@ void LoadoutDialogModel::setExtraAllocatedWeaponCount(const SCP_vector& list, c } } } - + set_modified(); buildCurrentLists(); } @@ -942,6 +943,7 @@ void LoadoutDialogModel::setSkipValidation(const bool skipIt) { // this is designed to be a global control, so turn this off in TvT, until we hear from someone otherwise. for (auto& team : _teams) { team.skipValidation = skipIt; + set_modified(); } } diff --git a/qtfred/src/ui/FredView.cpp b/qtfred/src/ui/FredView.cpp index 63df4bdbe64..747af1e4082 100644 --- a/qtfred/src/ui/FredView.cpp +++ b/qtfred/src/ui/FredView.cpp @@ -758,6 +758,7 @@ void FredView::on_actionReinforcements_triggered(bool) { } void FredView::on_actionLoadout_triggered(bool) { auto editorDialog = new dialogs::LoadoutDialog(this, _viewport); + editorDialog->setAttribute(Qt::WA_DeleteOnClose); editorDialog->show(); } DialogButton FredView::showButtonDialog(DialogType type, diff --git a/qtfred/src/ui/dialogs/LoadoutDialog.cpp b/qtfred/src/ui/dialogs/LoadoutDialog.cpp index 9e730551c21..8952ad3d317 100644 --- a/qtfred/src/ui/dialogs/LoadoutDialog.cpp +++ b/qtfred/src/ui/dialogs/LoadoutDialog.cpp @@ -6,6 +6,7 @@ #include #include #include +#include constexpr int TABLE_MODE = 0; constexpr int VARIABLE_MODE = 1; @@ -23,7 +24,7 @@ LoadoutDialog::LoadoutDialog(FredView* parent, EditorViewport* viewport) // Major Changes, like Applying the model, rejecting changes and updating the UI. connect(_model.get(), &AbstractDialogModel::modelChanged, this, &LoadoutDialog::updateUI); connect(this, &QDialog::accepted, _model.get(), &LoadoutDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &LoadoutDialogModel::reject); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &LoadoutDialog::rejectHandler); // Ship and Weapon lists, selection changed. connect(ui->listShipsNotUsed, @@ -237,7 +238,19 @@ LoadoutDialog::LoadoutDialog(FredView* parent, EditorViewport* viewport) } // a result of competing CI requirements -LoadoutDialog::~LoadoutDialog(){} // NOLINT +LoadoutDialog::~LoadoutDialog() {} // NOLINT + +void LoadoutDialog::closeEvent(QCloseEvent* e) +{ + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; +} + +void LoadoutDialog::rejectHandler() +{ + this->close(); +} void LoadoutDialog::onSwitchViewButtonPressed() { diff --git a/qtfred/src/ui/dialogs/LoadoutDialog.h b/qtfred/src/ui/dialogs/LoadoutDialog.h index 7c47b7861ff..5802642ca33 100644 --- a/qtfred/src/ui/dialogs/LoadoutDialog.h +++ b/qtfred/src/ui/dialogs/LoadoutDialog.h @@ -29,7 +29,15 @@ class LoadoutDialog : public QDialog explicit LoadoutDialog(FredView* parent, EditorViewport* viewport); ~LoadoutDialog() override; -private: + protected: + /** + * @brief Overides the Dialogs Close event to add a confermation dialog + * @param [in] *e The event. + */ + void closeEvent(QCloseEvent*) override; + void rejectHandler(); + + private: std::unique_ptr ui; std::unique_ptr _model; EditorViewport* _viewport; diff --git a/qtfred/ui/LoadoutDialog.ui b/qtfred/ui/LoadoutDialog.ui index a454de8ee09..a80e96f859c 100644 --- a/qtfred/ui/LoadoutDialog.ui +++ b/qtfred/ui/LoadoutDialog.ui @@ -957,21 +957,5 @@ - - buttonBox - rejected() - fso::fred::dialogs::LoadoutDialog - reject() - - - 309 - 625 - - - 309 - 321 - - -
From 069a30c1905f3eb171ec9d4385a37fc4f148ad36 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:16:27 +0000 Subject: [PATCH 06/18] Update Mission Spec dialog --- .../dialogs/MissionSpecDialogModel.cpp | 10 ------- .../mission/dialogs/MissionSpecDialogModel.h | 16 ---------- qtfred/src/ui/FredView.cpp | 1 + qtfred/src/ui/dialogs/MissionSpecDialog.cpp | 29 +++++++------------ qtfred/src/ui/dialogs/MissionSpecDialog.h | 1 + qtfred/ui/MissionSpecDialog.ui | 16 ---------- 6 files changed, 12 insertions(+), 61 deletions(-) diff --git a/qtfred/src/mission/dialogs/MissionSpecDialogModel.cpp b/qtfred/src/mission/dialogs/MissionSpecDialogModel.cpp index 8ce9fa26444..c5eeaa0cf06 100644 --- a/qtfred/src/mission/dialogs/MissionSpecDialogModel.cpp +++ b/qtfred/src/mission/dialogs/MissionSpecDialogModel.cpp @@ -367,16 +367,6 @@ SCP_string MissionSpecDialogModel::getDesignerNoteText() { return _m_mission_notes; } -void MissionSpecDialogModel::set_modified() { - if (!_modified) { - _modified = true; - } -} - -bool MissionSpecDialogModel::query_modified() { - return _modified; -} - } } } diff --git a/qtfred/src/mission/dialogs/MissionSpecDialogModel.h b/qtfred/src/mission/dialogs/MissionSpecDialogModel.h index 5d48d93fc67..ceaf9b05637 100644 --- a/qtfred/src/mission/dialogs/MissionSpecDialogModel.h +++ b/qtfred/src/mission/dialogs/MissionSpecDialogModel.h @@ -16,10 +16,6 @@ class MissionSpecDialogModel : public AbstractDialogModel { private: void initializeData(); - template - void modify(T &a, const T &b); - - bool _modified = false; SCP_string _m_created; SCP_string _m_modified; @@ -49,8 +45,6 @@ class MissionSpecDialogModel : public AbstractDialogModel { int _m_type; - void set_modified(); - public: MissionSpecDialogModel(QObject* parent, EditorViewport* viewport); @@ -122,18 +116,8 @@ class MissionSpecDialogModel : public AbstractDialogModel { void setDesignerNoteText(const SCP_string&); SCP_string getDesignerNoteText(); - bool query_modified(); }; -template -inline void MissionSpecDialogModel::modify(T &a, const T &b) { - if (a != b) { - a = b; - set_modified(); - modelChanged(); - } -} - } } } diff --git a/qtfred/src/ui/FredView.cpp b/qtfred/src/ui/FredView.cpp index 747af1e4082..0acb6a625d7 100644 --- a/qtfred/src/ui/FredView.cpp +++ b/qtfred/src/ui/FredView.cpp @@ -728,6 +728,7 @@ void FredView::on_actionBriefing_triggered(bool) { } void FredView::on_actionMission_Specs_triggered(bool) { auto missionSpecEditor = new dialogs::MissionSpecDialog(this, _viewport); + missionSpecEditor->setAttribute(Qt::WA_DeleteOnClose); missionSpecEditor->show(); } void FredView::on_actionWaypoint_Paths_triggered(bool) { diff --git a/qtfred/src/ui/dialogs/MissionSpecDialog.cpp b/qtfred/src/ui/dialogs/MissionSpecDialog.cpp index c35a6370715..8679c03c6c1 100644 --- a/qtfred/src/ui/dialogs/MissionSpecDialog.cpp +++ b/qtfred/src/ui/dialogs/MissionSpecDialog.cpp @@ -3,7 +3,7 @@ #include "ui_MissionSpecDialog.h" #include - +#include "mission/util.h" #include #include @@ -17,7 +17,7 @@ MissionSpecDialog::MissionSpecDialog(FredView* parent, EditorViewport* viewport) ui->setupUi(this); connect(this, &QDialog::accepted, _model.get(), &MissionSpecDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &MissionSpecDialogModel::reject); + connect(ui->dialogButtonBox, &QDialogButtonBox::rejected, _model.get(), &MissionSpecDialogModel::reject); connect(_model.get(), &AbstractDialogModel::modelChanged, this, &MissionSpecDialog::updateUI); @@ -103,23 +103,14 @@ MissionSpecDialog::MissionSpecDialog(FredView* parent, EditorViewport* viewport) MissionSpecDialog::~MissionSpecDialog() { } -void MissionSpecDialog::closeEvent(QCloseEvent* event) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, "Changes detected", "Do you want to keep your changes?", - { DialogButton::Yes, DialogButton::No, DialogButton::Cancel }); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - } - - QDialog::closeEvent(event); +void MissionSpecDialog::closeEvent(QCloseEvent* e) { + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; +} +void MissionSpecDialog::rejectHandler() +{ + this->close(); } void MissionSpecDialog::updateUI() { diff --git a/qtfred/src/ui/dialogs/MissionSpecDialog.h b/qtfred/src/ui/dialogs/MissionSpecDialog.h index 57c9f38ec6e..7c36fee6453 100644 --- a/qtfred/src/ui/dialogs/MissionSpecDialog.h +++ b/qtfred/src/ui/dialogs/MissionSpecDialog.h @@ -27,6 +27,7 @@ class MissionSpecDialog : public QDialog protected: void closeEvent(QCloseEvent*) override; + void rejectHandler(); private slots: void on_customWingNameButton_clicked(); diff --git a/qtfred/ui/MissionSpecDialog.ui b/qtfred/ui/MissionSpecDialog.ui index e26935a2e5b..1cd7c7554e1 100644 --- a/qtfred/ui/MissionSpecDialog.ui +++ b/qtfred/ui/MissionSpecDialog.ui @@ -1053,22 +1053,6 @@ - - dialogButtonBox - rejected() - fso::fred::dialogs::MissionSpecDialog - reject() - - - 628 - 19 - - - 357 - 297 - - - From 5892edaf5709004f67abd653c0fc233946f43c45 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:17:41 +0000 Subject: [PATCH 07/18] Update Reinforcements dialog --- .../dialogs/ReinforcementsEditorDialogModel.cpp | 7 +++++++ qtfred/src/ui/FredView.cpp | 1 + .../ui/dialogs/ReinforcementsEditorDialog.cpp | 17 ++++++++++++++--- .../src/ui/dialogs/ReinforcementsEditorDialog.h | 1 + qtfred/ui/ReinforcementsDialog.ui | 16 ---------------- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/qtfred/src/mission/dialogs/ReinforcementsEditorDialogModel.cpp b/qtfred/src/mission/dialogs/ReinforcementsEditorDialogModel.cpp index c60e2406f7d..9714c803890 100644 --- a/qtfred/src/mission/dialogs/ReinforcementsEditorDialogModel.cpp +++ b/qtfred/src/mission/dialogs/ReinforcementsEditorDialogModel.cpp @@ -147,6 +147,7 @@ void ReinforcementsDialogModel::addToReinforcements(const SCP_vector _listUpdateRequired = true; _numberLineEditUpdateRequired = true; modelChanged(); + set_modified(); } void ReinforcementsDialogModel::removeFromReinforcements(const SCP_vector& namesIn) @@ -170,6 +171,7 @@ void ReinforcementsDialogModel::removeFromReinforcements(const SCP_vector _numberLineEditUpdateRequired = true; modelChanged(); + set_modified(); } void ReinforcementsDialogModel::setUseCount(int count) @@ -257,6 +260,7 @@ void ReinforcementsDialogModel::setUseCount(int count) for (auto& reinforcement : _selectedReinforcementIndices) { std::get<1>(_reinforcementList[reinforcement]) = count; } + set_modified(); } void ReinforcementsDialogModel::setBeforeArrivalDelay(int delay) @@ -264,6 +268,7 @@ void ReinforcementsDialogModel::setBeforeArrivalDelay(int delay) for (auto& reinforcement : _selectedReinforcementIndices) { std::get<2>(_reinforcementList[reinforcement]) = delay; } + set_modified(); } void ReinforcementsDialogModel::moveReinforcementsUp() @@ -284,6 +289,7 @@ void ReinforcementsDialogModel::moveReinforcementsUp() updateSelectedIndices(); _listUpdateRequired = true; modelChanged(); + set_modified(); } } @@ -303,6 +309,7 @@ void ReinforcementsDialogModel::moveReinforcementsDown() updateSelectedIndices(); _listUpdateRequired = true; modelChanged(); + set_modified(); } } diff --git a/qtfred/src/ui/FredView.cpp b/qtfred/src/ui/FredView.cpp index 0acb6a625d7..eaef2795d55 100644 --- a/qtfred/src/ui/FredView.cpp +++ b/qtfred/src/ui/FredView.cpp @@ -755,6 +755,7 @@ void FredView::on_actionCommand_Briefing_triggered(bool) { } void FredView::on_actionReinforcements_triggered(bool) { auto editorDialog = new dialogs::ReinforcementsDialog(this, _viewport); + editorDialog->setAttribute(Qt::WA_DeleteOnClose); editorDialog->show(); } void FredView::on_actionLoadout_triggered(bool) { diff --git a/qtfred/src/ui/dialogs/ReinforcementsEditorDialog.cpp b/qtfred/src/ui/dialogs/ReinforcementsEditorDialog.cpp index a0c1bd47311..5021ae806fd 100644 --- a/qtfred/src/ui/dialogs/ReinforcementsEditorDialog.cpp +++ b/qtfred/src/ui/dialogs/ReinforcementsEditorDialog.cpp @@ -1,6 +1,6 @@ #include "ReinforcementsEditorDialog.h" #include "ui_ReinforcementsDialog.h" - +#include "mission/util.h" #include #include #include @@ -22,7 +22,9 @@ namespace dialogs { connect(_model.get(), &AbstractDialogModel::modelChanged, this, &ReinforcementsDialog::updateUI); connect(this, &QDialog::accepted, _model.get(), &ReinforcementsDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &ReinforcementsDialogModel::reject); + connect(ui->okAndCancelButtonBox, + &QDialogButtonBox::rejected, + this, &ReinforcementsDialog::rejectHandler); connect(ui->delayLineEdit, @@ -197,7 +199,16 @@ namespace dialogs { ReinforcementsDialog::~ReinforcementsDialog() {} // NOLINT - void ReinforcementsDialog::closeEvent(QCloseEvent* ){} + void ReinforcementsDialog::closeEvent(QCloseEvent* e){ + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; + } + + void ReinforcementsDialog::rejectHandler() + { + this->close(); + } } } diff --git a/qtfred/src/ui/dialogs/ReinforcementsEditorDialog.h b/qtfred/src/ui/dialogs/ReinforcementsEditorDialog.h index 8d07a6042b7..18a245d4a75 100644 --- a/qtfred/src/ui/dialogs/ReinforcementsEditorDialog.h +++ b/qtfred/src/ui/dialogs/ReinforcementsEditorDialog.h @@ -28,6 +28,7 @@ class ReinforcementsDialog : public QDialog { protected: void closeEvent(QCloseEvent*) override; + void rejectHandler(); private slots: void on_chosenShipsList_clicked(); diff --git a/qtfred/ui/ReinforcementsDialog.ui b/qtfred/ui/ReinforcementsDialog.ui index 37cce44e423..f01a24205e9 100644 --- a/qtfred/ui/ReinforcementsDialog.ui +++ b/qtfred/ui/ReinforcementsDialog.ui @@ -458,21 +458,5 @@ - - okAndCancelButtonBox - rejected() - fso::fred::dialogs::ReinforcementsDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - From d94da96ca403e61d9433851b1943049ceaf769f4 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:22:16 +0000 Subject: [PATCH 08/18] Update Shield Dialog --- .../mission/dialogs/ShieldSystemDialogModel.h | 10 ------- qtfred/src/ui/FredView.cpp | 5 ++-- qtfred/src/ui/dialogs/ShieldSystemDialog.cpp | 30 +++++++------------ qtfred/src/ui/dialogs/ShieldSystemDialog.h | 5 +++- qtfred/ui/ShieldSystemDialog.ui | 16 ---------- 5 files changed, 17 insertions(+), 49 deletions(-) diff --git a/qtfred/src/mission/dialogs/ShieldSystemDialogModel.h b/qtfred/src/mission/dialogs/ShieldSystemDialogModel.h index 94875d6d66a..8eb37b68748 100644 --- a/qtfred/src/mission/dialogs/ShieldSystemDialogModel.h +++ b/qtfred/src/mission/dialogs/ShieldSystemDialogModel.h @@ -34,8 +34,6 @@ class ShieldSystemDialogModel: public AbstractDialogModel { private: void initializeData(); - template - void modify(T &a, const T &b); std::vector _shipTypeOptions; std::vector _teamOptions; @@ -45,14 +43,6 @@ class ShieldSystemDialogModel: public AbstractDialogModel { int _currType; }; -template -inline void ShieldSystemDialogModel::modify(T &a, const T &b) { - if (a != b) { - a = b; - modelChanged(); - } -} - } } } diff --git a/qtfred/src/ui/FredView.cpp b/qtfred/src/ui/FredView.cpp index eaef2795d55..e9d1d054bcb 100644 --- a/qtfred/src/ui/FredView.cpp +++ b/qtfred/src/ui/FredView.cpp @@ -1133,8 +1133,9 @@ void FredView::on_actionBackground_triggered(bool) { } void FredView::on_actionShield_System_triggered(bool) { - dialogs::ShieldSystemDialog dialog(this, _viewport); - dialog.exec(); + auto dialog = new dialogs::ShieldSystemDialog(this, _viewport); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void FredView::on_actionVoice_Acting_Manager_triggered(bool) { diff --git a/qtfred/src/ui/dialogs/ShieldSystemDialog.cpp b/qtfred/src/ui/dialogs/ShieldSystemDialog.cpp index 6fc2863781b..160f704380a 100644 --- a/qtfred/src/ui/dialogs/ShieldSystemDialog.cpp +++ b/qtfred/src/ui/dialogs/ShieldSystemDialog.cpp @@ -3,7 +3,7 @@ #include "ShieldSystemDialog.h" #include "ui/util/SignalBlockers.h" #include "ui_ShieldSystemDialog.h" - +#include "mission/util.h" namespace fso { namespace fred { @@ -17,7 +17,7 @@ ShieldSystemDialog::ShieldSystemDialog(FredView* parent, EditorViewport* viewpor ui->setupUi(this); connect(this, &QDialog::accepted, _model.get(), &ShieldSystemDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &ShieldSystemDialogModel::reject); + connect(ui->dialogButtonBox, &QDialogButtonBox::rejected, this, &ShieldSystemDialog::rejectHandler); connect(_model.get(), &AbstractDialogModel::modelChanged, this, &ShieldSystemDialog::updateUI); @@ -113,25 +113,15 @@ void ShieldSystemDialog::keyPressEvent(QKeyEvent* event) { QDialog::keyPressEvent(event); } -void ShieldSystemDialog::closeEvent(QCloseEvent* event) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, "Changes detected", "Do you want to keep your changes?", - { DialogButton::Yes, DialogButton::No, DialogButton::Cancel }); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - } - - QDialog::closeEvent(event); +void ShieldSystemDialog::closeEvent(QCloseEvent* e) { + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; +} +void ShieldSystemDialog::rejectHandler() +{ + this->close(); } - } } } diff --git a/qtfred/src/ui/dialogs/ShieldSystemDialog.h b/qtfred/src/ui/dialogs/ShieldSystemDialog.h index c0c870ec31d..dc7298cc4f5 100644 --- a/qtfred/src/ui/dialogs/ShieldSystemDialog.h +++ b/qtfred/src/ui/dialogs/ShieldSystemDialog.h @@ -24,7 +24,10 @@ class ShieldSystemDialog : public QDialog protected: void keyPressEvent(QKeyEvent* event) override; void closeEvent(QCloseEvent*) override; -private: + + void rejectHandler(); + + private: void updateUI(); void updateTeam(); void updateType(); diff --git a/qtfred/ui/ShieldSystemDialog.ui b/qtfred/ui/ShieldSystemDialog.ui index 11137c17e66..fc66fc7fe6d 100644 --- a/qtfred/ui/ShieldSystemDialog.ui +++ b/qtfred/ui/ShieldSystemDialog.ui @@ -130,22 +130,6 @@ - - dialogButtonBox - rejected() - fso::fred::dialogs::ShieldSystemDialog - reject() - - - 195 - 132 - - - 154 - 80 - - - From 2b1bf2c1bb62d42ef30587001361c8e8f75dbc19 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:23:35 +0000 Subject: [PATCH 09/18] Update Mission Goals dialog --- qtfred/src/ui/FredView.cpp | 5 +-- qtfred/src/ui/dialogs/MissionGoalsDialog.cpp | 34 ++++++-------------- qtfred/src/ui/dialogs/MissionGoalsDialog.h | 1 + qtfred/ui/MissionGoalsDialog.ui | 16 --------- 4 files changed, 14 insertions(+), 42 deletions(-) diff --git a/qtfred/src/ui/FredView.cpp b/qtfred/src/ui/FredView.cpp index e9d1d054bcb..689c7d8b54f 100644 --- a/qtfred/src/ui/FredView.cpp +++ b/qtfred/src/ui/FredView.cpp @@ -1143,8 +1143,9 @@ void FredView::on_actionVoice_Acting_Manager_triggered(bool) { dialog.exec(); } void FredView::on_actionMission_Objectives_triggered(bool) { - dialogs::MissionGoalsDialog dialog(this, _viewport); - dialog.exec(); + auto dialog = new dialogs::MissionGoalsDialog(this, _viewport); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void FredView::on_actionFiction_Viewer_triggered(bool) { diff --git a/qtfred/src/ui/dialogs/MissionGoalsDialog.cpp b/qtfred/src/ui/dialogs/MissionGoalsDialog.cpp index a641153d558..022e2519570 100644 --- a/qtfred/src/ui/dialogs/MissionGoalsDialog.cpp +++ b/qtfred/src/ui/dialogs/MissionGoalsDialog.cpp @@ -2,7 +2,7 @@ #include "MissionGoalsDialog.h" #include "ui/util/SignalBlockers.h" - +#include "mission/util.h" #include "ui_MissionGoalsDialog.h" namespace fso { @@ -26,7 +26,7 @@ MissionGoalsDialog::MissionGoalsDialog(QWidget* parent, EditorViewport* viewport ui->helpTextBox->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); connect(this, &QDialog::accepted, _model.get(), &MissionGoalsDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &MissionGoalsDialogModel::reject); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &MissionGoalsDialog::rejectHandler); connect(_model.get(), &MissionGoalsDialogModel::modelChanged, this, &MissionGoalsDialog::updateUI); @@ -198,29 +198,15 @@ void MissionGoalsDialog::changeGoalCategory(int type) { recreate_tree(); } } -void MissionGoalsDialog::closeEvent(QCloseEvent* event) { - if (_model->query_modified()) { - auto result = QMessageBox::question(this, - "Close", - "Do you want to keep your changes?", - QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, - QMessageBox::Cancel); - - if (result == QMessageBox::Cancel) { - event->ignore(); - return; - } - - if (result == QMessageBox::Yes) { - accept(); - event->accept(); - return; - } - } - - QDialog::closeEvent(event); +void MissionGoalsDialog::closeEvent(QCloseEvent* e) { + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; +} +void MissionGoalsDialog::rejectHandler() +{ + this->close(); } - } } } diff --git a/qtfred/src/ui/dialogs/MissionGoalsDialog.h b/qtfred/src/ui/dialogs/MissionGoalsDialog.h index 7f633033154..8cbe7a3d150 100644 --- a/qtfred/src/ui/dialogs/MissionGoalsDialog.h +++ b/qtfred/src/ui/dialogs/MissionGoalsDialog.h @@ -28,6 +28,7 @@ class MissionGoalsDialog : public QDialog, public SexpTreeEditorInterface protected: void closeEvent(QCloseEvent* event) override; + void rejectHandler(); private: void updateUI(); diff --git a/qtfred/ui/MissionGoalsDialog.ui b/qtfred/ui/MissionGoalsDialog.ui index 07dc8176d3f..3d41d59779e 100644 --- a/qtfred/ui/MissionGoalsDialog.ui +++ b/qtfred/ui/MissionGoalsDialog.ui @@ -255,22 +255,6 @@ - - buttonBox - rejected() - fso::fred::dialogs::MissionGoalsDialog - reject() - - - 506 - 119 - - - 286 - 274 - - - buttonBox accepted() From abdef2ca07ec93f2521217beebca7089601626e9 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:26:45 +0000 Subject: [PATCH 10/18] Update Object Orientation dialog --- qtfred/src/ui/FredView.cpp | 3 +- .../ui/dialogs/ObjectOrientEditorDialog.cpp | 28 +++++++------------ .../src/ui/dialogs/ObjectOrientEditorDialog.h | 1 + qtfred/ui/ObjectOrientationDialog.ui | 16 ----------- 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/qtfred/src/ui/FredView.cpp b/qtfred/src/ui/FredView.cpp index 689c7d8b54f..3dafe37db9b 100644 --- a/qtfred/src/ui/FredView.cpp +++ b/qtfred/src/ui/FredView.cpp @@ -863,8 +863,9 @@ void FredView::mouseDoubleClickEvent(QMouseEvent* event) { } void FredView::orientEditorTriggered() { auto dialog = new dialogs::ObjectOrientEditorDialog(this, _viewport); + dialog->setAttribute(Qt::WA_DeleteOnClose); // This is a modal dialog - dialog->exec(); + dialog->show(); } void FredView::onUpdateEditorActions() { ui->actionObjects->setEnabled(query_valid_object(fred->currentObject)); diff --git a/qtfred/src/ui/dialogs/ObjectOrientEditorDialog.cpp b/qtfred/src/ui/dialogs/ObjectOrientEditorDialog.cpp index 4b5195e50f1..9e8c0e2b56b 100644 --- a/qtfred/src/ui/dialogs/ObjectOrientEditorDialog.cpp +++ b/qtfred/src/ui/dialogs/ObjectOrientEditorDialog.cpp @@ -6,7 +6,7 @@ #include "ui_ObjectOrientationDialog.h" #include - +#include "mission/util.h" #include namespace fso { @@ -19,7 +19,7 @@ ObjectOrientEditorDialog::ObjectOrientEditorDialog(FredView* parent, EditorViewp ui->setupUi(this); connect(this, &QDialog::accepted, _model.get(), &ObjectOrientEditorDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &ObjectOrientEditorDialogModel::reject); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ObjectOrientEditorDialog::rejectHandler); connect(_model.get(), &AbstractDialogModel::modelChanged, this, &ObjectOrientEditorDialog::updateUI); @@ -67,23 +67,15 @@ ObjectOrientEditorDialog::ObjectOrientEditorDialog(FredView* parent, EditorViewp ObjectOrientEditorDialog::~ObjectOrientEditorDialog() { } -void ObjectOrientEditorDialog::closeEvent(QCloseEvent* event) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, "Changes detected", "Do you want to keep your changes?", - { DialogButton::Yes, DialogButton::No, DialogButton::Cancel }); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - } +void ObjectOrientEditorDialog::closeEvent(QCloseEvent* e) { + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; +} - QDialog::closeEvent(event); +void ObjectOrientEditorDialog::rejectHandler() +{ + this->close(); } void ObjectOrientEditorDialog::updateUI() { diff --git a/qtfred/src/ui/dialogs/ObjectOrientEditorDialog.h b/qtfred/src/ui/dialogs/ObjectOrientEditorDialog.h index 7bac4890026..b50a10057f8 100644 --- a/qtfred/src/ui/dialogs/ObjectOrientEditorDialog.h +++ b/qtfred/src/ui/dialogs/ObjectOrientEditorDialog.h @@ -22,6 +22,7 @@ class ObjectOrientEditorDialog : public QDialog { protected: void closeEvent(QCloseEvent*) override; + void rejectHandler(); private: std::unique_ptr ui; diff --git a/qtfred/ui/ObjectOrientationDialog.ui b/qtfred/ui/ObjectOrientationDialog.ui index 1a599168802..5b3bd355d34 100644 --- a/qtfred/ui/ObjectOrientationDialog.ui +++ b/qtfred/ui/ObjectOrientationDialog.ui @@ -292,21 +292,5 @@ - - buttonBox - rejected() - fso::fred::dialogs::ObjectOrientEditorDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - From 68c2fcc31c160e528128c7cdc8357b9c06a769a9 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:28:32 +0000 Subject: [PATCH 11/18] Update Ship editor dialog --- .../dialogs/ShipEditor/ShipEditorDialogModel.h | 15 --------------- .../ui/dialogs/ShipEditor/ShipEditorDialog.cpp | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/qtfred/src/mission/dialogs/ShipEditor/ShipEditorDialogModel.h b/qtfred/src/mission/dialogs/ShipEditor/ShipEditorDialogModel.h index d864efcecce..5a2ac86f0a9 100644 --- a/qtfred/src/mission/dialogs/ShipEditor/ShipEditorDialogModel.h +++ b/qtfred/src/mission/dialogs/ShipEditor/ShipEditorDialogModel.h @@ -15,9 +15,6 @@ namespace dialogs { class ShipEditorDialogModel : public AbstractDialogModel { private: - template - void modify(T& a, const T& b); - int _m_no_departure_warp; int _m_no_arrival_warp; bool _m_player_ship; @@ -76,7 +73,6 @@ class ShipEditorDialogModel : public AbstractDialogModel { public: ShipEditorDialogModel(QObject* parent, EditorViewport* viewport); void initializeData(); - bool _modified = false; bool apply() override; void reject() override; @@ -232,17 +228,6 @@ class ShipEditorDialogModel : public AbstractDialogModel { */ int getIfPlayerShip() const; }; - -template -inline void ShipEditorDialogModel::modify(T& a, const T& b) -{ - if (a != b) { - a = b; - set_modified(); - update_data(); - modelChanged(); - } -} } // namespace dialogs } // namespace fred } // namespace fso \ No newline at end of file diff --git a/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.cpp b/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.cpp index 15fff8905f8..d69dc3a7b5d 100644 --- a/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.cpp +++ b/qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.cpp @@ -203,7 +203,7 @@ void ShipEditorDialog::on_tblInfoButton_clicked() void ShipEditorDialog::update() { if (this->isVisible()) { - if (_model->getNumSelectedObjects() && _model->_modified) { + if (_model->getNumSelectedObjects() && _model->query_modified()) { _model->apply(); } _model->initializeData(); From 30bc3c78acf7cf195a22963562dad90efd8705f8 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:29:11 +0000 Subject: [PATCH 12/18] Add delete on close to dialogs that don't need other changes --- qtfred/src/ui/FredView.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qtfred/src/ui/FredView.cpp b/qtfred/src/ui/FredView.cpp index 3dafe37db9b..1c7bac04cd9 100644 --- a/qtfred/src/ui/FredView.cpp +++ b/qtfred/src/ui/FredView.cpp @@ -704,6 +704,7 @@ void FredView::keyReleaseEvent(QKeyEvent* event) { } void FredView::on_actionEvents_triggered(bool) { auto eventEditor = new dialogs::EventEditorDialog(this, _viewport); + eventEditor->setAttribute(Qt::WA_DeleteOnClose); eventEditor->show(); } void FredView::on_actionSelectionLock_triggered(bool enabled) { @@ -733,6 +734,7 @@ void FredView::on_actionMission_Specs_triggered(bool) { } void FredView::on_actionWaypoint_Paths_triggered(bool) { auto editorDialog = new dialogs::WaypointEditorDialog(this, _viewport); + editorDialog->setAttribute(Qt::WA_DeleteOnClose); editorDialog->show(); } void FredView::on_actionShips_triggered(bool) @@ -981,7 +983,8 @@ bool FredView::showModalDialog(IBaseDialog* dlg) { void FredView::on_actionSelectionList_triggered(bool) { auto dialog = new dialogs::SelectionDialog(this, _viewport); // This is a modal dialog - dialog->exec(); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void FredView::on_actionOrbitSelected_triggered(bool enabled) { _viewport->Lookat_mode = enabled; From bb589059c55864b83faed03ec029e457327328e8 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:37:22 +0000 Subject: [PATCH 13/18] Update Wing names dialog --- .../dialogs/CustomWingNamesDialogModel.h | 10 ------- .../src/ui/dialogs/CustomWingNamesDialog.cpp | 29 +++++++------------ qtfred/src/ui/dialogs/CustomWingNamesDialog.h | 2 ++ qtfred/src/ui/dialogs/MissionSpecDialog.cpp | 3 +- qtfred/ui/CustomWingNamesDialog.ui | 16 ---------- 5 files changed, 14 insertions(+), 46 deletions(-) diff --git a/qtfred/src/mission/dialogs/CustomWingNamesDialogModel.h b/qtfred/src/mission/dialogs/CustomWingNamesDialogModel.h index e9ba5f3c933..87b7d6340b8 100644 --- a/qtfred/src/mission/dialogs/CustomWingNamesDialogModel.h +++ b/qtfred/src/mission/dialogs/CustomWingNamesDialogModel.h @@ -24,22 +24,12 @@ class CustomWingNamesDialogModel : public AbstractDialogModel { private: void initializeData(); - template - void modify(T &a, T &b); SCP_string _m_starting[3]; SCP_string _m_squadron[5]; SCP_string _m_tvt[2]; }; -template -inline void CustomWingNamesDialogModel::modify(T & a, T & b) { - if (a != b) { - a = b; - modelChanged(); - } -} - } } } diff --git a/qtfred/src/ui/dialogs/CustomWingNamesDialog.cpp b/qtfred/src/ui/dialogs/CustomWingNamesDialog.cpp index bb69959db07..56deb21eb95 100644 --- a/qtfred/src/ui/dialogs/CustomWingNamesDialog.cpp +++ b/qtfred/src/ui/dialogs/CustomWingNamesDialog.cpp @@ -1,6 +1,7 @@ #include "CustomWingNamesDialog.h" #include "ui_CustomWingNamesDialog.h" +#include namespace fso { namespace fred { @@ -12,7 +13,7 @@ CustomWingNamesDialog::CustomWingNamesDialog(QWidget* parent, EditorViewport* vi ui->setupUi(this); connect(this, &QDialog::accepted, _model.get(), &CustomWingNamesDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &CustomWingNamesDialogModel::reject); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &CustomWingNamesDialog::rejectHandler); connect(_model.get(), &AbstractDialogModel::modelChanged, this, &CustomWingNamesDialog::updateUI); @@ -41,25 +42,15 @@ CustomWingNamesDialog::CustomWingNamesDialog(QWidget* parent, EditorViewport* vi CustomWingNamesDialog::~CustomWingNamesDialog() { } -void CustomWingNamesDialog::closeEvent(QCloseEvent * event) { - if (_model->query_modified()) { - auto button = _viewport->dialogProvider->showButtonDialog(DialogType::Question, "Changes detected", "Do you want to keep your changes?", - { DialogButton::Yes, DialogButton::No, DialogButton::Cancel }); - - if (button == DialogButton::Cancel) { - event->ignore(); - return; - } - - if (button == DialogButton::Yes) { - accept(); - return; - } - } - - QDialog::closeEvent(event); +void CustomWingNamesDialog::closeEvent(QCloseEvent * e) { + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; +} +void CustomWingNamesDialog::rejectHandler() +{ + this->close(); } - void CustomWingNamesDialog::updateUI() { // Update starting wings ui->startingWing_1->setText(_model->getStartingWing(0).c_str()); diff --git a/qtfred/src/ui/dialogs/CustomWingNamesDialog.h b/qtfred/src/ui/dialogs/CustomWingNamesDialog.h index f50f209aae2..338f9b76cb1 100644 --- a/qtfred/src/ui/dialogs/CustomWingNamesDialog.h +++ b/qtfred/src/ui/dialogs/CustomWingNamesDialog.h @@ -27,6 +27,8 @@ class CustomWingNamesDialog : public QDialog protected: void closeEvent(QCloseEvent*) override; + void rejectHandler(); + private: std::unique_ptr ui; std::unique_ptr _model; diff --git a/qtfred/src/ui/dialogs/MissionSpecDialog.cpp b/qtfred/src/ui/dialogs/MissionSpecDialog.cpp index 8679c03c6c1..30b68f25370 100644 --- a/qtfred/src/ui/dialogs/MissionSpecDialog.cpp +++ b/qtfred/src/ui/dialogs/MissionSpecDialog.cpp @@ -299,7 +299,8 @@ void MissionSpecDialog::squadronNameChanged(const QString & string) { void MissionSpecDialog::on_customWingNameButton_clicked() { CustomWingNamesDialog* dialog = new CustomWingNamesDialog(this, _viewport); - dialog->exec(); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void MissionSpecDialog::on_squadronLogoButton_clicked() { diff --git a/qtfred/ui/CustomWingNamesDialog.ui b/qtfred/ui/CustomWingNamesDialog.ui index 228b47be1d7..51f16a5f6ec 100644 --- a/qtfred/ui/CustomWingNamesDialog.ui +++ b/qtfred/ui/CustomWingNamesDialog.ui @@ -138,21 +138,5 @@ - - buttonBox - rejected() - fso::fred::dialogs::CustomWingNamesDialog - reject() - - - 603 - 50 - - - 324 - 50 - - -
From 76abb2819dd80e294d142b37508ae3996559960f Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:52:53 +0000 Subject: [PATCH 14/18] Update Command Briefing Dialog --- .../dialogs/CommandBriefingDialogModel.cpp | 17 +++++++++++++---- qtfred/src/ui/FredView.cpp | 1 + .../src/ui/dialogs/CommandBriefingDialog.cpp | 18 +++++++++++++----- qtfred/src/ui/dialogs/CommandBriefingDialog.h | 2 ++ qtfred/ui/CommandBriefingDialog.ui | 16 ---------------- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/qtfred/src/mission/dialogs/CommandBriefingDialogModel.cpp b/qtfred/src/mission/dialogs/CommandBriefingDialogModel.cpp index 4c41327023a..14d2502bcbb 100644 --- a/qtfred/src/mission/dialogs/CommandBriefingDialogModel.cpp +++ b/qtfred/src/mission/dialogs/CommandBriefingDialogModel.cpp @@ -144,7 +144,7 @@ void CommandBriefingDialogModel::addStage() _wipCommandBrief.num_stages++; _currentStage = _wipCommandBrief.num_stages - 1; - + set_modified(); modelChanged(); } @@ -155,6 +155,7 @@ void CommandBriefingDialogModel::insertStage() if (_wipCommandBrief.num_stages >= CMD_BRIEF_STAGES_MAX) { _wipCommandBrief.num_stages = CMD_BRIEF_STAGES_MAX; + set_modified(); modelChanged(); // signal that the model has changed, in case of inexplicable invalid index. return; } @@ -164,6 +165,7 @@ void CommandBriefingDialogModel::insertStage() for (int i = _wipCommandBrief.num_stages - 1; i > _currentStage; i--) { _wipCommandBrief.stage[i] = _wipCommandBrief.stage[i - 1]; } + set_modified(); modelChanged(); } @@ -181,6 +183,7 @@ void CommandBriefingDialogModel::deleteStage() _wipCommandBrief.stage[0].wave = -1; memset(_wipCommandBrief.stage[0].wave_filename, 0, CF_MAX_FILENAME_LENGTH); memset(_wipCommandBrief.stage[0].ani_filename, 0, CF_MAX_FILENAME_LENGTH); + set_modified(); modelChanged(); return; } @@ -293,13 +296,15 @@ int CommandBriefingDialogModel::getSpeechInstanceNumber() void CommandBriefingDialogModel::setBriefingText(const SCP_string& briefingText) { - _wipCommandBrief.stage[_currentStage].text = briefingText; + _wipCommandBrief.stage[_currentStage].text = briefingText; + set_modified(); modelChanged(); } void CommandBriefingDialogModel::setAnimationFilename(const SCP_string& animationFilename) { - strcpy_s(_wipCommandBrief.stage[_currentStage].ani_filename, animationFilename.c_str()); + strcpy_s(_wipCommandBrief.stage[_currentStage].ani_filename, animationFilename.c_str()); + set_modified(); modelChanged(); } @@ -307,24 +312,28 @@ void CommandBriefingDialogModel::setSpeechFilename(const SCP_string& speechFilen { _soundTestUpdateRequired = true; strcpy_s(_wipCommandBrief.stage[_currentStage].wave_filename, speechFilename.c_str()); - setWaveID(); + setWaveID(); + set_modified(); modelChanged(); } void CommandBriefingDialogModel::setCurrentTeam(const ubyte& teamIn) { _currentTeam = teamIn; + set_modified(); }; // not yet fully supported void CommandBriefingDialogModel::setLowResolutionFilename(const SCP_string& lowResolutionFilename) { strcpy_s(_wipCommandBrief.background[0], lowResolutionFilename.c_str()); + set_modified(); modelChanged(); } void CommandBriefingDialogModel::setHighResolutionFilename(const SCP_string& highResolutionFilename) { strcpy_s(_wipCommandBrief.background[1], highResolutionFilename.c_str()); + set_modified(); modelChanged(); } diff --git a/qtfred/src/ui/FredView.cpp b/qtfred/src/ui/FredView.cpp index 1c7bac04cd9..67e722207ce 100644 --- a/qtfred/src/ui/FredView.cpp +++ b/qtfred/src/ui/FredView.cpp @@ -753,6 +753,7 @@ void FredView::on_actionObjects_triggered(bool) { } void FredView::on_actionCommand_Briefing_triggered(bool) { auto editorDialog = new dialogs::CommandBriefingDialog(this, _viewport); + editorDialog->setAttribute(Qt::WA_DeleteOnClose); editorDialog->show(); } void FredView::on_actionReinforcements_triggered(bool) { diff --git a/qtfred/src/ui/dialogs/CommandBriefingDialog.cpp b/qtfred/src/ui/dialogs/CommandBriefingDialog.cpp index 83ab998b6a9..ad7c46358d4 100644 --- a/qtfred/src/ui/dialogs/CommandBriefingDialog.cpp +++ b/qtfred/src/ui/dialogs/CommandBriefingDialog.cpp @@ -1,6 +1,6 @@ #include "CommandBriefingDialog.h" #include "ui_CommandBriefingDialog.h" - +#include "mission/util.h" #include #include #include @@ -22,7 +22,7 @@ namespace dialogs { connect(this, &QDialog::accepted, _model.get(), &CommandBriefingDialogModel::apply); connect(viewport->editor, &Editor::currentObjectChanged, _model.get(), &CommandBriefingDialogModel::apply); connect(viewport->editor, &Editor::objectMarkingChanged, _model.get(), &CommandBriefingDialogModel::apply); - connect(this, &QDialog::rejected, _model.get(), &CommandBriefingDialogModel::reject); + connect(ui->okAndCancelButtons, &QDialogButtonBox::rejected, this, &CommandBriefingDialog::rejectHandler); connect(ui->actionChangeTeams, static_cast(&QSpinBox::valueChanged), @@ -283,8 +283,16 @@ namespace dialogs { CommandBriefingDialog::~CommandBriefingDialog() {}; //NOLINT - void CommandBriefingDialog::closeEvent(QCloseEvent*){} - -} // dialogs + void CommandBriefingDialog::closeEvent(QCloseEvent* e) + { + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; + } + void CommandBriefingDialog::rejectHandler() + { + this->close(); + } + } // dialogs } // fred } // fso \ No newline at end of file diff --git a/qtfred/src/ui/dialogs/CommandBriefingDialog.h b/qtfred/src/ui/dialogs/CommandBriefingDialog.h index 005aecb06f4..4b1c27ba01c 100644 --- a/qtfred/src/ui/dialogs/CommandBriefingDialog.h +++ b/qtfred/src/ui/dialogs/CommandBriefingDialog.h @@ -29,6 +29,8 @@ class CommandBriefingDialog : public QDialog { protected: void closeEvent(QCloseEvent*) override; + void rejectHandler(); + private slots: // where the buttons go void on_actionPrevStage_clicked(); void on_actionNextStage_clicked(); diff --git a/qtfred/ui/CommandBriefingDialog.ui b/qtfred/ui/CommandBriefingDialog.ui index d1a67643de2..a3d2171d896 100644 --- a/qtfred/ui/CommandBriefingDialog.ui +++ b/qtfred/ui/CommandBriefingDialog.ui @@ -352,21 +352,5 @@ - - okAndCancelButtons - rejected() - fso::fred::dialogs::CommandBriefingDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - From d6c9ff43d72cbe7ad443ad4748d471cde2cccf45 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 15:07:29 +0000 Subject: [PATCH 15/18] Asteroid editor and add delete on close to a few more unchanged dialogs --- .../dialogs/AsteroidEditorDialogModel.cpp | 16 ------ .../dialogs/AsteroidEditorDialogModel.h | 16 ------ qtfred/src/ui/FredView.cpp | 19 +++++-- .../src/ui/dialogs/AsteroidEditorDialog.cpp | 57 +++++-------------- qtfred/src/ui/dialogs/AsteroidEditorDialog.h | 7 ++- qtfred/ui/AsteroidEditorDialog.ui | 16 ------ 6 files changed, 33 insertions(+), 98 deletions(-) diff --git a/qtfred/src/mission/dialogs/AsteroidEditorDialogModel.cpp b/qtfred/src/mission/dialogs/AsteroidEditorDialogModel.cpp index 74a86c03521..ca2ff87720a 100644 --- a/qtfred/src/mission/dialogs/AsteroidEditorDialogModel.cpp +++ b/qtfred/src/mission/dialogs/AsteroidEditorDialogModel.cpp @@ -26,7 +26,6 @@ AsteroidEditorDialogModel::AsteroidEditorDialogModel(QObject* parent, EditorView _field_type(FT_ACTIVE), _debris_genre(DG_ASTEROID), _bypass_errors(false), - _modified(false), _cur_field(0), _last_field(-1) { @@ -494,21 +493,6 @@ void AsteroidEditorDialogModel::update_init() _last_field = _cur_field; } -void AsteroidEditorDialogModel::set_modified() -{ - _modified = true; -} - -void AsteroidEditorDialogModel::unset_modified() -{ - _modified = false; -} - -bool AsteroidEditorDialogModel::get_modified() -{ - return _modified; -} - void AsteroidEditorDialogModel::showErrorDialogNoCancel(const SCP_string& message) { if (_bypass_errors) { diff --git a/qtfred/src/mission/dialogs/AsteroidEditorDialogModel.h b/qtfred/src/mission/dialogs/AsteroidEditorDialogModel.h index 0d65b6abd2b..ffe409d2521 100644 --- a/qtfred/src/mission/dialogs/AsteroidEditorDialogModel.h +++ b/qtfred/src/mission/dialogs/AsteroidEditorDialogModel.h @@ -61,13 +61,7 @@ Q_OBJECT void update_init(); bool validate_data(); - void set_modified(); - void unset_modified(); - bool get_modified(); - private: - template - void modify(T &a, const T &b); void showErrorDialogNoCancel(const SCP_string& message); void initializeData(); @@ -98,7 +92,6 @@ Q_OBJECT asteroid_field _a_field; // :v: had unfinished plans for multiple fields? bool _bypass_errors; - bool _modified; int _cur_field; int _last_field; @@ -110,15 +103,6 @@ Q_OBJECT std::unordered_map debris_inverse_idx_lookup; }; -template -inline void AsteroidEditorDialogModel::modify(T &a, const T &b) { - if (a != b) { - a = b; - set_modified(); - modelChanged(); - } -} - } // namespace dialogs } // namespace fred } // namespace fso diff --git a/qtfred/src/ui/FredView.cpp b/qtfred/src/ui/FredView.cpp index 67e722207ce..eb8d2893faa 100644 --- a/qtfred/src/ui/FredView.cpp +++ b/qtfred/src/ui/FredView.cpp @@ -721,10 +721,12 @@ void FredView::onShipClassSelected(int ship_class) { } void FredView::on_actionAsteroid_Field_triggered(bool) { auto asteroidFieldEditor = new dialogs::AsteroidEditorDialog(this, _viewport); + asteroidFieldEditor->setAttribute(Qt::WA_DeleteOnClose); asteroidFieldEditor->show(); } void FredView::on_actionBriefing_triggered(bool) { auto eventEditor = new dialogs::BriefingEditorDialog(this); + eventEditor->setAttribute(Qt::WA_DeleteOnClose); eventEditor->show(); } void FredView::on_actionMission_Specs_triggered(bool) { @@ -740,12 +742,14 @@ void FredView::on_actionWaypoint_Paths_triggered(bool) { void FredView::on_actionShips_triggered(bool) { auto editorDialog = new dialogs::ShipEditorDialog(this, _viewport); + editorDialog->setAttribute(Qt::WA_DeleteOnClose); editorDialog->show(); } void FredView::on_actionCampaign_triggered(bool) { //TODO: Save if Changes auto editorCampaign = new dialogs::CampaignEditorDialog(this, _viewport); + editorCampaign->setAttribute(Qt::WA_DeleteOnClose); editorCampaign->show(); } void FredView::on_actionObjects_triggered(bool) { @@ -1128,13 +1132,15 @@ void FredView::on_actionError_Checker_triggered(bool) { fred->global_error_check(); } void FredView::on_actionAbout_triggered(bool) { - dialogs::AboutDialog dialog(this); - dialog.exec(); + auto dialog = new dialogs::AboutDialog(this); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void FredView::on_actionBackground_triggered(bool) { - dialogs::BackgroundEditorDialog dialog(this, _viewport); - dialog.exec(); + auto dialog = new dialogs::BackgroundEditorDialog(this, _viewport); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void FredView::on_actionShield_System_triggered(bool) { @@ -1144,8 +1150,9 @@ void FredView::on_actionShield_System_triggered(bool) { } void FredView::on_actionVoice_Acting_Manager_triggered(bool) { - dialogs::VoiceActingManager dialog(this, _viewport); - dialog.exec(); + auto dialog = new dialogs::VoiceActingManager(this, _viewport); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } void FredView::on_actionMission_Objectives_triggered(bool) { auto dialog = new dialogs::MissionGoalsDialog(this, _viewport); diff --git a/qtfred/src/ui/dialogs/AsteroidEditorDialog.cpp b/qtfred/src/ui/dialogs/AsteroidEditorDialog.cpp index 39760412e82..a49ec326639 100644 --- a/qtfred/src/ui/dialogs/AsteroidEditorDialog.cpp +++ b/qtfred/src/ui/dialogs/AsteroidEditorDialog.cpp @@ -4,6 +4,7 @@ #include #include "ui_AsteroidEditorDialog.h" +#include namespace fso { namespace fred { @@ -22,6 +23,8 @@ AsteroidEditorDialog::AsteroidEditorDialog(FredView *parent, EditorViewport* vie ui(new Ui::AsteroidEditorDialog()), _model(new AsteroidEditorDialogModel(this, viewport)) { + connect(this, &QDialog::accepted, _model.get(), &AsteroidEditorDialogModel::apply); + connect(ui->dialogButtonBox, &QDialogButtonBox::rejected, this, &AsteroidEditorDialog::rejectHandler); ui->setupUi(this); _model->update_init(); @@ -127,6 +130,18 @@ AsteroidEditorDialog::AsteroidEditorDialog(FredView *parent, EditorViewport* vie AsteroidEditorDialog::~AsteroidEditorDialog() = default; +void AsteroidEditorDialog::closeEvent(QCloseEvent* e) +{ + if (!rejectOrCloseHandler(this, _model.get(), _viewport)) { + e->ignore(); + }; +} + +void AsteroidEditorDialog::rejectHandler() +{ + this->close(); +} + QString & AsteroidEditorDialog::getBoxText(AsteroidEditorDialogModel::_box_line_edits type) { return _model->getBoxText(type); @@ -331,48 +346,6 @@ void AsteroidEditorDialog::updateUI() ui->lineEdit_ibox_maxZ->setText(_model->AsteroidEditorDialogModel::getBoxText(AsteroidEditorDialogModel::_I_MAX_Z)); } - - -void AsteroidEditorDialog::done(int r) -{ - if(QDialog::Accepted == r) // ok was pressed - { - // TODO consider moving the validation to when values are entered - // but just visually indicate that there's a problem at that time - // hard fail (by checking status boolean?) here instead - // i.e. let FREDers have temp bad values when they're changing stuff - // if they know what they're doing - if (_model->apply()) { - // all ok - QDialog::done(r); - _model->unset_modified(); - return; - } - else { - // leave dialog open - return; - } - } - else // cancel, close or exc was pressed - { - if (_model->get_modified()) { - // give FREDer a chance in case they cancelled by mistake - // although I wonder if we're better off with always saving & don't prompt - // ~philisophical~ - auto z = _viewport->dialogProvider->showButtonDialog(DialogType::Question, - "Question", - "You have unsaved changes, do you wish to discard them?", - { DialogButton::Ok, DialogButton::Cancel }); - if (z == DialogButton::Cancel) { - return; - } - } - QDialog::done(r); - _model->unset_modified(); - return; - } -} - } // namespace dialogs } // namespace fred } // namespace fso diff --git a/qtfred/src/ui/dialogs/AsteroidEditorDialog.h b/qtfred/src/ui/dialogs/AsteroidEditorDialog.h index a64a66f47fc..b8ace401067 100644 --- a/qtfred/src/ui/dialogs/AsteroidEditorDialog.h +++ b/qtfred/src/ui/dialogs/AsteroidEditorDialog.h @@ -18,10 +18,13 @@ class AsteroidEditorDialog : public QDialog Q_OBJECT public: AsteroidEditorDialog(FredView* parent, EditorViewport* viewport); - ~AsteroidEditorDialog() override; + ~AsteroidEditorDialog() override; + + protected: + void closeEvent(QCloseEvent* e); + void rejectHandler(); private: - void done(int r) override; void toggleEnabled(bool enabled); void toggleInnerBoxEnabled(bool enabled); diff --git a/qtfred/ui/AsteroidEditorDialog.ui b/qtfred/ui/AsteroidEditorDialog.ui index 1889c2672cb..25d11b03b28 100644 --- a/qtfred/ui/AsteroidEditorDialog.ui +++ b/qtfred/ui/AsteroidEditorDialog.ui @@ -378,22 +378,6 @@ - - dialogButtonBox - rejected() - fso::fred::dialogs::AsteroidEditorDialog - reject() - - - 337 - 317 - - - 337 - 169 - - - From 5b3df074730395a44aee9f887232cd8a7e680852 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 15:39:05 +0000 Subject: [PATCH 16/18] And unused --- qtfred/src/mission/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtfred/src/mission/util.cpp b/qtfred/src/mission/util.cpp index 87ef8542904..2604e9c991e 100644 --- a/qtfred/src/mission/util.cpp +++ b/qtfred/src/mission/util.cpp @@ -93,7 +93,7 @@ void time_to_mission_info_string(const std::tm* src, char* dest, size_t dest_max std::strftime(dest, dest_max_len, "%x at %X", src); } -bool rejectOrCloseHandler(QDialog* dialog, +bool rejectOrCloseHandler(__UNUSED QDialog* dialog, fso::fred::dialogs::AbstractDialogModel* model, fso::fred::EditorViewport* viewport) { From 22ec235c225c9a9ada0a7d42f08be529bb605725 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Sat, 28 Dec 2024 15:53:36 +0000 Subject: [PATCH 17/18] Add missing override --- qtfred/src/ui/dialogs/AsteroidEditorDialog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtfred/src/ui/dialogs/AsteroidEditorDialog.h b/qtfred/src/ui/dialogs/AsteroidEditorDialog.h index b8ace401067..3ba6294c5ce 100644 --- a/qtfred/src/ui/dialogs/AsteroidEditorDialog.h +++ b/qtfred/src/ui/dialogs/AsteroidEditorDialog.h @@ -21,7 +21,7 @@ class AsteroidEditorDialog : public QDialog ~AsteroidEditorDialog() override; protected: - void closeEvent(QCloseEvent* e); + void closeEvent(QCloseEvent* e) override; void rejectHandler(); private: From 77de5c0aa70086291cd8b16d96f0ab78b8a6f5d6 Mon Sep 17 00:00:00 2001 From: The Force <2040992+TheForce172@users.noreply.github.com> Date: Mon, 30 Dec 2024 17:37:05 +0000 Subject: [PATCH 18/18] Address Feedback --- qtfred/src/mission/dialogs/LoadoutEditorDialogModel.cpp | 1 + .../src/mission/dialogs/ReinforcementsEditorDialogModel.cpp | 2 ++ qtfred/src/ui/FredView.cpp | 4 ++-- qtfred/src/ui/dialogs/MissionSpecDialog.cpp | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/qtfred/src/mission/dialogs/LoadoutEditorDialogModel.cpp b/qtfred/src/mission/dialogs/LoadoutEditorDialogModel.cpp index 13c1b883306..b15d0d5d100 100644 --- a/qtfred/src/mission/dialogs/LoadoutEditorDialogModel.cpp +++ b/qtfred/src/mission/dialogs/LoadoutEditorDialogModel.cpp @@ -933,6 +933,7 @@ void LoadoutDialogModel::setRequiredWeapon(const SCP_vector& list, c } set_modified(); buildCurrentLists(); + modelChanged(); } bool LoadoutDialogModel::getSkipValidation() { diff --git a/qtfred/src/mission/dialogs/ReinforcementsEditorDialogModel.cpp b/qtfred/src/mission/dialogs/ReinforcementsEditorDialogModel.cpp index 9714c803890..32b01e37b50 100644 --- a/qtfred/src/mission/dialogs/ReinforcementsEditorDialogModel.cpp +++ b/qtfred/src/mission/dialogs/ReinforcementsEditorDialogModel.cpp @@ -260,6 +260,7 @@ void ReinforcementsDialogModel::setUseCount(int count) for (auto& reinforcement : _selectedReinforcementIndices) { std::get<1>(_reinforcementList[reinforcement]) = count; } + modelChanged(); set_modified(); } @@ -268,6 +269,7 @@ void ReinforcementsDialogModel::setBeforeArrivalDelay(int delay) for (auto& reinforcement : _selectedReinforcementIndices) { std::get<2>(_reinforcementList[reinforcement]) = delay; } + modelChanged(); set_modified(); } diff --git a/qtfred/src/ui/FredView.cpp b/qtfred/src/ui/FredView.cpp index eb8d2893faa..851a71faa1f 100644 --- a/qtfred/src/ui/FredView.cpp +++ b/qtfred/src/ui/FredView.cpp @@ -872,7 +872,7 @@ void FredView::orientEditorTriggered() { auto dialog = new dialogs::ObjectOrientEditorDialog(this, _viewport); dialog->setAttribute(Qt::WA_DeleteOnClose); // This is a modal dialog - dialog->show(); + dialog->exec(); } void FredView::onUpdateEditorActions() { ui->actionObjects->setEnabled(query_valid_object(fred->currentObject)); @@ -989,7 +989,7 @@ void FredView::on_actionSelectionList_triggered(bool) { auto dialog = new dialogs::SelectionDialog(this, _viewport); // This is a modal dialog dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->show(); + dialog->exec(); } void FredView::on_actionOrbitSelected_triggered(bool enabled) { _viewport->Lookat_mode = enabled; diff --git a/qtfred/src/ui/dialogs/MissionSpecDialog.cpp b/qtfred/src/ui/dialogs/MissionSpecDialog.cpp index 30b68f25370..1b9a87c8f52 100644 --- a/qtfred/src/ui/dialogs/MissionSpecDialog.cpp +++ b/qtfred/src/ui/dialogs/MissionSpecDialog.cpp @@ -300,7 +300,7 @@ void MissionSpecDialog::squadronNameChanged(const QString & string) { void MissionSpecDialog::on_customWingNameButton_clicked() { CustomWingNamesDialog* dialog = new CustomWingNamesDialog(this, _viewport); dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->show(); + dialog->exec(); } void MissionSpecDialog::on_squadronLogoButton_clicked() {