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

489 lines
17 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.

/*
* ParameterEditor.cpp
*
* Created on: 2011-9-16
* Author: dev
*/
#include <QMainWindow>
#include <QDebug>
#include "logModuleParamers.h"
#include <QItemDelegate>
#include <QModelIndex>
#include <QPainter>
#include <QMouseEvent>
#include <QHeaderView>
// #include "ObjectEvent.h"
#include "ModuleCheckResult.h"
#include "ParameterEditor.h"
#include "ModuleParameter.h"
#include "ParameterEditorModel.h"
#include "ParameterItemDelegate.h"
#include "ModuleInformation.h"
#include "ParameterProperty.h"
#include "PaiInfoEditor.h"
// #include "TimeStampLogger.h"
// #include "ConsoleOutputWidget.h"
//item的缩进距离10像素
const int ITEM_INDENTATION = 10;
using namespace pai::workflow;
namespace pai {
namespace graphics2d {
CParameterEditor::CParameterEditor(QWidget* pParent) :
QTreeView(pParent),
m_moduleInfo(NULL),
m_model(new ParameterEditorModel()),
m_paramItemDelegate(NULL)
{
old_zoneno=-1;
setProperty("HideBorder", QVariant(true));
// this->setFixedHeight(500);
m_model->setParent(this);
connect(m_model, SIGNAL(signalMakeIndexVisible(const QModelIndex &)), this, SLOT(slotOnMakeIndexVisible(const QModelIndex &)));
connect(m_model, SIGNAL(signalBackModule(pai::workflow::CModuleInformation *)),this, SLOT(slotBackModule(pai::workflow::CModuleInformation *)));
connect(this, SIGNAL(clicked(const QModelIndex &)), this,SLOT(slotgetCurrentIndex(const QModelIndex &)));
setModel(m_model);
connect(m_model, SIGNAL(signalErrorInfoChanged(pai::workflow::CModuleInformation *, bool,const pai::module::CModuleCheckResult, ValidateEventSource)),
this, SLOT(slotShowErrors(pai::workflow::CModuleInformation *,bool, pai::module::CModuleCheckResult, ValidateEventSource)));
connect(m_model, SIGNAL(signalDataPropertyChanged(const QModelIndex&,const QString&,const QVariant&)),
this, SLOT(slotOnDataPropertyChanged(const QModelIndex&,const QString&,const QVariant&)));
connect(m_model, SIGNAL(signalExclieChanged(const QString&)),
this, SLOT(slotExclieChanged(const QString&)));
connect(m_model,SIGNAL(signalZoneValueChanged(QString )),this,SLOT(slotZoneValueChanged(QString)));
// connect( (const QObject*)( &GetObjectEvent() ),SIGNAL(DeleteDepth(QWidget *,float)),this,SLOT(slotDeleteDepth(QWidget *,float)));
// connect( (const QObject*)( &GetObjectEvent() ),SIGNAL(AddDepth(QWidget *,float)),this,SLOT(slotAddDepth(QWidget *,float)));
// connect( (const QObject*)( &GetObjectEvent() ),SIGNAL(ChangeMXParam(QWidget *,float,float,float,QString,int,int)),this,SLOT(slotChangeMXParam(QWidget *,float,float,float,QString,int,int)));
// connect( (const QObject*)( &GetObjectEvent() ),SIGNAL(ChangeCurrentParam(QWidget *,float,float)),this,SLOT(slotChangeCurrentParam(QWidget *,float,float)));
// connect( (const QObject*)( &GetObjectEvent() ),SIGNAL(ChangeExpand(QWidget *,float,int)),this,SLOT(slotChangeExpand(QWidget *,float,int)));
m_model->setHeaderData(0,Qt::Orientation::Horizontal,QString::fromLocal8Bit("Param"));
m_model->setHeaderData(1,Qt::Orientation::Horizontal,QString::fromLocal8Bit("Value"));
// header()->setMovable(false);
header()->setAutoScroll(true);
this->setColumnWidth(0,200);
this->setColumnWidth(1,220);
setIndentation(ITEM_INDENTATION);
//this 并不是Delegate的父亲对Delegate没有管理权限
//最好在ParameterItemDelegate类中也不要添加setView(...)接口保持一个Delegate对应一个view
m_paramItemDelegate = new ParameterItemDelegate(this);
setItemDelegate(m_paramItemDelegate);
//防止编辑区域比较窄时,点击属性名称列或者赋值列导致页面左右动
setAutoScroll(false);
setAlternatingRowColors(true);
}
CParameterEditor::~CParameterEditor()
{
// m_paramItemDelegate析构
if(m_paramItemDelegate)
{
delete m_paramItemDelegate;
m_paramItemDelegate = NULL;
}
}
pai::workflow::CModuleInformation *CParameterEditor::GetModuleInfo()
{
return m_moduleInfo;
}
void CParameterEditor::FinishInputData()
{
if(m_model) {
auto rCurrentItem = m_model->index(m_model->m_currentindex.row(),0,m_model->m_currentindex.parent());
this->setCurrentIndex(rCurrentItem);
// m_model->EvaluateInputData(m_model->m_currentinde);
}
}
void CParameterEditor::slotZoneValueChanged(QString zonename)
{
// if(zonename.isEmpty()) GetObjectEvent().OnRefressMXParam(this);
// else {
// float sdep,edep;
// if(m_model->GetCurrentZone(sdep,edep)) {
// GetObjectEvent().OnRefressMXParam(this,sdep,edep);
// }
// }
}
void CParameterEditor::Clear()
{
if(m_model != NULL)
{
m_model->clear();
}
m_moduleInfo = NULL;
}
bool CParameterEditor::GetCurrentZone(float &sdep,float &edep)
{
return m_model->GetCurrentZone(sdep,edep);
}
void CParameterEditor::slotAddDepth(QWidget *pWin,float depth)
{
if(!pWin) return;
float dep=(int)(depth*10+0.5)/10.0;
if(!pWin) return;
QMainWindow *pMainW=NULL;
QWidget *pW=dynamic_cast<QWidget *>(this->parent());
while(pW) {
pMainW=dynamic_cast<QMainWindow *>(pW);
if(pMainW) break;
pW=dynamic_cast<QWidget *>(pW->parent());
}
if(!pW&&!pMainW) return;
pW=dynamic_cast<QWidget *>(pWin->parent());
if(pW==dynamic_cast<QWidget*>(pMainW->parent())) {
float dep=(int)(depth*10+0.5)/10.0;
// m_model->AddDepth(dep,"Zones");
}
// GetObjectEvent().OnRefressMXParam(this);
}
void CParameterEditor::slotDeleteDepth(QWidget *pWin,float depth)
{
if(!pWin) return;
float dep=(int)(depth*10+0.5)/10.0;
if(!pWin) return;
QMainWindow *pMainW=NULL;
QWidget *pW=dynamic_cast<QWidget *>(this->parent());
while(pW) {
pMainW=dynamic_cast<QMainWindow *>(pW);
if(pMainW) break;
pW=dynamic_cast<QWidget *>(pW->parent());
}
if(!pW&&!pMainW) return;
pW=dynamic_cast<QWidget *>(pWin->parent());
if(pW==dynamic_cast<QWidget*>(pMainW->parent())) {
m_model->DeleteDepth(dep,"Zones");
}
// GetObjectEvent().OnRefressMXParam(this);
}
void CParameterEditor::slotChangeCurrentParam(QWidget *pWin,float depth,float minX)
{
float dep=(int)(depth*10+0.5)/10.0;
if(!pWin) return;
QMainWindow *pMainW=NULL;
QWidget *pW=dynamic_cast<QWidget *>(this->parent());
while(pW) {
pMainW=dynamic_cast<QMainWindow *>(pW);
if(pMainW) break;
pW=dynamic_cast<QWidget *>(pW->parent());
}
if(!pW&&!pMainW) return;
pW=dynamic_cast<QWidget *>(pWin->parent());
if(pW==dynamic_cast<QWidget*>(pMainW->parent())) {
m_model->ChangeCurrentParam(dep,minX,"Zones");
this->update();
}
}
void CParameterEditor::slotChangeExpand(QWidget *pWin,float depth,int zoneno)
{
float dep=(int)(depth*10+0.5)/10.0;
if(!pWin) return;
QMainWindow *pMainW=NULL;
QWidget *pW=dynamic_cast<QWidget *>(this->parent());
while(pW) {
pMainW=dynamic_cast<QMainWindow *>(pW);
if(pMainW) break;
pW=dynamic_cast<QWidget *>(pW->parent());
}
if(!pW&&!pMainW) return;
pW=dynamic_cast<QWidget *>(pWin->parent());
if(pW==dynamic_cast<QWidget*>(pMainW->parent())) {
QModelIndex index=m_model->ChangeExpand(dep,zoneno,"Zones");
if(zoneno!= old_zoneno) {
slotExclieChanged("Zones");
this->expand(index);
}
old_zoneno=zoneno;
this->update();
}
}
void CParameterEditor::slotChangeMXParam(QWidget *pWin,float depth,float minX,float maxX,QString curvename,int zoneno,int changetype)
{
float dep=(int)(depth*10+0.5)/10.0;
if(!pWin) return;
QMainWindow *pMainW=NULL;
QWidget *pW=dynamic_cast<QWidget *>(this->parent());
while(pW) {
pMainW=dynamic_cast<QMainWindow *>(pW);
if(pMainW) break;
pW=dynamic_cast<QWidget *>(pW->parent());
}
if(!pW&&!pMainW) return;
pW=dynamic_cast<QWidget *>(pWin->parent());
if(pW==dynamic_cast<QWidget*>(pMainW->parent())) {
m_model->ChangeMXParam(dep,minX,maxX,curvename,zoneno,changetype,"Zones");
this->update();
CModuleParamers *pMP=dynamic_cast<CModuleParamers *>(pMainW);
if(pMP) {
pMP->slotRunCurrentZone();
}
}
}
void CParameterEditor::slotExclieChanged(const QString& id)
{
QModelIndex a;
ParameterProperty *rootItem= m_model->ParameterPropertyFromIndex(a);
ParameterProperty* pArrayCategory = rootItem->GetParameterProperty(id.toStdString());
if(pArrayCategory) {
a=m_model->IndexFromParameterProperty(pArrayCategory);
int rowCount = m_model->rowCount(a);
if(rowCount>0)
{
for(int i=0;i<rowCount;i++)
{
QModelIndex childIndex = a.child(i,0);
int rowCount1 = m_model->rowCount(childIndex);
if(rowCount1>0) {
for(int j=0;j<rowCount1;j++) {
QModelIndex childIndex1 = childIndex.child(j,0);
setExpanded(childIndex1,false);
}
}
setExpanded(childIndex,false);
}
}
}
}
void CParameterEditor::slotgetCurrentIndex(const QModelIndex &index)
{
m_model->m_currentindex=index;
}
void CParameterEditor::slotOnMakeIndexVisible(const QModelIndex &index)
{
scrollTo(index, QAbstractItemView::PositionAtTop);
}
void CParameterEditor::slotOpen(pai::workflow::CModuleInformation* pInfo, bool IsModuleReadOnly)
{
if (IsModuleReadOnly || pInfo == m_moduleInfo)
{
return;
}
// pai::gui::TimeStampLogger::GetInstance().WriteGUIBenchMarkLog("Workflow", true, "Open parameter editor");
Init(pInfo);
if (!pInfo || pInfo->IsBlankModule())
return;
// this->expandToDepth(1);
// this->expandAll();
// resizeColumnToContents(0);
// pai::gui::TimeStampLogger::GetInstance().WriteGUIBenchMarkLog("Workflow", false, "Open parameter editor");
}
void CParameterEditor::slotForceOpen(pai::workflow::CModuleInformation* pInfo)
{
// pai::gui::TimeStampLogger::GetInstance().WriteGUIBenchMarkLog("Workflow", true, "Open parameter editor");
Init(pInfo);
if (!pInfo || pInfo->IsBlankModule())
return;
CModuleParameter* param = pInfo->GetModule()->GetModuleParameter();
if(param) {
QModelIndex a;
ParameterProperty *rootItem= m_model->ParameterPropertyFromIndex(a);
ParameterProperty* pArrayCategory = rootItem->GetParameterProperty("Zones");
if(pArrayCategory) {
a=m_model->IndexFromParameterProperty(pArrayCategory);
expand(a);
}
}
// this->expandToDepth(1);
// this->expandAll();
//resizeColumnToContents(0);
// pai::gui::TimeStampLogger::GetInstance().WriteGUIBenchMarkLog("Workflow", false, "Open parameter editor");
}
void CParameterEditor::drawBranches(QPainter * pPainter, const QRect & rect, const QModelIndex & index) const
{
ParameterProperty *childItem = static_cast<ParameterProperty*> (index.internalPointer());
if ((childItem != NULL) && (childItem->IsCategory()))
{
if (childItem->GetChildCount() == 0)
{
if (selectionModel()->isSelected(index))
{
QLinearGradient linearGrad(rect.topLeft(), rect.bottomLeft());
linearGrad.setColorAt(0.0, QColor("#F6FDFF"));
linearGrad.setColorAt(1.0, QColor("#DAF3FD"));
pPainter->fillRect(rect,QBrush(linearGrad));
pPainter->setPen(QPen(QBrush(QColor("#ADBEC8")), 1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
pPainter->drawLine(rect.bottomLeft(), rect.bottomRight());
}
else
{
QLinearGradient linearGrad(rect.topLeft(), rect.bottomLeft());
linearGrad.setColorAt(0.0, QColor("#E7F1F8"));
linearGrad.setColorAt(1.0, QColor("#D5E4F2"));
pPainter->fillRect(rect,QBrush(linearGrad));
pPainter->setPen(QPen(QBrush(QColor("#ADBEC8")), 1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
pPainter->drawLine(rect.bottomLeft(), rect.bottomRight());
}
}
else
{
QTreeView::drawBranches(pPainter, rect, index);
}
}
else
{
pPainter->setPen(QPen(QBrush(QColor("#FFFFFF")), 1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
pPainter->drawLine(rect.bottomLeft(), rect.bottomRight());
QTreeView::drawBranches(pPainter, rect, index);
}
}
void CParameterEditor::rowsInserted ( const QModelIndex & parent, int start, int end )
{
QTreeView::rowsInserted(parent,start,end);
for(int i=start;i<=end;++i)
{
if(i==start){//测井项目的每个井段要先打开{
openPersistentEditor(parent.child(i,1));
openPersistentEditor(parent.child(i+1,1));}
if(parent.child(i,1).data(Qt::UserRole).toString().contains("Invisible"))
{
setRowHidden(i,parent,true);
}
}
}
void CParameterEditor::slotOnDataPropertyChanged(const QModelIndex& dataIndex,const QString& strPropertyName,const QVariant& varPropertyValue)
{
if(strPropertyName=="Visible")
{
bool bVisible = varPropertyValue.toBool();
setRowHidden(dataIndex.row(),dataIndex.parent(),!bVisible);
}
}
void CParameterEditor::slotShowErrors(pai::workflow::CModuleInformation *pModuleInfo,bool, CModuleCheckResult /*errorInfo*/, ValidateEventSource /*eventSource*/)
{
//如果m_moduleInfo发生变化表示参数编辑界面要展现另一个模块则原来的线程校验结果没有必要显示
if (pModuleInfo == m_moduleInfo)
{
//显示校验信息时如果有QDoubleSpinBoxQSpinBoxQLineEdit
//三种控件,使用默认风格
setStyleSheet("QDoubleSpinBox;QSpinBox;QLineEdit");
}
}
void CParameterEditor::slotBackModule(CModuleInformation *pBakcModule)
{
if(!pBakcModule)
{
return;
}
Init(pBakcModule);
CModuleParameter* param = pBakcModule->GetModule()->GetModuleParameter();
if(param) {
QModelIndex a;
ParameterProperty *rootItem= m_model->ParameterPropertyFromIndex(a);
ParameterProperty* pArrayCategory = rootItem->GetParameterProperty("Zones");
if(pArrayCategory) {
a=m_model->IndexFromParameterProperty(pArrayCategory);
expand(a);
}
}
// this->expandToDepth(1);
// this->expandAll();
//resizeColumnToContents(0);
}
void CParameterEditor::resizeEvent ( QResizeEvent * pEvent )
{
QTreeView::resizeEvent(pEvent);
//在重置parameters页签大小时QDoubleSpinBoxQSpinBoxQLineEdit
//三种控件用默认风格显示。QDoubleSpinBox和QSpinBox两种控件目前在parameters页签
//中没有用到而QLineEdit控件重置大小时用不用默认的风格没有任何的区别
setStyleSheet("QDoubleSpinBox;QSpinBox;QLineEdit");
}
void CParameterEditor::Init(CModuleInformation *pInfo)
{
// //在初始化模块参数面板的model之前把上次的显示内容清理掉
// // AppendConsole(pai::log::PAI_DEBUG,"param model clearing...");
// if(m_model&&!m_model->m_CompositeMethod)//单方法模式下,不进行清空
// Clear();//TODOAIYA
//从slf文件读取参数卡
//////////////////////////////////////////////////
// AppendConsole(pai::log::PAI_DEBUG,"param model cleared");
if (pInfo == NULL || pInfo->IsBlankModule())
{
return;
}
//保证计算属性控件的sizeHint为显示后真实需要的
if (isVisible() == false)
{
setVisible(true);
}
m_moduleInfo = pInfo;
// AppendConsole(pai::log::PAI_DEBUG,"param model generating...");
if(m_model)
{
m_model->BuildItems(m_moduleInfo);
}
reset();
// AppendConsole(pai::log::PAI_DEBUG,"param model generated");
// AppendConsole(pai::log::PAI_DEBUG,"param editor generating...");
if(m_model)
{
// AppendConsole(pai::log::PAI_DEBUG," param editor RowCount="+QString::number(m_model->rowCount(), 10));
for (int i = 1; i < m_model->rowCount(); i++)
{
// if(i>=3)
setFirstColumnSpanned(i, QModelIndex(), true);
QModelIndex categoryIndex = m_model->index(i, 0, QModelIndex());
ParameterProperty *pP1=m_model->ParameterPropertyFromIndex(categoryIndex);
// AppendConsole(pai::log::PAI_DEBUG," param editor category RowCount="+QString::number(m_model->rowCount(categoryIndex), 10));
for (int j = 0; j < m_model->rowCount(categoryIndex); j++)
{
QModelIndex parameterIndex = m_model->index(j, 1, categoryIndex);
if(i<=1&&!m_model->m_CompositeMethod)//测井项目的输入曲线部分要接受拖拽,数量较少,因此先打开,多模块场景都打开
this->openPersistentEditor(parameterIndex);
if(m_model->m_CompositeMethod) this->openPersistentEditor(parameterIndex);
if(parameterIndex.data(Qt::UserRole).toString().contains("Invisible"))
{
setRowHidden(j,categoryIndex,true);
}
}
m_model->HandleCategoryVisible(categoryIndex);
//setExpanded(categoryIndex, true);
}
//打开数组分类项的Add按钮
// AppendConsole(pai::log::PAI_DEBUG," param editor Add button adding...");
for (int i = 0; i < m_model->rowCount(); i++)
{
QModelIndex categoryIndex = m_model->index(i, 1, QModelIndex());
this->openPersistentEditor(categoryIndex);
}
//更新删除按钮的显示或隐藏
m_model->HandleDeleteButtons();
// AppendConsole(pai::log::PAI_DEBUG," param editor Add buuton added");
}
setFirstColumnSpanned(0,QModelIndex(),true);
m_model->slotZoneChanged(0);
// AppendConsole(pai::log::PAI_DEBUG,"param editor generated");
}
}
}