Fixed the version combobox

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-10-20 00:44:36 +03:00
parent 55946c8923
commit 6883c19579
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
2 changed files with 28 additions and 11 deletions

View File

@ -39,17 +39,17 @@ class CheckComboModel : public QIdentityProxyModel {
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const
{ {
if (role == Qt::CheckStateRole) { if (role == Qt::CheckStateRole) {
auto txt = QIdentityProxyModel::data(index, BaseVersionList::VersionIdRole).toString(); auto txt = QIdentityProxyModel::data(index, Qt::DisplayRole).toString();
return checked.contains(txt) ? Qt::Checked : Qt::Unchecked; return checked.contains(txt) ? Qt::Checked : Qt::Unchecked;
} }
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
return QIdentityProxyModel::data(index, BaseVersionList::VersionIdRole); return QIdentityProxyModel::data(index, Qt::DisplayRole);
return {}; return {};
} }
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole)
{ {
if (role == Qt::CheckStateRole) { if (role == Qt::CheckStateRole) {
auto txt = QIdentityProxyModel::data(index, BaseVersionList::VersionIdRole).toString(); auto txt = QIdentityProxyModel::data(index, Qt::DisplayRole).toString();
if (checked.contains(txt)) { if (checked.contains(txt)) {
checked.removeOne(txt); checked.removeOne(txt);
} else { } else {
@ -72,11 +72,10 @@ class CheckComboModel : public QIdentityProxyModel {
CheckComboBox::CheckComboBox(QWidget* parent) : QComboBox(parent), m_separator(",") CheckComboBox::CheckComboBox(QWidget* parent) : QComboBox(parent), m_separator(",")
{ {
// read-only contents QLineEdit* lineEdit = new QLineEdit(this);
// QLineEdit* lineEdit = new QLineEdit(this); lineEdit->setReadOnly(false);
// lineEdit->setReadOnly(false); setLineEdit(lineEdit);
// setLineEdit(lineEdit); lineEdit->disconnect(this);
// lineEdit->disconnect(this);
setInsertPolicy(QComboBox::NoInsert); setInsertPolicy(QComboBox::NoInsert);
view()->installEventFilter(this); view()->installEventFilter(this);
@ -150,7 +149,6 @@ bool CheckComboBox::eventFilter(QObject* receiver, QEvent* event)
showPopup(); showPopup();
return true; return true;
} else if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Escape) { } else if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Escape) {
// it is important to call QComboBox implementation
QComboBox::hidePopup(); QComboBox::hidePopup();
return (keyEvent->key() != Qt::Key_Escape); return (keyEvent->key() != Qt::Key_Escape);
} }

View File

@ -14,6 +14,20 @@ unique_qobject_ptr<ModFilterWidget> ModFilterWidget::create(MinecraftInstance* i
return unique_qobject_ptr<ModFilterWidget>(new ModFilterWidget(instance, parent)); return unique_qobject_ptr<ModFilterWidget>(new ModFilterWidget(instance, parent));
} }
class VersionBasicModel : public QIdentityProxyModel {
Q_OBJECT
public:
explicit VersionBasicModel(QObject* parent = nullptr) : QIdentityProxyModel(parent) {}
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override
{
if (role == Qt::DisplayRole)
return QIdentityProxyModel::data(index, BaseVersionList::VersionIdRole);
return {};
}
};
ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, QWidget* parent) ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, QWidget* parent)
: QTabWidget(parent), ui(new Ui::ModFilterWidget), m_instance(instance), m_filter(new Filter()) : QTabWidget(parent), ui(new Ui::ModFilterWidget), m_instance(instance), m_filter(new Filter())
{ {
@ -21,7 +35,10 @@ ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, QWidget* parent)
m_versions_proxy = new VersionProxyModel(this); m_versions_proxy = new VersionProxyModel(this);
ui->versionsCb->setModel(m_versions_proxy); auto proxy = new VersionBasicModel(this);
proxy->setSourceModel(m_versions_proxy);
ui->versionsCb->setModel(proxy);
ui->versionsCb->setSeparator("| ");
m_versions_proxy->setFilter(BaseVersionList::TypeRole, new RegexpFilter("(release)", false)); m_versions_proxy->setFilter(BaseVersionList::TypeRole, new RegexpFilter("(release)", false));
@ -177,4 +194,6 @@ void ModFilterWidget::onHideInstalledFilterChanged()
emit filterChanged(); emit filterChanged();
else else
emit filterUnchanged(); emit filterUnchanged();
} }
#include "ModFilterWidget.moc"