#include "nmWxRCDialog.h" #include #include #include #include #include #include #include #include "ZxBaseUtil.h" #include "nmWxRCWell.h" nmWxRCDialog::nmWxRCDialog() { this->initUI(); this->resize(800, 720); } void nmWxRCDialog::on_save() { // 检查第1列是否都写了值,如何不全则不能提交 QStringList valueList; qDebug() << "================="; for (int row = 0; row < m_pTableWidget->rowCount(); ++row) { QTableWidgetItem* item = m_pTableWidget->item(row, 0); QString value = item->text(); if (value.trimmed().length() == 0) { // TODO,数据是空的,进行提示! return; } valueList.append(value); } // 渲染 QString sDir = ZxBaseUtil::getDirOf(s_Dir_Temp, "Nm/Solver"); QString sFile = sDir + "par.txt"; QFile file(sFile); //检查 if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qWarning("Cannot open file for writing: %s", qPrintable(file.errorString())); return; } QTextStream out(&file); for (int i = 0; i < valueList.size(); i++) { out << valueList[i] << "\n"; } file.close(); this->accept(); } void nmWxRCDialog::initUI() { QVBoxLayout* mainLayout = new QVBoxLayout; this->setLayout(mainLayout); QTabWidget* tabWidget = new QTabWidget; mainLayout->addWidget(tabWidget); // 油藏属性设置 tabWidget->addTab(this->initOilReservoirUI(), tr("OilReservoir")); tabWidget->addTab(this->initWellsUI(), tr("Wells")); // 井属性设置 // 下方的操作按钮 // 底部按钮 QHBoxLayout* hLayout = new QHBoxLayout; QPushButton* saveBT = new QPushButton("Save"); QPushButton* cancelBT = new QPushButton("Cancel"); connect(saveBT, SIGNAL(clicked()), this, SLOT(on_save())); connect(cancelBT, SIGNAL(clicked()), this, SLOT(reject())); hLayout->addStretch(); hLayout->addWidget(saveBT); hLayout->addWidget(cancelBT); mainLayout->addLayout(hLayout); } QWidget* nmWxRCDialog::initOilReservoirUI() { QVBoxLayout* mainLayout = new QVBoxLayout; m_pTableWidget = new QTableWidget; // 设置为3列, // 第一列是 名称,也是垂直的表头 // 第二列是 值 // 第三列是 单位 // 设置表头 m_pTableWidget->setColumnCount(2); // 设置列数为2 m_pTableWidget->setRowCount(7); // 设置行数为7 QStringList horizontalHeaders; horizontalHeaders << tr("value") << tr("unit"); m_pTableWidget->setHorizontalHeaderLabels(horizontalHeaders); m_pTableWidget->horizontalHeader()->setVisible(true); QStringList headers; headers << tr("Initial formation pressure") << tr("permeability") << tr("Reservoir thickness") << tr("Fluid viscosity") << tr("Volume coefficient") << tr("porosity") << tr("Overall compressibility"); // 定义表头内容 m_pTableWidget->setVerticalHeaderLabels(headers); // 设置表头标签 // 获取垂直表头的 QHeaderView 并设置宽度 QHeaderView *verticalHeader = m_pTableWidget->verticalHeader(); verticalHeader->setVisible(true); verticalHeader->setFixedWidth(160); m_pTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch); // 单位列表 QStringList unitList; unitList << "Pa" << "mD" << "m" << "mPa.s" << "-" << "-" << "1/Mpa"; // 各个参数初始值 QVector valueList; valueList.push_back(30); valueList.push_back(100); valueList.push_back(5); valueList.push_back(1); valueList.push_back(1.1); valueList.push_back(0.1); valueList.push_back(0.0035); valueList.push_back(1); // 填充数据 for (int row = 0; row < m_pTableWidget->rowCount(); ++row) { for (int column = 0; column < m_pTableWidget->columnCount(); ++column) { QString content = QString("Row %1, Column %2").arg(row + 1).arg(column + 1); if (column == 1) { content = unitList[row]; } else { content = QString::number(valueList[row]); } QTableWidgetItem *item = new QTableWidgetItem(content); if (column == 1) { item->setFlags(item->flags() & ~Qt::ItemIsEditable); } // 内容居中 item->setTextAlignment(Qt::AlignCenter | Qt::AlignVCenter); m_pTableWidget->setItem(row, column, item); } } return m_pTableWidget; } QWidget* nmWxRCDialog::initWellsUI() { QVector wellNames; wellNames.append("well1"); wellNames.append("well2"); QVector wellRadius; wellRadius.append(0.05); wellRadius.append(0.03); nmWxRCWell* widget = new nmWxRCWell(wellNames, wellRadius, NULL); return widget; }