98 lines
2.9 KiB
C++
98 lines
2.9 KiB
C++
#include "baseItemPropertyProxy.h"
|
|
#include "graphicsItem/functionModelItem/graphicsFunctionModelItem.h"
|
|
#include "graphicsDataModel/fixedPortsModel.h"
|
|
#include "baseProperty.h"
|
|
|
|
BaseItemPropertyProxy::BaseItemPropertyProxy(GraphicsFunctionModelItem* pItem)
|
|
: BasePropertyProxy(pItem)
|
|
,_pItem(pItem)
|
|
,_pControl(nullptr)
|
|
{
|
|
_pControl= _pItem->getHandle();
|
|
}
|
|
|
|
BaseItemPropertyProxy::~BaseItemPropertyProxy()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
QString BaseItemPropertyProxy::getName() const
|
|
{
|
|
|
|
return _pItem->getName();
|
|
}
|
|
|
|
void BaseItemPropertyProxy::setName(QString str)
|
|
{
|
|
|
|
}
|
|
|
|
QMap<QString,double> BaseItemPropertyProxy::getMap()
|
|
{
|
|
QUuid uid = _pItem->getProperty()->uuid();
|
|
QMap<QString,double> map;
|
|
if(_pControl){
|
|
auto pPara = _pControl->getMonitorPara();
|
|
auto lstInfo = pPara.value(uid);
|
|
if(!lstInfo.isEmpty()){
|
|
for(auto &info:lstInfo){
|
|
if(info.bSelected)
|
|
map[info.sName] = info.mapValue.size()?info.mapValue.last():0; //取最新的值
|
|
}
|
|
}
|
|
}
|
|
return map;
|
|
}
|
|
|
|
void BaseItemPropertyProxy::setMap(QMap<QString,double> mapSetting)
|
|
{
|
|
int nMode = _pControl->getCurMode();
|
|
if(nMode == 0) //编辑模式不设置
|
|
return;
|
|
QUuid uid = _pItem->getProperty()->uuid();
|
|
|
|
QList<ParamUpdateInfo> updateList;
|
|
auto pPara = _pControl->getMonitorPara();
|
|
|
|
const QList<MonitorItemAttributeInfo>& attributeList = pPara.value(uid);
|
|
|
|
// 2. 构建sName到MonitorItemAttributeInfo的快速查找表
|
|
QHash<QString, const MonitorItemAttributeInfo*> nameToAttribute;
|
|
for (const MonitorItemAttributeInfo& attributeInfo : attributeList) {
|
|
nameToAttribute[attributeInfo.sName] = &attributeInfo;
|
|
}
|
|
|
|
// 3. 遍历mapSetting进行比较
|
|
for (auto it = mapSetting.constBegin(); it != mapSetting.constEnd(); ++it) {
|
|
const QString& targetName = it.key();
|
|
double settingValue = it.value();
|
|
|
|
if (nameToAttribute.contains(targetName)) {
|
|
const MonitorItemAttributeInfo* attributeInfo = nameToAttribute[targetName];
|
|
|
|
if(attributeInfo->nConnectType == 1) //量测情况先不设置值
|
|
continue;
|
|
// 4. 获取当前值
|
|
double currentValue = 0.0;
|
|
if (!attributeInfo->mapValue.isEmpty()) {
|
|
auto firstIt = attributeInfo->mapValue.constBegin();
|
|
currentValue = firstIt.value();
|
|
}
|
|
|
|
// 5. 比较并记录需要更新的项
|
|
if (qAbs(currentValue - settingValue) > 1e-10) { //记录不同项
|
|
ParamUpdateInfo updateInfo;
|
|
updateInfo.sToken = attributeInfo->sConnectPara;
|
|
updateInfo.oldVal = currentValue;
|
|
updateInfo.newVal = settingValue;
|
|
updateList.append(updateInfo);
|
|
}
|
|
}
|
|
}
|
|
|
|
if(!updateList.isEmpty()){
|
|
_pControl->updateParamData(updateList);
|
|
}
|
|
}
|