|
|
|
|
@ -4,9 +4,15 @@
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QDesktopServices>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QClipboard>
|
|
|
|
|
#include <qnumeric.h>
|
|
|
|
|
|
|
|
|
|
#include "nmDataAnalyzeManager.h"
|
|
|
|
|
#include "nmDataFracture.h"
|
|
|
|
|
@ -14,9 +20,24 @@
|
|
|
|
|
#include "nmPlotGraphicBinder.h"
|
|
|
|
|
#include "nmObjLineCrack.h"
|
|
|
|
|
#include "ZxPlot.h"
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
|
|
|
|
|
|
|
#include "ExcelUtils.h"
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
QString initialImportDirectory()
|
|
|
|
|
{
|
|
|
|
|
QString directory = ZxBaseUtil::getLastDir();
|
|
|
|
|
if (directory.isEmpty() || !QDir(directory).exists()) {
|
|
|
|
|
directory = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
|
|
|
|
|
}
|
|
|
|
|
if (directory.isEmpty() || !QDir(directory).exists()) {
|
|
|
|
|
directory = QDir::homePath();
|
|
|
|
|
}
|
|
|
|
|
return directory;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构造函数
|
|
|
|
|
nmWxDFNLoadFromFile::nmWxDFNLoadFromFile(QWidget* pParent)
|
|
|
|
|
: iDlgBase(pParent)
|
|
|
|
|
@ -24,10 +45,6 @@ nmWxDFNLoadFromFile::nmWxDFNLoadFromFile(QWidget* pParent)
|
|
|
|
|
this->setWindowTitle(tr("Load from file..."));
|
|
|
|
|
this->setMinimumSize(861, 708);
|
|
|
|
|
|
|
|
|
|
QString appDir = QCoreApplication::applicationDirPath();
|
|
|
|
|
appDir = appDir.section('/', 0, -2); // 获取上一级目录
|
|
|
|
|
m_sLastOpenedFilePath = appDir + "/Temp/DFN";
|
|
|
|
|
|
|
|
|
|
this->initUI();
|
|
|
|
|
this->initConnections();
|
|
|
|
|
|
|
|
|
|
@ -73,6 +90,8 @@ void nmWxDFNLoadFromFile::initUI()
|
|
|
|
|
m_pLoadTxtButton->setIcon(loadTXTIcon);
|
|
|
|
|
m_pLoadExcelButton->setIcon(loadExcelIcon);
|
|
|
|
|
m_pCopyButton->setIcon(loadCopyIcon);
|
|
|
|
|
m_pCopyButton->setToolTip(tr("Paste from clipboard"));
|
|
|
|
|
m_pCopyButton->setAccessibleName(tr("Paste from clipboard"));
|
|
|
|
|
|
|
|
|
|
// 设置图标大小
|
|
|
|
|
int iconSize = 32;
|
|
|
|
|
@ -122,7 +141,7 @@ void nmWxDFNLoadFromFile::initUI()
|
|
|
|
|
|
|
|
|
|
m_pOtherSeparatorEdit = new QLineEdit(this);
|
|
|
|
|
m_pOtherSeparatorEdit->setMaximumWidth(50);
|
|
|
|
|
m_pOtherSeparatorEdit->setText(";"); // 默认自定义分隔符为分号
|
|
|
|
|
m_pOtherSeparatorEdit->setText(";,"); // 默认支持分号和逗号
|
|
|
|
|
|
|
|
|
|
QVBoxLayout* pSepLayout = new QVBoxLayout(m_pSeparatorGroup);
|
|
|
|
|
pSepLayout->addWidget(m_pSpaceCheck);
|
|
|
|
|
@ -188,6 +207,7 @@ void nmWxDFNLoadFromFile::initConnections()
|
|
|
|
|
|
|
|
|
|
connect(m_pLoadTxtButton, SIGNAL(clicked()), this, SLOT(onLoadTxtClicked()));
|
|
|
|
|
connect(m_pLoadExcelButton, SIGNAL(clicked()), this, SLOT(onLoadExcelClicked()));
|
|
|
|
|
connect(m_pCopyButton, SIGNAL(clicked()), this, SLOT(onLoadClipboardClicked()));
|
|
|
|
|
connect(m_pBrowseButton, SIGNAL(clicked()), this, SLOT(onBrowseClicked()));
|
|
|
|
|
|
|
|
|
|
connect(m_pColumnTable, SIGNAL(cellClicked(int, int)), this, SLOT(onTableClicked(int, int)));
|
|
|
|
|
@ -233,7 +253,7 @@ void nmWxDFNLoadFromFile::setupTable()
|
|
|
|
|
|
|
|
|
|
// 设置垂直表头
|
|
|
|
|
QStringList verticalHeaders;
|
|
|
|
|
verticalHeaders << "Column" << "Type" << "Unit";
|
|
|
|
|
verticalHeaders << tr("Column") << tr("Type") << tr("Unit");
|
|
|
|
|
m_pColumnTable->setVerticalHeaderLabels(verticalHeaders);
|
|
|
|
|
|
|
|
|
|
// 设置表头样式
|
|
|
|
|
@ -262,7 +282,7 @@ void nmWxDFNLoadFromFile::onLoadTxtClicked()
|
|
|
|
|
QString filePath = QFileDialog::getOpenFileName(
|
|
|
|
|
this,
|
|
|
|
|
tr("Open Text File"),
|
|
|
|
|
m_sLastOpenedFilePath,
|
|
|
|
|
initialImportDirectory(),
|
|
|
|
|
tr("Text Files (*.txt);;All Files (*)")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@ -277,27 +297,17 @@ void nmWxDFNLoadFromFile::onLoadTxtClicked()
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_sLastOpenedFilePath = filePath;
|
|
|
|
|
m_pFilePathEdit->setText(filePath);
|
|
|
|
|
|
|
|
|
|
// 读取文件内容
|
|
|
|
|
QStringList lines = readFileContent(filePath);
|
|
|
|
|
if (lines.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析内容
|
|
|
|
|
QRegExp separatorRegex = buildSeparatorRegex();
|
|
|
|
|
QList<QStringList> parsedData;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < lines.size(); ++i) {
|
|
|
|
|
parsedData << lines[i].split(separatorRegex, QString::SkipEmptyParts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理数据
|
|
|
|
|
clearDataRows();
|
|
|
|
|
setupTableColumns(parsedData.isEmpty() ? 0 : parsedData[0].size());
|
|
|
|
|
populateDataRows(parsedData);
|
|
|
|
|
ZxBaseUtil::setLastDir(QFileInfo(filePath).absolutePath());
|
|
|
|
|
m_clipboardText.clear();
|
|
|
|
|
m_pFilePathEdit->setReadOnly(false);
|
|
|
|
|
m_pFilePathEdit->setText(filePath);
|
|
|
|
|
showParsedData(parseTextLines(lines));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxDFNLoadFromFile::onLoadExcelClicked()
|
|
|
|
|
@ -305,7 +315,7 @@ void nmWxDFNLoadFromFile::onLoadExcelClicked()
|
|
|
|
|
QString filePath = QFileDialog::getOpenFileName(
|
|
|
|
|
this,
|
|
|
|
|
tr("Open Excel File"),
|
|
|
|
|
m_sLastOpenedFilePath,
|
|
|
|
|
initialImportDirectory(),
|
|
|
|
|
tr("Excel Files (*.xls *.xlsx);;All Files (*)")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@ -321,19 +331,28 @@ void nmWxDFNLoadFromFile::onLoadExcelClicked()
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_sLastOpenedFilePath = filePath;
|
|
|
|
|
m_pFilePathEdit->setText(filePath);
|
|
|
|
|
|
|
|
|
|
// 解析Excel数据
|
|
|
|
|
QList<QStringList> excelData = parseExcelData(filePath);
|
|
|
|
|
if (excelData.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理数据
|
|
|
|
|
clearDataRows();
|
|
|
|
|
setupTableColumns(excelData.isEmpty() ? 0 : excelData[0].size());
|
|
|
|
|
populateDataRows(excelData);
|
|
|
|
|
ZxBaseUtil::setLastDir(QFileInfo(filePath).absolutePath());
|
|
|
|
|
m_clipboardText.clear();
|
|
|
|
|
m_pFilePathEdit->setReadOnly(false);
|
|
|
|
|
m_pFilePathEdit->setText(filePath);
|
|
|
|
|
showParsedData(excelData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxDFNLoadFromFile::onLoadClipboardClicked()
|
|
|
|
|
{
|
|
|
|
|
const QString text = QApplication::clipboard()->text();
|
|
|
|
|
if (text.trimmed().isEmpty()) return;
|
|
|
|
|
|
|
|
|
|
m_clipboardText = text;
|
|
|
|
|
m_pFilePathEdit->setReadOnly(true);
|
|
|
|
|
m_pFilePathEdit->setText(tr("Clipboard"));
|
|
|
|
|
updateSeparators();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxDFNLoadFromFile::onBrowseClicked()
|
|
|
|
|
@ -341,7 +360,7 @@ void nmWxDFNLoadFromFile::onBrowseClicked()
|
|
|
|
|
QString filePath = QFileDialog::getOpenFileName(
|
|
|
|
|
this,
|
|
|
|
|
tr("Open Text File"),
|
|
|
|
|
m_sLastOpenedFilePath,
|
|
|
|
|
initialImportDirectory(),
|
|
|
|
|
tr("Text Files (*.txt);;All Files (*)")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@ -356,27 +375,17 @@ void nmWxDFNLoadFromFile::onBrowseClicked()
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_sLastOpenedFilePath = filePath;
|
|
|
|
|
m_pFilePathEdit->setText(filePath);
|
|
|
|
|
|
|
|
|
|
// 读取文件内容
|
|
|
|
|
QStringList lines = readFileContent(filePath);
|
|
|
|
|
if (lines.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析内容
|
|
|
|
|
QRegExp separatorRegex = buildSeparatorRegex();
|
|
|
|
|
QList<QStringList> parsedData;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < lines.size(); ++i) {
|
|
|
|
|
parsedData << lines[i].split(separatorRegex, QString::SkipEmptyParts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理数据
|
|
|
|
|
clearDataRows();
|
|
|
|
|
setupTableColumns(parsedData.isEmpty() ? 0 : parsedData[0].size());
|
|
|
|
|
populateDataRows(parsedData);
|
|
|
|
|
ZxBaseUtil::setLastDir(QFileInfo(filePath).absolutePath());
|
|
|
|
|
m_clipboardText.clear();
|
|
|
|
|
m_pFilePathEdit->setReadOnly(false);
|
|
|
|
|
m_pFilePathEdit->setText(filePath);
|
|
|
|
|
showParsedData(parseTextLines(lines));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxDFNLoadFromFile::onTableClicked(int row, int col)
|
|
|
|
|
@ -404,11 +413,12 @@ void nmWxDFNLoadFromFile::onTableClicked(int row, int col)
|
|
|
|
|
|
|
|
|
|
// 根据行设置不同的选项
|
|
|
|
|
if (row == 1) { // Type行
|
|
|
|
|
comboBox->addItems(m_allTypeOptions);
|
|
|
|
|
foreach (const QString& type, m_allTypeOptions) {
|
|
|
|
|
comboBox->addItem(type == "UnDefined" ? tr("UnDefined") : type, type);
|
|
|
|
|
}
|
|
|
|
|
} else { // Unit行 - 根据Type动态生成选项
|
|
|
|
|
// 获取当前列的Type值
|
|
|
|
|
QTableWidgetItem* typeItem = m_pColumnTable->item(1, col);
|
|
|
|
|
QString typeValue = typeItem ? typeItem->text() : "UnDefined";
|
|
|
|
|
QString typeValue = columnType(col);
|
|
|
|
|
|
|
|
|
|
// 获取对应的单位选项列表
|
|
|
|
|
QStringList unitOptions = m_typeToUnitOptions.value(typeValue);
|
|
|
|
|
@ -445,7 +455,7 @@ void nmWxDFNLoadFromFile::onCellChanged(int row, int col)
|
|
|
|
|
// 获取新的Type值
|
|
|
|
|
QTableWidgetItem* typeItem = m_pColumnTable->item(1, col);
|
|
|
|
|
if (!typeItem) return;
|
|
|
|
|
QString newType = typeItem->text();
|
|
|
|
|
QString newType = columnType(col);
|
|
|
|
|
|
|
|
|
|
// 获取对应的默认Unit
|
|
|
|
|
QString defaultUnit = m_typeToDefaultUnit.value(newType, "");
|
|
|
|
|
@ -474,9 +484,11 @@ void nmWxDFNLoadFromFile::closeOpenComboBox()
|
|
|
|
|
// 保存值到表格项
|
|
|
|
|
QTableWidgetItem* item = m_pColumnTable->item(r, c);
|
|
|
|
|
if (item) {
|
|
|
|
|
if (r == 1) item->setData(Qt::UserRole, comboBox->itemData(comboBox->currentIndex()));
|
|
|
|
|
item->setText(selectedText);
|
|
|
|
|
} else {
|
|
|
|
|
item = new QTableWidgetItem(selectedText);
|
|
|
|
|
if (r == 1) item->setData(Qt::UserRole, comboBox->itemData(comboBox->currentIndex()));
|
|
|
|
|
item->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
m_pColumnTable->setItem(r, c, item);
|
|
|
|
|
}
|
|
|
|
|
@ -491,6 +503,11 @@ void nmWxDFNLoadFromFile::closeOpenComboBox()
|
|
|
|
|
|
|
|
|
|
void nmWxDFNLoadFromFile::updateSeparators()
|
|
|
|
|
{
|
|
|
|
|
if (!m_clipboardText.isEmpty()) {
|
|
|
|
|
showParsedData(parseTextLines(m_clipboardText.split(QRegExp("\\r\\n|[\\r\\n]"))));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查是否有文件加载
|
|
|
|
|
QString filePath = m_pFilePathEdit->text();
|
|
|
|
|
if (filePath.isEmpty()) {
|
|
|
|
|
@ -508,24 +525,13 @@ void nmWxDFNLoadFromFile::updateSeparators()
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析内容
|
|
|
|
|
QRegExp separatorRegex = buildSeparatorRegex();
|
|
|
|
|
QList<QStringList> parsedData;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < lines.size(); ++i) {
|
|
|
|
|
parsedData << lines[i].split(separatorRegex, QString::SkipEmptyParts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理数据
|
|
|
|
|
clearDataRows();
|
|
|
|
|
setupTableColumns(parsedData.isEmpty() ? 0 : parsedData[0].size());
|
|
|
|
|
populateDataRows(parsedData);
|
|
|
|
|
showParsedData(parseTextLines(lines));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxDFNLoadFromFile::onOkClicked()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
closeOpenComboBox();
|
|
|
|
|
QVector<DFNData> vecDatas;
|
|
|
|
|
|
|
|
|
|
// 检查是否有足够的数据行(至少4行:表头+1行数据)
|
|
|
|
|
@ -544,11 +550,7 @@ void nmWxDFNLoadFromFile::onOkClicked()
|
|
|
|
|
QVector<QString> columnTypes;
|
|
|
|
|
|
|
|
|
|
for (int col = 0; col < m_pColumnTable->columnCount(); ++col) {
|
|
|
|
|
QTableWidgetItem* typeItem = m_pColumnTable->item(1, col);
|
|
|
|
|
|
|
|
|
|
QString type = typeItem ? typeItem->text() : "UnDefined";
|
|
|
|
|
|
|
|
|
|
columnTypes.append(type);
|
|
|
|
|
columnTypes.append(columnType(col));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查是否设置了必需的列(X1, Y1, X2, Y2)
|
|
|
|
|
@ -565,7 +567,7 @@ void nmWxDFNLoadFromFile::onOkClicked()
|
|
|
|
|
|
|
|
|
|
// 从第4行开始读取数据(前3行是表头)
|
|
|
|
|
for (int row = 3; row < m_pColumnTable->rowCount(); ++row) {
|
|
|
|
|
DFNData dataRow;
|
|
|
|
|
DFNData dataRow = {0};
|
|
|
|
|
|
|
|
|
|
// 检查是否定义了Fc、Wf、o列
|
|
|
|
|
bool hasFc = columnTypes.contains("Fc");
|
|
|
|
|
@ -582,9 +584,15 @@ void nmWxDFNLoadFromFile::onOkClicked()
|
|
|
|
|
QTableWidgetItem* item = m_pColumnTable->item(row, col);
|
|
|
|
|
QString value = item ? item->text() : "";
|
|
|
|
|
QString type = columnTypes[col];
|
|
|
|
|
if (type == "UnDefined") continue;
|
|
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
|
double numValue = value.toDouble(&ok);
|
|
|
|
|
if (!ok || !qIsFinite(numValue)) {
|
|
|
|
|
QMessageBox::warning(this, tr("Import Error"),
|
|
|
|
|
tr("Invalid numeric value at data row %1, column %2.").arg(row - 2).arg(col + 1));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type == "X1") {
|
|
|
|
|
if (ok) dataRow.x1 = numValue;
|
|
|
|
|
@ -635,9 +643,9 @@ void nmWxDFNLoadFromFile::onOkClicked()
|
|
|
|
|
vecPts.append(pt1);
|
|
|
|
|
vecPts.append(pt2);
|
|
|
|
|
pFractrue->setFracturePoints(vecPts);
|
|
|
|
|
// 裂缝流动类型,默认为无限导流
|
|
|
|
|
// 保存固定的有限导流模型标识,中文翻译仅用于界面显示。
|
|
|
|
|
nmDataAttribute tempAttr = pFractrue->getFractureFlowModel();
|
|
|
|
|
tempAttr.setValue(tr("Finite Conductivity"));
|
|
|
|
|
tempAttr.setValue(QString::fromLatin1("Finite Conductivity"));
|
|
|
|
|
pFractrue->setFractureFlowModel(tempAttr);
|
|
|
|
|
// 裂缝导流能力
|
|
|
|
|
tempAttr = pFractrue->getFractureDfc();
|
|
|
|
|
@ -694,20 +702,70 @@ void nmWxDFNLoadFromFile::clearDataRows()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建分隔符正则表达式
|
|
|
|
|
QRegExp nmWxDFNLoadFromFile::buildSeparatorRegex() const
|
|
|
|
|
// 保留制表符、逗号等分隔符之间的空单元格,避免缺值时后续坐标错列。
|
|
|
|
|
QList<QStringList> nmWxDFNLoadFromFile::parseTextLines(const QStringList& lines) const
|
|
|
|
|
{
|
|
|
|
|
QStringList separators;
|
|
|
|
|
if (m_pSpaceCheck->isChecked()) {
|
|
|
|
|
separators << " ";
|
|
|
|
|
}
|
|
|
|
|
if (m_pTabCheck->isChecked()) {
|
|
|
|
|
separators << "\\t";
|
|
|
|
|
QString separators = m_pOtherSeparatorEdit->text();
|
|
|
|
|
if (m_pTabCheck->isChecked()) separators += QChar('\t');
|
|
|
|
|
const QRegExp delimiter(QString("[%1]").arg(QRegExp::escape(separators)));
|
|
|
|
|
QList<QStringList> rows;
|
|
|
|
|
foreach (const QString& line, lines) {
|
|
|
|
|
if (line.trimmed().isEmpty()) continue;
|
|
|
|
|
const bool hasTabs = m_pTabCheck->isChecked() && line.contains(QChar('\t'));
|
|
|
|
|
const bool hasExplicitDelimiter = hasTabs || (!separators.isEmpty() && line.contains(delimiter));
|
|
|
|
|
const QStringList cells = hasTabs ? line.split(QChar('\t'), QString::KeepEmptyParts)
|
|
|
|
|
: (separators.isEmpty() ? QStringList(line) : line.split(delimiter, QString::KeepEmptyParts));
|
|
|
|
|
QStringList row;
|
|
|
|
|
foreach (const QString& cell, cells) {
|
|
|
|
|
if (!hasExplicitDelimiter && m_pSpaceCheck->isChecked() && !cell.trimmed().isEmpty()) {
|
|
|
|
|
row += cell.trimmed().split(QRegExp(" +"), QString::SkipEmptyParts);
|
|
|
|
|
} else {
|
|
|
|
|
row << cell.trimmed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rows << row;
|
|
|
|
|
}
|
|
|
|
|
if (!m_pOtherSeparatorEdit->text().isEmpty()) {
|
|
|
|
|
separators << QRegExp::escape(m_pOtherSeparatorEdit->text());
|
|
|
|
|
return rows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxDFNLoadFromFile::showParsedData(const QList<QStringList>& dataLines)
|
|
|
|
|
{
|
|
|
|
|
closeOpenComboBox();
|
|
|
|
|
clearDataRows();
|
|
|
|
|
int columnCount = 0;
|
|
|
|
|
foreach (const QStringList& row, dataLines) columnCount = qMax(columnCount, row.size());
|
|
|
|
|
setupTableColumns(columnCount);
|
|
|
|
|
if (dataLines.isEmpty()) return;
|
|
|
|
|
|
|
|
|
|
// 识别包含四个坐标字段的表头,其余非数据列(如名称)默认忽略。
|
|
|
|
|
QStringList headerTypes;
|
|
|
|
|
foreach (const QString& value, dataLines.first()) {
|
|
|
|
|
QString type = "UnDefined";
|
|
|
|
|
foreach (const QString& candidate, m_allTypeOptions) {
|
|
|
|
|
if (value.trimmed().compare(candidate, Qt::CaseInsensitive) == 0) {
|
|
|
|
|
type = candidate;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
headerTypes << type;
|
|
|
|
|
}
|
|
|
|
|
const bool hasHeader = headerTypes.contains("X1") && headerTypes.contains("Y1")
|
|
|
|
|
&& headerTypes.contains("X2") && headerTypes.contains("Y2");
|
|
|
|
|
if (hasHeader) {
|
|
|
|
|
for (int col = 0; col < columnCount; ++col) {
|
|
|
|
|
const QString type = headerTypes.value(col, "UnDefined");
|
|
|
|
|
QTableWidgetItem* item = m_pColumnTable->item(1, col);
|
|
|
|
|
item->setData(Qt::UserRole, type);
|
|
|
|
|
item->setText(type == "UnDefined" ? tr("UnDefined") : type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QRegExp(QString("[%1]+").arg(separators.join("")));
|
|
|
|
|
populateDataRows(hasHeader ? dataLines.mid(1) : dataLines);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString nmWxDFNLoadFromFile::columnType(int column) const
|
|
|
|
|
{
|
|
|
|
|
QTableWidgetItem* item = m_pColumnTable->item(1, column);
|
|
|
|
|
return item ? item->data(Qt::UserRole).toString() : QString("UnDefined");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置表格列
|
|
|
|
|
@ -717,13 +775,16 @@ void nmWxDFNLoadFromFile::setupTableColumns(int columnCount)
|
|
|
|
|
|
|
|
|
|
for (int col = 0; col < columnCount; ++col) {
|
|
|
|
|
// Column行
|
|
|
|
|
QTableWidgetItem* colItem = new QTableWidgetItem(QString("Column %1").arg(col + 1));
|
|
|
|
|
QTableWidgetItem* colItem = new QTableWidgetItem(tr("Column %1").arg(col + 1));
|
|
|
|
|
colItem->setFlags((colItem->flags() & ~Qt::ItemIsEditable) | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
|
|
|
|
m_pColumnTable->setItem(0, col, colItem);
|
|
|
|
|
|
|
|
|
|
// Type行
|
|
|
|
|
QString defaultType = (col < m_allTypeOptions.size()) ? m_allTypeOptions[col] : "UnDefined";
|
|
|
|
|
m_pColumnTable->setItem(1, col, new QTableWidgetItem(defaultType));
|
|
|
|
|
QTableWidgetItem* typeItem = new QTableWidgetItem(defaultType == "UnDefined" ? tr("UnDefined") : defaultType);
|
|
|
|
|
typeItem->setData(Qt::UserRole, defaultType);
|
|
|
|
|
typeItem->setFlags(typeItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
m_pColumnTable->setItem(1, col, typeItem);
|
|
|
|
|
|
|
|
|
|
// Unit行
|
|
|
|
|
QString defaultUnit = m_typeToDefaultUnit.value(defaultType, "");
|
|
|
|
|
@ -758,8 +819,8 @@ QStringList nmWxDFNLoadFromFile::readFileContent(const QString& filePath)
|
|
|
|
|
|
|
|
|
|
QTextStream in(&file);
|
|
|
|
|
while (!in.atEnd()) {
|
|
|
|
|
QString line = in.readLine().trimmed();
|
|
|
|
|
if (!line.isEmpty()) {
|
|
|
|
|
QString line = in.readLine();
|
|
|
|
|
if (!line.trimmed().isEmpty()) {
|
|
|
|
|
lines << line;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|