Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QT Fred Boillerplate Removal and Memory Safety #6493

Merged
merged 18 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions qtfred/src/mission/dialogs/AbstractDialogModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

}
}
}
23 changes: 23 additions & 0 deletions qtfred/src/mission/dialogs/AbstractDialogModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class AbstractDialogModel: public QObject {
Editor* _editor = nullptr;
EditorViewport* _viewport = nullptr;

template <typename T>
/**
* @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);

Expand All @@ -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
Expand All @@ -51,6 +64,16 @@ class AbstractDialogModel: public QObject {
void modelChanged();
};

template <typename T>
inline void AbstractDialogModel::modify(T& a, const T& b)
{
if (a != b) {
a = b;
set_modified();
modelChanged();
}
}

}
}
}
Expand Down
16 changes: 0 additions & 16 deletions qtfred/src/mission/dialogs/AsteroidEditorDialogModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 0 additions & 16 deletions qtfred/src/mission/dialogs/AsteroidEditorDialogModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ Q_OBJECT
void update_init();
bool validate_data();

void set_modified();
void unset_modified();
bool get_modified();

private:
template<typename T>
void modify(T &a, const T &b);

void showErrorDialogNoCancel(const SCP_string& message);
void initializeData();
Expand Down Expand Up @@ -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;

Expand All @@ -110,15 +103,6 @@ Q_OBJECT
std::unordered_map<int, int> debris_inverse_idx_lookup;
};

template<typename T>
inline void AsteroidEditorDialogModel::modify(T &a, const T &b) {
if (a != b) {
a = b;
set_modified();
modelChanged();
}
}

} // namespace dialogs
} // namespace fred
} // namespace fso
17 changes: 13 additions & 4 deletions qtfred/src/mission/dialogs/CommandBriefingDialogModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void CommandBriefingDialogModel::addStage()

_wipCommandBrief.num_stages++;
_currentStage = _wipCommandBrief.num_stages - 1;

set_modified();
modelChanged();
}

Expand All @@ -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;
}
Expand All @@ -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();
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -293,38 +296,44 @@ 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();
}

void CommandBriefingDialogModel::setSpeechFilename(const SCP_string& speechFilename)
{
_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();
}

Expand Down
10 changes: 0 additions & 10 deletions qtfred/src/mission/dialogs/CustomWingNamesDialogModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,12 @@ class CustomWingNamesDialogModel : public AbstractDialogModel {
private:
void initializeData();

template<typename T>
void modify(T &a, T &b);

SCP_string _m_starting[3];
SCP_string _m_squadron[5];
SCP_string _m_tvt[2];
};

template<typename T>
inline void CustomWingNamesDialogModel::modify(T & a, T & b) {
if (a != b) {
a = b;
modelChanged();
}
}

}
}
}
11 changes: 0 additions & 11 deletions qtfred/src/mission/dialogs/FictionViewerDialogModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class FictionViewerDialogModel: public AbstractDialogModel {
private:
void initializeData();

template<typename T>
void modify(T &a, const T &b);

SCP_string _storyFile;
SCP_string _fontFile;
Expand All @@ -59,15 +57,6 @@ class FictionViewerDialogModel: public AbstractDialogModel {
int _maxStoryFileLength, _maxFontFileLength, _maxVoiceFileLength;
};


template<typename T>
inline void FictionViewerDialogModel::modify(T &a, const T &b) {
if (a != b) {
a = b;
modelChanged();
}
}

}
}
}
23 changes: 13 additions & 10 deletions qtfred/src/mission/dialogs/LoadoutEditorDialogModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ void LoadoutDialogModel::setPlayerEntryDelay(float delay)
{
_playerEntryDelay = delay;
modelChanged();
set_modified();

}

Expand Down Expand Up @@ -721,7 +722,7 @@ void LoadoutDialogModel::setShipEnabled(const SCP_vector<SCP_string>& list, bool
}
}
}

set_modified();
Goober5000 marked this conversation as resolved.
Show resolved Hide resolved
buildCurrentLists();
}

Expand Down Expand Up @@ -754,7 +755,7 @@ void LoadoutDialogModel::setShipVariableEnabled(const SCP_vector<SCP_string>& li
item);
}
}

set_modified();
buildCurrentLists();
}

Expand All @@ -780,7 +781,7 @@ void LoadoutDialogModel::setWeaponEnabled(const SCP_vector<SCP_string>& list, bo
}
}
}

set_modified();
buildCurrentLists();
}

Expand Down Expand Up @@ -813,7 +814,7 @@ void LoadoutDialogModel::setWeaponVariableEnabled(const SCP_vector<SCP_string>&
item);
}
}

set_modified();
buildCurrentLists();
}

Expand All @@ -828,7 +829,7 @@ void LoadoutDialogModel::setExtraAllocatedShipCount(const SCP_vector<SCP_string>
}
}
}

set_modified();
buildCurrentLists();
}

Expand All @@ -842,7 +843,7 @@ void LoadoutDialogModel::setExtraAllocatedForShipVariablesCount(const SCP_vector
}
}
}

set_modified();
buildCurrentLists();
}

Expand All @@ -856,7 +857,7 @@ void LoadoutDialogModel::setExtraAllocatedWeaponCount(const SCP_vector<SCP_strin
}
}
}

set_modified();
buildCurrentLists();
}

Expand All @@ -870,7 +871,7 @@ void LoadoutDialogModel::setExtraAllocatedForWeaponVariablesCount(const SCP_vect
}
}
}

set_modified();
buildCurrentLists();
}

Expand Down Expand Up @@ -916,7 +917,7 @@ void LoadoutDialogModel::setExtraAllocatedViaVariable(const SCP_vector<SCP_strin
}
}
}

set_modified();
buildCurrentLists();
}

Expand All @@ -930,8 +931,9 @@ void LoadoutDialogModel::setRequiredWeapon(const SCP_vector<SCP_string>& list, c
}
}
}

set_modified();
buildCurrentLists();
modelChanged();
}

bool LoadoutDialogModel::getSkipValidation() {
Expand All @@ -942,6 +944,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();
}
}

Expand Down
10 changes: 0 additions & 10 deletions qtfred/src/mission/dialogs/MissionSpecDialogModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
}
}
Loading
Loading