裂缝 属性

This commit is contained in:
crqiqi77 2026-04-23 09:38:17 +08:00
parent e510af2405
commit 30d7301cd6
2 changed files with 64 additions and 15 deletions

View File

@ -183,6 +183,7 @@ bool CPickFrac::saveToFile()
return false;
}
// 如果没有裂缝,清空表记录
if (m_items.isEmpty()) {
logio->SetTableRecordCount(iIndex, 0);
logio->CloseTable(iIndex);
@ -191,6 +192,7 @@ bool CPickFrac::saveToFile()
return true;
}
// 按深度排序
QMap<double, DraggableCrackItem*> sortedMap;
for (DraggableCrackItem *item : m_items) {
double depth = item->getDepthForSort();
@ -216,11 +218,46 @@ void CPickFrac::onRemoveCrackItem(DraggableCrackItem *item)
{
if (!item) return;
if (m_items.removeOne(item)) {
// 立即从画布移除所有图形项
item->cleanupFromPlot();
// 失活并清空静态指针
if (DraggableCrackItem::getActiveItem() == item) {
item->deactivate();
}
// 断开信号
disconnect(item, nullptr, this, nullptr);
// 延迟删除,确保当前事件完全结束
QTimer::singleShot(0, item, &QObject::deleteLater);
saveToFile();
// 直接删除,不再延迟
delete item;
// 强制重绘
m_myCustomPlot->replot();
// 保存文件
saveToFile();
}
}
void DraggableCrackItem::cleanupFromPlot()
{
if (m_type == TypeA_Sine) {
if (m_curve) m_plot->removeItem(m_curve);
if (m_tracer1) m_plot->removeItem(m_tracer1);
if (m_tracer2) m_plot->removeItem(m_tracer2);
} else if (m_type == TypeB_Polyline) {
for (auto &item : m_lines) {
if (item.line) m_plot->removeItem(item.line);
if (item.startTracer) m_plot->removeItem(item.startTracer);
if (item.endTracer) m_plot->removeItem(item.endTracer);
}
m_lines.clear();
} else if (m_type == TypeC_Closed) {
if (m_curveC) {
m_plot->removePlottable(m_curveC);
m_curveC = nullptr;
}
for (auto label : m_labelsC) {
if (label) m_plot->removeItem(label);
}
m_labelsC.clear();
m_pointsC.clear();
}
}
@ -316,12 +353,15 @@ void DraggableCrackItem::deactivate()
m_draggedPointIndex = -1;
setDragPointsVisible(false);
}
if (s_activeItem == this) s_activeItem = nullptr;
if (s_activeItem == this) {
s_activeItem = nullptr;
}
m_plot->replot();
}
void DraggableCrackItem::setDragPointsVisible(bool visible)
{
if (m_pendingDelete) return;
if (m_type == TypeA_Sine) {
if (m_tracer1) m_tracer1->setVisible(visible);
if (m_tracer2) m_tracer2->setVisible(visible);
@ -340,6 +380,7 @@ void DraggableCrackItem::setDragPointsVisible(bool visible)
void DraggableCrackItem::startEditing()
{
if (m_pendingDelete) return;
m_editingMode = true;
if (s_activeItem && s_activeItem != this) s_activeItem->deactivate();
s_activeItem = this;
@ -470,7 +511,6 @@ void DraggableCrackItem::setPolylineData(const QVector<QPointF> &points, double
item.startTracer = startTracer;
item.endTracer = endTracer;
m_lines.append(item);
i++;
}
updateLinesPosition();
}
@ -493,9 +533,9 @@ void DraggableCrackItem::updateLinesPosition()
void DraggableCrackItem::clearLines()
{
for (auto &item : m_lines) {
if (item.line) { m_plot->removeItem(item.line); delete item.line; }
if (item.startTracer) { m_plot->removeItem(item.startTracer); delete item.startTracer; }
if (item.endTracer) { m_plot->removeItem(item.endTracer); delete item.endTracer; }
if (item.line) { m_plot->removeItem(item.line); }
if (item.startTracer) { m_plot->removeItem(item.startTracer); }
if (item.endTracer) { m_plot->removeItem(item.endTracer); }
}
m_lines.clear();
m_plot->replot();
@ -547,8 +587,7 @@ void DraggableCrackItem::clearPolylineC()
{
for (auto label : m_labelsC) {
if (label) {
label->setParent(nullptr);
delete label;
m_plot->removeItem(label);
}
}
m_labelsC.clear();
@ -640,10 +679,10 @@ bool DraggableCrackItem::eventFilter(QObject *obj, QEvent *event)
QAction *selectedAction = menu.exec(ce->globalPos());
if (selectedAction == deleteAction) {
m_pendingDelete = true;
deactivate(); // 清空全局激活指针
emit removeMe(this);
deactivate(); // 清空全局激活指针
emit removeMe(this); // 触发删除
}
return true;
return true; // 阻止事件继续传递
}
return false;
}
@ -976,6 +1015,12 @@ bool DraggableCrackItem::eventFilter(QObject *obj, QEvent *event)
}
}
}
if (s_activeItem == this) {
s_activeItem->deactivate();
s_activeItem = nullptr;
return true;
}
}
return false;
}

View File

@ -66,7 +66,7 @@ public:
void setDraggingEnabled(bool enabled);
QList<DraggableCrackItem*> getAllItems() const { return m_items; }
bool saveToFile();
bool createNewCrack(int iType, double depth); // 根据形状类型创建
bool createNewCrack(int iType, double depth);
public:
QMyCustomPlot *m_myCustomPlot;
@ -124,6 +124,8 @@ public:
// 获取当前激活的item静态
static DraggableCrackItem* getActiveItem() { return s_activeItem; }
void cleanupFromPlot(); // 立即从画布移除所有图形项
signals:
void dataChanged();
void removeMe(DraggableCrackItem* item);
@ -172,7 +174,9 @@ private:
// 编辑模式标志
bool m_editingMode = false;
bool m_pendingDelete = false; // 标记是否即将删除
// 删除安全标志
bool m_pendingDelete = false;
// 辅助函数
void updateCurveFromTargets();