Commit 557c4159 authored by Jan Grulich's avatar Jan Grulich

Add default value for parent in contructors of all validator classes

parent 751f4da0
......@@ -142,7 +142,7 @@ WireGuardInterfaceWidget::WireGuardInterfaceWidget(const NetworkManager::Setting
d->keyValidator = new WireGuardKeyValidator(this);
// Create validator for listen port
d->portValidator = new QIntValidator(nullptr);
d->portValidator = new QIntValidator;
d->portValidator->setBottom(0);
d->portValidator->setTop(65535);
......@@ -153,7 +153,7 @@ WireGuardInterfaceWidget::WireGuardInterfaceWidget(const NetworkManager::Setting
d->ui.fwmarkLineEdit->setValidator(d->fwmarkValidator);
// Create a validator for the MTU field.
d->mtuValidator = new QIntValidator(nullptr);
d->mtuValidator = new QIntValidator();
d->mtuValidator->setBottom(0);
d->ui.mtuLineEdit->setValidator(d->mtuValidator);
......@@ -402,7 +402,7 @@ NMVariantMapMap WireGuardInterfaceWidget::importConnectionSettings(const QString
NMVariantMapList peers;
QVariantMap ipv4Data;
QVariantMap *currentPeer = nullptr;
WireGuardKeyValidator keyValidator(nullptr);
WireGuardKeyValidator keyValidator;
NetworkManager::Ipv4Setting ipv4Setting;
NetworkManager::Ipv6Setting ipv6Setting;
NetworkManager::WireGuardSetting wgSetting;
......@@ -588,7 +588,7 @@ NMVariantMapMap WireGuardInterfaceWidget::importConnectionSettings(const QString
havePublicKey = true;
}
} else if (key == PNM_WG_CONF_TAG_ALLOWED_IPS) {
SimpleIpListValidator validator(nullptr, SimpleIpListValidator::WithCidr, SimpleIpListValidator::Both);
SimpleIpListValidator validator(SimpleIpListValidator::WithCidr, SimpleIpListValidator::Both);
QString val = keyValue[1].trimmed();
if (QValidator::Acceptable == validator.validate(val, pos))
{
......
......@@ -49,9 +49,8 @@
#define PNM_WG_PEER_KEY_PRESHARED_KEY_FLAGS "preshared-key-flags"
#define PNM_WG_PEER_KEY_PUBLIC_KEY "public-key"
static WireGuardKeyValidator keyValidator(nullptr);
static SimpleIpListValidator allowedIPsValidator(nullptr, SimpleIpListValidator::WithCidr,
SimpleIpListValidator::Both);
static WireGuardKeyValidator keyValidator;
static SimpleIpListValidator allowedIPsValidator(SimpleIpListValidator::WithCidr, SimpleIpListValidator::Both);
class WireGuardPeerWidget::Private
{
......@@ -204,8 +203,8 @@ WireGuardPeerWidget::EndPointValid WireGuardPeerWidget::isEndpointValid(QString
// separated by '.', so "ab.cc" is valid but "a.cc" is not. The full string must also be less
// than 255 characters long.
static QRegExpValidator fqdnValidator(QRegExp(QLatin1String("(?=.{5,254}$)([a-zA-Z0-9][a-zA-Z0-9-]{1,62}\\.){1,63}[a-zA-Z]{2,63}")), nullptr);
static SimpleIpV4AddressValidator ipv4Validator(nullptr);
static SimpleIpV6AddressValidator ipv6Validator(nullptr);
static SimpleIpV4AddressValidator ipv4Validator;
static SimpleIpV6AddressValidator ipv6Validator;
int pos = 0;
bool addressValid = QValidator::Acceptable == fqdnValidator.validate(address, pos)
......
......@@ -50,9 +50,8 @@
#define PNM_WG_PEER_KEY_PRESHARED_KEY_FLAGS "preshared-key-flags"
#define PNM_WG_PEER_KEY_PUBLIC_KEY "public-key"
static WireGuardKeyValidator keyValidator(nullptr);
static SimpleIpListValidator allowedIPsValidator(nullptr, SimpleIpListValidator::WithCidr,
SimpleIpListValidator::Both);
static WireGuardKeyValidator keyValidator();
static SimpleIpListValidator allowedIPsValidator(SimpleIpListValidator::WithCidr, SimpleIpListValidator::Both);
class WireGuardTabWidget::Private
{
......
......@@ -23,9 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QStringList>
#include <QVector>
SimpleIpListValidator::SimpleIpListValidator(QObject *parent,
AddressStyle style,
AddressType type)
SimpleIpListValidator::SimpleIpListValidator(AddressStyle style, AddressType type, QObject *parent)
: QValidator(parent)
, m_ipv6Validator(nullptr)
, m_ipv4Validator(nullptr)
......@@ -38,7 +36,7 @@ SimpleIpListValidator::SimpleIpListValidator(QObject *parent,
ipv4Style = SimpleIpV4AddressValidator::AddressStyle::WithCidr;
else
ipv4Style = SimpleIpV4AddressValidator::AddressStyle::WithPort;
m_ipv4Validator = new SimpleIpV4AddressValidator(this, ipv4Style);
m_ipv4Validator = new SimpleIpV4AddressValidator(ipv4Style, this);
}
if (type == Ipv6 || type == Both) {
SimpleIpV6AddressValidator::AddressStyle ipv6Style;
......@@ -48,7 +46,7 @@ SimpleIpListValidator::SimpleIpListValidator(QObject *parent,
ipv6Style = SimpleIpV6AddressValidator::AddressStyle::WithCidr;
else
ipv6Style = SimpleIpV6AddressValidator::AddressStyle::WithPort;
m_ipv6Validator = new SimpleIpV6AddressValidator(this, ipv6Style);
m_ipv6Validator = new SimpleIpV6AddressValidator(ipv6Style, this);
}
}
......
......@@ -31,9 +31,8 @@ public:
enum AddressType {Ipv4, Ipv6, Both};
enum AddressStyle {Base, WithCidr, WithPort};
explicit SimpleIpListValidator(QObject *parent,
AddressStyle style = AddressStyle::Base,
AddressType allow = AddressType::Both);
explicit SimpleIpListValidator(AddressStyle style = AddressStyle::Base,
AddressType allow = AddressType::Both, QObject *parent = nullptr);
~SimpleIpListValidator() override;
State validate(QString &, int &) const override;
......
......@@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QStringList>
#include <QVector>
SimpleIpV4AddressValidator::SimpleIpV4AddressValidator(QObject *parent, AddressStyle style)
SimpleIpV4AddressValidator::SimpleIpV4AddressValidator(AddressStyle style, QObject *parent)
: QValidator(parent)
, m_addressStyle(style)
{
......
......@@ -28,7 +28,7 @@ class Q_DECL_EXPORT SimpleIpV4AddressValidator : public QValidator
public:
enum AddressStyle {Base, WithCidr, WithPort};
explicit SimpleIpV4AddressValidator(QObject *parent, AddressStyle style = AddressStyle::Base);
explicit SimpleIpV4AddressValidator(AddressStyle style = AddressStyle::Base, QObject *parent = nullptr);
~SimpleIpV4AddressValidator() override;
State validate(QString &, int &) const override;
......
......@@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QStringList>
#include <QVector>
SimpleIpV6AddressValidator::SimpleIpV6AddressValidator(QObject *parent, AddressStyle style)
SimpleIpV6AddressValidator::SimpleIpV6AddressValidator(AddressStyle style, QObject *parent)
: QValidator(parent)
, m_addressStyle(style)
{
......
......@@ -28,7 +28,7 @@ class Q_DECL_EXPORT SimpleIpV6AddressValidator : public QValidator
public:
enum AddressStyle {Base, WithCidr, WithPort};
explicit SimpleIpV6AddressValidator(QObject *parent, AddressStyle style = AddressStyle::Base);
explicit SimpleIpV6AddressValidator(AddressStyle style = AddressStyle::Base, QObject *parent = nullptr);
~SimpleIpV6AddressValidator() override;
State validate(QString &, int &) const override;
......
......@@ -30,7 +30,7 @@ IpV4Delegate::~IpV4Delegate() {}
QWidget * IpV4Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
{
QLineEdit *editor = new QLineEdit(parent);
editor->setValidator(new SimpleIpV4AddressValidator(editor));
editor->setValidator(new SimpleIpV4AddressValidator(SimpleIpV4AddressValidator::Base, editor));
return editor;
}
......@@ -30,7 +30,7 @@ IpV6Delegate::~IpV6Delegate() {}
QWidget * IpV6Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
{
QLineEdit *editor = new QLineEdit(parent);
editor->setValidator(new SimpleIpV6AddressValidator(editor));
editor->setValidator(new SimpleIpV6AddressValidator(SimpleIpV6AddressValidator::Base, editor));
return editor;
}
......@@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class WireGuardKeyValidator : public QValidator
{
public:
explicit WireGuardKeyValidator(QObject *parent);
explicit WireGuardKeyValidator(QObject *parent = nullptr);
~WireGuardKeyValidator() override;
QValidator::State validate(QString &, int &) const override;
......
......@@ -78,12 +78,12 @@ SshSettingWidget::SshSettingWidget(const NetworkManager::VpnSetting::Ptr &settin
connect(d->ui.le_netmask, &QLineEdit::textChanged, this, &SshSettingWidget::slotWidgetChanged);
connect(d->ui.le_remoteIp, &QLineEdit::textChanged, this, &SshSettingWidget::slotWidgetChanged);
SimpleIpV4AddressValidator *ipv4Validator = new SimpleIpV4AddressValidator(this);
SimpleIpV4AddressValidator *ipv4Validator = new SimpleIpV4AddressValidator(SimpleIpV4AddressValidator::Base, this);
d->ui.le_localIp->setValidator(ipv4Validator);
d->ui.le_remoteIp->setValidator(ipv4Validator);
d->ui.le_netmask->setValidator(ipv4Validator);
SimpleIpV6AddressValidator *ipv6Validator = new SimpleIpV6AddressValidator(this);
SimpleIpV6AddressValidator *ipv6Validator = new SimpleIpV6AddressValidator(SimpleIpV6AddressValidator::Base, this);
d->ui.le_localIpv6->setValidator(ipv6Validator);
d->ui.le_remoteIpv6->setValidator(ipv6Validator);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment