rework: make the filter as a tabbed widget in the dialog itself

Still needs a clear indication that the filter only applies after you
click the search button...
This commit is contained in:
flow
2022-04-14 10:27:03 -03:00
parent 63bce04648
commit 277de41200
11 changed files with 138 additions and 247 deletions

View File

@ -1,122 +0,0 @@
#include "FilterModsDialog.h"
#include "ui_FilterModsDialog.h"
FilterModsDialog::FilterModsDialog(Version def, QWidget* parent)
: QDialog(parent), m_filter(new Filter()), m_internal_filter(new Filter()), ui(new Ui::FilterModsDialog)
{
ui->setupUi(this);
m_mcVersion_buttons.addButton(ui->strictVersionButton, VersionButtonID::Strict);
m_mcVersion_buttons.addButton(ui->majorVersionButton, VersionButtonID::Major);
m_mcVersion_buttons.addButton(ui->allVersionsButton, VersionButtonID::All);
//m_mcVersion_buttons.addButton(ui->betweenVersionsButton, VersionButtonID::Between);
connect(&m_mcVersion_buttons, SIGNAL(idClicked(int)), this, SLOT(onVersionFilterChanged(int)));
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(m_previous_mcVersion_id);
auto mcVersionSplit = mcVersionStr().split(".");
ui->strictVersionButton->setText(
tr("Strict match (= %1)").arg(mcVersionStr()));
ui->majorVersionButton->setText(
tr("Major version match (= %1.%2.x)").arg(mcVersionSplit[0], mcVersionSplit[1]));
ui->allVersionsButton->setText(
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;
}
void FilterModsDialog::disableVersionButton(VersionButtonID id)
{
switch(id){
case(VersionButtonID::Strict):
ui->strictVersionButton->setEnabled(false);
break;
case(VersionButtonID::Major):
ui->majorVersionButton->setEnabled(false);
break;
case(VersionButtonID::All):
ui->allVersionsButton->setEnabled(false);
break;
case(VersionButtonID::Between):
// ui->betweenVersionsButton->setEnabled(false);
break;
default:
break;
}
}
// 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);
//ui->upperVersionComboBox->setEnabled(id == VersionButtonID::Between);
auto versionSplit = mcVersionStr().split(".");
int index = 0;
m_internal_filter->versions.clear();
switch(id){
case(VersionButtonID::Strict):
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_internal_filter->versions.push_front(i);
i = Version(QString("%1.%2.%3").arg(versionSplit[0], versionSplit[1], QString("%1").arg(index)));
}
break;
case(VersionButtonID::All):
// Empty list to avoid enumerating all versions :P
break;
case(VersionButtonID::Between):
// TODO
break;
default:
break;
}
}
FilterModsDialog::~FilterModsDialog()
{
delete ui;
}

View File

@ -1,65 +0,0 @@
#pragma once
#include <QDialog>
#include <QButtonGroup>
#include "Version.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
class MinecraftInstance;
namespace Ui {
class FilterModsDialog;
}
class FilterModsDialog : public QDialog
{
Q_OBJECT
public:
enum VersionButtonID {
Strict = 0,
Major = 1,
All = 2,
Between = 3
};
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);
~FilterModsDialog();
int execWithInstance(MinecraftInstance* instance);
/// By default all buttons are enabled
void disableVersionButton(VersionButtonID);
auto getFilter() -> std::shared_ptr<Filter> { return m_filter; }
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);
private:
Ui::FilterModsDialog* ui;
MinecraftInstance* m_instance = nullptr;
QButtonGroup m_mcVersion_buttons;
VersionButtonID m_previous_mcVersion_id = VersionButtonID::Strict;
};

View File

@ -1,135 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FilterModsDialog</class>
<widget class="QDialog" name="FilterModsDialog">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>345</width>
<height>169</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Filter options</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Minecraft versions</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QFormLayout" name="formLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QRadioButton" name="strictVersionButton">
<property name="text">
<string>StrictVersion</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="majorVersionButton">
<property name="text">
<string>MajorVersion</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="allVersionsButton">
<property name="text">
<string>AllVersions</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>FilterModsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>FilterModsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>