453 lines
17 KiB
C++
453 lines
17 KiB
C++
|
|
/*
|
|||
|
|
* ParameterItemDelegate.cpp
|
|||
|
|
*
|
|||
|
|
* Created on: 2011-9-16
|
|||
|
|
* Author: dev
|
|||
|
|
*/
|
|||
|
|
#include <cassert>
|
|||
|
|
#include <QTreeView>
|
|||
|
|
#include <QSpinBox>
|
|||
|
|
#include <QDoubleSpinBox>
|
|||
|
|
#include <QDebug>
|
|||
|
|
#include <QAbstractItemView>
|
|||
|
|
#include <QPainter>
|
|||
|
|
#include <QString>
|
|||
|
|
#include <QSize>
|
|||
|
|
#include <QLabel>
|
|||
|
|
#include <QApplication>
|
|||
|
|
#include <QCheckBox>
|
|||
|
|
#include <QDialogButtonBox>
|
|||
|
|
// #include "ObjectEvent.h"
|
|||
|
|
#include "ParameterItemDelegate.h"
|
|||
|
|
#include "ParameterProperty.h"
|
|||
|
|
#include "ParameterItem.h"
|
|||
|
|
#include "ParameterEditor.h"
|
|||
|
|
#include "PaiLineEdit.h"
|
|||
|
|
#include "PaiInfoEditor.h"
|
|||
|
|
#include "ParameterTableWidget.h"
|
|||
|
|
#include "PaiLineEdit.h"
|
|||
|
|
#include "PaiToolButton.h"
|
|||
|
|
#include "PaiObjectBrowser.h"
|
|||
|
|
#include "ParameterEditorModel.h"
|
|||
|
|
#include "WorkflowConst.h"
|
|||
|
|
#include "CStringType.h";
|
|||
|
|
#include <QTextCodec>
|
|||
|
|
using namespace pai;
|
|||
|
|
using namespace pai::gui;
|
|||
|
|
using namespace pai::module;
|
|||
|
|
using namespace pai::graphics2d;
|
|||
|
|
|
|||
|
|
ParameterItemDelegate::ParameterItemDelegate(CParameterEditor* pView) :
|
|||
|
|
m_pView(pView)
|
|||
|
|
{
|
|||
|
|
// TODO Auto-generated constructor stub
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ParameterItemDelegate::~ParameterItemDelegate()
|
|||
|
|
{
|
|||
|
|
// TODO Auto-generated destructor stub
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QWidget *ParameterItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& /*option*/,
|
|||
|
|
const QModelIndex & index) const
|
|||
|
|
{
|
|||
|
|
QWidget* editor = 0;
|
|||
|
|
ParameterProperty* parameterPro = static_cast<ParameterProperty*> (index.internalPointer());
|
|||
|
|
if ((parameterPro != NULL) && (parameterPro->IsParameterItem()))
|
|||
|
|
{
|
|||
|
|
if (index.column() == 0)
|
|||
|
|
return 0;
|
|||
|
|
if (index.column() == 1)
|
|||
|
|
{
|
|||
|
|
editor = new CPaiInfoEditor(parameterPro, parent,parameterPro->GetDisplayName());
|
|||
|
|
if(parent){
|
|||
|
|
CPaiInfoEditor*pInE=dynamic_cast<CPaiInfoEditor*>(editor);
|
|||
|
|
if(pInE)
|
|||
|
|
{
|
|||
|
|
QLineEdit *pEdit=dynamic_cast<QLineEdit *>(pInE->GetInternalEditor());
|
|||
|
|
if(pEdit){
|
|||
|
|
pEdit->setFont(parent->font());//parent->font());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
connect(editor, SIGNAL(_signalInternalEditorLostFocus(const QString &)), this, SLOT(slotOnFinishEditing(const QString &)));
|
|||
|
|
|
|||
|
|
if(((CPaiInfoEditor*)editor)->HasDeleteButton())
|
|||
|
|
{
|
|||
|
|
//如果用户点击了删除按钮,由model负责删除参数面板树上的条目
|
|||
|
|
connect(editor, SIGNAL(signalDeleteItem(const QString&)), index.model(), SLOT(slotOnDeleteItem(const QString&)));
|
|||
|
|
//如果用户点击了隐藏显示按钮,由model负责控制参数面板树上的条目显示与否
|
|||
|
|
connect(editor, SIGNAL(signalHideShowItems(const QString&,bool)), index.model(), SLOT(slotOnHideShowItem(const QString&,bool)));
|
|||
|
|
//如果用户点击了隐藏显示按钮,由model负责控制参数面板树上的条目显示与否
|
|||
|
|
connect(editor, SIGNAL(signalHideShowOptionalItems(const QString&,bool)), index.model(), SLOT(slotOnHideShowOptionalItem(const QString&,bool)));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(parameterPro->GetParameterItem()->GetName().toStdString().find("Overwrite") != std::string::npos
|
|||
|
|
|| parameterPro->GetParameterItem()->GetId() == "SurfaceID")
|
|||
|
|
{
|
|||
|
|
connect(index.model(),SIGNAL(signalDataPropertyChanged(const QModelIndex& ,const QString& ,const QVariant&)),
|
|||
|
|
editor, SLOT(slotDataPropertyChanged(const QModelIndex& ,const QString& ,const QVariant&)));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(parameterPro->GetParameterItem()->GetInputData().find("Disable;") != std::string::npos ||
|
|||
|
|
parameterPro->GetParameterItem()->GetInputData().find("Enable;") != std::string::npos)
|
|||
|
|
{
|
|||
|
|
connect(index.model(),SIGNAL(signalDataPropertyChanged(const QModelIndex& ,const QString& ,const QVariant&)),
|
|||
|
|
editor, SLOT(slotDataPropertyChanged(const QModelIndex& ,const QString& ,const QVariant&)));
|
|||
|
|
if(parameterPro->GetParameterItem()->GetInputData().find("Disable;") != std::string::npos)
|
|||
|
|
((CPaiInfoEditor *)editor)->slotDataPropertyChanged(index ,QString("Ability") ,QVariant(false));
|
|||
|
|
else
|
|||
|
|
((CPaiInfoEditor *)editor)->slotDataPropertyChanged(index ,QString("Ability") ,QVariant(true));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if((parameterPro != NULL) && (parameterPro->IsCategory()))
|
|||
|
|
{
|
|||
|
|
if (index.column() == 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (index.column() == 1)
|
|||
|
|
{
|
|||
|
|
CParameterItem * pArrayParameterItem = parameterPro->GetParameterItem();
|
|||
|
|
if(pArrayParameterItem != NULL && pArrayParameterItem->GetType() == pai::module::ParmType_ARRAY)//如果一个分类项它拥有数组参数项,那就意味着需要在分类项上创建增加数组项的按钮作为Editor
|
|||
|
|
{
|
|||
|
|
//我们在pArrayParameterItem的InputMetaData中预存了Add按钮的文本
|
|||
|
|
//在分类项上创建增加数组项的按钮作为Editor
|
|||
|
|
editor = new CPaiInfoEditor(parameterPro, parent,"");
|
|||
|
|
|
|||
|
|
QWidget* internelEditor=((CPaiInfoEditor*)editor)->GetInternalEditor();
|
|||
|
|
CParameterItemButtonBox* paramcategroy=dynamic_cast<CParameterItemButtonBox*>(internelEditor);
|
|||
|
|
if(paramcategroy)
|
|||
|
|
{
|
|||
|
|
// connect(paramcategroy->m_cb_Zones,SIGNAL(currentIndexChanged(int)), index.model(),SLOT(slotZoneChanged(int)));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//如果用户点击了这些按钮,由model负责添加或删除参数面板树上的条目
|
|||
|
|
connect(((CPaiInfoEditor*)editor)->GetInternalEditor(), SIGNAL(clicked(QAbstractButton *)), index.model(), SLOT(slotOnArrayItemButtonClicked(QAbstractButton *)));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return editor;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ParameterItemDelegate::slotOnFinishEditing(const QString &str1)
|
|||
|
|
{
|
|||
|
|
QWidget* pSenderEditor = dynamic_cast<QWidget*> (sender());
|
|||
|
|
CPaiInfoEditor* pInfoEditor = dynamic_cast<CPaiInfoEditor*> (pSenderEditor);
|
|||
|
|
if(pInfoEditor)
|
|||
|
|
{
|
|||
|
|
CParameterItemControl* pControl = dynamic_cast<CParameterItemControl*> (pInfoEditor->GetInternalEditor());
|
|||
|
|
if(pControl) {
|
|||
|
|
CParameterItem*pItem=pControl->GetParameterItem();
|
|||
|
|
if(pItem){
|
|||
|
|
ParameterType paramType = pItem->GetType();
|
|||
|
|
if(paramType == pai::module::ParmType_STRING)
|
|||
|
|
{
|
|||
|
|
if(str1.isEmpty()||str1==" ")
|
|||
|
|
{
|
|||
|
|
QString cs=pItem->GetCategory().c_str();
|
|||
|
|
QTextCodec *codec = QTextCodec::codecForName("UTF8");
|
|||
|
|
cs+=codec->toUnicode("不能为空!");
|
|||
|
|
AfxMessageBox(cs);
|
|||
|
|
QLineEdit*pEdit=dynamic_cast<QLineEdit*>(pInfoEditor->GetInternalEditor());
|
|||
|
|
QString dv=pItem->GetStringValue().c_str();
|
|||
|
|
if(pEdit)pEdit->setText(dv);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (paramType == pai::module::ParmType_INT)
|
|||
|
|
{
|
|||
|
|
bool ok = false;
|
|||
|
|
int intValue = str1.toInt(&ok);
|
|||
|
|
if (ok == true)
|
|||
|
|
pItem->SetValue(intValue);
|
|||
|
|
else
|
|||
|
|
pItem->SetValue(str1.toStdString());
|
|||
|
|
pItem->SetStringValue(str1.toStdString());
|
|||
|
|
}
|
|||
|
|
else if (paramType == pai::module::ParmType_DOUBLE)
|
|||
|
|
{
|
|||
|
|
bool ok = false;
|
|||
|
|
double Value = str1.toDouble(&ok);
|
|||
|
|
if (ok == true)
|
|||
|
|
pItem->SetValue(Value);
|
|||
|
|
else
|
|||
|
|
pItem->SetValue(str1.toStdString());
|
|||
|
|
pItem->SetStringValue(str1.toStdString());
|
|||
|
|
}
|
|||
|
|
else if (paramType == pai::module::ParmType_FLOAT)
|
|||
|
|
{
|
|||
|
|
bool ok = false;
|
|||
|
|
float Value=str1.toFloat(&ok);
|
|||
|
|
if (ok == true)
|
|||
|
|
{
|
|||
|
|
QString str=pItem->GetId().c_str();
|
|||
|
|
if(str.indexOf("ZoneBottom")>-1||str.indexOf("ZoneTop")>-1)
|
|||
|
|
{
|
|||
|
|
if(str.indexOf("ZoneBottom")>-1)
|
|||
|
|
{
|
|||
|
|
str.replace("ZoneBottom","ZoneTop");
|
|||
|
|
CCompositeParameterItem *pParentItem=dynamic_cast<CCompositeParameterItem*>(pItem->GetParentItem());
|
|||
|
|
if(pParentItem){
|
|||
|
|
CParameterItem*pItem2=pParentItem->GetParameterItem(str.toStdString());
|
|||
|
|
if(pItem2){
|
|||
|
|
float val1=pItem2->GetValue(0.0);
|
|||
|
|
/*
|
|||
|
|
if(val1>Value) {
|
|||
|
|
QTextCodec *codec = QTextCodec::codecForName("UTF8");
|
|||
|
|
AfxMessageBox(codec->toUnicode("处理井段底深小于顶深,无效!"));
|
|||
|
|
QLineEdit*pEdit=dynamic_cast<QLineEdit*>(pInfoEditor->GetInternalEditor());
|
|||
|
|
QString dv=pItem->GetStringValue().c_str();
|
|||
|
|
if(pEdit)pEdit->setText(dv);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
*/
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if(str.indexOf("ZoneTop")>-1)
|
|||
|
|
{
|
|||
|
|
str.replace("ZoneTop","ZoneBottom");
|
|||
|
|
CCompositeParameterItem *pParentItem=dynamic_cast<CCompositeParameterItem*>(pItem->GetParentItem());
|
|||
|
|
if(pParentItem){
|
|||
|
|
CParameterItem*pItem2=pParentItem->GetParameterItem(str.toStdString());
|
|||
|
|
if(pItem2){
|
|||
|
|
float val1=pItem2->GetValue(0.0);
|
|||
|
|
/*
|
|||
|
|
if(val1<Value) {
|
|||
|
|
QTextCodec *codec = QTextCodec::codecForName("UTF8");
|
|||
|
|
AfxMessageBox(codec->toUnicode("处理井段顶深大于底深,无效!"));
|
|||
|
|
QLineEdit*pEdit=dynamic_cast<QLineEdit*>(pInfoEditor->GetInternalEditor());
|
|||
|
|
QString dv=pItem->GetStringValue().c_str();
|
|||
|
|
if(pEdit)pEdit->setText(dv);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
*/
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
pItem->SetValue(Value);
|
|||
|
|
pItem->SetStringValue(str1.toStdString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (paramType == pai::module::ParmType_BOOL)
|
|||
|
|
{
|
|||
|
|
pItem->SetValue(str1.toInt());
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
if(pItem->GetInputType()!=HDFSFILEBROWSER && pItem->GetInputType()!= HDFSFILEEDITOR)
|
|||
|
|
{
|
|||
|
|
pItem->SetStringValue(str1.toStdString());
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
pItem->SetDefault(str1.toStdString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
QString str=pItem->GetId().c_str();
|
|||
|
|
if(str.indexOf("ZoneBottom")>-1||str.indexOf("ZoneTop")>-1)
|
|||
|
|
{
|
|||
|
|
ParameterEditorModel* pModel = dynamic_cast<ParameterEditorModel*>(m_pView->model());
|
|||
|
|
if(pModel) {
|
|||
|
|
pModel->FreshDepth("Zones");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if(str.indexOf('.')>-1) {
|
|||
|
|
str=str.left(str.indexOf('.'));
|
|||
|
|
ParameterEditorModel* pModel = dynamic_cast<ParameterEditorModel*>(m_pView->model());
|
|||
|
|
if(pModel) {
|
|||
|
|
pModel->OnZoneValueChanged(str);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
emit commitData(pSenderEditor);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ParameterItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
|||
|
|
{
|
|||
|
|
ParameterProperty *paramProperty = static_cast<ParameterProperty*> (index.internalPointer());
|
|||
|
|
|
|||
|
|
CPaiInfoEditor* pInfoEditor = dynamic_cast<CPaiInfoEditor*> (editor);
|
|||
|
|
if(pInfoEditor == NULL)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
CParameterItemControl* pControl = dynamic_cast<CParameterItemControl*> (pInfoEditor->GetInternalEditor());
|
|||
|
|
CPaiObjectBrowser* pBrowser = dynamic_cast<CPaiObjectBrowser*> (pInfoEditor->GetInternalEditor());
|
|||
|
|
ParameterEditorModel* pModel = dynamic_cast<ParameterEditorModel*>(m_pView->model());
|
|||
|
|
if(pBrowser && pModel)
|
|||
|
|
{
|
|||
|
|
connect(pBrowser, SIGNAL(signalLayerPickFileChanged(const QString&)), pModel, SLOT(slotBuildMaxEnergySurfaceIDs(const QString&)), Qt::UniqueConnection);
|
|||
|
|
}
|
|||
|
|
if(pControl != NULL)
|
|||
|
|
{
|
|||
|
|
pControl->SetDisplayValue(index.model()->data(index, Qt::EditRole));
|
|||
|
|
QVariant varBackgroudValue(index.model()->data(index, ParameterEditorModel::HDFSFileRole));
|
|||
|
|
if(varBackgroudValue.isValid())
|
|||
|
|
{
|
|||
|
|
pControl->SetValue(varBackgroudValue);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
connect(paramProperty,SIGNAL(signalSetErrorMessage(const QString&)),pInfoEditor,SLOT(slotSetErrorMessage(const QString&)),Qt::UniqueConnection);
|
|||
|
|
connect(paramProperty,SIGNAL(signalFinishValidation()),pInfoEditor,SLOT(slotStopAnimate()),Qt::UniqueConnection);
|
|||
|
|
connect(paramProperty,SIGNAL(signalShouldShowDeleteButton(bool)),pInfoEditor,SLOT(slotShowDeleteButton(bool)),Qt::UniqueConnection);
|
|||
|
|
connect(paramProperty,SIGNAL(signalHideShowItemsIcon(bool)),pInfoEditor,SLOT(slotUpdateHideShowItemsIcon(bool)),Qt::UniqueConnection);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ParameterItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
|||
|
|
{
|
|||
|
|
ParameterProperty *paramProperty = static_cast<ParameterProperty*> (index.internalPointer());
|
|||
|
|
|
|||
|
|
pai::module::ParameterInputType paramInputType = paramProperty->GetInputType();
|
|||
|
|
|
|||
|
|
CPaiInfoEditor* pInfoEditor = dynamic_cast<CPaiInfoEditor*> (editor);
|
|||
|
|
if(pInfoEditor == NULL) return;
|
|||
|
|
|
|||
|
|
CParameterItemControl* pControl = dynamic_cast<CParameterItemControl*> (pInfoEditor->GetInternalEditor());
|
|||
|
|
if(pControl != NULL)
|
|||
|
|
{
|
|||
|
|
model->setData(index, pControl->GetDisplayValue(), Qt::EditRole);
|
|||
|
|
|
|||
|
|
if(paramInputType==pai::module::HDFSFILEBROWSER || paramInputType==pai::module::HDFSFILEEDITOR)
|
|||
|
|
{
|
|||
|
|
model->setData(index, pControl->GetValue(), ParameterEditorModel::HDFSFileRole);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QWidget* pWidget = dynamic_cast<QWidget*> (pInfoEditor->GetInternalEditor());
|
|||
|
|
if (NULL != pWidget)
|
|||
|
|
{
|
|||
|
|
if(paramInputType==pai::module::EDITABLEDGRID)
|
|||
|
|
{
|
|||
|
|
// do noting
|
|||
|
|
}
|
|||
|
|
else if (!paramProperty->GetParameterItem()->SameAsDefault()
|
|||
|
|
|| paramInputType==pai::module::HDFSFILEBROWSER
|
|||
|
|
|| paramInputType==pai::module::HDFSFILEEDITOR)
|
|||
|
|
{
|
|||
|
|
pWidget->setProperty("IsSameWithDefault", false);
|
|||
|
|
pWidget->update();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
pWidget->setProperty("IsSameWithDefault", true);
|
|||
|
|
pWidget->update();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ParameterEditorModel* pModel = dynamic_cast<ParameterEditorModel*>(m_pView->model());
|
|||
|
|
if(pModel != NULL)
|
|||
|
|
{
|
|||
|
|
// pModel->StartValidation();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ParameterItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
|
|||
|
|
{
|
|||
|
|
ParameterProperty* paramPro = static_cast<ParameterProperty*> (index.internalPointer());
|
|||
|
|
if (paramPro->IsCategory())
|
|||
|
|
{
|
|||
|
|
if (paramPro->GetChildCount() == 0)
|
|||
|
|
{
|
|||
|
|
if (m_pView->selectionModel()->isSelected(index))
|
|||
|
|
{
|
|||
|
|
QLinearGradient linearGrad(option.rect.topLeft(), option.rect.bottomLeft());
|
|||
|
|
linearGrad.setColorAt(0.0, QColor("#F6FDFF"));
|
|||
|
|
linearGrad.setColorAt(1.0, QColor("#DAF3FD"));
|
|||
|
|
painter->fillRect(option.rect,QBrush(linearGrad));
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
QLinearGradient linearGrad(option.rect.topLeft(), option.rect.bottomLeft());
|
|||
|
|
linearGrad.setColorAt(0.0, QColor("#E7F1F8"));
|
|||
|
|
linearGrad.setColorAt(1.0, QColor("#D5E4F2"));
|
|||
|
|
painter->fillRect(option.rect,QBrush(linearGrad));
|
|||
|
|
}
|
|||
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|||
|
|
|
|||
|
|
painter->setPen(QPen(QBrush(QColor("#ADBEC8")), 1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
|
|||
|
|
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
painter->setPen(QPen(QBrush(QColor("#FFFFFF")), 1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
|
|||
|
|
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
|||
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|||
|
|
|
|||
|
|
if(paramPro->IsParameterItem()
|
|||
|
|
&& paramPro->GetParameterItem()->IsNessary()
|
|||
|
|
&& index.column()==0)
|
|||
|
|
{
|
|||
|
|
painter->setPen(Qt::red);
|
|||
|
|
QString strStar("* ");
|
|||
|
|
int iHOffset = painter->fontMetrics().width(strStar);
|
|||
|
|
int iVOffset = option.rect.height()/2 - g_iParameterItemStarMargin;
|
|||
|
|
pai::module::ParameterInputType paramInputType = paramPro->GetInputType();
|
|||
|
|
if(paramInputType==pai::module::EDITABLEDGRID || paramInputType==pai::module::CHECKBOX)
|
|||
|
|
{
|
|||
|
|
iHOffset = option.rect.width() + g_iParameterItemStarMargin;
|
|||
|
|
}
|
|||
|
|
painter->drawText(option.rect.bottomRight()-QPoint(iHOffset,iVOffset), strStar);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QSize ParameterItemDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
QSize size = QStyledItemDelegate::sizeHint(option, index);
|
|||
|
|
|
|||
|
|
ParameterProperty* paramPro = static_cast<ParameterProperty*> (index.internalPointer());
|
|||
|
|
if(!paramPro)return size;
|
|||
|
|
if(paramPro->GetInputType()==pai::module::SPLIT) {
|
|||
|
|
CParameterItem *pItem=paramPro->GetParameterItem();
|
|||
|
|
QString str=pItem->GetInputMetaData().c_str();
|
|||
|
|
QStringList strs=str.split('/');
|
|||
|
|
int n=strs.size()/4+1;
|
|||
|
|
int m=strs.size()%4;
|
|||
|
|
if(n&&m==0) n-=1;
|
|||
|
|
size.setHeight(n*20);
|
|||
|
|
size.setWidth(4*20+10);//for red *
|
|||
|
|
}
|
|||
|
|
else if (paramPro->IsCategory())
|
|||
|
|
{
|
|||
|
|
size.setHeight(30);
|
|||
|
|
// size.rwidth() += 10;//for red *
|
|||
|
|
}
|
|||
|
|
// size.rwidth() += 10;//for red *
|
|||
|
|
return size;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ParameterItemDelegate::updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option,
|
|||
|
|
const QModelIndex & index) const
|
|||
|
|
{
|
|||
|
|
QStyleOptionViewItem smallRectOption(option);
|
|||
|
|
|
|||
|
|
smallRectOption.rect.adjust(0, 0, -20, 0);
|
|||
|
|
|
|||
|
|
ParameterProperty* paramProperty = static_cast<ParameterProperty*> (index.internalPointer());
|
|||
|
|
CParameterItem *paramItem = paramProperty->GetParamItem();
|
|||
|
|
if(paramItem!=NULL && (paramItem->GetInputType()==pai::module::EDITABLEDGRID || paramItem->GetInputType()==pai::module::CHECKBOX))
|
|||
|
|
{
|
|||
|
|
QModelIndex labelModelIndex = index.sibling(index.row(),0);
|
|||
|
|
smallRectOption.rect.setLeft(m_pView->visualRect(labelModelIndex).left());//表格和checkbox的左侧与文本左侧对齐。
|
|||
|
|
}
|
|||
|
|
QStyledItemDelegate::updateEditorGeometry(editor, smallRectOption, index);
|
|||
|
|
}
|
|||
|
|
void ParameterItemDelegate::drawBackground(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|