fix: Polish usage in some cases

Also fiz some typos
This commit is contained in:
flow 2022-04-03 10:21:48 -03:00
parent 76dfb7825a
commit 63bce04648
5 changed files with 64 additions and 27 deletions

View File

@ -2,7 +2,7 @@
#include "ui_FilterModsDialog.h"
FilterModsDialog::FilterModsDialog(Version def, QWidget* parent)
: QDialog(parent), m_filter(new Filter()), ui(new Ui::FilterModsDialog)
: QDialog(parent), m_filter(new Filter()), m_internal_filter(new Filter()), ui(new Ui::FilterModsDialog)
{
ui->setupUi(this);
@ -13,28 +13,44 @@ FilterModsDialog::FilterModsDialog(Version def, QWidget* parent)
connect(&m_mcVersion_buttons, SIGNAL(idClicked(int)), this, SLOT(onVersionFilterChanged(int)));
m_filter->versions.push_front(def);
m_internal_filter->versions.push_front(def);
commitChanges();
}
int FilterModsDialog::execWithInstance(MinecraftInstance* instance)
{
m_instance = instance;
auto* pressed_button = m_mcVersion_buttons.checkedButton();
// Fix first openening behaviour
onVersionFilterChanged(0);
onVersionFilterChanged(m_previous_mcVersion_id);
auto mcVersionSplit = mcVersionStr().split(".");
ui->strictVersionButton->setText(
tr("Strict match (= %1)").arg(mcVersionStr()));
ui->majorVersionButton->setText(
tr("Major varsion match (= %1.%2.x)").arg(mcVersionSplit[0], mcVersionSplit[1]));
tr("Major version match (= %1.%2.x)").arg(mcVersionSplit[0], mcVersionSplit[1]));
ui->allVersionsButton->setText(
tr("Any version match"));
tr("Any version"));
//ui->betweenVersionsButton->setText(
// tr("Between two versions"));
int ret = QDialog::exec();
if(ret == QDialog::DialogCode::Accepted){
// If there's no change, let's sey it's a cancel to the caller
if(*m_internal_filter.get() == *m_filter.get())
return QDialog::DialogCode::Rejected;
m_previous_mcVersion_id = (VersionButtonID) m_mcVersion_buttons.checkedId();
commitChanges();
} else {
pressed_button->click();
revertChanges();
}
m_instance = nullptr;
return ret;
}
@ -59,6 +75,16 @@ void FilterModsDialog::disableVersionButton(VersionButtonID id)
}
}
// Do deep copy
void FilterModsDialog::commitChanges()
{
m_filter->versions = m_internal_filter->versions;
}
void FilterModsDialog::revertChanges()
{
m_internal_filter->versions = m_filter->versions;
}
void FilterModsDialog::onVersionFilterChanged(int id)
{
//ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between);
@ -67,15 +93,15 @@ void FilterModsDialog::onVersionFilterChanged(int id)
auto versionSplit = mcVersionStr().split(".");
int index = 0;
m_filter->versions.clear();
m_internal_filter->versions.clear();
switch(id){
case(VersionButtonID::Strict):
m_filter->versions.push_front(mcVersion());
m_internal_filter->versions.push_front(mcVersion());
break;
case(VersionButtonID::Major):
for(auto i = Version(QString("%1.%2").arg(versionSplit[0], versionSplit[1])); i <= mcVersion(); index++){
m_filter->versions.push_front(i);
m_internal_filter->versions.push_front(i);
i = Version(QString("%1.%2.%3").arg(versionSplit[0], versionSplit[1], QString("%1").arg(index)));
}
break;

View File

@ -26,9 +26,13 @@ public:
struct Filter {
std::list<Version> versions;
bool operator==(const Filter& other) const { return versions == other.versions; }
bool operator!=(const Filter& other) const { return !(*this == other); }
};
std::shared_ptr<Filter> m_filter;
std::shared_ptr<Filter> m_internal_filter;
public:
explicit FilterModsDialog(Version def, QWidget* parent = nullptr);
@ -45,6 +49,9 @@ private:
inline auto mcVersionStr() const -> QString { return m_instance ? m_instance->getPackProfile()->getComponentVersion("net.minecraft") : ""; }
inline auto mcVersion() const -> Version { return { mcVersionStr() }; }
void commitChanges();
void revertChanges();
private slots:
void onVersionFilterChanged(int id);
@ -54,4 +61,5 @@ private:
MinecraftInstance* m_instance = nullptr;
QButtonGroup m_mcVersion_buttons;
VersionButtonID m_previous_mcVersion_id = VersionButtonID::Strict;
};

View File

@ -59,14 +59,15 @@ auto ModPage::eventFilter(QObject* watched, QEvent* event) -> bool
void ModPage::filterMods()
{
filter_dialog.execWithInstance(static_cast<MinecraftInstance*>(m_instance));
auto ret = filter_dialog.execWithInstance(static_cast<MinecraftInstance*>(m_instance));
m_filter = filter_dialog.getFilter();
listModel->refresh();
if(ui->versionSelectionBox->count() > 0){
if(ret == QDialog::DialogCode::Accepted){
listModel->refresh();
int prev_count = ui->versionSelectionBox->count();
ui->versionSelectionBox->clear();
updateModVersions();
updateModVersions(prev_count);
}
}
@ -152,7 +153,7 @@ void ModPage::retranslate()
ui->retranslateUi(this);
}
void ModPage::updateModVersions()
void ModPage::updateModVersions(int prev_count)
{
auto packProfile = (dynamic_cast<MinecraftInstance*>(m_instance))->getPackProfile();
@ -173,9 +174,11 @@ void ModPage::updateModVersions()
if(valid || m_filter->versions.size() == 0)
ui->versionSelectionBox->addItem(version.version, QVariant(i));
}
if (ui->versionSelectionBox->count() == 0) { ui->versionSelectionBox->addItem(tr("No valid version found!"), QVariant(-1)); }
if (ui->versionSelectionBox->count() == 0 && prev_count != 0) {
ui->versionSelectionBox->addItem(tr("No valid version found!"), QVariant(-1));
ui->modSelectionButton->setText(tr("Cannot select invalid version :("));
}
ui->modSelectionButton->setText(tr("Cannot select invalid version :("));
updateSelectionButton();
}

View File

@ -43,7 +43,7 @@ class ModPage : public QWidget, public BasePage {
auto getFilter() const -> const std::shared_ptr<FilterModsDialog::Filter> { return m_filter; }
auto getCurrent() -> ModPlatform::IndexedPack& { return current; }
void updateModVersions();
void updateModVersions(int prev_count = -1);
void openedImpl() override;
auto eventFilter(QObject* watched, QEvent* event) -> bool override;

View File

@ -67,22 +67,22 @@ auto FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString min
return ver.mcVersion.contains(mineVer);
}
// We override this so that it refreshes correctly, otherwise it wouldn't show
// any mod on the mod list, because the CF API does not support it :(
// We override this so that it refreshes correctly, otherwise it would show
// invalid mods on the mod list, because the API would return mods for the
// wrong mod loader :(
void FlameModPage::filterMods()
{
filter_dialog.execWithInstance(static_cast<MinecraftInstance*>(m_instance));
int prev_size = m_filter->versions.size();
auto ret = filter_dialog.execWithInstance(static_cast<MinecraftInstance*>(m_instance));
m_filter = filter_dialog.getFilter();
int new_size = m_filter->versions.size();
if(new_size <= 1 && new_size != prev_size)
listModel->refresh();
if(ret == QDialog::DialogCode::Accepted){
// CF API can't handle well this
if(!m_filter->versions.empty())
listModel->refresh();
if(ui->versionSelectionBox->count() > 0){
int prev_count = ui->versionSelectionBox->count();
ui->versionSelectionBox->clear();
updateModVersions();
updateModVersions(prev_count);
}
}