From 23fdba635d5cca4eaff49ee62b1445f319e52940 Mon Sep 17 00:00:00 2001 From: crqiqi77 Date: Fri, 3 Apr 2026 17:26:26 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=91=E7=8E=87=E7=BB=9F=E8=AE=A1=E5=9B=BE?= =?UTF-8?q?=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logPlus/PropertyWidget.cpp | 30 ++++-- logPlus/formdraw.cpp | 96 +++++++------------ logPlus/forminfo.h | 2 +- logPlus/qmycustomplot.cpp | 185 +++++++++++++++++-------------------- logPlus/qmycustomplot.h | 8 +- 5 files changed, 145 insertions(+), 176 deletions(-) diff --git a/logPlus/PropertyWidget.cpp b/logPlus/PropertyWidget.cpp index 6294b2d..a246bad 100644 --- a/logPlus/PropertyWidget.cpp +++ b/logPlus/PropertyWidget.cpp @@ -4213,46 +4213,57 @@ void PropertyWidget::changedPlObjectProperty(QString strProperty, QVariant varVa else if ("线数" == strProperty) { this->m_formInfo->m_pl_lineNumber = varVal.toInt(); + flag = true; } else if ("统计线高度" == strProperty) { this->m_formInfo->m_pl_lineHeight = varVal.toDouble(); + flag = true; } else if ("线粗细" == strProperty) { this->m_formInfo->m_pl_lineThickness = varVal.toInt(); + flag = true; } else if ("线颜色" == strProperty) { this->m_formInfo->m_pl_lineColor = varVal.value(); + flag = true; } else if ("是否绘制标注?" == strProperty) { this->m_formInfo->m_pl_drawAnnotation = varVal.toBool(); + flag = true; } else if ("绘制直方图?" == strProperty) { this->m_formInfo->m_pl_drawHistogram = varVal.toBool(); + flag = true; } else if ("宽度" == strProperty) { this->m_formInfo->m_pl_baselineWidth = varVal.toInt(); + flag = true; } else if ("颜色" == strProperty) { this->m_formInfo->m_pl_baselineColor = varVal.value(); + flag = true; } else if ("统计间隔" == strProperty) { this->m_formInfo->m_pl_statInterval = varVal.toInt(); + flag = true; } else if ("最小倾角" == strProperty) { this->m_formInfo->m_pl_minInclination = varVal.toDouble(); + flag = true; } else if ("最大倾角" == strProperty) { this->m_formInfo->m_pl_maxInclination = varVal.toDouble(); + flag = true; } else if ("高导缝" == strProperty) { @@ -4327,12 +4338,19 @@ void PropertyWidget::changedPlObjectProperty(QString strProperty, QVariant varVa variantMap["m_pl_circleLineWidth"] = this->m_formInfo->m_pl_circleLineWidth; variantMap["m_pl_isFillEnabled"] = this->m_formInfo->m_pl_isFillEnabled; variantMap["m_pl_fillColor"] = this->m_formInfo->m_pl_fillColor; - - - - - - + // 线数 + variantMap["m_pl_lineNumber"] = this->m_formInfo->m_pl_lineNumber; + variantMap["m_pl_lineHeight"] = this->m_formInfo->m_pl_lineHeight; + variantMap["m_pl_lineThickness"] = this->m_formInfo->m_pl_lineThickness; + variantMap["m_pl_lineColor"] = this->m_formInfo->m_pl_lineColor; + variantMap["m_pl_drawAnnotation"] = this->m_formInfo->m_pl_drawAnnotation; + variantMap["m_pl_drawHistogram"] = this->m_formInfo->m_pl_drawHistogram; + variantMap["m_pl_baselineWidth"] = this->m_formInfo->m_pl_baselineWidth; + variantMap["m_pl_baselineColor"] = this->m_formInfo->m_pl_baselineColor; + // 统计间隔 + variantMap["m_pl_statInterval"] = this->m_formInfo->m_pl_statInterval; + variantMap["m_pl_minInclination"] = this->m_formInfo->m_pl_minInclination; + variantMap["m_pl_maxInclination"] = this->m_formInfo->m_pl_maxInclination; emit CallManage::getInstance()->sig_changePlObjectProperty(variantMap); } diff --git a/logPlus/formdraw.cpp b/logPlus/formdraw.cpp index a68cdea..8a307d2 100644 --- a/logPlus/formdraw.cpp +++ b/logPlus/formdraw.cpp @@ -322,71 +322,37 @@ void FormDraw::setDrawData(QStringList listdt, QJsonObject objInfo) // 例区高度 pInfo->setFixedHeight(pInfo->m_headHeight); - - -// // 数据 -// int m_pl_dataType = 0; // 数据类型 -// QString m_pl_azimuthCurve = "DDIR"; // 方位曲线 -// QString m_pl_inclinationCurve = "DANG"; // 倾角曲线 -// // 字体相关配置 -// QFont m_pl_fontScale = QFont("微软雅黑", 7); // 刻度字体大小 -// // 控制曲线参数 -// QString m_pl_controlCurveName = "GRAD"; // 控制曲线名 -// double m_pl_controlMinValue = 0; // 控制最小值 -// double m_pl_controlMaxValue = 100; // 控制最大值 -// // 方位频率绘图参数 -// int m_pl_sectorCount = 36; // 扇形数量 -// double m_pl_circleRadius = 1; // 圆半径(cm) -// QColor m_pl_circleColor = Qt::black; // 圆线颜色 -// int m_pl_circleLineWidth = 2; // 圆线宽度 -// bool m_pl_isFillEnabled = true; // 是否启用填充 -// QColor m_pl_fillColor = Qt::black; // 填充颜色 -// // 倾角频率绘图参数 -// int m_pl_lineNumber = 9; // 线数 -// double m_pl_lineHeight = 2; // 统计线高度 -// int m_pl_lineThickness = 2; // 线粗细 -// QColor m_pl_lineColor = Qt::black; // 线颜色 -// bool m_pl_drawAnnotation = true; // 是否绘制标注 -// bool m_pl_drawHistogram = true; // 是否绘制直方图 -// // 基线参数 -// int m_pl_baselineWidth = 2; // 基线宽度 -// QColor m_pl_baselineColor = Qt::black; // 基线颜色 -// // 统计参数 -// int m_pl_statInterval = 20; // 统计间隔 -// double m_pl_minInclination = 0; // 最小倾角 -// double m_pl_maxInclination = 90; // 最大倾角 -// // 地质要素分类开关 -// bool m_pl_highGap = false; // 高导缝 -// bool m_pl_highReservoir = false; // 高阻缝 -// bool m_pl_reticularFracture = false; // 网状缝 -// bool m_pl_inducedFracture = false; // 诱导缝 -// bool m_pl_bedLayer = false; // 层理 -// bool m_pl_erosionSurface = false; // 侵蚀面 -// bool m_pl_pore = false; // 孔洞 -// bool m_pl_vesicle = false; // 气孔 -// bool m_pl_gravel = false; // 砾石 -// bool m_pl_nodule = false; // 结核 -// bool m_pl_lumps = false; // 团块 -// bool m_pl_fault = false; // 断层 -// bool m_pl_verticalFracture = false; // 垂直缝 -// bool m_pl_custom1 = false; // 自定义1 -// bool m_pl_custom2 = false; // 自定义2 - - - double m_LeftVal3 = pInfo->m_pl_controlMinValue; - double m_RightVal3 = pInfo->m_pl_controlMaxValue; - - - QString csCurveGrad = "GRAD"; - double LeftVal3 = 0; - double RightVal3 = 100; - int nArc = 36; - double nR = 50; - QColor crArc = Qt::black; - int nArcLineWidth = 1; - bool bFill = true; - QColor crFill = Qt::black; - curv->fgrqDraw(csCurveGrad, LeftVal3, RightVal3, nArc, nR, crArc, nArcLineWidth, bFill, crFill); + QString csCurveGrad = pInfo->m_pl_controlCurveName; + double LeftVal3 = pInfo->m_pl_controlMinValue; + double RightVal3 = pInfo->m_pl_controlMaxValue; + int nArc = pInfo->m_pl_sectorCount; + double nR = pInfo->m_pl_circleRadius; + QColor crArc = pInfo->m_pl_circleColor; + int nArcLineWidth = pInfo->m_pl_circleLineWidth; + bool bFill = pInfo->m_pl_isFillEnabled; + QColor crFill = pInfo->m_pl_fillColor; + // 线数 + int lineNumber = pInfo->m_pl_lineNumber; + // 统计线高度 + double lineHeight = pInfo->m_pl_lineHeight; + // 线粗细 + int lineThickness = pInfo->m_pl_lineThickness; + // 线颜色 + QColor lineColor = pInfo->m_pl_lineColor; + // 是否绘制标注? + bool drawAnnotation = pInfo->m_pl_drawAnnotation; + // 绘制直方图? + bool drawHistogram = pInfo->m_pl_drawHistogram; + // 基线参数 + int baselineWidth = pInfo->m_pl_baselineWidth; // 基线宽度 + QColor baselineColor = pInfo->m_pl_baselineColor; // 基线颜色 + // 统计参数 + int statInterval = pInfo->m_pl_statInterval; // 统计间隔 + double minInclination = pInfo->m_pl_minInclination; // 最小倾角 + double maxInclination = pInfo->m_pl_maxInclination; // 最大倾角 + curv->fgrqDraw(csCurveGrad, LeftVal3, RightVal3, nArc, nR, crArc, nArcLineWidth, bFill, crFill, + lineNumber, lineHeight, lineThickness, lineColor, drawAnnotation, drawHistogram, + baselineWidth, baselineColor, statInterval, minInclination, maxInclination); } else if("roseObject" == strType) { diff --git a/logPlus/forminfo.h b/logPlus/forminfo.h index 905e22f..7d9f3cd 100644 --- a/logPlus/forminfo.h +++ b/logPlus/forminfo.h @@ -270,7 +270,7 @@ public: int m_pl_baselineWidth = 2; // 基线宽度 QColor m_pl_baselineColor = Qt::black; // 基线颜色 // 统计参数 - int m_pl_statInterval = 20; // 统计间隔 + int m_pl_statInterval = 10; // 统计间隔 double m_pl_minInclination = 0; // 最小倾角 double m_pl_maxInclination = 90; // 最大倾角 // 地质要素分类开关 diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index 1313e21..34edd2c 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -10044,15 +10044,37 @@ void QMyCustomPlot::s_changePlObjectProperty(QVariantMap variantMap) int nArcLineWidth = variantMap["m_pl_circleLineWidth"].toInt(); bool bFill = variantMap["m_pl_isFillEnabled"].toBool(); QColor crFill = variantMap["m_pl_fillColor"].value(); + // 线数 + int lineNumber = variantMap["m_pl_lineNumber"].toInt(); + // 统计线高度 + double lineHeight = variantMap["m_pl_lineHeight"].toDouble(); + // 线粗细 + int lineThickness = variantMap["m_pl_lineThickness"].toInt(); + // 线颜色 + QColor lineColor = variantMap["m_pl_lineColor"].value(); + // 是否绘制标注? + bool drawAnnotation = variantMap["m_pl_drawAnnotation"].toBool(); + // 绘制直方图? + bool drawHistogram = variantMap["m_pl_drawHistogram"].toBool(); + // 宽度 + int baselineWidth = variantMap["m_pl_baselineWidth"].toInt(); + // 颜色 + QColor baselineColor = variantMap["m_pl_baselineColor"].value(); + // 统计间隔 + int statInterval = variantMap["m_pl_statInterval"].toInt(); + double minInclination = variantMap["m_pl_minInclination"].toDouble(); + double maxInclination = variantMap["m_pl_maxInclination"].toDouble(); - - - this->fgrqDraw(csCurveGrad, LeftVal3, RightVal3, nArc, nR, crArc, nArcLineWidth, bFill, crFill); + this->fgrqDraw(csCurveGrad, LeftVal3, RightVal3, nArc, nR, crArc, nArcLineWidth, bFill, crFill, + lineNumber, lineHeight, lineThickness, lineColor, drawAnnotation, drawHistogram, baselineWidth, + baselineColor, statInterval, minInclination, maxInclination); } void QMyCustomPlot::fgrqDraw(QString csCurveGrad, double LeftVal3, double RightVal3, int nArc, - double nR, QColor crArc, int nArcLineWidth, bool bFill, QColor crFill) + double nR, QColor crArc, int nArcLineWidth, bool bFill, QColor crFill, + int lineNumber, double lineHeight, int lineThickness, QColor lineColor, bool drawAnnotation, bool drawHistogram, + int baselineWidth, QColor baselineColor, int nstep, double LeftVal, double RightVal) { this->clearGraphs(); this->clearItems(); @@ -10080,10 +10102,8 @@ void QMyCustomPlot::fgrqDraw(QString csCurveGrad, double LeftVal3, double RightV float x,y,x1,y1,x2,y2; float ifdir[360]; - float m_LeftVal = 0.0f; - float m_RightVal = 90.0f; - float mind=min(m_RightVal , m_LeftVal); - float maxd=max(m_RightVal , m_LeftVal); + float mind=min(RightVal , LeftVal); + float maxd=max(RightVal , LeftVal); float dirmax,dipmax,dr; float deps; float ftmpSdep = m_SDep; @@ -10106,7 +10126,6 @@ void QMyCustomPlot::fgrqDraw(QString csCurveGrad, double LeftVal3, double RightV int nPointNum = m_FracTabList.count(); int n = m_FracDefList.count(); - int nstep = 5; int tmp = ftmpSdep / nstep; float flDep = tmp * nstep; @@ -10130,11 +10149,11 @@ void QMyCustomPlot::fgrqDraw(QString csCurveGrad, double LeftVal3, double RightV { // 圆里面的十字 QCPItemLine* pLine1 = new QCPItemLine(this); + pLine1->setPen(QPen(baselineColor, baselineWidth)); pLine1->m_bCustom = true; pLine1->m_dr = qDegreesToRadians(k*90.0); pLine1->m_nRadius = 0; pLine1->m_nTailLen=nR; - pLine1->setPen(wPen); pLine1->start->setCoords(centerY,centerX); pLine1->end->setCoords(centerY,centerX); } @@ -10237,10 +10256,16 @@ void QMyCustomPlot::fgrqDraw(QString csCurveGrad, double LeftVal3, double RightV } } + int iIndex; flVal = 3.1415926535 *2./ nArc ; dirmax=0; dipmax=0; for(i=0;i<=nArc;i++) - if (dirmaxbottomRight->setCoords(x, y); } +//float ifdir[360], int iIndex, float dirmax - + if(drawAnnotation) + { + this->drawDipAngle(centerX, centerY, ifdir, iIndex, dirmax, lineNumber, lineHeight, lineThickness, lineColor, + drawHistogram, baselineWidth, baselineColor, LeftVal, RightVal); + } flDep += nstep; } - this->drawDipAngle(0, 0); + this->replot(); } -void QMyCustomPlot::drawDipAngle(double centerX, double centerY) +void QMyCustomPlot::drawDipAngle(double centerX, double centerY, float ifdir[360], int iIndex, float dirmax, +int lineNumber, double lineHeight, int lineThickness, QColor lineColor, bool drawHistogram, +int baselineWidth, QColor baselineColor, double minInclination, double maxInclination) { - // 2. 开启 QCustomPlot 的绘制层 - this->setBackground(Qt::white); - this->axisRect()->setBackground(Qt::white); + double startX = centerX + 400; + double startY = centerY - 5; + QCPItemLine *line = new QCPItemLine(this); + line->setPen(QPen(baselineColor, baselineWidth)); + line->start->setCoords(startY, startX); + line->end->setCoords(startY, startX - 800); - // 3. 获取绘制对象(关键!直接拿到 painter) - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); + if(drawHistogram) + { + QCPItemText *minText = new QCPItemText(this); + minText->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter); + minText->position->setCoords(startY, startX - 800); + minText->setFont(QFont("微软雅黑", 8)); + minText->setText(QString::number(minInclination)); - // 4. 获取绘制区域 - QRect drawRect = this->axisRect()->rect(); + QCPItemText *maxText = new QCPItemText(this); + maxText->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter); + maxText->position->setCoords(startY, startX); + maxText->setFont(QFont("微软雅黑", 8)); + maxText->setText(QString::number(maxInclination)); + } - // 5. 画测试线:左上角 → 右下角(红色粗线,看得清) - QPen pen(Qt::red); - pen.setWidth(2); - painter.setPen(pen); - painter.drawLine(drawRect.topLeft(), drawRect.bottomRight()); + // ===================== 关键:每个刻度长度都不一样 ===================== + const double totalLen = 800; + const double step = totalLen / (lineNumber - 1); - // 6. 标记文字 - painter.setPen(Qt::black); - painter.drawText(drawRect, Qt::AlignTop|Qt::AlignLeft, "左上角"); - painter.drawText(drawRect, Qt::AlignBottom|Qt::AlignRight, "右下角"); + for (int i = 0; i < lineNumber; ++i) + { + double currY = startX - i * step; + + // 🔥🔥🔥 核心:每个刻度单独计算长度(和你GDI完全一样,每个长度不同) + double dynamicLen = 0.1 * ifdir[i] / dirmax + lineHeight; + + QCPItemLine *scaleLine = new QCPItemLine(this); + scaleLine->setPen(QPen(lineColor, lineThickness)); + scaleLine->start->setCoords(startY, currY); + scaleLine->end->setCoords(startY + dynamicLen, currY); // 每个刻度长度不同 + } - - - - - - - - - - - - - - - - -// // 拿到 QCustomPlot 的画布区域 -// QRect rect = this->axisRect()->rect(); // 绘制区域(和你原来的 rect 一致) - -//// rect.getRect(); - -// // 你原来的所有坐标逻辑 1:1 保留 -// int baseY = rect.top() + rect.height() * 2 / 3; -// int textH = rect.height() / 3; -// int lineY = baseY + textH - 7; -// int x1 = rect.left() + 20; -// int x2 = rect.right() - 30; - -// // 开始在 QCustomPlot 上绘制 -// QPainter painter(this); -// painter.setRenderHint(QPainter::Antialiasing); - -// // 1. 画底部刻度主线(完全不变) -// painter.drawLine(0, 0, 100, 100); - -// // 2. 字体 -//// QFont oldFont = painter.font(); -//// painter.setFont(m_cp_curveScale); - -// // 3. 你的参数(完全不变) -// int minVal = 0; -// int maxVal = 100; -//// if(m_cp_scaleDivisionsOrCustom <= 0) -//// m_cp_scaleDivisionsOrCustom = 1; -// int tickCount = 9 + 1; -// int tickHeight = 6; -// int textOffsetUp = 18; - -// // 4. 计算步长(完全不变) -// double step = (maxVal - minVal) * 1.0 / (tickCount - 1); - -// // 5. 循环画刻度 + 文字(完全不变) -// for (int i = 0; i < tickCount; ++i) { -// int val = minVal + qRound(step * i); -// qreal ratio = (val - minVal) * 1.0 / (maxVal - minVal); -// int tickX = x1 + ratio * (x2 - x1); - -// // 画小刻度 -// painter.drawLine(tickX, lineY, tickX, lineY - tickHeight); - -// // 画文字(位置完全一样) -// painter.drawText( -// tickX - 12, -// lineY - tickHeight - textOffsetUp, -// 24, 14, -// Qt::AlignCenter, -// QString::number(val) -// ); -// } - -// painter.setFont(oldFont); +// QRect rect = this->axisRect()->rect(); +// qDebug() << centerY << "--==--=-=-=" << centerX << "-----------" << rect; } void QMyCustomPlot::Refurbish() diff --git a/logPlus/qmycustomplot.h b/logPlus/qmycustomplot.h index 611c007..62e9e02 100644 --- a/logPlus/qmycustomplot.h +++ b/logPlus/qmycustomplot.h @@ -637,9 +637,13 @@ public: QString m_qsDepth,m_qsDIP,m_qsDIR,m_qsID,m_qsProperty; // 控制曲线 float m_SDep,m_EDep,m_Rlev; // csCurveGrad曲线名 LeftVal3最小值 RightVal3最大值 nArc扇形 nR圆半径 crArc圆颜色 nArcLineWidth圆线宽度 bFill是否填充 - void fgrqDraw(QString csCurveGrad, double LeftVal3, double RightVal3, int nArc, double nR, QColor crArc, int nArcLineWidth, bool bFill, QColor crFill); + void fgrqDraw(QString csCurveGrad, double LeftVal3, double RightVal3, int nArc, double nR, QColor crArc, int nArcLineWidth, bool bFill, QColor crFill, + int lineNumber, double lineHeight, int lineThickness, QColor lineColor, bool drawAnnotation, bool drawHistogram, + int baselineWidth, QColor baselineColor, int nstep, double minInclination, double maxInclination); // 绘制倾角 - void drawDipAngle(double centerX, double centerY); + void drawDipAngle(double centerX, double centerY, float ifdir[360], int iIndex, float dirmax, + int lineNumber, double lineHeight, int lineThickness, QColor lineColor, bool drawHistogram, + int baselineWidth, QColor baselineColor, double minInclination, double maxInclination); void Refurbish();