259 lines
8.3 KiB
C++
259 lines
8.3 KiB
C++
#include "WellLogProjectDialog.h"
|
|
#include "ui_WellLogProjectDialog.h"
|
|
#include <QDir>
|
|
#include <QDoubleValidator>
|
|
#include <QDebug>
|
|
#include "geometryutils.h"
|
|
|
|
CWellLogProjectDialog::CWellLogProjectDialog(QWidget *parent, Qt::WindowFlags flags) :
|
|
WellLogDialog(parent, flags),
|
|
m_bNameFlag(false)
|
|
{
|
|
m_pUI = new Ui::WellLogProjectDialog();
|
|
m_pUI->setupUi(this);
|
|
m_Edit = false;
|
|
QDoubleValidator* dv = new QDoubleValidator(this);
|
|
dv->setNotation(QDoubleValidator::StandardNotation);
|
|
dv->setRange(-1000.00,1000.00,2);
|
|
m_pUI->x1->setValidator(dv);
|
|
m_pUI->x2->setValidator(dv);
|
|
m_pUI->y1->setValidator(dv);
|
|
m_pUI->y2->setValidator(dv);
|
|
|
|
m_pLabel = new CWellLogLabel;
|
|
m_pLabel->setVisible(false);
|
|
m_pUI->horizontalLayout->addWidget(m_pLabel);
|
|
|
|
m_pLabel_basin = new CWellLogLabel;
|
|
m_pLabel_basin->setVisible(false);
|
|
m_pUI->horizontalLayout_4->addWidget(m_pLabel_basin);
|
|
|
|
connect(m_pUI->ProjectName,SIGNAL( textEdited()),this,SLOT(slotOnEditFinishedProjectName() ));
|
|
m_pUI->okbtn->setIcon(QIcon( ::GetImagePath() + "icon/OK.png"));
|
|
m_pUI->cancelbtn->setIcon(QIcon( ::GetImagePath() + "icon/Cancel.png"));
|
|
}
|
|
|
|
CWellLogProjectDialog::~CWellLogProjectDialog()
|
|
{
|
|
delete m_pUI;
|
|
m_pUI = NULL;
|
|
}
|
|
|
|
void CWellLogProjectDialog::slotOnEditFinishedProjectName()
|
|
{
|
|
m_bNameFlag = ValidateProjectName();
|
|
}
|
|
|
|
|
|
void CWellLogProjectDialog::isEdit(bool flag)
|
|
{
|
|
m_Edit = flag;
|
|
}
|
|
void CWellLogProjectDialog::GetOKAndCancel(QPushButton* &okBtn,QPushButton* &cancelBtn)
|
|
{
|
|
okBtn = m_pUI->okbtn;
|
|
cancelBtn = m_pUI->cancelbtn;
|
|
}
|
|
|
|
void CWellLogProjectDialog::DataToView()
|
|
{
|
|
//初始化
|
|
m_pUI->x1->setText("0");
|
|
m_pUI->x2->setText("0");
|
|
m_pUI->y1->setText("0");
|
|
m_pUI->y2->setText("0");
|
|
|
|
// pai::datamodel::CObjProject* project = dynamic_cast<pai::datamodel::CObjProject*>(pObject);
|
|
// if(project != NULL)
|
|
// {
|
|
// QString title = m_Edit == false ? "新建项目":"编辑项目";
|
|
// this->setWindowTitle(title);
|
|
// pai::ios::welllog::Project& pProject = project->GetProject();
|
|
// m_pUI->ProjectName->setText(project->GetName());
|
|
// m_pUI->ownedBasin->setText(QString::fromLocal8Bit(pProject.GetBasin().c_str()));
|
|
// m_pUI->x1->setText(QString::number(pProject.GetX1()));
|
|
// m_pUI->x2->setText(QString::number(pProject.GetX2()));
|
|
// m_pUI->y1->setText(QString::number(pProject.GetY1()));
|
|
// m_pUI->y2->setText(QString::number(pProject.GetY2()));
|
|
// m_pUI->comment->setText(QString::fromLocal8Bit(pProject.GetDescription().c_str()));
|
|
// }
|
|
}
|
|
|
|
void CWellLogProjectDialog::ViewToData()
|
|
{
|
|
// pai::datamodel::CObjProject* project = dynamic_cast<pai::datamodel::CObjProject*>(pObject);
|
|
// if(project != NULL)
|
|
// {
|
|
// pai::ios::welllog::Project& pProject = project->GetProject();
|
|
// project->SetName(m_pUI->ProjectName->text());
|
|
// pProject.SetBasin(m_pUI->ownedBasin->text().toStdString());
|
|
// pProject.SetX1(m_pUI->x1->text().toDouble());
|
|
// pProject.SetX2(m_pUI->x2->text().toDouble());
|
|
// pProject.SetY1(m_pUI->y1->text().toDouble());
|
|
// pProject.SetY2(m_pUI->y2->text().toDouble());
|
|
// pProject.SetDescription(m_pUI->comment->toHtml().toStdString());
|
|
|
|
// }
|
|
}
|
|
|
|
bool CWellLogProjectDialog::ValidateProjectName()
|
|
{
|
|
bool flag =true;
|
|
QString errInfo;
|
|
if(m_pUI->ProjectName->text() == "")
|
|
{
|
|
errInfo = "名称不能为空";
|
|
m_pLabel->ShowPromtMessage(PT_Warning);
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
QString textFormat("^[\\w ]{1,20}$");
|
|
QRegExp rx(textFormat);
|
|
if(!rx.exactMatch(m_pUI->ProjectName->text()))
|
|
{
|
|
QString str = "\"\"";
|
|
errInfo = "1-20个字符,支持中英文,数字,\"_\"格式";
|
|
m_pLabel->ShowPromtMessage(PT_Error);
|
|
m_pUI->ProjectName->setFocus();
|
|
flag = false;
|
|
}
|
|
}
|
|
|
|
if (flag)
|
|
{
|
|
QString strNewName=m_pUI->ProjectName->text();
|
|
m_strNewName = strNewName;
|
|
if(m_Edit)
|
|
{
|
|
//编辑项目
|
|
if(strNewName.compare(m_strOldName, Qt::CaseInsensitive)!=0)
|
|
{
|
|
QString name=GetLogdataPath()+m_strOldName;
|
|
QDir dir(name);
|
|
QString nname=GetLogdataPath()+strNewName;
|
|
if(dir.exists()) {
|
|
QFile file(name);
|
|
if(file.rename(nname)) {
|
|
//
|
|
flag = RenameWellName(m_strOldPath, strNewName);
|
|
if(flag==false)
|
|
{
|
|
errInfo = "无法更改工程名!";
|
|
m_pLabel->ShowPromtMessage(PT_Warning);
|
|
flag=false;
|
|
}
|
|
else {
|
|
//改名成功
|
|
flag=true;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
//AfxMessageBox("无法更改工程名!");
|
|
errInfo = "无法更改工程名!";
|
|
m_pLabel->ShowPromtMessage(PT_Warning);
|
|
flag=false;
|
|
}
|
|
}
|
|
else {
|
|
//AfxMessageBox("无法更改工程名!");
|
|
errInfo = "无法更改工程名!";
|
|
m_pLabel->ShowPromtMessage(PT_Warning);
|
|
flag=false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//新建项目
|
|
QString folderPath=::GetLogdataPath()+strNewName;
|
|
QDir dir;
|
|
if(dir.exists(folderPath)) {
|
|
//if(QMessageBox::warning(NULL,"提示",QString("同名工程已存在,您确认要继续建立该工程吗?"),QMessageBox::Yes,QMessageBox::No)!=QMessageBox::Yes)
|
|
{
|
|
errInfo = "同名工程已存在,请重新设置名称!";
|
|
m_pLabel->ShowPromtMessage(PT_Warning);
|
|
flag=false;
|
|
}
|
|
}
|
|
else {
|
|
// 如果目录不存在,则创建它。
|
|
if (!dir.mkpath(folderPath)) { // mkpath 尝试创建所有必需的中间目录。
|
|
qDebug() << "Failed to create directory:" << folderPath;
|
|
} else {
|
|
qDebug() << "Directory created:" << folderPath;
|
|
}
|
|
//创建文件
|
|
QString strProjectFolder = GetProjectFolder();
|
|
QDir dir2;
|
|
if(!dir2.exists(strProjectFolder)) {
|
|
// 如果目录不存在,则创建它。
|
|
if (!dir.mkpath(strProjectFolder)) { // mkpath 尝试创建所有必需的中间目录。
|
|
qDebug() << "Failed to create directory:" << strProjectFolder;
|
|
} else {
|
|
qDebug() << "Directory created:" << strProjectFolder;
|
|
}
|
|
}
|
|
QString strProjectFile = strProjectFolder + strNewName;
|
|
strProjectFile += ".wwl";
|
|
QFile file(strProjectFile);
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
qDebug() << "Cannot open file for writing:" << strProjectFile;
|
|
errInfo = "无法创建工程文件!";
|
|
m_pLabel->ShowPromtMessage(PT_Warning);
|
|
flag=false;
|
|
}
|
|
else
|
|
{
|
|
// QTextStream out(&file);
|
|
// out << content;
|
|
// file.close();
|
|
// qDebug() << "File saved successfully:" << strProjectFile;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(flag){
|
|
errInfo = "名称验证通过";
|
|
m_pLabel->ShowPromtMessage(PT_Right);
|
|
flag=true;
|
|
}
|
|
// else {
|
|
// errInfo = "名称验证未通过";
|
|
// m_pLabel->ShowPromtMessage(PT_Warning);
|
|
// flag=false;
|
|
// }
|
|
}
|
|
ShowValidatorLabel(m_pLabel,errInfo);
|
|
|
|
return flag;
|
|
}
|
|
|
|
int CWellLogProjectDialog::Validate()
|
|
{
|
|
m_bNameFlag = ValidateProjectName();
|
|
return m_bNameFlag&&
|
|
(m_pUI->x1->text()!="")&&
|
|
(m_pUI->y1->text()!="")&&
|
|
m_pUI->x2->text()!=""&&
|
|
m_pUI->y2->text()!="";
|
|
}
|
|
|
|
void CWellLogProjectDialog::ShowValidatorLabel(CWellLogLabel * pLabel, const QString& strtext)
|
|
{
|
|
QFont textFont;
|
|
textFont.setFamily("宋体");
|
|
textFont.setPointSize(10);
|
|
QFontMetrics fm(textFont);
|
|
pLabel->setText(strtext);
|
|
QRect rec =fm.boundingRect(strtext);
|
|
pLabel->setFixedWidth(rec.width() +16);
|
|
pLabel->setVisible(true);
|
|
}
|
|
|
|
void CWellLogProjectDialog::SetEditFilePath(QString strOldName, QString strPath)
|
|
{
|
|
m_strOldName = strOldName;
|
|
m_strOldPath = strPath;
|
|
}
|