833 lines
25 KiB
C++
833 lines
25 KiB
C++
#include "mainwindowcurve.h"
|
||
#include "ui_mainwindowcurve.h"
|
||
#include <QFile>
|
||
#include <QTextStream>
|
||
#include "CallManage.h"
|
||
#include <QAbstractItemView>
|
||
|
||
extern int g_iOneWidth; //道宽
|
||
extern QString g_prjname;
|
||
//
|
||
extern int g_iY1;
|
||
extern int g_iY2;
|
||
extern double g_dPixelPerCm;//每厘米像素数
|
||
extern int g_iScale;
|
||
|
||
MainWindowCurve::MainWindowCurve(QWidget *parent) :
|
||
QMainWindow(parent),
|
||
ui(new Ui::MainWindowCurve)
|
||
{
|
||
ui->setupUi(this);
|
||
|
||
// 设置工具栏的位置,此处设置为在左侧
|
||
addToolBar(Qt::LeftToolBarArea, ui->toolBar);
|
||
|
||
//初始化工具栏
|
||
initMainToolBar();
|
||
initToolBar();
|
||
|
||
//加载样式
|
||
loadStyle(":/qrc/qss/flatgray.css");
|
||
|
||
ui->tableWidget->hide();
|
||
ui->tableWidget_3->hide();
|
||
//
|
||
//
|
||
ui->tableWidget->verticalHeader()->hide();
|
||
ui->tableWidget->horizontalHeader()->hide();
|
||
|
||
//
|
||
//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->horizontalHeader()->setFixedHeight(3);//标题栏高度
|
||
//我们让一列也可以滑动
|
||
ui->tableWidget_2->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||
ui->tableWidget_2->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||
// //表头
|
||
// QStringList list;
|
||
// list << "" << "" << "" << "";
|
||
// ui->tableWidget->setHorizontalHeaderLabels(list);
|
||
|
||
////
|
||
ui->tableWidget_3->verticalHeader()->hide();
|
||
ui->tableWidget_3->horizontalHeader()->hide();
|
||
|
||
|
||
connect(this, SIGNAL(sig_NewTrackChangeWidth(QString)), this, SLOT(s_NewTrackChangeWidth(QString)));
|
||
|
||
}
|
||
|
||
MainWindowCurve::~MainWindowCurve()
|
||
{
|
||
delete ui;
|
||
}
|
||
|
||
//初始化工具栏
|
||
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, &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()
|
||
{
|
||
//Logdata
|
||
QString folderPath;
|
||
folderPath = GetLogdataPath();
|
||
folderPath = folderPath + g_prjname;
|
||
//folderPath = folderPath + "/multiwell.json";
|
||
|
||
//打开
|
||
QString fileFull = "";
|
||
fileFull = QFileDialog::getOpenFileName(this,
|
||
tr("选择模板"),
|
||
folderPath,
|
||
tr("多井图文件(*.json)"));
|
||
if (fileFull.isEmpty())
|
||
{
|
||
return;
|
||
}
|
||
|
||
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 模板文件读取成功!";
|
||
} else {
|
||
qWarning() << "JSON 模板文件打开失败:" << file.errorString();
|
||
}
|
||
}
|
||
|
||
void MainWindowCurve::DisplayWells(QJsonArray wellsArray)
|
||
{
|
||
//清空
|
||
m_listWell.clear();
|
||
ui->tableWidget_2->clear();
|
||
QMap<int, int> mapWells;
|
||
|
||
int id = 0;
|
||
int iCount = wellsArray.size();
|
||
for(int i=0; i<iCount; i++)
|
||
{
|
||
QJsonValue wellValue = wellsArray[i];
|
||
|
||
QJsonObject wellObj = wellValue.toObject();
|
||
//
|
||
if (wellObj.contains("id"))
|
||
{
|
||
QJsonValue value = wellObj.value("id");
|
||
if (value.isDouble()) {
|
||
id = value.toInt();
|
||
qDebug() << "id:" << QString::number(id);
|
||
//
|
||
mapWells.insert(id, i);
|
||
}
|
||
}
|
||
}
|
||
|
||
for(int id=0; id<iCount; id++)
|
||
{
|
||
if(mapWells.contains(id*2))
|
||
{
|
||
int iNum = mapWells.value(id*2);
|
||
//按照id顺序,展示井
|
||
QJsonValue wellValue = wellsArray[iNum];
|
||
QJsonObject wellObj = wellValue.toObject();
|
||
//
|
||
if (wellObj.contains("info"))
|
||
{
|
||
QJsonValue value = wellObj.value("info");
|
||
if (value.isObject()) {
|
||
QJsonObject wellObjInfo = value.toObject();
|
||
//展示其中一口井
|
||
DisplayWell_One(wellObjInfo);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void MainWindowCurve::DisplayWell_One(QJsonObject wellObjInfo)
|
||
{
|
||
QString strWellName = "";
|
||
QJsonArray tracksArray;
|
||
|
||
if (wellObjInfo.contains("WellName"))
|
||
{
|
||
QJsonValue value = wellObjInfo.value("WellName");
|
||
if (value.isString()) {
|
||
strWellName = value.toString();
|
||
qDebug() << "WellName:" << strWellName;
|
||
|
||
//新建井
|
||
s_NewWell(strWellName);
|
||
m_listWell.push_back(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<int, int> mapTracks;
|
||
|
||
int id = 0;
|
||
int iCount = tracksArray.size();
|
||
for(int i=0; i<iCount; i++)
|
||
{
|
||
QJsonValue trackValue = tracksArray[i];
|
||
|
||
QJsonObject trackObj = trackValue.toObject();
|
||
//
|
||
if (trackObj.contains("id"))
|
||
{
|
||
QJsonValue value = trackObj.value("id");
|
||
if (value.isDouble()) {
|
||
id = value.toInt();
|
||
qDebug() << "id:" << QString::number(id);
|
||
//
|
||
mapTracks.insert(id, i);
|
||
}
|
||
}
|
||
}
|
||
|
||
for(int id=0; id<iCount; id++)
|
||
{
|
||
if(mapTracks.contains(id))
|
||
{
|
||
int iNum = mapTracks.value(id);
|
||
//按照id顺序,展示道
|
||
QJsonValue trackValue = tracksArray[iNum];
|
||
QJsonObject trackObj = trackValue.toObject();
|
||
//
|
||
if (trackObj.contains("info"))
|
||
{
|
||
QJsonValue value = trackObj.value("info");
|
||
if (value.isObject()) {
|
||
QJsonObject trackObjInfo = value.toObject();
|
||
//展示其中一道
|
||
DisplayTrack_One(trackObjInfo, id);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//展示其中一道
|
||
void MainWindowCurve::DisplayTrack_One(QJsonObject trackObjInfo, int id)
|
||
{
|
||
QString strWellName = "";
|
||
QString strTrackName = "";
|
||
QJsonArray linesArray;
|
||
|
||
if (trackObjInfo.contains("WellName"))
|
||
{
|
||
QJsonValue value = trackObjInfo.value("WellName");
|
||
if (value.isString()) {
|
||
strWellName = value.toString();
|
||
qDebug() << "WellName:" << strWellName;
|
||
}
|
||
}
|
||
if (trackObjInfo.contains("TrackName"))
|
||
{
|
||
QJsonValue value = trackObjInfo.value("TrackName");
|
||
if (value.isString()) {
|
||
strTrackName = value.toString();
|
||
qDebug() << "TrackName:" << strTrackName;
|
||
}
|
||
}
|
||
|
||
//新建道+曲线
|
||
emit CallManage::getInstance()->sig_NewTrack_No_Line(strWellName, strTrackName);//新建空白道,没有曲线
|
||
if(id>0)
|
||
{
|
||
//改变井宽
|
||
emit sig_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<int, int> mapLines;
|
||
|
||
int id = 0;
|
||
int iCount = linesArray.size();
|
||
for(int i=0; i<iCount; i++)
|
||
{
|
||
QJsonValue lineValue = linesArray[i];
|
||
|
||
QJsonObject lineObj = lineValue.toObject();
|
||
//
|
||
if (lineObj.contains("id"))
|
||
{
|
||
QJsonValue value = lineObj.value("id");
|
||
if (value.isDouble()) {
|
||
id = value.toInt();
|
||
qDebug() << "id:" << QString::number(id);
|
||
//
|
||
mapLines.insert(id, i);
|
||
}
|
||
}
|
||
}
|
||
|
||
for(int id=0; id<iCount; id++)
|
||
{
|
||
if(mapLines.contains(id))
|
||
{
|
||
int iNum = mapLines.value(id);
|
||
//按照id顺序,展示曲线
|
||
QJsonValue lineValue = linesArray[iNum];
|
||
QJsonObject lineObj = lineValue.toObject();
|
||
//
|
||
if (lineObj.contains("info"))
|
||
{
|
||
QJsonValue value = lineObj.value("info");
|
||
if (value.isObject()) {
|
||
QJsonObject lineObjInfo = value.toObject();
|
||
//展示其中一条曲线
|
||
DisplayLine_One(lineObjInfo);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//展示其中一条曲线
|
||
void MainWindowCurve::DisplayLine_One(QJsonObject lineObjInfo)
|
||
{
|
||
QString strSlfName = "";
|
||
QString strWellName = "";
|
||
QString strTrackName = "";
|
||
QString strLineName = "";
|
||
|
||
if (lineObjInfo.contains("SlfName"))
|
||
{
|
||
QJsonValue value = lineObjInfo.value("SlfName");
|
||
if (value.isString()) {
|
||
strSlfName = value.toString();
|
||
qDebug() << "SlfName:" << strSlfName;
|
||
}
|
||
}
|
||
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(strLineName!="")
|
||
{
|
||
//新建曲线
|
||
emit CallManage::getInstance()->sig_AddLine(strSlfName, strWellName, strTrackName, strLineName);
|
||
}
|
||
}
|
||
|
||
|
||
QJsonObject MainWindowCurve::makeJson()
|
||
{
|
||
// 创建根对象
|
||
QJsonObject rootObj;
|
||
//
|
||
rootObj["prjname"] = g_prjname;
|
||
|
||
// 创建JSON数组并填充数据
|
||
QJsonArray subcaseArray;
|
||
//
|
||
int columnCount = ui->tableWidget_2->columnCount();//总列数
|
||
for(int i=0; i<columnCount; i++)
|
||
{
|
||
if(i%2==0)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
//空白列
|
||
continue;
|
||
}
|
||
|
||
if( ui->tableWidget_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; i<rowcount; i++)
|
||
{
|
||
if(i==0)
|
||
{
|
||
//设置高度
|
||
ui->tableWidget->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);
|
||
ui->tableWidget_2->setCellWidget(i, columnCount, widgetWell);
|
||
}
|
||
}
|
||
//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(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; i<column; i++)
|
||
{
|
||
if(i%2==0)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
//空白列
|
||
continue;
|
||
}
|
||
//
|
||
QString strWellNameTemp = ui->tableWidget_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::NewWellAndTrack(QString strWellName, QString strSlfName, QString strLineName)
|
||
{
|
||
//
|
||
if(m_listWell.contains(strWellName))
|
||
{
|
||
//不在道里,新建道+曲线
|
||
//新建道+曲线
|
||
emit CallManage::getInstance()->sig_NewTrack(strWellName, strSlfName, strLineName);
|
||
//改变井宽
|
||
emit sig_NewTrackChangeWidth(strWellName);
|
||
}
|
||
else
|
||
{
|
||
//井没创建,创建井+道+曲线
|
||
//新建井
|
||
s_NewWell(strWellName);
|
||
m_listWell.push_back(strWellName);
|
||
|
||
//新建道+曲线
|
||
emit CallManage::getInstance()->sig_NewTrack(strWellName, strSlfName, strLineName);
|
||
}
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
//QMessageBox::information(this, "提示", strExtern);
|
||
|
||
// 接受拖拽事件
|
||
event->setDropAction(Qt::MoveAction);
|
||
event->accept();
|
||
}
|
||
else
|
||
{
|
||
// 如果数据格式不正确,不接受拖拽事件
|
||
event->ignore();
|
||
}
|
||
// 恢复鼠标光标
|
||
//QApplication::restoreOverrideCursor();
|
||
}
|