Check "Select all" checkbox if all options are already selected

+ code cleanup

Signed-off-by: Marcelo Hernandez <marcelohdez.inq@gmail.com>
This commit is contained in:
Marcelo Hernandez 2022-10-23 00:25:38 -04:00
parent 15593b5c09
commit 4caf06bc99
No known key found for this signature in database
GPG Key ID: 1405A0E7C9C4D61D
4 changed files with 65 additions and 101 deletions

View File

@ -4,12 +4,13 @@
#include "InstanceCopyPrefs.h"
InstanceCopyPrefs::InstanceCopyPrefs(bool setAll)
: copySaves(setAll),
keepPlaytime(setAll),
copyGameOptions(setAll),
copyResourcePacks(setAll),
copyShaderPacks(setAll),
copyServers(setAll),
copyMods(setAll)
{}
bool InstanceCopyPrefs::allTrue() const
{
return copySaves &&
keepPlaytime &&
copyGameOptions &&
copyResourcePacks &&
copyShaderPacks &&
copyServers &&
copyMods;
}

View File

@ -6,16 +6,15 @@
#define LAUNCHER_INSTANCECOPYPREFS_H
struct InstanceCopyPrefs {
explicit InstanceCopyPrefs(bool setAll);
~InstanceCopyPrefs() = default;
bool copySaves = true;
bool keepPlaytime = true;
bool copyGameOptions = true;
bool copyResourcePacks = true;
bool copyShaderPacks = true;
bool copyServers = true;
bool copyMods = true;
bool copySaves;
bool keepPlaytime;
bool copyGameOptions;
bool copyResourcePacks;
bool copyShaderPacks;
bool copyServers;
bool copyMods;
bool allTrue() const;
};
#endif // LAUNCHER_INSTANCECOPYPREFS_H

View File

@ -122,6 +122,40 @@ QString CopyInstanceDialog::instGroup() const
return ui->groupBox->currentText();
}
const InstanceCopyPrefs& CopyInstanceDialog::getChosenOptions() const
{
return m_selectedOptions;
}
void CopyInstanceDialog::checkAllCheckboxes(const bool& b)
{
ui->keepPlaytimeCheckbox->setChecked(b);
ui->copySavesCheckbox->setChecked(b);
ui->copyGameOptionsCheckbox->setChecked(b);
ui->copyResPacksCheckbox->setChecked(b);
ui->copyShaderPacksCheckbox->setChecked(b);
ui->copyServersCheckbox->setChecked(b);
ui->copyModsCheckbox->setChecked(b);
}
// Sets b to true if state is a checked checkbox
void CopyInstanceDialog::checkBool(bool& b, const int& state)
{
if(state == Qt::Unchecked)
{
b = false;
}
else if(state == Qt::Checked)
{
b = true;
}
// Have "Select all" checkbox checked if all options are already checked:
ui->selectAllCheckbox->blockSignals(true);
ui->selectAllCheckbox->setChecked(m_selectedOptions.allTrue());
ui->selectAllCheckbox->blockSignals(false);
}
void CopyInstanceDialog::on_iconButton_clicked()
{
IconPickerDialog dlg(this);
@ -134,123 +168,51 @@ void CopyInstanceDialog::on_iconButton_clicked()
}
}
void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1)
{
updateDialogState();
}
const InstanceCopyPrefs& CopyInstanceDialog::getChosenOptions() const
{
return m_selectedOptions;
}
void CopyInstanceDialog::on_selectAllCheckbox_stateChanged(int state)
{
bool checked;
if(state == Qt::Unchecked)
{
checked = false;
}
else if(state == Qt::Checked)
{
checked = true;
}
checkBool(checked, state);
checkAllCheckboxes(checked);
}
void CopyInstanceDialog::checkAllCheckboxes(bool b)
{
ui->keepPlaytimeCheckbox->setChecked(b);
ui->copySavesCheckbox->setChecked(b);
ui->copyGameOptionsCheckbox->setChecked(b);
ui->copyResPacksCheckbox->setChecked(b);
ui->copyShaderPacksCheckbox->setChecked(b);
ui->copyServersCheckbox->setChecked(b);
ui->copyModsCheckbox->setChecked(b);
}
void CopyInstanceDialog::on_copySavesCheckbox_stateChanged(int state)
{
if(state == Qt::Unchecked)
{
m_selectedOptions.copySaves = false;
}
else if(state == Qt::Checked)
{
m_selectedOptions.copySaves = true;
}
checkBool(m_selectedOptions.copySaves, state);
}
void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state)
{
if(state == Qt::Unchecked)
{
m_selectedOptions.keepPlaytime = false;
}
else if(state == Qt::Checked)
{
m_selectedOptions.keepPlaytime = true;
}
checkBool(m_selectedOptions.keepPlaytime, state);
}
void CopyInstanceDialog::on_copyGameOptionsCheckbox_stateChanged(int state)
{
if(state == Qt::Unchecked)
{
m_selectedOptions.copyGameOptions = false;
}
else if(state == Qt::Checked)
{
m_selectedOptions.copyGameOptions = true;
}
checkBool(m_selectedOptions.copyGameOptions, state);
}
void CopyInstanceDialog::on_copyResPacksCheckbox_stateChanged(int state)
{
if(state == Qt::Unchecked)
{
m_selectedOptions.copyResourcePacks = false;
}
else if(state == Qt::Checked)
{
m_selectedOptions.copyResourcePacks = true;
}
checkBool(m_selectedOptions.copyResourcePacks, state);
}
void CopyInstanceDialog::on_copyShaderPacksCheckbox_stateChanged(int state)
{
if(state == Qt::Unchecked)
{
m_selectedOptions.copyShaderPacks = false;
}
else if(state == Qt::Checked)
{
m_selectedOptions.copyShaderPacks = true;
}
checkBool(m_selectedOptions.copyShaderPacks, state);
}
void CopyInstanceDialog::on_copyServersCheckbox_stateChanged(int state)
{
if(state == Qt::Unchecked)
{
m_selectedOptions.copyServers = false;
}
else if(state == Qt::Checked)
{
m_selectedOptions.copyServers = true;
}
checkBool(m_selectedOptions.copyServers, state);
}
void CopyInstanceDialog::on_copyModsCheckbox_stateChanged(int state)
{
if(state == Qt::Unchecked)
{
m_selectedOptions.copyMods = false;
}
else if(state == Qt::Checked)
{
m_selectedOptions.copyMods = true;
}
checkBool(m_selectedOptions.copyMods, state);
}

View File

@ -47,7 +47,9 @@ slots:
void on_instNameTextBox_textChanged(const QString &arg1);
// Checkbox options:
void checkAllCheckboxes(bool b);
void checkAllCheckboxes(const bool& b);
void checkBool(bool& b, const int& state);
void on_selectAllCheckbox_stateChanged(int state);
void on_copySavesCheckbox_stateChanged(int state);
void on_keepPlaytimeCheckbox_stateChanged(int state);
@ -61,5 +63,5 @@ private:
Ui::CopyInstanceDialog *ui;
QString InstIconKey;
InstancePtr m_original;
InstanceCopyPrefs m_selectedOptions = InstanceCopyPrefs(true); // Default to all options as true
InstanceCopyPrefs m_selectedOptions;
};