442 lines
12 KiB
C++
442 lines
12 KiB
C++
/*
|
|
* CPaiWorkflowTemplateTree.cpp
|
|
*
|
|
* Created on: 2012-12-6
|
|
* Author: dev
|
|
*/
|
|
|
|
#include <QDir>
|
|
#include <QDebug>
|
|
#include <QHeaderView>
|
|
#include <QFileDialog>
|
|
#include <QMimeData>
|
|
#include <QScrollBar>
|
|
#include <QDrag>
|
|
#include <QMenu>
|
|
|
|
#include "PaiSettings.h"
|
|
#include "PaiTreeItemDelegate.h"
|
|
#include "PaiWorkflowTemplateTree.h"
|
|
#include "PaiObject.h"
|
|
#include "PaiWorkflowDataModel.h"
|
|
#include "WorkflowPackage.h"
|
|
#include "DeleteTemplateCmd.h"
|
|
#include "ConsoleGUIService.h"
|
|
#include "PaiAction.h"
|
|
#include "GlobalUtility.h"
|
|
#include "PaiDropEventAnalyser.h"
|
|
#include "DeleteTemplateCmd.h"
|
|
#include "SaveHelper.h"
|
|
#include "Log.h"
|
|
#include "PAIConst.h"
|
|
#include "PaiFileDialog.h"
|
|
#include "WorkflowConst.h"
|
|
#include "PaiBalloonTip.h"
|
|
#include "Utils.h"
|
|
#include "PaiTypes.h"
|
|
#include "WellLogWorkflowDataModel.h"
|
|
#include "GeometryUtils.h"
|
|
using namespace pai;
|
|
using namespace pai::gui;
|
|
using namespace pai::objectmodel;
|
|
|
|
CPaiWorkflowTemplateTree* CPaiWorkflowTemplateTree::instance = NULL;
|
|
|
|
CPaiWorkflowTemplateTree::CPaiWorkflowTemplateTree(QUuid id,QWidget *parent) :
|
|
QTreeWidget(parent)
|
|
,m_bActive(true)
|
|
{
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(RightMenuRequest(const QPoint &)));
|
|
//关联这两个信号,用来隐藏气泡
|
|
connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(slotHideBalloon()));
|
|
connect(verticalScrollBar(),SIGNAL(actionTriggered(int)), this, SLOT(slotHideBalloon()));
|
|
|
|
setDragEnabled(true);
|
|
setDropIndicatorShown(true);
|
|
setItemDelegate(new PaiTreeItemDelegate(this));
|
|
this->setColumnCount(1); //设置TreeWidget的列
|
|
this->header()->setVisible(false);
|
|
this->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
QList< QTreeWidgetItem* > toplevelTreeItems;
|
|
|
|
//添加默认的分类 Common Templates
|
|
m_pCommonTemplateItem = new QTreeWidgetItem();
|
|
QIcon commonIcon(":/workflow_master.png");
|
|
m_pCommonTemplateItem->setIcon(0, commonIcon);
|
|
m_pCommonTemplateItem->setText(0, QString("CompositeModule"));
|
|
toplevelTreeItems.push_back(m_pCommonTemplateItem);
|
|
|
|
QList< CWellLogWorkflowDataModel* > synWfs;
|
|
CWellLogWorkflowDataModel wfMgmt(id);
|
|
|
|
if(wfMgmt.GetWorkflowTemplates(synWfs))
|
|
{
|
|
for(int i = 0; i < synWfs.count(); ++i)
|
|
{
|
|
m_lstChildren.push_back(synWfs.at(i));
|
|
|
|
//设定各个项
|
|
QTreeWidgetItem* workflowItem = new QTreeWidgetItem(m_pCommonTemplateItem);
|
|
|
|
//设置Icon
|
|
QIcon icon(::GetImagePath() + "icon/Workflowtemplate.png");
|
|
workflowItem->setIcon(0, icon);
|
|
if(synWfs.at(i) != NULL)
|
|
{
|
|
workflowItem->setText(0, synWfs.at(i)->GetName());
|
|
workflowItem->setData(0, pai::gui::IDRole, QVariant(synWfs.at(i)->GetID().toString()));
|
|
workflowItem->setData(0, pai::gui::DBIDRole, QVariant(qlonglong(synWfs.at(i)->GetDBID())));
|
|
}
|
|
}
|
|
}
|
|
this->addTopLevelItems(toplevelTreeItems);
|
|
m_pCommonTemplateItem->setExpanded(true);
|
|
}
|
|
|
|
void CPaiWorkflowTemplateTree::MonkeyClickedModule(QString CompositeModuleID)
|
|
{
|
|
for(int i = 0; i < m_lstChildren.count(); ++i)
|
|
{
|
|
if(m_lstChildren.at(i)->GetName() ==CompositeModuleID)
|
|
{
|
|
((CWellLogWorkflowDataModel*)m_lstChildren.at(i))->LoadFromTemplateFile();
|
|
emit itemDoubleClicked(m_lstChildren.at(i));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
CPaiWorkflowTemplateTree::~CPaiWorkflowTemplateTree()
|
|
{
|
|
qDeleteAll(m_lstChildren);
|
|
m_lstChildren.clear();
|
|
}
|
|
|
|
void CPaiWorkflowTemplateTree::slotHideBalloon()
|
|
{
|
|
PaiBalloonTip::HideBalloon();
|
|
}
|
|
|
|
CPaiWorkflowTemplateTree* CPaiWorkflowTemplateTree::GetInstance()
|
|
{
|
|
if(instance == NULL)
|
|
{
|
|
instance = new CPaiWorkflowTemplateTree(QUuid());
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
void CPaiWorkflowTemplateTree::startDrag(Qt::DropActions /*supportedActions*/)
|
|
{
|
|
if(currentItem() == NULL || currentItem()->parent() == NULL)
|
|
{
|
|
//分类节点不能拖动
|
|
return;
|
|
}
|
|
QMimeData *pMimeData = new QMimeData;
|
|
|
|
pai::objectmodel::PaiDropEventAnalyser analyser;
|
|
QByteArray array;
|
|
DraggedData draggedData;
|
|
draggedData.dataSource = DRAG_TEMPLATETREE;
|
|
draggedData.id = currentItem()->data(0,pai::gui::DBIDRole).toString();
|
|
draggedData.dataName = currentItem()->text(0);
|
|
draggedData.dataType = QString("Template");
|
|
draggedData.reserve = QString("");
|
|
analyser.Serialize(draggedData,array);
|
|
pMimeData->setData(QString::number(DRAG_TEMPLATETREE),array);
|
|
|
|
QDrag *pDrag = new QDrag((QWidget*)(this->parent()));
|
|
pDrag->setMimeData(pMimeData);
|
|
|
|
pDrag->exec(Qt::CopyAction);
|
|
}
|
|
|
|
void CPaiWorkflowTemplateTree::mouseDoubleClickEvent(QMouseEvent *event)
|
|
{
|
|
if(currentItem() == NULL)
|
|
return;
|
|
|
|
if(currentItem()->parent() == NULL)
|
|
{
|
|
QTreeWidget::mouseDoubleClickEvent(event);
|
|
return;
|
|
}
|
|
|
|
for(int i = 0; i < m_lstChildren.count(); ++i)
|
|
{
|
|
if(m_lstChildren.at(i)->GetName() == currentItem()->text(0))
|
|
{
|
|
//实现晚加载
|
|
((CWellLogWorkflowDataModel*)m_lstChildren.at(i))->LoadFromTemplateFile();
|
|
emit itemDoubleClicked(m_lstChildren.at(i));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
QList< pai::objectmodel::PaiObject* > CPaiWorkflowTemplateTree::GetChildren()
|
|
{
|
|
return m_lstChildren;
|
|
}
|
|
|
|
pai::objectmodel::PaiObject* CPaiWorkflowTemplateTree::GetChildByName(QString strChildName)
|
|
{
|
|
PaiObject* pObject = NULL;
|
|
for(int i = 0; i < m_lstChildren.count(); ++i)
|
|
{
|
|
if((m_lstChildren.at(i)) && (m_lstChildren.at(i)->GetName() == strChildName))
|
|
{
|
|
pObject = m_lstChildren.at(i);
|
|
break;
|
|
}
|
|
}
|
|
return pObject;
|
|
}
|
|
|
|
bool CPaiWorkflowTemplateTree::AddChild(PaiObject* pChild)
|
|
{
|
|
if(pChild == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(!m_lstChildren.contains(pChild))
|
|
{
|
|
for(int i = 0; i < m_lstChildren.count(); ++i)
|
|
{
|
|
if((m_lstChildren.at(i)->GetID() == pChild->GetID()) && (m_lstChildren.at(i)->GetDBID() == pChild->GetDBID()))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
m_lstChildren.push_back(pChild);
|
|
|
|
//模板保存
|
|
CWellLogWorkflowDataModel * cuentdm=dynamic_cast<CWellLogWorkflowDataModel *>(pChild);
|
|
|
|
QString szPath =GetWorkflowTemplatePath();
|
|
|
|
std::string filenames=(GetWorkflowTemplatePath()+ pChild->GetName() ).toStdString();
|
|
if(cuentdm) cuentdm->Save(filenames);
|
|
|
|
//设定各个项
|
|
QTreeWidgetItem* workflowItem = new QTreeWidgetItem(m_pCommonTemplateItem);
|
|
|
|
//设置Icon
|
|
QIcon icon(::GetImagePath() + "icon/Workflowtemplate.png");
|
|
workflowItem->setIcon(0, icon);
|
|
workflowItem->setText(0, pChild->GetName());
|
|
workflowItem->setData(0, pai::gui::IDRole, QVariant(pChild->GetID().toString()));
|
|
workflowItem->setData(0, pai::gui::DBIDRole, QVariant(qlonglong(pChild->GetDBID())));
|
|
workflowItem->setSelected(true);
|
|
if(m_pCommonTemplateItem)
|
|
{
|
|
m_pCommonTemplateItem->addChild(workflowItem);
|
|
}
|
|
if(m_pNewAddedItem)
|
|
{
|
|
m_pNewAddedItem = workflowItem;
|
|
}
|
|
scrollToItem(workflowItem);
|
|
ActiveItem(pChild->GetName());
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool CPaiWorkflowTemplateTree::RemoveChild(pai::objectmodel::PaiObject* pChild)
|
|
{
|
|
if(pChild)
|
|
{
|
|
if(m_pCommonTemplateItem != NULL)
|
|
{
|
|
for(int i = 0; i < m_pCommonTemplateItem->childCount(); ++i)
|
|
{
|
|
QTreeWidgetItem* pChildItem = m_pCommonTemplateItem->child(i);
|
|
if((pChildItem != NULL) && (pChildItem->text(0) == pChild->GetName()))
|
|
{
|
|
m_pCommonTemplateItem->removeChild(pChildItem);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
this->update();
|
|
if(m_lstChildren.removeOne(pChild))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
QRect CPaiWorkflowTemplateTree::GetNewAddedItemRect()
|
|
{
|
|
return this->visualItemRect(m_pNewAddedItem);
|
|
}
|
|
|
|
QRect CPaiWorkflowTemplateTree::GetItemRect(QString strItemName)
|
|
{
|
|
QRect rect;
|
|
|
|
if(m_pCommonTemplateItem != NULL)
|
|
{
|
|
for(int i = 0; i < m_pCommonTemplateItem->childCount(); ++i)
|
|
{
|
|
QTreeWidgetItem* pChildItem = m_pCommonTemplateItem->child(i);
|
|
if((pChildItem) && (pChildItem->text(0) == strItemName))
|
|
{
|
|
rect = this->visualItemRect(pChildItem);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return rect;
|
|
}
|
|
|
|
void CPaiWorkflowTemplateTree::RightMenuRequest(const QPoint &point)
|
|
{
|
|
QMenu rightMenu;
|
|
|
|
QTreeWidgetItem* pItem = itemAt(point);
|
|
if(pItem == NULL)
|
|
return;
|
|
|
|
if(pItem->parent() != NULL)
|
|
{
|
|
QAction* pEditTemplateAction = rightMenu.addAction(tr("Edit"), this, SLOT(slotEditItem()));
|
|
pEditTemplateAction->setEnabled(true);
|
|
|
|
QAction* pDeleteTemplateAction = rightMenu.addAction(tr("Delete"), this, SLOT(slotDeleteItem()));
|
|
pDeleteTemplateAction->setEnabled(true);
|
|
|
|
PaiAction* pExportTemplateAction = new PaiAction(tr("Export Templates..."), this);
|
|
connect(pExportTemplateAction, SIGNAL(triggered()), this, SLOT(slotExportTemplates()));
|
|
rightMenu.addAction(pExportTemplateAction);
|
|
pExportTemplateAction->setEnabled(true);
|
|
}
|
|
else
|
|
{
|
|
PaiAction* pImportTemplateAction = new PaiAction(tr("Import Templates..."), this);
|
|
connect(pImportTemplateAction, SIGNAL(triggered()), this, SLOT(slotImportTemplates()));
|
|
rightMenu.addAction(pImportTemplateAction);
|
|
pImportTemplateAction->setEnabled(true);
|
|
}
|
|
rightMenu.exec(QCursor::pos());
|
|
}
|
|
|
|
QList< pai::objectmodel::PaiObject* > CPaiWorkflowTemplateTree::GetSelectedChildren()
|
|
{
|
|
QList< PaiObject* > objectList;
|
|
|
|
if(m_pCommonTemplateItem != NULL)
|
|
{
|
|
for(int i = 0; i < m_pCommonTemplateItem->childCount(); ++i)
|
|
{
|
|
if((m_pCommonTemplateItem->child(i)) && (m_pCommonTemplateItem->child(i)->isSelected()))
|
|
{
|
|
PaiObject* pObj = GetChildByName(m_pCommonTemplateItem->child(i)->text(0));
|
|
if(pObj)
|
|
{
|
|
objectList << pObj;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return objectList;
|
|
}
|
|
|
|
void CPaiWorkflowTemplateTree::slotEditItem()
|
|
{
|
|
QAction* pAction = dynamic_cast< QAction* > (sender());
|
|
if(pAction == NULL)
|
|
return;
|
|
|
|
QList< PaiObject* > objectList = GetSelectedChildren();
|
|
emit itemEdit(objectList);
|
|
}
|
|
|
|
void CPaiWorkflowTemplateTree::slotDeleteItem()
|
|
{
|
|
QAction* pAction = dynamic_cast< QAction* > (sender());
|
|
if(pAction == NULL)
|
|
return;
|
|
|
|
QList< PaiObject* > objectList = GetSelectedChildren();
|
|
if(objectList.empty())
|
|
return;
|
|
|
|
QStringList names;
|
|
for(int i = 0; i < objectList.count(); ++i)
|
|
{
|
|
if(objectList.at(i) != NULL)
|
|
{
|
|
names.append(objectList.at(i)->GetName());
|
|
}
|
|
}
|
|
|
|
if(PaiMessageBox::Warning(NULL, tr("Warning!"),
|
|
tr("Do you want to delete \"%1\" ?").arg(names.join(" ")), PaiMessageBox::Yes
|
|
| PaiMessageBox::No, PaiMessageBox::No) == PaiMessageBox::Yes)
|
|
{
|
|
emit itemDelete(objectList);
|
|
for(int i = 0; i < objectList.count(); ++i)
|
|
{
|
|
DeleteTemplateCmd deleteTemplateCmd(this, objectList.at(i));
|
|
deleteTemplateCmd.redo();
|
|
}
|
|
}
|
|
}
|
|
|
|
void CPaiWorkflowTemplateTree::ActiveItem(const QString name)
|
|
{
|
|
if(m_pCommonTemplateItem != NULL)
|
|
{
|
|
for(int i = 0; i < m_pCommonTemplateItem->childCount(); ++i)
|
|
{
|
|
if(m_pCommonTemplateItem->child(i) != NULL)
|
|
{
|
|
if(m_pCommonTemplateItem->child(i)->text(0) == name)
|
|
{
|
|
m_pCommonTemplateItem->child(i)->setSelected(true);
|
|
}
|
|
else
|
|
{
|
|
m_pCommonTemplateItem->child(i)->setSelected(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CPaiWorkflowTemplateTree::slotExportTemplates()
|
|
{
|
|
QAction* pAction = dynamic_cast< QAction* > (sender());
|
|
if(pAction == NULL)
|
|
return;
|
|
|
|
emit exportTemplates(TEMPLATE_TYPE);
|
|
}
|
|
|
|
void CPaiWorkflowTemplateTree::slotImportTemplates()
|
|
{
|
|
emit importTemplates(TEMPLATE_TYPE);
|
|
}
|
|
|
|
|
|
void CPaiWorkflowTemplateTree::SetActive(bool bActive)
|
|
{
|
|
m_bActive = bActive;
|
|
}
|
|
|
|
bool CPaiWorkflowTemplateTree::isActive()
|
|
{
|
|
return m_bActive;
|
|
}
|
|
|
|
|