图头支持拷贝图片粘贴到表格
This commit is contained in:
parent
c380f9006f
commit
ca21b8fda8
|
|
@ -403,6 +403,7 @@ void PropertyWidget::ChangHeadItemProperty()
|
||||||
label->setPixmap(*pixmap);
|
label->setPixmap(*pixmap);
|
||||||
label->setAlignment(Qt::AlignHCenter);
|
label->setAlignment(Qt::AlignHCenter);
|
||||||
label->show();
|
label->show();
|
||||||
|
//
|
||||||
m_formHead->m_bRefresh=false;
|
m_formHead->m_bRefresh=false;
|
||||||
m_tableWidget->setCellWidget(m_iRow, m_iCol, label);
|
m_tableWidget->setCellWidget(m_iRow, m_iCol, label);
|
||||||
|
|
||||||
|
|
@ -414,7 +415,17 @@ void PropertyWidget::ChangHeadItemProperty()
|
||||||
}
|
}
|
||||||
else if(strLast.toLower()==".png")
|
else if(strLast.toLower()==".png")
|
||||||
{
|
{
|
||||||
|
// 加载图片
|
||||||
|
QPixmap pixmap(imagePath);
|
||||||
|
//pixmap.scaled(colWidth-1, rowHeight-1, Qt::KeepAspectRatio, Qt::SmoothTransformation);//缩放
|
||||||
|
//1.直接采用控件显示
|
||||||
|
QLabel* label = new QLabel;
|
||||||
|
label->setPixmap(pixmap.scaled(colWidth-1, rowHeight-1, Qt::KeepAspectRatio, Qt::SmoothTransformation));//pixmap
|
||||||
|
label->setAlignment(Qt::AlignHCenter);
|
||||||
|
label->show();
|
||||||
|
//
|
||||||
|
m_formHead->m_bRefresh=false;
|
||||||
|
m_tableWidget->setCellWidget(m_iRow, m_iCol, label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,16 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QDateTime>
|
||||||
#include "backgrounddelegate.h"
|
#include "backgrounddelegate.h"
|
||||||
#include "PropertyWidget.h"
|
#include "PropertyWidget.h"
|
||||||
|
#include "geometryutils.h"
|
||||||
|
|
||||||
//extern int g_iRows;
|
//extern int g_iRows;
|
||||||
//extern int g_iCols;
|
//extern int g_iCols;
|
||||||
|
|
||||||
|
extern QString g_prjname;
|
||||||
|
|
||||||
int g_iFixedWidth=40;
|
int g_iFixedWidth=40;
|
||||||
int g_iFixedHeight=30;
|
int g_iFixedHeight=30;
|
||||||
|
|
||||||
|
|
@ -156,7 +160,7 @@ void FormHead::Init(int iRows, int iCols)
|
||||||
QSvgRenderer* svgRender = new QSvgRenderer();
|
QSvgRenderer* svgRender = new QSvgRenderer();
|
||||||
svgRender->load(imagePath);
|
svgRender->load(imagePath);
|
||||||
//
|
//
|
||||||
QPixmap* pixmap = new QPixmap(colWidth, rowHeight);
|
QPixmap* pixmap = new QPixmap(colWidth-1, rowHeight-1);
|
||||||
pixmap->fill(Qt::transparent);//设置背景透明
|
pixmap->fill(Qt::transparent);//设置背景透明
|
||||||
QPainter p(pixmap);
|
QPainter p(pixmap);
|
||||||
svgRender->render(&p);
|
svgRender->render(&p);
|
||||||
|
|
@ -169,7 +173,15 @@ void FormHead::Init(int iRows, int iCols)
|
||||||
}
|
}
|
||||||
else if(strLast.toLower()==".png")
|
else if(strLast.toLower()==".png")
|
||||||
{
|
{
|
||||||
|
// 加载图片
|
||||||
|
QPixmap pixmap(imagePath);
|
||||||
|
//pixmap.scaled(colWidth-1, rowHeight-1, Qt::KeepAspectRatio, Qt::SmoothTransformation);//缩放
|
||||||
|
//1.直接采用控件显示
|
||||||
|
QLabel* label = new QLabel;
|
||||||
|
label->setPixmap(pixmap.scaled(colWidth-1, rowHeight-1, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
|
label->setAlignment(Qt::AlignHCenter);
|
||||||
|
label->show();
|
||||||
|
ui->tableWidget->setCellWidget(i, j,label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -393,16 +405,6 @@ void FormHead::copy()
|
||||||
|
|
||||||
void FormHead::Paste()
|
void FormHead::Paste()
|
||||||
{
|
{
|
||||||
QString pastText = QApplication::clipboard()->text();
|
|
||||||
QStringList rowList = pastText.split("\n", QString::KeepEmptyParts);
|
|
||||||
if(rowList.size()==0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(rowList.at(rowList.size()-1)=="")
|
|
||||||
{
|
|
||||||
rowList.removeAt(rowList.size()-1);
|
|
||||||
}
|
|
||||||
QTableWidgetItem* crtItem = ui->tableWidget->currentItem();
|
QTableWidgetItem* crtItem = ui->tableWidget->currentItem();
|
||||||
int rowN, colN;
|
int rowN, colN;
|
||||||
if (!crtItem)
|
if (!crtItem)
|
||||||
|
|
@ -415,6 +417,61 @@ void FormHead::Paste()
|
||||||
rowN = ui->tableWidget->row(crtItem);
|
rowN = ui->tableWidget->row(crtItem);
|
||||||
colN = ui->tableWidget->column(crtItem);
|
colN = ui->tableWidget->column(crtItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool bImg=false;
|
||||||
|
QPixmap pixmap = QApplication::clipboard()->pixmap();
|
||||||
|
if(pixmap.isNull())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bImg=true;
|
||||||
|
|
||||||
|
//1.直接采用控件显示
|
||||||
|
QLabel* label = new QLabel;
|
||||||
|
label->setPixmap(pixmap);
|
||||||
|
label->setAlignment(Qt::AlignHCenter);
|
||||||
|
label->show();
|
||||||
|
ui->tableWidget->setCellWidget(rowN, colN, label);
|
||||||
|
|
||||||
|
// 保存为PNG文件
|
||||||
|
QString strImg = QDateTime::currentDateTime().toString("yyyyMMdd-hhmmsszzz");
|
||||||
|
//Logdata
|
||||||
|
QString folderPath;
|
||||||
|
folderPath = GetLogdataPath();
|
||||||
|
folderPath = folderPath + g_prjname;
|
||||||
|
folderPath = folderPath + "/" + strImg + ".png";
|
||||||
|
pixmap.save(folderPath, "PNG");
|
||||||
|
|
||||||
|
//
|
||||||
|
QTableWidgetItem* item = ui->tableWidget->item(rowN, colN);
|
||||||
|
// 将图片路径存储在Qt::UserRole+1角色中
|
||||||
|
item->setData(Qt::UserRole+1, folderPath); // 图片路径
|
||||||
|
item->setData(Qt::UserRole+2, pixmap.width()/g_dPixelPerCm); //图例宽
|
||||||
|
item->setData(Qt::UserRole+3, pixmap.height()/g_dPixelPerCm); //图例高
|
||||||
|
PropertyService()->initHeadProperty(this, ui->tableWidget, item, rowN, colN);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString pastText = QApplication::clipboard()->text();
|
||||||
|
QStringList rowList = pastText.split("\n", QString::KeepEmptyParts);
|
||||||
|
if(rowList.size()==0)
|
||||||
|
{
|
||||||
|
if(pixmap.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bImg=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(rowList.at(rowList.size()-1)=="")
|
||||||
|
{
|
||||||
|
rowList.removeAt(rowList.size()-1);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < (ui->tableWidget->rowCount() - rowN) && (i < rowList.length()); i++)
|
for (int i = 0; i < (ui->tableWidget->rowCount() - rowN) && (i < rowList.length()); i++)
|
||||||
{
|
{
|
||||||
QStringList rowDataList = rowList.at(i).split("\t", QString::KeepEmptyParts);
|
QStringList rowDataList = rowList.at(i).split("\t", QString::KeepEmptyParts);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "CallManage.h"
|
#include "CallManage.h"
|
||||||
|
|
||||||
|
extern int g_iOneWidth; //道宽
|
||||||
|
|
||||||
//曲线名称栏(表格)
|
//曲线名称栏(表格)
|
||||||
FormTrack::FormTrack(QWidget *parent, QString strWellName, QString strTrackName) :
|
FormTrack::FormTrack(QWidget *parent, QString strWellName, QString strTrackName) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
|
|
@ -82,6 +84,10 @@ void FormTrack::s_addLine(QString strSlfName, QString strWellName, QString strTr
|
||||||
int row = ui->tableWidget->rowCount();
|
int row = ui->tableWidget->rowCount();
|
||||||
ui->tableWidget->setRowCount(row + 1);
|
ui->tableWidget->setRowCount(row + 1);
|
||||||
|
|
||||||
|
//避免出现小滚动条
|
||||||
|
//ui->tableWidget->resize(g_iOneWidth, 100*(row + 1)+10);
|
||||||
|
//this->resize(g_iOneWidth, 100*(row + 1)+30);
|
||||||
|
|
||||||
//曲线信息栏
|
//曲线信息栏
|
||||||
FormInfo *formInfo = new FormInfo(this, strSlfName, strWellName, strTrackName, strLineName, lineColor);
|
FormInfo *formInfo = new FormInfo(this, strSlfName, strWellName, strTrackName, strLineName, lineColor);
|
||||||
formInfo->m_strUuid = m_strUuid;
|
formInfo->m_strUuid = m_strUuid;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ FormWell::FormWell(QWidget *parent, QString strWellName) :
|
||||||
//ui->tableWidget->horizontalHeader()->hide();//列
|
//ui->tableWidget->horizontalHeader()->hide();//列
|
||||||
int rowcount = 3; //总行数
|
int rowcount = 3; //总行数
|
||||||
ui->tableWidget->setRowCount(rowcount); //动态设置行数
|
ui->tableWidget->setRowCount(rowcount); //动态设置行数
|
||||||
|
//ui->tableWidget->verticalHeader()->setFixedWidth(3);//标题栏宽度
|
||||||
ui->tableWidget->horizontalHeader()->setFixedHeight(3);
|
ui->tableWidget->horizontalHeader()->setFixedHeight(3);
|
||||||
|
|
||||||
//关联信号槽
|
//关联信号槽
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ MainWindowCurve::MainWindowCurve(QWidget *parent) :
|
||||||
//ui->tableWidget_2->horizontalHeader()->hide();//列
|
//ui->tableWidget_2->horizontalHeader()->hide();//列
|
||||||
int rowcount = 2; //总行数
|
int rowcount = 2; //总行数
|
||||||
ui->tableWidget_2->setRowCount(rowcount); //动态设置行数
|
ui->tableWidget_2->setRowCount(rowcount); //动态设置行数
|
||||||
|
//ui->tableWidget_2->verticalHeader()->setFixedWidth(3);//标题栏宽度
|
||||||
ui->tableWidget_2->horizontalHeader()->setFixedHeight(3);//标题栏高度
|
ui->tableWidget_2->horizontalHeader()->setFixedHeight(3);//标题栏高度
|
||||||
//我们让一列也可以滑动
|
//我们让一列也可以滑动
|
||||||
ui->tableWidget_2->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
ui->tableWidget_2->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user