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.
nmWATI/Src/nmNum/nmSubWxs/nmNewDlg.cpp

225 lines
6.4 KiB
C++

#include "nmNewDlg.h"
#include "zxLogInstance.h"
#include "ZxResolutionHelper.h"
#include "zxSysUtils.h"
#include "iParaItemCtrl.h"
#include "iParameterUtils.h"
#include "iGridRowItem.h"
#include "iGridRowUtils.h"
#include "nmData/nmDataLogFile.h"
nmNewDlg::nmNewDlg(QWidget *parent) :
iDlgBase(parent)
{
m_mainLayout = NULL;
m_listParas.clear();
setWindowTitle(tr("New Analyze 123"));
nmDataLogFile::getInstance()->writeLog("create nmNewDlg");
}
nmNewDlg::~nmNewDlg()
{
}
void nmNewDlg::initUI()
{
nmDataLogFile::getInstance()->writeLog("initUI nmNewDlg");
m_mainLayout = new QVBoxLayout();
Q_ASSERT (NULL != m_mainLayout);
m_mainLayout->setSpacing(0);
m_mainLayout->setMargin(0);
m_mainLayout->setSizeConstraint(QVBoxLayout::SetMinAndMaxSize);
//以ScrollArea来显示,出现滚动条
{
QWidget* pWxBk = new QWidget();
Q_ASSERT (NULL != pWxBk);
pWxBk->setContextMenuPolicy(Qt::CustomContextMenu);
pWxBk->setAutoFillBackground(true);
pWxBk->setLayout(m_mainLayout);
// Area,设置Widget
QScrollArea* pArea = new QScrollArea();
pArea->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
pArea->setWidgetResizable(true);
pArea->setWidget(pWxBk);
pArea->setContextMenuPolicy(Qt::CustomContextMenu);//*/
// Layout, 设置Area。
QVBoxLayout* pLayoutBk = new QVBoxLayout();
pLayoutBk->setSpacing(0);
pLayoutBk->setMargin(0);
pLayoutBk->addWidget(pArea);
setLayout(pLayoutBk);
}
this->renderComponents();
}
void nmNewDlg::renderComponents()
{
// TODO渲染新建分析需要的组件
QFormLayout* fLayout = new QFormLayout;
// 创建标签和输入框
// Job名称
QLabel *nameLabel = new QLabel("Job name:");
QLineEdit *nameEdit = new QLineEdit();
// 相态选择
QLabel *phaseLabel = new QLabel("Phase selection:");
// 创建三个三态复选框
QHBoxLayout *phaseLayout = new QHBoxLayout;
QCheckBox *checkboxWater = new QCheckBox("Water");
QCheckBox *checkboxOil = new QCheckBox("Oil");
QCheckBox *checkboxGas = new QCheckBox("Gas");
phaseLayout->addWidget(checkboxWater);
phaseLayout->addWidget(checkboxOil);
phaseLayout->addWidget(checkboxGas);
// 将标签和输入框添加到表单布局中
fLayout->addRow(nameLabel, nameEdit);
fLayout->addRow(phaseLabel, phaseLayout);
// 添加到主框架上
m_mainLayout->addItem(fLayout);
nmDataLogFile::getInstance()->writeLog("renderComponents nmNewDlg!!!");
}
void nmNewDlg::refreshUIs(QStringList &listParas, bool bReserveOlds)
{
nmDataLogFile::getInstance()->writeLog("refreshUIs nmNewDlg!!!");
if (NULL == m_mainLayout) {
return;
}
nmDataLogFile::getInstance()->writeLog("refreshUIs nmNewDlg");
m_listParas = listParas;
// 备份原有的参数内容
QMap<QString, QVariant> mapOldParas;
mapOldParas.clear();
if (bReserveOlds) {
backupOldParas(mapOldParas, listParas);
}
// Clear Old
QVBoxLayout* pLayout = m_mainLayout;
clearLayout(pLayout);
// 创建
m_pGridItemUtils = new iGridRowUtils();
Q_ASSERT (NULL != m_pGridItemUtils);
m_pGridItemUtils->setParent(this);
connect(m_pGridItemUtils, SIGNAL(sigHelpMsg(QString&)), \
this, SLOT(slotHelpMsg(QString&)));
m_mainLayout->addWidget(m_pGridItemUtils);
\
QStringList list1 = listParas;//TODO 这是为了其他接口用的,此处暂未使用
m_pGridItemUtils->buildRowUtils(listParas, list1, false, this);
// 恢复原有的参数内容
if (bReserveOlds && !mapOldParas.isEmpty()) {
restoreOldParas(mapOldParas);
}
}
void nmNewDlg::backupOldParas(QMap<QString, QVariant> &map, QStringList &listParas)
{
map.clear();
if (NULL != m_pGridItemUtils) {
foreach (QString s, listParas) {
map[s] = m_pGridItemUtils->getItemValueByPara(s);
}
}
}
void nmNewDlg::restoreOldParas(QMap<QString, QVariant> &map)
{
if (NULL == m_pGridItemUtils) {
return;
}
// 恢复先前备份的数据
QMap<QString, QVariant>::iterator iter = map.begin();
for (; iter != map.end(); iter++) {
QString sPara = iter.key();
iParameter* p = iParameterUtils::getPara(sPara);
if (NULL == p || p->m_bReadonly) {
continue;
}
QVariant o = iter.value();
if (!o.isValid()) {
continue;
}
m_pGridItemUtils->setParaValue(sPara, o);
}
}
bool nmNewDlg::setParaValue(QString sPara, QVariant o)
{
if (NULL != m_pGridItemUtils) {
if (m_pGridItemUtils->setParaValue(sPara, o)) {
return true;
}
}
return false;
}
bool nmNewDlg::getParaValue(QString sPara, QVariant &o)
{
if (NULL != m_pGridItemUtils) {
if (m_pGridItemUtils->getParaValue(sPara, o)) {
return true;
}
}
return false;
}
bool nmNewDlg::getAllParaValues(QMap<QString, QVariant> &map, bool bOnlyFitted, bool bClearMap)
{
if (bClearMap) {
map.clear();
}
if (NULL != m_pGridItemUtils) {
if (!m_pGridItemUtils->getAllParaValues(map, bOnlyFitted, false)) {
return false;
}
}
return true;
}
bool nmNewDlg::getAllParaUnits(QMap<QString, QString> &map, bool bOnlyFitted, bool bClearMap)
{
if (NULL != m_pGridItemUtils && \
!m_pGridItemUtils->getAllParaUnits(map, bOnlyFitted, false)) {
return false;
}
return true;
}
void nmNewDlg::onSerialize(ZxSerializer *ser)
{
nmDataLogFile::getInstance()->writeLog("onSerialize nmNewDlg!!!");
iDlgBase::onSerialize(ser);
ser->write("ParaLists", m_listParas);
if (NULL != m_pGridItemUtils) {
m_pGridItemUtils->onSerialize(ser);
}
}
void nmNewDlg::onDeserialize(ZxSerializer *ser)
{
nmDataLogFile::getInstance()->writeLog("onDeserialize nmNewDlg");
iDlgBase::onDeserialize(ser);
// 参数反序列化后,重新渲染
m_bUnableSP = true;
m_listParas.clear();
ser->read("ParaLists", m_listParas);
refreshUIs(m_listParas);
if (NULL != m_pGridItemUtils) {
m_pGridItemUtils->onDeserialize(ser);
}
m_bUnableSP = false;
}
void nmNewDlg::slotHelpMsg(QString &s)
{
}
void nmNewDlg::paintEvent(QPaintEvent *e)
{
nmDataLogFile::getInstance()->writeLog("paintEvent nmNewDlg");
iDlgBase::paintEvent(e);
}