Fix SSL mode combobox did not work properly

This commit is contained in:
Eelke Klein 2026-10-26 14:47:19 +01:00
parent 04f525e2e9
commit 0dcee5f76c
No known key found for this signature in database
6 changed files with 228 additions and 34 deletions

View file

@ -1,12 +1,20 @@
#include "SslModeModel.h"
#include <QStringList>
namespace {
const QStringList sslModes = {QString(), "disable", "allow", "prefer", "require", "verify-ca", "verify-full"};
}
SslModeModel::SslModeModel(QObject *parent)
: QAbstractListModel(parent)
{}
int SslModeModel::rowCount(const QModelIndex &) const
int SslModeModel::rowCount(const QModelIndex &parent) const
{
return 6;
return parent.isValid() ? 0 : static_cast<int>(sslModes.size());
}
int SslModeModel::columnCount(const QModelIndex &) const
@ -16,49 +24,43 @@ int SslModeModel::columnCount(const QModelIndex &) const
QVariant SslModeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.model() != this || index.row() < 0 || index.row() >= rowCount()
|| index.column() < 0 || index.column() >= ColCount)
return {};
if (index.column() == Name) {
const auto &mode = sslModes.at(index.row());
if (role == Qt::UserRole)
return mode;
if (role == Qt::DisplayRole || role == Qt::EditRole)
return index.row() == 0 ? tr("Default") : mode;
return {};
}
QVariant v;
if (role == Qt::DisplayRole) {
switch (index.column()) {
case Name:
switch(index.row()) {
case 0:
v = tr("disable");
break;
case 1:
v = tr("allow");
break;
case 2:
v = tr("prefer");
break;
case 3:
v = tr("require");
break;
case 4:
v = tr("verify_ca");
break;
case 5:
v = tr("verify_full");
break;
}
break;
case Description:
switch(index.row()) {
case 0:
v = tr("try a non encrypted connection only");
v = tr("use the PostgreSQL default SSL mode");
break;
case 1:
v = tr("try no encryption first then try encrypted");
v = tr("try a non encrypted connection only");
break;
case 2:
v = tr("try encrypted first then not encrypted");
v = tr("try no encryption first then try encrypted");
break;
case 3:
v = tr("require an encrypted connection");
v = tr("try encrypted first then not encrypted");
break;
case 4:
v = tr("verify encryption certificate has a valid signature");
v = tr("require an encrypted connection");
break;
case 5:
v = tr("verify encryption certificate has a valid signature");
break;
case 6:
v = tr("verify encryption certificate has a valid signature and matches the host");
break;
}