982 lines
34 KiB
C++
982 lines
34 KiB
C++
#pragma warning(push,0)
|
||
//#include "DataHelper.h"
|
||
//#include "Family.h"
|
||
#include <QMessageBox>
|
||
#include <QFileDialog>
|
||
#include <QTextStream>
|
||
#include "InDefTableDlg.h"
|
||
#include "ui_InDefTable.h"
|
||
#include "CStringType.h"
|
||
//#include "ObjWell.h"
|
||
//#include "TiShiDlg.h"
|
||
//#include "ui_TiShi.h"
|
||
//#include "DataImport.h"
|
||
#include <QHBoxLayout>
|
||
#include <QListView>
|
||
//#include "AdaptionComboBox.h"
|
||
//////////////////////////////////////////////////////////////////////////
|
||
//#include "SigelWellCtl.h"
|
||
//#include "MultWellCtl.h"
|
||
|
||
//extern DEFAULTTABLE DefauleTable[DefTabNum];
|
||
//extern DEFAULTTABLE *DefauleTable;//[DefTabNum];
|
||
int DefTabNum = 0;
|
||
#pragma warning(pop)
|
||
//using namespace pai::ios::welllog;
|
||
using namespace Ui;
|
||
|
||
#define MAPPINGTABLENUM 10
|
||
#define MNUMBER 3
|
||
|
||
//BEGIN_OSGGRAPHICS_NAMESPACE
|
||
CInDefTableDlg::CInDefTableDlg(int curitemType,QWidget * parent, Qt::WindowFlags flags)
|
||
: QDialog(parent,flags)/*,m_sigWell(NULL),m_mutlWell(NULL)*/
|
||
{
|
||
|
||
WellNameCol=0;//1;
|
||
CurItemType=curitemType;
|
||
m_pUI = new Ui_InDefTable();
|
||
m_pUI->setupUi(this);
|
||
// m_sigWell=new SigelForm;
|
||
// m_mutlWell=new MultForm;
|
||
|
||
m_pUI->tableWidget->setMouseTracking(true);
|
||
QObject::connect(m_pUI->okbtn, SIGNAL(clicked()), this, SLOT(slotSave()));
|
||
QObject::connect(m_pUI->cancelbtn, SIGNAL(clicked()), this, SLOT(slotCancel()));
|
||
QObject::connect(m_pUI->pushButtonFind, SIGNAL(clicked()), this, SLOT(slotOpenFile()));
|
||
QObject::connect(m_pUI->comboBox_Table, SIGNAL(currentIndexChanged(int)),this, SLOT(changeTabletype()));
|
||
QObject::connect(m_pUI->spinBox_Var,SIGNAL(valueChanged(int)),this,SLOT(slotVarLineChanged(int)));
|
||
QObject::connect(m_pUI->spinBox_Data,SIGNAL(valueChanged(int)),this,SLOT(slotDataLineChanged(int)));
|
||
// QObject::connect(m_pUI->pushButton_PreView, SIGNAL(clicked()), this, SLOT(slotPreView()));
|
||
QObject::connect(m_pUI->checkBox_Space, SIGNAL(clicked()), this, SLOT(slotCheckSpace()));
|
||
QObject::connect(m_pUI->checkBox_Comma, SIGNAL(clicked()), this, SLOT(slotCheckComma()));
|
||
QObject::connect(m_pUI->checkBox_Semicolon, SIGNAL(clicked()), this, SLOT(slotCheckSem()));
|
||
QObject::connect(m_pUI->checkBox_Tab, SIGNAL(clicked()), this, SLOT(slotCheckTab()));
|
||
QObject::connect(m_pUI->checkBox_Spa_2, SIGNAL(clicked()), this, SLOT(slotCheckDubSpace()));
|
||
QObject::connect(m_pUI->tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(slotRefreshZd(int,int)));
|
||
//whp add 2020.4.20
|
||
QObject::connect(m_pUI->comboBox_DefStr,SIGNAL(currentIndexChanged(int)),this, SLOT(slotChangeDefValue()));
|
||
QObject::connect(m_pUI->comboBox_DefValue,SIGNAL(currentIndexChanged(int)),this, SLOT(slotChangeDefValue()));
|
||
// if (!CurItemType)
|
||
// {setWindowTitle(" 多井离散数据导入交互界面");
|
||
// m_mutlWell->setupUi(m_pUI->showWellPart);
|
||
// connect(m_mutlWell->pushButton_SelAll, SIGNAL(clicked()), this, SLOT(slotSelAll()));
|
||
// connect(m_mutlWell->pushButton_NotSelAll, SIGNAL(clicked()), this, SLOT(slotNotSelAll()));
|
||
// connect(m_mutlWell->pushButton_ReSel, SIGNAL(clicked()), this, SLOT(slotReverseSel()));
|
||
// }else
|
||
// {
|
||
// setWindowTitle(" 单井离散数据导入交互界面");
|
||
// m_sigWell->setupUi(m_pUI->showWellPart);
|
||
// }
|
||
|
||
|
||
m_pUI->lineEdit->setText("");
|
||
TableType=DefTabNum;
|
||
VarLine=0;//变量名所在行
|
||
UnitLine=0;//单位所在行
|
||
DataLine=1;//数据开始行
|
||
TotalLine=0;
|
||
IsSpa=IsTab=IsCom=IsSem=DelDubSpa=0;
|
||
|
||
//m_pUI->okbtn->setStyleSheet("QPushButton:checked{background-color:green}");
|
||
//m_pUI->cancelbtn->setStyleSheet("QPushButton:checked{background-color:blue}");
|
||
/*this->setStyleSheet("QPushButton{background-color:black;\
|
||
color: white; border-radius: 30px; border: 3px groove gray;\
|
||
border-style: outset;}"
|
||
"QPushButton:hover{background-color:red; color: white;}"
|
||
"QPushButton:pressed{background-color:rgb(85, 170, 255);\
|
||
border-style: inset; }");*/
|
||
//QHeaderView* headerView = m_pUI->tableWidget->horizontalHeader();
|
||
//headerView->setHidden(true); //行名隐藏 隐藏后无法改变列宽了????
|
||
}
|
||
//whp add 2020.4.20
|
||
void CInDefTableDlg::slotChangeDefValue()
|
||
{
|
||
int FirstCol=0;
|
||
if(!CurItemType)FirstCol=1;
|
||
int colIndex;
|
||
int num=m_pUI->tableWidget->columnCount();
|
||
for(int col=0;col<m_pUI->tableWidget->columnCount();col++)
|
||
{
|
||
if(!col&&!CurItemType)continue;// du多井时第一列是井名
|
||
QWidget *widget=m_pUI->tableWidget->cellWidget(0,col);
|
||
QComboBox *combox=(QComboBox*)widget;
|
||
QString ss=combox->currentText();
|
||
if(ss!="不导入")continue;
|
||
// for(int Row=0;Row<m_pUI->tableWidget->rowCount();Row++)
|
||
// {
|
||
// QString DataStr;
|
||
// if(DefauleTable[TableType].tinfo[col-FirstCol].RepCode!=6)DataStr=m_pUI->comboBox_DefValue->currentText();
|
||
// else DataStr=m_pUI->comboBox_DefStr->currentText();
|
||
// m_pUI->tableWidget->setItem(Row+1,col,new QTableWidgetItem(DataStr));
|
||
// }
|
||
}
|
||
|
||
}
|
||
void CInDefTableDlg::mRefresh()
|
||
{
|
||
slotVarLineChanged(VarLine);
|
||
slotDataLineChanged(DataLine);
|
||
InitList1();
|
||
PreView(1);
|
||
}
|
||
void CInDefTableDlg:: slotCheckSpace(){IsSpa=!IsSpa;mRefresh();}
|
||
void CInDefTableDlg:: slotCheckComma(){IsCom=!IsCom;mRefresh();}
|
||
void CInDefTableDlg:: slotCheckSem(){IsSem=!IsSem;mRefresh();}
|
||
void CInDefTableDlg:: slotCheckTab(){IsTab=!IsTab;mRefresh();}
|
||
void CInDefTableDlg:: slotCheckDubSpace(){DelDubSpa=!DelDubSpa;mRefresh();}
|
||
void CInDefTableDlg::changeTabletype()
|
||
{
|
||
TableType=m_pUI->comboBox_Table->currentIndex();
|
||
m_pUI->lineEdit_TableAliasName->setText(m_pUI->comboBox_Table->currentText());
|
||
if(TableType < DefTabNum)
|
||
{
|
||
// m_pUI->lineEdit_TableName->setText(DefauleTable[TableType].TableName);
|
||
// m_pUI->lineEdit_des->setText(DefauleTable[TableType].TableName);
|
||
}
|
||
else if(TableType == DefTabNum)
|
||
{
|
||
m_pUI->lineEdit_TableName->setText("Custom");
|
||
m_pUI->lineEdit_des->setText("");
|
||
}
|
||
else{
|
||
TableType = DefTabNum;
|
||
m_pUI->comboBox_Table->setCurrentIndex(DefTabNum);
|
||
m_pUI->lineEdit_TableName->setText("Custom");
|
||
m_pUI->lineEdit_des->setText("");
|
||
}
|
||
PreView(0);
|
||
}
|
||
void CInDefTableDlg::slotSave()
|
||
{
|
||
if(m_pUI->lineEdit->text().isEmpty()) {
|
||
//AfxMessageBox("请输入文件名称");
|
||
return;
|
||
}
|
||
|
||
FileName = m_pUI->lineEdit->text();
|
||
|
||
//accept();
|
||
slotEnterOk();
|
||
}
|
||
/**
|
||
*@brief 取消槽函数
|
||
*/
|
||
void CInDefTableDlg::slotCancel()
|
||
{
|
||
reject ();
|
||
}
|
||
void CInDefTableDlg::slotOpenFile()
|
||
{
|
||
QString DataFile = QFileDialog::getOpenFileName(NULL,"打开表数据文件",/*::GetDataPath(),*/
|
||
"表数据文件(*.txt;*.prn;*.csv;*.las)");
|
||
if(DataFile=="")return;
|
||
FileName=DataFile;
|
||
VarLine=0;//变量名所在行
|
||
UnitLine=0;//单位所在行
|
||
DataLine=1;//数据开始行
|
||
TotalLine=0;
|
||
IsSpa=IsTab=IsCom=IsSem=DelDubSpa=0;
|
||
Init();
|
||
this->resize(this->size() - QSize(1,1));
|
||
this->resize(this->size() + QSize(1,1));
|
||
}
|
||
|
||
void CInDefTableDlg::PreView(bool RefreshW)//RefreshW是否刷新勾选井名表格
|
||
{
|
||
if(!TotalLine)
|
||
return;//whp add 2020.3.6
|
||
|
||
m_pUI->tableWidget->clearContents();
|
||
if(!DataLine)
|
||
return;
|
||
|
||
//当前选择项是“井”,第一列是井名
|
||
int WellNum = 0;
|
||
WellNameList.clear();
|
||
|
||
#pragma region 确定数据列数-->TableCol
|
||
int TableCol = 0;
|
||
// if(TableType < DefTabNum)
|
||
// {
|
||
// TableCol = DefauleTable[TableType].ZdNum;
|
||
// if(!CurItemType)
|
||
// TableCol += 1;
|
||
// }
|
||
// else if(TableType == DefTabNum) //自定义表
|
||
// {
|
||
// if(VarLine)
|
||
// TableCol = VarNameList.size();
|
||
// else TableCol = VarNameList.size();
|
||
// }
|
||
// else{
|
||
// TableType = DefTabNum;
|
||
// if(VarLine)
|
||
// TableCol = VarNameList.size();
|
||
// }
|
||
// m_pUI->tableWidget->setColumnCount(TableCol);
|
||
// #pragma endregion
|
||
|
||
// QStringList header;
|
||
// if(!CurItemType)
|
||
// header << "井名";
|
||
|
||
// #pragma region 字段名-->tableWidget
|
||
// if(TableType < DefTabNum)
|
||
// {
|
||
// for(int i = 0; i < DefauleTable[TableType].ZdNum; i++)
|
||
// header << QString(QLatin1String(DefauleTable[TableType].tinfo[i].Name));
|
||
// }
|
||
// else
|
||
// {
|
||
// if(!CurItemType)
|
||
// for(int i = 1; i < VarNameList.size(); i++)
|
||
// header << VarNameList.at(i);
|
||
// else
|
||
// for(int i = 0; i < VarNameList.size(); i++)
|
||
// header << VarNameList.at(i);
|
||
// }
|
||
// m_pUI->tableWidget->setHorizontalHeaderLabels(header);
|
||
// #pragma endregion
|
||
// if(TableType<DefTabNum){
|
||
// if(DefauleTable[TableType].ZdNum < 10)
|
||
// m_pUI->tableWidget->horizontalHeader()->resizeSections(QHeaderView::Stretch);
|
||
// else
|
||
// m_pUI->tableWidget->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
|
||
// }
|
||
// else {
|
||
// m_pUI->tableWidget->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
|
||
// }
|
||
// m_pUI->tableWidget->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
|
||
|
||
// #pragma region 生成comboBox内容-->header
|
||
// header.clear();
|
||
// int len=DataList.size();
|
||
|
||
// if(VarLine) //若已发现数据中的字段名,生成带有字段名的header
|
||
// {
|
||
// for(int i = 0; i < VarNameList.size(); i++)
|
||
// header << "第" + QString::number(i + 1) + "列:" + VarNameList[i];
|
||
// len = VarNameList.size();
|
||
// }
|
||
// else //若没有发现字段名,根据数据列数生成非字段名的header
|
||
// for(int i = 0; i < DataList.size(); i++)
|
||
// header << "第" + QString::number(i + 1) + "列";//QString::number(i+1);
|
||
// //whp add 2020.1.8
|
||
// header<<"不导入"; //额外情况
|
||
// //whp change 2020.3.6
|
||
// //m_pUI->tableWidget->setRowCount(TotalLine-DataLine+1+1);
|
||
// //2020.8.2 for刷新慢
|
||
// #pragma endregion
|
||
|
||
// #pragma region 设置table行数
|
||
// int LineNum = MapData.count(); //数据行数
|
||
// //if(MapData.count()>=100)LineNum=100;
|
||
// m_pUI->tableWidget->setRowCount(LineNum);//MapData.count()+1);
|
||
// #pragma endregion
|
||
|
||
// int FirstCol = 0;
|
||
// if(!CurItemType)
|
||
// FirstCol = 1;
|
||
|
||
// //首行为字段选择行
|
||
// #pragma region 初次生成首行的选择框,
|
||
// for(int i = 0; i < TableCol; i++)
|
||
// {
|
||
// AdaptionComboBox *comboBox = new AdaptionComboBox();
|
||
|
||
// //comboBox->setEditable(true);
|
||
// comboBox->addItems( header ); //每个选择框中的内容相同
|
||
|
||
// if(!i && !CurItemType) //首列且是“井”
|
||
// {
|
||
// comboBox->setCurrentIndex(WellNameCol); //指向井名列
|
||
// }
|
||
// else
|
||
// {
|
||
// int sel = VarNameList.size(); //先指向“不导入”
|
||
|
||
// if(TableType == DefTabNum) //按实际数据字段列顺序即可
|
||
// sel = i;
|
||
// #pragma region 确定该字段是数据中的哪一列(从0开始)
|
||
// else
|
||
// {
|
||
// QString name = QString(QLatin1String(DefauleTable[TableType].tinfo[i-FirstCol].Name));
|
||
// for(int m = 0; m < VarNameList.size(); m++)
|
||
// {
|
||
// if(VarNameList[m].toUpper() == name.toUpper())
|
||
// {
|
||
// sel = m;
|
||
// break;
|
||
// }
|
||
// }
|
||
// }
|
||
// #pragma endregion
|
||
|
||
// comboBox->setCurrentIndex(sel); //确定初始选择框中的默认内容
|
||
// }
|
||
|
||
// //信槽链接——当前值改变——》slotComboxSelectChange(int)
|
||
// connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComboxSelectChange(int)));
|
||
|
||
// comboBox->setProperty("row", 0);
|
||
// comboBox->setProperty("col", i);
|
||
// m_pUI->tableWidget->setCellWidget( 0, i, comboBox );
|
||
// //slotRefreshZd(0,i);//whp add 2020.1.8
|
||
// }
|
||
#pragma endregion
|
||
|
||
//whp change 2020.1.8
|
||
int colIndex;
|
||
|
||
#pragma region 将数值填入
|
||
// for(int Row = 0; Row < LineNum; Row++) //遍历每行数据
|
||
// {
|
||
// QStringList List = MapData.find(Row).value();
|
||
// QString DataStr;
|
||
// for(int i = 0; i < TableCol; i++)
|
||
// {
|
||
// if(!i && !CurItemType) //井的第0列是井名
|
||
// {
|
||
// colIndex=WellNameCol;
|
||
// }
|
||
// #pragma region 确定该字段是数据中的哪一列(从0开始)--> colIndex
|
||
// else
|
||
// {
|
||
// int sel = VarNameList.size(); //不导入
|
||
|
||
// if(TableType == DefTabNum)
|
||
// sel = i;
|
||
// else
|
||
// {
|
||
// QString name = QString(QLatin1String(DefauleTable[TableType].tinfo[i - FirstCol].Name));
|
||
// for(int m = 0; m < VarNameList.size(); m++)
|
||
// {
|
||
// if(VarNameList[m].toUpper() == name.toUpper())
|
||
// {
|
||
// sel=m;
|
||
// break;
|
||
// }
|
||
// }
|
||
// }
|
||
// colIndex=sel;
|
||
// }
|
||
// #pragma endregion
|
||
|
||
// #pragma region 提取该行该列值
|
||
// if(colIndex>=0&&colIndex < List.size())
|
||
// DataStr = List[colIndex];
|
||
// else
|
||
// {
|
||
// if(TableType==DefTabNum)
|
||
// DataStr="";
|
||
// else{
|
||
// if(DefauleTable[TableType].tinfo[i-FirstCol].RepCode != 6)
|
||
// DataStr = m_pUI->comboBox_DefValue->currentText();
|
||
// else
|
||
// DataStr = m_pUI->comboBox_DefStr->currentText();
|
||
// }
|
||
// }
|
||
// m_pUI->tableWidget->setItem( Row+1, i, new QTableWidgetItem(DataStr));
|
||
// #pragma endregion
|
||
// }
|
||
// }
|
||
#pragma endregion
|
||
|
||
#pragma region 井名处理
|
||
if(RefreshW && !CurItemType)//当前选择项是“井”时,显示所有井名
|
||
{
|
||
//统计所有井名
|
||
/*int num=Mm_pUI->tableWidget->rowCount();//3.6
|
||
for(int i=1;i<m_pUI->tableWidget->rowCount();i++)
|
||
{
|
||
bool flag=0;
|
||
QString DataStr=List[WellNameCol];//m_pUI->tableWidget->item(i,0)->text();
|
||
for(int j=0;j<WellNameList.size();j++)
|
||
{
|
||
if(WellNameList.at(j)!=DataStr)continue;
|
||
flag=1;break;
|
||
}
|
||
if(!flag)WellNameList.append(DataStr);
|
||
}*/
|
||
int num = MapData.count();
|
||
for(int i = 0; i < num; i++)
|
||
{
|
||
QStringList List=MapData.find(i).value();
|
||
bool flag=0;
|
||
QString DataStr=List[WellNameCol];//m_pUI->tableWidget->item(i,0)->text();
|
||
for(int j=0;j<WellNameList.size();j++)
|
||
{
|
||
if(WellNameList.at(j)!=DataStr)
|
||
continue;
|
||
flag=1;
|
||
break;
|
||
}
|
||
if(!flag)
|
||
WellNameList.append(DataStr);
|
||
}
|
||
// //20191227
|
||
// m_mutlWell->tableWidget_WellName->clearContents();
|
||
// m_mutlWell->tableWidget_WellName->setColumnCount(1);
|
||
// QStringList header;
|
||
// header<<"导入井名";
|
||
// m_mutlWell->tableWidget_WellName->setHorizontalHeaderLabels(header);
|
||
// m_mutlWell->tableWidget_WellName->horizontalHeader()->setStretchLastSection(true);
|
||
// m_mutlWell->tableWidget_WellName->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
|
||
// m_mutlWell->tableWidget_WellName->setRowCount(WellNameList.size());
|
||
// for(int i=0;i<WellNameList.size();i++)
|
||
// {
|
||
// m_mutlWell->tableWidget_WellName->setItem(i,0,new QTableWidgetItem(WellNameList.at(i)));
|
||
// m_mutlWell->tableWidget_WellName->item(i,0)->setCheckState(Qt::Checked);
|
||
// }
|
||
}
|
||
#pragma endregion
|
||
}
|
||
|
||
void CInDefTableDlg::slotVarLineChanged(int LineNo)//变量名所在行
|
||
{
|
||
// VarLine=LineNo;
|
||
// QFile file(FileName);
|
||
// if(!file.open(QIODevice::ReadOnly )) {
|
||
// AfxMessageBox("文件无法打开!");
|
||
// return;
|
||
// }
|
||
// char*pLine=new char[5000];
|
||
// //略过变量名行前的行
|
||
// for(int i=0;i<LineNo-1;i++){
|
||
// file.readLine(pLine,50000);
|
||
// }
|
||
// #pragma region whp add 自动匹配缺省表(表类型)
|
||
// file.readLine(pLine,50000);
|
||
// {
|
||
// char *p=strstr(pLine,"\r\n");
|
||
// if(p) *p=0;
|
||
// }
|
||
// QByteArray line=pLine;
|
||
// line=line.toUpper();
|
||
// VarNameList = GetStringList(line,IsSpa,IsTab,IsCom,IsSem,DelDubSpa);//line.split(",");
|
||
|
||
// for(int i = 0; i < DefTabNum; i++) //遍历所有表类型
|
||
// {
|
||
// int num=0;
|
||
// for(int j = 0; j < DefauleTable[i].ZdNum; j++) //ZdNum暂且猜测是该表类型下拥有的字段数
|
||
// {
|
||
// QString zdm = QString(QLatin1String(DefauleTable[i].tinfo[j].Name)).toUpper();
|
||
// if(line.indexOf(zdm) >= 0) //数据中有该字段
|
||
// num++;
|
||
// }
|
||
// if(num == DefauleTable[i].ZdNum) //该表类型符合当前数据文件
|
||
// {
|
||
// TableType = i;
|
||
// m_pUI->comboBox_Table->setCurrentIndex(i); //修改窗口的表类型显示
|
||
// break;
|
||
// }
|
||
// }
|
||
// #pragma endregion
|
||
|
||
// if(CurItemType==0)
|
||
// for(int i=0;i<VarNameList.size();i++)
|
||
// {
|
||
// QString str=VarNameList.at(i).toUpper();
|
||
// if(str.indexOf("WELLNAME")>=0)
|
||
// {
|
||
// WellNameCol=i;//+1;
|
||
// break;
|
||
// }
|
||
// }
|
||
|
||
// file.close();
|
||
// InitList1();
|
||
// PreView(1);
|
||
// delete pLine;
|
||
}
|
||
void CInDefTableDlg::slotDataLineChanged(int LineNo)//数据开始行
|
||
{
|
||
// DataLine=LineNo;
|
||
// QFile file(FileName);
|
||
// file.open(QIODevice::ReadOnly );
|
||
// char*pLine=new char[5000];
|
||
// for(int i=0;i<LineNo-1;i++){
|
||
// file.readLine(pLine,50000);
|
||
// }
|
||
// file.readLine(pLine,50000);
|
||
// {
|
||
// char *p=strstr(pLine,"\r\n");
|
||
// if(p) *p='\0';
|
||
// }
|
||
// QByteArray line=pLine;
|
||
// DataList = GetStringList(line,IsSpa,IsTab,IsCom,IsSem,DelDubSpa);//line.split(",");
|
||
// delete pLine;
|
||
// file.close();
|
||
|
||
// InitList1();
|
||
// PreView(1);
|
||
}
|
||
bool CInDefTableDlg::Init()
|
||
{
|
||
//AfxMessageBox("ddd");
|
||
QHBoxLayout *hboxLayout=new QHBoxLayout();
|
||
MaxCol=0; ////预览数据最大列数
|
||
m_pUI->showWellPart->setLayout(hboxLayout);
|
||
QFile file(FileName);
|
||
file.open(QIODevice::ReadOnly );
|
||
int Row=0;
|
||
char*pLine=new char[5000];
|
||
QByteArray line, line1 = "";
|
||
|
||
#pragma region 自动判断需要使用的分隔符并打钩
|
||
int DubTab=-1,DubSem=-1,DubCom=-1,DubSpa=-1;//是否有连续的Tab、逗号、分号和空格
|
||
int Tab=-1,Sem=-1,Com=-1,Spa=-1;//是否有Tab、逗号、分号和空格分隔符
|
||
while(!file.atEnd())
|
||
{
|
||
file.readLine(pLine,5000);
|
||
{
|
||
char *p=strstr(pLine,"\r\n");
|
||
if(p) *p='\0';
|
||
}
|
||
line = pLine;
|
||
if(Row<100) //仅仅检查前100行是否有连续空格、单空格、Tab、逗号、分号
|
||
{
|
||
//if(DubTab<0)DubTab=line.indexOf(" ");
|
||
//if(DubSem<0)DubSem=line.indexOf(";;");
|
||
//if(DubCom<0)DubCom=line.indexOf(",,");
|
||
if(DubSpa<0)DubSpa=line.indexOf(" ");
|
||
if(Tab<0)Tab=line.indexOf(" ");
|
||
if(Sem<0)Sem=line.indexOf(";");
|
||
if(Com<0)Com=line.indexOf(",");
|
||
if(Spa<0)Spa=line.indexOf(" ");
|
||
}
|
||
//m_pUI->textEdit->append("Line "+QString::number(Row+1)+":"+line);
|
||
Row++;
|
||
}//分隔符选择框
|
||
if(Tab>=0){
|
||
IsTab=1;
|
||
m_pUI->checkBox_Tab->setChecked(IsTab);
|
||
}
|
||
if(Sem>=0){
|
||
IsSem=1;
|
||
m_pUI->checkBox_Semicolon->setChecked(IsSem);
|
||
}
|
||
if(Com>=0){
|
||
IsCom=1;
|
||
m_pUI->checkBox_Comma->setChecked(IsCom);
|
||
}
|
||
if(Spa>=0){
|
||
IsSpa=1;
|
||
m_pUI->checkBox_Space->setChecked(IsSpa);
|
||
}
|
||
if(DubSpa>=0){
|
||
DelDubSpa=1;
|
||
m_pUI->checkBox_Spa_2->setChecked(DelDubSpa);
|
||
}
|
||
#pragma endregion
|
||
|
||
m_pUI->spinBox_Var->setMinimum(0);m_pUI->spinBox_Var->setMaximum(Row);
|
||
m_pUI->spinBox_Data->setMinimum(0);m_pUI->spinBox_Data->setMaximum(Row);
|
||
m_pUI->comboBox_DefValue->addItem("-99999.");
|
||
m_pUI->comboBox_DefValue->addItem("-9999.");
|
||
m_pUI->comboBox_DefValue->addItem("-999.25");
|
||
m_pUI->comboBox_DefValue->addItem("-32767");
|
||
m_pUI->comboBox_DefValue->addItem("0");//whp add 2020.4.9
|
||
m_pUI->comboBox_DefStr->addItem("");
|
||
m_pUI->comboBox_DefStr->addItem("NULL");
|
||
m_pUI->comboBox_DefStr->addItem("NONE");
|
||
|
||
//初步判断变量行和数据行
|
||
file.seek(0);
|
||
int pos=Row;
|
||
if(Row > 20)
|
||
pos = Row - 1;//尽量避开尾部空行*********************************
|
||
MaxRow = pos; //总行数
|
||
#pragma region 记录最大列数
|
||
// for(int i = 0; i < pos; i++)
|
||
// {
|
||
// file.readLine(pLine,50000);
|
||
// {
|
||
// char *p=strstr(pLine,"\r\n");
|
||
// if(p) *p='\0';
|
||
// }
|
||
// QByteArray line=pLine;
|
||
// DataList=GetStringList(line, IsSpa, IsTab, IsCom, IsSem, DelDubSpa);
|
||
// if(DataList.size() < 2)continue; //数据量过少的直接抛弃*********************
|
||
// line1 = line;
|
||
// if(MaxCol < DataList.size())
|
||
// MaxCol = DataList.size(); //重置最大列数,初始为0
|
||
// }
|
||
// if(MaxCol==0)
|
||
// {
|
||
// QMessageBox::warning(NULL,"错误"," 无法识别数据文件:\r\n"+FileName);
|
||
// file.close();
|
||
// delete pLine;
|
||
// return 0;
|
||
// }
|
||
// #pragma endregion
|
||
|
||
// //保存末行的列数,暂且作为数据列数
|
||
// DataList = GetStringList(line1,IsSpa,IsTab,IsCom,IsSem,DelDubSpa);//line.split(",");//取数据行
|
||
// int VarNum=DataList.size();
|
||
// //if(MaxCol<VarNum)MaxCol=VarNum;
|
||
|
||
// #pragma region 确定字段名起始行,以及数据起始行
|
||
// file.seek(0);
|
||
// for(int i = 0; i < pos - 1; i++)//**************************
|
||
// {
|
||
// file.readLine(pLine,50000);
|
||
// {
|
||
// char *p=strstr(pLine,"\r\n");
|
||
// if(p) *p='\0';
|
||
// }
|
||
// line=pLine;
|
||
// DataList=GetStringList(line,IsSpa,IsTab,IsCom,IsSem,DelDubSpa);//line.split(",");//取变量名行
|
||
// //if(MaxCol<DataList.size())MaxCol=DataList.size();
|
||
// bool NotVarLine=0;
|
||
// if( VarNum == DataList.size())//找到符合数据行列数要求的行,初步判断为字段名行或者数据行*********************************************
|
||
// {
|
||
// for(int j = 0; j < VarNum; j++)
|
||
// {
|
||
// if(mIsNumber(DataList[j]))
|
||
// {
|
||
// NotVarLine=1; //非字段名行
|
||
// break;
|
||
// }
|
||
// }
|
||
// if(NotVarLine){ //认为是数据行,跳出(实际数据行数 = i+1)
|
||
// DataLine = i + 1;
|
||
// break;
|
||
// }
|
||
// VarLine=i+1;
|
||
// DataLine=i+2;
|
||
// break;
|
||
// }
|
||
// }
|
||
// #pragma endregion
|
||
|
||
// file.close();
|
||
// delete pLine;
|
||
// m_pUI->spinBox_Var->setValue(VarLine);
|
||
// m_pUI->spinBox_Data->setValue(DataLine);
|
||
// slotVarLineChanged(VarLine);
|
||
// TotalLine=Row;
|
||
// if(VarLine || DataLine)
|
||
// {
|
||
// InitList1();
|
||
// PreView(1);
|
||
// }
|
||
|
||
return 1;
|
||
}
|
||
|
||
//处理上面的table
|
||
void CInDefTableDlg::InitList1()
|
||
{
|
||
if(!TotalLine)
|
||
return;//whp add 2020.3.6
|
||
|
||
int ZdNum;
|
||
if(VarLine)//字段名行数
|
||
ZdNum = VarNameList.size(); //列数(字段数)
|
||
else
|
||
{
|
||
if(VarNameList.size()>DataList.size()) ZdNum=VarNameList.size();
|
||
else ZdNum = DataList.size();
|
||
}
|
||
if(ZdNum <= 0)
|
||
return;
|
||
|
||
MapData.clear();
|
||
m_pUI->tableWidget_1->clearContents();
|
||
m_pUI->tableWidget_1->setColumnCount(MaxCol);//设置表格最大列数:MaxCol 最大列数, tableWidget->setRowCount(10);是设置行数
|
||
|
||
QStringList header;
|
||
for(int i = 0; i < MaxCol; i++)//for(int i=0;i<ZdNum;i++)
|
||
{
|
||
if(VarLine <= 0 || i >= ZdNum) //不确定该列的字段名
|
||
header << "第" + QString::number(i+1) + "列";
|
||
else
|
||
header << "第" + QString::number(i+1) + "列\r\n" + VarNameList.at(i);
|
||
}
|
||
m_pUI->tableWidget_1->setHorizontalHeaderLabels(header); //设置表头
|
||
// m_pUI->tableWidget_1->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
|
||
|
||
QFile file(FileName);
|
||
file.open(QIODevice::ReadOnly );
|
||
m_pUI->tableWidget_1->setRowCount(MaxRow + 10); //设置行数,10行作为额外行
|
||
int Row = 0, row = 0; //row:记录当前待处理行
|
||
QByteArray line;
|
||
char*pLine=new char[5000];
|
||
//所有行遍历开始
|
||
// while(!file.atEnd())
|
||
// {
|
||
// file.readLine(pLine,50000);
|
||
// {
|
||
// char *p=strstr(pLine,"\r\n");
|
||
// if(p) *p='\0';
|
||
// }
|
||
// line=pLine;
|
||
// #pragma region 将该行内容写入tableWidget_1
|
||
// QStringList List = GetStringList(line,IsSpa,IsTab,IsCom,IsSem,DelDubSpa);
|
||
|
||
// QString DataStr;
|
||
// //if(row<100) //2020.8.2 for刷新慢
|
||
// {
|
||
// for(int i = 0; i < MaxCol; i++)
|
||
// {
|
||
// if(i < List.size())
|
||
// DataStr = List[i];
|
||
// else
|
||
// DataStr="";
|
||
|
||
// //将new QTableWidgetItem(DataStr)作为一个元素值放入对应位置(row行,i列)
|
||
// m_pUI->tableWidget_1->setItem(row, i, new QTableWidgetItem(DataStr));//List[colIndex[i]]));
|
||
// }
|
||
// }
|
||
// #pragma endregion
|
||
// row++;
|
||
|
||
// #pragma region 如果是空行就不用再判断是不是数据行了
|
||
// QString sss;
|
||
// bool IsNullLine = 1;
|
||
// for(int kk = 0; kk < List.size(); kk++)
|
||
// {
|
||
// sss = List.at(kk);
|
||
// if(sss != ""){
|
||
// IsNullLine = 0;
|
||
// break;
|
||
// }
|
||
// }
|
||
// if(IsNullLine)
|
||
// continue;
|
||
// #pragma endregion
|
||
|
||
// #pragma region 将数据行内容写入MapData
|
||
// //m_pUI->tableWidget_1->setRowCount(Row+1);
|
||
// if(Row >= DataLine - 1) //DataLine是实际行数,因此要减1, 判断当前处理行是否属于数据行
|
||
// MapData.insert(Row - (DataLine - 1), List);//MapData.insert(Row,List);whp change 2020.5.21
|
||
// #pragma endregion
|
||
// Row++;
|
||
|
||
// }//while(!textstream.atEnd())
|
||
|
||
// delete pLine;
|
||
// //2020.8.2 for刷新慢
|
||
// m_pUI->tableWidget_1->setRowCount(row); //重置table行数
|
||
// //if(row>=100)m_pUI->tableWidget_1->setRowCount(100);
|
||
// file.close();
|
||
// if(!CurItemType)
|
||
// {
|
||
// /* m_pUI->comboBox_WellName->clear();
|
||
// for(int i=0;i<ZdNum;i++)m_pUI->comboBox_WellName->addItem("第"+QString::number(i+1)+"列");
|
||
// m_pUI->comboBox_WellName->setCurrentIndex(0);*/
|
||
// }
|
||
}
|
||
|
||
bool CInDefTableDlg::mIsNumber(QString str)//判断字符串是否为数值
|
||
{
|
||
QByteArray ba = str.toLatin1();//QString 转换为 char*
|
||
const char *buf = ba.data();
|
||
int len=strlen(str.toStdString().c_str());//str.length();//whp change 2020.3.16
|
||
int dig[30];
|
||
int DotNum=0;//小数点个数
|
||
bool IsDigital=1;
|
||
for(int i=0;i<len;i++)
|
||
{
|
||
if(i==0&&buf[i]=='-')continue;//可能是负数
|
||
if(buf[i]=='.')DotNum++;
|
||
else if(!isdigit(buf[i])){IsDigital=0;break;}
|
||
if(DotNum>1){IsDigital=0;break;}
|
||
}
|
||
if(!IsDigital)return 0;//字符串0
|
||
else return 1;//是数值
|
||
}
|
||
|
||
void CInDefTableDlg::slotRefreshZd(int row,int col)
|
||
{
|
||
//刷新当前字段内容
|
||
if(row)return;
|
||
QWidget *widget=m_pUI->tableWidget->cellWidget(row,col);
|
||
QComboBox *combox=(QComboBox*)widget;
|
||
int colIndex=combox->currentIndex();
|
||
int FirstCol=0;
|
||
// if(!CurItemType)FirstCol=1;
|
||
// for(int Row=0;Row<MapData.count();Row++)
|
||
// {
|
||
// QStringList List=MapData.find(Row).value();
|
||
// QString DataStr;
|
||
|
||
// if(colIndex>=0&&colIndex<List.size())DataStr=List[colIndex];
|
||
// else
|
||
// {
|
||
// if(DefauleTable[TableType].tinfo[col-FirstCol].RepCode!=6)DataStr=m_pUI->comboBox_DefValue->currentText();
|
||
// else DataStr=m_pUI->comboBox_DefStr->currentText();
|
||
// }
|
||
// m_pUI->tableWidget->setItem(Row+1,col,new QTableWidgetItem(DataStr));//List[colIndex[i]]));
|
||
// if(!CurItemType)//当前选择项是“井”时,统计所有井名
|
||
// {
|
||
// if(col==0)
|
||
// {
|
||
// bool flag=0;
|
||
// DataStr=DataStr.toUpper();
|
||
// for(int j=0;j<WellNameList.size();j++)
|
||
// {
|
||
// if(WellNameList.at(j)!=DataStr)continue;
|
||
// flag=1;break;
|
||
// }
|
||
// if(!flag)WellNameList.append(DataStr);
|
||
// }
|
||
// }
|
||
// }
|
||
//当前选择项是“井”时,刷新井名列表
|
||
|
||
//////////////////////////////////////////////////////////////////////////
|
||
if(CurItemType==0&&row==0)
|
||
{
|
||
// m_mutlWell->tableWidget_WellName->clearContents();
|
||
// m_mutlWell->tableWidget_WellName->setColumnCount(1);
|
||
// QStringList header;
|
||
// header<<"井名";
|
||
// m_mutlWell->tableWidget_WellName->setHorizontalHeaderLabels(header);
|
||
// m_mutlWell->tableWidget_WellName->horizontalHeader()->setStretchLastSection(true);
|
||
// m_mutlWell->tableWidget_WellName->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
|
||
// m_mutlWell->tableWidget_WellName->setRowCount(WellNameList.size());
|
||
// for(int i=0;i<WellNameList.size();i++)
|
||
// {
|
||
// m_mutlWell->tableWidget_WellName->setItem(i,0,new QTableWidgetItem(WellNameList.at(i)));
|
||
// m_mutlWell->tableWidget_WellName->item(i,0)->setCheckState(Qt::Checked);
|
||
// }
|
||
}
|
||
|
||
}
|
||
void CInDefTableDlg::slotSelAll()
|
||
{
|
||
// for(int i=0;i<WellNameList.size();i++)m_mutlWell->tableWidget_WellName->item(i,0)->setCheckState(Qt::Checked);
|
||
}
|
||
void CInDefTableDlg::slotNotSelAll()
|
||
{
|
||
// for(int i=0;i<WellNameList.size();i++)
|
||
// m_mutlWell->tableWidget_WellName->item(i,0)->setCheckState(Qt::Unchecked);
|
||
}
|
||
//mult well
|
||
void CInDefTableDlg::slotReverseSel()
|
||
{
|
||
|
||
|
||
// //////////////////////////////////////////////////////////////////////////
|
||
// for(int i=0;i<WellNameList.size();i++)
|
||
// {
|
||
// Qt::CheckState eState= m_mutlWell->tableWidget_WellName->item(i,0)->checkState();
|
||
// if (eState==Qt::Checked)m_mutlWell->tableWidget_WellName->item(i,0)->setCheckState(Qt::Unchecked);
|
||
// else m_mutlWell->tableWidget_WellName->item(i,0)->setCheckState(Qt::Checked);
|
||
// }
|
||
}
|
||
|
||
void CInDefTableDlg::slotEnterOk()
|
||
{
|
||
|
||
}
|
||
|
||
//comboBox change
|
||
void CInDefTableDlg::slotComboxSelectChange(int index)
|
||
{
|
||
if(! m_pUI->tableWidget->isActiveWindow())
|
||
return;
|
||
//刷新当前字段内容
|
||
|
||
//QWidget *widget=m_pUI->tableWidget->cellWidget(row,col);
|
||
QComboBox *combox = (QComboBox*)sender();
|
||
|
||
int row = combox->property("row").toInt();
|
||
int col = combox->property("col").toInt();
|
||
|
||
int colIndex = index;
|
||
if(!CurItemType && col == 0)
|
||
WellNameList.clear();//whp add 2020.3.6
|
||
for(int Row = 0; Row < MapData.count(); Row++)
|
||
{
|
||
QStringList List = MapData.find(Row).value();
|
||
QString DataStr;
|
||
int FirstCol = 0;
|
||
if(!CurItemType)
|
||
FirstCol = 1;
|
||
|
||
if(colIndex>=0&&colIndex < List.size())
|
||
DataStr = List[colIndex];
|
||
else
|
||
{
|
||
// if(TableType<DefTabNum)
|
||
// if(DefauleTable[TableType].tinfo[col-FirstCol].RepCode != 6)
|
||
// DataStr = m_pUI->comboBox_DefValue->currentText();
|
||
// else
|
||
// DataStr = m_pUI->comboBox_DefStr->currentText();
|
||
}
|
||
m_pUI->tableWidget->setItem(Row+1, col, new QTableWidgetItem(DataStr));
|
||
if(!CurItemType && col == 0)//当前选择项是“井”时,统计所有井名 whp change 2020.3.6
|
||
{
|
||
bool flag=0;
|
||
DataStr=DataStr.toUpper();
|
||
for(int j=0;j<WellNameList.size();j++)
|
||
{
|
||
if(WellNameList.at(j)!=DataStr)continue;
|
||
flag=1;break;
|
||
}
|
||
if(!flag)WellNameList.append(DataStr);
|
||
}
|
||
}
|
||
//当前选择项是“井”时,刷新井名列表
|
||
if(CurItemType==0&&row==0&&col==0)//if(CurItemType==0&&row==0)whp change 2020.3.6
|
||
{
|
||
// m_mutlWell->tableWidget_WellName->clearContents();
|
||
// m_mutlWell->tableWidget_WellName->setColumnCount(1);
|
||
// QStringList header;
|
||
// header<<"井名";
|
||
// m_mutlWell->tableWidget_WellName->setHorizontalHeaderLabels(header);
|
||
// m_mutlWell->tableWidget_WellName->horizontalHeader()->setStretchLastSection(true);
|
||
// m_mutlWell->tableWidget_WellName->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
|
||
// m_mutlWell->tableWidget_WellName->setRowCount(WellNameList.size());
|
||
// for(int i=0;i<WellNameList.size();i++)
|
||
// {
|
||
// m_mutlWell->tableWidget_WellName->setItem(i,0,new QTableWidgetItem(WellNameList.at(i)));
|
||
// m_mutlWell->tableWidget_WellName->item(i,0)->setCheckState(Qt::Checked);
|
||
// }
|
||
}
|
||
|
||
}
|
||
|
||
void CInDefTableDlg::accept()
|
||
{
|
||
//throw std::logic_error("The method or operation is not implemented.");
|
||
QDialog::done(Rejected);
|
||
}
|
||
void CInDefTableDlg::resizeEvent(QResizeEvent *pEvent)
|
||
{
|
||
QDialog::resizeEvent(pEvent);
|
||
|
||
//m_pUI->tableWidget->horizontalHeader()->resizeSections(QHeaderView::Stretch);
|
||
// m_pUI->tableWidget->horizontalHeader()->setResizeMode(1,QHeaderView::ResizeToContents);
|
||
if(m_pUI->tableWidget->columnCount()<10)m_pUI->tableWidget->horizontalHeader()->resizeSections(QHeaderView::Stretch);
|
||
else m_pUI->tableWidget->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
|
||
|
||
if(MaxCol<10)m_pUI->tableWidget_1->horizontalHeader()->resizeSections(QHeaderView::Stretch);
|
||
else m_pUI->tableWidget_1->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
|
||
// m_pUI->tableWidget_1->horizontalHeader()->resizeSections(QHeaderView::Stretch);
|
||
}
|
||
|
||
void CInDefTableDlg::showEvent(QShowEvent * pEvent)
|
||
{
|
||
QDialog::showEvent(pEvent);
|
||
// if(m_bFirstShow)
|
||
{
|
||
|
||
// m_pUI->tableWidget->horizontalHeader()->resizeSections(QHeaderView::Stretch);
|
||
//m_pUI->tableWidget->horizontalHeader()->setResizeMode(1,QHeaderView::ResizeToContents);
|
||
if(m_pUI->tableWidget->columnCount()<10)m_pUI->tableWidget->horizontalHeader()->resizeSections(QHeaderView::Stretch);
|
||
else m_pUI->tableWidget->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
|
||
|
||
if(MaxCol<10)m_pUI->tableWidget_1->horizontalHeader()->resizeSections(QHeaderView::Stretch);
|
||
else m_pUI->tableWidget_1->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
|
||
//m_pUI->tableWidget_1->horizontalHeader()->resizeSections(QHeaderView::Stretch);
|
||
//m_bFirstShow =false;
|
||
}
|
||
|
||
}
|
||
//END_OSGGRAPHICS_NAMESPACE
|