diff --git a/Bin/Config/Lang/cn/nmNum_cn.qm b/Bin/Config/Lang/cn/nmNum_cn.qm
index f016e465..140921bd 100644
Binary files a/Bin/Config/Lang/cn/nmNum_cn.qm and b/Bin/Config/Lang/cn/nmNum_cn.qm differ
diff --git a/Bin/Config/Lang/cn/nmNum_cn.ts b/Bin/Config/Lang/cn/nmNum_cn.ts
index 3e419a77..a9bfb2f5 100644
--- a/Bin/Config/Lang/cn/nmNum_cn.ts
+++ b/Bin/Config/Lang/cn/nmNum_cn.ts
@@ -6431,6 +6431,14 @@ Please check your input coordinates.
Measure
测量
+
+ Measurement results
+ 测量结果
+
+
+ Length
+ 长度
+
Fit start to nearest well
将起点拟合到最近的井
diff --git a/Include/nmNum/nmPlot/nmGuiPlot.h b/Include/nmNum/nmPlot/nmGuiPlot.h
index 33b14b73..63d04a47 100644
--- a/Include/nmNum/nmPlot/nmGuiPlot.h
+++ b/Include/nmNum/nmPlot/nmGuiPlot.h
@@ -117,9 +117,9 @@ class NM_PLOT_EXPORT nmGuiPlot : public iGuiPlot {
// 删除图元对象
void slotDeleteOneObj(QString sName, void* obj);
- // 删除测量对象
+ // 删除本 Map 的测量图元和数据,不访问全局当前分析。
void deleteMeasureObjects();
- // 清除当前测量对象
+ // 开始新一次测量时清空本 Map 的线段,保留数据对象供对话框继续监听。
void clearPreviousMeasure();
// 结束测量
void finishMeasure();
@@ -218,6 +218,8 @@ class NM_PLOT_EXPORT nmGuiPlot : public iGuiPlot {
// 获取 Binder
nmPlotGraphicBinder* graphicBinder() const { return m_pGraphicBinder; }
+ /** @brief 返回本 Map 实际绑定的管理器;未绑定时返回空,不回退到当前分析。 */
+ nmDataAnalyzeManager* boundDataManager() const;
protected:
diff --git a/Include/nmNum/nmPlot/nmPlotGraphicBinder.h b/Include/nmNum/nmPlot/nmPlotGraphicBinder.h
index 1037b766..965e39d0 100644
--- a/Include/nmNum/nmPlot/nmPlotGraphicBinder.h
+++ b/Include/nmNum/nmPlot/nmPlotGraphicBinder.h
@@ -101,7 +101,7 @@ public:
// 调用:删除测量线图元前
void removeMeasureBinding(nmObjLineMeasure* pGraphic);
- // 坐标同步:从数据对象读取起点终点,写回图元(拟合功能修改数据后由 paintBack 调用)
+ // 坐标同步:数据变更时主动调用,paintBack 保留兜底;本函数不请求重绘。
void syncMeasurePoints(nmObjLineMeasure* pGraphic);
// ==================== 区域标记图元 ====================
@@ -205,6 +205,9 @@ public slots:
void onDataChanged();
private slots:
+ /** @brief 测量数据变更后同步所属线段并刷新视口,避免拟合结果等待鼠标移动才显示。 */
+ void onMeasureDataChanged();
+
// 断层图元信号 → 数据同步
void onGraphicFlowModelChanged(int model);
void onGraphicLeakageChanged(double leakage);
diff --git a/Include/nmNum/nmSubWxs/nmWxMeasureDlg.h b/Include/nmNum/nmSubWxs/nmWxMeasureDlg.h
index 692eb859..8a9b5ef0 100644
--- a/Include/nmNum/nmSubWxs/nmWxMeasureDlg.h
+++ b/Include/nmNum/nmSubWxs/nmWxMeasureDlg.h
@@ -2,47 +2,74 @@
#define NMWXMEASUREDLG_H
#include "iDlgBase.h"
-#include
#include "nmSubWxs_global.h"
-#include "nmDataMeasure.h"
-class QVBoxLayout;
+#include
+
+class QLineEdit;
class QPushButton;
-class nmGUIComponentBase;
-class nmDataWellBase;
+class nmDataAnalyzeManager;
+class nmDataMeasure;
+/**
+ * @brief 测量工具浮动对话框,显示测量长度,并支持将端点拟合到最近的井。
+ * @note 长度使用可复制的只读输入框,显示单位与换算由框架单位绑定器管理。
+ * 切换单位只改变显示,测量数据始终保留米制长度;关闭窗口时通知绘图区结束测量。
+ * 初始尺寸随字体和主题计算,控件采用推荐高度,窗口纵向拉伸时内容保持紧凑。
+ * 输入列与单位列沿用储层参数常规字段的 8:5 横向伸展比例。
+ */
class NM_SUB_WXS_EXPORT nmWxMeasureDlg : public iDlgBase
{
Q_OBJECT
+
public:
+ /** @brief 绑定父级 nmGuiPlot 所属的分析数据;parent 负责管理对话框生命周期。 */
explicit nmWxMeasureDlg(QWidget* parent = nullptr);
- void initUI();
- void initComponents();
- void initPara();
-
- void closeEvent(QCloseEvent* event);
signals:
- void needDeleteMeasureObj();
- void sigonFitStartClicked();
- void sigonFitEndClicked();
+ /** @brief 对话框结束时通知所属绘图区移除测量工具和线段。 */
+ void needDeleteMeasureObj();
+
+public slots:
+ /** @brief 将测量起点拟合到最近的井,并重新计算米制长度。 */
+ void onFitStartClicked();
+
+ /** @brief 将测量终点拟合到最近的井,并重新计算米制长度。 */
+ void onFitEndClicked();
+
+ /** @brief 从测量模型刷新只读长度,保留用户当前选择的显示单位。 */
+ void updateDisplay();
+
+ /** @brief 响应底部关闭按钮,结束对话框。 */
+ void onCloseClicked();
+
+ /** @brief 开始新一次测量时,恢复两个端点的拟合操作。 */
+ void resetButtons();
+
+protected:
+ /** @brief 响应标题栏关闭,通知绘图区清理后交给基类处理关闭事件。 */
+ void closeEvent(QCloseEvent* event) override;
+
+private:
+ /** @brief 创建统一的长度字段、端点操作区和底部按钮区。 */
+ void initUI() override;
+
+ /** @brief 共用的端点拟合逻辑;bFitStart 为 true 时处理起点,否则处理终点。 */
+ void fitToNearestWell(bool bFitStart);
+
private:
+ // 借用父级 Map 的分析管理器及测量数据,不负责释放;对象删除后自动置空。
+ // 拟合始终从同一分析读取井,避免切换分析后将其他分析的井坐标写入本次测量。
+ QPointer m_pDataManager;
+ QPointer m_pData;
- QVBoxLayout* m_pMainLayout;
- QVector m_vecWellList;
+ // 长度及拟合按钮均由 Qt 父子对象机制释放,不使用旧的业务单位控件。
+ QLineEdit* m_pLengthEdit;
QPushButton* m_pFitStartButton;
QPushButton* m_pFitEndButton;
- double* m_pLength;
- nmDataMeasure* m_pData;
- nmGUIComponentBase* m_pLengthCom;
-
-public slots:
- void onFitStartClicked();
- void onFitEndClicked();
- void updateDisplay();
- void onCloseClicked();
- void resetButtons();
+ // 框架单位对是否绑定成功;失败时不显示未经换算的长度。
+ bool m_bUnitBound;
};
#endif // NMWXMEASUREDLG_H
diff --git a/Include/nmNum/nmSubWxs/nmWxMeasuringScaleDlg.h b/Include/nmNum/nmSubWxs/nmWxMeasuringScaleDlg.h
index 9ab2276e..9de4c6b5 100644
--- a/Include/nmNum/nmSubWxs/nmWxMeasuringScaleDlg.h
+++ b/Include/nmNum/nmSubWxs/nmWxMeasuringScaleDlg.h
@@ -5,6 +5,7 @@
#include "nmSubWxs_global.h"
#include
+#include
#include
class QLineEdit;
@@ -14,6 +15,8 @@ class QLineEdit;
* @note 起始点、终点使用可复制的只读输入框;实际长度的显示单位和换算由框架单位绑定器管理。
* 确认后仅向调用方返回米制长度,由所属绘图窗口在标定成功后保存分析数据。
* 取消或关闭窗口不提交编辑内容。
+ * 字段初始尺寸由字体和主题决定,坐标内容影响推荐宽度;控件采用推荐高度,纵向保持紧凑。
+ * 输入列与单位列沿用储层参数常规字段的 8:5 横向伸展比例。
*/
class NM_SUB_WXS_EXPORT nmWxMeasuringScaleDlg : public iDlgBase
{
@@ -30,6 +33,9 @@ public:
*/
nmWxMeasuringScaleDlg(QPointF startPoint, QPointF endPoint, double* pLength);
+ /** @brief 按布局、当前字体及坐标文字给出推荐尺寸,不设置固定尺寸或内容最小宽度。 */
+ QSize sizeHint() const override;
+
protected:
/**
* @brief 校验当前单位下的长度,返回米制长度并以 Accepted 状态关闭窗口。
diff --git a/Src/nmNum/nmPlot/nmGuiPlot.cpp b/Src/nmNum/nmPlot/nmGuiPlot.cpp
index 698cb77e..2de001ad 100644
--- a/Src/nmNum/nmPlot/nmGuiPlot.cpp
+++ b/Src/nmNum/nmPlot/nmGuiPlot.cpp
@@ -1313,6 +1313,10 @@ void nmGuiPlot::applyMeasuringScale(const QPointF& pStart, const QPointF& pEnd)
void nmGuiPlot::deleteMeasureObjects()
{
+ if(m_pPlot == nullptr) {
+ return;
+ }
+
QVector measureObjs = getObjsByTag("nObjLineMeasure");
for(int i = 0; i < measureObjs.count(); i++) {
@@ -1325,8 +1329,11 @@ void nmGuiPlot::deleteMeasureObjects()
}
}
- // 清空数据对象
- nmDataAnalyzeManager::getCurrentInstance()->removeMeasureData();
+ // 先解除本 Map 的图元绑定,再删除所属分析的测量数据。
+ // 非模态对话框关闭时,当前页签可能已切换,不能使用全局当前分析。
+ if(m_pDataManager != nullptr) {
+ m_pDataManager->removeMeasureData();
+ }
// 恢复画布可编辑状态
setAllPlotObjectsEditable(true);
@@ -1334,6 +1341,10 @@ void nmGuiPlot::deleteMeasureObjects()
void nmGuiPlot::clearPreviousMeasure()
{
+ if(m_pPlot == nullptr) {
+ return;
+ }
+
QVector measureObjs = getObjsByTag("nObjLineMeasure");
for(int i = 0; i < measureObjs.count(); i++) {
@@ -1346,7 +1357,8 @@ void nmGuiPlot::clearPreviousMeasure()
}
}
- nmDataMeasure* data = nmDataAnalyzeManager::getCurrentInstance()->getMeasureData();
+ // 连续测量复用同一数据对象,保证对话框的刷新连接仍然有效。
+ nmDataMeasure* data = m_pDataManager != nullptr ? m_pDataManager->getMeasureData() : nullptr;
if(data) {
data->setStartPoint(QPointF(0, 0));
@@ -1505,6 +1517,11 @@ void nmGuiPlot::deleteAllDFNPlots()
}
}
+nmDataAnalyzeManager* nmGuiPlot::boundDataManager() const
+{
+ return m_pDataManager;
+}
+
nmDataAnalyzeManager* nmGuiPlot::dataManager() const
{
return m_pDataManager != nullptr
diff --git a/Src/nmNum/nmPlot/nmPlotGraphicBinder.cpp b/Src/nmNum/nmPlot/nmPlotGraphicBinder.cpp
index faa9c41b..669b0c34 100644
--- a/Src/nmNum/nmPlot/nmPlotGraphicBinder.cpp
+++ b/Src/nmNum/nmPlot/nmPlotGraphicBinder.cpp
@@ -27,6 +27,7 @@
#include "ZxDataGaugeP.h"
#include "ZxDataGaugeF.h"
#include "ZxBaseUtil.h"
+#include "ZxRenderView.h"
#include "Defines.h"
#include "iDataTypes.h"
#include "zxSysUtils.h"
@@ -150,9 +151,14 @@ void nmPlotGraphicBinder::syncFaultName(nmObjLineFault* pGraphic)
}
// 切换分析时更新绑定的 DataManager
-// 旧图元已由 deleteAllPlotObjs 清除,清理残留映射避免悬空指针
+// Map 重建时先解除测量刷新连接并清理映射,供调用方安全移除旧图元。
void nmPlotGraphicBinder::updateDataMgr(nmDataAnalyzeManager* pDataMgr)
{
+ // 重建或切换 Map 时先断开旧测量数据的刷新连接,再清空图元映射。
+ foreach(nmDataMeasure* pMeasureData, m_mapMeasureData.values()) {
+ QObject::disconnect(pMeasureData, SIGNAL(sigMeasureDataChanged()),
+ this, SLOT(onMeasureDataChanged()));
+ }
m_mapFaultData.clear();
m_setBoundGraphics.clear();
m_mapCrackData.clear();
@@ -967,6 +973,8 @@ void nmPlotGraphicBinder::createMeasureForGraphic(nmObjLineMeasure* pGraphic)
// 获取测量数据单例
nmDataMeasure* pData = m_pDataMgr->getMeasureData();
+ // 同一图元再次绑定时先清除旧连接,避免初始化端点期间反向覆盖新线段。
+ removeMeasureBinding(pGraphic);
// 将图元坐标推入数据
QVector pts = pGraphic->getAllValues();
@@ -986,6 +994,9 @@ void nmPlotGraphicBinder::createMeasureForGraphic(nmObjLineMeasure* pGraphic)
// 建立映射
m_mapMeasureData[pGraphic] = pData;
pGraphic->setGraphicBinder(this);
+ // 对话框只修改模型;由绑定器负责把变更送回所属画布,不依赖偶然重绘。
+ QObject::connect(pData, SIGNAL(sigMeasureDataChanged()),
+ this, SLOT(onMeasureDataChanged()), Qt::UniqueConnection);
m_pDataMgr->notifyDataChanged();
}
@@ -997,10 +1008,37 @@ void nmPlotGraphicBinder::removeMeasureBinding(nmObjLineMeasure* pGraphic)
return;
}
- m_mapMeasureData.remove(pGraphic);
+ nmDataMeasure* pData = m_mapMeasureData.take(pGraphic);
+ // 一个数据对象可能关联多个图元,仅在最后一个绑定移除后断开刷新。
+ if(pData != nullptr && !m_mapMeasureData.values().contains(pData)) {
+ QObject::disconnect(pData, SIGNAL(sigMeasureDataChanged()),
+ this, SLOT(onMeasureDataChanged()));
+ }
+}
+
+void nmPlotGraphicBinder::onMeasureDataChanged()
+{
+ nmDataMeasure* pData = qobject_cast(sender());
+ if(pData == nullptr) {
+ return;
+ }
+
+ QMap::const_iterator it = m_mapMeasureData.constBegin();
+ for(; it != m_mapMeasureData.constEnd(); ++it) {
+ if(it.key() == nullptr || it.value() != pData) {
+ continue;
+ }
+ nmObjLineMeasure* pGraphic = it.key();
+ syncMeasurePoints(pGraphic);
+ ZxRenderView* pView = pGraphic->getView();
+ if(pView != nullptr) {
+ // 更新整个视口,覆盖拟合前后的线段区域,避免旧位置留下残影。
+ pView->viewport()->update();
+ }
+ }
}
-// 坐标同步:从数据对象读取起点终点,写回图元(拟合功能修改数据后由 paintBack 调用)
+// 同步端点但不触发重绘,避免 paintBack 中的兜底调用形成循环刷新。
void nmPlotGraphicBinder::syncMeasurePoints(nmObjLineMeasure* pGraphic)
{
if (!pGraphic || !m_pDataMgr) return;
@@ -1018,11 +1056,11 @@ void nmPlotGraphicBinder::syncMeasurePoints(nmObjLineMeasure* pGraphic)
return;
}
- pGraphic->blockSignals(true);
+ const bool bOldSignalsBlocked = pGraphic->blockSignals(true);
QVector pts;
pts << startPt << endPt;
pGraphic->setAllValues(pts);
- pGraphic->blockSignals(false);
+ pGraphic->blockSignals(bOldSignalsBlocked);
}
// ==================== 区域标记图元 ====================
diff --git a/Src/nmNum/nmSubWnd/nmSubWndMain.cpp b/Src/nmNum/nmSubWnd/nmSubWndMain.cpp
index bd355dd5..ee94e63a 100644
--- a/Src/nmNum/nmSubWnd/nmSubWndMain.cpp
+++ b/Src/nmNum/nmSubWnd/nmSubWndMain.cpp
@@ -1723,7 +1723,7 @@ QWidget* nmSubWndMain::showMeasureDialog()
{
nmGuiPlot* plot = dynamic_cast(m_pWxPlot);
- if(plot == nullptr) {
+ if(plot == nullptr || plot->boundDataManager() == nullptr) {
return nullptr;
}
@@ -1743,7 +1743,8 @@ QWidget* nmSubWndMain::showMeasureDialog()
measureDlg->setObjectName("nmMeasureDialog");
measureDlg->setAttribute(Qt::WA_DeleteOnClose, true);
bindDialogCmdDestroyed(measureDlg, 5129);
- nmDataMeasure* measureData = nmDataAnalyzeManager::getCurrentInstance()->getMeasureData();
+ // 与对话框及图元绑定器共用本 Map 的测量数据,避免连接到其他分析。
+ nmDataMeasure* measureData = plot->boundDataManager()->getMeasureData();
if(measureData != nullptr) {
connect(measureData, SIGNAL(sigMeasureDataChanged()), measureDlg, SLOT(updateDisplay()));
}
diff --git a/Src/nmNum/nmSubWxs/nmWxMeasureDlg.cpp b/Src/nmNum/nmSubWxs/nmWxMeasureDlg.cpp
index 7a4a4779..96cb9084 100644
--- a/Src/nmNum/nmSubWxs/nmWxMeasureDlg.cpp
+++ b/Src/nmNum/nmSubWxs/nmWxMeasureDlg.cpp
@@ -1,247 +1,254 @@
#include "nmWxMeasureDlg.h"
-#include
-#include
-#include
-#include
-#include
-#include
-
+#include "iUnitWxBinder.h"
#include "nmDataAnalyzeManager.h"
-#include "nmGUIComponentLineEdit.h"
+#include "nmDataMeasure.h"
#include "nmDataWellBase.h"
+#include "nmGuiPlot.h"
+#include "ZxBaseUtil.h"
-Q_DECLARE_METATYPE(double *)
-Q_DECLARE_METATYPE(QString *)
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
nmWxMeasureDlg::nmWxMeasureDlg(QWidget* parent)
: iDlgBase(parent),
- m_pMainLayout(NULL),
- m_pFitStartButton(NULL),
- m_pFitEndButton(NULL),
- m_pLength(NULL),
- m_pData(NULL),
- m_pLengthCom(NULL)
+ m_pLengthEdit(nullptr),
+ m_pFitStartButton(nullptr),
+ m_pFitEndButton(nullptr),
+ m_bUnitBound(false)
{
+ // 浮动窗口必须绑定父级画布的分析,不能随全局当前页签变化而串用数据。
+ nmGuiPlot* pOwnerPlot = qobject_cast(parent);
+ if (pOwnerPlot != nullptr)
+ {
+ m_pDataManager = pOwnerPlot->boundDataManager();
+ }
+ if (!m_pDataManager.isNull())
+ {
+ m_pData = m_pDataManager->getMeasureData();
+ }
- this->initUI();
- this->resize(400, 150);
- this->setWindowTitle(tr("Measure"));
- m_pFitStartButton->setEnabled(false);
- m_pFitEndButton->setEnabled(false);
+ initUI();
+ updateDisplay();
+ setWindowTitle(tr("Measure"));
+ // 保留浮动置顶行为,便于在绘图区连续测量,同时移除无帮助内容的问号按钮。
+ setWindowFlags((windowFlags() | Qt::WindowStaysOnTopHint) &
+ ~Qt::WindowContextHelpButtonHint);
+ // 初始大小由字体、主题及布局推荐尺寸决定;adjustSize 同时考虑屏幕尺寸。
+ // 这里只设置初始大小,不限制用户之后调整窗口。
+ adjustSize();
}
void nmWxMeasureDlg::initUI()
{
- m_pMainLayout = new QVBoxLayout;
- this->setLayout(m_pMainLayout);
- // 构建组件
- this->initPara();
- this->initComponents();
-
- // 按钮部分
- m_pFitStartButton = new QPushButton(tr("Fit start to nearest well"));
- m_pFitEndButton = new QPushButton(tr("Fit end to nearest well"));
-
- QString qss = "QPushButton:disabled { color: #888888; }";
- m_pFitStartButton->setStyleSheet(qss);
- m_pFitEndButton->setStyleSheet(qss);
-
+ // 与比例尺设置保持相同的外边距和分组间距,控件尺寸交给字体与主题计算。
+ QVBoxLayout* pMainLayout = new QVBoxLayout(this);
+ pMainLayout->setContentsMargins(12, 10, 12, 0);
+ pMainLayout->setSpacing(10);
+
+ QGroupBox* pGroup = new QGroupBox(tr("Measurement results"), this);
+ // 分组只横向伸展,内容高度由字体和主题的推荐尺寸决定,避免纵向拉长控件或行间距。
+ pGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ QGridLayout* pGrid = new QGridLayout(pGroup);
+ pGrid->setContentsMargins(8, 15, 8, 10);
+ pGrid->setHorizontalSpacing(6);
+ pGrid->setVerticalSpacing(6);
+ // 沿用储层参数常规字段的三列规则:标签按内容,输入框与单位下拉框按 8:5 伸展。
+ pGrid->setColumnStretch(0, 0);
+ pGrid->setColumnStretch(1, 8);
+ pGrid->setColumnStretch(2, 5);
+
+ QLabel* pLengthLabel = new QLabel(tr("Length"), pGroup);
+ pLengthLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
+ pLengthLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ pGrid->addWidget(pLengthLabel, 0, 0);
+
+ // 长度只能由测量和端点拟合产生;只读而非禁用,允许用户选中、复制结果。
+ m_pLengthEdit = new QLineEdit(pGroup);
+ m_pLengthEdit->setObjectName("measureLength");
+ m_pLengthEdit->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
+ m_pLengthEdit->setReadOnly(true);
+ // 纵向 Fixed 使用当前字体和主题的推荐高度,不设置固定像素高度。
+ m_pLengthEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ pGrid->addWidget(m_pLengthEdit, 0, 1);
+
+ QComboBox* pLengthUnit = new QComboBox(pGroup);
+ pLengthUnit->setObjectName("measureLengthUnit");
+ // 推荐及最小宽度按完整单位列表和主题箭头计算,窗口拉宽时与输入框一起伸展。
+ pLengthUnit->setSizeAdjustPolicy(QComboBox::AdjustToContents);
+ pLengthUnit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ pGrid->addWidget(pLengthUnit, 0, 2);
+
+ // 由米识别框架长度单位组,不借用井参数及其范围,也不读取模型的旧手写单位列表。
+ // 单位切换和显示精度交给绑定器处理,不将显示单位或显示数值写回测量模型。
+ pLengthUnit->addItem("m");
+ m_bUnitBound = bindUnitPairWxs(m_pLengthEdit, pLengthUnit, QString(), false);
+ m_bUnitBound = m_bUnitBound && m_pUnitBinder != nullptr;
+ m_pLengthEdit->setEnabled(m_bUnitBound);
+ pLengthUnit->setEnabled(m_bUnitBound);
+
+ m_pFitStartButton = new QPushButton(tr("Fit start to nearest well"), pGroup);
+ m_pFitEndButton = new QPushButton(tr("Fit end to nearest well"), pGroup);
+ // 拟合属于显式操作,不设为默认按钮,避免复制长度时按回车触发端点变化。
+ m_pFitStartButton->setAutoDefault(false);
+ m_pFitEndButton->setAutoDefault(false);
+ m_pFitStartButton->setEnabled(false);
+ m_pFitEndButton->setEnabled(false);
+ m_pFitStartButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ m_pFitEndButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ // 两个端点操作各占一行,横跨字段区,沿用分组的统一行间距。
+ pGrid->addWidget(m_pFitStartButton, 1, 0, 1, 3);
+ pGrid->addWidget(m_pFitEndButton, 2, 0, 1, 3);
connect(m_pFitStartButton, SIGNAL(clicked()), this, SLOT(onFitStartClicked()));
connect(m_pFitEndButton, SIGNAL(clicked()), this, SLOT(onFitEndClicked()));
-
- // 底部按钮
- QHBoxLayout *bottomLayout = new QHBoxLayout();
- bottomLayout->addStretch(1);
- QPushButton *closeButton = new QPushButton(tr("Close"));
- connect(closeButton, SIGNAL(clicked()), this, SLOT(onCloseClicked()));
- bottomLayout->addWidget(closeButton);
-
- // 将所有部件添加到主布局
- m_pMainLayout->addSpacing(10);
- m_pMainLayout->addSpacing(10);
- m_pMainLayout->addWidget(m_pFitStartButton);
- m_pMainLayout->addWidget(m_pFitEndButton);
- m_pMainLayout->addStretch(1);
- m_pMainLayout->addLayout(bottomLayout);
-
- setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
+ pMainLayout->addWidget(pGroup);
+ // 纵向余量由分组与底部按钮之间的布局空间吸收,内容保持紧凑排列。
+ pMainLayout->addStretch(1);
+
+ // 底部沿用标准按钮框、框架图标及统一留白。
+ QWidget* pFooter = new QWidget(this);
+ pFooter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ QHBoxLayout* pFooterLayout = new QHBoxLayout(pFooter);
+ pFooterLayout->setContentsMargins(4, 5, 4, 5);
+ pFooterLayout->setSpacing(8);
+ pFooterLayout->addStretch();
+ QDialogButtonBox* pButtons = new QDialogButtonBox(
+ QDialogButtonBox::Close, Qt::Horizontal, pFooter);
+ QPushButton* pClose = pButtons->button(QDialogButtonBox::Close);
+ pClose->setText(tr("Close"));
+ pClose->setIcon(zxLoadIcon("Cancel"));
+ pClose->setAutoDefault(false);
+ pFooterLayout->addWidget(pButtons);
+ pMainLayout->addWidget(pFooter);
+ connect(pButtons, SIGNAL(rejected()), this, SLOT(onCloseClicked()));
}
-void nmWxMeasureDlg::initPara() {
-
- m_pData = nmDataAnalyzeManager::getCurrentInstance()->getMeasureData();
- m_pData->getLength().setName(tr("Length :"));
- m_vecWellList = nmDataAnalyzeManager::getCurrentInstance()->getWellDataList();
+void nmWxMeasureDlg::onFitStartClicked()
+{
+ fitToNearestWell(true);
}
-void nmWxMeasureDlg::initComponents() {
-
- m_pLengthCom = new nmGUIComponentLineEdit(&m_pData->getLength(), false);
- m_pMainLayout->addWidget(m_pLengthCom);
+void nmWxMeasureDlg::onFitEndClicked()
+{
+ fitToNearestWell(false);
}
-void nmWxMeasureDlg::onFitStartClicked()
+void nmWxMeasureDlg::fitToNearestWell(bool bFitStart)
{
- // 使用当前井列表;没有可拟合的井时保留测量点,避免写入默认原点。
- m_vecWellList = nmDataAnalyzeManager::getCurrentInstance()->getWellDataList();
- if (m_vecWellList.isEmpty()) {
+ if (m_pDataManager.isNull() || m_pData.isNull())
+ {
return;
}
- m_pFitStartButton->setEnabled(false);
+ // 每次读取所属分析的最新井列表;无井时保留测量点和按钮状态。
+ const QVector vecWells = m_pDataManager->getWellDataList();
+ const QPointF current = m_pData->getCurrentPoint();
+ // 沿用测量模型约定:(0, 0) 表示没有待处理的单点,按已有线段端点拟合。
+ const bool bSinglePoint = !(qFuzzyCompare(current.x(), 0.0) &&
+ qFuzzyCompare(current.y(), 0.0));
+ const QPointF reference = bSinglePoint ? current :
+ (bFitStart ? m_pData->getStartPoint() : m_pData->getEndPoint());
+
+ double dMinDistance = std::numeric_limits::max();
+ QPointF nearest;
+ bool bFound = false;
+ for (int nIndex = 0; nIndex < vecWells.size(); ++nIndex)
+ {
+ nmDataWellBase* pWell = vecWells[nIndex];
+ if (pWell == nullptr)
+ {
+ continue;
+ }
+
+ const QPointF wellPoint(pWell->getX().getValue().toDouble(),
+ pWell->getY().getValue().toDouble());
+ const double dDistance = QLineF(reference, wellPoint).length();
+ if (dDistance < dMinDistance)
+ {
+ dMinDistance = dDistance;
+ nearest = wellPoint;
+ bFound = true;
+ }
+ }
+ if (!bFound)
+ {
+ return;
+ }
- // 先取出当前点
- QPointF current = m_pData->getCurrentPoint();
- // 判断 current 是否为 (0,0)
- if (qFuzzyCompare(current.x(), 0.0) && qFuzzyCompare(current.y(), 0.0)) {
- QPointF ref = m_pData->getStartPoint();
-
- double minDist = std::numeric_limits::max();
- QPointF nearest;
- for (int i = 0; i < m_vecWellList.size(); ++i) {
- nmDataWellBase* pWell = m_vecWellList[i];
- double x = pWell->getX().getValue().toDouble();
- double y = pWell->getY().getValue().toDouble();
- QPointF pt(x, y);
- double dist = QLineF(ref, pt).length();
- if (dist < minDist) {
- minDist = dist;
- nearest = pt;
- }
- }
+ // 单点测量中,未拟合的一端保留点击位置;普通线段只移动指定端点。
+ if (bFitStart)
+ {
+ m_pFitStartButton->setEnabled(false);
m_pData->setStartPoint(nearest);
+ if (bSinglePoint)
+ {
+ m_pData->setEndPoint(current);
+ }
+ }
+ else
+ {
+ m_pFitEndButton->setEnabled(false);
+ if (bSinglePoint)
+ {
+ m_pData->setStartPoint(current);
+ }
+ m_pData->setEndPoint(nearest);
+ }
- // 重新计算长度
- QPointF endPt = m_pData->getEndPoint();
- double newLen = QLineF(nearest, endPt).length();
- nmDataAttribute lenAttr = m_pData->getLength();
- lenAttr.setValue(newLen);
- m_pData->setLength(lenAttr);
- }
- else {
-
- QPointF startPt = current;
-
- // 找 nearest well
- double minDist = std::numeric_limits::max();
- QPointF nearest;
- for (int i = 0; i < m_vecWellList.size(); ++i) {
- nmDataWellBase* pWell = m_vecWellList[i];
- double x = pWell->getX().getValue().toDouble();
- double y = pWell->getY().getValue().toDouble();
- QPointF pt(x, y);
- double dist = QLineF(startPt, pt).length();
- if (dist < minDist) {
- minDist = dist;
- nearest = pt;
- }
- }
- // 单点测量先拟合起点时,将起点移到井上,终点保留在点击位置。
- m_pData->setStartPoint(nearest);
- m_pData->setEndPoint(startPt);
-
- // 重新计算长度
- double newLen = QLineF(startPt, nearest).length();
- nmDataAttribute lenAttr = m_pData->getLength();
- lenAttr.setValue(newLen);
- m_pData->setLength(lenAttr);
- }
+ // 几何计算使用模型中的米制坐标,不读取可能已切为英尺等单位的界面文本。
+ const double dLength = QLineF(m_pData->getStartPoint(), m_pData->getEndPoint()).length();
+ nmDataAttribute length = m_pData->getLength();
+ length.setValue(dLength);
+ m_pData->setLength(length);
m_pData->setCurrentPoint(QPointF(0, 0));
- // 刷新界面显示
- updateDisplay();
+ updateDisplay();
}
-void nmWxMeasureDlg::onFitEndClicked()
+void nmWxMeasureDlg::updateDisplay()
{
- // 使用当前井列表;没有可拟合的井时保留测量点,避免写入默认原点。
- m_vecWellList = nmDataAnalyzeManager::getCurrentInstance()->getWellDataList();
- if (m_vecWellList.isEmpty()) {
+ if (m_pData.isNull())
+ {
+ m_pLengthEdit->clear();
+ m_pFitStartButton->setEnabled(false);
+ m_pFitEndButton->setEnabled(false);
return;
}
- m_pFitEndButton->setEnabled(false);
-
- // 先取出当前点
- QPointF current = m_pData->getCurrentPoint();
- // 判断 current 是否为 (0,0)
- if (qFuzzyCompare(current.x(), 0.0) && qFuzzyCompare(current.y(), 0.0)) {
-
- QPointF ref = m_pData->getEndPoint();
-
- double minDist = std::numeric_limits::max();
- QPointF nearest;
- for (int i = 0; i < m_vecWellList.size(); ++i) {
- nmDataWellBase* pWell = m_vecWellList[i];
- double x = pWell->getX().getValue().toDouble();
- double y = pWell->getY().getValue().toDouble();
- QPointF pt(x, y);
- double dist = QLineF(ref, pt).length();
- if (dist < minDist) {
- minDist = dist;
- nearest = pt;
- }
- }
- m_pData->setEndPoint(nearest);
-
- // 重新计算长度
- QPointF startPt = m_pData->getStartPoint();
- double newLen = QLineF(startPt, nearest).length();
- nmDataAttribute lenAttr = m_pData->getLength();
- lenAttr.setValue(newLen);
- m_pData->setLength(lenAttr);
- }
- else {
-
- QPointF startPt = current;
-
- // 找 nearest well
- double minDist = std::numeric_limits::max();
- QPointF nearest;
- for (int i = 0; i < m_vecWellList.size(); ++i) {
- nmDataWellBase* pWell = m_vecWellList[i];
- double x = pWell->getX().getValue().toDouble();
- double y = pWell->getY().getValue().toDouble();
- QPointF pt(x, y);
- double dist = QLineF(startPt, pt).length();
- if (dist < minDist) {
- minDist = dist;
- nearest = pt;
- }
- }
- // 更新起点和终点
- m_pData->setStartPoint(startPt);
- m_pData->setEndPoint(nearest);
-
- // 重新计算长度
- double newLen = QLineF(startPt, nearest).length();
- nmDataAttribute lenAttr = m_pData->getLength();
- lenAttr.setValue(newLen);
- m_pData->setLength(lenAttr);
- }
- m_pData->setCurrentPoint(QPointF(0, 0));
- // 刷新界面显示
- updateDisplay();
-}
-
-void nmWxMeasureDlg::updateDisplay() {
- m_pLengthCom->updateValueFromOrigin();
+ if (m_bUnitBound)
+ {
+ // 更新基准值而不重建单位列表,连续测量和拟合后仍保留当前显示单位。
+ m_pUnitBinder->setBaseValue(m_pLengthEdit, m_pData->getLength().getValue().toDouble());
+ }
+ else
+ {
+ m_pLengthEdit->clear();
+ }
}
void nmWxMeasureDlg::closeEvent(QCloseEvent* event)
{
- emit needDeleteMeasureObj();
- iDlgBase::closeEvent(event);
+ emit needDeleteMeasureObj();
+ iDlgBase::closeEvent(event);
}
void nmWxMeasureDlg::onCloseClicked()
{
- emit needDeleteMeasureObj();
- accept();
+ emit needDeleteMeasureObj();
+ accept();
}
void nmWxMeasureDlg::resetButtons()
{
- m_pFitStartButton->setEnabled(true);
- m_pFitEndButton ->setEnabled(true);
+ const bool bCanFit = !m_pDataManager.isNull() && !m_pData.isNull();
+ m_pFitStartButton->setEnabled(bCanFit);
+ m_pFitEndButton->setEnabled(bCanFit);
}
diff --git a/Src/nmNum/nmSubWxs/nmWxMeasuringScaleDlg.cpp b/Src/nmNum/nmSubWxs/nmWxMeasuringScaleDlg.cpp
index a7c25089..18fcec9a 100644
--- a/Src/nmNum/nmSubWxs/nmWxMeasuringScaleDlg.cpp
+++ b/Src/nmNum/nmSubWxs/nmWxMeasuringScaleDlg.cpp
@@ -1,11 +1,11 @@
#include "nmWxMeasuringScaleDlg.h"
#include "iUnitWxBinder.h"
-#include "nmParameterField.h"
#include "ZxBaseUtil.h"
#include
#include
+#include
#include
#include
#include
@@ -15,6 +15,13 @@
#include
#include
+namespace
+{
+ // 与储层参数常规字段一致;初始尺寸计算和实际布局使用同一比例。
+ const int s_nValueStretch = 8;
+ const int s_nUnitStretch = 5;
+}
+
nmWxMeasuringScaleDlg::nmWxMeasuringScaleDlg(
QPointF startPoint, QPointF endPoint, double* pLength)
: m_startPoint(startPoint),
@@ -30,7 +37,39 @@ nmWxMeasuringScaleDlg::nmWxMeasuringScaleDlg(
initUI();
setWindowTitle(tr("MeasuringScale setting"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
- resize(460, 200);
+ // 按字体、主题及坐标内容选择初始大小,由 Qt 结合屏幕尺寸限制初始展开范围。
+ // 不固定窗口大小,长坐标仍可通过拉宽窗口或在只读框内移动光标查看。
+ adjustSize();
+}
+
+QSize nmWxMeasuringScaleDlg::sizeHint() const
+{
+ QSize preferredSize = iDlgBase::sizeHint();
+ const QComboBox* pLengthUnit = findChild("scaleLengthUnit");
+ if (m_pLengthEdit == nullptr || pLengthUnit == nullptr || !preferredSize.isValid())
+ {
+ return preferredSize;
+ }
+
+ // 三个输入框共用一列;在布局推荐宽度上,为较长的坐标文本补足空间。
+ // 最小推荐宽度包含主题边框和内边距,扣除其字符宽度后可估算文本之外的留白。
+ const QFontMetrics metrics = m_pLengthEdit->fontMetrics();
+ const int nTextPadding = qMax(0, m_pLengthEdit->minimumSizeHint().width() - metrics.maxWidth())
+ + metrics.width(QLatin1String("00"));
+ const int nCoordinateWidth = qMax(metrics.width(m_sStartPoint), metrics.width(m_sEndPoint))
+ + nTextPadding;
+ // 输入列变宽时单位列也会按 8:5 伸展,初始推荐宽度需同时预留两列的空间。
+ const int nEditorHintWidth = m_pLengthEdit->sizeHint().width();
+ const int nUnitHintWidth = pLengthUnit->sizeHint().width();
+ const int nTotalStretch = s_nValueStretch + s_nUnitStretch;
+ const int nWidthForCoordinates =
+ (qMax(nCoordinateWidth, nEditorHintWidth) * nTotalStretch + s_nValueStretch - 1)
+ / s_nValueStretch;
+ const int nWidthForUnits =
+ (nUnitHintWidth * nTotalStretch + s_nUnitStretch - 1) / s_nUnitStretch;
+ preferredSize.rwidth() += qMax(0,
+ qMax(nWidthForCoordinates, nWidthForUnits) - nEditorHintWidth - nUnitHintWidth);
+ return preferredSize;
}
void nmWxMeasuringScaleDlg::initUI()
@@ -41,13 +80,16 @@ void nmWxMeasuringScaleDlg::initUI()
pMainLayout->setSpacing(10);
QGroupBox* pGroup = new QGroupBox(tr("Scale parameters"), this);
+ // 与测量工具一致:分组只横向伸展,纵向使用字体和主题计算的内容高度。
+ pGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
QGridLayout* pGrid = new QGridLayout(pGroup);
pGrid->setContentsMargins(8, 15, 8, 10);
pGrid->setHorizontalSpacing(6);
pGrid->setVerticalSpacing(6);
- pGrid->setColumnStretch(1, 1);
- pGrid->setColumnMinimumWidth(1, nmParameterField::editorMinimumWidth());
- pGrid->setColumnMinimumWidth(2, nmParameterField::unitMinimumWidth());
+ // 标签由文字决定宽度;输入框与单位下拉框沿用储层参数的 8:5 横向伸展比例。
+ pGrid->setColumnStretch(0, 0);
+ pGrid->setColumnStretch(1, s_nValueStretch);
+ pGrid->setColumnStretch(2, s_nUnitStretch);
// 三行共用相同尺寸的输入框,标签不带冒号;坐标行保留空单位列以保证对齐。
const QStringList listLabels = QStringList()
@@ -57,12 +99,12 @@ void nmWxMeasuringScaleDlg::initUI()
{
QLabel* pLabel = new QLabel(listLabels[nRow], pGroup);
pLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
+ pLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
pGrid->addWidget(pLabel, nRow, 0);
pEditors[nRow] = new QLineEdit(pGroup);
pEditors[nRow]->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
- pEditors[nRow]->setFixedHeight(nmParameterField::editorHeight());
- pEditors[nRow]->setMinimumWidth(nmParameterField::editorMinimumWidth());
+ // 输入列随窗口加宽;纵向 Fixed 采用主题推荐高度,不固定像素值。
pEditors[nRow]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
pGrid->addWidget(pEditors[nRow], nRow, 1);
}
@@ -79,8 +121,9 @@ void nmWxMeasuringScaleDlg::initUI()
QComboBox* pLengthUnit = new QComboBox(pGroup);
pLengthUnit->setObjectName("scaleLengthUnit");
- pLengthUnit->setFixedHeight(nmParameterField::editorHeight());
- pLengthUnit->setMinimumWidth(nmParameterField::unitMinimumWidth());
+ // 随完整单位列表和字体计算宽度,窗口缩小时仍保留单位文字及下拉箭头。
+ pLengthUnit->setSizeAdjustPolicy(QComboBox::AdjustToContents);
+ pLengthUnit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
pGrid->addWidget(pLengthUnit, 2, 2);
// 以米作为单位组识别入口;参数标识为空时,框架按下拉框已有单位查找单位组。
@@ -97,10 +140,12 @@ void nmWxMeasuringScaleDlg::initUI()
m_pLengthEdit->setEnabled(m_bUnitBound);
pLengthUnit->setEnabled(m_bUnitBound);
pMainLayout->addWidget(pGroup);
- pMainLayout->addStretch();
+ // 纵向余量由分组与底部按钮之间的布局空间吸收,不拉长输入框或行间距。
+ pMainLayout->addStretch(1);
// 使用标准按钮框和框架图标,与其他已统一的参数对话框保持相同的底部布局。
QWidget* pFooter = new QWidget(this);
+ pFooter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
QHBoxLayout* pFooterLayout = new QHBoxLayout(pFooter);
pFooterLayout->setContentsMargins(4, 5, 4, 5);
pFooterLayout->setSpacing(8);