From a757d6583ee15600c0910c6b91edde49a9d0dd98 Mon Sep 17 00:00:00 2001 From: wangxiaolei <12345678> Date: Fri, 13 Mar 2026 14:58:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B2=A9=E5=BF=83=E5=9B=BE=E7=89=87=20?= =?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logPlus/YxzpDialog.cpp | 113 ++++++++++++++++++++++++++++++++++++++ logPlus/YxzpDialog.h | 38 +++++++++++++ logPlus/logPlus.pro | 2 + logPlus/qmycustomplot.cpp | 108 +++++++++++++++++++++++++++++++++++- logPlus/qmycustomplot.h | 7 +++ 5 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 logPlus/YxzpDialog.cpp create mode 100644 logPlus/YxzpDialog.h diff --git a/logPlus/YxzpDialog.cpp b/logPlus/YxzpDialog.cpp new file mode 100644 index 0000000..9909dd6 --- /dev/null +++ b/logPlus/YxzpDialog.cpp @@ -0,0 +1,113 @@ +#include "YxzpDialog.h" + +YxzpDialog::YxzpDialog(QWidget *parent) + : QDialog(parent) +{ + // setStyleSheet("QDialog { background-color: #888; }"); + setWindowTitle("图片"); + setFixedSize(600, 500); // 固定窗口大小,和示例接近 + + // 1. 边框属性行(示例里是占位,这里也做一个输入框) + QHBoxLayout *layoutBorder = new QHBoxLayout; + QLabel *labelBorder = new QLabel(QObject::tr("边框属性:")); + labelBorder->setMinimumWidth(60); // 统一最小宽度(可根据文本调整) + labelBorder->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); + QLineEdit *editBorder = new QLineEdit; + editBorder->setReadOnly(true); + editBorder->setPlaceholderText(""); + layoutBorder->setContentsMargins(0, 20, 0, 0); + layoutBorder->addWidget(labelBorder); + layoutBorder->addWidget(editBorder); + + // 2. 图片路径行 + QHBoxLayout *layoutPath = new QHBoxLayout; + QLabel *labelPath = new QLabel(QObject::tr("图片路径:")); + labelPath->setMinimumWidth(60); // 统一最小宽度(可根据文本调整) + labelPath->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); + m_editPath = new QLineEdit; + m_editPath->setReadOnly(true); // 只读,只能通过按钮选择 + QPushButton *btnSelect = new QPushButton("..."); + btnSelect->setFixedWidth(80); + layoutPath->addWidget(labelPath); + layoutPath->addWidget(m_editPath); + layoutPath->addWidget(btnSelect); + + // 3. 预览区域 + QVBoxLayout *layoutPreview = new QVBoxLayout; + QLabel *labelPreviewTitle = new QLabel(QObject::tr("预览")); + m_labelPreview = new QLabel; + m_labelPreview->setFrameStyle(QFrame::Box | QFrame::Sunken); // 加边框 + m_labelPreview->setAlignment(Qt::AlignCenter); + m_labelPreview->setMinimumSize(550, 320); // 预览区域最小尺寸 + layoutPreview->addWidget(labelPreviewTitle); + layoutPreview->addWidget(m_labelPreview); + + // 4. 按钮行 + QHBoxLayout *layoutButtons = new QHBoxLayout; + QPushButton *btnOk = new QPushButton(QObject::tr("确定")); + QPushButton *btnCancel = new QPushButton(QObject::tr("取消")); + // layoutButtons->setContentsMargins(0, 20, 0, 0); + layoutButtons->addStretch(); // 推到右侧 + layoutButtons->addWidget(btnOk); + layoutButtons->addWidget(btnCancel); + + // 总布局 + QVBoxLayout *mainLayout = new QVBoxLayout(this); + mainLayout->addLayout(layoutBorder); + mainLayout->addLayout(layoutPath); + mainLayout->addLayout(layoutPreview); + mainLayout->addStretch(); + mainLayout->addLayout(layoutButtons); + mainLayout->setContentsMargins(20, 0, 20, 10); + mainLayout->setSpacing(15); + + // 信号槽连接 + connect(btnSelect, &QPushButton::clicked, this, &YxzpDialog::onSelectImage); + connect(btnOk, &QPushButton::clicked, this, &YxzpDialog::onAccept); + connect(btnCancel, &QPushButton::clicked, this, &YxzpDialog::onReject); +} + +QString YxzpDialog::getImagePath() const +{ + return m_imagePath; +} + +void YxzpDialog::onSelectImage() +{ + // 弹出文件选择框,仅允许 JPG 图片 + QString filePath = QFileDialog::getOpenFileName( + this, + "选择图片", + QDir::homePath(), + "JPG 图片 (*.jpg *.jpeg)" + ); + + if (!filePath.isEmpty()) + { + m_editPath->setText(filePath); + // 加载并预览图片 + QPixmap pixmap(filePath); + if (!pixmap.isNull()) + { + // 按比例缩放预览 + QPixmap scaledPixmap = pixmap.scaled( + m_labelPreview->size(), + Qt::KeepAspectRatio, + Qt::SmoothTransformation + ); + m_labelPreview->setPixmap(scaledPixmap); + } + } +} + +void YxzpDialog::onAccept() +{ + m_imagePath = m_editPath->text(); + accept(); // 关闭对话框,返回 QDialog::Accepted +} + +void YxzpDialog::onReject() +{ + m_imagePath.clear(); + reject(); // 关闭对话框,返回 QDialog::Rejected +} diff --git a/logPlus/YxzpDialog.h b/logPlus/YxzpDialog.h new file mode 100644 index 0000000..6402322 --- /dev/null +++ b/logPlus/YxzpDialog.h @@ -0,0 +1,38 @@ +#ifndef YXZPDIALOG_H +#define YXZPDIALOG_H +// 岩心照片 自定义 dialog +#include +#include +#include +#include +#include +#include +#include + + +#include + +class YxzpDialog : public QDialog +{ + Q_OBJECT +public: + explicit YxzpDialog(QWidget *parent = nullptr); + + // 获取最终选择的图片路径 + QString getImagePath() const; + +private slots: + // 选择图片按钮点击 + void onSelectImage(); + // 确认按钮点击 + void onAccept(); + // 取消按钮点击 + void onReject(); + +private: + QLineEdit *m_editPath; // 图片路径输入框 + QLabel *m_labelPreview; // 预览图片 + QString m_imagePath; // 存储最终路径 +}; + +#endif // YXZPCUSDIALOG_H diff --git a/logPlus/logPlus.pro b/logPlus/logPlus.pro index c1b71db..c4e4b00 100644 --- a/logPlus/logPlus.pro +++ b/logPlus/logPlus.pro @@ -58,6 +58,7 @@ SOURCES += \ TransparentDraggableSwallCore.cpp \ TransparentGroupResult.cpp \ ViewInfo.cpp \ + YxzpDialog.cpp \ backgrounddelegate.cpp \ customtabbar.cpp \ customtabwidget.cpp \ @@ -121,6 +122,7 @@ HEADERS += \ TransparentDraggableSwallCore.h \ TransparentGroupResult.h \ ViewInfo.h \ + YxzpDialog.h \ backgrounddelegate.h \ customtabbar.h \ customtabwidget.h \ diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index 6be7b08..2f16773 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -21,6 +21,7 @@ #include "slf.h" #include "MemRdWt.h" #include "PropertyWidget.h" +#include "YxzpDialog.h" //是否隐藏刻度 extern int g_iShow; @@ -1094,6 +1095,18 @@ void QMyCustomPlot::contextMenuEvent(QContextMenuEvent *event) menu.addAction(QIcon(::GetImagePath() + "icon/CopyCoreTxt.png"), "刷新数据", this, &QMyCustomPlot::RefreshItems_Layer); menu.exec(event->globalPos()); } + else if (m_strLineName == "IMAGE_DATA") + { + QMenu menu(this); + //岩心图片 + menu.addAction(QIcon(::GetImagePath() + "curve.png"), "开始编辑岩心图片", this, &QMyCustomPlot::onEditImage); + menu.addAction(QIcon(::GetImagePath() + "icon/CopyCoreTxt.png"), "从剪切板文本数据粘贴", this, &QMyCustomPlot::addItemsImage); + menu.addAction(QIcon(::GetImagePath() + "icon/ClearSelectCore.png"), "取消选中", this, &QMyCustomPlot::ClearSelectItems); + menu.addAction(QIcon(::GetImagePath() + "icon/Delete.png"), "全部清空", this, &QMyCustomPlot::DeleteItemsImage); + menu.addAction(QIcon(::GetImagePath() + "icon/CopyCoreTxt.png"), "刷新数据", this, &QMyCustomPlot::RefreshItemsImage); + menu.addAction(QIcon(::GetImagePath() + "development.png"), "合并结论", this, &QMyCustomPlot::MegResultImage); + menu.exec(event->globalPos()); + } } //右键--添加分段线 @@ -1451,6 +1464,99 @@ void QMyCustomPlot::onEditGujing() } } +void QMyCustomPlot::onEditImage() +{ + this->setInteractions(QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables | QCP::iMultiSelect); // 轴、图例、图表可以被选择,并且是多选的方式 + this->setSelectionRectMode(QCP::srmCustom); // 鼠标框选 + + if(m_bFirstTimeConnect) + { + //信号槽只绑定一次,避免重复绑定 + m_bFirstTimeConnect = false; + + for (int i=0; i < this->graphCount(); ++i) { + QCPGraph *graph = this->graph(i); + graph->setSelectable(QCP::stDataRange); + break; + } + + connect(this->selectionRect(), &QCPSelectionRect::accepted, [this](){ + if(this->m_bDrawRect == false) + { + this->m_bDrawRect = true; + return; + } + // 当选择完成时,获取矩形范围并放大 + QRectF rect = this->selectionRect()->rect(); // 获取选择的矩形区域(像素坐标) + m_bEditRect=true;//当前是否正在编辑曲线。 + + // 转换为坐标轴范围 + double top = rect.top(); + double bottom = rect.bottom(); + + double right_Hight = this->xAxis->pixelToCoord(top); + double left_Low = this->xAxis->pixelToCoord(bottom); + + //追加判断,避免框选重叠 + TransparentDraggableGujing *pDraggableRect =NULL; + { + QMap::Iterator it = m_mapDraggable_Gujing.begin(); + while( it != m_mapDraggable_Gujing.end() ) + { + pDraggableRect = (TransparentDraggableGujing*)it.value(); + // + QCPRange tmpRange = pDraggableRect->getRange(); + if(tmpRange.lower >= left_Low && tmpRange.upper <= right_Hight) + { + return; + } + + if(tmpRange.upper >= left_Low && tmpRange.upper <= right_Hight) + { + return; + } + + if(tmpRange.lower >= left_Low && tmpRange.lower <= right_Hight) + { + return; + } + + it++; + } + } + { + // 弹框选择图片 + YxzpDialog dlg(nullptr); + QString imagePath = ""; + if (dlg.exec() == QDialog::Accepted) // 点击“确定”按钮 + { + imagePath = dlg.getImagePath(); + } + + //添加固井结论 + this->addImageToPlot(left_Low, right_Hight, imagePath); + + //保存 + this->SaveToSLF_Gujing(); + + //属性清空 + PropertyService()->InitCurrentViewInfo(); + + //取消框选 + this->setInteractions(QCP::iSelectLegend | QCP::iSelectPlottables); + this->setSelectionRectMode(QCP::srmNone); + } + }); + + //this->selectionRect()->cancel(); + } +} + +void QMyCustomPlot::addItemsImage(){} +void QMyCustomPlot::DeleteItemsImage(){} +void QMyCustomPlot::RefreshItemsImage(){} +void QMyCustomPlot::MegResultImage(){} + //右键--添加录井剖面 void QMyCustomPlot::onEditGeoLith() { @@ -3493,7 +3599,7 @@ void QMyCustomPlot::addImageToPlot(double left_Low, double right_Hight, const QS dragRect->setResult(imagePath); // 设置初始范围 dragRect->setRange(left_Low, right_Hight); - // 可选:设置颜色 + // 可选:设置颜色` dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色 //最小宽度 dragRect->setMinWidth(0.1); diff --git a/logPlus/qmycustomplot.h b/logPlus/qmycustomplot.h index c393b6e..1123fd6 100644 --- a/logPlus/qmycustomplot.h +++ b/logPlus/qmycustomplot.h @@ -373,6 +373,13 @@ public slots: //右键--气测-管柱-文本-FMT-射孔 void RefreshItems_Jiegutext(QString strAliasName = "气测-FMT-射孔-文本"); //刷新数据 + //右键--编辑岩心照片 + void onEditImage(); + void addItemsImage(); //从剪切板文本数据粘贴 + void DeleteItemsImage(); //全部清空 + void RefreshItemsImage(); //刷新数据 + void MegResultImage(); //合并结论 + // void addItems_Core();