From 6588598f428255f218bf1eb15d51d0732e610871 Mon Sep 17 00:00:00 2001 From: crqiqi77 Date: Thu, 26 Mar 2026 17:38:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B2=A9=E5=BF=83=E5=88=86=E6=9E=90=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logPlus/PropertyWidget.cpp | 82 ++++++++++++++++++--- logPlus/TransparentDraggableCorePhysics.cpp | 62 ++++++++++++++-- logPlus/TransparentDraggableCorePhysics.h | 10 +-- logPlus/formdraw.cpp | 44 ++++++++++- logPlus/forminfo.cpp | 6 +- logPlus/forminfo.h | 6 ++ 6 files changed, 188 insertions(+), 22 deletions(-) diff --git a/logPlus/PropertyWidget.cpp b/logPlus/PropertyWidget.cpp index 54e3381..0e2f89b 100644 --- a/logPlus/PropertyWidget.cpp +++ b/logPlus/PropertyWidget.cpp @@ -443,6 +443,67 @@ void PropertyWidget::changedCorePhysicsProperty(QtProperty *qtProperty, const QV this->m_tdCorePhysics->setCpCoreValue(temp); this->m_tdCorePhysics->mPlot->saveToSLFCorePhysics(); } + else if("左刻度" == m_propertyData[qtProperty]) + { + double temp = variant.toDouble(); + this->m_formInfo->m_cp_leftScale = temp; + this->m_tdCorePhysics->setCpLeftScale(temp); + } + else if("右刻度" == m_propertyData[qtProperty]) + { + double temp = variant.toDouble(); + this->m_formInfo->m_cp_rightScale = temp; + this->m_tdCorePhysics->setCpRightScale(temp); + } + else if("等分刻度数或自定义序列" == m_propertyData[qtProperty]) + { + double temp = variant.toDouble(); + this->m_formInfo->m_cp_scaleDivisionsOrCustom = temp; + this->m_tdCorePhysics->setCpScaleDivisionsOrCustom(temp); + + } + else if("刻度类型" == m_propertyData[qtProperty]) + { + int newStyle = 0; + int iStyle = variant.value(); + switch(iStyle) + { + case 0: + // 线性 + newStyle = 0; + break; + case 1: + // 对数 + newStyle = 1; + break; + case 2: + // 倾角 + newStyle = 2; + break; + } + this->m_formInfo->m_cp_scaleType = newStyle; + this->m_tdCorePhysics->setCpScaleType(newStyle); + + } + else if("显示单位" == m_propertyData[qtProperty]) + { + QString temp = variant.toString(); + this->m_formInfo->m_strUnit = temp; + this->m_tdCorePhysics->setCpDisplayUnit(temp); + this->m_formInfo->repaint(); + } + else if("曲线单位" == m_propertyData[qtProperty]) + { + QFont temp = variant.value(); + this->m_formInfo->m_strUnitFont = temp; + this->m_formInfo->repaint(); + } + else if("曲线刻度" == m_propertyData[qtProperty]) + { + QFont temp = variant.value(); + this->m_formInfo->m_cp_curveScale = temp; + this->m_tdCorePhysics->setCpCurveScale(temp); + } this->m_tdCorePhysics->update(); } @@ -3261,7 +3322,6 @@ void PropertyWidget::initCorePhysicsItemProperty(TransparentDraggableCorePhysics m_strUuid = formInfo->m_strUuid; m_strTrackUuid = formInfo->m_strTrackUuid; - // m_strSlfName = formInfo->m_strSlfName; m_strWellName = formInfo->m_strWellName; m_strTrackName = formInfo->m_strTrackName; @@ -3284,15 +3344,19 @@ void PropertyWidget::initCorePhysicsItemProperty(TransparentDraggableCorePhysics listStyle.append("虚点点线"); _CreateEnumPropertyItem("曲线线型", "线型", (int)formInfo->m_cp_lineStyle, listStyle); - _CreateVariantPropertyItem("显示设置", "左刻度", formInfo->m_yxzpLabelFont, QVariant::Font); - _CreateVariantPropertyItem("显示设置", "右刻度", formInfo->m_yxzpLabelRotation, QVariant::Int); - _CreateVariantPropertyItem("显示设置", "等分刻度数或自定义序列", formInfo->m_yxzpTwoEndDrawing, QVariant::Bool); - _CreateVariantPropertyItem("显示设置", "刻度类型", formInfo->m_yxzpDrawColor, QVariant::Bool); - _CreateVariantPropertyItem("显示设置", "显示单位", formInfo->m_nRotationAngle, QVariant::Double); + _CreateVariantPropertyItem("显示设置", "左刻度", formInfo->m_cp_leftScale, QVariant::Double); + _CreateVariantPropertyItem("显示设置", "右刻度", formInfo->m_cp_rightScale, QVariant::Double); + _CreateVariantPropertyItem("显示设置", "等分刻度数或自定义序列", formInfo->m_cp_scaleDivisionsOrCustom, QVariant::Int); + QStringList listStyle4; + listStyle4.append("线性"); + listStyle4.append("对数"); + listStyle4.append("倾角"); + _CreateEnumPropertyItem("显示设置", "刻度类型", formInfo->m_cp_scaleType, listStyle4); + _CreateVariantPropertyItem("显示设置", "显示单位", formInfo->m_strUnit, QVariant::String); - _CreateVariantPropertyItem("字体", "曲线名称", formInfo->m_yxzpTwoEndDrawing, QVariant::Bool); - _CreateVariantPropertyItem("字体", "曲线单位", formInfo->m_yxzpDrawColor, QVariant::Bool); - _CreateVariantPropertyItem("字体", "曲线刻度", formInfo->m_nRotationAngle, QVariant::Double); + _CreateVariantPropertyItem("字体", "字体", formInfo->m_curveNameFont, QVariant::Font); + _CreateVariantPropertyItem("字体", "曲线单位", formInfo->m_strUnitFont, QVariant::Font); + _CreateVariantPropertyItem("字体", "曲线刻度", formInfo->m_cp_curveScale, QVariant::Font); _CreateVariantPropertyItem("绘制方式", "杆状", formInfo->m_cp_drawAsBar, QVariant::Bool); _CreateVariantPropertyItem("绘制方式", "左界", formInfo->m_cp_leftBoundary, QVariant::Bool); diff --git a/logPlus/TransparentDraggableCorePhysics.cpp b/logPlus/TransparentDraggableCorePhysics.cpp index c114b4b..4143eb9 100644 --- a/logPlus/TransparentDraggableCorePhysics.cpp +++ b/logPlus/TransparentDraggableCorePhysics.cpp @@ -49,6 +49,9 @@ void TransparentDraggableCorePhysics::setRange(double left_Low, double right_Hig } } m_lY1 = lY1; + // lY2除以实际左到右刻度数值 + lY2 = lY2 / (getCpRightScale() - getCpLeftScale()) * 100; + qcpItemLine->start->setCoords(left_Low, lY1);//圆心位置 qcpItemLine->end->setCoords(right_Hight, lY2);//圆心位置 @@ -111,9 +114,9 @@ void TransparentDraggableCorePhysics::initRect() tracer = new QCPItemTracer(this->mPlot); tracer->setGraph(nullptr); // 不关联曲线,自由定位 tracer->setStyle(QCPItemTracer::tsCircle); // 圆形,可选:tsSquare, tsCross, tsPlus等 - tracer->setSize(8); // 点的大小(像素) + tracer->setSize(3); // 点的大小(像素) tracer->setPen(QPen(Qt::red)); // 边框颜色 - tracer->setBrush(QBrush(Qt::yellow)); // 填充颜色 + tracer->setBrush(QBrush(QColor(0, 0, 0, 0))); // 黄色半透明,Alpha=128 tracer->setInterpolating(false); // 绑定到线条终点(关键!) tracer->position->setParentAnchor(this->qcpItemLine->end); @@ -374,6 +377,10 @@ double TransparentDraggableCorePhysics::getCpLeftScale() const void TransparentDraggableCorePhysics::setCpLeftScale(double value) { this->m_cp_leftScale = value; + + this->mPlot->yAxis2->setRange(value, this->mPlot->yAxis2->range().upper); + // 重新绘制图形 + this->setRange(this->m_left_Low, this->m_left_Low, this->getCpCoreValue(), false); } double TransparentDraggableCorePhysics::getCpRightScale() const @@ -384,6 +391,10 @@ double TransparentDraggableCorePhysics::getCpRightScale() const void TransparentDraggableCorePhysics::setCpRightScale(double value) { this->m_cp_rightScale = value; + + this->mPlot->yAxis2->setRange(this->mPlot->yAxis2->range().lower, value); + // 重新绘制图形 + this->setRange(this->m_left_Low, this->m_left_Low, this->getCpCoreValue(), false); } int TransparentDraggableCorePhysics::getCpScaleType() const @@ -394,6 +405,23 @@ int TransparentDraggableCorePhysics::getCpScaleType() const void TransparentDraggableCorePhysics::setCpScaleType(int value) { this->m_cp_scaleType = value; + + int newStyle = 0; + switch(value) + { + case 0: + // 线性 + this->mPlot->yAxis2->setScaleType(QCPAxis::stLinear); + break; + case 1: + // 对数 + this->mPlot->yAxis2->setScaleType(QCPAxis::stLogarithmic); + break; + case 2: + // 倾角 没有倾角类型 + this->mPlot->yAxis2->setScaleType(QCPAxis::stLogarithmic); + break; + } } int TransparentDraggableCorePhysics::getCpScaleDivisionsOrCustom() const @@ -404,6 +432,24 @@ int TransparentDraggableCorePhysics::getCpScaleDivisionsOrCustom() const void TransparentDraggableCorePhysics::setCpScaleDivisionsOrCustom(int value) { this->m_cp_scaleDivisionsOrCustom = value; + + // 创建文本刻度 Ticker + QSharedPointer textTicker(new QCPAxisTickerText); + double minVal = this->mPlot->yAxis2->range().lower; + double maxVal = this->mPlot->yAxis2->range().upper; + // 计算步长:(最大值 - 最小值) / 等分数 + double step = (maxVal - minVal) / value; + // 生成刻度 + for (int i = 0; i <= value; ++i) { + double value = minVal + step * i; + // 取整显示(34.0 显示为 "34") + QString label = QString::number(qRound(value)); + textTicker->addTick(value, label); + } + // 应用 Ticker + this->mPlot->yAxis2->setTicker(textTicker); + // 设置范围(稍微留边距,让刻度显示完整) +// this->mPlot->yAxis2->setRange(minVal - step * 0.1, maxVal + step * 0.1); } QString TransparentDraggableCorePhysics::getCpDisplayUnit() const @@ -436,14 +482,16 @@ void TransparentDraggableCorePhysics::setCpCurveUnit(const QString &value) this->m_cp_curveUnit = value; } -double TransparentDraggableCorePhysics::getCpCurveScale() const +QFont TransparentDraggableCorePhysics::getCpCurveScale() const { return this->m_cp_curveScale; } -void TransparentDraggableCorePhysics::setCpCurveScale(double value) +void TransparentDraggableCorePhysics::setCpCurveScale(QFont value) { this->m_cp_curveScale = value; + + this->mPlot->yAxis2->setTickLabelFont(value); } bool TransparentDraggableCorePhysics::getCpDrawAsBar() const @@ -587,7 +635,11 @@ void TransparentDraggableCorePhysics::setCpSymbolSize(int value) { this->m_cp_symbolSize = value; - tracer->setSize(value); // 点的大小(像素) + QList tracers = this->mPlot->findChildren(); + foreach (QCPItemTracer *tracer, tracers) { + tracer->setSize(value); // 点的大小(像素) + } + } QColor TransparentDraggableCorePhysics::getCpSymbolFillColor() const diff --git a/logPlus/TransparentDraggableCorePhysics.h b/logPlus/TransparentDraggableCorePhysics.h index aba0bd7..37dcb32 100644 --- a/logPlus/TransparentDraggableCorePhysics.h +++ b/logPlus/TransparentDraggableCorePhysics.h @@ -87,8 +87,8 @@ public: QString getCpCurveUnit() const; void setCpCurveUnit(const QString &value); - double getCpCurveScale() const; - void setCpCurveScale(double value); + QFont getCpCurveScale() const; + void setCpCurveScale(QFont value); bool getCpDrawAsBar() const; void setCpDrawAsBar(bool value); @@ -130,14 +130,14 @@ private: int m_cp_lineWidth; // 线宽 QColor m_cp_lineColor; // 线条颜色 Qt::PenStyle m_cp_lineStyle; // 线型 - double m_cp_leftScale; // 左刻度 - double m_cp_rightScale; // 右刻度 + double m_cp_leftScale = 0; // 左刻度 + double m_cp_rightScale = 100; // 右刻度 int m_cp_scaleType; // 刻度类型 int m_cp_scaleDivisionsOrCustom; // 等分刻度数或自定序列 QString m_cp_displayUnit; // 显示单位 QString m_cp_curveName; // 曲线名称 QString m_cp_curveUnit; // 曲线单位 - double m_cp_curveScale; // 曲线刻度 + QFont m_cp_curveScale; // 曲线刻度 bool m_cp_drawAsBar; // 杆状 bool m_cp_leftBoundary; // 左界 bool m_cp_skipZeroInvalidValues; // 不绘零等无效值 diff --git a/logPlus/formdraw.cpp b/logPlus/formdraw.cpp index 9fc63a2..f158a5b 100644 --- a/logPlus/formdraw.cpp +++ b/logPlus/formdraw.cpp @@ -6602,11 +6602,53 @@ void FormDraw::initCorePhysics(QMyCustomPlot *widget, QString strSlfName, QStrin widget->xAxis = yAxis; widget->yAxis = xAxis; + QCPAxis *yAxis2 = widget->yAxis2; + QCPAxis *xAxis2 = widget->xAxis2; + widget->xAxis2 = yAxis2; + widget->yAxis2 = xAxis2; + // //隐藏刻度 widget->xAxis->setTicks(false); widget->yAxis->setTicks(false); widget->xAxis2->setTicks(false); - widget->yAxis2->setTicks(false); + widget->yAxis2->setTicks(true); + + widget->yAxis2->setTickLabels(true); + widget->yAxis2->setTickLabelSide(QCPAxis::lsInside); + + + widget->yAxis2->setRange(0, 100); + // 设置刻度 + // 创建文本刻度 Ticker + QSharedPointer textTicker(new QCPAxisTickerText); + double minVal = widget->yAxis2->range().lower; + double maxVal = widget->yAxis2->range().upper; + int value = 2; + // 计算步长:(最大值 - 最小值) / 等分数 + double step = (maxVal - minVal) / value; + // 生成刻度 + for (int i = 0; i <= value; ++i) { + double value = minVal + step * i; + // 取整显示(34.0 显示为 "34") + QString label = QString::number(qRound(value)); + textTicker->addTick(value, label); + } + // 应用 Ticker + widget->yAxis2->setTicker(textTicker); + + + // 创建固定刻度器 - 刻度位置和标签完全由你控制 +// QSharedPointer fixedTicker(new QCPAxisTickerFixed); +// fixedTicker->setTickStep(10.0); // 固定刻度间隔 +// widget->yAxis2->setTicker(fixedTicker); + // 获取当前数据范围 +// double lower = widget->yAxis2->range().lower; +// double upper = widget->yAxis2->range().upper; +// widget->yAxis2->setRange(lower - 9, upper + 11); +// double margin = (upper - lower) * 0.05; // 5% 边距 +// widget->yAxis2->setRange(lower - margin, upper + margin); + + QVector x, y; diff --git a/logPlus/forminfo.cpp b/logPlus/forminfo.cpp index 7226aba..909645e 100644 --- a/logPlus/forminfo.cpp +++ b/logPlus/forminfo.cpp @@ -731,8 +731,10 @@ void FormInfo::paintEvent(QPaintEvent* event) if(m_strType=="waveObject" || m_strType=="curveObject") { + QFont oldFont = painter.font(); + painter.setFont(m_strUnitFont); painter.drawText(rect.left()+10, rect.top() + rect.height() * 2 / 3, rect.width(), rect.height() / 3, Qt::AlignCenter, m_strUnit); - + painter.setFont(oldFont); // 显示刻度 if (m_bShowScale) { @@ -754,7 +756,7 @@ void FormInfo::paintEvent(QPaintEvent* event) if(m_strLineName == "深度") { - // 2. 给painter设置字体(关键步骤) + // 2. 给painter设置字体(关键步骤) || m_strLineName == "CORE_PHYSICS" painter.setFont(m_strUnitFont); painter.drawText(rect.left(), rect.top() + rect.height() * 2 / 3, rect.width(), rect.height() / 3, Qt::AlignCenter, this->m_strUnit); } diff --git a/logPlus/forminfo.h b/logPlus/forminfo.h index 8716e7f..7935016 100644 --- a/logPlus/forminfo.h +++ b/logPlus/forminfo.h @@ -236,6 +236,12 @@ public: double m_cp_depth; // 深度 double m_cp_corrDepth; // 校正深度 double m_cp_coreValue; // 数值 + double m_cp_leftScale = 0; // 左刻度 + double m_cp_rightScale = 100; // 右刻度 + int m_cp_scaleDivisionsOrCustom = 2; // 等分刻度数或自定序列 + int m_cp_scaleType = 0; // 刻度类型 + QFont m_cp_curveUnit; // 曲线单位 + QFont m_cp_curveScale; // 曲线刻度 public: void setLineWidth(double dWidth);