From 0aeec10a646fa39c39c09461c2fabee82f38ee95 Mon Sep 17 00:00:00 2001 From: crqiqi77 Date: Thu, 19 Mar 2026 09:44:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B2=A9=E5=BF=83=E7=85=A7=E7=89=87=20?= =?UTF-8?q?=E8=BE=B9=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logPlus/PropertyWidget.cpp | 65 ++++++++++++++++++++------ logPlus/PropertyWidget.h | 5 +- logPlus/forminfo.h | 13 +----- logPlus/qmycustomplot.cpp | 28 ++++++++++- logPlus/qmycustomplot.h | 2 + logPlus/transparentdraggableimage.cpp | 67 ++++++++++++++++++++++++--- logPlus/transparentdraggableimage.h | 16 +++++++ 7 files changed, 161 insertions(+), 35 deletions(-) diff --git a/logPlus/PropertyWidget.cpp b/logPlus/PropertyWidget.cpp index 889816e..20fb05c 100644 --- a/logPlus/PropertyWidget.cpp +++ b/logPlus/PropertyWidget.cpp @@ -226,27 +226,57 @@ void PropertyWidget::changedYxzpItemProperty(QtProperty *qtProperty, const QVari { if(m_tdImage) { -// double lower = qVariant.value(); -// m_tdImage->setLower(-lower); - m_tdImage->mPlot->SaveToSLFImage(); + int borderWidth = qVariant.toInt(); + m_tdImage->setBorderWidth(borderWidth); + m_tdImage->setRange(m_tdImage->getRange().lower, m_tdImage->getRange().upper); } } else if("颜色" == m_propertyData[qtProperty]) { if(m_tdImage) { -// double lower = qVariant.value(); -// m_tdImage->setLower(-lower); - m_tdImage->mPlot->SaveToSLFImage(); + QColor newColor = qVariant.value(); + m_tdImage->setBorderColor(newColor); + m_tdImage->setRange(m_tdImage->getRange().lower, m_tdImage->getRange().upper); } } else if("线型" == m_propertyData[qtProperty]) { if(m_tdImage) { -// double lower = qVariant.value(); -// m_tdImage->setLower(-lower); - m_tdImage->mPlot->SaveToSLFImage(); + Qt::PenStyle newStyle = Qt::SolidLine; + int iStyle = qVariant.value(); + switch(iStyle) + { + case 0: + //无 + newStyle = Qt::NoPen; + break; + case 1: + //实线 + newStyle = Qt::SolidLine; + break; + case 2: + //虚线 + newStyle = Qt::DashLine; + break; + case 3: + //点线 + newStyle = Qt::DotLine; + break; + case 4: + //虚点线 + newStyle = Qt::DashDotLine; + break; + case 5: + //虚点点线 + newStyle = Qt::DashDotDotLine; + break; + default: + break; + } + m_tdImage->setBorderStyle(newStyle); + m_tdImage->setRange(m_tdImage->getRange().lower, m_tdImage->getRange().upper); } } } @@ -2785,7 +2815,8 @@ void PropertyWidget::initImageProperty(FormInfo *formInfo) m_strCurrentProperty = Image_Property; } -void PropertyWidget::initImageItemProperty(TransparentDraggableImage* tdImage, double lower, double upper, QString pictureFile,double left, double width) +void PropertyWidget::initImageItemProperty(TransparentDraggableImage* tdImage, double lower, double upper, QString pictureFile, + double left, double width, QColor borderColor, Qt::PenStyle borderStyle, int borderWidth) { //初始化,清空 InitCurrentViewInfo(); @@ -2821,9 +2852,17 @@ void PropertyWidget::initImageItemProperty(TransparentDraggableImage* tdImage, d _CreateVariantPropertyItem("当前项", "左边距%", left, QVariant::Int); _CreateVariantPropertyItem("当前项", "宽度%", width, QVariant::Int); - _CreateVariantPropertyItem("边框属性", "线宽", formInfo->m_yxzpLineWidth, QVariant::Int); - _CreateVariantPropertyItem("边框属性", "颜色", formInfo->m_yxzpColor, QVariant::Color); - _CreateVariantPropertyItem("边框属性", "线型", formInfo->m_yxzpLineshape, QVariant::String); + _CreateVariantPropertyItem("边框属性", "线宽", borderWidth, QVariant::Int); + _CreateVariantPropertyItem("边框属性", "颜色", borderColor, QVariant::Color); +// _CreateVariantPropertyItem("边框属性", "线型", borderStyle, QVariant::String); + QStringList listStyle; + listStyle.append("无"); + listStyle.append("实线"); + listStyle.append("虚线"); + listStyle.append("点线"); + listStyle.append("虚点线"); + listStyle.append("虚点点线"); + _CreateEnumPropertyItem("边框属性", "线型", (int)borderStyle, listStyle); } //当前属性类型 diff --git a/logPlus/PropertyWidget.h b/logPlus/PropertyWidget.h index df22198..3d088e6 100644 --- a/logPlus/PropertyWidget.h +++ b/logPlus/PropertyWidget.h @@ -75,10 +75,11 @@ class PropertyWidget:public QDockWidget { Q_OBJECT + public: PropertyWidget(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); ~PropertyWidget(); - + private: QtTreePropertyBrowser *m_pPropertyBrowser; QtVariantPropertyManager *m_pVariantManager; @@ -177,7 +178,7 @@ public: // 岩心照片属性 void initImageProperty(FormInfo *formInfo); - void initImageItemProperty(TransparentDraggableImage* tdImage, double lower, double upper, QString strResult, double left, double width); + void initImageItemProperty(TransparentDraggableImage* tdImage, double lower, double upper, QString strResult, double left, double width, QColor borderColor, Qt::PenStyle borderStyle, int borderWidth); // 井壁取心属性 void initSwallCoreProperty(FormInfo *formInfo); diff --git a/logPlus/forminfo.h b/logPlus/forminfo.h index a7a537b..737d03c 100644 --- a/logPlus/forminfo.h +++ b/logPlus/forminfo.h @@ -165,18 +165,7 @@ public: bool m_yxzpTwoEndDrawing; // 绘制颜色 bool m_yxzpDrawColor; - // 图片文件 - QString m_yxzpPictureFile; - // 左边距 - double m_yxzpLeftMargin; - // 宽度 - double m_yxzpWidth; - // 线宽 - int m_yxzpLineWidth; - // 颜色 - QString m_yxzpColor; - // 线型 - QString m_yxzpLineshape; + //气测/FMT/射孔/文本 QStringList m_FieldNameList; diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index 298eb7e..6d7c088 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -3974,7 +3974,33 @@ void QMyCustomPlot::addImageToPlot(double left_Low, double right_Hight, const QS m_mapDraggable_Image[strUuid] = dragRect; } -void QMyCustomPlot::addImageToPlot(double left_Low, double right_Hight, const QString imagePath, double left, double width) +void QMyCustomPlot::addImageToPlot(double left_Low, double right_Hight, const QString imagePath, + double left, double width) +{ + QtCommonClass *qtCommon = new QtCommonClass(this); + QString strUuid = qtCommon->getUUid(); + + // 在初始化代码中 + TransparentDraggableImage *dragRect = new TransparentDraggableImage(this, strUuid); + //图片,提前设值,后面setRange改变 + dragRect->setResult(imagePath); + + // 可选:设置颜色 + dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色 + //最小宽度 + dragRect->setMinWidth(0.1); + //dragRect->setTitle(strText); + dragRect->setLeft(left); + dragRect->setWidth(width); + + // 设置初始范围 + dragRect->setRange(left_Low, right_Hight,left,width); + + m_mapDraggable_Image[strUuid] = dragRect; +} + +void QMyCustomPlot::addImageToPlot(double left_Low, double right_Hight, const QString imagePath, + double left, double width, QColor borderColor, Qt::PenStyle borderStyle, int borderWidth) { QtCommonClass *qtCommon = new QtCommonClass(this); QString strUuid = qtCommon->getUUid(); diff --git a/logPlus/qmycustomplot.h b/logPlus/qmycustomplot.h index 0d34465..e702170 100644 --- a/logPlus/qmycustomplot.h +++ b/logPlus/qmycustomplot.h @@ -279,6 +279,8 @@ public: //岩心照片 void addImageToPlot(double left_Low, double right_Hight, const QString imagePath); void addImageToPlot(double left_Low, double right_Hight, const QString imagePath, double left, double width); + // left_Low底, right_Hight高 imagePath图片 left左边距 width宽 mBorderColor边框颜色、 mBorderStyle边框样式 mBorderWidth边框宽 + void addImageToPlot(double left_Low, double right_Hight, const QString imagePath, double left, double width, QColor mBorderColor, Qt::PenStyle mBorderStyle, int mBorderWidth); //曲线 void addRandomGraph(QVector x, QVector y, QString strSlfName, QString strLineName, QString strAliasName, QString strUnit, diff --git a/logPlus/transparentdraggableimage.cpp b/logPlus/transparentdraggableimage.cpp index 0c82e08..24b9a8c 100644 --- a/logPlus/transparentdraggableimage.cpp +++ b/logPlus/transparentdraggableimage.cpp @@ -199,6 +199,13 @@ void TransparentDraggableImage::setRange(double left_Low, double right_Hight) //mRect->topLeft->setCoords(left, mPlot->yAxis->range().upper); //mRect->bottomRight->setCoords(right, mPlot->yAxis->range().lower); + if(m_BorderColor == nullptr){ + this->m_BorderColor = QColor(0, 0, 0, 200); // 边框颜色 + this->m_BorderStyle = Qt::SolidLine; // 边框线型 + this->m_BorderWidth = 1; // 边框线宽(像素) + } + // 应用边框样式到主矩形 + mRect->setPen(QPen(m_BorderColor, m_BorderWidth, m_BorderStyle)); updateHandles(); mPlot->replot(); } @@ -244,6 +251,7 @@ void TransparentDraggableImage::setRange(double left_Low, double right_Hight,dou mItemTitle->position->setCoords((mRect->topLeft->coords().x() + mRect->bottomRight->coords().x())/2, (mRect->topLeft->coords().y() + mRect->bottomRight->coords().y())/2); // 设置文本在矩形中心位置 + mRect->setPen(QPen(m_BorderColor, m_BorderWidth, m_BorderStyle)); updateHandles(); mPlot->replot(); } @@ -305,7 +313,17 @@ void TransparentDraggableImage::initRect() mRect = new QCPItemRect(mPlot); mRect->setLayer("overlay"); // 确保在最上层 mRect->setBrush(QBrush(QColor(255, 255, 255, 50))); // 半透明蓝色 - mRect->setPen(QPen(QColor(70, 70, 255, 200))); +// mRect->setPen(QPen(QColor(70, 70, 255, 200))); + + // 左边距 宽度 都是百分比 + this->m_left = 0; + this->m_width = 100; + // ========== 新增:边框样式成员变量 ========== + this->m_BorderColor = QColor(0, 0, 0, 200); // 边框颜色 + this->m_BorderStyle = Qt::SolidLine; // 边框线型 + this->m_BorderWidth = 1; // 边框线宽(像素) + // 应用边框样式到主矩形 + mRect->setPen(QPen(this->m_BorderColor, this->m_BorderWidth, this->m_BorderStyle)); // 创建左右边界控制点 mLeftHandle = new QCPItemRect(mPlot); @@ -395,7 +413,10 @@ void TransparentDraggableImage::onMousePress(QMouseEvent *event) double hight = mRect->bottomRight->coords().x(); double left = getLeft(); double width = getWidth(); - PropertyService()->initImageItemProperty(this, low, hight, m_Result, left, width); + QColor borderColor = this->m_BorderColor; // 边框颜色 + Qt::PenStyle borderStyle = this->m_BorderStyle; // 边框线型 + int borderWidth = this->m_BorderWidth; // 边框线宽(像素) + PropertyService()->initImageItemProperty(this, low, hight, m_Result, left, width,borderColor,borderStyle,borderWidth); QMenu menu(nullptr); QAction *delAction = menu.addAction("删除框图"); @@ -497,7 +518,6 @@ void TransparentDraggableImage::onMouseMove(QMouseEvent *event) newRange.upper = getMyUpper(); newRange.lower = newRange.upper - width; } - // QCPRange axisRange = mPlot->xAxis->range(); // if(newRange.lower < axisRange.lower) { // newRange.lower = axisRange.lower; @@ -539,7 +559,6 @@ void TransparentDraggableImage::onMouseMove(QMouseEvent *event) } setRange(newRange.lower, newRange.upper); - } void TransparentDraggableImage::onMouseRelease(QMouseEvent *event) @@ -549,9 +568,12 @@ void TransparentDraggableImage::onMouseRelease(QMouseEvent *event) // 显示属性 double low = mRect->topLeft->coords().x(); double hight = mRect->bottomRight->coords().x(); - double left = getLeft(); - double width = getWidth(); - PropertyService()->initImageItemProperty(this, low, hight, m_Result, left, width); + double left = this->getLeft(); + double width = this->getWidth(); + QColor borderColor = this->m_BorderColor; // 边框颜色 + Qt::PenStyle borderStyle = this->m_BorderStyle; // 边框线型 + int borderWidth = this->m_BorderWidth; // 边框线宽(像素) + PropertyService()->initImageItemProperty(this, low, hight, m_Result, left, width, borderColor, borderStyle, borderWidth); //避免二次绘制框图 @@ -692,3 +714,34 @@ double TransparentDraggableImage::getWidth() { return this->m_width; } +// 设置边框颜色 +void TransparentDraggableImage::setBorderColor(const QColor &color) +{ + this->m_BorderColor = color; +} + +// 设置边框线型 +void TransparentDraggableImage::setBorderStyle(Qt::PenStyle style) +{ + this->m_BorderStyle = style; +} + +// 设置边框线宽 +void TransparentDraggableImage::setBorderWidth(int width) +{ + // 线宽不能小于1像素,避免无效值 + if (width < 1) width = 1; + this->m_BorderWidth = width; +} +QColor TransparentDraggableImage::geBorderColor() +{ + return this->m_BorderColor; +} +Qt::PenStyle TransparentDraggableImage::getBorderStyle() +{ + return this->m_BorderStyle; +} +int TransparentDraggableImage::getBorderWidth() +{ + return this->m_BorderWidth; +} diff --git a/logPlus/transparentdraggableimage.h b/logPlus/transparentdraggableimage.h index 1fddd6d..e08daba 100644 --- a/logPlus/transparentdraggableimage.h +++ b/logPlus/transparentdraggableimage.h @@ -58,6 +58,17 @@ public: void setWidth(double width); double getWidth(); + + // 设置边框颜色 + void setBorderColor(const QColor &color); + // 设置边框线型(实线、虚线、点线等) + void setBorderStyle(Qt::PenStyle style); + // 设置边框线宽 + void setBorderWidth(int width); + QColor geBorderColor(); + Qt::PenStyle getBorderStyle(); + int getBorderWidth(); + signals: void rangeChanged(QCPRange newRange); @@ -95,6 +106,11 @@ private: double mMinWidth; // 左边距 宽度 都是百分比 double m_left = 0, m_width = 100; + + // ========== 新增:边框样式成员变量 ========== + QColor m_BorderColor; // 边框颜色 + Qt::PenStyle m_BorderStyle; // 边框线型 + int m_BorderWidth; // 边框线宽(像素) }; #endif // TRANSPARENTDRAGGABLEIMAGE_H