2025-10-29 17:23:30 +08:00
|
|
|
|
#include "qmytreewidget.h"
|
2026-04-07 13:53:01 +08:00
|
|
|
|
#include "ObjWellLog.h"
|
|
|
|
|
|
#include<QMessageBox>
|
2025-10-29 17:23:30 +08:00
|
|
|
|
|
|
|
|
|
|
QMyTreeWidget::QMyTreeWidget(QWidget *parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
setDragEnabled(true);
|
|
|
|
|
|
setDefaultDropAction(Qt::MoveAction); // 或者 Qt::CopyAction,取决于你的需求
|
|
|
|
|
|
setAcceptDrops(true);
|
|
|
|
|
|
setDropIndicatorShown(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QMyTreeWidget::~QMyTreeWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-16 16:33:56 +08:00
|
|
|
|
QString QMyTreeWidget::getCurrentItemString()
|
|
|
|
|
|
{
|
|
|
|
|
|
QString sret = "";
|
|
|
|
|
|
QTreeWidgetItem *item = currentItem();
|
|
|
|
|
|
if(!item)
|
|
|
|
|
|
return sret;
|
|
|
|
|
|
if(item->parent()==NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
return sret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString strTreeTag = item->data(0, Qt::UserRole).toString();
|
2026-01-20 17:20:17 +08:00
|
|
|
|
if (strTreeTag == "wellItem")//井次名称
|
2025-12-16 16:33:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
//曲线
|
|
|
|
|
|
QString strSlfName = item->data(0, Qt::UserRole+1).toString();
|
|
|
|
|
|
//井名
|
|
|
|
|
|
QString strWellName = item->text(0);
|
|
|
|
|
|
|
|
|
|
|
|
sret = strSlfName + "#@@#"+ strWellName + "#@@#" +item->text(0)+ "#@@#" + strTreeTag;
|
|
|
|
|
|
}
|
|
|
|
|
|
return sret;
|
|
|
|
|
|
}
|
2026-04-07 13:53:01 +08:00
|
|
|
|
void QMyTreeWidget::closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint )
|
|
|
|
|
|
{
|
|
|
|
|
|
QTreeWidget::closeEditor(editor,hint);
|
|
|
|
|
|
QTreeWidgetItem *item = this->currentItem();
|
|
|
|
|
|
QString strSlfName = item->data(0, Qt::UserRole+1).toString();
|
|
|
|
|
|
QString strOldName = item->data(0, Qt::UserRole + 3).toString();
|
|
|
|
|
|
QString strNewName = item->text(0).toUpper();
|
|
|
|
|
|
if(!IsValidNmae(strNewName))
|
|
|
|
|
|
{
|
|
|
|
|
|
QString value="A~Za~z0~9#_-*\nαβγδεζηθικλμνξοπρστυφχψ";
|
|
|
|
|
|
QMessageBox::warning(NULL,"非法命名",strNewName+"不符合命名规则\r\n仅支持下列符号:\n"+value);
|
|
|
|
|
|
this->currentItem()->setText(0,strOldName);
|
|
|
|
|
|
// this->setItemSelected(item,true);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
//whp 2020.7.19end
|
|
|
|
|
|
if(strOldName==strNewName) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
QString strTreeTag = item->data(0, Qt::UserRole).toString();
|
2026-04-10 06:38:45 +08:00
|
|
|
|
if (strTreeTag != "wellItem" && strTreeTag != "wellname")//重命名表格、曲线、波列、参数表
|
|
|
|
|
|
{
|
|
|
|
|
|
CObjWellLog* pcopyingwelllog= new CObjWellLog();
|
|
|
|
|
|
pcopyingwelllog->SetSlfFileName(strSlfName);
|
|
|
|
|
|
pcopyingwelllog->SetName(strOldName);
|
|
|
|
|
|
if(!pcopyingwelllog->RenName(strNewName))
|
|
|
|
|
|
{
|
|
|
|
|
|
this->currentItem()->setText(0,strOldName);
|
2026-04-07 13:53:01 +08:00
|
|
|
|
// pObj->SetName(strOldName);
|
|
|
|
|
|
// AfxMessageBox("无法改名,可能因重名等问题所致!");
|
|
|
|
|
|
QMessageBox::information(NULL, "提示", "无法改名,可能因重名等问题所致!");
|
|
|
|
|
|
}
|
2026-04-10 06:38:45 +08:00
|
|
|
|
//else {
|
|
|
|
|
|
//::GetObjectEvent().OnDeAttchData(pObj->GetSlfFileName(),strOldName);
|
|
|
|
|
|
//::GetObjectEvent().OnRefreshData(pObj->GetSlfFileName(),strNewName);
|
|
|
|
|
|
//}
|
|
|
|
|
|
delete pcopyingwelllog;
|
|
|
|
|
|
item->setData(0, Qt::UserRole + 3, strNewName); // 存储额外数据,波列卡
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (strTreeTag == "wellItem" || strTreeTag == "wellname")//井次或井名
|
|
|
|
|
|
emit closeTreeEditor();
|
2026-04-07 13:53:01 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-10-29 17:23:30 +08:00
|
|
|
|
void QMyTreeWidget::startDrag(Qt::DropActions supportedActions)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(currentItem()->parent()==NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
//分类节点不能拖动
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创建拖拽事件
|
|
|
|
|
|
QTreeWidgetItem *item = currentItem();
|
|
|
|
|
|
QString strTreeTag = item->data(0, Qt::UserRole).toString();
|
|
|
|
|
|
if (strTreeTag == "root")
|
|
|
|
|
|
{
|
|
|
|
|
|
//根节点(项目名称)
|
|
|
|
|
|
}
|
2025-11-21 10:14:28 +08:00
|
|
|
|
else if (strTreeTag == "curveObject" || strTreeTag == "waveObject" || strTreeTag == "tableObject"){
|
2025-11-18 11:40:42 +08:00
|
|
|
|
//曲线
|
2025-10-29 17:23:30 +08:00
|
|
|
|
QString strSlfName = item->data(0, Qt::UserRole+1).toString();
|
|
|
|
|
|
QString strWellName = item->data(0, Qt::UserRole+2).toString();
|
|
|
|
|
|
|
|
|
|
|
|
//曲线对象(AC、BS...)
|
|
|
|
|
|
QMimeData *mimeData = new QMimeData;
|
|
|
|
|
|
// 这里需要根据你的item数据来设置mimeData,例如:
|
2025-11-21 10:14:28 +08:00
|
|
|
|
mimeData->setText(strSlfName + "#@@#"+ strWellName + "#@@#" +item->text(0)+ "#@@#" + strTreeTag);
|
2025-11-18 11:40:42 +08:00
|
|
|
|
// 创建QDrag对象
|
|
|
|
|
|
QDrag *drag = new QDrag(this);
|
|
|
|
|
|
drag->setMimeData(mimeData);
|
|
|
|
|
|
// 可以设置拖拽时的光标图标
|
|
|
|
|
|
QRect itemRect = visualItemRect(item); // 获取项的矩形区域
|
|
|
|
|
|
QPixmap itemPixmap = QWidget::grab(itemRect);//QPixmap::grabWidget(this, itemRect); // 获取项的屏幕截图
|
|
|
|
|
|
// 调整拖拽光标的热点,使其位于截图的中心
|
|
|
|
|
|
drag->setPixmap(itemPixmap);
|
|
|
|
|
|
|
2025-10-29 17:23:30 +08:00
|
|
|
|
// 执行拖拽操作
|
|
|
|
|
|
Qt::DropAction dropAction = drag->exec(supportedActions, Qt::MoveAction);
|
|
|
|
|
|
/*if (dropAction == Qt::MoveAction) {
|
|
|
|
|
|
// 处理拖拽结束的逻辑,例如从界面上移除拖拽的项
|
|
|
|
|
|
for (QTreeWidgetItem *item : items) {
|
|
|
|
|
|
this->takeTopLevelItem(this->indexOfTopLevelItem(item));
|
|
|
|
|
|
}
|
|
|
|
|
|
}*/
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|