diff --git a/logPlus/PropertyWidget.cpp b/logPlus/PropertyWidget.cpp index 466827e..c9dde42 100644 --- a/logPlus/PropertyWidget.cpp +++ b/logPlus/PropertyWidget.cpp @@ -454,28 +454,24 @@ void PropertyWidget::changedCorePhysicsProperty(QtProperty *qtProperty, const QV else if("序号" == m_propertyData[qtProperty]) { int temp = variant.toInt(); -// this->m_formInfo->m_cp_order = temp; this->m_tdCorePhysics->setCpOrder(temp); this->m_tdCorePhysics->mPlot->saveToSLFCorePhysics(); } else if("深度" == m_propertyData[qtProperty]) { double temp = variant.toDouble(); -// this->m_formInfo->m_cp_depth = temp; this->m_tdCorePhysics->setCpDepth(temp); this->m_tdCorePhysics->mPlot->saveToSLFCorePhysics(); } else if("校正深度" == m_propertyData[qtProperty]) { double temp = variant.toDouble(); -// this->m_formInfo->m_cp_corrDepth = temp; this->m_tdCorePhysics->setRange(temp,temp,this->m_tdCorePhysics->getCpCoreValue()); this->m_tdCorePhysics->mPlot->saveToSLFCorePhysics(); } else if("数值" == m_propertyData[qtProperty]) { double temp = variant.toDouble(); -// this->m_formInfo->m_cp_coreValue = temp; this->m_tdCorePhysics->setCpCoreValue(temp); this->m_tdCorePhysics->mPlot->saveToSLFCorePhysics(); } @@ -485,6 +481,10 @@ void PropertyWidget::changedCorePhysicsProperty(QtProperty *qtProperty, const QV this->m_formInfo->m_cp_leftScale = temp; this->m_formInfo->repaint(); + QVariantMap variantMap; + variantMap["leftScale"] = temp; + emit CallManage::getInstance()->sig_changeCorePhysicsProperty(variantMap); + // this->m_tdCorePhysics->setCpLeftScale(temp); // 这个操作需要修改所有对象 // QMap m_mapDraggable_CorePhysics = this->m_tdCorePhysics->mPlot->m_mapDraggable_CorePhysics; @@ -500,6 +500,10 @@ void PropertyWidget::changedCorePhysicsProperty(QtProperty *qtProperty, const QV this->m_formInfo->m_cp_rightScale = temp; this->m_formInfo->repaint(); + QVariantMap variantMap; + variantMap["rightScale"] = temp; + emit CallManage::getInstance()->sig_changeCorePhysicsProperty(variantMap); + // this->m_tdCorePhysics->setCpRightScale(temp); // QMap m_mapDraggable_CorePhysics = this->m_tdCorePhysics->mPlot->m_mapDraggable_CorePhysics; // for (QMap::Iterator iter = m_mapDraggable_CorePhysics.begin(); iter != m_mapDraggable_CorePhysics.end(); iter++) @@ -518,8 +522,8 @@ void PropertyWidget::changedCorePhysicsProperty(QtProperty *qtProperty, const QV } else if("刻度类型" == m_propertyData[qtProperty]) { - int newStyle = 0; int iStyle = variant.value(); + int newStyle = 0; switch(iStyle) { case 0: @@ -536,6 +540,10 @@ void PropertyWidget::changedCorePhysicsProperty(QtProperty *qtProperty, const QV break; } this->m_formInfo->m_cp_scaleType = newStyle; + + QVariantMap variantMap; + variantMap["scaleType"] = newStyle; + emit CallManage::getInstance()->sig_changeCorePhysicsProperty(variantMap); // this->m_tdCorePhysics->setCpScaleType(newStyle); } diff --git a/logPlus/TransparentDraggableCorePhysics.cpp b/logPlus/TransparentDraggableCorePhysics.cpp index 92bceed..3312fc5 100644 --- a/logPlus/TransparentDraggableCorePhysics.cpp +++ b/logPlus/TransparentDraggableCorePhysics.cpp @@ -52,6 +52,38 @@ void TransparentDraggableCorePhysics::setRange(double left_Low, double right_Hig // lY2除以实际左到右刻度数值 // lY2 = lY2 / (getCpRightScale() - getCpLeftScale()) * 100; + double minV = getCpLeftScale(); + double maxV = getCpRightScale(); + double value = lY2; + double finalValue = 0; + int scaleType = getCpScaleType(); // 0=线性 1=对数 2=倾角 + if (scaleType == 0) + { + // 线性(原来的公式) + finalValue = (value - minV) / (maxV - minV) * 100.0; + } + else if (scaleType == 1) + { + // 对数刻度(匹配 QCPAxis::stLogarithmic) + double logMin = log10(minV <= 0 ? 1 : minV); + double logMax = log10(maxV); + double logVal = log10(value); + finalValue = (logVal - logMin) / (logMax - logMin) * 100.0; + } + else if (scaleType == 2) + { + // 倾角刻度(正切非线性,QCustomPlot没有,我们自己实现标准倾角) + double PI = acos(-1); + auto linearNorm = (value - minV) / (maxV - minV); // 0~1 + double tanPos = tan(linearNorm * PI/2 - PI/4); // -1 ~ +1 + double tanNorm = (tanPos + 1.0) / 2.0; // 0~1 + finalValue = tanNorm * 100.0; + } + // 最终结果赋值给 lY2 + lY2 = finalValue; + + + qcpItemLine->start->setCoords(left_Low, lY1);//圆心位置 qcpItemLine->end->setCoords(right_Hight, lY2);//圆心位置 @@ -372,60 +404,44 @@ void TransparentDraggableCorePhysics::setCpLineStyle(Qt::PenStyle value) } -//double TransparentDraggableCorePhysics::getCpLeftScale() const -//{ -// return this->m_cp_leftScale; -//} +double TransparentDraggableCorePhysics::getCpLeftScale() const +{ + return this->m_cp_leftScale; +} -//void TransparentDraggableCorePhysics::setCpLeftScale(double value) -//{ -// this->m_cp_leftScale = value; +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); -//} + // 重新绘制图形 + this->setRange(this->m_left_Low, this->m_left_Low, this->getCpCoreValue(), false); +} -//double TransparentDraggableCorePhysics::getCpRightScale() const -//{ -// return this->m_cp_rightScale; -//} +double TransparentDraggableCorePhysics::getCpRightScale() const +{ + return this->m_cp_rightScale; +} -//void TransparentDraggableCorePhysics::setCpRightScale(double value) -//{ -// this->m_cp_rightScale = value; +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); -//} + // 重新绘制图形 + this->setRange(this->m_left_Low, this->m_left_Low, this->getCpCoreValue(), false); +} -//int TransparentDraggableCorePhysics::getCpScaleType() const -//{ -// return this->m_cp_scaleType; -//} +int TransparentDraggableCorePhysics::getCpScaleType() const +{ + return this->m_cp_scaleType; +} -//void TransparentDraggableCorePhysics::setCpScaleType(int value) -//{ -// this->m_cp_scaleType = value; +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; -//// } -//} + // 重新绘制图形 + this->setRange(this->m_left_Low, this->m_left_Low, this->getCpCoreValue(), false); +} //int TransparentDraggableCorePhysics::getCpScaleDivisionsOrCustom() const //{ @@ -642,7 +658,6 @@ void TransparentDraggableCorePhysics::setCpSymbolSize(int value) foreach (QCPItemTracer *tracer, tracers) { tracer->setSize(value); // 点的大小(像素) } - } QColor TransparentDraggableCorePhysics::getCpSymbolFillColor() const diff --git a/logPlus/TransparentDraggableCorePhysics.h b/logPlus/TransparentDraggableCorePhysics.h index 9f212e5..4adf41a 100644 --- a/logPlus/TransparentDraggableCorePhysics.h +++ b/logPlus/TransparentDraggableCorePhysics.h @@ -63,14 +63,14 @@ public: Qt::PenStyle getCpLineStyle() const; void setCpLineStyle(Qt::PenStyle value); -// double getCpLeftScale() const; -// void setCpLeftScale(double value); + double getCpLeftScale() const; + void setCpLeftScale(double value); -// double getCpRightScale() const; -// void setCpRightScale(double value); + double getCpRightScale() const; + void setCpRightScale(double value); -// int getCpScaleType() const; -// void setCpScaleType(int value); + int getCpScaleType() const; + void setCpScaleType(int value); // int getCpScaleDivisionsOrCustom() const; // void setCpScaleDivisionsOrCustom(int value); @@ -126,9 +126,9 @@ private: int m_cp_lineWidth; // 线宽 QColor m_cp_lineColor; // 线条颜色 Qt::PenStyle m_cp_lineStyle; // 线型 -// double m_cp_leftScale = 0; // 左刻度 -// double m_cp_rightScale = 100; // 右刻度 -// int m_cp_scaleType; // 刻度类型 + double m_cp_leftScale = 0; // 左刻度 + double m_cp_rightScale = 100; // 右刻度 + int m_cp_scaleType = 0; // 刻度类型 // int m_cp_scaleDivisionsOrCustom; // 等分刻度数或自定序列 QString m_cp_displayUnit; // 显示单位 QString m_cp_curveName; // 曲线名称 diff --git a/logPlus/forminfo.cpp b/logPlus/forminfo.cpp index 5050c84..df4b35e 100644 --- a/logPlus/forminfo.cpp +++ b/logPlus/forminfo.cpp @@ -852,8 +852,6 @@ void FormInfo::paintEvent(QPaintEvent* event) ); } painter.setFont(oldFont); - - } QWidget::paintEvent(event); diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index 08422fe..3697218 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -4944,6 +4944,23 @@ void QMyCustomPlot::s_changeCorePhysicsProperty(QVariantMap variantMap) { tdCorePhysics->setCpSymbolFillColor(variantMap["symbolFillColor"].value()); } + // 左刻度 + if(variantMap["leftScale"].isValid()) + { + tdCorePhysics->setCpLeftScale(variantMap["leftScale"].toDouble()); + } + // 右刻度 + if(variantMap["rightScale"].isValid()) + { + tdCorePhysics->setCpRightScale(variantMap["rightScale"].toDouble()); + } + + // 刻度类型 + if(variantMap["scaleType"].isValid()) + { + tdCorePhysics->setCpScaleType(variantMap["scaleType"].toInt()); + } + } this->replot(); }