logplus/ModuleConsole/src/PaiObjectBrowser.cpp

317 lines
8.6 KiB
C++
Raw Normal View History

2026-01-16 17:18:41 +08:00
/**
* @file PaiObjectBrowser.cpp
* @brief P.A.I系统对象浏览选择及输入
* @date: 2012-3-1
* @author: sinapec
*/
#include <QDropEvent>
#include <QMimeData>
#include <QDebug>
#include <QCompleter>
#include <QStringListModel>
#include <QApplication>
#include "PaiObjectBrowser.h"
// #include "PaiDataMaster.h"
// #include "PaiSeisData.h"
// #include "PaiHorizon.h"
// #include "PaiDropEventAnalyser.h"
// #include "PaiSurvey.h"
// #include "PaiProject.h"
#include "WorkflowConst.h"
#include "PaiValidator.h"
// #include "Log.h"
// #include "PaiJob.h"
#include "SaveHelper.h"
// #include "PaiTypes.h"
using namespace pai::gui;
using namespace pai::objectmodel;
void SetValidator(bool isObjectInput, PaiLineEdit *pLineEdit)
{
if(pLineEdit)
{
if (isObjectInput == false)
{
QRegExp regExp("(^[\u4e00-\u9fa50-9a-zA-Z_\\-\\.]+)|(^$)");
QRegExpValidator *dator = new QRegExpValidator(regExp,pLineEdit);
pLineEdit->setValidator(dator);
}
else
{
QRegExp regExp("(^[\u4e00-\u9fa50-9a-zA-Z_\\-\\.\\/\\ \\:]+)|(^$)");
QRegExpValidator *dator = new QRegExpValidator(regExp,pLineEdit);
pLineEdit->setValidator(dator);
}
}
}
CPaiObjectBrowser::CPaiObjectBrowser(const QList<QUuid>& lstObjectTypeIDs,QWidget* pParent)
: PaiLineEdit(pParent)
, CParameterItemControl(NULL)
, m_strData("")
, m_pCompleterModel(NULL)
, m_strOldText("")
{
SetRightIcon(":/arrow02.png");
m_lstObjectTypeIDs = lstObjectTypeIDs;
m_pCompleterModel = new QStringListModel();
QCompleter* pCompleter = new QCompleter(m_pCompleterModel,this);
pCompleter->setCompletionMode(QCompleter::PopupCompletion);
setCompleter(pCompleter);
setPlaceholderText(g_szInputPlaceholder);
SetValidator(true, this);
connect(this,SIGNAL(textEdited(const QString&)),this,SLOT(slotOnTextEdited(const QString&)));
connect(this,SIGNAL(rightIconClicked()),this,SLOT(slotBrowseAllData()));
}
CPaiObjectBrowser::~CPaiObjectBrowser()
{
}
QString CPaiObjectBrowser::GetData()
{
if(m_strData == "")
{
if(m_mapTexts.contains(text().trimmed()))
{
m_strData = m_mapTexts[text().trimmed()];
return m_strData;
}
return text().trimmed();
}
return m_strData;
}
void CPaiObjectBrowser::SetData(const QString& strData)
{
// if (m_lstObjectTypeIDs.contains(PaiHorizon::GetTypeIDString()) && (m_strData != strData))
// {
// emit signalLayerPickFileChanged(strData);
// }
// m_strData = strData;
}
QVariant CPaiObjectBrowser::GetDisplayValue() const
{
return text().trimmed();
}
QVariant CPaiObjectBrowser::GetValue() const
{
CPaiObjectBrowser* pThis = const_cast<CPaiObjectBrowser*>(this);
return pThis->GetData();
}
void CPaiObjectBrowser::SetDisplayValue(const QVariant& varDisplayValue)
{
setText(varDisplayValue.toString());
}
void CPaiObjectBrowser::SetValue(const QVariant& varValue)
{
SetData(varValue.toString());
}
void CPaiObjectBrowser::dropEvent ( QDropEvent *pEvent)
{
// PaiDropEventAnalyser dropAna(pEvent->mimeData());
// if(!dropAna.IsAvailable())
// {
// pEvent->ignore();
// return;
// }
// //获取解析后的拖拽数据
// QList<DraggedData>dataLst = dropAna.GetDraggedData();
// foreach(DraggedData draggedData, dataLst)
// {
// //如果是不支持的类型,直接忽略
// if(!m_lstObjectTypeIDs.contains(QUuid(draggedData.dataType)))
// {
// pEvent->ignore();
// return;
// }
// //获取数据指针
// bool ok;
// PaiGeoObject* pDragSeisData = dynamic_cast<PaiGeoObject*>(::GetObjectModelService()->GetObject((draggedData.id).toLongLong(&ok)));
// if(pDragSeisData && ok)
// {
// if (dynamic_cast<PaiDataMaster *>(pDragSeisData->GetParent())
// || !dynamic_cast<PaiSeisData *>(pDragSeisData))
// {
// setText(pDragSeisData->GetPhysicalFile());
// }
// else
// {
// PaiSurvey* pSurvey = pDragSeisData->GetForebear<PaiSurvey>();
// if(pSurvey)
// {
// PaiBaseMaster *pMaster = pSurvey->GetMaster(QUuid(pai::objectmodel::PaiDataMaster::GetTypeIDString()));
// if (pMaster)
// {
// setText(pMaster->GetFullPathName() + "/" + pDragSeisData->GetName());
// }
// }
// }
// SetData(pDragSeisData->GetPhysicalFile());
// }
// setFocus();
// // commit data as soon as the data has been dropped
// emit QLineEdit::editingFinished();
// break;
// }
}
void CPaiObjectBrowser::dragEnterEvent ( QDragEnterEvent *pEvent)
{
// PaiLineEdit::dragEnterEvent(pEvent);
// PaiDropEventAnalyser dropAna(pEvent->mimeData());
// //获取解析后的拖拽数据
// QList<DraggedData>dataLst = dropAna.GetDraggedData();
// bool bHasValidType = false;
// foreach(DraggedData draggedData, dataLst)
// {
// if(m_lstObjectTypeIDs.contains(QUuid(draggedData.dataType)))
// {
// bHasValidType = true;
// break;
// }
// }
// if(!bHasValidType)
// {
// pEvent->ignore();
// return;
// }
// pEvent->accept();
}
void CPaiObjectBrowser::BuildCompleteModel()
{
// QList<PaiObject*> lstObjs;
// foreach(QUuid objTypeID,m_lstObjectTypeIDs)
// {
// QList<PaiObject*> lstObjsForThisType;
// ::GetObjectModelService()->GetObjectByType(lstObjsForThisType,objTypeID);
// lstObjs.append(lstObjsForThisType);
// }
// m_mapTexts.clear();
// foreach(PaiObject* pObj, lstObjs)
// {
// PaiGeoObject* pGeoObject = dynamic_cast<PaiGeoObject*>(pObj);
// if (pGeoObject != NULL)
// {
// PaiJob *pJob = dynamic_cast<PaiJob *>(pGeoObject->GetParent());
// if (pJob)
// {
// continue;
// }
// m_mapTexts.insert(pGeoObject->GetFullPathName(),pGeoObject->GetPhysicalFile());
// }
// }
// m_pCompleterModel->setStringList(m_mapTexts.keys());
}
void CPaiObjectBrowser::focusInEvent ( QFocusEvent * e )
{
PaiLineEdit::focusInEvent(e);
BuildCompleteModel();
}
void CPaiObjectBrowser::focusOutEvent ( QFocusEvent * e )
{
if(m_mapTexts.contains(text().trimmed()))
{
SetData(m_mapTexts[text().trimmed()]);
}
PaiLineEdit::focusOutEvent(e);
}
void CPaiObjectBrowser::slotOnTextEdited(const QString& strNewText)
{
if(text().isEmpty() || !m_strOldText.startsWith(strNewText))
{
SetData("");
}
m_strOldText = strNewText;
}
void CPaiObjectBrowser::slotBrowseAllData()
{
m_strOldValue = text();
clear();
QString path("/");
QKeyEvent keyPress(QEvent::KeyPress,Qt::Key_Slash,Qt::NoModifier,path);
QApplication::sendEvent(this,&keyPress);
QKeyEvent keyRelease(QEvent::KeyRelease,Qt::Key_Slash,Qt::NoModifier,path);
QApplication::sendEvent(this,&keyRelease);
setText(m_strOldValue);
}
CHdfsFileEditor::CHdfsFileEditor(const QUuid& workflowID, QWidget* pParent)
:PaiLineEdit(pParent),CParameterItemControl(NULL), m_workflowID(workflowID)
{
setPlaceholderText(g_szOutputPlaceholder);
SetValidator(false, this);
//文件输入最多100字符限制
setMaxLength(100);
}
CHdfsFileEditor::~CHdfsFileEditor()
{
}
QString CHdfsFileEditor::GetData()
{
return "";
// if(text().trimmed().isEmpty())
// {
// return "";
// }
// QString value("");
// PaiObject* pWorkflow = ::GetObjectModelService()->GetObject(QUuid(m_workflowID));
// pai::log::Debug(_FLF("m_workflowID is " + m_workflowID.toString().toStdString()));
// if(pWorkflow == NULL)
// {
// return QString("/") + text().trimmed();
// }
// PaiSurvey *pSurvey = SaveHelper::GetSurveyByWfDBID(pWorkflow->GetDBID());
// if(pSurvey == NULL)
// {
// return QString("/") + text().trimmed();
// }
// value.append(pSurvey->GetPhysicalFile());
// value.append("/");
// value.append(text().trimmed());
// return value;
}
QVariant CHdfsFileEditor::GetDisplayValue() const
{
return text().trimmed();
}
QVariant CHdfsFileEditor::GetValue() const
{
CHdfsFileEditor* pThis = const_cast<CHdfsFileEditor*>(this);
if(pThis != NULL)
{
return pThis->GetData();
}
else
{
return QVariant();
}
}
void CHdfsFileEditor::SetDisplayValue(const QVariant& varDisplayValue)
{
setText(varDisplayValue.toString());
}
void CHdfsFileEditor::SetValue(const QVariant& /*varValue*/)
{
}