1.图头右键菜单功能完善,追加新增、删除行列等功能。2.优化json文件加载速度
This commit is contained in:
parent
2e55985bc8
commit
c6f9e47e74
|
|
@ -80,7 +80,7 @@ FormHead::~FormHead()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void FormHead::resizeWindow()
|
||||
void FormHead::resizeWindow(bool bDelete)
|
||||
{
|
||||
QRect rect = this->rect();
|
||||
int tempWidth = 0; //m_iCols*(g_iColsWidth+1)+g_iFixedWidth;
|
||||
|
|
@ -108,7 +108,7 @@ void FormHead::resizeWindow()
|
|||
ui->tableWidget->setGeometry(0, 2, tempWidth, tempHight);
|
||||
}
|
||||
|
||||
m_parent->resizeItem(m_indexID, tempWidth, tempHight);
|
||||
m_parent->resizeItem(m_indexID, tempWidth, tempHight, bDelete);
|
||||
}
|
||||
|
||||
void FormHead::resizeEvent(QResizeEvent *event)
|
||||
|
|
@ -177,51 +177,6 @@ void FormHead::Init(int iRows, int iCols)
|
|||
//item->setData(Qt::UserRole, QVariant("vertical"));
|
||||
//
|
||||
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-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();
|
||||
ui->tableWidget->setCellWidget(i, j,label);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -671,25 +626,19 @@ void FormHead::onItemChanged(QTableWidgetItem* item)
|
|||
void FormHead::slotContextMenu(QPoint pos)
|
||||
{
|
||||
QMenu menu(ui->tableWidget);
|
||||
QAction *mergeAction = menu.addAction("合并表格");
|
||||
QAction *refreshAction = menu.addAction("拆分表格");
|
||||
QAction *deleteAction = menu.addAction("删除行");
|
||||
QAction *addAction = menu.addAction("添加行");
|
||||
|
||||
// 弹出菜单
|
||||
QAction *selectedAction = menu.exec(ui->tableWidget->mapToGlobal(pos));
|
||||
|
||||
if (selectedAction == mergeAction) {
|
||||
qDebug() << "合并表格";
|
||||
slotMerge();
|
||||
} else if (selectedAction == deleteAction) {
|
||||
//删除1行
|
||||
int row = ui->tableWidget->currentRow();
|
||||
ui->tableWidget->removeRow(row);
|
||||
} else if (selectedAction == refreshAction) {
|
||||
qDebug() << "拆分表格";
|
||||
slotSplit();
|
||||
}
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/MergeCell.png"), "合并单元格", this, &FormHead::slotMerge);
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/Grid.png"), "拆分单元格", this, &FormHead::slotSplit);
|
||||
menu.addSeparator();
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/AddRow.png"), "前插入行", this, &FormHead::slotAddRow);
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/AddRow.png"), "后插入行", this, &FormHead::slotAddAfterRow);
|
||||
menu.addSeparator();
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/AddColumn.png"), "前插入列", this, &FormHead::slotAddCol);
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/AddColumn.png"), "后插入列", this, &FormHead::slotAddAfterCol);
|
||||
menu.addSeparator();
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/DelRow.png"), "删除行", this, &FormHead::slotDeleteRow);
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/DelColumn.png"), "删除列", this, &FormHead::slotDeleteCol);
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/DeleteTable.png"), "删除表", this, &FormHead::slotDeleteTable);
|
||||
menu.exec(ui->tableWidget->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
//合并
|
||||
|
|
@ -764,6 +713,189 @@ void FormHead::slotSplit()
|
|||
ui->tableWidget->setSpan(row, col, 1, 1); // 设置跨度为1
|
||||
}
|
||||
|
||||
//前插入行
|
||||
void FormHead::slotAddRow()
|
||||
{
|
||||
int row = ui->tableWidget->currentRow();
|
||||
ui->tableWidget->insertRow(row);
|
||||
|
||||
//新插入行,单元格初始化
|
||||
int iCols = ui->tableWidget->columnCount();
|
||||
for(int j=0; j<iCols; j++)
|
||||
{
|
||||
QTableWidgetItem* item = new QTableWidgetItem("");
|
||||
// 将图片路径存储在Qt::UserRole+1角色中
|
||||
item->setData(Qt::UserRole+1, ""); //图片路径 ./image/胜利符号库/解释结论符号/
|
||||
item->setData(Qt::UserRole+2, 0); //图例宽
|
||||
item->setData(Qt::UserRole+3, 0); //图例高
|
||||
|
||||
// 设置背景色
|
||||
QColor color(255, 255, 255, 255);
|
||||
QBrush HeadBrush = QBrush(color);
|
||||
HeadBrush.setStyle(Qt::SolidPattern);
|
||||
item->setBackground(HeadBrush);
|
||||
item->setData(Qt::BackgroundRole, color); // 双重保险
|
||||
// 设置字体颜色
|
||||
QColor colorTxt(0, 0, 0, 255);
|
||||
item->setForeground(QBrush(colorTxt));
|
||||
//item->setData(Qt::UserRole, QVariant("vertical"));
|
||||
//
|
||||
ui->tableWidget->setItem(row, j, item);
|
||||
}
|
||||
|
||||
//改变大小
|
||||
resizeWindow();
|
||||
}
|
||||
|
||||
//后插入行
|
||||
void FormHead::slotAddAfterRow()
|
||||
{
|
||||
int row = ui->tableWidget->currentRow();
|
||||
ui->tableWidget->insertRow(row+1);
|
||||
|
||||
//新插入行,单元格初始化
|
||||
int iCols = ui->tableWidget->columnCount();
|
||||
for(int j=0; j<iCols; j++)
|
||||
{
|
||||
QTableWidgetItem* item = new QTableWidgetItem("");
|
||||
// 将图片路径存储在Qt::UserRole+1角色中
|
||||
item->setData(Qt::UserRole+1, ""); //图片路径 ./image/胜利符号库/解释结论符号/
|
||||
item->setData(Qt::UserRole+2, 0); //图例宽
|
||||
item->setData(Qt::UserRole+3, 0); //图例高
|
||||
|
||||
// 设置背景色
|
||||
QColor color(255, 255, 255, 255);
|
||||
QBrush HeadBrush = QBrush(color);
|
||||
HeadBrush.setStyle(Qt::SolidPattern);
|
||||
item->setBackground(HeadBrush);
|
||||
item->setData(Qt::BackgroundRole, color); // 双重保险
|
||||
// 设置字体颜色
|
||||
QColor colorTxt(0, 0, 0, 255);
|
||||
item->setForeground(QBrush(colorTxt));
|
||||
//item->setData(Qt::UserRole, QVariant("vertical"));
|
||||
//
|
||||
ui->tableWidget->setItem(row+1, j, item);
|
||||
}
|
||||
|
||||
//改变大小
|
||||
resizeWindow();
|
||||
}
|
||||
|
||||
//前插入列
|
||||
void FormHead::slotAddCol()
|
||||
{
|
||||
int col = ui->tableWidget->currentColumn();
|
||||
ui->tableWidget->insertColumn(col);
|
||||
|
||||
//新插入行,单元格初始化
|
||||
int iRows = ui->tableWidget->rowCount();
|
||||
for(int j=0; j<iRows; j++)
|
||||
{
|
||||
QTableWidgetItem* item = new QTableWidgetItem("");
|
||||
// 将图片路径存储在Qt::UserRole+1角色中
|
||||
item->setData(Qt::UserRole+1, ""); //图片路径 ./image/胜利符号库/解释结论符号/
|
||||
item->setData(Qt::UserRole+2, 0); //图例宽
|
||||
item->setData(Qt::UserRole+3, 0); //图例高
|
||||
|
||||
// 设置背景色
|
||||
QColor color(255, 255, 255, 255);
|
||||
QBrush HeadBrush = QBrush(color);
|
||||
HeadBrush.setStyle(Qt::SolidPattern);
|
||||
item->setBackground(HeadBrush);
|
||||
item->setData(Qt::BackgroundRole, color); // 双重保险
|
||||
// 设置字体颜色
|
||||
QColor colorTxt(0, 0, 0, 255);
|
||||
item->setForeground(QBrush(colorTxt));
|
||||
//item->setData(Qt::UserRole, QVariant("vertical"));
|
||||
//
|
||||
ui->tableWidget->setItem(j, col, item);
|
||||
}
|
||||
|
||||
//改变大小
|
||||
resizeWindow();
|
||||
}
|
||||
|
||||
//后插入列
|
||||
void FormHead::slotAddAfterCol()
|
||||
{
|
||||
int col = ui->tableWidget->currentColumn();
|
||||
ui->tableWidget->insertColumn(col+1);
|
||||
|
||||
//新插入行,单元格初始化
|
||||
int iRows = ui->tableWidget->rowCount();
|
||||
for(int j=0; j<iRows; j++)
|
||||
{
|
||||
QTableWidgetItem* item = new QTableWidgetItem("");
|
||||
// 将图片路径存储在Qt::UserRole+1角色中
|
||||
item->setData(Qt::UserRole+1, ""); //图片路径 ./image/胜利符号库/解释结论符号/
|
||||
item->setData(Qt::UserRole+2, 0); //图例宽
|
||||
item->setData(Qt::UserRole+3, 0); //图例高
|
||||
|
||||
// 设置背景色
|
||||
QColor color(255, 255, 255, 255);
|
||||
QBrush HeadBrush = QBrush(color);
|
||||
HeadBrush.setStyle(Qt::SolidPattern);
|
||||
item->setBackground(HeadBrush);
|
||||
item->setData(Qt::BackgroundRole, color); // 双重保险
|
||||
// 设置字体颜色
|
||||
QColor colorTxt(0, 0, 0, 255);
|
||||
item->setForeground(QBrush(colorTxt));
|
||||
//item->setData(Qt::UserRole, QVariant("vertical"));
|
||||
//
|
||||
ui->tableWidget->setItem(j, col+1, item);
|
||||
}
|
||||
|
||||
//改变大小
|
||||
resizeWindow();
|
||||
}
|
||||
|
||||
//删除行
|
||||
void FormHead::slotDeleteRow()
|
||||
{
|
||||
//删除1行
|
||||
int row = ui->tableWidget->currentRow();
|
||||
ui->tableWidget->removeRow(row);
|
||||
|
||||
int rowCount = ui->tableWidget->rowCount();
|
||||
if(rowCount==0)
|
||||
{
|
||||
//改变大小,并删除父窗口的对应行
|
||||
resizeWindow(true);
|
||||
}
|
||||
else {
|
||||
//改变大小
|
||||
resizeWindow(false);
|
||||
}
|
||||
}
|
||||
|
||||
//删除列
|
||||
void FormHead::slotDeleteCol()
|
||||
{
|
||||
//删除1列
|
||||
int col = ui->tableWidget->currentColumn();
|
||||
ui->tableWidget->removeColumn(col);
|
||||
|
||||
int colCount = ui->tableWidget->columnCount();
|
||||
if(colCount==0)
|
||||
{
|
||||
//改变大小,并删除父窗口的对应行
|
||||
resizeWindow(true);
|
||||
}
|
||||
else {
|
||||
//改变大小
|
||||
resizeWindow(false);
|
||||
}
|
||||
}
|
||||
|
||||
//删除表
|
||||
void FormHead::slotDeleteTable()
|
||||
{
|
||||
//删除
|
||||
ui->tableWidget->clear();
|
||||
//改变大小,并删除父窗口的对应行
|
||||
resizeWindow(true);
|
||||
}
|
||||
|
||||
bool FormHead::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
if (obj == ui->tableWidget && event->type() == QEvent::KeyPress) {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public:
|
|||
QJsonObject makeJson();
|
||||
|
||||
public slots:
|
||||
void resizeWindow();
|
||||
void resizeWindow(bool bDelete=false);
|
||||
//
|
||||
void slotItemClicked(QTableWidgetItem* item);
|
||||
void onItemChanged(QTableWidgetItem* item);
|
||||
|
|
@ -65,6 +65,17 @@ public slots:
|
|||
void slotContextMenu(QPoint pos);
|
||||
void slotMerge();//合并
|
||||
void slotSplit();//拆分
|
||||
//
|
||||
void slotAddRow();//前插入行
|
||||
void slotAddAfterRow();//后插入行
|
||||
//
|
||||
void slotAddCol();//前插入列
|
||||
void slotAddAfterCol();//后插入列
|
||||
//
|
||||
void slotDeleteRow();//删除行
|
||||
void slotDeleteCol();//删除列
|
||||
void slotDeleteTable();//删除表
|
||||
|
||||
//图头
|
||||
void copy();
|
||||
void Paste();
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ void FormMultiHeads::AddHead()
|
|||
ui->tableWidget->setCellWidget(rowcount, 0, widgetHead);
|
||||
}
|
||||
|
||||
void FormMultiHeads::resizeItem(QString indexID, double colWidth, double rowHight)
|
||||
void FormMultiHeads::resizeItem(QString indexID, double colWidth, double rowHight, bool bDelete)
|
||||
{
|
||||
//
|
||||
int rowCount = ui->tableWidget->rowCount();//总行数
|
||||
|
|
@ -150,6 +150,12 @@ void FormMultiHeads::resizeItem(QString indexID, double colWidth, double rowHigh
|
|||
{
|
||||
if(widgetHead->m_indexID == indexID)
|
||||
{
|
||||
if(bDelete)
|
||||
{
|
||||
//删除1行
|
||||
ui->tableWidget->removeRow(i);
|
||||
}
|
||||
else {
|
||||
//设置行高度
|
||||
ui->tableWidget->setRowHeight(i, rowHight+8);
|
||||
|
||||
|
|
@ -159,6 +165,8 @@ void FormMultiHeads::resizeItem(QString indexID, double colWidth, double rowHigh
|
|||
//设置列宽
|
||||
ui->tableWidget->setColumnWidth(0, colWidth+8);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public slots:
|
|||
|
||||
public:
|
||||
void AddHead();
|
||||
void resizeItem(QString indexID, double tempWidth, double tempHight);
|
||||
void resizeItem(QString indexID, double tempWidth, double tempHight, bool bDelete=false);
|
||||
QJsonArray makeJsonArray();
|
||||
|
||||
//展示所有图头/成果表
|
||||
|
|
|
|||
|
|
@ -2311,6 +2311,19 @@ void MainWindowCurve::s_showHeadTable()
|
|||
m_dock2->hide();
|
||||
}
|
||||
else {
|
||||
//第一次显示,判断是否从json加载
|
||||
if(m_bHeadLoadJson)
|
||||
{
|
||||
m_bHeadLoadJson = false;
|
||||
|
||||
QString strHeadOrTail = ""; //Head代表图头, Tail代表成果表
|
||||
//展示所有图头
|
||||
strHeadOrTail = "Head"; //Head代表图头, Tail代表成果表
|
||||
m_formMultiHeads->DisplayHeads(m_headsArray, strHeadOrTail);
|
||||
//展示所有成果表
|
||||
strHeadOrTail = "Tail"; //Head代表图头, Tail代表成果表
|
||||
m_formMultiTails->DisplayHeads(m_tailsArray, strHeadOrTail);
|
||||
}
|
||||
m_dock1->show();
|
||||
m_dock2->show();
|
||||
}
|
||||
|
|
@ -3316,8 +3329,9 @@ void MainWindowCurve::Open(QString fileFull)
|
|||
{
|
||||
QString strPrjname = "";
|
||||
QJsonArray wellsArray;
|
||||
QJsonArray headsArray;
|
||||
QJsonArray tailsArray;
|
||||
//清空
|
||||
m_headsArray.empty();
|
||||
m_tailsArray.empty();
|
||||
|
||||
QJsonParseError jsonError;
|
||||
// 文件
|
||||
|
|
@ -3392,27 +3406,26 @@ void MainWindowCurve::Open(QString fileFull)
|
|||
}
|
||||
}
|
||||
//
|
||||
QString strHeadOrTail = ""; //Head代表图头, Tail代表成果表
|
||||
if (object.contains("heads"))
|
||||
{
|
||||
//true代表从json加载图头、结果表
|
||||
m_bHeadLoadJson = true;
|
||||
|
||||
QJsonValue value = object.value("heads");
|
||||
if (value.isArray()) {
|
||||
headsArray = value.toArray();
|
||||
qDebug() << "headsArray number:" << QString::number(headsArray.size());
|
||||
//展示所有图头
|
||||
strHeadOrTail = "Head"; //Head代表图头, Tail代表成果表
|
||||
m_formMultiHeads->DisplayHeads(headsArray, strHeadOrTail);
|
||||
m_headsArray = value.toArray();
|
||||
qDebug() << "headsArray number:" << QString::number(m_headsArray.size());
|
||||
}
|
||||
}
|
||||
if (object.contains("tails"))
|
||||
{
|
||||
//true代表从json加载图头、结果表
|
||||
m_bHeadLoadJson = true;
|
||||
|
||||
QJsonValue value = object.value("tails");
|
||||
if (value.isArray()) {
|
||||
tailsArray = value.toArray();
|
||||
qDebug() << "tailsArray number:" << QString::number(tailsArray.size());
|
||||
//展示所有图头
|
||||
strHeadOrTail = "Tail"; //Head代表图头, Tail代表成果表
|
||||
m_formMultiTails->DisplayHeads(tailsArray, strHeadOrTail);
|
||||
m_tailsArray = value.toArray();
|
||||
qDebug() << "tailsArray number:" << QString::number(m_tailsArray.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,10 @@ public:
|
|||
void initToolBar();
|
||||
void initToolBar_2();
|
||||
void initToolBar_3();
|
||||
bool m_bMerge = false;//是否拼接状态,否代表校深状态。为了切换时做数据清理
|
||||
bool m_bMerge = false;//true代表拼接状态,false代表校深状态。为了切换时做数据清理
|
||||
bool m_bHeadLoadJson = false;//true代表从json加载图头、结果表。false不加载
|
||||
QJsonArray m_headsArray;
|
||||
QJsonArray m_tailsArray;
|
||||
|
||||
// 返回 strWellName << strSlfName
|
||||
QStringList insertCol(int nW);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user