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.
259 lines
5.8 KiB
C++
259 lines
5.8 KiB
C++
|
|
#include "zxLogInstance.h"
|
|
#include "ZxResolutionHelper.h"
|
|
#include "zxSysUtils.h"
|
|
|
|
#include "iParaItemCtrl.h"
|
|
#include "iParameterUtils.h"
|
|
|
|
#include "iGridRowItem.h"
|
|
#include "iGridRowUtils.h"
|
|
|
|
#include "nmWxParaProperty.h"
|
|
|
|
nmWxParaProperty::nmWxParaProperty(QWidget *parent) :
|
|
iDlgBase(parent)
|
|
{
|
|
m_pMainLayout = NULL;
|
|
m_listParas.clear();
|
|
m_pGridItemUtils = NULL;
|
|
m_pHelpBox = NULL;
|
|
|
|
setWindowTitle(tr("Numerical para property"));
|
|
}
|
|
|
|
nmWxParaProperty::~nmWxParaProperty()
|
|
{
|
|
if (NULL != m_pGridItemUtils)
|
|
{
|
|
delete m_pGridItemUtils;
|
|
m_pGridItemUtils = NULL;
|
|
}
|
|
}
|
|
|
|
void nmWxParaProperty::initUI()
|
|
{
|
|
m_pMainLayout = new QVBoxLayout();
|
|
Q_ASSERT (NULL != m_pMainLayout);
|
|
m_pMainLayout->setSpacing(0);
|
|
m_pMainLayout->setMargin(0);
|
|
m_pMainLayout->setSizeConstraint(QVBoxLayout::SetMinAndMaxSize);
|
|
|
|
//以ScrollArea来显示,出现滚动条
|
|
{
|
|
QWidget* pWxBk = new QWidget();
|
|
Q_ASSERT (NULL != pWxBk);
|
|
pWxBk->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
pWxBk->setAutoFillBackground(true);
|
|
pWxBk->setLayout(m_pMainLayout);
|
|
|
|
// 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);
|
|
|
|
initUI_HelpBox();
|
|
if (NULL != m_pHelpBox)
|
|
{
|
|
pLayoutBk->addWidget(m_pHelpBox);
|
|
}
|
|
|
|
setLayout(pLayoutBk);
|
|
}
|
|
}
|
|
|
|
void nmWxParaProperty::initUI_HelpBox()
|
|
{
|
|
// Sub: HelpBox
|
|
m_pHelpBox = new QTextEdit();
|
|
Q_ASSERT (NULL != m_pHelpBox);
|
|
|
|
m_pHelpBox->setMaximumHeight(_resoSizeH(65));
|
|
m_pHelpBox->setReadOnly(true);
|
|
}
|
|
|
|
void nmWxParaProperty::refreshUIs(QStringList& listParas, bool bReserveOlds /*= true*/)
|
|
{
|
|
if (NULL == m_pMainLayout)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_listParas = listParas;
|
|
|
|
// 备份原有的参数内容
|
|
QMap<QString, QVariant> mapOldParas;
|
|
mapOldParas.clear();
|
|
if (bReserveOlds)
|
|
{
|
|
backupOldParas(mapOldParas, listParas);
|
|
}
|
|
|
|
// Clear Old
|
|
QVBoxLayout* pLayout = m_pMainLayout;
|
|
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_pMainLayout->addWidget(m_pGridItemUtils);\
|
|
QStringList list1 = listParas;//TODO 这是为了其他接口用的,此处暂未使用
|
|
m_pGridItemUtils->buildRowUtils(listParas, list1, false, this);
|
|
|
|
// 恢复原有的参数内容
|
|
if (bReserveOlds && !mapOldParas.isEmpty())
|
|
{
|
|
restoreOldParas(mapOldParas);
|
|
}
|
|
}
|
|
|
|
void nmWxParaProperty::backupOldParas(QMap<QString, QVariant>& map, \
|
|
QStringList& listParas)
|
|
{
|
|
map.clear();
|
|
if (NULL != m_pGridItemUtils)
|
|
{
|
|
foreach (QString s, listParas)
|
|
{
|
|
map[s] = m_pGridItemUtils->getItemValueByPara(s);
|
|
}
|
|
}
|
|
}
|
|
|
|
void nmWxParaProperty::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 nmWxParaProperty::setParaValue(QString sPara, QVariant o)
|
|
{
|
|
if (NULL != m_pGridItemUtils && \
|
|
m_pGridItemUtils->setParaValue(sPara, o))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool nmWxParaProperty::getParaValue(QString sPara, QVariant& o)
|
|
{
|
|
if (NULL != m_pGridItemUtils)
|
|
{
|
|
if (m_pGridItemUtils->getParaValue(sPara, o))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool nmWxParaProperty::getAllParaValues(QMap<QString, QVariant>& map,
|
|
bool bOnlyFitted/* = false*/,
|
|
bool bClearMap /*= true*/)
|
|
{
|
|
if (bClearMap)
|
|
{
|
|
map.clear();
|
|
}
|
|
if (NULL != m_pGridItemUtils)
|
|
{
|
|
if (!m_pGridItemUtils->getAllParaValues(map, bOnlyFitted, false))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool nmWxParaProperty::getAllParaUnits(QMap<QString, QString>& map,
|
|
bool bOnlyFitted/* = false*/,
|
|
bool bClearMap /*= true*/)
|
|
{
|
|
if (NULL != m_pGridItemUtils && \
|
|
!m_pGridItemUtils->getAllParaUnits(map, bOnlyFitted, false))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void nmWxParaProperty::onSerialize(ZxSerializer* ser)
|
|
{
|
|
iDlgBase::onSerialize(ser);
|
|
|
|
ser->write("ParaLists", m_listParas);
|
|
if (NULL != m_pGridItemUtils)
|
|
{
|
|
m_pGridItemUtils->onSerialize(ser);
|
|
}
|
|
}
|
|
|
|
void nmWxParaProperty::onDeserialize(ZxSerializer* ser)
|
|
{
|
|
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;
|
|
}
|
|
|
|
// help msg
|
|
void nmWxParaProperty::slotHelpMsg(QString& s)
|
|
{
|
|
if (NULL == m_pHelpBox)
|
|
{
|
|
return;
|
|
}
|
|
m_pHelpBox->setHtml(s);
|
|
}
|
|
|
|
void nmWxParaProperty::paintEvent(QPaintEvent *e)
|
|
{
|
|
iDlgBase::paintEvent(e);
|
|
}
|