#include "nmWxMeasureDlg.h" #include #include #include #include #include #include #include "nmDataAnalyzeManager.h" #include "nmGUIComponentLineEdit.h" #include "nmDataWellBase.h" Q_DECLARE_METATYPE(double *) Q_DECLARE_METATYPE(QString *) nmWxMeasureDlg::nmWxMeasureDlg(QWidget* parent) : iDlgBase(parent), m_pMainLayout(NULL), m_pFitStartButton(NULL), m_pFitEndButton(NULL), m_pLength(NULL), m_pData(NULL), m_pLengthCom(NULL) { this->initUI(); this->resize(400, 150); this->setWindowTitle(tr("Measure")); m_pFitStartButton->setEnabled(false); m_pFitEndButton->setEnabled(false); } 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); 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); } void nmWxMeasureDlg::initPara() { m_pData = nmDataAnalyzeManager::getCurrentInstance()->getMeasureData(); m_pData->getLength().setName(tr("Length :")); m_vecWellList = nmDataAnalyzeManager::getCurrentInstance()->getWellDataList(); } void nmWxMeasureDlg::initComponents() { m_pLengthCom = new nmGUIComponentLineEdit(&m_pData->getLength(), false); m_pMainLayout->addWidget(m_pLengthCom); } void nmWxMeasureDlg::onFitStartClicked() { m_pFitStartButton->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->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; } } m_pData->setStartPoint(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(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::onFitEndClicked() { 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(); } void nmWxMeasureDlg::closeEvent(QCloseEvent* event) { emit needDeleteMeasureObj(); iDlgBase::closeEvent(event); } void nmWxMeasureDlg::onCloseClicked() { emit needDeleteMeasureObj(); accept(); } void nmWxMeasureDlg::resetButtons() { m_pFitStartButton->setEnabled(true); m_pFitEndButton ->setEnabled(true); }