logplus/ModuleConsole/src/ParameterEditorModel.cpp
2026-01-16 17:18:41 +08:00

1959 lines
70 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* ParameterEditorModule.cpp
*
* Created on: 2011-9-16
* Author: dev
*/
#include <cassert>
#include <QFormLayout>
#include <QAbstractItemModel>
#include <QApplication>
#include <QPalette>
#include <QDialog>
#include <QDebug>
#include <QFont>
#include <QDialogButtonBox>
#include <QInputDialog>
#include <QVariant>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include "LogModuleConsole.h"
#include "LogModuleParamers.h"
#include "WorkflowSceneManager.h"
#include "WorkflowWidget.h"
#include "ParameterEditorModel.h"
#include "ParameterProperty.h"
#include "ComplexInputDataParser.h"
#include "ParameterItem.h"
#include "ModuleParameter.h"
#include "Module.h"
#include "SaveHelper.h"
#include "WorkflowConst.h"
#include "WorkflowWidget.h"
#include "WorkflowSceneManager.h"
#include "ModuleInformation.h"
#include "ModuleCheckResult.h"
#include "PaiPushButton.h"
#include "ModuleManager.h"
#include "GlobalModuleBackup.h"
#include "PAIConst.h"
// #include "PaiMessageBox.h"
// #include "Log.h"
#include "ParameterValidateThread.h"
// #include "PaiThreadPoolManager.h"
// #include "HorizonInterface.h"
#include "PaiInfoEditor.h"
// #include "TimeStampLogger.h"
#include "VecViewCommand.h"
#include "ObjectID.h"
#include <PELibraryModule.h>
#include "geometryutils.h"
#include <QLabel>
using namespace pai::workflow;
using namespace pai::graphics2d;
using namespace pai::objectmodel;
// using namespace pai::ios::proj;
using namespace pai::module;
ParameterEditorModel::ParameterEditorModel(QObject *parent) :
QAbstractItemModel(parent), m_rootItem(new ParameterProperty(NULL, "")), m_pModuleInfo(NULL)
{
// TODO Auto-generated constructor stub
m_CompositeMethod=false;
m_SelectedCompositeMethod="";
m_pValidateThread=NULL;
m_currentindex=QModelIndex();
}
ParameterEditorModel::~ParameterEditorModel()
{
if(m_rootItem)
{
delete m_rootItem;
m_rootItem = NULL;
}
// if(m_pValidateThread) delete m_pValidateThread;
}
CParameterValidateThread * ParameterEditorModel::GetValidateThread()
{
return m_pValidateThread;
}
void ParameterEditorModel::SetCurrentWorkflowID(const QUuid &workflowID)
{
m_workflowID = workflowID;
}
QModelIndex ParameterEditorModel::index(int row, int column, const QModelIndex & parent) const
{
ParameterProperty *pParentItem = ParameterPropertyFromIndex(parent);
if (pParentItem != NULL && pParentItem->IsRoot())
{
if (row >= pParentItem->GetChildCount() || row < 0)
return QModelIndex();
ParameterProperty *childItem = pParentItem->GetChild(row);
Q_ASSERT(childItem != NULL);
return createIndex(row, column, childItem);
}
else
{
if (pParentItem != NULL && pParentItem->IsCategory())
{
if (row >= pParentItem->GetChildCount() || row < 0)
return QModelIndex();
ParameterProperty *childItem = pParentItem->GetChild(row);
Q_ASSERT(childItem != NULL);
return createIndex(row, column, childItem);
}
else
{
return QModelIndex();
}
}
return QModelIndex();
}
QModelIndex ParameterEditorModel::parent(const QModelIndex & index) const
{
if (!index.isValid())
return QModelIndex();
ParameterProperty *pChildItem = static_cast<ParameterProperty*> (index.internalPointer());
if (NULL != pChildItem)
{
ParameterProperty *pParentItem = dynamic_cast<ParameterProperty*> (pChildItem->GetParent());
if (pParentItem)
{
if (pParentItem->IsRoot())
{
return QModelIndex();
}
else
{
return createIndex(pParentItem->GetRow(), 0, pParentItem);
}
}
}
return QModelIndex();
}
int ParameterEditorModel::rowCount(const QModelIndex & parent) const
{
ParameterProperty *pParentItem = ParameterPropertyFromIndex(parent);
if (pParentItem != NULL)
{
return pParentItem->GetChildCount();
}
return 0;
}
int ParameterEditorModel::columnCount(const QModelIndex & /*parent*/) const
{
return 2;
}
QVariant ParameterEditorModel::data(const QModelIndex & index, int role) const
{
//最终要返回的结果
QVariant result = QVariant();
if (!index.isValid())
{
return result;
}
ParameterProperty *item = static_cast<ParameterProperty*> (index.internalPointer());
if (NULL != item)
{
if (item->IsRoot())
{
return result;
}
switch (role)
{
case Qt::ToolTipRole:
{
if (item->IsParameterItem())
{
QString descTips = CPaiInfoEditor::GetToolTipDescription(
QString::fromStdString(item->GetParameterItem()->GetDescription()));
result = QVariant(descTips);
}
break;
}
case Qt::DecorationRole:
{
break;
}
case Qt::FontRole:
{
QFont ft = QApplication::font();
if (item->IsCategory())
{
//如果是模块名,设置粗字体
if (index.parent()==QModelIndex() && index.row() == 0)
{
ft.setBold(true);
}
result.setValue<QFont> (ft);
}
else if (item->IsParameterItem())
{
result.setValue<QFont> (ft);
}
break;
}
case Qt::DisplayRole:
{
if (index.column() == 0)
{
//这里把EDITABLEDGRID的标注取消是一种临时的做法
if (item->IsParameterItem() && (item->GetParameterItem()->GetInputType() == CHECKBOX
|| item->GetParameterItem()->GetInputType() == EDITABLEDGRID))
{
return result;
}
result = QVariant(item->GetDisplayName());
}
if (index.column() == 1)
{
result = QVariant(item->GetDisplayValue());
}
break;
}
case Qt::EditRole:
{
if (index.column() == 0)
{
if (item->IsParameterItem() && (item->GetParameterItem()->GetInputType() == CHECKBOX))
{
return result;
}
result = QVariant(item->GetDisplayName());
}
if (index.column() == 1)
{
result = QVariant(item->GetDisplayValue());
}
break;
}
case Qt::BackgroundRole:
{
result = QVariant(false);
break;
}
case Qt::UserRole:
{
if (item->IsParameterItem())
{
result = QVariant(QString::fromStdString(item->GetParameterItem()->GetInputData()));
}
break;
}
case ErrorRole:
{
if (item->IsParameterItem())
{
result = QVariant(item->GetErrorMessage());
}
break;
}
case HDFSFileRole:
{
if (item->IsParameterItem())
{
result = QVariant(QString::fromStdString(item->GetParamItem()->GetStringValue()));
}
break;
}
default:
{
break;
}
}
}
return result;
}
bool ParameterEditorModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
if (!index.isValid())
return false;
if(role == Qt::EditRole)
{
ParameterProperty *paramProperty = static_cast<ParameterProperty*> (index.internalPointer());
if (paramProperty->IsCategory())
{
return false;
}
else if (paramProperty->IsParameterItem())
{
ParameterType paramType = paramProperty->GetType();
CParameterItem *paramItem = paramProperty->GetParamItem();
std::string strOldValue = paramItem->GetStringValue();
if (paramType == pai::module::ParmType_INT)
{
bool ok = false;
int intValue = value.toInt(&ok);
if (ok == true)
paramItem->SetValue(intValue);
else
paramItem->SetValue(value.toString().toStdString());
}
else if (paramType == pai::module::ParmType_DOUBLE)
{
bool ok = false;
value.toDouble(&ok);
if (ok == true)
paramItem->SetStringValue(value.toString().toStdString());
}
else if (paramType == pai::module::ParmType_FLOAT)
{
bool ok = false;
value.toFloat(&ok);
if (ok == true)
paramItem->SetStringValue(value.toString().toStdString());
}
else if (paramType == pai::module::ParmType_BOOL)
{
paramItem->SetValue(value.toBool());
}
else
{
if(paramItem->GetInputType()!=HDFSFILEBROWSER && paramItem->GetInputType()!= HDFSFILEEDITOR)
{
paramItem->SetStringValue(value.toString().toStdString());
}
else
{
paramItem->SetDefault(value.toString().toStdString());
}
}
EvaluateInputData(index);
if(strOldValue != paramItem->GetStringValue())
{
emit dataChanged(index,index);
}
return true;
}
}
if(role == HDFSFileRole)
{
ParameterProperty *paramProperty = static_cast<ParameterProperty*> (index.internalPointer());
if (paramProperty->IsCategory())
{
return false;
}
else if (paramProperty->IsParameterItem())
{
CParameterItem *paramItem = paramProperty->GetParamItem();
assert(paramItem->GetInputType()==HDFSFILEBROWSER || paramItem->GetInputType()==HDFSFILEEDITOR);
std::string strOldValue = paramItem->GetStringValue();
paramItem->SetValue(value.toString().toStdString());
if(strOldValue != paramItem->GetStringValue())
{
emit dataChanged(index,index);
}
return true;
}
else
{
}
}
return false;
}
Qt::ItemFlags ParameterEditorModel::flags(const QModelIndex & /*index*/) const
{
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
}
QVariant ParameterEditorModel::headerData ( int , Qt::Orientation orientation, int role ) const
{
if(role == Qt::DisplayRole && orientation==Qt::Horizontal)
{
return QVariant(" ");
}
return QVariant();
}
void ParameterEditorModel::EnableOverwriteItem()
{
if (m_pModuleInfo == NULL || (m_pModuleInfo->GetClassName() != "COutputModule" && m_pModuleInfo->GetClassName() != "CPAISortModule"))
{
return;
}
for (int i = 1; i < rowCount(); i++)
{
QModelIndex categoryIndex = index(i, 0, QModelIndex());
for (int j = 0; j < rowCount(categoryIndex); j++)
{
QModelIndex parameterIndex = index(j, 1, categoryIndex);
ParameterProperty *paramProperty = static_cast<ParameterProperty*> (parameterIndex.internalPointer());
if (paramProperty)
{
if (QString::fromStdString(paramProperty->GetParamItem()->GetId()).contains(".outputoverwrite"))
{
if (paramProperty->GetParamItem()->GetInputData() == "")
{
if (paramProperty->GetParamItem()->ValueToBool())
{
paramProperty->GetParamItem()->SetValue(false);
emit dataChanged(parameterIndex, parameterIndex);
}
emit signalDataPropertyChanged(parameterIndex, "Enable", QVariant(false));
}
else
{
emit signalDataPropertyChanged(parameterIndex, "Enable", QVariant(true));
}
}
}
}
}
}
// void ParameterEditorModel::slotBuildMaxEnergySurfaceIDs(const QString& layerPickFile)
// {
// if (m_pModuleInfo == NULL || m_pModuleInfo->GetClassName() != "CMaxEnergyRS")
// {
// return;
// }
// for (int i = 1; i < rowCount(); i++)
// {
// QModelIndex categoryIndex = index(i, 0, QModelIndex());
// for (int j = 0; j < rowCount(categoryIndex); j++)
// {
// QModelIndex parameterIndex = index(j, 1, categoryIndex);
// ParameterProperty *paramProperty = static_cast<ParameterProperty*> (parameterIndex.internalPointer());
// if (paramProperty && paramProperty->GetParamItem()->GetId() == "SurfaceID")
// {
// CParameterItem *pItem = paramProperty->GetParamItem();
// pItem->SetInputMetaData("");
// if (!layerPickFile.isEmpty())
// {
// HorizonInterface horizonInterface;
// long long horizonid = 0;
// try
// {
// horizonid = horizonInterface.GetHorizonInfoID(layerPickFile.toStdString());
// }
// catch (std::exception& e)
// {
// horizonid = 0;
// }
// if(horizonid > 0)
// {
// std::vector<long long> horizonSurfaceIDs;
// horizonInterface.GetHorizonSurface(horizonid, horizonSurfaceIDs);
// int size = horizonSurfaceIDs.size();
// if (size > 0)
// {
// QString inputMetaData = "";
// for(int i = 0; i < size - 1; ++i)
// {
// inputMetaData += QString::number(horizonSurfaceIDs[i]);
// inputMetaData += "/";
// }
// inputMetaData += QString::number(horizonSurfaceIDs[size -1]);
// pItem->SetInputMetaData(inputMetaData.toStdString());
// }
// }
// }
// emit signalDataPropertyChanged(parameterIndex, "LayerPickChanged", QVariant(""));
// pItem->SetValue(0);
// emit dataChanged(parameterIndex, parameterIndex);
// break;
// }
// }
// }
// }
void ParameterEditorModel::BuildItems(pai::workflow::CModuleInformation* pModuleInfo)
{
if (pModuleInfo == NULL)
return;
m_pModuleInfo = pModuleInfo;
if (pModuleInfo != NULL)
{
CModule *pModule = m_pModuleInfo->GetModule();
if(pModule == NULL)
{
return;
}
QString moduName = QString::fromStdString(pModule->GetMetaData()->GetName());
//在重新申请空间之前,释放之前的内存空间
if(m_rootItem)
{
if(!m_CompositeMethod){
delete m_rootItem;;//TODOAIYA
m_rootItem = NULL;;//TODOAIYA
}
}
if(m_rootItem==NULL)
m_rootItem = new ParameterProperty(NULL, "");
if(m_CompositeMethod)
m_rootItem->AddChild(NULL, m_SelectedCompositeMethod);
else
m_rootItem->AddChild(NULL, moduName);
m_rootItem->SetWorkflowID(m_workflowID);
std::vector < std::string > vecCategories;
pModule->GetModuleParameter()->GetCategoryNames(vecCategories);
for (size_t i = 0; i < vecCategories.size(); ++i)
{
//多模块情况下,不显示参数部分 TODO不应该采用这种逻辑
if(i>=vecCategories.size()-1&&m_CompositeMethod)
break;
bool bArrayItemSetted = false;//第一层
ParameterProperty* categoryName =NULL;
if(vecCategories[i]!="处理井段") {
categoryName =m_rootItem->AddChild(NULL, QString::fromStdString(/*moduName.toStdString()+*/vecCategories[i]));
}
if(categoryName) {
categoryName->SetWorkflowID(m_workflowID);
}
std::vector<CParameterItem*> vecParameterItems =
pModule->GetModuleParameter()->GetParameterItemsByCategory(vecCategories[i]);
for (size_t j = 0; j < vecParameterItems.size(); j++)
{
CParameterItem*pitem=vecParameterItems[j];
//参数区创建
if (vecParameterItems[j] != NULL && (vecParameterItems[j]->GetType() == ParmType_CUSTOM
|| vecParameterItems[j]->GetType() == ParmType_ARRAY))
{
if(!categoryName) {
categoryName=m_rootItem;
}
AddCompositeItemp(categoryName,vecParameterItems[j]);
}
else//输入输出区创建
{
categoryName->AddChild(vecParameterItems[j], "");
}
}
}
//初始化后立即启动参数校验线程
// StartValidation(ValidateEventSource_FromBuildItems);
}
}
void ParameterEditorModel::HandleCategoryVisible(const QModelIndex &categoryIndex)
{
if (categoryIndex.isValid() == false)
return;
bool findVisible = false;
for (int i = 0 ; i < rowCount(categoryIndex); ++i)
{
QModelIndex parameterIndex = index(i, 1, categoryIndex);
if (parameterIndex.isValid() == true)
{
if(parameterIndex.data(Qt::UserRole).toString().contains("Invisible") == false)
{
findVisible = true;
break;
}
}
}
//获得被控制的控件的ParameterProperty
ParameterProperty *pCategoryProperty = static_cast<ParameterProperty*> (categoryIndex.internalPointer());
if (NULL != pCategoryProperty && pCategoryProperty->IsCategory())
{
emit signalDataPropertyChanged(categoryIndex, "Visible", QVariant(findVisible));
}
}
void ParameterEditorModel::slotOnParameterValidated()
{
CParameterValidateThread* pValidateThread = dynamic_cast<CParameterValidateThread*>(sender());
if(pValidateThread == NULL)
{
return;
}
QAction *pAction = ::GetGlobalCommand().GetAction(GetViewCmdID_RunWorkflow());
if(pAction&&m_pModuleInfo) {
QString name;
if(m_pModuleInfo->GetModule()&&m_pModuleInfo->GetModule()->GetMetaData()) name=m_pModuleInfo->GetModule()->GetMetaData()->GetName().c_str();
pAction->setToolTip("Run_"+name);
pAction->setEnabled(pValidateThread->GetCheckResult());
}
// pai::gui::TimeStampLogger::GetInstance().WriteGUIBenchMarkLog("Workflow", true, "Show parameter error on parameter tab");
pai::module::CModuleCheckResult* pErrorInfo = pValidateThread->GetCheckResult();
workflow::CModuleInformation* pModuleInfo = pValidateThread->GetModuleInfo();
//如果m_pModuleInfo发生变化表示属性编辑界面要展现另一个模块则原来的线程校验结果没有必要显示
if (pModuleInfo != m_pModuleInfo)
{
emit signalErrorInfoChanged(m_pModuleInfo,pValidateThread->GetModuleCheckResult(),*pErrorInfo, pValidateThread->GetValidateEventSource());
pValidateThread->deleteLater();
return;
}
if (pErrorInfo != NULL)
{
//清空所有之前的错误信息
ParameterProperty * pRootItem = m_rootItem;
pRootItem->ClearAllErrorMessage();
std::vector < std::string > vecParameterItemIDs;
pErrorInfo->GetErroInfoParameterIDs(vecParameterItemIDs);
QString strParamItemErrorMessage = "";
for(unsigned int j = 0; j < vecParameterItemIDs.size(); j++)
{
ParameterProperty *paramProperty = pRootItem->GetParameterPropertyWithValidInputType(
vecParameterItemIDs.at(j));
if (paramProperty != NULL)
{
strParamItemErrorMessage = QString::fromStdString(pErrorInfo
->GetErrorMessage(vecParameterItemIDs.at(j)));
paramProperty->SetErrorMessage(strParamItemErrorMessage + "$"
+ QString::fromStdString(vecParameterItemIDs.at(j)));
}
}
submit();
emit signalErrorInfoChanged(pValidateThread->GetModuleInfo(),pValidateThread->GetModuleCheckResult(),*pErrorInfo, pValidateThread->GetValidateEventSource());
}
EnableOverwriteItem();
pValidateThread->deleteLater();
// pai::gui::TimeStampLogger::GetInstance().WriteGUIBenchMarkLog("Workflow",false, "Show parameter error on parameter tab");
}
void ParameterEditorModel::AddCompositeItemp(ParameterProperty* pPP1,pai::module::CParameterItem* pItem,int pos)
{
ParameterProperty* pPP2=NULL;
CCompositeParameterItem* pCompositeItem2 =dynamic_cast<CCompositeParameterItem*> (pItem);
if(pCompositeItem2&&pCompositeItem2->GetChildCount()<500)
{
pPP2=pPP1->AddChild(pCompositeItem2,pCompositeItem2->GetCategory().c_str(),pos);//第二层
if(!pPP2) return;
int count=pCompositeItem2->GetChildCount();
for(int k=0;k<count;k++)
{
AddCompositeItemp(pPP2,pCompositeItem2->GetParameterItem(k));
}
}
else {
if(pItem&&pPP1) {
pPP2=pPP1->AddChild(pItem,"",pos);//pItem1->GetCategory().c_str());//第二层
}
}
}
CParameterItem* CreateItem(PELibraryModule *current_module,CCompositeParameterItem* pArrayItem,int no,float sdep,float edep)
{
if(!current_module) return NULL;
if (pArrayItem == NULL) return NULL;
CParameterItem* pItem0 = pArrayItem->GetParameterItem(no);
if (pItem0 == NULL) return NULL;
CParameterItem* pNewAddedItem = NULL;
pNewAddedItem = new CCompositeParameterItem(*(dynamic_cast<CCompositeParameterItem*> (pItem0)));
((CCompositeParameterItem*) pNewAddedItem)->InitializeToShortIDs();
current_module->ChangeZone(pNewAddedItem);
QString zonename="Zone";
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(pNewAddedItem);
if(currentzone&&currentzone->GetChildCount()>=2) {
CParameterItem* pItem1=currentzone->GetParameterItem(0);
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(pItem1&&pItem2) {
pItem1->SetStringValue(toString(sdep,'f',3,true,false).toStdString());
pItem2->SetStringValue(toString(edep,'f',3,true,false).toStdString());
pItem1->SetValue(sdep);
pItem2->SetValue(edep);
zonename="井段("+QString::fromStdString(pItem1->GetStringValue())+
"~"+QString::fromStdString(pItem2->GetStringValue())+
")";
}
}
current_module->ChangeZone(pNewAddedItem);
pNewAddedItem->SetId(zonename.toStdString());
pNewAddedItem->SetCategory(zonename.toStdString());
return pNewAddedItem;
}
bool ParameterEditorModel::GetCurrentZone(float &sdep,float &edep)
{
CModule *pModule = m_pModuleInfo->GetModule();
if(pModule == NULL) return false;
PELibraryModule * current_module=dynamic_cast<PELibraryModule *>(pModule);
if(!current_module)return false;
QString strArrayItemID ="Zones";
CCompositeParameterItem* Zones =
dynamic_cast<CCompositeParameterItem*> (pModule->GetModuleParameter()->GetParameterItem(strArrayItemID.toStdString()));
if (Zones == NULL) return false;
if(!m_rootItem) return false;
ParameterProperty* pArrayCategory = m_rootItem->GetParameterProperty(strArrayItemID.toStdString());
if(!pArrayCategory) return false;
ParameterProperty *pArrayCategory0= ParameterPropertyFromIndex(m_currentindex);
if(!pArrayCategory0) return false;
CParameterItem *pItem=pArrayCategory0->GetParameterItem();
if (pItem != NULL)
{
QString paramName=QString::fromStdString(pItem->GetId());
int count=Zones->GetChildCount();
for(int i=0;i<count;i++)
{
bool iscurr=0;
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(i));
if(!currentzone) continue;
if(currentzone==pItem) {
iscurr=true;
}
else {
CParameterItem *pp=currentzone->GetParameterItem(paramName.toStdString());
if(pp) {
iscurr=true;
}
}
if(iscurr) {
CParameterItem* pItem1=currentzone->GetParameterItem(0);
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2) continue;
if(!pItem1) continue;
QString val=pItem1->GetStringValue().c_str();
sdep=val.toFloat();
val=pItem2->GetStringValue().c_str();
edep=val.toFloat();
return true;
}
}
}
return false;
}
void ParameterEditorModel::ChangeCurrentParam(float depth,float minX,QString ID)
{
if(!m_pModuleInfo) return;
CModule *pModule = m_pModuleInfo->GetModule();
if(pModule == NULL) return;
PELibraryModule * current_module=dynamic_cast<PELibraryModule *>(pModule);
if(!current_module)return;
QString strArrayItemID =ID;// "Zones";
ParameterProperty *pArrayCategory= ParameterPropertyFromIndex(m_currentindex);
if(!pArrayCategory) return;
CParameterItem *pArrayItem=pArrayCategory->GetParameterItem();
if (pArrayItem != NULL)
{
CCompositeParameterItem* pItem1=dynamic_cast<CCompositeParameterItem*>(pArrayItem);
if(!pItem1){
pArrayItem->SetValue(minX);
pArrayItem->SetStringValue(QString::number(minX).toStdString());
return;
}
else if(pItem1->GetInputType()!=COMBOX) {
pItem1->SetValue(minX);
pItem1->SetStringValue(QString::number(minX).toStdString());
}
}
}
QModelIndex ParameterEditorModel::ChangeExpand(float depth,int zoneno,QString ID)
{
CModule *pModule = m_pModuleInfo->GetModule();
if(pModule == NULL) return QModelIndex();
PELibraryModule * current_module=dynamic_cast<PELibraryModule *>(pModule);
if(!current_module)return QModelIndex();
QString strArrayItemID =ID;// "Zones";
CCompositeParameterItem* pArrayItem =
dynamic_cast<CCompositeParameterItem*> (pModule->GetModuleParameter()->GetParameterItem(strArrayItemID.toStdString()));
if (pArrayItem == NULL) return QModelIndex();
if(!m_rootItem) return QModelIndex();
ParameterProperty* pArrayCategory = m_rootItem->GetParameterProperty(strArrayItemID.toStdString());
if(!pArrayCategory) return QModelIndex();
ParameterProperty*pch=pArrayCategory->GetChild(zoneno);
if(pch) {
return IndexFromParameterProperty(pch);
}
}
void ParameterEditorModel::ChangeMXParam(float depth,float minX,float maxX,QString curvename,int zoneno,int changetype,QString ID)
{
CModule *pModule = m_pModuleInfo->GetModule();
if(pModule == NULL) return;
PELibraryModule * current_module=dynamic_cast<PELibraryModule *>(pModule);
if(!current_module)return;
QString strArrayItemID =ID;// "Zones";
CCompositeParameterItem* pArrayItem =
dynamic_cast<CCompositeParameterItem*> (pModule->GetModuleParameter()->GetParameterItem(strArrayItemID.toStdString()));
if (pArrayItem == NULL) return;
if(!m_rootItem) return;
ParameterProperty* pArrayCategory = m_rootItem->GetParameterProperty(strArrayItemID.toStdString());
if(!pArrayCategory) return;
if (pArrayItem != NULL)
{
CCompositeParameterItem* Zones=pArrayItem;
int count=Zones->GetChildCount();
{
int i=zoneno;
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(zoneno));
if(!currentzone) return;
if(currentzone->GetChildCount()<2) return;
CParameterItem* pItem1=currentzone->GetParameterItem(0);
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2) return;
if(!pItem1) return;
if(changetype==3) {
CCompositeParameterItem* currentzone1=currentzone;
QString depstr=toString(depth,'f',1,true,false);
float olddep=atof(pItem1->GetStringValue().c_str());
pItem1->SetStringValue(depstr.toStdString());
pItem1->SetValue(depth);
QString zonename="井段("+QString::fromStdString(pItem1->GetStringValue())+
"~"+QString::fromStdString(pItem2->GetStringValue())+
")";
ParameterProperty *pProperty=pArrayCategory->GetChild(zoneno);
if(pProperty) {
pProperty->SetCategoryName(zonename);
}
currentzone->SetCategory(zonename.toStdString());
if(zoneno) {
currentzone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(zoneno-1));
if(!currentzone) return;
if(currentzone->GetChildCount()<2) return;
CParameterItem* pItem1=currentzone->GetParameterItem(0);
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2||!pItem1) return;
pItem2->SetStringValue(depstr.toStdString());
pItem2->SetValue(depth);
QString zonename="井段("+QString::fromStdString(pItem1->GetStringValue())+
"~"+QString::fromStdString(pItem2->GetStringValue())+
")";
//currentzone->SetId(zonename.toStdString());
ParameterProperty *pProperty=pArrayCategory->GetChild(zoneno-1);
if(pProperty) {
pProperty->SetCategoryName(zonename);
}
currentzone->SetCategory(zonename.toStdString());
}
if(depth<olddep) currentzone=currentzone1;
}
else {
std::vector<CParameterItem> vecLeafItems;
currentzone->GetAllLeafParameterItems(vecLeafItems);
count=vecLeafItems.size();
for(int j=2;j<count;j++) {
QString paramName=QString::fromStdString(vecLeafItems[j].GetId());
paramName=paramName.right(paramName.size()-paramName.lastIndexOf(".")-1);
int no=-1;
char strTmp[16] = "visualParam.txt";
QStringList pars=GetSimilarCurves(curvename,strTmp,true);
if(pars.size()){
if(pars.indexOf(paramName,0)==-1) continue;
}
else if(curvename=="VSH"||curvename=="SH") {
if(paramName!="SHCT") continue;
}
else if(paramName!="SHFG") continue;
if(vecLeafItems[j].GetInputType()== SPLIT){
QString str;
str=vecLeafItems[j].GetInputMetaData().c_str();
QStringList strlst=str.split("/");
no=strlst.indexOf(curvename);
if(no<0) {
for(int n=0;n<9;n++) {
QString tem=QString::number(n+1)+curvename;
no=strlst.indexOf(tem);
if(no>-1) break;
}
}
}
else if(vecLeafItems[j].GetInputType()==COMBOX){
QString str;
str=vecLeafItems[j].GetInputMetaData().c_str();
QStringList strlst=str.split("/");
no=strlst.indexOf(curvename);
if(no<0) {
for(int n=0;n<9;n++) {
QString tem=QString::number(n+1)+curvename;
no=strlst.indexOf(tem);
if(no>-1) break;
}
}
}
else {
no=atof(vecLeafItems[j].GetStringValue().c_str());
}
if(no<0||no>9) {
if(paramName=="SHFG") continue;
// AfxMessageBox("SHFG无对应曲线或对应曲线不唯一无法设置极值\n您可采用选中待改字段在曲线窗口用CCTRL+鼠标左击进行修正!");
}
//else
{
QString Gmn="GMN"+QString::number(no+1);
QString Gmx="GMX"+QString::number(no+1);
if(pars.size()>1) {
Gmn=pars.at(0);
Gmx=pars.at(1);
}
else if(pars.size()>0) {
Gmn="rwrwrwr";
Gmx=pars.at(0);
}
if(curvename=="SH"||curvename=="VSH") {
Gmx="SHCT";
Gmn="wewwer";
}
int num=0;
for(int k=2;k<count;k++) {
QString paramName0=QString::fromStdString(vecLeafItems[k].GetId());
QString paramName1=paramName0.right(paramName0.size()-paramName0.lastIndexOf(".")-1);
if(paramName1==Gmn){
CParameterItem *pItem1=currentzone->GetParameterItem(paramName0.toStdString());
if(pItem1) {
pItem1->SetValue(minX);
pItem1->SetStringValue(QString::number(minX).toStdString());
}
num++;
}
else if(paramName1==Gmx){
CParameterItem *pItem1=currentzone->GetParameterItem(paramName0.toStdString());
if(pItem1) {
pItem1->SetValue(maxX);
pItem1->SetStringValue(QString::number(maxX).toStdString());
}
num++;
}
if(pars.size()&&num>=pars.size()) break;
if(curvename=="SH"||curvename=="VSH") {
if(num) break;
}
else if(num>1) break;
}
}
break;
}
}
ParameterProperty* pCategory = m_rootItem->GetParameterProperty(currentzone->GetId().c_str());
if(pCategory) {
QModelIndex index1=IndexFromParameterProperty(pCategory);
if(index1.isValid()) {
m_currentindex=index1;
}
}
return;
}
}
}
void ParameterEditorModel::AddDepth(float sdep,QString ID)
{
if(!m_pModuleInfo) return;
CModule *pModule = m_pModuleInfo->GetModule();
if(pModule == NULL) return;
PELibraryModule * current_module=dynamic_cast<PELibraryModule *>(pModule);
if(!current_module)return;
QString strArrayItemID =ID;// "Zones";//pButton->property("ArrayItemID").toString();
CCompositeParameterItem* pArrayItem =
dynamic_cast<CCompositeParameterItem*> (pModule->GetModuleParameter()->GetParameterItem(strArrayItemID.toStdString()));
if (pArrayItem == NULL) return;
if(!m_rootItem) return;
ParameterProperty* pArrayCategory = m_rootItem->GetParameterProperty(strArrayItemID.toStdString());
if(!pArrayCategory) return;
if (pArrayItem != NULL)
{
std::vector<float> sdeps,edeps;
CCompositeParameterItem* Zones=pArrayItem;
int count=Zones->GetChildCount();
if(count<1) {
AfxMessageBox("初始参数缺失,不能生成层段!");
return;
}
for(int i=0;i<count;i++){
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(i));
if(!currentzone) continue;
if(currentzone->GetChildCount()<2) continue;
CParameterItem* pItem1=currentzone->GetParameterItem(0);
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2) continue;
if(!pItem1) continue;
QString val=pItem1->GetStringValue().c_str();
float val1=val.toFloat();
if(sdep==val1) {
AfxMessageBox("当前深度段已存在!");
return;
}
sdeps.push_back(val1);
val=pItem2->GetStringValue().c_str();
val1=val.toFloat();
if(sdep==val1) {
AfxMessageBox("当前深度段已存在!");
return;
}
edeps.push_back(val1);
}
int fi=-1;
for(int i=0;i<count;i++)
{
float sdep1=sdeps[i];
float edep1=edeps[i];
if(sdep<sdep1) {
fi=i;
break;
}
}
int en=-1;
for(int i=count-1;i>=0;i--)
{
float sdep1=sdeps[i];
float edep1=edeps[i];
if(sdep>edep1) {
en=i;
break;
}
}
int paramgroups=0;
CParameterItem* pNewAddedItem =NULL;
if(fi==-1&&en==-1) en=count-1;
if(fi==0||en==count-1) {
int i=fi;
if(i<0) i=en;
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(i));
if(!currentzone) return;
if(currentzone->GetChildCount()<2) return;
CParameterItem* pItem1=currentzone->GetParameterItem(0);
if(!pItem1) return;
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2) return;
if(fi>-1){
pItem1->SetValue(sdep);
pItem1->SetStringValue(toString(sdep,'f',3,true,false).toStdString());
pItem2->SetValue(sdeps[0]);
pItem2->SetStringValue(toString(sdeps[0],'f',3,true,false).toStdString());
QString zonename="井段("+QString::fromStdString(pItem1->GetStringValue())+
"~"+QString::fromStdString(pItem2->GetStringValue())+
")";
currentzone->SetId(zonename.toStdString());
for(int k=0;k<pArrayCategory->GetChildCount();k++) {
ParameterProperty *pProperty=pArrayCategory->GetChild(k);
if(pProperty) {
if(pProperty->GetDisplayName().compare(currentzone->GetCategory().c_str())==0) {
pProperty->SetCategoryName(zonename);
}
}
}
currentzone->SetCategory(zonename.toStdString());
pNewAddedItem =CreateItem(current_module,pArrayItem,i,sdeps[0],edeps[0]);
pArrayItem->InsertParameterItem(i+1,*pNewAddedItem);
paramgroups=i+1;
}
else {
int md=-1;
for(int i=0;i<count;i++)
{
float sdep1=sdeps[i];
float edep1=edeps[i];
if(sdep>sdep1&&sdep<edep1) {
md=i;
break;
}
}
if(md!=-1) {
i=md;
float sdep1=sdeps[i];
float edep1=edeps[i];
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(i));
if(!currentzone) return;
if(currentzone->GetChildCount()<2) return;
CParameterItem* pItem1=currentzone->GetParameterItem(0);
if(!pItem1) return;
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2) return;
pItem2->SetStringValue(toString(sdep,'f',3,true,false).toStdString());
pItem2->SetValue(sdep);
QString zonename="井段("+QString::fromStdString(pItem1->GetStringValue())+
"~"+QString::fromStdString(pItem2->GetStringValue())+
")";
//currentzone->SetId(zonename.toStdString());
for(int k=0;k<pArrayCategory->GetChildCount();k++) {
ParameterProperty *pProperty=pArrayCategory->GetChild(k);
if(pProperty) {
if(pProperty->GetDisplayName().compare(currentzone->GetCategory().c_str())==0) {
pProperty->SetCategoryName(zonename);
}
}
}
currentzone->SetCategory(zonename.toStdString());
pNewAddedItem =CreateItem(current_module,pArrayItem,i,sdep,edeps[i]);
}
else pNewAddedItem =CreateItem(current_module,pArrayItem,i,edeps[i],sdep);
pArrayItem->AddParameterItem(*pNewAddedItem);
paramgroups=pArrayItem->GetChildCount()-1;
}
}
else {
int i=-1;
if(fi>-1&&en>-1&&fi>en)
{
i=en;
if(i<0) return;
float sdep1=edeps[i];
float edep1=sdep;
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(i));
if(!currentzone) return;
if(currentzone->GetChildCount()<2) return;
pNewAddedItem =CreateItem(current_module,pArrayItem,i,edeps[i],sdep);
pArrayItem->InsertParameterItem(i+1,*pNewAddedItem);
paramgroups=i+1;
}
else {
en=-1;
for(int i=0;i<count;i++)
{
float sdep1=sdeps[i];
float edep1=edeps[i];
if(sdep>sdep1&&sdep<edep1) {
en=i;
break;
}
}
i=en;
if(i<0) return;
float sdep1=sdeps[i];
float edep1=edeps[i];
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(i));
if(!currentzone) return;
if(currentzone->GetChildCount()<2) return;
CParameterItem* pItem1=currentzone->GetParameterItem(0);
if(!pItem1) return;
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2) return;
pItem2->SetStringValue(toString(sdep,'f',3,true,false).toStdString());
pItem2->SetValue(sdep);
QString zonename="井段("+QString::fromStdString(pItem1->GetStringValue())+
"~"+QString::fromStdString(pItem2->GetStringValue())+
")";
currentzone->SetId(zonename.toStdString());
for(int k=0;k<pArrayCategory->GetChildCount();k++) {
ParameterProperty *pProperty=pArrayCategory->GetChild(k);
if(pProperty) {
if(pProperty->GetDisplayName().compare(currentzone->GetCategory().c_str())==0) {
pProperty->SetCategoryName(zonename);
}
}
}
currentzone->SetCategory(zonename.toStdString());
pNewAddedItem =CreateItem(current_module,pArrayItem,i,sdep,edeps[i]);
pArrayItem->InsertParameterItem(i+1,*pNewAddedItem);
paramgroups=i+1;
}
}
if(pNewAddedItem)delete pNewAddedItem;
pNewAddedItem = NULL;
for(int i=0;i<pArrayItem->GetChildCount();i++) {
QString zonename="Zones["+QString::number(i)+"]";
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(i));
currentzone->SetId(zonename.toStdString());
}
//this->BuildItems(m_pModuleInfo);
//return;
//得到数组分类项
{
int m=0;
QList<int> lstNewRows;
if (pArrayCategory != NULL)
{
//得到数组分类项下需要显示的参数项
// int paramgroups=pArrayItem->GetChildCount();
CParameterItem*pItem0=pArrayItem->GetParameterItem(paramgroups);
CParameterItem* pItem =dynamic_cast<CParameterItem*> (pItem0);
if(pItem) {
AddCompositeItemp(pArrayCategory,pItem,paramgroups);
}
lstNewRows.clear();
std::vector<CParameterItem*> vecResultItems;
pArrayItem->GetParameterItemsWithValidInputType(vecResultItems);
for (size_t k = 0; k < vecResultItems.size(); ++k)
{
lstNewRows.push_back(k);
}
//更新删除按钮的显示或隐藏
if(pArrayCategory != NULL)
{
pArrayCategory->HandleDeleteButton();
}
emit layoutChanged();
//找到parent项中新添的子项发送信号确保新添项可视
if(!lstNewRows.isEmpty())
emit signalMakeIndexVisible(IndexFromParameterProperty(pArrayCategory).child(lstNewRows.first(), 0));
StartValidation();
}
}
}
}
void ParameterEditorModel::DeleteDepth(float sdep,QString ID)
{
int index=-1;
if(!m_pModuleInfo) return;
CModule *pModule = m_pModuleInfo->GetModule();
if(pModule == NULL) return;
PELibraryModule * current_module=dynamic_cast<PELibraryModule *>(pModule);
if(!current_module)return;
QString strArrayItemID =ID;// "Zones";//pButton->property("ArrayItemID").toString();
CCompositeParameterItem* pArrayItem =
dynamic_cast<CCompositeParameterItem*> (pModule->GetModuleParameter()->GetParameterItem(strArrayItemID.toStdString()));
if (pArrayItem == NULL) return;
if(!m_rootItem) return;
ParameterProperty* pArrayCategory = m_rootItem->GetParameterProperty(strArrayItemID.toStdString());
if(!pArrayCategory) return;
if (pArrayItem != NULL)
{
CCompositeParameterItem* Zones=pArrayItem;
int count=Zones->GetChildCount();
if(count<2) {
AfxMessageBox("当前层段数小于2段,不可以删除!");
return;
}
for(int i=0;i<count;i++){
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(i));
if(!currentzone) continue;
if(currentzone->GetChildCount()<2) continue;
CParameterItem* pItem1=currentzone->GetParameterItem(0);
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2) continue;
if(!pItem1) continue;
QString val=pItem1->GetStringValue().c_str();
float val1=val.toFloat();
val=pItem2->GetStringValue().c_str();
float val2=val.toFloat();
if(sdep>=val1&&sdep<val2) {
index=i;
break;
}
}
if(index>-1&&index<pArrayItem->GetChildCount()) {
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(pArrayItem->GetParameterItem(index));
if(currentzone) {
float sdep=0;
QString id=currentzone->GetId().c_str();
if(index!=0&&index!=pArrayItem->GetChildCount()-1)
{
if(currentzone->GetChildCount()<2) return;
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2) return;
sdep=atof(pItem2->GetStringValue().c_str());
currentzone=dynamic_cast<CCompositeParameterItem*>(pArrayItem->GetParameterItem(index-1));
}
else currentzone=NULL;
if(slotOnDeleteItem(id)) {
m_currentindex=QModelIndex();
if(currentzone) {
if(currentzone->GetChildCount()<2) return;
CParameterItem* pItem1=currentzone->GetParameterItem(0);
if(!pItem1) return;
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2) return;
pItem2->SetValue(sdep);
pItem2->SetStringValue(toString(sdep,'f',3,true,false).toStdString());
QString zonename="井段("+QString::fromStdString(pItem1->GetStringValue())+
"~"+QString::fromStdString(pItem2->GetStringValue())+
")";
// currentzone->SetId(zonename.toStdString());
for(int k=0;k<pArrayCategory->GetChildCount();k++) {
ParameterProperty *pProperty=pArrayCategory->GetChild(k);
if(pProperty) {
if(pProperty->GetDisplayName().compare(currentzone->GetCategory().c_str())==0) {
pProperty->SetCategoryName(zonename);
}
}
}
currentzone->SetCategory(zonename.toStdString());
}
OnZoneValueChanged("");
}
}
}
}
}
void ParameterEditorModel::OnZoneValueChanged(QString str)
{
emit signalZoneValueChanged(str);
}
void ParameterEditorModel::FreshDepth(QString strArrayItemID)
{
CModule *pModule = m_pModuleInfo->GetModule();
if(pModule == NULL)
{
return;
}
PELibraryModule * current_module=dynamic_cast<PELibraryModule *>(pModule);
if(!current_module){
return;
}
ParameterProperty* pArrayCategory = m_rootItem->GetParameterProperty(strArrayItemID.toStdString());
if(!pArrayCategory) return;
CCompositeParameterItem* pArrayItem =
dynamic_cast<CCompositeParameterItem*> (pModule->GetModuleParameter()->GetParameterItem(strArrayItemID.toStdString()));
if (pArrayItem != NULL)
{
for(int i=0;i<pArrayItem->GetChildCount();i++){
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(pArrayItem->GetParameterItem(i));
if(!currentzone) continue;
if(currentzone->GetChildCount()<2) continue;
CParameterItem* pItem1=currentzone->GetParameterItem(0);
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(pItem1&&pItem2) {
float sdep=atof(pItem1->GetStringValue().c_str());
float edep=atof(pItem2->GetStringValue().c_str());
QString itemname="井段("
+QString::fromStdString(toString(sdep,'f',3,true,false).toStdString())+
"~"
+QString::fromStdString(toString(edep,'f',3,true,false).toStdString())+
")";
// QString itemname="井段("+QString::fromStdString(pItem1->GetStringValue())+
// "~"+QString::fromStdString(pItem2->GetStringValue())+
// ")";
// currentzone->SetId(itemname.toStdString());
for(int k=0;k<pArrayCategory->GetChildCount();k++) {
ParameterProperty *pProperty=pArrayCategory->GetChild(k);
if(pProperty) {
if(pProperty->GetDisplayName().compare(currentzone->GetCategory().c_str())==0) {
pProperty->SetCategoryName(itemname);
}
}
}
currentzone->SetCategory(itemname.toStdString());
}
}
}
}
void ParameterEditorModel::slotOnArrayItemButtonClicked(QAbstractButton * pButton)
{
if (pButton->property("ActionID").toString() == "Fresh")
{
QString strArrayItemID = pButton->property("ArrayItemID").toString();
emit signalExclieChanged("Zones");
//FreshDepth(strArrayItemID);
}
else if (pButton->property("ActionID").toString() == "HasDeleteButton")
{
if(!m_rootItem) return;
CModule *pModule = m_pModuleInfo->GetModule();
if(pModule == NULL) return;
PELibraryModule * current_module=dynamic_cast<PELibraryModule *>(pModule);
if(!current_module)return;
QString strArrayItemID = pButton->property("ArrayItemID").toString();
CCompositeParameterItem* pArrayItem =
dynamic_cast<CCompositeParameterItem*> (pModule->GetModuleParameter()->GetParameterItem(strArrayItemID.toStdString()));
if (pArrayItem == NULL) return;
ParameterProperty* pArrayCategory = m_rootItem->GetParameterProperty(strArrayItemID.toStdString());
if(!pArrayCategory) return;
if(pArrayItem->GetChildCount()<2)
{
AfxMessageBox("层段数为1不可以删除!");
return;
}
ParameterProperty *pP1=ParameterPropertyFromIndex(m_currentindex);
int index=-1;
if(pP1) {
QString name=pP1->GetDisplayName();
for(int i=0;i<pArrayItem->GetChildCount();i++) {
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(pArrayItem->GetParameterItem(i));
if(!currentzone) continue;
if(name.toStdString()==currentzone->GetCategory()){
index=i;
int flag = QMessageBox::warning(NULL,"提示",QString("您确信删除"+name+"?"),QMessageBox::Yes,QMessageBox::No);
if(flag!=QMessageBox::Yes) {
return;
}
}
}
}
else {
QDialog dialog(NULL);
dialog.setModal(false);
Qt::WindowFlags flags = dialog.windowFlags();
flags |= Qt::WindowStaysOnTopHint;
flags &= ~Qt::WindowContextHelpButtonHint;
dialog.setWindowFlags(flags);
dialog.setWindowTitle("选择删除深度段");
QFormLayout form(&dialog);
form.addRow(new QLabel("深度段:"));
// Value1
QString value1 = QString("分段深度位置: ");
QComboBox *spinbox1 = new QComboBox(&dialog);
for(int i=0;i<pArrayItem->GetChildCount();i++) {
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(pArrayItem->GetParameterItem(i));
if(!currentzone) continue;
spinbox1->addItem(currentzone->GetCategory().c_str());
}
if(pArrayItem->GetChildCount()) spinbox1->setCurrentIndex(0);
form.addRow("", spinbox1);
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, &dialog);
form.addRow(&buttonBox);
QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
dialog.show();
if (dialog.exec() == QDialog::Accepted) {
index=spinbox1->currentIndex();
}
}
if(index>-1&&index<pArrayItem->GetChildCount()) {
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(pArrayItem->GetParameterItem(index));
if(currentzone) {
float sdep=0;
QString id=currentzone->GetId().c_str();
if(index!=0&&index!=pArrayItem->GetChildCount()-1)
{
if(currentzone->GetChildCount()<2) return;
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2) return;
sdep=atof(pItem2->GetStringValue().c_str());
currentzone=dynamic_cast<CCompositeParameterItem*>(pArrayItem->GetParameterItem(index-1));
}
else currentzone=NULL;
if(slotOnDeleteItem(id)) {
m_currentindex=QModelIndex();
if(currentzone) {
if(currentzone->GetChildCount()<2) return;
CParameterItem* pItem1=currentzone->GetParameterItem(0);
if(!pItem1) return;
CParameterItem* pItem2=currentzone->GetParameterItem(1);
if(!pItem2) return;
pItem2->SetValue(sdep);
pItem2->SetStringValue(toString(sdep,'f',3,true,false).toStdString());
QString zonename="井段("+QString::fromStdString(pItem1->GetStringValue())+
"~"+QString::fromStdString(pItem2->GetStringValue())+
")";
// currentzone->SetId(zonename.toStdString());
for(int k=0;k<pArrayCategory->GetChildCount();k++) {
ParameterProperty *pProperty=pArrayCategory->GetChild(k);
if(pProperty) {
if(pProperty->GetDisplayName().compare(currentzone->GetCategory().c_str())==0) {
pProperty->SetCategoryName(zonename);
}
}
}
currentzone->SetCategory(zonename.toStdString());
}
OnZoneValueChanged("");
}
}
}
else return;
}
else if (pButton->property("ActionID").toString() == "Add")
{
QDialog dialog(NULL);
dialog.setModal(false);
Qt::WindowFlags flags = dialog.windowFlags();
flags |= Qt::WindowStaysOnTopHint;
flags &= ~Qt::WindowContextHelpButtonHint;
dialog.setWindowFlags(flags);
dialog.setWindowTitle("处理深度段");
QFormLayout form(&dialog);
form.addRow(new QLabel("输入处理深度分段点:"));
// Value1
QString value1 = QString("分段深度位置: ");
QLineEdit *spinbox1 = new QLineEdit(&dialog);
form.addRow(value1, spinbox1);
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, &dialog);
form.addRow(&buttonBox);
QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
dialog.show();
if (dialog.exec() == QDialog::Accepted) {
// Do something here
}
else return;
float sdep=spinbox1->text().toFloat();
QString strArrayItemID =pButton->property("ArrayItemID").toString();
AddDepth(sdep,strArrayItemID);
OnZoneValueChanged("");
}
}
bool ParameterEditorModel::slotOnDeleteItem(const QString& strDeleteItemID)
{
if(m_pModuleInfo == NULL)
{
return false;
}
CModule *pModule = m_pModuleInfo->GetModule();
CModuleParameter * pModulePara = pModule->GetModuleParameter();
if(!pModulePara) return false;
CParameterItem* pDeleteItem = pModulePara->GetParameterItem(strDeleteItemID.toStdString());
if (pDeleteItem == NULL) return false;
{
//通知界面布局
ParameterProperty* pArrayCategory = NULL;
QList<int> lstDeleteRows;
CParameterItem* pParentItem = pDeleteItem->GetParentItem();
if(pParentItem != NULL && m_rootItem != NULL)
{
pArrayCategory = m_rootItem->GetParameterProperty(pParentItem->GetId());
if(pArrayCategory != NULL)
{
//统计待删除对象在父节点中的索引
CCompositeParameterItem* pCompositeDeleteItem = dynamic_cast<CCompositeParameterItem*> (pDeleteItem);
if(pCompositeDeleteItem != NULL)
{
for(int i=0;i<pCompositeDeleteItem->GetChildCount();++i)
{
if(!pCompositeDeleteItem->GetParameterItem(i)) continue;
ParameterProperty* pDeleteProperty = m_rootItem->GetParameterProperty(pCompositeDeleteItem->GetParameterItem(i)->GetId());
if(pDeleteProperty != NULL)
{
lstDeleteRows.push_back(pDeleteProperty->GetRow());//得到待删除的节点在父节点的索引
}
}
}
else
{
ParameterProperty* pDeleteProperty = m_rootItem->GetParameterProperty(pDeleteItem->GetId());
if(pDeleteProperty != NULL)
{
lstDeleteRows.push_back(pDeleteProperty->GetRow());
}
}
qSort(lstDeleteRows.begin(),lstDeleteRows.end());
}
}
emit layoutAboutToBeChanged();
QModelIndex arrayCategoryModelIndex = IndexFromParameterProperty(pArrayCategory);
if(lstDeleteRows.size()) beginRemoveRows(arrayCategoryModelIndex, lstDeleteRows.first(), lstDeleteRows.last());
//删除参数面板树节点
CCompositeParameterItem* pCompositeDeleteItem = dynamic_cast<CCompositeParameterItem*> (pDeleteItem);
if(pCompositeDeleteItem != NULL)
{
for(int i=0;i<pCompositeDeleteItem->GetChildCount();++i)
{
m_rootItem->RemoveChild(pCompositeDeleteItem->GetParameterItem(i)->GetId());
}
m_rootItem->RemoveChild(pCompositeDeleteItem->GetId());
}
else
{
m_rootItem->RemoveChild(strDeleteItemID.toStdString());
}
if(lstDeleteRows.size()) endRemoveRows();
emit layoutChanged();
//删除参数项
CCompositeParameterItem* pCompositeParentItem = dynamic_cast<CCompositeParameterItem*> (pParentItem);
if (pCompositeParentItem != NULL)
{
//删除该项
pCompositeParentItem->RemoveParameterItem(strDeleteItemID.toStdString());
}
//更新其他删除按钮的ID
emit signalDataPropertyChanged(arrayCategoryModelIndex,"ChildrenItemID",QVariant());
//更新删除按钮的显示或隐藏
if(pArrayCategory != NULL)
{
pArrayCategory->HandleDeleteButton();
}
// StartValidation();
}
return true;
}
void ParameterEditorModel::slotOnHideShowOptionalItem(const QString& strToHideItemID,bool hide)
{
if(m_pModuleInfo == NULL)
{
return;
}
CModule *pModule = m_pModuleInfo->GetModule();
CParameterItem* pParamItem = pModule->GetModuleParameter()->GetParameterItem(strToHideItemID.toStdString());
if (pParamItem != NULL)
{
CModule *pModule = m_pModuleInfo->GetModule();
CParameterItem* pToHideItem = pModule->GetModuleParameter()->GetParameterItem(strToHideItemID.toStdString());
if (pToHideItem != NULL)
{
//通知界面布局
ParameterProperty* pArrayCategory = NULL;
QList<ParameterProperty*> lstHideRows;
CParameterItem* pParentItem = pToHideItem->GetParentItem();
if(pParentItem != NULL && m_rootItem != NULL)
{
pArrayCategory = m_rootItem->GetParameterProperty(pParentItem->GetId());
if(pArrayCategory != NULL)
{
//统计待删除对象在父节点中的索引
CCompositeParameterItem* pCompositeToHideItem = dynamic_cast<CCompositeParameterItem*> (pToHideItem);
if(pCompositeToHideItem != NULL)
{
for(int i=0;i<pCompositeToHideItem->GetChildCount();++i)
{
ParameterProperty* pDeleteProperty = m_rootItem->GetParameterProperty(pCompositeToHideItem->GetParameterItem(i)->GetId());
if(pDeleteProperty != NULL)
{
lstHideRows.push_back(pDeleteProperty);
}
}
}
else
{
ParameterProperty* pDeleteProperty = m_rootItem->GetParameterProperty(pToHideItem->GetId());
if(pDeleteProperty != NULL)
{
lstHideRows.push_back(pDeleteProperty);
}
}
}
}
emit layoutAboutToBeChanged();
//第一个不隐藏
for(int paramindex=1;paramindex<lstHideRows.size();paramindex++){
QModelIndex arrayCategoryModelIndex = IndexFromParameterProperty(lstHideRows[paramindex]);
if(hide&&!lstHideRows[paramindex]->GetParameterItem()->IsNessary())
emit signalDataPropertyChanged(arrayCategoryModelIndex, "Visible", QVariant(!hide));
else if(!hide)
emit signalDataPropertyChanged(arrayCategoryModelIndex, "Visible", QVariant(!hide));
}
emit layoutChanged();
}
}
}
void ParameterEditorModel::slotZoneChanged(int changedtoindex)
{
if(changedtoindex>=0)
slotOnHideShowItem("Zones["+QString::number(changedtoindex)+"]",false);
}
void ParameterEditorModel::slotOnHideShowItem(const QString& strToHideItemID,bool hide)
{
return;
if(m_pModuleInfo == NULL)
{
return;
}
CModule *pModule = m_pModuleInfo->GetModule();
if(pModule == NULL)
{
return;
}
if(!hide)//显示一个井段参数,先把其他的都隐藏了
{
PELibraryModule * current_module=dynamic_cast<PELibraryModule *>(pModule);
if(current_module){
int zonecount=current_module->GetZoneCount();
if(zonecount>1)
for(int i=0;i<zonecount;i++)
{
QString astrToHideItemID="Zones["+QString::number(i)+"]";
if(astrToHideItemID!=strToHideItemID)//关闭其他的
slotOnHideShowItem(astrToHideItemID, true);
}
}
}
CParameterItem* pParamItem = pModule->GetModuleParameter()->GetParameterItem(strToHideItemID.toStdString());
if (pParamItem != NULL)
{
CModule *pModule = m_pModuleInfo->GetModule();
CParameterItem* pToHideItem = pModule->GetModuleParameter()->GetParameterItem(strToHideItemID.toStdString());
if (pToHideItem != NULL)
{
//通知界面布局
ParameterProperty* pArrayCategory = NULL;
QList<ParameterProperty*> lstHideRows;
CParameterItem* pParentItem = pToHideItem->GetParentItem();
if(pParentItem != NULL && m_rootItem != NULL)
{
pArrayCategory = m_rootItem->GetParameterProperty(pParentItem->GetId());
if(pArrayCategory != NULL)
{
//统计待删除对象在父节点中的索引
CCompositeParameterItem* pCompositeToHideItem = dynamic_cast<CCompositeParameterItem*> (pToHideItem);
if(pCompositeToHideItem != NULL)
{
for(int i=0;i<pCompositeToHideItem->GetChildCount();++i)
{
ParameterProperty* pDeleteProperty = m_rootItem->GetParameterProperty(pCompositeToHideItem->GetParameterItem(i)->GetId());
if(pDeleteProperty != NULL)
{
lstHideRows.push_back(pDeleteProperty);
}
}
}
else
{
ParameterProperty* pDeleteProperty = m_rootItem->GetParameterProperty(pToHideItem->GetId());
if(pDeleteProperty != NULL)
{
lstHideRows.push_back(pDeleteProperty);
}
}
}
}
emit layoutAboutToBeChanged();
//第一个不隐藏,第一个需要更新图标
//lstHideRows[0]->HideShowItemsIcon(hide);
//其他的都隐藏
for(int paramindex=0;paramindex<lstHideRows.size();paramindex++){
QModelIndex arrayCategoryModelIndex = IndexFromParameterProperty(lstHideRows[paramindex]);
emit signalDataPropertyChanged(arrayCategoryModelIndex, "Visible", QVariant(!hide));
}
emit layoutChanged();
}
}
}
void ParameterEditorModel::clear()
{
emit layoutAboutToBeChanged();
beginRemoveRows(QModelIndex(), 0, rowCount());
//在重新申请空间之前,释放之前的内存空间
if(m_rootItem)
{
delete m_rootItem;
m_rootItem = NULL;
}
m_rootItem = new ParameterProperty(NULL, "");
endRemoveRows();
emit layoutChanged();
m_pModuleInfo = NULL;
}
ParameterProperty * ParameterEditorModel::ParameterPropertyFromIndex(const QModelIndex &index) const
{
if (index.isValid())
{
return static_cast<ParameterProperty *> (index.internalPointer());
}
else
{
return m_rootItem;
}
}
QModelIndex ParameterEditorModel::IndexFromParameterProperty(ParameterProperty * pParameterProperty) const
{
if ((pParameterProperty == m_rootItem) || !pParameterProperty)
{
return QModelIndex();
}
ParameterProperty *pParent = pParameterProperty->GetParent();
if (pParent != NULL)
{
for (int i = 0; i < pParent->GetChildCount(); ++i)
{
if (pParameterProperty == pParent->GetChild(i))
{
return createIndex(i, 0, pParameterProperty);
}
}
}
return QModelIndex();
}
pai::workflow::CModuleInformation *ParameterEditorModel::GetModuleInformation()
{
return m_pModuleInfo;
}
QModelIndex ParameterEditorModel::GetIndexByParameterItemID(const QModelIndex& parentIndex, const QString& strItemID)
{
ParameterProperty *pParentParamProperty = static_cast<ParameterProperty*> (parentIndex.internalPointer());
if(!pParentParamProperty) return QModelIndex();
for (int i = 0; i < pParentParamProperty->GetChildCount(); ++i)
{
ParameterProperty * pChildParamProperty = pParentParamProperty->GetChild(i);
if (pChildParamProperty != NULL && pChildParamProperty->IsParameterItem())
{
QString strChildItemID = QString::fromStdString(pChildParamProperty->GetParamItem()->GetId());
if (strChildItemID == strItemID)
{
return createIndex(i, 0, pChildParamProperty);
}
}
}
return QModelIndex();
}
void ParameterEditorModel::EvaluateInputData(const QModelIndex& index)
{
if (!index.isValid())
{
return;
}
//TODO 这个函数目前并没有真正地去做一个脚本引擎去解析和执行脚本,而是临时地用来达到输入输出模块的一个参数项之间的互动需求而已
ParameterProperty *pParamProperty =
static_cast<ParameterProperty*> (index.internalPointer());
if (pParamProperty->IsParameterItem())
{
CParameterItem *pParamItem = pParamProperty->GetParamItem();
assert(pParamItem != NULL);
QString strInputData = QString::fromStdString(
pParamItem->GetInputData());
strInputData.simplified();
QString strOnClick("onclick");
if (strInputData.contains(strOnClick))
{
//创建解析器将当前参数的QModelIndex当前的参数取值当前参数的ID传给构造函数。
ComplexInputDataParser parser(index, strInputData, QString::fromStdString(pParamItem->GetStringValue()), pParamItem->GetId());
//获得被该参数控制的控制信息列表
QList<ItemData> itemDataList;
QList<ItemData> itemDataList_ = parser.GetItemDataList();
// 将选中的项最后刷新来保证item有交叉时部分item无法显示的问题(16507)
for (int i = 0; i < itemDataList_.size(); ++i)
{
ItemData itemData = itemDataList_.at(i);
if(itemData.GetValue().toStdString() == pParamItem->GetStringValue())
{
itemDataList.append(itemData);
}
else
{
itemDataList.prepend(itemData);
}
}
for (int i = 0; i < itemDataList.size(); ++i)
{
//获得被该参数控制的一条控制信息
ItemData itemData = itemDataList.at(i);
//获得被该控制信息控制的控件的ID列表
QStringList destItemIDList = itemData.GetDestItemIDList();
for (int j = 0; j < destItemIDList.size(); ++j)
{
//获得被控制的控件的QModelIndex
QModelIndex destSubIndex = GetIndexByParameterItemID(itemData.GetParentIndex(), itemData.GetParentID() + destItemIDList[j]);
//获得被控制的控件的ParameterProperty
ParameterProperty *pParamProperty = static_cast<ParameterProperty*> (destSubIndex.internalPointer());
if (NULL != pParamProperty && pParamProperty->IsParameterItem())
{
//根据参数值和属性获得被控制控件的InputData字符串
std::string newInputData = parser.ResetInputDataString(pParamProperty->GetParameterItem()->GetInputData(), itemData.GetProperty(), itemData.GetValue());
pParamProperty->GetParameterItem()->SetInputData(newInputData);
//修改界面显示或者能用状态。
QVariant varPropertyValue(itemData.GetValue().toStdString() == pParamItem->GetStringValue() ? true : false);
emit signalDataPropertyChanged(destSubIndex, itemData.GetProperty(), varPropertyValue);
}
}
//获得被该控制信息控制的类别列表
QStringList destCategoryList = itemData.GetDestCategoryList();
for (int j = 0; j < destCategoryList.size(); ++j)
{
ParameterProperty *pCategoryProperty = NULL;
if(m_rootItem != NULL)
{
pCategoryProperty = m_rootItem->GetParameterProperty(destCategoryList[j].toStdString());
}
if (pCategoryProperty != NULL)
{
//获得类别下所有的控件
for(int k = 0; k < pCategoryProperty->GetChildCount(); ++k)
{
ParameterProperty *pParamProperty = pCategoryProperty->GetChild(k);
if (NULL != pParamProperty && pParamProperty->IsParameterItem())
{
//获得被控制的控件的QModelIndex
QModelIndex destSubIndex = IndexFromParameterProperty(pParamProperty);
//根据参数值和属性获得被控制控件的InputData字符串
std::string newInputData = parser.ResetInputDataString(pParamProperty->GetParameterItem()->GetInputData(), itemData.GetProperty(), itemData.GetValue());
pParamProperty->GetParameterItem()->SetInputData(newInputData);
//修改界面显示或者能用状态。
QVariant varPropertyValue(itemData.GetValue().toStdString() == pParamItem->GetStringValue() ? true : false);
emit signalDataPropertyChanged(destSubIndex, itemData.GetProperty(), varPropertyValue);
}
}
}
HandleCategoryVisible(IndexFromParameterProperty(pCategoryProperty));
}
}
}//end of is onclick
}//end of is parameteritem
}
void ParameterEditorModel::HandleDeleteButtons()
{
if(m_rootItem)
{
for(int i=0;i<m_rootItem->GetChildCount();++i)
{
if(m_rootItem->GetChild(i) == NULL)
{
continue;
}
m_rootItem->GetChild(i)->HandleDeleteButton();
}
}
}
void ParameterEditorModel::SetModuleInfo(pai::workflow::CModuleInformation *pModuleInfo)
{
m_pModuleInfo=pModuleInfo;
}
void ParameterEditorModel::StartValidation(ValidateEventSource eventSource)
{
// if(m_pModuleInfo != NULL)
// {
// QThreadPool *pThreadPool = PaiThreadPoolManager::GetInstance()->GetThreadPool(m_workflowID);
// if (pThreadPool != NULL)
// {
// m_pValidateThread = new CParameterValidateThread(m_pModuleInfo, eventSource);
// connect(m_pValidateThread, SIGNAL(finished()), this, SLOT(slotOnParameterValidated()));
// pThreadPool->start(m_pValidateThread);
// }
// }
}
// void ParameterEditorModel::StopValidation()
// {
// QThreadPool *pThreadPool = PaiThreadPoolManager::GetInstance()->GetThreadPool(m_workflowID);
// if (pThreadPool != NULL)
// {
// pThreadPool->waitForDone();
// }
// }