2025-04-03 18:33:10 +08:00
|
|
|
|
#include "propertyContentDlg.h"
|
|
|
|
|
|
#include <QScrollArea>
|
|
|
|
|
|
#include <QFormLayout>
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
#include <QSpinBox>
|
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
|
#include <QDateEdit>
|
|
|
|
|
|
|
|
|
|
|
|
PropertyContentDlg::PropertyContentDlg(QWidget *parent)
|
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
|
,_layout(nullptr)
|
|
|
|
|
|
{
|
2025-04-09 16:20:34 +08:00
|
|
|
|
setWindowFlags(Qt::Widget);
|
|
|
|
|
|
//this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
2025-04-03 18:33:10 +08:00
|
|
|
|
_layout = new QVBoxLayout(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PropertyContentDlg::~PropertyContentDlg()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PropertyContentDlg::createGroupView(groupStateInfo infos)
|
|
|
|
|
|
{
|
|
|
|
|
|
QScrollArea* scrollArea = new QScrollArea(this);
|
|
|
|
|
|
QWidget* content = new QWidget();
|
2025-04-09 16:20:34 +08:00
|
|
|
|
QFormLayout* formLayout = createFormLayout(content);
|
2025-04-03 18:33:10 +08:00
|
|
|
|
|
|
|
|
|
|
// 动态生成字段
|
|
|
|
|
|
for(auto& info:infos.info) {
|
2025-04-09 16:20:34 +08:00
|
|
|
|
QLabel* label = new QLabel(info.name,this);
|
2025-04-03 18:33:10 +08:00
|
|
|
|
QWidget* editor = createEditor(info);
|
|
|
|
|
|
formLayout->addRow(label, editor);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
scrollArea->setWidget(content);
|
|
|
|
|
|
scrollArea->setWidgetResizable(true);
|
|
|
|
|
|
_layout->addWidget(scrollArea);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget* PropertyContentDlg::createEditor(propertyStateInfo pro)
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget* pWidget = nullptr;
|
|
|
|
|
|
if(pro.type.contains("SMALLINT"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QSpinBox* spin = new QSpinBox(this);
|
|
|
|
|
|
spin->setRange(-32768, 32767);
|
|
|
|
|
|
pWidget = spin;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("INTEGER"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QSpinBox* spin = new QSpinBox(this);
|
|
|
|
|
|
pWidget = spin;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("BIGINT"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit *lineEdit = new QLineEdit(this);
|
|
|
|
|
|
QRegularExpression regExp("^[+-]?(0|[1-9][0-9]{0,18})$");
|
|
|
|
|
|
QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this);
|
|
|
|
|
|
lineEdit->setValidator(validator);
|
|
|
|
|
|
pWidget = lineEdit;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("REAL"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QDoubleSpinBox* dbSpin = new QDoubleSpinBox(this);
|
|
|
|
|
|
dbSpin->setDecimals(6);
|
|
|
|
|
|
pWidget = dbSpin;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("DOUBLE PRECISION"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QDoubleSpinBox* dbSpin = new QDoubleSpinBox(this);
|
|
|
|
|
|
dbSpin->setDecimals(15);
|
|
|
|
|
|
pWidget = dbSpin;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("NUMERIC") || pro.type.contains("DECIMAL"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit *lineEdit = new QLineEdit(this);
|
|
|
|
|
|
|
|
|
|
|
|
// 正则表达式:支持正负号、整数/小数、科学计数法
|
|
|
|
|
|
QRegularExpression regExp(
|
|
|
|
|
|
"^[+-]?" // 可选正负号
|
|
|
|
|
|
"(?:0|[1-9]\\d*)(?:\\.\\d+)?" // 整数部分(避免前导零)和小数部分
|
|
|
|
|
|
"(?:[eE][+-]?\\d+)?" // 科学计数法(如e5, E-3)
|
|
|
|
|
|
);
|
|
|
|
|
|
QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this);
|
|
|
|
|
|
lineEdit->setValidator(validator);
|
|
|
|
|
|
pWidget = lineEdit;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("SERIAL") || pro.type.contains("BIGSERIAL"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLabel *label = new QLabel(this);
|
|
|
|
|
|
pWidget = label;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("CHAR") || pro.type.contains("VARCHAR"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit *lineEdit = new QLineEdit(this);
|
|
|
|
|
|
lineEdit->setMaxLength(pro.lengthPrecision);
|
|
|
|
|
|
pWidget = lineEdit;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("TEXT"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit *lineEdit = new QLineEdit(this);
|
|
|
|
|
|
pWidget = lineEdit;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("BYTEA"))
|
|
|
|
|
|
{
|
|
|
|
|
|
//todo:二进制文件上传
|
|
|
|
|
|
QLabel *label = new QLabel(this);
|
|
|
|
|
|
pWidget = label;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("DATE"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QDateEdit* dateEdit = new QDateEdit(this);
|
|
|
|
|
|
dateEdit->setDisplayFormat("yyyy-MM-dd");
|
|
|
|
|
|
pWidget = dateEdit;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("TIME"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QTimeEdit* timeEdit = new QTimeEdit(this);
|
|
|
|
|
|
timeEdit->setDisplayFormat("HH:mm:ss");
|
|
|
|
|
|
pWidget = timeEdit;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("TIMESTAMP"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QDateTimeEdit* dateTimeEidt = new QDateTimeEdit(this);
|
|
|
|
|
|
dateTimeEidt->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
pWidget = dateTimeEidt;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("UUID"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit *lineEdit = new QLineEdit(this);
|
|
|
|
|
|
QRegularExpression regExp("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
|
|
|
|
|
|
QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this);
|
|
|
|
|
|
lineEdit->setValidator(validator);
|
|
|
|
|
|
pWidget = lineEdit;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.type.contains("JSON") || pro.type.contains("JSONB"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit *lineEdit = new QLineEdit(this);
|
|
|
|
|
|
pWidget = lineEdit;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(pWidget)
|
|
|
|
|
|
{
|
|
|
|
|
|
pWidget->setProperty("name",pro.name);
|
|
|
|
|
|
propertyContentInfo info;
|
|
|
|
|
|
info.proName = pro.name;
|
|
|
|
|
|
info.proType = pro.type;
|
|
|
|
|
|
info.proEditer = pWidget;
|
|
|
|
|
|
_mapPro.insert(pro.name,info);
|
|
|
|
|
|
}
|
|
|
|
|
|
return pWidget;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QMap<QString,propertyStateInfo> PropertyContentDlg::getPropertyValue() const
|
|
|
|
|
|
{
|
|
|
|
|
|
QMap<QString,propertyStateInfo> map;
|
|
|
|
|
|
|
|
|
|
|
|
for(auto &pro:_mapPro)
|
|
|
|
|
|
{
|
|
|
|
|
|
propertyStateInfo info;
|
|
|
|
|
|
info.type = pro.proType;
|
|
|
|
|
|
info.name = pro.proName;
|
|
|
|
|
|
if(pro.proEditer != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(pro.proType.contains("SMALLINT") || pro.proType.contains("INTEGER"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QSpinBox* spin = qobject_cast<QSpinBox*>(pro.proEditer);
|
|
|
|
|
|
if(spin)
|
|
|
|
|
|
info.defaultValue = spin->value();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("BIGINT"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
info.defaultValue = lineEdit->text();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("REAL") || pro.proType.contains("DOUBLE PRECISION"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QDoubleSpinBox* dbSpin = qobject_cast<QDoubleSpinBox*>(pro.proEditer);
|
|
|
|
|
|
if(dbSpin)
|
|
|
|
|
|
info.defaultValue = dbSpin->value();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("NUMERIC") || pro.proType.contains("DECIMAL"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
info.defaultValue = lineEdit->text();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("SERIAL") || pro.proType.contains("BIGSERIAL"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLabel* label = qobject_cast<QLabel*>(pro.proEditer);
|
|
|
|
|
|
if(label)
|
|
|
|
|
|
info.defaultValue = label->text();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("CHAR") || pro.proType.contains("VARCHAR"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
info.defaultValue = lineEdit->text();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("TEXT"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
info.defaultValue = lineEdit->text();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("BYTEA"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLabel* label = qobject_cast<QLabel*>(pro.proEditer);
|
|
|
|
|
|
if(label)
|
|
|
|
|
|
info.defaultValue = label->text();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("DATE"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QDateEdit* dateEdit = qobject_cast<QDateEdit*>(pro.proEditer);
|
|
|
|
|
|
if(dateEdit)
|
|
|
|
|
|
info.defaultValue = dateEdit->text();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("TIME"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QTimeEdit* timeEdit = qobject_cast<QTimeEdit*>(pro.proEditer);
|
|
|
|
|
|
if(timeEdit)
|
|
|
|
|
|
info.defaultValue = timeEdit->text();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("TIMESTAMP"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QDateTimeEdit* dateTimeEidt = qobject_cast<QDateTimeEdit*>(pro.proEditer);
|
|
|
|
|
|
if(dateTimeEidt)
|
|
|
|
|
|
info.defaultValue = dateTimeEidt->text();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("UUID"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
info.defaultValue = lineEdit->text();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(pro.proType.contains("JSON") || pro.proType.contains("JSONB"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
info.defaultValue = lineEdit->text();
|
|
|
|
|
|
}
|
|
|
|
|
|
map.insert(pro.proName,info);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return map;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PropertyContentDlg::setPropertyValue(QMap<QString,propertyStateInfo> map)
|
|
|
|
|
|
{
|
|
|
|
|
|
for(auto &info:map)
|
|
|
|
|
|
{
|
|
|
|
|
|
propertyContentInfo pro = _mapPro[info.name];
|
|
|
|
|
|
if(info.type.contains("SMALLINT") || info.type.contains("INTEGER"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QSpinBox* spin = qobject_cast<QSpinBox*>(pro.proEditer);
|
|
|
|
|
|
if(spin)
|
|
|
|
|
|
spin->setValue(info.defaultValue.toInt());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("BIGINT"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
lineEdit->setText(info.defaultValue.toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("REAL") || info.type.contains("DOUBLE PRECISION"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QDoubleSpinBox* dbSpin = qobject_cast<QDoubleSpinBox*>(pro.proEditer);
|
|
|
|
|
|
if(dbSpin)
|
|
|
|
|
|
dbSpin->setValue(info.defaultValue.toDouble());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("NUMERIC") || info.type.contains("DECIMAL"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
lineEdit->setText(info.defaultValue.toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("SERIAL") || info.type.contains("BIGSERIAL"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLabel* label = qobject_cast<QLabel*>(pro.proEditer);
|
|
|
|
|
|
if(label)
|
|
|
|
|
|
label->setText(info.defaultValue.toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("CHAR") || info.type.contains("VARCHAR"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
lineEdit->setText(info.defaultValue.toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("TEXT"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
lineEdit->setText(info.defaultValue.toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("BYTEA"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLabel* label = qobject_cast<QLabel*>(pro.proEditer);
|
|
|
|
|
|
if(label)
|
|
|
|
|
|
label->setText(info.defaultValue.toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("DATE"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QDateEdit* dateEdit = qobject_cast<QDateEdit*>(pro.proEditer);
|
|
|
|
|
|
QDate date = QDate::fromString(info.defaultValue.toString(), "yyyy-MM-dd");
|
|
|
|
|
|
if(dateEdit)
|
|
|
|
|
|
dateEdit->setDate(date);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("TIME"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QTimeEdit* timeEdit = qobject_cast<QTimeEdit*>(pro.proEditer);
|
|
|
|
|
|
QTime time = QTime::fromString(info.defaultValue.toString(), "HH:mm:ss");
|
|
|
|
|
|
if(timeEdit)
|
|
|
|
|
|
timeEdit->setTime(time);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("TIMESTAMP"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QDateTimeEdit* dateTimeEidt = qobject_cast<QDateTimeEdit*>(pro.proEditer);
|
|
|
|
|
|
QDateTime dateTime = QDateTime::fromString(info.defaultValue.toString(), "yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
if(dateTimeEidt)
|
|
|
|
|
|
dateTimeEidt->setDateTime(dateTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("UUID"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
lineEdit->setText(info.defaultValue.toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(info.type.contains("JSON") || info.type.contains("JSONB"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(pro.proEditer);
|
|
|
|
|
|
if(lineEdit)
|
|
|
|
|
|
lineEdit->setText(info.defaultValue.toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-09 16:20:34 +08:00
|
|
|
|
QFormLayout* PropertyContentDlg::createFormLayout(QWidget* parent)
|
2025-04-03 18:33:10 +08:00
|
|
|
|
{
|
2025-04-09 16:20:34 +08:00
|
|
|
|
QFormLayout* layout = new QFormLayout(parent);
|
2025-04-03 18:33:10 +08:00
|
|
|
|
layout->setHorizontalSpacing(20); // 标签与控件间距
|
|
|
|
|
|
layout->setVerticalSpacing(12); // 行间距
|
|
|
|
|
|
layout->setLabelAlignment(Qt::AlignRight); // 标签右对齐
|
|
|
|
|
|
layout->setContentsMargins(12, 12, 12, 12); // 内边距
|
|
|
|
|
|
return layout;
|
|
|
|
|
|
}
|