You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AppFlow/CFDStruct/CUIProperty/CUIComponentILineEdit.cpp

143 lines
4.4 KiB
C++

#include "CUIComponentILineEdit.h"
3 weeks ago
#include <CUIConfig.h>
#include <CUIPropertyWidget.h>
#include <QDebug>
#include <QDoubleValidator>
#include <QHBoxLayout>
#include <QIntValidator>
#include <QLabel>
3 weeks ago
/**
* @brief CUIComponentLineEdit::CUIComponentLineEdit
3 weeks ago
* @param conf
* @param parent
*/
CUIComponentLineEdit::CUIComponentLineEdit(CUIConfig *conf,
QVector<CUIPropertyWidget *> &subCUI,
QWidget *parent)
: CUIComponentBaseWidget(parent), CUIComponentBase() {
this->m_conf = conf;
this->initSetting();
this->initUI(subCUI);
3 weeks ago
}
/**
* @brief CUIComponentLineEdit::getLabelWidth label
3 weeks ago
* @return label
*/
qint32 CUIComponentLineEdit::getLabelWidth() {
return m_label->minimumSizeHint().width();
3 weeks ago
}
/**
* @brief CUIComponentLineEdit::setLabelWidth label
3 weeks ago
* @param width
*/
void CUIComponentLineEdit::setLabelWidth(qint32 width) {
m_label->setMinimumWidth(width);
3 weeks ago
}
/**
* @brief CUIComponentLineEdit::initUI
3 weeks ago
*/
void CUIComponentLineEdit::initUI(QVector<CUIPropertyWidget *> &subCUI) {
m_layout = new QHBoxLayout();
m_label = new QLabel(m_conf->getPropertyValue("name"));
m_label->setFixedWidth(m_labelLength);
m_lineEdit = new QLineEdit(this->getValueString());
m_layout->addWidget(m_label);
m_layout->addWidget(m_lineEdit);
// m_dataType = static_cast<CUI_DATA_TYPE>(this->m_conf->getPropertyOriginValue("data_type").toInt());
this->setLayout(m_layout);
// 设置格式校验
this->setValidator();
this->setInputTips();
connect(m_lineEdit, &QLineEdit::textEdited, this,
&CUIComponentLineEdit::onTextChanged);
3 weeks ago
}
void CUIComponentLineEdit::setValidator() {
qDebug() << m_dataType;
switch ((int)m_dataType) {
case CUI_DATA_TYPE_DOUBLE: {
qDebug() << m_rangeMin.toInt() << ' ' << m_rangeMax.toInt();
m_lineEdit->setValidator(new QDoubleValidator(m_rangeMin.toDouble(),
m_rangeMax.toDouble(), 10));
break;
}
case CUI_DATA_TYPE_INT: {
qDebug() << m_rangeMin.toInt() << ' ' << m_rangeMax.toInt();
m_lineEdit->setValidator(
new QIntValidator(m_rangeMin.toInt(), m_rangeMax.toInt()));
break;
}
3 weeks ago
}
}
/**
* @brief CUIComponentLineEdit::showMsg
3 weeks ago
*/
void CUIComponentLineEdit::setInputTips() {
3 weeks ago
QString msg = "";
if (m_checkRange) {
msg += m_inclusiveMin ? "[" : "(";
msg += this->getRangeMinString() + "," + this->getRangeMaxString();
msg += m_inclusiveMax ? "]" : ")";
3 weeks ago
}
if (m_required) {
msg += "\t" + tr("(required)");
3 weeks ago
}
m_lineEdit->setPlaceholderText(msg);
3 weeks ago
}
/**
* @brief CUIComponentLineEdit::checkRange
3 weeks ago
*/
void CUIComponentLineEdit::showRangeError() {
if (m_checkRange) {
QPalette palette = m_lineEdit->palette();
if (this->inRange(this->getQVFrom(m_lineEdit->text()))) {
3 weeks ago
palette.setColor(QPalette::Text, Qt::black);
} else {
3 weeks ago
palette.setColor(QPalette::Text, Qt::red);
}
m_lineEdit->setPalette(palette);
3 weeks ago
}
}
/**
* @brief CUIComponentLineEdit::onTextChanged
3 weeks ago
*
* ,LineEdit
*
*
* @param text
*/
void CUIComponentLineEdit::onTextChanged(const QString &text) {
this->showRangeError();
// 如果在范围内,
if (this->inRange(m_lineEdit->text())) {
// switch (m_dataType) {
// case CUI_DATA_TYPE_DOUBLE: {
// m_value = qvariant_cast<double>(m_lineEdit->text().toDouble());
// break;
// }
// case CUI_DATA_TYPE_INT: {
// // qDebug()<< qvariant_cast<int>(m_lineEdit->text().toInt());
// m_value = qvariant_cast<int>(m_lineEdit->text().toInt());
// break;
// }
// case CUI_DATA_TYPE_STRING: {
// m_value = m_lineEdit->text();
// break;
// }
// }
m_value = this->getQVFrom(m_lineEdit->text());
this->setValueToOrigin();
qDebug() << "setValueToOrigin LineEidt" << m_value;
}
3 weeks ago
}