|
|
|
|
#include "Defines.h"
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
|
|
#include "zxSysUtils.h"
|
|
|
|
|
#include "zxLogInstance.h"
|
|
|
|
|
|
|
|
|
|
#include "iWxPvtMain.h"
|
|
|
|
|
#include "nmWxDataKrog.h"
|
|
|
|
|
#include "nmWxDataBasic.h"
|
|
|
|
|
|
|
|
|
|
#include "ZxDataWell.h"
|
|
|
|
|
|
|
|
|
|
#include "nmWxWizard.h"
|
|
|
|
|
|
|
|
|
|
nmWxWizard::nmWxWizard(QWidget *parent) :
|
|
|
|
|
iWxBase(parent)
|
|
|
|
|
{
|
|
|
|
|
m_pStackedWidget = NULL;
|
|
|
|
|
|
|
|
|
|
m_vecSubWxs.clear();
|
|
|
|
|
|
|
|
|
|
m_pBtnBack = NULL;
|
|
|
|
|
m_pBtnNext = NULL;
|
|
|
|
|
|
|
|
|
|
m_oWsm = NM_WSM_All;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nmWxWizard::~nmWxWizard()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::setWsm(nmWxWizard::nmWizardShowMode o)
|
|
|
|
|
{
|
|
|
|
|
m_oWsm = o;
|
|
|
|
|
}
|
|
|
|
|
nmWxWizard::nmWizardShowMode nmWxWizard::getWsm()
|
|
|
|
|
{
|
|
|
|
|
return m_oWsm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::initUI()
|
|
|
|
|
{
|
|
|
|
|
initBase();
|
|
|
|
|
clearWx();
|
|
|
|
|
|
|
|
|
|
foreach (iWxBase* p, m_vecSubWxs)
|
|
|
|
|
{
|
|
|
|
|
m_pStackedWidget->addWidget(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_pStackedWidget->count() > 0)
|
|
|
|
|
{
|
|
|
|
|
m_pStackedWidget->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateBtnStates();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::initBase()
|
|
|
|
|
{
|
|
|
|
|
QVBoxLayout* pLayout = new QVBoxLayout();
|
|
|
|
|
Q_ASSERT (NULL != pLayout);
|
|
|
|
|
|
|
|
|
|
m_pStackedWidget = new QStackedWidget();
|
|
|
|
|
pLayout->addWidget(m_pStackedWidget);
|
|
|
|
|
|
|
|
|
|
QGroupBox* pGroupBox = new QGroupBox();
|
|
|
|
|
pGroupBox->setFlat(true);
|
|
|
|
|
pGroupBox->setMaximumHeight(4);
|
|
|
|
|
pLayout->addWidget(pGroupBox);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout* pLayoutH = new QHBoxLayout();
|
|
|
|
|
Q_ASSERT (NULL != pLayoutH);
|
|
|
|
|
pLayout->addLayout(pLayoutH);
|
|
|
|
|
{
|
|
|
|
|
QPushButton* pBtn1 = new QPushButton(tr("Help"));
|
|
|
|
|
pLayoutH->addWidget(pBtn1);
|
|
|
|
|
connect(pBtn1, SIGNAL(clicked()), this, SLOT(on_btnHelp_clicked()));
|
|
|
|
|
pBtn1->setIcon(zxLoadIcon("Help"));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QPushButton* pBtnL = new QPushButton(tr("LoadFromFile"));
|
|
|
|
|
pLayoutH->addWidget(pBtnL);
|
|
|
|
|
connect(pBtnL, SIGNAL(clicked()), this, SLOT(slotLoad()));
|
|
|
|
|
|
|
|
|
|
QPushButton* pBtnS = new QPushButton(tr("SaveToFile"));
|
|
|
|
|
pLayoutH->addWidget(pBtnS);
|
|
|
|
|
connect(pBtnS, SIGNAL(clicked()), this, SLOT(slotSave()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSpacerItem* pSpacer1 = new QSpacerItem(168, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
|
pLayoutH->addItem(pSpacer1);
|
|
|
|
|
QPushButton* pBtn2 = new QPushButton(tr("<<Back"));
|
|
|
|
|
pLayoutH->addWidget(pBtn2);
|
|
|
|
|
m_pBtnBack = pBtn2;
|
|
|
|
|
connect(pBtn2, SIGNAL(clicked()), this, SLOT(on_btnBack_clicked()));
|
|
|
|
|
pBtn2->setIcon(zxLoadIcon("PreviousOne"));
|
|
|
|
|
|
|
|
|
|
QPushButton* pBtn3 = new QPushButton(tr("Next>>"));
|
|
|
|
|
pLayoutH->addWidget(pBtn3);
|
|
|
|
|
m_pBtnNext = pBtn3;
|
|
|
|
|
connect(pBtn3, SIGNAL(clicked()), this, SLOT(on_btnNext_clicked()));
|
|
|
|
|
pBtn3->setIcon(zxLoadIcon("NextOne"));
|
|
|
|
|
|
|
|
|
|
// QSpacerItem* pSpacer2 = new QSpacerItem(168, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
|
// pLayoutH->addItem(pSpacer2);
|
|
|
|
|
|
|
|
|
|
QPushButton* pBtn4 = new QPushButton(tr("Cancel"));
|
|
|
|
|
pLayoutH->addWidget(pBtn4);
|
|
|
|
|
connect(pBtn4, SIGNAL(clicked()), this, SLOT(on_btnCancel_clicked()));
|
|
|
|
|
pBtn4->setIcon(zxLoadIcon("Cancel"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setLayout(pLayout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::clearWx()
|
|
|
|
|
{
|
|
|
|
|
if (NULL == m_pStackedWidget)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while (m_pStackedWidget->count() > 0)
|
|
|
|
|
{
|
|
|
|
|
QWidget* pWx = m_pStackedWidget->widget(0);
|
|
|
|
|
Q_ASSERT (NULL != pWx);
|
|
|
|
|
m_pStackedWidget->removeWidget(pWx);
|
|
|
|
|
pWx->setParent(NULL);
|
|
|
|
|
}
|
|
|
|
|
//m_vecSubWxs.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::updateBtnStates()
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT (NULL != m_pBtnBack && NULL != m_pBtnNext);
|
|
|
|
|
|
|
|
|
|
int nIndex = m_pStackedWidget->currentIndex();
|
|
|
|
|
m_pBtnBack->setEnabled(nIndex > 0);
|
|
|
|
|
|
|
|
|
|
int nRealLast = m_pStackedWidget->count() - 1;
|
|
|
|
|
if (!m_bShowGasConst && (m_nIndexHide == nRealLast))
|
|
|
|
|
{
|
|
|
|
|
nRealLast--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool bLast = (nIndex == nRealLast);
|
|
|
|
|
if (bLast)
|
|
|
|
|
{
|
|
|
|
|
m_pBtnNext->setText(tr("OK"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_pBtnNext->setText(tr("Next>>"));
|
|
|
|
|
}
|
|
|
|
|
m_pBtnBack->setVisible(m_pStackedWidget->count() > 1);
|
|
|
|
|
|
|
|
|
|
changeTitle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::on_btnBack_clicked()
|
|
|
|
|
{
|
|
|
|
|
int nIndex = m_pStackedWidget->currentIndex();
|
|
|
|
|
if (nIndex > 0)
|
|
|
|
|
{
|
|
|
|
|
m_pStackedWidget->setCurrentIndex(nIndex - 1);
|
|
|
|
|
updateBtnStates();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::on_btnNext_clicked()
|
|
|
|
|
{
|
|
|
|
|
int nIndex = m_pStackedWidget->currentIndex();
|
|
|
|
|
|
|
|
|
|
int nRealLast = m_pStackedWidget->count() - 1;
|
|
|
|
|
if (nIndex == nRealLast)//m_pStackedWidget->count() - 1)
|
|
|
|
|
{
|
|
|
|
|
if (m_oWsm == NM_WSM_All)
|
|
|
|
|
{
|
|
|
|
|
// 取消关联
|
|
|
|
|
clearWx();
|
|
|
|
|
m_vecSubWxs.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit sigWizardOptionOk();
|
|
|
|
|
this->accept();
|
|
|
|
|
}
|
|
|
|
|
else if (nIndex < m_pStackedWidget->count() - 1)
|
|
|
|
|
{
|
|
|
|
|
m_pStackedWidget->setCurrentIndex(nIndex + 1);
|
|
|
|
|
updateBtnStates();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::appendSubWx(iWxBase* p)
|
|
|
|
|
{
|
|
|
|
|
m_vecSubWxs.append(p);
|
|
|
|
|
|
|
|
|
|
nmWxDataBasic* p1 = dynamic_cast<nmWxDataBasic*>(p);
|
|
|
|
|
if (NULL != p1)
|
|
|
|
|
{
|
|
|
|
|
// 信号关联TODO
|
|
|
|
|
connect(p1, SIGNAL(sigParasChanged(QMap<QString,QVariant>&)), \
|
|
|
|
|
this, SLOT(slotParasObtained(QMap<QString,QVariant>&)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::resetSubWx(iWxBase* p /*= NULL*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::slotParasObtained(QMap<QString, QVariant>& map)
|
|
|
|
|
{
|
|
|
|
|
// QMap<QString, QVariant>::iterator iter = map.begin();
|
|
|
|
|
// for (; iter != map.end(); iter++)
|
|
|
|
|
// {
|
|
|
|
|
// QString sPara = iter.key();
|
|
|
|
|
// if (_isSame(sPara, "FluidOption"))
|
|
|
|
|
// {
|
|
|
|
|
// QString s = (iter.value().toString());
|
|
|
|
|
// m_bShowGasConst = (_isSame(s, s_Tag_Gas_EN) || \
|
|
|
|
|
// _isSame(s, s_Tag_Gas_CN));
|
|
|
|
|
// changeTitle();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 标题
|
|
|
|
|
void nmWxWizard::changeTitle()
|
|
|
|
|
{
|
|
|
|
|
if (NULL == m_pStackedWidget)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int nCount = m_pStackedWidget->count();
|
|
|
|
|
int nIndex = m_pStackedWidget->currentIndex();
|
|
|
|
|
if (!m_bShowGasConst && nIndex >= m_nIndexHide)
|
|
|
|
|
{
|
|
|
|
|
nIndex--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nIndex++;
|
|
|
|
|
|
|
|
|
|
QString s = "";
|
|
|
|
|
iWxBase* pWx = dynamic_cast<iWxBase*>(m_pStackedWidget->currentWidget());
|
|
|
|
|
if (NULL != pWx)
|
|
|
|
|
{
|
|
|
|
|
s = pWx->windowTitle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString sTitle = tr("Nm Analysis Wizard Steps (%1/%2): %3").arg(nIndex).arg(nCount).arg(s);
|
|
|
|
|
setWindowTitle(sTitle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::paintEvent(QPaintEvent *e)
|
|
|
|
|
{
|
|
|
|
|
iWxBase::paintEvent(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::onSerialize(ZxSerializer* ser)
|
|
|
|
|
{
|
|
|
|
|
iWxBase::onSerialize(ser);
|
|
|
|
|
|
|
|
|
|
int n = 0;
|
|
|
|
|
foreach (iWxBase* p, m_vecSubWxs)
|
|
|
|
|
{
|
|
|
|
|
QString sTag = QString("Sub_%1").arg(n++);
|
|
|
|
|
ser->push(sTag);
|
|
|
|
|
p->onSerialize(ser);
|
|
|
|
|
ser->pop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::onDeserialize(ZxSerializer* ser)
|
|
|
|
|
{
|
|
|
|
|
iWxBase::onDeserialize(ser);
|
|
|
|
|
|
|
|
|
|
int n = 0;
|
|
|
|
|
foreach (iWxBase* p, m_vecSubWxs)
|
|
|
|
|
{
|
|
|
|
|
QString sTag = QString("Sub_%1").arg(n++);
|
|
|
|
|
ser->push(sTag);
|
|
|
|
|
p->onDeserialize(ser);
|
|
|
|
|
ser->pop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::slotLoad()
|
|
|
|
|
{
|
|
|
|
|
QString sDir = ZxDataWell::getJobDirOf(m_pDataWell);
|
|
|
|
|
if (sDir.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
sDir = ZxBaseUtil::getLastDir();
|
|
|
|
|
}
|
|
|
|
|
QString sFile = QFileDialog::getOpenFileName(NULL, QObject::tr("Load wizard setting"), sDir, QObject::tr("Wizard files (*.dnd)"));
|
|
|
|
|
if (!QFile::exists(sFile))
|
|
|
|
|
{
|
|
|
|
|
zxLogRunW(tr("Failed to find file\r\n%1").arg(sFile));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFileInfo fi(sFile);
|
|
|
|
|
ZxBaseUtil::setLastDir(fi.absolutePath());
|
|
|
|
|
|
|
|
|
|
ZxXpfDoc xpf("nmWxWizard");
|
|
|
|
|
if (!xpf.load(sFile))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZxSerializer ser(&xpf, false);
|
|
|
|
|
|
|
|
|
|
onDeserialize(&ser); //调用本身反序列化
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::slotSave()
|
|
|
|
|
{
|
|
|
|
|
QString sDir = ZxDataWell::getJobDirOf(m_pDataWell);
|
|
|
|
|
if (sDir.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
sDir = ZxBaseUtil::getLastDir();
|
|
|
|
|
}
|
|
|
|
|
QString sFile = QFileDialog::getSaveFileName(NULL, QObject::tr("Save wizard setting"), sDir, QObject::tr("Wizard files (*.dnd)"));
|
|
|
|
|
if (sFile.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFile file(sFile);
|
|
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
|
ZxXpfDoc xpf("nmWxWizard");
|
|
|
|
|
ZxSerializer ser(&xpf, true);
|
|
|
|
|
|
|
|
|
|
onSerialize(&ser); //调用本身序列化
|
|
|
|
|
|
|
|
|
|
if (xpf.save(sFile))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QString sError = tr("Failed to save file.");
|
|
|
|
|
QMessageBox::warning(NULL, zxAppID, sError);
|
|
|
|
|
zxLogRunW(sError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::on_btnCancel_clicked()
|
|
|
|
|
{
|
|
|
|
|
// 取消关联
|
|
|
|
|
clearWx();
|
|
|
|
|
|
|
|
|
|
this->reject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxWizard::on_btnHelp_clicked()
|
|
|
|
|
{
|
|
|
|
|
QString sDir = ZxBaseUtil::getDirOf(s_Dir_Config, zxAppID);
|
|
|
|
|
QString sChm = sDir + "Help.chm";
|
|
|
|
|
ZxBaseUtil::startHelp(sChm);
|
|
|
|
|
}
|