75 lines
2.0 KiB
C++
75 lines
2.0 KiB
C++
//
|
|
// Created by Krad on 2021/11/11.
|
|
//
|
|
|
|
#include "GetRouteDialog.h"
|
|
|
|
#include <QRegularExpressionValidator>
|
|
#include <QFormLayout>
|
|
#include <QLabel>
|
|
#include "components/ULineEdit.h"
|
|
|
|
#include "device/networkmanager.h"
|
|
|
|
GetRouteDialog::GetRouteDialog(QWidget* parent, Qt::WindowFlags f)
|
|
: GUIFormBaseDialog(parent, f)
|
|
, mDestination(new ULineEdit(this))
|
|
, mNetmask(new ULineEdit(this))
|
|
, mGateway(new ULineEdit(this))
|
|
, mLabelError(new QLabel(this))
|
|
{
|
|
setWindowModality(Qt::WindowModal);
|
|
QFormLayout* formLayout = new QFormLayout(mFormWidget);
|
|
formLayout->addRow(QString(tr("Destination")), mDestination);
|
|
formLayout->addRow(QString(tr("Netmask")), mNetmask);
|
|
formLayout->addRow(QString(tr("Gateway")), mGateway);
|
|
mLabelError->setObjectName("warn");
|
|
formLayout->addRow("", mLabelError);
|
|
|
|
//set ip input restrictions
|
|
QRegularExpression regex("^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)$");
|
|
QRegularExpressionValidator* validator = new QRegularExpressionValidator(regex, this);
|
|
mDestination->setValidator(validator);
|
|
mNetmask->setValidator(validator);
|
|
mGateway->setValidator(validator);
|
|
}
|
|
|
|
GetRouteDialog::~GetRouteDialog()
|
|
{
|
|
|
|
}
|
|
|
|
QStringList GetRouteDialog::getList()const
|
|
{
|
|
return QStringList() << mDestination->text() << mNetmask->text() << mGateway->text();;
|
|
}
|
|
void GetRouteDialog::setList(const QStringList& list)
|
|
{
|
|
if (!list.empty())
|
|
{
|
|
mDestination->setText(list[0]);
|
|
mNetmask->setText(list[1]);
|
|
mGateway->setText(list[2]);
|
|
}
|
|
}
|
|
|
|
bool GetRouteDialog::updateReferenceData()
|
|
{
|
|
if (!NetworkManager::validate(mDestination->text()))
|
|
{
|
|
mLabelError->setText(tr("Wrong Destination!"));
|
|
return false;
|
|
}
|
|
if (!NetworkManager::validate(mNetmask->text()))
|
|
{
|
|
mLabelError->setText(tr("Wrong Netmask!"));
|
|
return false;
|
|
}
|
|
if (!NetworkManager::validate(mGateway->text()))
|
|
{
|
|
mLabelError->setText(tr("Wrong Gateway!"));
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|