Add "Select all" checkbox + ui revamp + code cleanup

Signed-off-by: Marcelo Hernandez <marcelohdez.inq@gmail.com>
This commit is contained in:
Marcelo Hernandez 2022-10-22 23:04:36 -04:00
parent e7e56eb1e3
commit 15593b5c09
No known key found for this signature in database
GPG Key ID: 1405A0E7C9C4D61D
9 changed files with 153 additions and 144 deletions

View File

@ -32,6 +32,7 @@ set(CORE_SOURCES
InstanceCreationTask.h InstanceCreationTask.h
InstanceCreationTask.cpp InstanceCreationTask.cpp
InstanceCopyPrefs.h InstanceCopyPrefs.h
InstanceCopyPrefs.cpp
InstanceCopyTask.h InstanceCopyTask.h
InstanceCopyTask.cpp InstanceCopyTask.cpp
InstanceImportTask.h InstanceImportTask.h

View File

@ -0,0 +1,15 @@
//
// Created by marcelohdez on 10/22/22.
//
#include "InstanceCopyPrefs.h"
InstanceCopyPrefs::InstanceCopyPrefs(bool setAll)
: copySaves(setAll),
keepPlaytime(setAll),
copyGameOptions(setAll),
copyResourcePacks(setAll),
copyShaderPacks(setAll),
copyServers(setAll),
copyMods(setAll)
{}

View File

@ -6,6 +6,9 @@
#define LAUNCHER_INSTANCECOPYPREFS_H #define LAUNCHER_INSTANCECOPYPREFS_H
struct InstanceCopyPrefs { struct InstanceCopyPrefs {
explicit InstanceCopyPrefs(bool setAll);
~InstanceCopyPrefs() = default;
bool copySaves; bool copySaves;
bool keepPlaytime; bool keepPlaytime;
bool copyGameOptions; bool copyGameOptions;

View File

@ -5,7 +5,7 @@
#include "pathmatcher/RegexpMatcher.h" #include "pathmatcher/RegexpMatcher.h"
#include <QtConcurrentRun> #include <QtConcurrentRun>
InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, InstanceCopyPrefs prefs) InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, const InstanceCopyPrefs& prefs)
{ {
m_origInstance = origInstance; m_origInstance = origInstance;
m_keepPlaytime = prefs.keepPlaytime; m_keepPlaytime = prefs.keepPlaytime;
@ -51,7 +51,7 @@ InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, InstanceCopyPrefs p
} }
} }
void InstanceCopyTask::appendToFilter(QString& filter, const QString &append) void InstanceCopyTask::appendToFilter(QString& filter, const QString& append)
{ {
if (!filter.isEmpty()) if (!filter.isEmpty())
filter.append('|'); // OR regex filter.append('|'); // OR regex

View File

@ -15,7 +15,7 @@ class InstanceCopyTask : public InstanceTask
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit InstanceCopyTask(InstancePtr origInstance, InstanceCopyPrefs prefs); explicit InstanceCopyTask(InstancePtr origInstance, const InstanceCopyPrefs& prefs);
protected: protected:
//! Entry point for tasks. //! Entry point for tasks.

View File

@ -1616,17 +1616,7 @@ void MainWindow::on_actionCopyInstance_triggered()
if (!copyInstDlg.exec()) if (!copyInstDlg.exec())
return; return;
auto copyTask = new InstanceCopyTask( auto copyTask = new InstanceCopyTask(m_selectedInstance, copyInstDlg.getChosenOptions());
m_selectedInstance,
InstanceCopyPrefs {
copyInstDlg.shouldCopySaves(),
copyInstDlg.shouldKeepPlaytime(),
copyInstDlg.shouldCopyGameOptions(),
copyInstDlg.shouldCopyResourcePacks(),
copyInstDlg.shouldCopyShaderPacks(),
copyInstDlg.shouldCopyServers(),
copyInstDlg.shouldCopyMods()
});
copyTask->setName(copyInstDlg.instName()); copyTask->setName(copyInstDlg.instName());
copyTask->setGroup(copyInstDlg.instGroup()); copyTask->setGroup(copyInstDlg.instGroup());
copyTask->setIcon(copyInstDlg.iconKey()); copyTask->setIcon(copyInstDlg.iconKey());

View File

@ -78,13 +78,13 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent)
} }
ui->groupBox->setCurrentIndex(index); ui->groupBox->setCurrentIndex(index);
ui->groupBox->lineEdit()->setPlaceholderText(tr("No group")); ui->groupBox->lineEdit()->setPlaceholderText(tr("No group"));
ui->copySavesCheckbox->setChecked(m_copySaves); ui->copySavesCheckbox->setChecked(m_selectedOptions.copySaves);
ui->keepPlaytimeCheckbox->setChecked(m_keepPlaytime); ui->keepPlaytimeCheckbox->setChecked(m_selectedOptions.keepPlaytime);
ui->copyGameOptionsCheckbox->setChecked(m_copyGameOptions); ui->copyGameOptionsCheckbox->setChecked(m_selectedOptions.copyGameOptions);
ui->copyResPacksCheckbox->setChecked(m_copyResourcePacks); ui->copyResPacksCheckbox->setChecked(m_selectedOptions.copyResourcePacks);
ui->copyShaderPacksCheckbox->setChecked(m_copyShaderPacks); ui->copyShaderPacksCheckbox->setChecked(m_selectedOptions.copyShaderPacks);
ui->copyServersCheckbox->setChecked(m_copyServers); ui->copyServersCheckbox->setChecked(m_selectedOptions.copyServers);
ui->copyModsCheckbox->setChecked(m_copyMods); ui->copyModsCheckbox->setChecked(m_selectedOptions.copyMods);
} }
CopyInstanceDialog::~CopyInstanceDialog() CopyInstanceDialog::~CopyInstanceDialog()
@ -139,122 +139,118 @@ void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1)
updateDialogState(); updateDialogState();
} }
bool CopyInstanceDialog::shouldCopySaves() const const InstanceCopyPrefs& CopyInstanceDialog::getChosenOptions() const
{ {
return m_copySaves; 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;
}
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) void CopyInstanceDialog::on_copySavesCheckbox_stateChanged(int state)
{ {
if(state == Qt::Unchecked) if(state == Qt::Unchecked)
{ {
m_copySaves = false; m_selectedOptions.copySaves = false;
} }
else if(state == Qt::Checked) else if(state == Qt::Checked)
{ {
m_copySaves = true; m_selectedOptions.copySaves = true;
} }
} }
bool CopyInstanceDialog::shouldKeepPlaytime() const
{
return m_keepPlaytime;
}
void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state) void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state)
{ {
if(state == Qt::Unchecked) if(state == Qt::Unchecked)
{ {
m_keepPlaytime = false; m_selectedOptions.keepPlaytime = false;
} }
else if(state == Qt::Checked) else if(state == Qt::Checked)
{ {
m_keepPlaytime = true; m_selectedOptions.keepPlaytime = true;
} }
} }
bool CopyInstanceDialog::shouldCopyGameOptions() const
{
return m_copyGameOptions;
}
void CopyInstanceDialog::on_copyGameOptionsCheckbox_stateChanged(int state) void CopyInstanceDialog::on_copyGameOptionsCheckbox_stateChanged(int state)
{ {
if(state == Qt::Unchecked) if(state == Qt::Unchecked)
{ {
m_copyGameOptions = false; m_selectedOptions.copyGameOptions = false;
} }
else if(state == Qt::Checked) else if(state == Qt::Checked)
{ {
m_copyGameOptions = true; m_selectedOptions.copyGameOptions = true;
} }
} }
bool CopyInstanceDialog::shouldCopyResourcePacks() const
{
return m_copyResourcePacks;
}
void CopyInstanceDialog::on_copyResPacksCheckbox_stateChanged(int state) void CopyInstanceDialog::on_copyResPacksCheckbox_stateChanged(int state)
{ {
if(state == Qt::Unchecked) if(state == Qt::Unchecked)
{ {
m_copyResourcePacks = false; m_selectedOptions.copyResourcePacks = false;
} }
else if(state == Qt::Checked) else if(state == Qt::Checked)
{ {
m_copyResourcePacks = true; m_selectedOptions.copyResourcePacks = true;
} }
} }
bool CopyInstanceDialog::shouldCopyShaderPacks() const
{
return m_copyShaderPacks;
}
void CopyInstanceDialog::on_copyShaderPacksCheckbox_stateChanged(int state) void CopyInstanceDialog::on_copyShaderPacksCheckbox_stateChanged(int state)
{ {
if(state == Qt::Unchecked) if(state == Qt::Unchecked)
{ {
m_copyShaderPacks = false; m_selectedOptions.copyShaderPacks = false;
} }
else if(state == Qt::Checked) else if(state == Qt::Checked)
{ {
m_copyShaderPacks = true; m_selectedOptions.copyShaderPacks = true;
} }
} }
bool CopyInstanceDialog::shouldCopyServers() const
{
return m_copyServers;
}
void CopyInstanceDialog::on_copyServersCheckbox_stateChanged(int state) void CopyInstanceDialog::on_copyServersCheckbox_stateChanged(int state)
{ {
if(state == Qt::Unchecked) if(state == Qt::Unchecked)
{ {
m_copyServers = false; m_selectedOptions.copyServers = false;
} }
else if(state == Qt::Checked) else if(state == Qt::Checked)
{ {
m_copyServers = true; m_selectedOptions.copyServers = true;
} }
} }
bool CopyInstanceDialog::shouldCopyMods() const
{
return m_copyMods;
}
void CopyInstanceDialog::on_copyModsCheckbox_stateChanged(int state) void CopyInstanceDialog::on_copyModsCheckbox_stateChanged(int state)
{ {
if(state == Qt::Unchecked) if(state == Qt::Unchecked)
{ {
m_copyMods = false; m_selectedOptions.copyMods = false;
} }
else if(state == Qt::Checked) else if(state == Qt::Checked)
{ {
m_copyMods = true; m_selectedOptions.copyMods = true;
} }
} }

View File

@ -17,7 +17,7 @@
#include <QDialog> #include <QDialog>
#include "BaseVersion.h" #include "BaseVersion.h"
#include <BaseInstance.h> #include "InstanceCopyPrefs.h"
class BaseInstance; class BaseInstance;
@ -39,18 +39,16 @@ public:
QString instName() const; QString instName() const;
QString instGroup() const; QString instGroup() const;
QString iconKey() const; QString iconKey() const;
bool shouldCopySaves() const; const InstanceCopyPrefs& getChosenOptions() const;
bool shouldKeepPlaytime() const;
bool shouldCopyGameOptions() const;
bool shouldCopyResourcePacks() const;
bool shouldCopyShaderPacks() const;
bool shouldCopyServers() const;
bool shouldCopyMods() const;
private private
slots: slots:
void on_iconButton_clicked(); void on_iconButton_clicked();
void on_instNameTextBox_textChanged(const QString &arg1); void on_instNameTextBox_textChanged(const QString &arg1);
// Checkbox options:
void checkAllCheckboxes(bool b);
void on_selectAllCheckbox_stateChanged(int state);
void on_copySavesCheckbox_stateChanged(int state); void on_copySavesCheckbox_stateChanged(int state);
void on_keepPlaytimeCheckbox_stateChanged(int state); void on_keepPlaytimeCheckbox_stateChanged(int state);
void on_copyGameOptionsCheckbox_stateChanged(int state); void on_copyGameOptionsCheckbox_stateChanged(int state);
@ -63,11 +61,5 @@ private:
Ui::CopyInstanceDialog *ui; Ui::CopyInstanceDialog *ui;
QString InstIconKey; QString InstIconKey;
InstancePtr m_original; InstancePtr m_original;
bool m_copySaves = true; InstanceCopyPrefs m_selectedOptions = InstanceCopyPrefs(true); // Default to all options as true
bool m_keepPlaytime = true;
bool m_copyGameOptions = true;
bool m_copyResourcePacks = true;
bool m_copyShaderPacks = true;
bool m_copyServers = true;
bool m_copyMods = true;
}; };

View File

@ -9,8 +9,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>265</width> <width>341</width>
<height>425</height> <height>385</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -60,7 +60,7 @@
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>60</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
@ -83,7 +83,10 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="groupDropdownLayout">
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="labelVersion_3"> <widget class="QLabel" name="labelVersion_3">
<property name="text"> <property name="text">
@ -110,62 +113,73 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="copySavesCheckbox"> <layout class="QGridLayout" name="copyOptionsLayout">
<property name="text"> <item row="3" column="0">
<string>Copy saves</string> <widget class="QCheckBox" name="copySavesCheckbox">
</property> <property name="text">
</widget> <string>Copy saves</string>
</item> </property>
<item> </widget>
<widget class="QCheckBox" name="keepPlaytimeCheckbox"> </item>
<property name="text"> <item row="6" column="0">
<string>Keep play time</string> <widget class="QCheckBox" name="copyResPacksCheckbox">
</property> <property name="enabled">
</widget> <bool>true</bool>
</item> </property>
<item> <property name="text">
<widget class="QCheckBox" name="copyGameOptionsCheckbox"> <string>Copy resource packs</string>
<property name="toolTip"> </property>
<string>Copy the in-game options like FOV, max framerate, etc.</string> </widget>
</property> </item>
<property name="text"> <item row="6" column="1">
<string>Copy game options</string> <widget class="QCheckBox" name="copyModsCheckbox">
</property> <property name="toolTip">
</widget> <string>Disabling this will still keep the mod loader (ex: Fabric, Quilt, etc.) but erase the mods folder and their configs.</string>
</item> </property>
<item> <property name="text">
<widget class="QCheckBox" name="copyResPacksCheckbox"> <string>Copy mods</string>
<property name="enabled"> </property>
<bool>true</bool> </widget>
</property> </item>
<property name="text"> <item row="5" column="0">
<string>Copy resource packs</string> <widget class="QCheckBox" name="copyGameOptionsCheckbox">
</property> <property name="toolTip">
</widget> <string>Copy the in-game options like FOV, max framerate, etc.</string>
</item> </property>
<item> <property name="text">
<widget class="QCheckBox" name="copyShaderPacksCheckbox"> <string>Copy game options</string>
<property name="text"> </property>
<string>Copy shader packs</string> </widget>
</property> </item>
</widget> <item row="5" column="1">
</item> <widget class="QCheckBox" name="copyServersCheckbox">
<item> <property name="text">
<widget class="QCheckBox" name="copyServersCheckbox"> <string>Copy servers</string>
<property name="text"> </property>
<string>Copy servers</string> </widget>
</property> </item>
</widget> <item row="1" column="1">
</item> <widget class="QCheckBox" name="keepPlaytimeCheckbox">
<item> <property name="text">
<widget class="QCheckBox" name="copyModsCheckbox"> <string>Keep play time</string>
<property name="toolTip"> </property>
<string>Disabling this will still keep the mod loader (ex: Fabric, Quilt, etc.) but erase the mods folder and their configs.</string> </widget>
</property> </item>
<property name="text"> <item row="3" column="1">
<string>Copy mods</string> <widget class="QCheckBox" name="copyShaderPacksCheckbox">
</property> <property name="text">
</widget> <string>Copy shader packs</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="selectAllCheckbox">
<property name="text">
<string>Select all</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
@ -183,8 +197,6 @@
<tabstop>iconButton</tabstop> <tabstop>iconButton</tabstop>
<tabstop>instNameTextBox</tabstop> <tabstop>instNameTextBox</tabstop>
<tabstop>groupBox</tabstop> <tabstop>groupBox</tabstop>
<tabstop>copySavesCheckbox</tabstop>
<tabstop>keepPlaytimeCheckbox</tabstop>
</tabstops> </tabstops>
<resources> <resources>
<include location="../../graphics.qrc"/> <include location="../../graphics.qrc"/>