/** * @file PaiObjectBrowser.cpp * @brief 一个支持P.A.I系统对象浏览选择及输入(包括拖拽)的复合文本框 * @date: 2012-3-1 * @author: sinapec */ #include #include #include #include #include #include #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& 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(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; // } // //获取解析后的拖拽数据 // QListdataLst = dropAna.GetDraggedData(); // foreach(DraggedData draggedData, dataLst) // { // //如果是不支持的类型,直接忽略 // if(!m_lstObjectTypeIDs.contains(QUuid(draggedData.dataType))) // { // pEvent->ignore(); // return; // } // //获取数据指针 // bool ok; // PaiGeoObject* pDragSeisData = dynamic_cast(::GetObjectModelService()->GetObject((draggedData.id).toLongLong(&ok))); // if(pDragSeisData && ok) // { // if (dynamic_cast(pDragSeisData->GetParent()) // || !dynamic_cast(pDragSeisData)) // { // setText(pDragSeisData->GetPhysicalFile()); // } // else // { // PaiSurvey* pSurvey = pDragSeisData->GetForebear(); // 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()); // //获取解析后的拖拽数据 // QListdataLst = 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 lstObjs; // foreach(QUuid objTypeID,m_lstObjectTypeIDs) // { // QList lstObjsForThisType; // ::GetObjectModelService()->GetObjectByType(lstObjsForThisType,objTypeID); // lstObjs.append(lstObjsForThisType); // } // m_mapTexts.clear(); // foreach(PaiObject* pObj, lstObjs) // { // PaiGeoObject* pGeoObject = dynamic_cast(pObj); // if (pGeoObject != NULL) // { // PaiJob *pJob = dynamic_cast(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(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*/) { }