From c8f80b3b589d69ad866e309e43d26616f8c8da13 Mon Sep 17 00:00:00 2001 From: jiayulong <22806282@qq.com> Date: Wed, 12 Nov 2025 16:56:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E5=A4=B4=E5=B1=9E=E6=80=A7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=8F=AF=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=9B=BE=E4=BE=8B=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=96=87=E5=AD=97=E5=AD=97=E4=BD=93=E3=80=81?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E9=85=8D=E7=BD=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logPlus/PropertyWidget.cpp | 267 ++++++++++++++++++++++++++++----- logPlus/PropertyWidget.h | 17 ++- logPlus/backgrounddelegate.cpp | 24 +++ logPlus/backgrounddelegate.h | 15 ++ logPlus/formhead.cpp | 139 +++++++++++++++-- logPlus/formhead.h | 8 +- logPlus/forminfo.cpp | 9 +- logPlus/formmultiheads.cpp | 21 +-- logPlus/formmultiheads.ui | 4 +- logPlus/logPlus.pro | 4 +- logPlus/mainwindow.cpp | 3 +- logPlus/mainwindowcurve.cpp | 15 ++ 12 files changed, 457 insertions(+), 69 deletions(-) create mode 100644 logPlus/backgrounddelegate.cpp create mode 100644 logPlus/backgrounddelegate.h diff --git a/logPlus/PropertyWidget.cpp b/logPlus/PropertyWidget.cpp index a0c18b4..18d4bb2 100644 --- a/logPlus/PropertyWidget.cpp +++ b/logPlus/PropertyWidget.cpp @@ -2,9 +2,12 @@ #include #include #include +#include +#include #include "CallManage.h" extern int g_iScale; +extern double g_dPixelPerCm;//每厘米像素数 PropertyWidget::PropertyWidget(const QString &title, QWidget *parent , Qt::WindowFlags flags ) :QDockWidget(title,parent,flags) @@ -61,6 +64,7 @@ void PropertyWidget::InitCurrentViewInfo() m_propertyData.clear(); m_mapGroupItem.clear(); + m_strUuid = ""; m_strSlfName = ""; m_strWellName = ""; m_strTrackName = ""; @@ -73,13 +77,13 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant { if("深度比例尺" == m_propertyData[pProperty]) { - qDebug() << "深度比例尺->改变"; + //qDebug() << "深度比例尺->改变"; //当前属性类型 if(m_strCurrentProperty == Widget_Property) { int iScale = 200; QString newScale = pProperty->valueText(); - qDebug() << "深度比例尺->" << newScale; + //qDebug() << "深度比例尺->" << newScale; // int pos = newScale.indexOf(":"); if(pos>-1) @@ -96,10 +100,9 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant g_iScale = iScale; } } - else if("左刻度" == m_propertyData[pProperty]) { - qDebug() << "左刻度->改变"; + //qDebug() << "左刻度->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -111,7 +114,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("右刻度" == m_propertyData[pProperty]) { - qDebug() << "右刻度->改变"; + //qDebug() << "右刻度->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -123,7 +126,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("刻度类型" == m_propertyData[pProperty]) { - qDebug() << "刻度类型->改变"; + //qDebug() << "刻度类型->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -135,7 +138,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("颜色" == m_propertyData[pProperty]) { - qDebug() << "颜色->改变"; + //qDebug() << "颜色->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -147,7 +150,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("线宽" == m_propertyData[pProperty]) { - qDebug() << "线宽->改变"; + //qDebug() << "线宽->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -157,7 +160,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("线型" == m_propertyData[pProperty]) { - qDebug() << "线型->改变"; + //qDebug() << "线型->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -194,7 +197,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("填充模式" == m_propertyData[pProperty]) { - qDebug() << "填充模式->改变"; + //qDebug() << "填充模式->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -203,7 +206,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("填充类型" == m_propertyData[pProperty]) { - qDebug() << "填充类型->改变"; + //qDebug() << "填充类型->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -212,7 +215,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("目标曲线" == m_propertyData[pProperty]) { - qDebug() << "目标曲线->改变"; + //qDebug() << "目标曲线->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -221,7 +224,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("填充颜色" == m_propertyData[pProperty]) { - qDebug() << "填充颜色->改变"; + //qDebug() << "填充颜色->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -230,7 +233,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("填充岩性" == m_propertyData[pProperty]) { - qDebug() << "填充岩性->改变"; + //qDebug() << "填充岩性->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -239,7 +242,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("岩性前景色" == m_propertyData[pProperty]) { - qDebug() << "岩性前景色->改变"; + //qDebug() << "岩性前景色->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -248,7 +251,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("岩性背景色" == m_propertyData[pProperty]) { - qDebug() << "岩性背景色->改变"; + //qDebug() << "岩性背景色->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { @@ -257,13 +260,164 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant } else if("头部图例" == m_propertyData[pProperty]) { - qDebug() << "头部图例->改变"; + //qDebug() << "头部图例->改变"; //当前属性类型 if(m_strCurrentProperty == Curve_Property) { ChangFillProperty(); } } + //图头--------------------------- + else if("图例" == m_propertyData[pProperty]) + { + //qDebug() << "图例->改变"; + //当前属性类型 + if(m_strCurrentProperty == Head_Property) + { + QString newSvg = variant.value(); + m_item->setData(Qt::UserRole+1, newSvg); // 图片路径 + //图头项改变 + ChangHeadItemProperty(); + } + } + else if("图例宽(cm)" == m_propertyData[pProperty]) + { + //qDebug() << "图例宽(cm)->改变"; + //当前属性类型 + if(m_strCurrentProperty == Head_Property) + { + double newWidth = variant.value(); + m_item->setData(Qt::UserRole+2, newWidth); // 图片路径 + m_colWidth = newWidth; + //图头项改变 + ChangHeadItemProperty(); + } + } + else if("图例高(cm)" == m_propertyData[pProperty]) + { + //qDebug() << "图例高(cm)->改变"; + //当前属性类型 + if(m_strCurrentProperty == Head_Property) + { + double newHight = variant.value(); + m_item->setData(Qt::UserRole+3, newHight); // 图片路径 + m_rowHeight = newHight; + //图头项改变 + ChangHeadItemProperty(); + } + } + else if("内容" == m_propertyData[pProperty]) + { + //qDebug() << "内容->改变"; + //当前属性类型 + if(m_strCurrentProperty == Head_Property) + { + QString newText = variant.value(); + m_formHead->m_bRefresh=false; + m_item->setText(newText); + } + } + else if("方向" == m_propertyData[pProperty]) + { + //qDebug() << "方向->改变"; + //当前属性类型 + if(m_strCurrentProperty == Head_Property) + { + QString newDirection = pProperty->valueText(); + if(newDirection=="垂直") + { + + } + else{ + //m_item-> + } + } + } + else if("字体颜色" == m_propertyData[pProperty]) + { + //qDebug() << "字体颜色->改变"; + //当前属性类型 + if(m_strCurrentProperty == Head_Property) + { + //字体颜色 + // 假设variant已经被设置为包含QColor + QColor newColor = variant.value(); + // 设置字体颜色 + QBrush brush(newColor); // 使用Qt::red预定义颜色 + m_formHead->m_bRefresh=false; + m_item->setForeground(brush); + } + } + else if("字体" == m_propertyData[pProperty]) + { + //qDebug() << "字体->改变"; + //当前属性类型 + if(m_strCurrentProperty == Head_Property) + { + //字体 + // 假设variant已经被设置为包含QColor + QFont newFont = variant.value(); + // 设置字体 + m_formHead->m_bRefresh=false; + m_item->setFont(newFont); + } + } +} + +void PropertyWidget::ChangHeadItemProperty() +{ + //清空 + m_tableWidget->setCellWidget(m_iRow, m_iCol, nullptr); + + //--------------------------- + QString imagePath = ""; //"./image/胜利符号库/解释结论符号/油层.svg" + QVariant bgData = m_item->data(Qt::UserRole+1); // 我们约定用这个角色存储图片路径 + if (bgData.isValid()) { + imagePath = bgData.toString(); + } + if(imagePath=="") + { + return; + } + + if(imagePath!="") + { + if(imagePath.size()>4) + { + int colWidth = m_colWidth*g_dPixelPerCm; + int rowHeight = m_rowHeight*g_dPixelPerCm; + // + QString strLast = imagePath.right(4); + if(strLast.toLower()==".svg") + { + // + QSvgRenderer* svgRender = new QSvgRenderer(); + svgRender->load(imagePath); + // + QPixmap* pixmap = new QPixmap(colWidth-1, rowHeight-1); + pixmap->fill(Qt::transparent);//设置背景透明 + QPainter p(pixmap); + svgRender->render(&p); + //1.直接采用控件显示 + QLabel* label = new QLabel; + label->setPixmap(*pixmap); + label->setAlignment(Qt::AlignHCenter); + label->show(); + m_formHead->m_bRefresh=false; + m_tableWidget->setCellWidget(m_iRow, m_iCol,label); + + //m_item->setIcon(QIcon(*pixmap)); + // 设置背景刷 + //QBrush brush(*pixmap); + //m_item->setBackground(brush); + //m_tableWidget->setItem(m_iRow, m_iCol, new QTableWidgetItem(QIcon(*pixmap),tr(""))); + } + else if(strLast.toLower()==".png") + { + + } + } + } } void PropertyWidget::ChangFillProperty() @@ -288,7 +442,7 @@ void PropertyWidget::ChangFillProperty() if(pProperty->hasValue()) { newFillMode = pProperty->valueText(); - qDebug() << "填充模式->" << newFillMode; + //qDebug() << "填充模式->" << newFillMode; } } else if(it.value()=="填充类型") @@ -297,7 +451,7 @@ void PropertyWidget::ChangFillProperty() if(pProperty->hasValue()) { newFillType = pProperty->valueText(); - qDebug() << "填充类型->" << newFillType; + //qDebug() << "填充类型->" << newFillType; } } else if(it.value()=="目标曲线") @@ -306,7 +460,7 @@ void PropertyWidget::ChangFillProperty() if(pProperty->hasValue()) { newTargetLine = pProperty->valueText(); - qDebug() << "目标曲线->" << newTargetLine; + //qDebug() << "目标曲线->" << newTargetLine; // if(newTargetLine=="左界道" || newTargetLine=="右界道" || newTargetLine=="对称线") { @@ -334,7 +488,7 @@ void PropertyWidget::ChangFillProperty() { newColor = pProperty->value().value(); } - qDebug() << "填充颜色->"; + //qDebug() << "填充颜色->"; } else if(it.value()=="填充岩性") { @@ -343,7 +497,7 @@ void PropertyWidget::ChangFillProperty() { newLithosImage = pProperty->valueText(); } - qDebug() << "填充岩性->" << newLithosImage; + //qDebug() << "填充岩性->" << newLithosImage; } else if(it.value()=="岩性前景色") { @@ -352,7 +506,7 @@ void PropertyWidget::ChangFillProperty() { frontColor = pProperty->value().value(); } - qDebug() << "岩性前景色->"; + //qDebug() << "岩性前景色->"; } else if(it.value()=="岩性背景色") { @@ -361,7 +515,7 @@ void PropertyWidget::ChangFillProperty() { backColor = pProperty->value().value(); } - qDebug() << "岩性背景色->"; + //qDebug() << "岩性背景色->"; } else if(it.value()=="头部图例") { @@ -369,7 +523,7 @@ void PropertyWidget::ChangFillProperty() if(pProperty->hasValue()) { newHeadFill = pProperty->valueText(); - qDebug() << "头部图例->" << newHeadFill; + //qDebug() << "头部图例->" << newHeadFill; } } } @@ -481,27 +635,11 @@ void PropertyWidget::initWidgetProperty() } void PropertyWidget::initCurveProperty(FormInfo *formInfo, QStringList strListOtherLine, QList listMin, QList listMax, QStringList strListOtherScaleType) -//void PropertyWidget::initCurveProperty(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QColor lineColor, double dWidth, QStringList strListOtherLine) { //初始化,清空 InitCurrentViewInfo(); m_strUuid = formInfo->m_strUuid; -// QString strSlfName = formInfo->m_strSlfName; -// QString strWellName = formInfo->m_strWellName; -// QString strTrackName = formInfo->m_strTrackName; -// QString strLineName = formInfo->m_strLineName; -// int ilineStyle = formInfo->m_lineStyle; -// QString newHeadFill = formInfo->m_newHeadFill; - -// QColor lineColor = formInfo->m_lineColor; -// double dWidth = formInfo->m_dWidth; -// float vmax = formInfo->m_vmax; -// float vmin = formInfo->m_vmin; -// QString strScaleType = formInfo->m_strScaleType; -// QColor frontColor = formInfo->m_frontColor; -// QColor backColor = formInfo->m_backColor; - // m_strSlfName = formInfo->m_strSlfName; m_strWellName = formInfo->m_strWellName; @@ -578,3 +716,50 @@ void PropertyWidget::initCurveProperty(FormInfo *formInfo, QStringList strListOt _CreateVariantPropertyItem("岩性填充", "岩性前景色", formInfo->m_frontColor, QVariant::Color); _CreateVariantPropertyItem("岩性填充", "岩性背景色", formInfo->m_backColor, QVariant::Color); } + + +void PropertyWidget::initHeadProperty(FormHead *formHead, QTableWidget *tableWidget, QTableWidgetItem* item, int row, int col) +{ + //初始化,清空 + InitCurrentViewInfo(); + + m_formHead = formHead; + m_tableWidget = tableWidget; + m_item = item; + m_iRow = row; + m_iCol = col; + + //当前属性类型 + m_strCurrentProperty = Head_Property; + + QStringList listDirection; + listDirection.append("水平"); + listDirection.append("垂直"); + + QString imagePath = "";//"./image/胜利符号库/解释结论符号/油层.svg" + QVariant bgData = m_item->data(Qt::UserRole+1); // 我们约定用这个角色存储图片路径 + if (bgData.isValid()) { + imagePath = bgData.toString(); + } + //图例宽 + QVariant colWidthData = m_item->data(Qt::UserRole+2); + if (colWidthData.isValid()) { + m_colWidth = colWidthData.toDouble(); + } + //图例高 + QVariant rowHeightData = m_item->data(Qt::UserRole+3); + if (rowHeightData.isValid()) { + m_rowHeight = rowHeightData.toDouble(); + } + + _CreateVariantPropertyItem("单元格", "图例", imagePath, VariantManager::filePathTypeId()); //"./image/胜利符号库/岩性符号/砂岩.png" + _CreateVariantPropertyItem("单元格", "图例宽(cm)", m_colWidth, QVariant::Double, 0, 100); + _CreateVariantPropertyItem("单元格", "图例高(cm)", m_rowHeight, QVariant::Double, 0, 100); + + _CreateVariantPropertyItem("文本", "内容", item->text(), QVariant::String); + _CreateVariantPropertyItem("文本", "字体", m_item->font(), QVariant::Font); + _CreateEnumPropertyItem("文本", "方向", 0, listDirection); + _CreateVariantPropertyItem("文本", "字体颜色", m_item->foreground().color(), QVariant::Color); + +} + diff --git a/logPlus/PropertyWidget.h b/logPlus/PropertyWidget.h index e1e4894..8e536d3 100644 --- a/logPlus/PropertyWidget.h +++ b/logPlus/PropertyWidget.h @@ -6,6 +6,7 @@ */ #pragma once #include +#include #include "qtpropertybrowser.h" #include "qtvariantproperty.h" @@ -15,10 +16,12 @@ #include "variantfactory.h" // #include "forminfo.h" +#include "formhead.h" //当前曲线类型 #define Widget_Property "Widget_Property" #define Curve_Property "Curve_Property" +#define Head_Property "Head_Property" #pragma execution_character_set("utf-8") @@ -57,6 +60,14 @@ public: QList m_listMax; QStringList m_strListOtherScaleType; + FormHead *m_formHead; + QTableWidget *m_tableWidget; + QTableWidgetItem* m_item; + int m_iRow; + int m_iCol; + double m_colWidth = 1; + double m_rowHeight = 1; + public: QWidget* GetPropertyWidget(); @@ -66,11 +77,15 @@ public: void InitCurrentViewInfo(); //初始化属性,清空 void initWidgetProperty(); //可视解释整体属性 - //void initCurveProperty(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QColor lineColor, double dWidth, QStringList strListOtherLine); //曲线属性 + //曲线 void initCurveProperty(FormInfo *formInfo, QStringList strListOtherLine, QList listMin, QList listMax, QStringList strListOtherScaleType); + //图头 + void initHeadProperty(FormHead *formHead, QTableWidget *tableWidget, QTableWidgetItem* item, int row, int col); void ChangFillProperty();//填充属性改变 + void ChangHeadItemProperty();//图头项改变 + public slots: void SlotPropertyChanged( QtProperty *property, const QVariant &variant ); diff --git a/logPlus/backgrounddelegate.cpp b/logPlus/backgrounddelegate.cpp new file mode 100644 index 0000000..f818311 --- /dev/null +++ b/logPlus/backgrounddelegate.cpp @@ -0,0 +1,24 @@ +#include "backgrounddelegate.h" +#include +#include + +BackgroundDelegate::BackgroundDelegate(QObject *parent) + : QStyledItemDelegate(parent) +{ +} + +void BackgroundDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + // 首先,检查这个单元格是否有背景图片数据,我们可以使用一个角色来存储,比如Qt::UserRole+1 + QVariant bgData = index.data(Qt::UserRole+1); // 我们约定用这个角色存储图片路径 + if (bgData.isValid()) { + QString imagePath = bgData.toString(); + QPixmap pixmap(imagePath); + if (!pixmap.isNull()) { + // 绘制背景图片,缩放到单元格大小 + painter->drawPixmap(option.rect, pixmap.scaled(option.rect.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + } + } + // 然后调用基类绘制文本等 + QStyledItemDelegate::paint(painter, option, index); +} diff --git a/logPlus/backgrounddelegate.h b/logPlus/backgrounddelegate.h new file mode 100644 index 0000000..5de778a --- /dev/null +++ b/logPlus/backgrounddelegate.h @@ -0,0 +1,15 @@ +#ifndef BACKGROUNDDELEGATE_H +#define BACKGROUNDDELEGATE_H + + +// 在头文件中声明 +#include + +class BackgroundDelegate : public QStyledItemDelegate +{ +public: + explicit BackgroundDelegate(QObject *parent = nullptr); + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; +}; + +#endif // BACKGROUNDDELEGATE_H diff --git a/logPlus/formhead.cpp b/logPlus/formhead.cpp index 031d8ef..8bab741 100644 --- a/logPlus/formhead.cpp +++ b/logPlus/formhead.cpp @@ -6,13 +6,20 @@ #include #include "CallManage.h" #include +#include +#include +#include "backgrounddelegate.h" +#include "PropertyWidget.h" //extern int g_iRows; //extern int g_iCols; -int g_iColsWidth=200; -int g_iRowsHight=80; +int g_iFixedWidth=20; +int g_iFixedHeight=20; +int g_iColsWidth=100; +int g_iRowsHight=40; +extern double g_dPixelPerCm;//每厘米像素数 //画图头 FormHead::FormHead(QWidget *parent, int indexID) : QWidget(parent), @@ -31,8 +38,8 @@ FormHead::FormHead(QWidget *parent, int indexID) : // //ui->tableWidget->verticalHeader()->hide(); //行 //ui->tableWidget->horizontalHeader()->hide(); //列 - ui->tableWidget->verticalHeader()->setFixedWidth(3);//标题栏宽度 - ui->tableWidget->horizontalHeader()->setFixedHeight(3);//标题栏高度 + ui->tableWidget->verticalHeader()->setFixedWidth(g_iFixedWidth);//标题栏宽度 + ui->tableWidget->horizontalHeader()->setFixedHeight(g_iFixedHeight);//标题栏高度 //ui->tableWidget->setColumnCount(1); //动态设置列数 //ui->tableWidget->horizontalHeader()->setStretchLastSection(true);//最后一列铺满最后 //标题 @@ -43,12 +50,14 @@ FormHead::FormHead(QWidget *parent, int indexID) : ui->tableWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); // 设置右键菜单策略 ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextMenu(QPoint))); // 在窗口构造函数中 //ui->tableWidget->installEventFilter(this); + // 设置整个表格的委托,或者特定列的委托 + //ui->tableWidget->setItemDelegate(new BackgroundDelegate(ui->tableWidget)); // 连接信号和槽 connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextMenu(QPoint))); + //connect(ui->tableWidget, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(slotItemClicked(QTableWidgetItem*))); } FormHead::~FormHead() @@ -59,14 +68,16 @@ FormHead::~FormHead() void FormHead::resizeWindow() { QRect rect = this->rect(); + int tempWidth = m_iCols*g_iColsWidth+g_iFixedWidth+10; + int tempHight = m_iRows*g_iRowsHight+g_iFixedHeight+10; //调整大小 - if(rect.width()>m_iCols*g_iColsWidth) + if(rect.width()>tempWidth) { - ui->tableWidget->setGeometry((rect.width()-(m_iCols*g_iColsWidth+1))/2, 0, m_iCols*(g_iColsWidth+1)+4, m_iRows*(g_iRowsHight+2)+4); + ui->tableWidget->setGeometry((rect.width()-tempWidth)/2, 2, tempWidth, tempHight); } else { - ui->tableWidget->setGeometry(0, 0, m_iCols*(g_iColsWidth+1)+4, m_iRows*(g_iRowsHight+2)+4); + ui->tableWidget->setGeometry(0, 2, tempWidth, tempHight); } } @@ -75,7 +86,7 @@ void FormHead::resizeEvent(QResizeEvent *event) resizeWindow(); } -void FormHead::Init(int iRows, int iCols, int iWidth) +void FormHead::Init(int iRows, int iCols) { m_iRows =iRows; m_iCols = iCols; @@ -93,6 +104,19 @@ void FormHead::Init(int iRows, int iCols, int iWidth) ui->tableWidget->setColumnCount(m_iCols);//列数 ui->tableWidget->setRowCount(m_iRows); //动态设置行数 +// for(int i=0; itableWidget->setVerticalHeaderItem(i, headerItem); +// } +// for(int j=0; jtableWidget->setHorizontalHeaderItem(j, headerItem); +// } + for(int i=0; itableWidget->setColumnWidth(j, g_iColsWidth); - QTableWidgetItem* item = new QTableWidgetItem(""); - ui->tableWidget->setItem(i, j, item); + double colWidth = g_iColsWidth-1; + double rowHeight = g_iRowsHight-1; + QTableWidgetItem* item = new QTableWidgetItem("");//QString::number(i) + "-" + QString::number(j) + // 将图片路径存储在Qt::UserRole+1角色中 + item->setData(Qt::UserRole+1, "./image/胜利符号库/解释结论符号/"); // 图片路径 + item->setData(Qt::UserRole+2, colWidth/g_dPixelPerCm); //图例宽 + item->setData(Qt::UserRole+3, rowHeight/g_dPixelPerCm); //图例高 + ui->tableWidget->setItem(i, j, item); + + //--------------------------- + QString imagePath = ""; //"./image/胜利符号库/解释结论符号/油层.svg" + QVariant bgData = item->data(Qt::UserRole+1); // 我们约定用这个角色存储图片路径 + if (bgData.isValid()) { + imagePath = bgData.toString(); + } + if(imagePath=="") + { + continue; + } + // + if(imagePath.size()>4) + { + // + QString strLast = imagePath.right(4); + if(strLast.toLower()==".svg") + { + QSvgRenderer* svgRender = new QSvgRenderer(); + svgRender->load(imagePath); + // + QPixmap* pixmap = new QPixmap(colWidth, rowHeight); + pixmap->fill(Qt::transparent);//设置背景透明 + QPainter p(pixmap); + svgRender->render(&p); + //1.直接采用控件显示 + QLabel* label = new QLabel; + label->setPixmap(*pixmap); + label->setAlignment(Qt::AlignHCenter); + label->show(); + ui->tableWidget->setCellWidget(i, j,label); + } + else if(strLast.toLower()==".png") + { + + } + } + } + } + //初始化完成后再连接信号槽,防止数据初始化时激活信号 + connect(ui->tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onItemChanged(QTableWidgetItem*))); + connect(ui->tableWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onItemSelectionChanged())); +} + +void FormHead::slotItemClicked(QTableWidgetItem* item) +{ + if (item) { + // 获取行和列索引 + int row = item->row(); + int column = item->column(); + if(row>=0 && column>=0) + { + PropertyService()->initHeadProperty(this, ui->tableWidget, item, row, column); + } + } +} + +void FormHead::onItemSelectionChanged() +{ + QTableWidgetItem* item = ui->tableWidget->currentItem(); + if (item) { + // 获取行和列索引 + int row = item->row(); + int column = item->column(); + if(row>=0 && column>=0) + { + PropertyService()->initHeadProperty(this, ui->tableWidget, item, row, column); + } + } +} + +void FormHead::onItemChanged(QTableWidgetItem* item) +{ + if(m_bRefresh==false) + { + //针对属性页修改了内容,避免重复刷新属性页 + m_bRefresh=true; + return; + } + + if (item) { + // 获取行和列索引 + int row = item->row(); + int column = item->column(); + if(row>=0 && column>=0) + { + PropertyService()->initHeadProperty(this, ui->tableWidget, item, row, column); } } } diff --git a/logPlus/formhead.h b/logPlus/formhead.h index ff0b298..1f412ea 100644 --- a/logPlus/formhead.h +++ b/logPlus/formhead.h @@ -35,12 +35,18 @@ public: int m_iRows; int m_iCols; + bool m_bRefresh=true; + public: - void Init(int iRows, int iCols, int iWidth); + void Init(int iRows, int iCols); void resizeEvent(QResizeEvent *event); public slots: void resizeWindow(); + // + void slotItemClicked(QTableWidgetItem* item); + void onItemChanged(QTableWidgetItem* item); + void onItemSelectionChanged(); //图头右键菜单响应函数 void slotContextMenu(QPoint pos); diff --git a/logPlus/forminfo.cpp b/logPlus/forminfo.cpp index b8cb363..71235f8 100644 --- a/logPlus/forminfo.cpp +++ b/logPlus/forminfo.cpp @@ -67,7 +67,14 @@ QJsonObject FormInfo::makeJson() // 创建根对象 QJsonObject rootObj; // - rootObj["SlfName"] = m_strSlfName; + QString slffilename=QString(""); + int ind=m_strSlfName.lastIndexOf('\\'); + int ind2=m_strSlfName.lastIndexOf('/'); + if(ind2>ind) ind=ind2; + if(ind>-1) { + slffilename=m_strSlfName.mid(ind+1); + } + rootObj["SlfName"] = slffilename; rootObj["WellName"] = m_strWellName; rootObj["TrackName"] = m_strTrackName; rootObj["LineName"] = m_strLineName; diff --git a/logPlus/formmultiheads.cpp b/logPlus/formmultiheads.cpp index 5c3b08d..d21f587 100644 --- a/logPlus/formmultiheads.cpp +++ b/logPlus/formmultiheads.cpp @@ -10,6 +10,8 @@ extern int g_iRows; extern int g_iCols; extern int g_iColsWidth; extern int g_iRowsHight; +extern int g_iFixedWidth; +extern int g_iFixedHeight; FormMultiHeads::FormMultiHeads(QWidget *parent) : QWidget(parent), @@ -29,8 +31,8 @@ FormMultiHeads::FormMultiHeads(QWidget *parent) : // //ui->tableWidget->verticalHeader()->hide(); //行 //ui->tableWidget->horizontalHeader()->hide(); //列 - ui->tableWidget->verticalHeader()->setFixedWidth(3);//标题栏宽度 - ui->tableWidget->horizontalHeader()->setFixedHeight(3);//标题栏高度 + ui->tableWidget->verticalHeader()->setFixedWidth(10);//标题栏宽度 + ui->tableWidget->horizontalHeader()->setFixedHeight(10);//标题栏高度 ui->tableWidget->setColumnCount(1); //动态设置列数 ui->tableWidget->horizontalHeader()->setStretchLastSection(true);//最后一列铺满最后 //标题 @@ -73,28 +75,27 @@ void FormMultiHeads::slotContextMenu(QPoint pos) QTableWidgetItem *headerItem = new QTableWidgetItem(""); ui->tableWidget->setVerticalHeaderItem(rowcount, headerItem); - int iWidth=0; + int tempWidth = g_iCols*g_iColsWidth+g_iFixedWidth+15; + int tempHight = g_iRows*g_iRowsHight+g_iFixedHeight+15; //设置行高度 - ui->tableWidget->setRowHeight(rowcount, g_iRows*(g_iRowsHight+2)+1); + ui->tableWidget->setRowHeight(rowcount, tempHight); if(rowcount==0) { - iWidth=g_iCols*g_iColsWidth; //设置列宽 - ui->tableWidget->setColumnWidth(0, g_iCols*(g_iColsWidth+1)+1); + ui->tableWidget->setColumnWidth(0, tempWidth); } else { - iWidth=ui->tableWidget->columnWidth(0); + int iWidth=ui->tableWidget->columnWidth(0); if(iWidthtableWidget->setColumnWidth(0, g_iCols*(g_iColsWidth+1)+1); + ui->tableWidget->setColumnWidth(0, tempWidth); } } // FormHead *widgetHead = new FormHead(this, 1); - widgetHead->Init(g_iRows, g_iCols, iWidth); + widgetHead->Init(g_iRows, g_iCols); ui->tableWidget->setCellWidget(rowcount, 0, widgetHead); } else if (result == QDialog::Rejected) { diff --git a/logPlus/formmultiheads.ui b/logPlus/formmultiheads.ui index 657b899..1e87391 100644 --- a/logPlus/formmultiheads.ui +++ b/logPlus/formmultiheads.ui @@ -15,13 +15,13 @@ - 18 + 9 9 - 18 + 9 0 diff --git a/logPlus/logPlus.pro b/logPlus/logPlus.pro index 4c09908..8945c32 100644 --- a/logPlus/logPlus.pro +++ b/logPlus/logPlus.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui +QT += core gui svg greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -33,6 +33,7 @@ SOURCES += \ InDefTableDlg.cpp \ InterfaceWidget.cpp \ PropertyWidget.cpp \ + backgrounddelegate.cpp \ customtabbar.cpp \ customtabwidget.cpp \ fileedit.cpp \ @@ -66,6 +67,7 @@ HEADERS += \ InterfaceWidget.h \ PropertyWidget.h \ TransparentDraggableRect.h \ + backgrounddelegate.h \ customtabbar.h \ customtabwidget.h \ fileedit.h \ diff --git a/logPlus/mainwindow.cpp b/logPlus/mainwindow.cpp index 0f2bad7..22dca27 100644 --- a/logPlus/mainwindow.cpp +++ b/logPlus/mainwindow.cpp @@ -456,7 +456,8 @@ void MainWindow::s_ShowCurve(QString strSlfName, QString strName) { WellLogTableDialogNew* pDialog = new WellLogTableDialogNew(); pDialog->setName(strSlfName, strName, CURVE_OBJECT); - QString wellname;QString path; + QString wellname; + QString path; GetWellNameAndPath(strSlfName, wellname, path); m_centerWidgets->addTab(pDialog, wellname + ":" + strName); int iCount = m_centerWidgets->count(); diff --git a/logPlus/mainwindowcurve.cpp b/logPlus/mainwindowcurve.cpp index f2c7df1..e822feb 100644 --- a/logPlus/mainwindowcurve.cpp +++ b/logPlus/mainwindowcurve.cpp @@ -1279,6 +1279,16 @@ void MainWindowCurve::DisplayLine_One(QJsonObject lineObjInfo) if (value.isString()) { strSlfName = value.toString(); //qDebug() << "SlfName:" << strSlfName; + + // + QString slffilename=QString(""); + int ind=strSlfName.lastIndexOf('\\'); + int ind2=strSlfName.lastIndexOf('/'); + if(ind2>ind) ind=ind2; + if(ind>-1) { + slffilename = strSlfName.mid(ind+1); + strSlfName = slffilename; + } } } if (lineObjInfo.contains("WellName")) @@ -1384,6 +1394,11 @@ void MainWindowCurve::DisplayLine_One(QJsonObject lineObjInfo) } } + + QString folderPath = GetLogdataPath(); + folderPath = folderPath + g_prjname; + strSlfName = folderPath + "/" + "#" + strWellName + "/" + strSlfName; + if(strLineName!="") { //新建曲线