71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
#include "baseContentDlg.h"
|
||
#include <QScrollArea>
|
||
#include <QFormLayout>
|
||
#include <QLabel>
|
||
#include <QSpinBox>
|
||
#include <QLineEdit>
|
||
#include <QDateEdit>
|
||
#include <QJsonDocument>
|
||
#include <QJsonParseError>
|
||
|
||
BaseContentDlg::BaseContentDlg(QWidget *parent)
|
||
: QDialog(parent)
|
||
,_curModelController(nullptr)
|
||
{
|
||
setWindowFlags(Qt::Widget);
|
||
//this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
||
}
|
||
|
||
BaseContentDlg::~BaseContentDlg()
|
||
{
|
||
|
||
}
|
||
|
||
QFormLayout* BaseContentDlg::createFormLayout(QWidget* parent)
|
||
{
|
||
QFormLayout* layout = new QFormLayout(parent);
|
||
layout->setHorizontalSpacing(20); // 标签与控件间距
|
||
layout->setVerticalSpacing(12); // 行间距
|
||
layout->setLabelAlignment(Qt::AlignRight); // 标签右对齐
|
||
layout->setContentsMargins(12, 12, 12, 12); // 内边距
|
||
return layout;
|
||
}
|
||
|
||
QJsonObject BaseContentDlg::parseCTWindingDefaultValue(const QVariant &value)
|
||
{
|
||
// 情况 1:已经是 QJsonObject ✅
|
||
if (value.canConvert<QJsonObject>())
|
||
{
|
||
return value.value<QJsonObject>();
|
||
}
|
||
|
||
// 情况 2:QVariantMap(Qt 常见中间态)
|
||
if (value.canConvert<QVariantMap>())
|
||
{
|
||
return QJsonObject::fromVariantMap(value.toMap());
|
||
}
|
||
|
||
// 情况 3:数据库来的 QString(JSON 文本)
|
||
if (value.typeId() == QMetaType::QString)
|
||
{
|
||
QString jsonStr = value.toString().trimmed();
|
||
if (jsonStr.isEmpty())
|
||
return {};
|
||
|
||
QJsonParseError err;
|
||
QJsonDocument doc = QJsonDocument::fromJson(jsonStr.toUtf8(), &err);
|
||
if (err.error != QJsonParseError::NoError)
|
||
{
|
||
qWarning() << "CTWinding JSON parse error:" << err.errorString();
|
||
return {};
|
||
}
|
||
|
||
return doc.object();
|
||
}
|
||
|
||
// 其他情况
|
||
qWarning() << "Unsupported CTWinding defaultValue type:"
|
||
<< value.typeName();
|
||
return {};
|
||
}
|