12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #include "QtLineEditor.h"
- #include "preHeader.h"
- QtLineEditor::QtLineEditor(QWidget*parent)
- : QLineEdit(parent)
- {
- //set a slot to process the text changed
- connect(this, &QLineEdit::textChanged, this, &QtLineEditor::OnTextChanged);
- //set a slot to process the text edited
- connect(this, &QLineEdit::textChanged, this, &QtLineEditor::OnTextEdited);
- //init the target
- m_nTarget = nullptr;
- m_strTarget = nullptr;
- }
- QtLineEditor::~QtLineEditor()
- {
- }
- void QtLineEditor::init(QString strText, bool isIntOrNot, int nMax)
- {
- //set the text
- this->setText(strText);
- //set a branch to process the int or string
- if (isIntOrNot)
- {
- //set the flags
- m_bIsInt = true;
- //set the limit
- this->setMaxLength(5);
- //set the max value
- this->setValidator(new QIntValidator(-nMax, nMax, this));
- }
- else
- {
- //set the flags
- m_bIsInt = false;
- //set the limit
- this->setMaxLength(15);
- //set the max value
- this->setValidator(new QRegExpValidator(QRegExp("[0-9a-zA-Z]+$"), this));
- }
-
- }
- void QtLineEditor::SetEditTarget(int* nTarget)
- {
- if (m_bIsInt)
- {
- //init the target
- m_nTarget = nTarget;
- }
- }
- void QtLineEditor::SetEditTarget(QString* strTarget)
- {
- if (!m_bIsInt)
- {
- //init the target
- m_strTarget = strTarget;
- }
- }
- void QtLineEditor::OnTextChanged(const QString & text)
- {
- if (m_nTarget == nullptr && m_strTarget == nullptr )
- {
- return;
- }
- //set a branch to process the int or string
- if (m_bIsInt)
- {
- //set the value
- *m_nTarget = text.toInt();
- }
- else
- {
- //set the value
- *m_strTarget = text;
- }
- }
- void QtLineEditor::OnTextEdited(const QString& text)
- {
- //set a branch to process the int or string
- if (m_strTarget == nullptr)
- {
- return;
- }
- if (!m_bIsInt)
- {
-
- }
- }
|