From 8f528ffcdb4ce2f27a015fe7f0867e71a444d614 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Mon, 10 Feb 2020 09:06:26 -0600 Subject: Qt 5: Small tweaks to SubnetBox * Add setSubnetCIDR, to programmatically change the value. * Add signal for when the value changes. * Ensure the proper amount of .0 octets are appended when the spinbox changes. --- ui/qt5/subnetbox.cc | 11 +++++++++++ ui/qt5/subnetbox.hh | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/ui/qt5/subnetbox.cc b/ui/qt5/subnetbox.cc index 54f1732..071cec8 100644 --- a/ui/qt5/subnetbox.cc +++ b/ui/qt5/subnetbox.cc @@ -40,10 +40,16 @@ int SubnetBox::subnetCIDR(void) const { return cidr->value(); } +void SubnetBox::setSubnetCIDR(int value) { + cidr->setValue(value); + cidrEdited(value); +} + void SubnetBox::subnetEdited(const QString &text) { int value = subnet_mask_to_cidr(text.toUtf8()); if(value > 0) { cidr->setValue(value); + emit valueChanged(value); } } @@ -60,6 +66,11 @@ void SubnetBox::cidrEdited(int value) { } snprintf(temp, 4, "%d", lastfilled); data.append(temp); + for(int i = 3; i > bytes; i--) { + data.append(".0"); + } subnet->setText(data); + + emit valueChanged(value); } diff --git a/ui/qt5/subnetbox.hh b/ui/qt5/subnetbox.hh index 9f2edbf..8104a6b 100644 --- a/ui/qt5/subnetbox.hh +++ b/ui/qt5/subnetbox.hh @@ -26,11 +26,15 @@ public: SubnetBox(QWidget *parent = nullptr); QString subnetMask() const; int subnetCIDR() const; + void setSubnetCIDR(int value); public slots: void subnetEdited(const QString &text); void cidrEdited(int value); +signals: + void valueChanged(int value); + private: QHBoxLayout *layout; QLineEdit *subnet; -- cgit v1.2.3-60-g2f50