refactoring qad widgets part 2

c++ cast, nullptr, forward declaration, agregate ui, connect to member functions, order and clear includes
This commit is contained in:
2022-12-12 10:18:34 +03:00
parent 728c132f2b
commit 4497123421
23 changed files with 837 additions and 500 deletions

View File

@@ -1,4 +1,10 @@
#include "qipedit.h"
#include "qalgorithms.h"
#include <QLabel>
#include <QLineEdit>
#include <QBoxLayout>
#include <QIntValidator>
QIPEdit::QIPEdit(QWidget * parent, const QString & ip): QWidget(parent) {
layout = new QBoxLayout(QBoxLayout::LeftToRight, this);
@@ -19,32 +25,20 @@ QIPEdit::QIPEdit(QWidget * parent, const QString & ip): QWidget(parent) {
layout->addWidget(dots.back());
}
}
//for (int i = 0; i < 3; i++) edits[i]->setTabOrder(edits[i+1], edits[i]);
connect(edits[0], SIGNAL(returnPressed()), this, SLOT(returnPressed0()));
connect(edits[1], SIGNAL(returnPressed()), this, SLOT(returnPressed1()));
connect(edits[2], SIGNAL(returnPressed()), this, SLOT(returnPressed2()));
connect(edits[3], SIGNAL(returnPressed()), this, SLOT(returnPressed3()));
connect(edits[0], SIGNAL(textChanged(const QString & )), this, SLOT(textChanged0(const QString & )));
connect(edits[1], SIGNAL(textChanged(const QString & )), this, SLOT(textChanged1(const QString & )));
connect(edits[2], SIGNAL(textChanged(const QString & )), this, SLOT(textChanged2(const QString & )));
connect(edits[3], SIGNAL(textChanged(const QString & )), this, SLOT(textChanged3(const QString & )));
connect(edits[0], &QLineEdit::returnPressed, this, &QIPEdit::returnPressed0);
connect(edits[1], &QLineEdit::returnPressed, this, &QIPEdit::returnPressed1);
connect(edits[2], &QLineEdit::returnPressed, this, &QIPEdit::returnPressed2);
connect(edits[3], &QLineEdit::returnPressed, this, &QIPEdit::returnPressed3);
connect(edits[0], &QLineEdit::textChanged, this, &QIPEdit::textChanged0);
connect(edits[1], &QLineEdit::textChanged, this, &QIPEdit::textChanged1);
connect(edits[2], &QLineEdit::textChanged, this, &QIPEdit::textChanged2);
connect(edits[3], &QLineEdit::textChanged, this, &QIPEdit::textChanged3);
setLayout(layout);
setIP(ip);
cind = 0;
}
QIPEdit::~QIPEdit() {
foreach (QLineEdit * i, edits)
delete i;
foreach (QLabel * i, dots)
delete i;
edits.clear();
dots.clear();
delete layout;
}
void QIPEdit::setIP(const QString & text) {
QString s, str = text;
s = str.left(str.indexOf('.'));
@@ -80,3 +74,11 @@ void QIPEdit::returnPress(int index) {
edits[index + 1]->setSelection(0, 3);
}
}
inline void QIPEdit::textChange(int index, const QString &text) {
if (text.length() == 3 && isVisible()) {
returnPress(index);
}
emit valueChanged(IP());
}