593 lines
16 KiB
C++
593 lines
16 KiB
C++
/*
|
|
* ParameterItemControl.cpp
|
|
*
|
|
* Created on: 2012-3-27
|
|
* Author: dev
|
|
*/
|
|
#include <cassert>
|
|
#include <limits>
|
|
#include <float.h>
|
|
#include <QtDebug>
|
|
#include <QDropEvent>
|
|
#include <QHBoxLayout>
|
|
#include "ParameterItemControl.h"
|
|
#include "WorkflowConst.h"
|
|
#include "PaiRadioButton.h"
|
|
#include "PaiPushButton.h"
|
|
#include "PaiValidator.h"
|
|
// #include "error.h"
|
|
using namespace pai::gui;
|
|
using namespace pai::module;
|
|
/**
|
|
* @brief 设置输入限制
|
|
*/
|
|
void SetValidator(pai::module::ParameterType eParamType, QLineEdit *pLineEdit, bool isNessary)
|
|
{
|
|
if(pLineEdit == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (eParamType == pai::module::ParmType_INT || eParamType == pai::module::ParmType_LONG)
|
|
{
|
|
PaiIntValidator *dator = new PaiIntValidator(-2147483647, 2147483647, pLineEdit);
|
|
dator->SetSupportNullString(!isNessary);
|
|
pLineEdit->setValidator(dator);
|
|
}
|
|
else if (eParamType == pai::module::ParmType_FLOAT || eParamType == pai::module::ParmType_DOUBLE)
|
|
{
|
|
QRegExp regExp("(^-?(([1-9][0-9]{0,9})|(0))\\.([0-9]{0,9}[0-9])$)|(^-?[1-9][0-9]{0,9}$)|(^0$)" + (isNessary? QString() : QString("|(^$)")));
|
|
QRegExpValidator *dator = new QRegExpValidator(regExp,pLineEdit);
|
|
pLineEdit->setValidator(dator);
|
|
}
|
|
}
|
|
|
|
CParameterItemControl::CParameterItemControl(CParameterItem* pParameterItem)
|
|
:m_pParameterItem(pParameterItem)
|
|
{
|
|
|
|
}
|
|
|
|
CParameterItemControl::~CParameterItemControl()
|
|
{
|
|
}
|
|
////////////////////////////////RADIOBUTTON///////////////////////////
|
|
CParameterItemRadioButtonGroup::CParameterItemRadioButtonGroup(CParameterItem* pParameterItem,QWidget* pParent)
|
|
:QGroupBox(pParent),CParameterItemControl(pParameterItem)
|
|
{
|
|
QHBoxLayout* pLayout = new QHBoxLayout;
|
|
pLayout->setMargin(0);
|
|
pLayout->setSpacing(0);
|
|
|
|
QString strInputMetaData = QString::fromStdString(pParameterItem->GetInputMetaData());
|
|
QStringList strComboboxTexts = strInputMetaData.split('/');
|
|
for (int i = 0; i < strComboboxTexts.size(); ++i)
|
|
{
|
|
PaiRadioButton *pButton = new PaiRadioButton(strComboboxTexts[i]);
|
|
connect(pButton, SIGNAL(toggled(bool)), this, SLOT(slotOnToggled(bool)));
|
|
pLayout->addWidget(pButton);
|
|
}
|
|
|
|
setLayout(pLayout);
|
|
}
|
|
void CParameterItemRadioButtonGroup::slotOnToggled(bool toggled)
|
|
{
|
|
if (toggled == true)
|
|
emit signalInternalIndexChanged();
|
|
}
|
|
QVariant CParameterItemRadioButtonGroup::GetDisplayValue() const
|
|
{
|
|
if(m_pParameterItem == NULL)
|
|
{
|
|
return QVariant();
|
|
}
|
|
|
|
pai::module::ParameterType eParamType = m_pParameterItem->GetType();
|
|
QList<QObject*> childrenList = children();
|
|
int index = 0;
|
|
for (int i = 0; i < childrenList.size(); ++i)
|
|
{
|
|
QRadioButton *pButton = dynamic_cast<QRadioButton *>(childrenList[i]);
|
|
if (NULL != pButton)
|
|
{
|
|
if (pButton->isChecked() == true)
|
|
{
|
|
if (eParamType == pai::module::ParmType_INT || eParamType == pai::module::ParmType_LONG)
|
|
return index;
|
|
else //STRING
|
|
return pButton->text();
|
|
}
|
|
else
|
|
index++;
|
|
}
|
|
}
|
|
return QVariant();
|
|
}
|
|
void CParameterItemRadioButtonGroup::installEventFilter(QObject * filterObj)
|
|
{
|
|
QList<QObject*> childrenList = children();
|
|
for (int i = 0; i < childrenList.size(); ++i)
|
|
{
|
|
QRadioButton *pButton = dynamic_cast<QRadioButton *>(childrenList[i]);
|
|
if (NULL != pButton)
|
|
{
|
|
pButton->installEventFilter(filterObj);
|
|
}
|
|
}
|
|
}
|
|
QVariant CParameterItemRadioButtonGroup::GetValue() const
|
|
{
|
|
return GetDisplayValue();
|
|
}
|
|
void CParameterItemRadioButtonGroup::SetDisplayValue(const QVariant& varDisplayValue)
|
|
{
|
|
SetValue(varDisplayValue);
|
|
}
|
|
void CParameterItemRadioButtonGroup::SetValue(const QVariant& varValue)
|
|
{
|
|
if(m_pParameterItem == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
pai::module::ParameterType eParamType = m_pParameterItem->GetType();
|
|
QList<QObject*> childrenList = children();
|
|
int index = 0;
|
|
for (int i = 0; i < childrenList.size(); ++i)
|
|
{
|
|
QRadioButton *pButton = dynamic_cast<QRadioButton *>(childrenList.at(i));
|
|
if (NULL != pButton)
|
|
{
|
|
if (eParamType == pai::module::ParmType_INT || eParamType == pai::module::ParmType_LONG)
|
|
{
|
|
if (index++ == varValue.toInt())
|
|
pButton->setChecked(true);
|
|
else
|
|
continue;
|
|
}
|
|
else //STRING
|
|
{
|
|
if (pButton->text() == varValue.toString())
|
|
pButton->setChecked(true);
|
|
else
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
////////////////////////////////SPINBOX///////////////////////////
|
|
CParameterItemSpinBox::CParameterItemSpinBox(CParameterItem* pParameterItem,QWidget* pParent)
|
|
:PaiSpinBox(pParent),CParameterItemControl(pParameterItem)
|
|
{
|
|
setRange(INT_MIN,INT_MAX);
|
|
}
|
|
QVariant CParameterItemSpinBox::GetDisplayValue() const
|
|
{
|
|
return GetValue();
|
|
}
|
|
|
|
QVariant CParameterItemSpinBox::GetValue() const
|
|
{
|
|
return value();
|
|
}
|
|
void CParameterItemSpinBox::SetDisplayValue(const QVariant& varDisplayValue)
|
|
{
|
|
SetValue(varDisplayValue);
|
|
}
|
|
void CParameterItemSpinBox::SetValue(const QVariant& varValue)
|
|
{
|
|
setValue(varValue.toInt());
|
|
}
|
|
////////////////////////////////DOUBLE SPINBOX///////////////////////////
|
|
CParameterItemDoubleSpinBox::CParameterItemDoubleSpinBox(CParameterItem* pParameterItem,QWidget* pParent)
|
|
:QDoubleSpinBox(pParent),CParameterItemControl(pParameterItem)
|
|
{
|
|
setRange(DBL_MIN,DBL_MAX);
|
|
}
|
|
QVariant CParameterItemDoubleSpinBox::GetDisplayValue() const
|
|
{
|
|
return GetValue();
|
|
}
|
|
|
|
QVariant CParameterItemDoubleSpinBox::GetValue() const
|
|
{
|
|
if(m_pParameterItem == NULL)
|
|
{
|
|
return QVariant();
|
|
}
|
|
|
|
pai::module::ParameterType paramType = m_pParameterItem->GetType();
|
|
if(paramType == pai::module::ParmType_FLOAT)
|
|
{
|
|
return QVariant(static_cast<float>(value()));
|
|
}
|
|
else if(paramType == pai::module::ParmType_DOUBLE)
|
|
{
|
|
return value();
|
|
}
|
|
else
|
|
{
|
|
return QVariant();
|
|
}
|
|
}
|
|
void CParameterItemDoubleSpinBox::SetDisplayValue(const QVariant& varDisplayValue)
|
|
{
|
|
SetValue(varDisplayValue);
|
|
}
|
|
void CParameterItemDoubleSpinBox::SetValue(const QVariant& varValue)
|
|
{
|
|
if(m_pParameterItem == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
pai::module::ParameterType paramType = m_pParameterItem->GetType();
|
|
if(paramType == pai::module::ParmType_FLOAT)
|
|
{
|
|
setValue(static_cast<double>(varValue.toFloat()));
|
|
}
|
|
else if(paramType == pai::module::ParmType_DOUBLE)
|
|
{
|
|
setValue(varValue.toDouble());
|
|
}
|
|
else
|
|
{
|
|
// throw pai::error::invalid_argument("Parameter is error!");
|
|
}
|
|
}
|
|
////////////////////////////////CHECKBOX///////////////////////////
|
|
CParameterItemCheckBox::CParameterItemCheckBox(CParameterItem* pParameterItem,QWidget* pParent)
|
|
:QCheckBox(pParent),CParameterItemControl(pParameterItem)
|
|
{
|
|
setText(pParameterItem->GetName());
|
|
}
|
|
QVariant CParameterItemCheckBox::GetDisplayValue() const
|
|
{
|
|
return GetValue();
|
|
}
|
|
|
|
QVariant CParameterItemCheckBox::GetValue() const
|
|
{
|
|
return isChecked();
|
|
}
|
|
void CParameterItemCheckBox::SetDisplayValue(const QVariant& varDisplayValue)
|
|
{
|
|
SetValue(varDisplayValue);
|
|
}
|
|
void CParameterItemCheckBox::SetValue(const QVariant& varValue)
|
|
{
|
|
setCheckState(varValue.toBool()?(Qt::Checked):(Qt::Unchecked));
|
|
}
|
|
////////////////////////////////LINEEDIT//////////////////////////
|
|
CParameterItemLineEdit::CParameterItemLineEdit(CParameterItem* pParameterItem,QWidget* pParent)
|
|
:PaiLineEdit(pParent),CParameterItemControl(pParameterItem)
|
|
{
|
|
SetValidator(pParameterItem->GetType(), this, pParameterItem->IsNessary());
|
|
}
|
|
QVariant CParameterItemLineEdit::GetDisplayValue() const
|
|
{
|
|
return text().trimmed();
|
|
}
|
|
|
|
QVariant CParameterItemLineEdit::GetValue() const
|
|
{
|
|
return GetDisplayValue();
|
|
}
|
|
void CParameterItemLineEdit::SetDisplayValue(const QVariant& varDisplayValue)
|
|
{
|
|
setText(varDisplayValue.toString());
|
|
}
|
|
void CParameterItemLineEdit::SetValue(const QVariant& varValue)
|
|
{
|
|
SetDisplayValue(varValue);
|
|
}
|
|
void CParameterItemLineEdit::slotOnEditingFinished(const QString& text)
|
|
{
|
|
if(m_pParameterItem)
|
|
{
|
|
m_pParameterItem->SetStringValue(text.toStdString());
|
|
}
|
|
}
|
|
void CParameterItemLineEdit::dropEvent(QDropEvent *pEvent)
|
|
{
|
|
// QString strtext = pEvent->mimeData()->text();
|
|
// QStringList strlist=strtext.split('/');
|
|
// setText(strlist[strlist.length()-1]);
|
|
// setFocus();
|
|
// // commit data as soon as the data has been dropped
|
|
// emit QLineEdit::editingFinished();
|
|
}
|
|
////////////////////////////////COMBOBOX//////////////////////////
|
|
CParameterItemComboBox::CParameterItemComboBox(CParameterItem* pParameterItem,QWidget* pParent)
|
|
:PaiComboBox(pParent),CParameterItemControl(pParameterItem)
|
|
{
|
|
QString strInputMetaData = QString::fromStdString(pParameterItem->GetInputMetaData());
|
|
QStringList strComboboxTexts = strInputMetaData.split('/');
|
|
addItems(strComboboxTexts);
|
|
if(pParameterItem->GetInputData().find(g_szEditable)!=std::string::npos)
|
|
{
|
|
setEditable(true);
|
|
setCompleter(NULL);
|
|
SetValidator(pParameterItem->GetType(), lineEdit(), pParameterItem->IsNessary());
|
|
}
|
|
|
|
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(slotIndexChanged(int)));
|
|
|
|
}
|
|
QVariant CParameterItemComboBox::GetDisplayValue() const
|
|
{
|
|
if(m_pParameterItem == NULL)
|
|
{
|
|
return QVariant();
|
|
}
|
|
|
|
pai::module::ParameterType eParamType = m_pParameterItem->GetType();
|
|
if (eParamType == pai::module::ParmType_BOOL)
|
|
{
|
|
return currentIndex();
|
|
}
|
|
else if (eParamType == pai::module::ParmType_INT || eParamType == pai::module::ParmType_LONG)
|
|
{
|
|
if (isEditable())
|
|
{
|
|
return currentText();
|
|
}
|
|
else
|
|
{
|
|
return currentIndex();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return currentText();
|
|
}
|
|
}
|
|
|
|
QVariant CParameterItemComboBox::GetValue() const
|
|
{
|
|
return GetDisplayValue();
|
|
}
|
|
void CParameterItemComboBox::SetDisplayValue(const QVariant& varDisplayValue)
|
|
{
|
|
SetValue(varDisplayValue);
|
|
}
|
|
void CParameterItemComboBox::SetValue(const QVariant& varValue)
|
|
{
|
|
if(m_pParameterItem == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
pai::module::ParameterType eParamType = m_pParameterItem->GetType();
|
|
if (eParamType == pai::module::ParmType_BOOL)
|
|
{
|
|
setCurrentIndex(m_pParameterItem->GetValue<bool> ());
|
|
}
|
|
else if (eParamType == pai::module::ParmType_INT || eParamType == pai::module::ParmType_LONG)
|
|
{
|
|
if (isEditable())
|
|
{
|
|
setEditText(varValue.toString());
|
|
}
|
|
else
|
|
{
|
|
setCurrentIndex(varValue.toInt());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int iIndex = findText(varValue.toString());
|
|
setCurrentIndex(iIndex);
|
|
if (-1 == iIndex)
|
|
{
|
|
setEditText(varValue.toString());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void CParameterItemComboBox::slotIndexChanged(int index)
|
|
{
|
|
int paramIndex = -1;
|
|
bool ok = true;
|
|
if (m_pParameterItem)
|
|
{
|
|
pai::module::ParameterType eParamType = m_pParameterItem->GetType();
|
|
if (eParamType == pai::module::ParmType_BOOL)
|
|
{
|
|
paramIndex = m_pParameterItem->ValueToBool(&ok);
|
|
}
|
|
else if (eParamType == pai::module::ParmType_INT)
|
|
{
|
|
paramIndex = m_pParameterItem->ValueToInt(&ok);
|
|
}
|
|
else if (eParamType == pai::module::ParmType_LONG)
|
|
{
|
|
paramIndex = m_pParameterItem->ValueToLong(&ok);
|
|
}
|
|
else
|
|
{
|
|
paramIndex = findText(QString::fromStdString(m_pParameterItem->ValueToString()));
|
|
}
|
|
}
|
|
if (m_pParameterItem && ok == true && index != paramIndex)
|
|
{
|
|
emit signalInternalIndexChanged();
|
|
}
|
|
}
|
|
|
|
////////////////////////////////Add Button(Special)//////////////////////////
|
|
CParameterItemButtonBox::CParameterItemButtonBox(CParameterItem* pParameterItem,QWidget* pParent)
|
|
:QDialogButtonBox(pParent),CParameterItemControl(pParameterItem)
|
|
{
|
|
CurrentParameterItem=pParameterItem;
|
|
QString strMetaData = QString::fromStdString(pParameterItem->GetInputMetaData());
|
|
QStringList strData=strMetaData.split(";");
|
|
strData.removeAll("");
|
|
for(int i=0;i<strData.size();i++)
|
|
{
|
|
QStringList strButtonData=strData[i].split(":");
|
|
// strButtonData.removeAll("");
|
|
QString strAddButtonText(strButtonData[1]);
|
|
PaiPushButton * pAddButton = new PaiPushButton(strAddButtonText,this);
|
|
// pAddButton->setMaximumWidth(36);
|
|
addButton(pAddButton,QDialogButtonBox::ActionRole);
|
|
|
|
QStringList strButtonID=strButtonData[0].split(",");
|
|
|
|
pAddButton->setProperty(g_szActionID,strButtonID[0]);
|
|
pAddButton->setProperty(g_szArrayItemID,QString::fromStdString(pParameterItem->GetId()));
|
|
}
|
|
CCompositeParameterItem* currentitem=dynamic_cast<CCompositeParameterItem*>(pParameterItem);
|
|
/*
|
|
m_cb_Zones=new PaiComboBox(this);
|
|
m_cb_Zones->setMinimumWidth(154);
|
|
if(currentitem){
|
|
QHBoxLayout* pLayout = new QHBoxLayout;
|
|
pLayout->setMargin(26);
|
|
pLayout->setSpacing(4);
|
|
m_cb_Zones->setObjectName("zones_list_selector");
|
|
slotZonesSizeChanged();
|
|
this->setLayout(pLayout);
|
|
pLayout->addWidget(m_cb_Zones);
|
|
}
|
|
*/
|
|
}
|
|
void pai::gui::CParameterItemButtonBox::slotZonesSizeChanged()
|
|
{
|
|
/*
|
|
m_cb_Zones->clear();
|
|
CCompositeParameterItem* currentitem=dynamic_cast<CCompositeParameterItem*>(CurrentParameterItem);
|
|
for(int i=0;i<currentitem->GetChildCount();i++){
|
|
CCompositeParameterItem* currentzone=dynamic_cast<CCompositeParameterItem*>(currentitem->GetParameterItem(i));
|
|
if(!currentzone) continue;
|
|
if(currentzone->GetChildCount()<2) continue;
|
|
CParameterItem* pItem1=currentzone->GetParameterItem(0);
|
|
CParameterItem* pItem2=currentzone->GetParameterItem(1);
|
|
if(pItem1&&pItem2) {
|
|
QString itemname="井段("+QString::fromStdString(pItem1->GetStringValue())+
|
|
"~"+QString::fromStdString(pItem2->GetStringValue())+
|
|
")";
|
|
m_cb_Zones->addItem(itemname);
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
|
|
QVariant CParameterItemButtonBox::GetDisplayValue() const
|
|
{
|
|
return QVariant();
|
|
}
|
|
|
|
QVariant CParameterItemButtonBox::GetValue() const
|
|
{
|
|
return QVariant();
|
|
}
|
|
void CParameterItemButtonBox::SetDisplayValue(const QVariant& /*varDisplayValue*/)
|
|
{
|
|
}
|
|
void CParameterItemButtonBox::SetValue(const QVariant& /*varValue*/)
|
|
{
|
|
}
|
|
////////////////////////////////CHECKBOXSBUTTON///////////////////////////
|
|
CParameterItemCheckBoxGroup::CParameterItemCheckBoxGroup(CParameterItem* pParameterItem,QWidget* pParent)
|
|
:QGroupBox(pParent),CParameterItemControl(pParameterItem)
|
|
{
|
|
QGridLayout* pLayout = new QGridLayout;
|
|
pLayout->setMargin(0);
|
|
pLayout->setSpacing(0);
|
|
|
|
QString strInputMetaData = QString::fromStdString(pParameterItem->GetInputMetaData());
|
|
QStringList strComboboxTexts = strInputMetaData.split('/');
|
|
for (int i = 0; i < strComboboxTexts.size(); ++i)
|
|
{
|
|
int n=i/4;
|
|
int m=i%4;
|
|
QCheckBox *pButton = new QCheckBox(strComboboxTexts[i]);
|
|
connect(pButton, SIGNAL(toggled(bool)), this, SLOT(slotOnToggled(bool)));
|
|
pLayout->addWidget(pButton,n,m);
|
|
}
|
|
|
|
setLayout(pLayout);
|
|
}
|
|
void CParameterItemCheckBoxGroup::slotOnToggled(bool toggled)
|
|
{
|
|
if (toggled == true)
|
|
emit signalInternalIndexChanged();
|
|
}
|
|
QVariant CParameterItemCheckBoxGroup::GetDisplayValue() const
|
|
{
|
|
if(m_pParameterItem == NULL)
|
|
{
|
|
return QVariant();
|
|
}
|
|
|
|
pai::module::ParameterType eParamType = m_pParameterItem->GetType();
|
|
QList<QObject*> childrenList = children();
|
|
int index = 0;
|
|
QString val="";
|
|
for (int i = 0; i < childrenList.size(); ++i)
|
|
{
|
|
QCheckBox *pButton = dynamic_cast<QCheckBox *>(childrenList[i]);
|
|
if (NULL != pButton)
|
|
{
|
|
if (pButton->isChecked() == true)
|
|
{
|
|
QString name=pButton->text();
|
|
name=name.trimmed();
|
|
if(!val.isEmpty()) {
|
|
val+=",";
|
|
}
|
|
val+=name;
|
|
}
|
|
}
|
|
}
|
|
if(!val.isEmpty()) return val;
|
|
return QVariant();
|
|
}
|
|
void CParameterItemCheckBoxGroup::installEventFilter(QObject * filterObj)
|
|
{
|
|
QList<QObject*> childrenList = children();
|
|
for (int i = 0; i < childrenList.size(); ++i)
|
|
{
|
|
QCheckBox *pButton = dynamic_cast<QCheckBox *>(childrenList[i]);
|
|
if (NULL != pButton)
|
|
{
|
|
pButton->installEventFilter(filterObj);
|
|
}
|
|
}
|
|
}
|
|
QVariant CParameterItemCheckBoxGroup::GetValue() const
|
|
{
|
|
return GetDisplayValue();
|
|
}
|
|
void CParameterItemCheckBoxGroup::SetDisplayValue(const QVariant& varDisplayValue)
|
|
{
|
|
SetValue(varDisplayValue);
|
|
}
|
|
void CParameterItemCheckBoxGroup::SetValue(const QVariant& varValue)
|
|
{
|
|
if(m_pParameterItem == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
pai::module::ParameterType eParamType = m_pParameterItem->GetType();
|
|
QList<QObject*> childrenList = children();
|
|
int index = 0;
|
|
QString str=varValue.toString();
|
|
QStringList strlst=str.split(',');
|
|
for (int i = 0; i < childrenList.size(); ++i)
|
|
{
|
|
QCheckBox *pButton = dynamic_cast<QCheckBox *>(childrenList.at(i));
|
|
if (NULL != pButton)
|
|
{
|
|
QString name=pButton->text();
|
|
name=name.trimmed();
|
|
if(strlst.indexOf(name)>-1) {
|
|
pButton->setChecked(true);
|
|
}
|
|
}
|
|
}
|
|
}
|