Fixed the version combobox
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
55946c8923
commit
6883c19579
@ -39,17 +39,17 @@ class CheckComboModel : public QIdentityProxyModel {
|
||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (role == Qt::DisplayRole)
|
||||
return QIdentityProxyModel::data(index, BaseVersionList::VersionIdRole);
|
||||
return QIdentityProxyModel::data(index, Qt::DisplayRole);
|
||||
return {};
|
||||
}
|
||||
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole)
|
||||
{
|
||||
if (role == Qt::CheckStateRole) {
|
||||
auto txt = QIdentityProxyModel::data(index, BaseVersionList::VersionIdRole).toString();
|
||||
auto txt = QIdentityProxyModel::data(index, Qt::DisplayRole).toString();
|
||||
if (checked.contains(txt)) {
|
||||
checked.removeOne(txt);
|
||||
} else {
|
||||
@ -72,11 +72,10 @@ class CheckComboModel : public QIdentityProxyModel {
|
||||
|
||||
CheckComboBox::CheckComboBox(QWidget* parent) : QComboBox(parent), m_separator(",")
|
||||
{
|
||||
// read-only contents
|
||||
// QLineEdit* lineEdit = new QLineEdit(this);
|
||||
// lineEdit->setReadOnly(false);
|
||||
// setLineEdit(lineEdit);
|
||||
// lineEdit->disconnect(this);
|
||||
QLineEdit* lineEdit = new QLineEdit(this);
|
||||
lineEdit->setReadOnly(false);
|
||||
setLineEdit(lineEdit);
|
||||
lineEdit->disconnect(this);
|
||||
setInsertPolicy(QComboBox::NoInsert);
|
||||
|
||||
view()->installEventFilter(this);
|
||||
@ -150,7 +149,6 @@ bool CheckComboBox::eventFilter(QObject* receiver, QEvent* event)
|
||||
showPopup();
|
||||
return true;
|
||||
} 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();
|
||||
return (keyEvent->key() != Qt::Key_Escape);
|
||||
}
|
||||
|
@ -14,6 +14,20 @@ unique_qobject_ptr<ModFilterWidget> ModFilterWidget::create(MinecraftInstance* i
|
||||
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)
|
||||
: 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);
|
||||
|
||||
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));
|
||||
|
||||
@ -177,4 +194,6 @@ void ModFilterWidget::onHideInstalledFilterChanged()
|
||||
emit filterChanged();
|
||||
else
|
||||
emit filterUnchanged();
|
||||
}
|
||||
}
|
||||
|
||||
#include "ModFilterWidget.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user