#include "mainwindowcurve.h" #include "ui_mainwindowcurve.h" #include #include #include "CallManage.h" #include #include "qtcommonclass.h" #include #include #include "newheaddialog.h" #include "formhead.h" //#include "qmytablewidget.h" extern int g_iOneWidth; //道宽 extern QString g_prjname; // extern int g_iY1; extern int g_iY2; extern double g_dPixelPerCm;//每厘米像素数 extern int g_iScale; extern int g_iRows; extern int g_iCols; extern int g_iColsWidth; extern int g_iRowsHight; MainWindowCurve::MainWindowCurve(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindowCurve) { ui->setupUi(this); QtCommonClass *qtCommon = new QtCommonClass(this); m_strUuid = qtCommon->getUUid(); // 设置工具栏的位置,此处设置为在左侧 addToolBar(Qt::LeftToolBarArea, ui->toolBar); //初始化工具栏 initMainToolBar(); initToolBar(); //加载样式 loadStyle(":/qrc/qss/flatgray.css"); //------------------------------------- ui->tableWidget->hide(); // //隐藏网格线 // ui->tableWidget->setShowGrid(false); // //设置样式表,不显示竖直边框 // ui->tableWidget->setStyleSheet( "QTableView::item {border-left: 0px solid black;} \ // QTableView::item:selected {border-left: 0px solid black;}\ // QTableView::item {border-right: 0px solid black;} \ // QTableView::item:selected {border-right: 0px solid black;}"); // // // ui->tableWidget->verticalHeader()->hide(); //行 // ui->tableWidget->horizontalHeader()->hide(); //列 // //ui->tableWidget->verticalHeader()->setFixedWidth(3);//标题栏宽度 // //ui->tableWidget->horizontalHeader()->setFixedHeight(3);//标题栏高度 // ui->tableWidget->setColumnCount(1); //动态设置列数 // ui->tableWidget->horizontalHeader()->setStretchLastSection(true);//最后一列铺满最后 // //标题 // QTableWidgetItem *headerItem = new QTableWidgetItem(""); // ui->tableWidget->setHorizontalHeaderItem(0, headerItem); // //我们让一列也可以滑动 // ui->tableWidget->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); // 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_2->setFrameShape(QFrame::NoFrame); //设置无边框 //隐藏网格线 ui->tableWidget_2->setShowGrid(false); //设置样式表,只显示竖直边框 ui->tableWidget_2->setStyleSheet( "QTableView::item {border-left: 1px solid black;} \ QTableView::item:selected {border-left: 1px solid black;}\ QTableView::item {border-right: 1px solid black;} \ QTableView::item:selected {border-right: 1px solid black;}"); ui->tableWidget_2->verticalHeader()->hide(); //行 //ui->tableWidget_2->horizontalHeader()->hide();//列 int rowcount = 2; //总行数 ui->tableWidget_2->setRowCount(rowcount); //动态设置行数 //ui->tableWidget_2->verticalHeader()->setFixedWidth(3);//标题栏宽度 ui->tableWidget_2->horizontalHeader()->setFixedHeight(3);//标题栏高度 //我们让一列也可以滑动 ui->tableWidget_2->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); ui->tableWidget_2->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); //------------------------------------- ui->tableWidget_3->hide(); ui->tableWidget_3->verticalHeader()->hide(); ui->tableWidget_3->horizontalHeader()->hide(); connect(this, SIGNAL(sig_NewTrackChangeWidth(QString)), this, SLOT(s_NewTrackChangeWidth(QString))); connect(this, SIGNAL(sig_NewWell(QString)), this, SLOT(s_NewWell(QString))); connect(CallManage::getInstance(), SIGNAL(sig_mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*))); //数据组织与管理树 m_dock1=new QDockWidget(tr(""),this); m_dock1->setFeatures(QDockWidget::NoDockWidgetFeatures);//QDockWidget::DockWidgetMovable //dock1->setAllowedAreas(Qt::TopDockWidgetArea); // m_formMultiHeads = new FormMultiHeads(this); m_dock1->setWidget(m_formMultiHeads); addDockWidget(Qt::TopDockWidgetArea,m_dock1); //移除标题栏 QWidget* lTitleBar = m_dock1->titleBarWidget(); QWidget* lEmptyWidget = new QWidget(); m_dock1->setTitleBarWidget(lEmptyWidget); delete lTitleBar; //属性编辑器 // m_propertyWidget = PropertyService(); // m_propertyWidget->setWindowTitle("属性编辑器"); // m_propertyWidget->setParent(this); // addDockWidget( Qt::TopDockWidgetArea, m_propertyWidget); } MainWindowCurve::~MainWindowCurve() { delete ui; } //鼠标滚动,通知可视解释窗口 void MainWindowCurve::s_mouseWheel(QWheelEvent *event) { if (event->angleDelta().y() > 0) { ui->tableWidget_2->verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepSub); // 向下滚动 } else { ui->tableWidget_2->verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepAdd); // 向上滚动 } //verticalScrollBar() horizontalScrollBar() //event->accept(); // 确保事件被处理 } //初始化工具栏 void MainWindowCurve::initMainToolBar() { QSize toolIconSize(18, 18); ui->mainToolBar->setIconSize(toolIconSize); //设置工具栏图标大小 QIcon newFileIcon(":/image/new.png"); QIcon openFileIcon(":/image/open.png"); QIcon compileIcon(":/image/compile.png"); QIcon runIcon(":/image/capacity.png"); QIcon debugIcon(":/image/anaysis.png"); QIcon grepIcon(":/image/grab.png"); QIcon loadIcon(":/image/export.png"); //Main工具栏 QAction* m_saveAc = nullptr; //保存 //QAction* m_openAc = nullptr; //打开 QAction* m_compileAc = nullptr; // QAction* m_runAc = nullptr;// QAction* m_debugAc = nullptr; // QAction* m_grepAc = nullptr; // QAction* m_loadAc = nullptr; //加载 m_saveAc = new QAction(newFileIcon, "保存", this); //m_openAc = new QAction(openFileIcon, "打开", this); m_grepAc = new QAction(grepIcon, "图头", this); m_compileAc = new QAction(compileIcon, "加载图文件", this); m_runAc = new QAction(runIcon, "设置井", this); m_debugAc = new QAction(debugIcon, "撤销", this); m_loadAc = new QAction(loadIcon, "重做", this); ui->mainToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); //此种方式为文字显示在图标右侧 //add QAction to Widget. ui->mainToolBar->addAction(m_saveAc); //ui->mainToolBar->addAction(m_openAc); ui->mainToolBar->addAction(m_grepAc); ui->mainToolBar->addAction(m_compileAc); ui->mainToolBar->addAction(m_runAc); ui->mainToolBar->addAction(m_debugAc); ui->mainToolBar->addAction(m_loadAc); connect(m_saveAc, &QAction::triggered, this, &MainWindowCurve::s_Save); //connect(m_openAc, &QAction::triggered, this, &MainWindowCurve::s_Open); connect(m_grepAc, &QAction::triggered, this, &MainWindowCurve::s_showHeadTable); // connect(m_grepAc, &QAction::triggered, this, &MainWindow::s_Risize); // connect(m_compileAc, &QAction::triggered, this, &MainWindow::s_AddOne); // connect(m_runAc, &QAction::triggered, this, &MainWindow::s_SaveImage); // connect(m_debugAc, &QAction::triggered, this, &MainWindow::s_DrawImg); // connect(m_loadAc, &QAction::triggered, this, &MainWindow::s_DrawLine); } //初始化工具栏 void MainWindowCurve::initToolBar() { QSize toolIconSize(18, 18); ui->toolBar->setIconSize(toolIconSize); //设置工具栏图标大小 QIcon newFileIcon(":/image/new.png"); QIcon openFileIcon(":/image/open.png"); QIcon compileIcon(":/image/compile.png"); QIcon runIcon(":/image/capacity.png"); QIcon debugIcon(":/image/anaysis.png"); QIcon grepIcon(":/image/grab.png"); QIcon loadIcon(":/image/export.png"); //工具栏 QAction* m_newAc2 = nullptr; //新建 QAction* m_openAc2 = nullptr; //打开 QAction* m_compileAc2 = nullptr; // QAction* m_runAc2 = nullptr;// QAction* m_debugAc2 = nullptr; // QAction* m_grepAc2 = nullptr; // QAction* m_loadAc2 = nullptr; //加载 m_newAc2 = new QAction(newFileIcon, "", this); m_openAc2 = new QAction(openFileIcon, "", this); m_grepAc2 = new QAction(grepIcon, "", this); m_compileAc2 = new QAction(compileIcon, "", this); m_runAc2 = new QAction(runIcon, "", this); m_debugAc2 = new QAction(debugIcon, "", this); m_loadAc2 = new QAction(loadIcon, "", this); m_newAc2->setToolTip("井"); m_openAc2->setToolTip("道"); m_grepAc2->setToolTip("曲线"); m_compileAc2->setToolTip("波列"); m_runAc2->setToolTip("解释结论道"); m_debugAc2->setToolTip("固井结论道"); m_loadAc2->setToolTip("井壁取心"); ui->toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly); //此种方式为文字显示在图标右侧 //add QAction to Widget. ui->toolBar->addAction(m_newAc2); ui->toolBar->addAction(m_openAc2); ui->toolBar->addAction(m_grepAc2); ui->toolBar->addAction(m_compileAc2); ui->toolBar->addAction(m_runAc2); ui->toolBar->addAction(m_debugAc2); ui->toolBar->addAction(m_loadAc2); //connect(m_newAc2, &QAction::triggered, this, &MainWindowCurve::s_NewWell); connect(m_openAc2, &QAction::triggered, this, &MainWindowCurve::s_NewTrack); // connect(m_compileAc, &QAction::triggered, this, &MainWindow::s_AddOne); // connect(m_runAc, &QAction::triggered, this, &MainWindow::s_SaveImage); // connect(m_debugAc, &QAction::triggered, this, &MainWindow::s_DrawImg); // connect(m_loadAc, &QAction::triggered, this, &MainWindow::s_DrawLine); } void MainWindowCurve::loadStyle(const QString &qssFile) { //加载样式表 QString qss; QFile file(qssFile); if (file.open(QFile::ReadOnly)) { //用QTextStream读取样式文件不用区分文件编码 带bom也行 QStringList list; QTextStream in(&file); //in.setCodec("utf-8"); while (!in.atEnd()) { QString line; in >> line; list << line; } file.close(); qss = list.join("\n"); QString paletteColor = qss.mid(20, 7); this->setPalette(QPalette(paletteColor)); //用时主要在下面这句 this->setStyleSheet(qss); } } void MainWindowCurve::s_Save() { //Logdata QString folderPath; folderPath = GetLogdataPath(); folderPath = folderPath + g_prjname; //folderPath = folderPath + "/multiwell.json"; QString exPortPath = QFileDialog::getSaveFileName(this, "另存为", folderPath, "多井图文件(*.json)"); if (exPortPath.isEmpty() == false) { QJsonObject rootObj = makeJson(); // 生成JSON文档 QJsonDocument doc(rootObj); // 写入文件 QFile file(exPortPath); if(file.open(QIODevice::WriteOnly)){ file.write(doc.toJson(QJsonDocument::Indented)); file.close(); qDebug() << "JSON文件写入成功!"; } else { qWarning() << "文件打开失败:" << file.errorString(); return; } } } //void MainWindowCurve::s_Open(QString fileFull) //{ //} //显示/隐藏图头 void MainWindowCurve::s_showHeadTable() { if(m_dock1->isVisible()) { m_dock1->hide(); } else { m_dock1->show(); } // if(ui->tableWidget->isVisible()) // { // ui->tableWidget->hide(); // } // else { // ui->tableWidget->show(); // } // QTableWidget *tableWidget = new QTableWidget(); // tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); // tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); // tableWidget->setRowCount(5); // tableWidget->setColumnCount(5); // for(int i=0; i<5; i++) // { // //tableWidget->setColumnWidth(i, 100); // for(int j=0; j<5; j++) // { // QTableWidgetItem* item = new QTableWidgetItem(""); // tableWidget->setItem(i, j, item); // } // } //// QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); // 首选大小策略 //// sizePolicy.setHorizontalStretch(0); // 水平拉伸因子 //// sizePolicy.setVerticalStretch(0); // 垂直拉伸因子 //// tableWidget->setSizePolicy(sizePolicy); // ui->verticalLayout_head->addWidget(tableWidget, 0, Qt::AlignCenter); // 通过布局添加表格 } QJsonObject MainWindowCurve::makeJson() { // 创建根对象 QJsonObject rootObj; // rootObj["prjname"] = g_prjname; // 创建JSON数组并填充数据 QJsonArray subcaseArray; // int columnCount = ui->tableWidget_2->columnCount();//总列数 for(int i=0; itableWidget_2->cellWidget(1, i) != nullptr ) { auto myWidget = ui->tableWidget_2->cellWidget(1, i); // FormWell *widgetWell = (FormWell*)myWidget;//获得widget if(widgetWell) { //options QJsonObject wellObj; wellObj["id"] = i; wellObj["info"] = widgetWell->makeJson(); subcaseArray.append(wellObj); } } } rootObj["wells"]=subcaseArray; return rootObj; } void MainWindowCurve::s_NewWell(QString strWellName) { //因为tableWidget需要提前规定好行数与列数 int rowcount = 2; //总行数 int columnCount = ui->tableWidget_2->columnCount();//总列数 if(columnCount==0) { //增加1列 ui->tableWidget_2->setColumnCount(columnCount+1); } else { //增加1列(空白) ui->tableWidget_2->setColumnCount(columnCount+1); //设置列宽 ui->tableWidget_2->setColumnWidth(columnCount, g_iOneWidth); // columnCount = ui->tableWidget_2->columnCount();//总列数 //增加1列 ui->tableWidget_2->setColumnCount(columnCount+1); } //设置列宽 ui->tableWidget_2->setColumnWidth(columnCount, g_iOneWidth); //标题 QTableWidgetItem *headerItem = new QTableWidgetItem(""); ui->tableWidget_2->setHorizontalHeaderItem(columnCount, headerItem); for(int i=0; itableWidget_2->setRowHeight(i, 100); // QTableWidgetItem* item = new QTableWidgetItem(strWellName); item->setFlags(item->flags() & (~Qt::ItemIsEditable)); item->setTextAlignment(Qt::AlignCenter); //设置文本居中 ui->tableWidget_2->setItem(i, columnCount, item); } else { double dHight = 0; dHight = (g_iY2-g_iY1)*100.0/(double)g_iScale * g_dPixelPerCm; if(dHight>32767) { dHight = 32767; } dHight = dHight+300+100+10; //设置高度 ui->tableWidget_2->setRowHeight(i, (int)dHight);//8020 // FormWell *widgetWell = new FormWell(this, strWellName); widgetWell->m_strUuid = m_strUuid; ui->tableWidget_2->setCellWidget(i, columnCount, widgetWell); // m_listWell.push_back(strWellName); } } //ui->tableWidget_2->resizeColumnsToContents(); // 调整列宽以适应内容 // 设置右键菜单策略 // ui->tableWidget_2->setContextMenuPolicy(Qt::CustomContextMenu); // connect(ui->tableWidget_2, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextMenu(QPoint))); } void MainWindowCurve::s_NewTrack() { if(ui->tableWidget_2->columnCount()==0) { return; } int column = ui->tableWidget_2->currentColumn();//列编号从0开始 if(column<0) { //当前没有选中井 return; } if(column%2==0) { } else { //空白列 return; } QString strWellName = ui->tableWidget_2->item(0, column)->text(); //新建道 emit CallManage::getInstance()->sig_NewTrack(m_strUuid, strWellName, "", "", ""); int iWidth = ui->tableWidget_2->columnWidth(column); //设置列宽 ui->tableWidget_2->setColumnWidth(column, iWidth+g_iOneWidth); } void MainWindowCurve::s_NewTrackChangeWidth(QString strWellName) { qDebug() << "MainWindowCurve s_NewTrackChangeWidth"; int column = ui->tableWidget_2->columnCount(); for(int i=0; itableWidget_2->item(0, i)->text(); if(strWellNameTemp==strWellName) { int iWidth = ui->tableWidget_2->columnWidth(i);//设置列宽 ui->tableWidget_2->setColumnWidth(i, iWidth+g_iOneWidth+6); } } } //新建空白道,没有曲线 void MainWindowCurve::s_NewTrack_No_Line(QString strWellName, QString strTrackName) { emit CallManage::getInstance()->sig_NewTrack_No_Line(m_strUuid, strWellName, strTrackName); } //新建曲线,带属性 void MainWindowCurve::s_AddLine_Property(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, double newLeftScale, double newRightScale, QString strScaleType, QColor lineColor, double width, Qt::PenStyle lineStyle) { emit CallManage::getInstance()->sig_AddLine_Property(m_strUuid, strSlfName, strWellName, strTrackName, strLineName, newLeftScale, newRightScale, strScaleType, lineColor, width, lineStyle); } //新建井+道+曲线(首条) void MainWindowCurve::NewWellAndTrack(QString strWellName, QString strSlfName, QString strLineName, QString strType) { // if(m_listWell.contains(strWellName)) { //不在道里,新建道+曲线 //新建道+曲线 emit CallManage::getInstance()->sig_NewTrack(m_strUuid, strWellName, strSlfName, strLineName, strType); //改变井宽 emit sig_NewTrackChangeWidth(strWellName); } else { //井没创建,创建井+道+曲线 //新建井 s_NewWell(strWellName); m_listWell.push_back(strWellName); //新建道+曲线 emit CallManage::getInstance()->sig_NewTrack(m_strUuid, strWellName, strSlfName, strLineName, strType); } } void MainWindowCurve::dragEnterEvent(QDragEnterEvent* event) { qDebug() << "MainWindowCurve dragEnterEvent"; const QMimeData* mimeData = event->mimeData(); // 检查拖拽的数据类型,确定是否接受拖拽 if (event->mimeData()->hasFormat("text/plain")) { event->acceptProposedAction(); //QApplication::setOverrideCursor(Qt::PointingHandCursor); // 设置鼠标为可添加状态 } else { event->ignore(); //QApplication::setOverrideCursor(Qt::ForbiddenCursor); // 设置鼠标为不可添加状态 } } void MainWindowCurve::dragMoveEvent(QDragMoveEvent* event) { //qDebug() << "MainWindowCurve dragMoveEvent"; // 可以在这里更新鼠标的位置,根据位置判断是否可以放置 // ... //dragEnterEvent(event); // 可以使用相同的逻辑 //event->accept(); } void MainWindowCurve::dropEvent(QDropEvent* event) { qDebug() << "MainWindowCurve dropEvent"; // 处理放置动作,更新UI或数据 if (event->mimeData()->hasFormat("text/plain")) { // 获取拖拽的数据 QString strExtern = event->mimeData()->text(); qDebug() << strExtern; // QStringList list = strExtern.split("#@@#");//QString字符串分割函数 if (list.size() > 2) { QString strSlfName = list[0]; QString strWellName = list[1]; QString strLineName = list[2]; qDebug() << "strSlfName:" << strSlfName<< " strWellName:" << strWellName<< " strLineName:" << strLineName; //新建井+道+曲线(首条) NewWellAndTrack(strWellName, strSlfName, strLineName, "curveObject"); } else { // QStringList listWave = strExtern.split("#$$#");//QString字符串分割函数 if (listWave.size() > 2) { QString strSlfName = listWave[0]; QString strWellName = listWave[1]; QString strWaveName = listWave[2]; qDebug() << "strSlfName:" << strSlfName<< " strWellName:" << strWellName<< " strWaveName:" << strWaveName; //新建井+道+波列(首条) NewWellAndTrack(strWellName, strSlfName, strWaveName, "waveObject"); } } //QMessageBox::information(this, "提示", strExtern); // 接受拖拽事件 event->setDropAction(Qt::MoveAction); event->accept(); } else { // 如果数据格式不正确,不接受拖拽事件 event->ignore(); } // 恢复鼠标光标 //QApplication::restoreOverrideCursor(); } void MainWindowCurve::slotContextMenu(QPoint pos) { // QMenu menu(ui->tableWidget); // QAction *newAction = menu.addAction("新建图头"); // // 弹出菜单 // QAction *selectedAction = menu.exec(ui->tableWidget->mapToGlobal(pos)); // if (selectedAction == newAction) { // NewHeadDialog *dlg = new NewHeadDialog(this); // // // dlg->setAttribute(Qt::WA_DeleteOnClose);//关闭时,自动删除窗口对象 // int result = dlg->exec();//模态对话框 // if (result == QDialog::Accepted) { // // 处理用户点击了确定按钮的逻辑 // qDebug() << "Accepted="; // int rowcount = ui->tableWidget->rowCount(); //总行数 // //增加1行 // ui->tableWidget->setRowCount(rowcount+1); // //行标题 // QTableWidgetItem *headerItem = new QTableWidgetItem(""); // ui->tableWidget->setVerticalHeaderItem(rowcount, headerItem); // int iWidth=0; // //设置行高度 // ui->tableWidget->setRowHeight(rowcount, g_iRows*(g_iRowsHight+2)+1); // if(rowcount==0) // { // iWidth=g_iCols*g_iColsWidth; // //设置列宽 // ui->tableWidget->setColumnWidth(0, g_iCols*(g_iColsWidth+1)+1); // } // else // { // iWidth=ui->tableWidget->columnWidth(0); // if(iWidthtableWidget->setColumnWidth(0, g_iCols*(g_iColsWidth+1)+1); // } // } // // // FormHead *widgetHead = new FormHead(this, 1); // widgetHead->Init(g_iRows, g_iCols, iWidth); // ui->tableWidget->setCellWidget(rowcount, 0, widgetHead); // } // else if (result == QDialog::Rejected) { // // 处理用户点击了取消按钮的逻辑 // qDebug() << "Rejected="; // } // else { // // 处理其他情况的逻辑 // qDebug() << "other="; // } // } // if(ui->tableWidget->rowCount()==0 && ui->tableWidget->rowCount()==0) // { // QMenu menu(ui->tableWidget); // QAction *newAction = menu.addAction("新建图头"); // // 弹出菜单 // QAction *selectedAction = menu.exec(ui->tableWidget->mapToGlobal(pos)); // if (selectedAction == newAction) { // NewHeadDialog *dlg = new NewHeadDialog(this); // // // dlg->setAttribute(Qt::WA_DeleteOnClose);//关闭时,自动删除窗口对象 // int result = dlg->exec();//模态对话框 // if (result == QDialog::Accepted) { // // 处理用户点击了确定按钮的逻辑 // qDebug() << "Accepted="; // // // ui->tableWidget->clear(); // // // ui->tableWidget->setColumnCount(g_iCols); // ui->tableWidget->setRowCount(g_iRows); //动态设置行数 // for(int i=0; itableWidget->setItem(i, j, item); // } // } // } // else if (result == QDialog::Rejected) { // // 处理用户点击了取消按钮的逻辑 // qDebug() << "Rejected="; // } // else { // // 处理其他情况的逻辑 // qDebug() << "other="; // } // } // } // else // { // 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(); // } // } } //合并 void MainWindowCurve::slotMerge() { // QModelIndexList list = ui->tableWidget->selectionModel()->selectedIndexes(); // if (list.size() < 2) // { // QMessageBox::warning(this, "单元格合并", "所选中单元格中为单个单元格,无法合并", "确定"); // return; // } // int topRow = 0; // int leftCol = 0; // int bottomRow = 0; // int rightCol = 0; // QList selectRanges = ui->tableWidget->selectedRanges(); // if (selectRanges.size() > 0) // { // topRow = selectRanges[0].topRow(); // leftCol = selectRanges[0].leftColumn(); // bottomRow = selectRanges[0].bottomRow(); // rightCol = selectRanges[0].rightColumn(); // } // for(auto range:selectRanges) // { // if(range.topRow() bottomRow) // bottomRow=range.bottomRow(); // if(range.rightColumn()>rightCol) // rightCol=range.rightColumn(); // } // int rowSpan = (bottomRow - topRow) + 1; // int colSpan = (rightCol - leftCol) + 1; // ui->tableWidget->setSpan(topRow, leftCol, rowSpan, colSpan); } //拆分 void MainWindowCurve::slotSplit() { // int row,col; // QList selectRanges = ui->tableWidget->selectedRanges(); // if (selectRanges.size() < 2) // { // QMessageBox::warning(this, "拆分表格失败", "单元格已是最小单位,不能再进行拆分", "确定"); // return; // } // QList selectItems = ui->tableWidget->selectedItems(); // if(selectItems.size()==0) // { // QMessageBox::warning(this, "拆分表格失败", "请先为表格设置元素item", "确定"); // return; // } // if(selectItems.size()>1) // { // QMessageBox::warning(this, "拆分表格失败", "非法选择", "确定"); // return; // } // for(auto item:selectItems) // { // row= item->row(); // col=item->column(); // } // ui->tableWidget->setSpan(row, col, 1, 1); // 设置跨度为1 } bool MainWindowCurve::eventFilter(QObject* obj, QEvent* event) { // if (obj == ui->tableWidget && event->type() == QEvent::KeyPress) { // QKeyEvent* keyEvent = static_cast(event); // if (keyEvent->matches(QKeySequence::Paste)) { // onPasteExcelData(); // return true; // } // } return QMainWindow::eventFilter(obj, event); } //复制粘贴事件 void MainWindowCurve::keyPressEvent(QKeyEvent * event) { // //excel 行分是 "\n" ; 列分是 "\t" // if (event->matches(QKeySequence::Copy)) // { // copy(); // } // else if (event->matches(QKeySequence::Paste)) // { // Paste(); // } // else if (event->matches(QKeySequence::SelectAll)) // { // ui->tableWidget->selectAll(); // } // else // { // QWidget::keyPressEvent(event); // } } void MainWindowCurve::copy() { // QMap> selMap;//行,列 // QList list = ui->tableWidget->selectedItems(); // if (list.count() <= 0) // return; // for (QTableWidgetItem* item : list) // { // int rowN = ui->tableWidget->row(item); // int colN = ui->tableWidget->column(item); // selMap[rowN].append(colN); // } // QString cpStr; // QMap>::iterator it = selMap.begin(); // while (it != selMap.end()) // { // for (int i = 0; i < (*it).count(); i++) // { // QTableWidgetItem* item = ui->tableWidget->item(it.key(), (*it).at(i)); // if (item) // { // cpStr.append(item->text().trimmed()); // } // if (i != (*it).count() - 1) // cpStr.append("\t"); // } // it++; // if (it != selMap.end()) // { // cpStr.append("\n"); // } // } // QApplication::clipboard()->setText(cpStr); } void MainWindowCurve::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(); // int rowN, colN; // if (!crtItem) // { // rowN = ui->tableWidget->currentRow(); // colN = ui->tableWidget->currentColumn(); // } // else // { // rowN = ui->tableWidget->row(crtItem); // colN = ui->tableWidget->column(crtItem); // } // for (int i = 0; i < (ui->tableWidget->rowCount() - rowN) && (i < rowList.length()); i++) // { // QStringList rowDataList = rowList.at(i).split("\t", QString::KeepEmptyParts); // for (int j = 0; j < (ui->tableWidget->columnCount() - colN) && (j < rowDataList.length()); j++) // { // int x = i + rowN; // int y = j + colN; // QTableWidgetItem* item = ui->tableWidget->item(x, y); // if (item) // { // item->setText(rowDataList.at(j)); // } // else // { // ui->tableWidget->setItem(x, y, new QTableWidgetItem(rowDataList.at(j))); // } // } // } } void MainWindowCurve::onPasteExcelData() { // QClipboard* clipboard = QApplication::clipboard(); // const QString clipData = clipboard->text(); // if (clipData.isEmpty()) return; // QList rowsData; // const QStringList rows = clipData.split('\n', QString::SkipEmptyParts); // for (const QString row:rows) { // rowsData << row.split('\t', QString::SkipEmptyParts); // } // QTableWidget* table = ui->tableWidget; // const QModelIndex currentIndex = table->currentIndex(); // const int startRow = currentIndex.isValid() ? currentIndex.row() : 0; // const int startCol = currentIndex.isValid() ? currentIndex.column() : 0; // table->setUpdatesEnabled(false); // table->setRowCount(std::max(table->rowCount(), startRow + rowsData.size())); // table->setColumnCount(std::max(table->columnCount(), startCol + rowsData[0].size())); // for (int i = 0; i < rowsData.size(); ++i) { // for (int j = 0; j < rowsData[i].size(); ++j) { // if (startRow + i >= table->rowCount()) break; // if (startCol + j >= table->columnCount()) break; // QTableWidgetItem* item = table->item(startRow + i, startCol + j); // if (!item) { // item = new QTableWidgetItem(); // table->setItem(startRow + i, startCol + j, item); // } // item->setText(rowsData[i][j]); // } // } // table->setUpdatesEnabled(true); } void MainWindowCurve::Open(QString fileFull) { QString strPrjname = ""; QJsonArray wellsArray; QJsonParseError jsonError; // 文件 QFile file(fileFull); if(file.open(QIODevice::ReadOnly)) { // 解析JSON QJsonDocument document = QJsonDocument::fromJson(file.readAll(), &jsonError); if (!document.isNull() && (jsonError.error == QJsonParseError::NoError)) { if (document.isObject()) { QJsonObject object = document.object(); // if (object.contains("prjname")) { QJsonValue value = object.value("prjname"); if (value.isString()) { strPrjname = value.toString(); qDebug() << "prjname:" << strPrjname; if(strPrjname != g_prjname) { file.close(); qDebug() << "JSON 模板文件项目名称与当前项目不一致!"; return; } } } // if (object.contains("wells")) { QJsonValue value = object.value("wells"); if (value.isArray()) { wellsArray = value.toArray(); qDebug() << "wellsArray number:" << QString::number(wellsArray.size()); //展示所有井 DisplayWells(wellsArray); } } } } // file.close(); qDebug() << "JSON 模板文件读取成功!"; //触发更新 //QTimer::singleShot(2000, this, SLOT(slot_time())); } else { qWarning() << "JSON 模板文件打开失败:" << file.errorString(); } } void MainWindowCurve::slot_time() { QProgressBar *progressBar = new QProgressBar(this); progressBar->setGeometry(100, 100, 500, 30); // 设置进度条的位置和大小 progressBar->setMaximum(100); // 设置最大值为100 progressBar->setValue(0); // 初始值设为0 progressBar->show(); double dHight = 0; dHight = (g_iY2-g_iY1)*100.0/(double)g_iScale * g_dPixelPerCm *10; if(dHight>32767) { dHight = 32767; } double dHightOne = dHight+300+100+10; //设置高度 ui->tableWidget_2->setRowHeight(1, (int)dHightOne);//8020 //-------------------- // int columnCount = ui->tableWidget_2->columnCount();//总列数 int iSplit = 100 / (columnCount/2+1); for(int i=0; isetValue(i*iSplit); // 更新进度条的值 QCoreApplication::processEvents(); // 让界面更新显示进度条的当前值 if( ui->tableWidget_2->cellWidget(1, i) != nullptr ) { auto myWidget = ui->tableWidget_2->cellWidget(1, i); // FormWell *widgetWell = (FormWell*)myWidget;//获得widget if(widgetWell) { widgetWell->setRowHeight(dHight, progressBar, iSplit); } } } // progressBar->deleteLater(); } void MainWindowCurve::DisplayWells(QJsonArray wellsArray) { QMap mapWells; int id = 0; int iCount = wellsArray.size(); for(int i=0; is_NewWell(strWellName); s_NewWell(strWellName); } } // if (wellObjInfo.contains("formTracks")) { QJsonValue value = wellObjInfo.value("formTracks"); if (value.isArray()) { tracksArray = value.toArray(); qDebug() << "tracksArray number:" << QString::number(tracksArray.size()); //展示所有道 DisplayTracks(tracksArray); } } } //展示所有道 void MainWindowCurve::DisplayTracks(QJsonArray tracksArray) { QMap mapTracks; int id = 0; int iCount = tracksArray.size(); for(int i=0; i0) { //改变井宽 s_NewTrackChangeWidth(strWellName); //mainWindowCurve->s_NewTrackChangeWidth(strWellName); } // if (trackObjInfo.contains("formInfos")) { QJsonValue value = trackObjInfo.value("formInfos"); if (value.isArray()) { linesArray = value.toArray(); qDebug() << "linesArray number:" << QString::number(linesArray.size()); //展示所有曲线 DisplayLines(linesArray); } } } //展示所有曲线 void MainWindowCurve::DisplayLines(QJsonArray linesArray) { QMap mapLines; int id = 0; int iCount = linesArray.size(); for(int i=0; iind) ind=ind2; if(ind>-1) { slffilename = strSlfName.mid(ind+1); strSlfName = slffilename; } } } if (lineObjInfo.contains("WellName")) { QJsonValue value = lineObjInfo.value("WellName"); if (value.isString()) { strWellName = value.toString(); //qDebug() << "WellName:" << strWellName; } } if (lineObjInfo.contains("TrackName")) { QJsonValue value = lineObjInfo.value("TrackName"); if (value.isString()) { strTrackName = value.toString(); //qDebug() << "TrackName:" << strTrackName; } } if (lineObjInfo.contains("LineName")) { QJsonValue value = lineObjInfo.value("LineName"); if (value.isString()) { strLineName = value.toString(); //qDebug() << "LineName:" << strLineName; } } if (lineObjInfo.contains("vmin")) { QJsonValue value = lineObjInfo.value("vmin"); if (value.isDouble()) { newLeftScale = value.toDouble(); //qDebug() << "vmin:" << QString::number(newLeftScale); } } if (lineObjInfo.contains("vmax")) { QJsonValue value = lineObjInfo.value("vmax"); if (value.isDouble()) { newRightScale = value.toDouble(); //qDebug() << "vmax:" << QString::number(newRightScale); } } if (lineObjInfo.contains("ScaleType")) { QJsonValue value = lineObjInfo.value("ScaleType"); if (value.isString()) { strScaleType = value.toString(); //qDebug() << "ScaleType:" << strScaleType; } } if (lineObjInfo.contains("Width")) { QJsonValue value = lineObjInfo.value("Width"); if (value.isDouble()) { width = value.toDouble(); //qDebug() << "Width:" << QString::number(width); } } if (lineObjInfo.contains("lineStyle")) { QJsonValue value = lineObjInfo.value("lineStyle"); if (value.isDouble()) { lineStyle = (Qt::PenStyle)value.toInt(); //qDebug() << "lineStyle:" << QString::number(lineStyle); } } // if (lineObjInfo.contains("lineColorRed")) { QJsonValue value = lineObjInfo.value("lineColorRed"); if (value.isDouble()) { lineColor.setRed(value.toInt()); //qDebug() << "lineColorRed:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("lineColorGreen")) { QJsonValue value = lineObjInfo.value("lineColorGreen"); if (value.isDouble()) { lineColor.setGreen(value.toInt()); //qDebug() << "lineColorGreen:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("lineColorBlue")) { QJsonValue value = lineObjInfo.value("lineColorBlue"); if (value.isDouble()) { lineColor.setBlue(value.toInt()); //qDebug() << "lineColorBlue:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("lineColorAlpha")) { QJsonValue value = lineObjInfo.value("lineColorAlpha"); if (value.isDouble()) { lineColor.setAlpha(value.toInt()); //qDebug() << "lineColorAlpha:" << QString::number(value.toInt()); } } QString folderPath = GetLogdataPath(); folderPath = folderPath + g_prjname; strSlfName = folderPath + "/" + "#" + strWellName + "/" + strSlfName; if(strLineName!="") { //新建曲线 s_AddLine_Property(strSlfName, strWellName, strTrackName, strLineName, newLeftScale, newRightScale, strScaleType, lineColor, width, lineStyle); } //--------------- if (lineObjInfo.contains("newHeadFill")) { QJsonValue value = lineObjInfo.value("newHeadFill"); if (value.isString()) { newHeadFill = value.toString(); //qDebug() << "newHeadFill:" << newHeadFill; } } if (lineObjInfo.contains("newTargetLine")) { QJsonValue value = lineObjInfo.value("newTargetLine"); if (value.isString()) { newTargetLine = value.toString(); //qDebug() << "newTargetLine:" << newTargetLine; } } if (lineObjInfo.contains("newFillType")) { QJsonValue value = lineObjInfo.value("newFillType"); if (value.isString()) { newFillType = value.toString(); //qDebug() << "newFillType:" << newFillType; } } if (lineObjInfo.contains("newFillMode")) { QJsonValue value = lineObjInfo.value("newFillMode"); if (value.isString()) { newFillMode = value.toString(); //qDebug() << "newFillMode:" << newFillMode; } } // if (lineObjInfo.contains("newColorRed")) { QJsonValue value = lineObjInfo.value("newColorRed"); if (value.isDouble()) { newColor.setRed(value.toInt()); //qDebug() << "newColorRed:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("newColorGreen")) { QJsonValue value = lineObjInfo.value("newColorGreen"); if (value.isDouble()) { newColor.setGreen(value.toInt()); //qDebug() << "newColorGreen:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("newColorBlue")) { QJsonValue value = lineObjInfo.value("newColorBlue"); if (value.isDouble()) { newColor.setBlue(value.toInt()); //qDebug() << "newColorBlue:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("newColorAlpha")) { QJsonValue value = lineObjInfo.value("newColorAlpha"); if (value.isDouble()) { newColor.setAlpha(value.toInt()); //qDebug() << "newColorAlpha:" << QString::number(value.toInt()); } } if (lineObjInfo.contains("newLithosImage")) { QJsonValue value = lineObjInfo.value("newLithosImage"); if (value.isString()) { newLithosImage = value.toString(); //qDebug() << "newLithosImage:" << newLithosImage; } } if (lineObjInfo.contains("new_vMin")) { QJsonValue value = lineObjInfo.value("new_vMin"); if (value.isDouble()) { new_vMin = value.toDouble(); //qDebug() << "new_vMin:" << QString::number(new_vMin); } } if (lineObjInfo.contains("new_vMax")) { QJsonValue value = lineObjInfo.value("new_vMax"); if (value.isDouble()) { new_vMax = value.toDouble(); //qDebug() << "new_vMax:" << QString::number(new_vMax); } } // if (lineObjInfo.contains("frontColorRed")) { QJsonValue value = lineObjInfo.value("frontColorRed"); if (value.isDouble()) { frontColor.setRed(value.toInt()); //qDebug() << "frontColorRed:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("frontColorGreen")) { QJsonValue value = lineObjInfo.value("frontColorGreen"); if (value.isDouble()) { frontColor.setGreen(value.toInt()); //qDebug() << "frontColorGreen:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("frontColorBlue")) { QJsonValue value = lineObjInfo.value("frontColorBlue"); if (value.isDouble()) { frontColor.setBlue(value.toInt()); //qDebug() << "frontColorBlue:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("frontColorAlpha")) { QJsonValue value = lineObjInfo.value("frontColorAlpha"); if (value.isDouble()) { frontColor.setAlpha(value.toInt()); //qDebug() << "frontColorAlpha:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("backColorRed")) { QJsonValue value = lineObjInfo.value("backColorRed"); if (value.isDouble()) { backColor.setRed(value.toInt()); //qDebug() << "backColorRed:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("backColorGreen")) { QJsonValue value = lineObjInfo.value("backColorGreen"); if (value.isDouble()) { backColor.setGreen(value.toInt()); //qDebug() << "backColorGreen:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("backColorBlue")) { QJsonValue value = lineObjInfo.value("backColorBlue"); if (value.isDouble()) { backColor.setBlue(value.toInt()); //qDebug() << "backColorBlue:" << QString::number(value.toInt()); } } // if (lineObjInfo.contains("backColorAlpha")) { QJsonValue value = lineObjInfo.value("backColorAlpha"); if (value.isDouble()) { backColor.setAlpha(value.toInt()); //qDebug() << "backColorAlpha:" << QString::number(value.toInt()); } } // if(newFillMode=="无填充") { //emit CallManage::getInstance()->sig_ClearFillMode(m_strUuid, strSlfName, strWellName, strTrackName, strLineName); } else //if(newFillMode=="填充") { // emit CallManage::getInstance()->sig_ChangeFillMode(m_strUuid, strSlfName, strWellName, strTrackName, strLineName, // newFillType, newTargetLine, newColor, newLithosImage, newHeadFill, // new_vMin, new_vMax, strOtherScaleType, frontColor, backColor, newFillMode); } }