多DNS界面优化

This commit is contained in:
zhangyuanyuan1 2022-10-14 17:40:20 +08:00
parent bd7e1dc447
commit 766f920bc8
14 changed files with 522 additions and 104 deletions

View File

@ -93,6 +93,7 @@ public:
QString strIPV4FirDns;
QString strIPV4SecDns;
QString strIPV4GateWay;
QList<QHostAddress> ipv4DnsList;
KyIpConfigType ipv6ConfigType = CONFIG_IP_DHCP;
QString strIPV6Address;
@ -100,6 +101,7 @@ public:
QString strIPV6FirDns;
QString strIPV6SecDns;
QString strIPV6GateWay;
QList<QHostAddress> ipv6DnsList;
KyEapMethodType enterpriseType;
KyEapMethodTlsInfo tlsInfo;

View File

@ -36,46 +36,48 @@ void CreatNetPage::initUI()
ipv4addressEdit = new LineEdit(this);
netMaskEdit = new LineEdit(this);
gateWayEdit = new LineEdit(this);
firstDnsEdit = new LineEdit(this);
secondDnsEdit = new LineEdit(this);
// firstDnsEdit = new LineEdit(this);
// secondDnsEdit = new LineEdit(this);
m_connNameLabel = new QLabel(this);
m_configLabel = new QLabel(this);
m_addressLabel = new QLabel(this);
m_maskLabel = new QLabel(this);
m_gateWayLabel = new QLabel(this);
m_dnsLabel = new QLabel(this);
m_secDnsLabel = new QLabel(this);
// m_dnsLabel = new QLabel(this);
// m_secDnsLabel = new QLabel(this);
// IP的正则格式限制
QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
m_dnsWidget = new MultipleDnsWidget(rx, this);
m_connNameLabel->setText(tr("Connection Name"));
m_configLabel->setText(tr("IPv4Config"));
m_addressLabel->setText(tr("Address"));
m_maskLabel->setText(tr("Netmask"));
m_gateWayLabel->setText(tr("Default Gateway"));
m_dnsLabel->setText(tr("Prefs DNS"));
m_secDnsLabel->setText(tr("Alternative DNS"));
// m_dnsLabel->setText(tr("Prefs DNS"));
// m_secDnsLabel->setText(tr("Alternative DNS"));
m_detailLayout = new QFormLayout(this);
m_detailLayout->setSpacing(24);
m_detailLayout->addRow(m_connNameLabel,connNameEdit);
m_detailLayout->addRow(m_configLabel,ipv4ConfigCombox);
m_detailLayout->addRow(m_addressLabel,ipv4addressEdit);
m_detailLayout->addRow(m_maskLabel,netMaskEdit);
m_detailLayout->addRow(m_gateWayLabel,gateWayEdit);
m_detailLayout->addRow(m_dnsLabel,firstDnsEdit);
m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit);
// m_detailLayout->addRow(m_dnsLabel,firstDnsEdit);
// m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit);
m_detailLayout->addRow(m_dnsWidget);
ipv4ConfigCombox->addItem(tr("Auto(DHCP)"), AUTO_CONFIG); //"自动(DHCP)"
ipv4ConfigCombox->addItem(tr("Manual"), MANUAL_CONFIG); //"手动"
// IP的正则格式限制
QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
ipv4addressEdit->setValidator(new QRegExpValidator(rx, this));
gateWayEdit->setValidator(new QRegExpValidator(rx, this));
netMaskEdit->setValidator(new QRegExpValidator(rx, this));
firstDnsEdit->setValidator(new QRegExpValidator(rx, this));
secondDnsEdit->setValidator(new QRegExpValidator(rx, this));
// firstDnsEdit->setValidator(new QRegExpValidator(rx, this));
// secondDnsEdit->setValidator(new QRegExpValidator(rx, this));
}
void CreatNetPage::initComponent() {
@ -90,8 +92,8 @@ void CreatNetPage::initComponent() {
connect(ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn()));
connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
// connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
// connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
}
bool CreatNetPage::checkConnectBtnIsEnabled()
@ -118,7 +120,7 @@ bool CreatNetPage::checkConnectBtnIsEnabled()
qDebug() << "create ipv4 gateway empty or invalid";
return false;
}
#if 0
if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) {
qDebug() << "create ipv4 dns sort invalid";
return false;
@ -133,6 +135,8 @@ bool CreatNetPage::checkConnectBtnIsEnabled()
qDebug() << "create ipv4 second dns invalid";
return false;
}
#endif
}
return true;
}
@ -151,15 +155,16 @@ void CreatNetPage::setLineEnabled(bool check) {
ipv4addressEdit->setEnabled(check);
netMaskEdit->setEnabled(check);
gateWayEdit->setEnabled(check);
firstDnsEdit->setEnabled(check);
secondDnsEdit->setEnabled(check);
// firstDnsEdit->setEnabled(check);
// secondDnsEdit->setEnabled(check);
m_dnsWidget->setEditEnabled(check);
if (!check) {
ipv4addressEdit->clear();
netMaskEdit->clear();
gateWayEdit->clear();
firstDnsEdit->clear();
secondDnsEdit->clear();
// firstDnsEdit->clear();
// secondDnsEdit->clear();
}
}
@ -191,13 +196,23 @@ void CreatNetPage::constructIpv4Info(KyConnectSetting &setting)
<< " gateWay " << gateWay;
QStringList dnsList;
dnsList.empty();
dnsList.clear();
#if 0
if (!firstDnsEdit->text().isEmpty()) {
dnsList << firstDnsEdit->text();
if (!secondDnsEdit->text().isEmpty()) {
dnsList << secondDnsEdit->text();
}
}
#endif
QList<QHostAddress> ipv4dnsList;
ipv4dnsList.clear();
ipv4dnsList = m_dnsWidget->getDns();
for (QHostAddress str: ipv4dnsList) {
dnsList << str.toString();
}
if (ipv4ConfigCombox->currentData() == AUTO_CONFIG) {
setting.setIpConfigType(IPADDRESS_V4, CONFIG_IP_DHCP);
} else {

View File

@ -32,6 +32,7 @@
#include <QDebug>
#include "coninfo.h"
#include "multiplednswidget.h"
class CreatNetPage : public QFrame
{
@ -46,10 +47,9 @@ private:
LineEdit *ipv4addressEdit;
LineEdit *netMaskEdit;
LineEdit *gateWayEdit;
LineEdit *firstDnsEdit;
LineEdit *secondDnsEdit;
// LineEdit *firstDnsEdit;
// LineEdit *secondDnsEdit;
private:
QFormLayout *m_detailLayout;
QVBoxLayout *mvBoxLayout;
QLabel *m_connNameLabel;
@ -57,8 +57,10 @@ private:
QLabel *m_addressLabel;
QLabel *m_maskLabel;
QLabel *m_gateWayLabel;
QLabel *m_dnsLabel;
QLabel *m_secDnsLabel;
// QLabel *m_dnsLabel;
// QLabel *m_secDnsLabel;
MultipleDnsWidget *m_dnsWidget = nullptr;
private:
void initUI();
void initComponent();

View File

@ -39,15 +39,15 @@ void Ipv4Page::initUI() {
ipv4addressEdit = new LineEdit(this);
netMaskEdit = new LineEdit(this);
gateWayEdit = new LineEdit(this);
firstDnsEdit = new LineEdit(this);
secondDnsEdit = new LineEdit(this);
// firstDnsEdit = new LineEdit(this);
// secondDnsEdit = new LineEdit(this);
m_configLabel = new QLabel(this);
m_addressLabel = new QLabel(this);
m_maskLabel = new QLabel(this);
m_gateWayLabel = new QLabel(this);
m_dnsLabel = new QLabel(this);
m_secDnsLabel = new QLabel(this);
// m_dnsLabel = new QLabel(this);
// m_secDnsLabel = new QLabel(this);
m_configEmptyLabel = new QLabel(this);
m_configEmptyLabel->setFixedHeight(LABEL_HEIGHT);
@ -64,16 +64,12 @@ void Ipv4Page::initUI() {
m_gateWayEmptyLabel = new QLabel(this);
m_gateWayEmptyLabel->setFixedHeight(LABEL_HEIGHT);
m_firstDnsEmptyLabel = new QLabel(this);
m_firstDnsEmptyLabel->setFixedHeight(LABEL_HEIGHT);
m_configLabel->setText(tr("IPv4Config"));
m_addressLabel->setText(tr("Address"));
m_maskLabel->setText(tr("Netmask"));
m_gateWayLabel->setText(tr("Default Gateway"));
m_dnsLabel->setText(tr("Prefs DNS"));
m_secDnsLabel->setText(tr("Alternative DNS"));
// m_dnsLabel->setText(tr("Prefs DNS"));
// m_secDnsLabel->setText(tr("Alternative DNS"));
m_statusLabel = new QLabel(this);
m_statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
@ -100,6 +96,10 @@ void Ipv4Page::initUI() {
maskLayout->addWidget(netMaskEdit);
maskLayout->addWidget(m_maskHintLabel);
// IP的正则格式限制
QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
m_dnsWidget = new MultipleDnsWidget(rx, this);
m_detailLayout = new QFormLayout(this);
m_detailLayout->setVerticalSpacing(0);
m_detailLayout->setContentsMargins(LAYOUT_MARGINS);
@ -109,9 +109,9 @@ void Ipv4Page::initUI() {
m_detailLayout->addRow(m_maskLabel,maskWidget);
m_detailLayout->addRow(m_gateWayLabel,gateWayEdit);
m_detailLayout->addRow(m_gateWayEmptyLabel);
m_detailLayout->addRow(m_dnsLabel,firstDnsEdit);
m_detailLayout->addRow(m_firstDnsEmptyLabel);
m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit);
// m_detailLayout->addRow(m_dnsLabel,firstDnsEdit);
// m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit);
m_detailLayout->addRow(m_dnsWidget);
ipv4ConfigCombox->addItem(tr("Auto(DHCP)")); //"自动(DHCP)"
ipv4ConfigCombox->addItem(tr("Manual")); //"手动"
@ -124,14 +124,11 @@ void Ipv4Page::initUI() {
// netMaskCombox->addItem("255.0.0.0"); //8
// IP的正则格式限制
QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
ipv4addressEdit->setValidator(new QRegExpValidator(rx, this));
gateWayEdit->setValidator(new QRegExpValidator(rx, this));
netMaskEdit->setValidator(new QRegExpValidator(rx, this));
firstDnsEdit->setValidator(new QRegExpValidator(rx, this));
secondDnsEdit->setValidator(new QRegExpValidator(rx, this));
// firstDnsEdit->setValidator(new QRegExpValidator(rx, this));
// secondDnsEdit->setValidator(new QRegExpValidator(rx, this));
initLoadingIcon();
}
@ -152,8 +149,8 @@ void Ipv4Page::initComponent() {
connect(ipv4addressEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
// connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
// connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
}
void Ipv4Page::setIpv4Config(KyIpConfigType ipv4Config)
@ -175,6 +172,12 @@ void Ipv4Page::setNetMask(const QString &netMask)
netMaskEdit->setText(netMask);
}
void Ipv4Page::setMulDns(const QList<QHostAddress> &dns)
{
m_dnsWidget->setDnsListText(dns);
}
#if 0
void Ipv4Page::setIpv4FirDns(const QString &ipv4FirDns)
{
firstDnsEdit->setText(ipv4FirDns);
@ -184,6 +187,7 @@ void Ipv4Page::setIpv4SecDns(const QString &ipv4SecDns)
{
secondDnsEdit->setText(ipv4SecDns);
}
#endif
void Ipv4Page::setGateWay(const QString &gateWay)
{
@ -213,22 +217,32 @@ bool Ipv4Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting)
isChanged = true;
}
qDebug() << "ipv4 netmask " << getNetMaskText(netMaskEdit->text());
QList<QHostAddress> ipv4dnsList;
ipv4dnsList.clear();
ipv4dnsList = m_dnsWidget->getDns();
if(info.strIPV4Address != ipv4addressEdit->text()
|| info.strIPV4NetMask != /*netMaskEdit->text()*/getNetMaskText(netMaskEdit->text())
|| info.strIPV4GateWay != gateWayEdit->text()
|| info.strIPV4FirDns != firstDnsEdit->text()
|| info.strIPV4SecDns != secondDnsEdit->text()) {
// || info.strIPV4FirDns != firstDnsEdit->text()
// || info.strIPV4SecDns != secondDnsEdit->text()
|| info.ipv4DnsList != ipv4dnsList) {
qDebug() << "ipv4 info changed";
QStringList dnsList;
dnsList.empty();
dnsList.clear();
for (QHostAddress str: ipv4dnsList) {
dnsList << str.toString();
}
#if 0
if (!firstDnsEdit->text().isEmpty()) {
dnsList << firstDnsEdit->text();
if (!secondDnsEdit->text().isEmpty()) {
dnsList << secondDnsEdit->text();
}
}
#endif
QString ipv4address =ipv4addressEdit->text();
QString netMask = getNetMaskText(netMaskEdit->text());
QString gateWay = gateWayEdit->text();
@ -261,7 +275,7 @@ bool Ipv4Page::checkConnectBtnIsEnabled()
// qDebug() << "ipv4 gateway empty or invalid";
// return false;
// }
#if 0
if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) {
qDebug() << "ipv4 dns sort invalid";
return false;
@ -276,6 +290,8 @@ bool Ipv4Page::checkConnectBtnIsEnabled()
qDebug() << "ipv4 second dns invalid";
return false;
}
#endif
}
return true;
}
@ -325,8 +341,8 @@ void Ipv4Page::setLineEnabled(bool check) {
ipv4addressEdit->clear();
netMaskEdit->clear();
gateWayEdit->clear();
firstDnsEdit->clear();
secondDnsEdit->clear();
// firstDnsEdit->clear();
// secondDnsEdit->clear();
ipv4addressEdit->setPlaceholderText(" ");
netMaskEdit->setPlaceholderText(" ");
@ -339,8 +355,9 @@ void Ipv4Page::setLineEnabled(bool check) {
ipv4addressEdit->setEnabled(check);
netMaskEdit->setEnabled(check);
gateWayEdit->setEnabled(check);
firstDnsEdit->setEnabled(check);
secondDnsEdit->setEnabled(check);
// firstDnsEdit->setEnabled(check);
// secondDnsEdit->setEnabled(check);
m_dnsWidget->setEditEnabled(check);
}
void Ipv4Page::setEnableOfSaveBtn() {

View File

@ -33,6 +33,7 @@
//#include "kylinconnectsetting.h"
#include "coninfo.h"
#include "multiplednswidget.h"
class Ipv4Page : public QFrame
{
@ -42,8 +43,9 @@ public:
void setIpv4Config(KyIpConfigType ipv4Config);
void setIpv4(const QString &ipv4);
void setNetMask(const QString &netMask);
void setIpv4FirDns(const QString &ipv4FirDns);
void setIpv4SecDns(const QString &ipv4SecDns);
// void setIpv4FirDns(const QString &ipv4FirDns);
// void setIpv4SecDns(const QString &ipv4SecDns);
void setMulDns(const QList<QHostAddress> &dns);
void setGateWay(const QString &gateWay);
bool checkIsChanged(const ConInfo info, KyConnectSetting &setting);
@ -57,8 +59,8 @@ private:
LineEdit *ipv4addressEdit;
LineEdit *netMaskEdit;
LineEdit *gateWayEdit;
LineEdit *firstDnsEdit;
LineEdit *secondDnsEdit;
// LineEdit *firstDnsEdit;
// LineEdit *secondDnsEdit;
QFormLayout *m_detailLayout;
QVBoxLayout *mvBoxLayout;
@ -66,14 +68,15 @@ private:
QLabel *m_addressLabel;
QLabel *m_maskLabel;
QLabel *m_gateWayLabel;
QLabel *m_dnsLabel;
QLabel *m_secDnsLabel;
// QLabel *m_dnsLabel;
// QLabel *m_secDnsLabel;
QLabel *m_configEmptyLabel;
QLabel *m_addressHintLabel;
QLabel *m_maskHintLabel;
QLabel *m_gateWayEmptyLabel;
QLabel *m_firstDnsEmptyLabel;
MultipleDnsWidget *m_dnsWidget = nullptr;
QLabel *m_statusLabel = nullptr;
QList<QIcon> m_loadIcons;

View File

@ -52,6 +52,12 @@ void Ipv6Page::setIpv6Perfix(const int &ipv6Perfix)
lengthEdit->setText(QString::number(ipv6Perfix));
}
void Ipv6Page::setMulDns(const QList<QHostAddress> &dns)
{
m_dnsWidget->setDnsListText(dns);
}
#if 0
void Ipv6Page::setIpv6FirDns(const QString &ipv6FirDns)
{
firstDnsEdit->setText(ipv6FirDns);
@ -61,6 +67,7 @@ void Ipv6Page::setIpv6SecDns(const QString &ipv6SecDns)
{
secondDnsEdit->setText(ipv6SecDns);
}
#endif
void Ipv6Page::setGateWay(const QString &gateWay)
{
@ -88,22 +95,31 @@ bool Ipv6Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting)
setting.setIpConfigType(IPADDRESS_V6, CONFIG_IP_MANUAL);
isChanged = true;
}
QList<QHostAddress> ipv6dnsList;
ipv6dnsList.clear();
ipv6dnsList = m_dnsWidget->getDns();
if(info.strIPV6Address != ipv6AddressEdit->text()
|| info.iIPV6Prefix != lengthEdit->text().toInt()
|| info.strIPV6GateWay != gateWayEdit->text()
|| info.strIPV6FirDns != firstDnsEdit->text()
|| info.strIPV6SecDns != secondDnsEdit->text()) {
// || info.strIPV6FirDns != firstDnsEdit->text()
// || info.strIPV6SecDns != secondDnsEdit->text()
|| info.ipv6DnsList != ipv6dnsList) {
qDebug() << "ipv6 info changed";
QStringList dnsList;
dnsList.empty();
dnsList.clear();
for (QHostAddress str: ipv6dnsList) {
dnsList << str.toString();
}
#if 0
if (!firstDnsEdit->text().isEmpty()) {
dnsList << firstDnsEdit->text();
if (!secondDnsEdit->text().isEmpty()) {
dnsList << secondDnsEdit->text();
}
}
#endif
QString ipv6address =ipv6AddressEdit->text();
QString prefix = lengthEdit->text();
QString gateWay = gateWayEdit->text();
@ -120,15 +136,15 @@ void Ipv6Page::initUI() {
ipv6AddressEdit = new LineEdit(this);
lengthEdit = new LineEdit(this);
gateWayEdit = new LineEdit(this);
firstDnsEdit = new LineEdit(this);
secondDnsEdit = new LineEdit(this);
// firstDnsEdit = new LineEdit(this);
// secondDnsEdit = new LineEdit(this);
m_configLabel = new QLabel(this);
m_addressLabel = new QLabel(this);
m_subnetLabel = new QLabel(this);
m_gateWayLabel = new QLabel(this);
m_dnsLabel = new QLabel(this);
m_secDnsLabel = new QLabel(this);
// m_dnsLabel = new QLabel(this);
// m_secDnsLabel = new QLabel(this);
m_configEmptyLabel = new QLabel(this);
m_configEmptyLabel->setFixedHeight(LABEL_HEIGHT);
@ -145,16 +161,12 @@ void Ipv6Page::initUI() {
m_subnetEmptyLabel = new QLabel(this);
m_subnetEmptyLabel->setFixedHeight(LABEL_HEIGHT);
m_firstDnsEmptyLabel = new QLabel(this);
m_firstDnsEmptyLabel->setFixedHeight(LABEL_HEIGHT);
m_configLabel->setText(tr("IPv6Config"));
m_addressLabel->setText(tr("Address"));
m_subnetLabel->setText(tr("Subnet prefix Length"));
m_gateWayLabel->setText(tr("Default Gateway"));
m_dnsLabel->setText(tr("Prefs DNS"));
m_secDnsLabel->setText(tr("Alternative DNS"));
// m_dnsLabel->setText(tr("Prefs DNS"));
// m_secDnsLabel->setText(tr("Alternative DNS"));
m_statusLabel = new QLabel(this);
m_statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
@ -181,6 +193,9 @@ void Ipv6Page::initUI() {
gateWayLayout->addWidget(gateWayEdit);
gateWayLayout->addWidget(m_gateWayHintLabel);
QRegExp ipv6_rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$");
m_dnsWidget = new MultipleDnsWidget(ipv6_rx, this);
m_detailLayout = new QFormLayout(this);
m_detailLayout->setContentsMargins(0, 0, 0, 0);
m_detailLayout->setVerticalSpacing(0);
@ -190,18 +205,17 @@ void Ipv6Page::initUI() {
m_detailLayout->addRow(m_subnetLabel,lengthEdit);
m_detailLayout->addRow(m_subnetEmptyLabel);
m_detailLayout->addRow(m_gateWayLabel,gateWayWidget);
m_detailLayout->addRow(m_dnsLabel,firstDnsEdit);
m_detailLayout->addRow(m_firstDnsEmptyLabel);
m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit);
// m_detailLayout->addRow(m_dnsLabel,firstDnsEdit);
// m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit);
m_detailLayout->addRow(m_dnsWidget);
ipv6ConfigCombox->addItem(tr("Auto(DHCP)")); //"自动(DHCP)"
ipv6ConfigCombox->addItem(tr("Manual")); //"手动"
QRegExp ipv6_rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$");
ipv6AddressEdit->setValidator(new QRegExpValidator(ipv6_rx, this));
gateWayEdit->setValidator(new QRegExpValidator(ipv6_rx, this));
firstDnsEdit->setValidator(new QRegExpValidator(ipv6_rx, this));
secondDnsEdit->setValidator(new QRegExpValidator(ipv6_rx, this));
// firstDnsEdit->setValidator(new QRegExpValidator(ipv6_rx, this));
// secondDnsEdit->setValidator(new QRegExpValidator(ipv6_rx, this));
QRegExp prefix_rx("\\b(?:(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\.){3}(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\b");
lengthEdit->setValidator(new QRegExpValidator(prefix_rx,this));
@ -225,8 +239,8 @@ void Ipv6Page::initComponent() {
connect(ipv6AddressEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(lengthEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
// connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
// connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
}
void Ipv6Page::configChanged(int index) {
@ -244,8 +258,8 @@ void Ipv6Page::setControlEnabled(bool check)
ipv6AddressEdit->clear();
lengthEdit->clear();
gateWayEdit->clear();
firstDnsEdit->clear();
secondDnsEdit->clear();
// firstDnsEdit->clear();
// secondDnsEdit->clear();
ipv6AddressEdit->setPlaceholderText(" ");
lengthEdit->setPlaceholderText(" ");
@ -259,8 +273,9 @@ void Ipv6Page::setControlEnabled(bool check)
ipv6AddressEdit->setEnabled(check);
lengthEdit->setEnabled(check);
gateWayEdit->setEnabled(check);
firstDnsEdit->setEnabled(check);
secondDnsEdit->setEnabled(check);
// firstDnsEdit->setEnabled(check);
// secondDnsEdit->setEnabled(check);
m_dnsWidget->setEditEnabled(check);
}
void Ipv6Page::setEnableOfSaveBtn()
@ -317,7 +332,7 @@ bool Ipv6Page::checkConnectBtnIsEnabled()
qDebug() << "ipv6 gateway empty or invalid";
return false;
}
#if 0
if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) {
qDebug() << "ipv6 dns sort invalid";
return false;
@ -332,6 +347,7 @@ bool Ipv6Page::checkConnectBtnIsEnabled()
qDebug() << "ipv6 second dns invalid";
return false;
}
#endif
}
return true;
}

View File

@ -33,6 +33,7 @@
//#include "kylinconnectsetting.h"
#include "coninfo.h"
#include "multiplednswidget.h"
class Ipv6Page : public QFrame
{
@ -42,8 +43,9 @@ public:
void setIpv6Config(KyIpConfigType ipv6Config);
void setIpv6(const QString &ipv4);
void setIpv6Perfix(const int &ipv6Perfix);
void setIpv6FirDns(const QString &ipv6FirDns);
void setIpv6SecDns(const QString &ipv6SecDns);
// void setIpv6FirDns(const QString &ipv6FirDns);
// void setIpv6SecDns(const QString &ipv6SecDns);
void setMulDns(const QList<QHostAddress> &dns);
void setGateWay(const QString &gateWay);
bool checkIsChanged(const ConInfo info, KyConnectSetting &setting);
@ -54,27 +56,28 @@ public:
void stopLoading();
void showIpv6AddressConflict(bool isConflict);
public:
private:
QComboBox *ipv6ConfigCombox;
LineEdit *ipv6AddressEdit;
LineEdit *lengthEdit;
LineEdit *gateWayEdit;
LineEdit *firstDnsEdit;
LineEdit *secondDnsEdit;
private:
// LineEdit *firstDnsEdit;
// LineEdit *secondDnsEdit;
QFormLayout *m_detailLayout;
QLabel *m_configLabel;
QLabel *m_addressLabel;
QLabel *m_subnetLabel;
QLabel *m_gateWayLabel;
QLabel *m_dnsLabel;
QLabel *m_secDnsLabel;
// QLabel *m_dnsLabel;
// QLabel *m_secDnsLabel;
QLabel *m_configEmptyLabel;
QLabel *m_addressHintLabel;
QLabel *m_subnetEmptyLabel;
QLabel *m_gateWayHintLabel;
QLabel *m_firstDnsEmptyLabel;
MultipleDnsWidget *m_dnsWidget = nullptr;
QLabel *m_statusLabel = nullptr;
QList<QIcon> m_loadIcons;
@ -83,6 +86,7 @@ private:
QLabel *m_iconLabel;
QLabel *m_textLabel;
private:
void initUI();
void initComponent();

View File

@ -0,0 +1,178 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "multiplednswidget.h"
#include <QApplication>
#define DNS_LISTWIDGET_HEIGHT 76
#define BUTTON_SIZE 36,36
#define ITEM_HEIGHT 36
MultipleDnsWidget::MultipleDnsWidget(const QRegExp &rx, QWidget *parent)
: m_regExp(rx),
QWidget(parent)
{
initUI();
initComponent();
}
void MultipleDnsWidget::initUI()
{
QVBoxLayout *mulDnsVLayout = new QVBoxLayout(this);
mulDnsVLayout->setContentsMargins(0, 0, 0, 0);
m_mulDnsLabel = new QLabel(this);
m_mulDnsLabel->setText(tr("DNS server:")); //DNS服务器
m_dnsListWidget = new QListWidget(this);
m_dnsListWidget->setFixedHeight(DNS_LISTWIDGET_HEIGHT);
m_dnsListWidget->setBackgroundRole(QPalette::Base);
m_dnsListWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus);
m_dnsListWidget->setFrameShape(QFrame::Shape::StyledPanel);
m_dnsListWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
setDnsListWidgetStyle();
m_addDnsBtn = new QPushButton(this);
m_addDnsBtn->setFixedSize(BUTTON_SIZE);
m_addDnsBtn->setProperty("useButtonPalette", true);
m_addDnsBtn->setIcon(QIcon::fromTheme("list-add-symbolic"));
m_removeDnsBtn = new QPushButton(this);
m_removeDnsBtn->setFixedSize(BUTTON_SIZE);
m_removeDnsBtn->setProperty("useButtonPalette", true);
m_removeDnsBtn->setIcon(QIcon::fromTheme("list-remove-symbolic"));
m_removeDnsBtn->setEnabled(false);
QHBoxLayout *btnHLayout = new QHBoxLayout();
btnHLayout->setContentsMargins(0, 0, 0, 0);
btnHLayout->setSpacing(1);
btnHLayout->setAlignment(Qt::AlignLeft);
btnHLayout->addWidget(m_addDnsBtn);
btnHLayout->addWidget(m_removeDnsBtn);
mulDnsVLayout->addWidget(m_mulDnsLabel, Qt::AlignLeft);
mulDnsVLayout->addWidget(m_dnsListWidget);
mulDnsVLayout->addLayout(btnHLayout);
}
void MultipleDnsWidget::initComponent()
{
connect(qApp, &QApplication::paletteChanged, this, &MultipleDnsWidget::setDnsListWidgetStyle);
connect(m_addDnsBtn, &QPushButton::clicked, this, &MultipleDnsWidget::onAddBtnClicked);
connect(m_removeDnsBtn, &QPushButton::clicked, this, &MultipleDnsWidget::onRemoveBtnClicked);
connect(m_dnsListWidget, &QListWidget::itemClicked, this, [=]() {
if (m_dnsListWidget->count() < 1) {
m_removeDnsBtn->setEnabled(false);
} else {
m_removeDnsBtn->setEnabled(true);
}
});
}
void MultipleDnsWidget::setEditEnabled(bool state)
{
m_addDnsBtn->setEnabled(state);
if (!state) {
m_dnsListWidget->clear();
}
}
QList<QHostAddress> MultipleDnsWidget::getDns() const
{
QStringList dnsList;
dnsList.clear();
QList<QHostAddress> ipv4dnsList;
ipv4dnsList.clear();
int row = 0;
QString aDns;
while (m_dnsListWidget->count() > row) {
aDns = m_dnsListWidget->item(row)->text();
if (!dnsList.contains(aDns)) {
dnsList << aDns;
ipv4dnsList << QHostAddress(aDns);
}
row ++;
}
return ipv4dnsList;
}
void MultipleDnsWidget::setDnsListText(const QList<QHostAddress> &dns)
{
m_dnsListWidget->clear();
for (QHostAddress str: dns) {
QListWidgetItem *dnsListWidgetItem = new QListWidgetItem(m_dnsListWidget);
dnsListWidgetItem->setSizeHint(QSize(0,ITEM_HEIGHT));
dnsListWidgetItem->setText(str.toString());
}
}
void MultipleDnsWidget::AddOneDnsItem(QListWidget *listWidget)
{
QListWidgetItem *dnsListWidgetItem = new QListWidgetItem(listWidget);
dnsListWidgetItem->setSizeHint(QSize(0,ITEM_HEIGHT));
dnsListWidgetItem->setFlags(dnsListWidgetItem->flags() | Qt::ItemIsEditable);
listWidget->addItem(dnsListWidgetItem);
listWidget->setCurrentItem(dnsListWidgetItem);
ListItemEdit *dnsListItemEdit = new ListItemEdit(m_regExp);
listWidget->setItemDelegateForRow(listWidget->currentIndex().row() , dnsListItemEdit);
listWidget->editItem(dnsListWidgetItem);
}
void MultipleDnsWidget::RemoveOneDnsItem(QListWidgetItem *aItem, QListWidget *listWidget)
{
if (aItem) {
listWidget->removeItemWidget(aItem);
delete aItem;
}
}
void MultipleDnsWidget::setDnsListWidgetStyle()
{
QPalette mpal(m_dnsListWidget->palette());
mpal.setColor(QPalette::Base, qApp->palette().base().color());
mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color());
m_dnsListWidget->setAlternatingRowColors(true);
m_dnsListWidget->setPalette(mpal);
}
void MultipleDnsWidget::onAddBtnClicked()
{
//避免重复添加空白项
if (m_dnsListWidget->currentItem()) {
if (m_dnsListWidget->currentItem()->text().isEmpty()) {
m_dnsListWidget->removeItemWidget(m_dnsListWidget->currentItem());
delete m_dnsListWidget->currentItem();
}
}
AddOneDnsItem(m_dnsListWidget);
m_removeDnsBtn->setEnabled(true);
}
void MultipleDnsWidget::onRemoveBtnClicked()
{
QListWidgetItem *aItem = m_dnsListWidget->currentItem();
if (!aItem) {
return;
}
RemoveOneDnsItem(aItem, m_dnsListWidget);
if (m_dnsListWidget->count()< 1) {
m_removeDnsBtn->setEnabled(false);
}
}

View File

@ -0,0 +1,66 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef MULTIPLEDNSWIDGET_H
#define MULTIPLEDNSWIDGET_H
#include <QWidget>
#include <QLabel>
#include <QLayout>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QAbstractItemView>
#include <QString>
#include <QList>
#include <QHostAddress>
#include <QDebug>
#include "listitemedit.h"
class MultipleDnsWidget: public QWidget
{
Q_OBJECT
public:
MultipleDnsWidget(const QRegExp &rx, QWidget *parent = nullptr);
~MultipleDnsWidget() = default;
void setEditEnabled(bool state);
QList<QHostAddress> getDns() const;
void setDnsListText(const QList<QHostAddress> &dns);
private:
void initUI();
void initComponent();
void AddOneDnsItem(QListWidget *listWidget);
void RemoveOneDnsItem(QListWidgetItem *aItem, QListWidget *listWidget);
QLabel *m_mulDnsLabel;
QListWidget *m_dnsListWidget = nullptr;
QPushButton *m_addDnsBtn;
QPushButton *m_removeDnsBtn;
QRegExp m_regExp;
private Q_SLOTS:
void setDnsListWidgetStyle();
void onAddBtnClicked();
void onRemoveBtnClicked();
};
#endif // MULTIPLEDNSWIDGET_H

View File

@ -495,8 +495,9 @@ void NetDetail::pagePadding(QString netName, bool isWlan)
ipv4Page->setIpv4Config(m_info.ipv4ConfigType);
ipv4Page->setIpv4(m_info.strIPV4Address);
ipv4Page->setNetMask(m_info.strIPV4NetMask);
ipv4Page->setIpv4FirDns(m_info.strIPV4FirDns);
ipv4Page->setIpv4SecDns(m_info.strIPV4SecDns);
// ipv4Page->setIpv4FirDns(m_info.strIPV4FirDns);
// ipv4Page->setIpv4SecDns(m_info.strIPV4SecDns);
ipv4Page->setMulDns(m_info.ipv4DnsList);
ipv4Page->setGateWay(m_info.strIPV4GateWay);
} else {
ipv4Page->setIpv4Config(m_info.ipv4ConfigType);
@ -507,8 +508,9 @@ void NetDetail::pagePadding(QString netName, bool isWlan)
ipv6Page->setIpv6Config(m_info.ipv6ConfigType);
ipv6Page->setIpv6(m_info.strIPV6Address);
ipv6Page->setIpv6Perfix(m_info.iIPV6Prefix);
ipv6Page->setIpv6FirDns(m_info.strIPV6FirDns);
ipv6Page->setIpv6SecDns(m_info.strIPV6SecDns);
// ipv6Page->setIpv6FirDns(m_info.strIPV6FirDns);
// ipv6Page->setIpv6SecDns(m_info.strIPV6SecDns);
ipv6Page->setMulDns(m_info.ipv6DnsList);
ipv6Page->setGateWay(m_info.strIPV6GateWay);
} else {
ipv6Page->setIpv6Config(m_info.ipv6ConfigType);
@ -665,12 +667,16 @@ void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived)
conInfo.strIPV4NetMask = connetSetting.m_ipv4Address.at(0).netmask().toString();
conInfo.strIPV4GateWay = connetSetting.m_ipv4Address.at(0).gateway().toString();
}
#if 0
if (connetSetting.m_ipv4Dns.size() == 1) {
conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString();
} else if (connetSetting.m_ipv4Dns.size() > 1) {
conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString();
conInfo.strIPV4SecDns = connetSetting.m_ipv4Dns.at(1).toString();
}
#endif
conInfo.ipv4DnsList = connetSetting.m_ipv4Dns;
}
if (connetSetting.m_ipv6ConfigIpType == CONFIG_IP_MANUAL) {
@ -679,13 +685,16 @@ void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived)
conInfo.iIPV6Prefix = ipv6Page->getPerfixLength(connetSetting.m_ipv6Address.at(0).netmask().toString());
conInfo.strIPV6GateWay = connetSetting.m_ipv6Address.at(0).gateway().toString();
}
#if 0
if (connetSetting.m_ipv6Dns.size() == 1) {
conInfo.strIPV6FirDns = connetSetting.m_ipv6Dns.at(0).toString();
} else if (connetSetting.m_ipv4Dns.size() > 1) {
conInfo.strIPV6FirDns = connetSetting.m_ipv6Dns.at(0).toString();
conInfo.strIPV6SecDns = connetSetting.m_ipv6Dns.at(1).toString();
}
#endif
conInfo.ipv6DnsList = connetSetting.m_ipv6Dns;
}
if (!bActived) {

View File

@ -10,6 +10,7 @@ HEADERS += \
$$PWD/ipv4page.h \
$$PWD/ipv6page.h \
$$PWD/joinhiddenwifipage.h \
$$PWD/multiplednswidget.h \
$$PWD/netdetail.h \
$$PWD/securitypage.h
@ -22,5 +23,6 @@ SOURCES += \
$$PWD/ipv4page.cpp \
$$PWD/ipv6page.cpp \
$$PWD/joinhiddenwifipage.cpp \
$$PWD/multiplednswidget.cpp \
$$PWD/netdetail.cpp \
$$PWD/securitypage.cpp

View File

@ -0,0 +1,54 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "listitemedit.h"
ListItemEdit::ListItemEdit(const QRegExp &rx, QObject *parent)
: m_regExp(rx),
QStyledItemDelegate(parent)
{
}
QWidget *ListItemEdit::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QLineEdit *editor = new QLineEdit(parent);
editor->setValidator(new QRegExpValidator(m_regExp, parent));
return editor;
}
void ListItemEdit::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QLineEdit *lineEdit = static_cast <QLineEdit*>(editor);
QString text = index.model()->data(index, Qt::EditRole).toString();
lineEdit->setText(text);
}
void ListItemEdit::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QLineEdit *lineEdit = static_cast <QLineEdit*>(editor);
QString text = lineEdit->text();
model->setData(index, text, Qt::EditRole);
}
void ListItemEdit::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}

View File

@ -0,0 +1,48 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef LISTITEMEDIT_H
#define LISTITEMEDIT_H
#include <QWidget>
#include <QStyledItemDelegate>
#include <QLineEdit>
class ListItemEdit: public QStyledItemDelegate
{
Q_OBJECT
public:
ListItemEdit(const QRegExp &rx, QObject *parent = nullptr);
~ListItemEdit() = default;
//创建一个控件
virtual QWidget *createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
//将数据设置到控件中
virtual void setEditorData (QWidget *editor, const QModelIndex &index) const;
//将控件中的数据更新到对应的model中
virtual void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
//更新控件位置
void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
private:
QRegExp m_regExp;
};
#endif // LISTITEMEDIT_H

View File

@ -3,6 +3,7 @@ INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/divider.h \
$$PWD/infobutton.h \
$$PWD/listitemedit.h \
$$PWD/loadingdiv.h \
$$PWD/radioitembutton.h \
$$PWD/switchbutton.h \
@ -12,6 +13,7 @@ HEADERS += \
SOURCES += \
$$PWD/divider.cpp \
$$PWD/infobutton.cpp \
$$PWD/listitemedit.cpp \
$$PWD/loadingdiv.cpp \
$$PWD/radioitembutton.cpp \
$$PWD/switchbutton.cpp \