GridFrame/source/createEditor.cpp

80 lines
2.1 KiB
C++

#include <QPushButton>
#include <QMessageBox>
#include "createEditor.h"
#include "projectManager.h"
#include "ui_createEditor.h"
#include "titleBar.h"
#include "diagramView.h"
CreateEditor::CreateEditor(QWidget *parent,DiagramView* p)
: QDialog(parent)
, ui(new Ui::createEditor)
, m_pView(p)
{
ui->setupUi(this);
setWindowModality(Qt::ApplicationModal);
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
initial();
QScreen *screen = this->screen() ? this->screen()
: QGuiApplication::primaryScreen();
move(screen->availableGeometry().center() - rect().center()); //linux
}
CreateEditor::~CreateEditor()
{
delete ui;
}
void CreateEditor::initial()
{
m_titleBar = new TitleBar(this);
m_titleBar->setTitle("新建");
ui->verticalLayout->insertWidget(0,m_titleBar);
connect(ui->btn_ok,&QPushButton::clicked,this,&CreateEditor::onOkClicked);
connect(ui->btn_cancel,&QPushButton::clicked,this,&CreateEditor::onCancelClicked);
}
void CreateEditor::showDlg()
{
show();
ui->le_name->clear();
}
void CreateEditor::onOkClicked()
{
bool val = m_pView->projectExist();
if(val){
QMessageBox msgBox;
msgBox.setText(QString::fromWCharArray(L"提示"));
msgBox.setInformativeText(QString::fromWCharArray(L"该操作将导致未保存数据丢失,是否继续"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Ok:
break;
case QMessageBox::Cancel:
return;
break;
default:
// should never be reached
break;
}
}
emit projectCreated();
bool res = ProjectManager::instance().createEditorProject(ui->le_name->text());
if(res){
QMessageBox::information(NULL, QString("提示"), QString::fromWCharArray(L"项目名已存在"));
return;
}
hide();
}
void CreateEditor::onCancelClicked()
{
hide();
}