147 lines
4.2 KiB
C++
147 lines
4.2 KiB
C++
/**
|
|
* @file PaiSaveAsWorkflowDialog.cpp
|
|
*/
|
|
#include "PaiSaveAsWorkflowDialog.h"
|
|
#include "PaiProjectComboBox.h"
|
|
#include "PaiPushButton.h"
|
|
#include "PaiObject.h"
|
|
#include "PaiLineEdit.h"
|
|
#include "PaiSurvey.h"
|
|
#include "GlobalUtility.h"
|
|
#include "WorkflowConst.h"
|
|
#include "SaveHelper.h"
|
|
#include "PaiLabel.h"
|
|
#include "PaiNameLineEdit.h"
|
|
|
|
#include <QFrame>
|
|
#include <QLabel>
|
|
#include <QCloseEvent>
|
|
#include <QHBoxLayout>
|
|
#include <QVBoxLayout>
|
|
#include <QString>
|
|
|
|
using namespace pai;
|
|
using namespace pai::gui;
|
|
using namespace pai::objectmodel;
|
|
|
|
|
|
|
|
PaiSaveAsWorkflowDialog::PaiSaveAsWorkflowDialog(long long /*defaultProject*/, long long defaultSurvey, const QString &workflowName, QWidget *parent)
|
|
: PaiDialog(parent)
|
|
{
|
|
setWindowTitle(tr(g_szSaveAs));
|
|
QVBoxLayout *pSaveAsLayout = new QVBoxLayout(GetContainer());
|
|
pSaveAsLayout->setSpacing(6);
|
|
pSaveAsLayout->setContentsMargins(9, 9, 9, 9);
|
|
|
|
QLabel* label1 = new QLabel(g_szProjectSurver, this);
|
|
QHBoxLayout *pSurveyLayout = new QHBoxLayout;
|
|
m_pProjectComboBox = new PaiProjectComboBox(new PaiComboBox, this);
|
|
m_pProjectComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
m_pProjectComboBox->GetSurveyComboBox()->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
|
m_pProjectComboBox->SetCurrentSurvey(defaultSurvey);
|
|
pSurveyLayout->addWidget(m_pProjectComboBox);
|
|
pSurveyLayout->addWidget(new QLabel("/"));
|
|
pSurveyLayout->addWidget(m_pProjectComboBox->GetSurveyComboBox());
|
|
|
|
QLabel* label2 = new QLabel(g_szWorkflowName, this);
|
|
m_WorkflowNameLEdit = new PaiNameLineEdit();
|
|
PaiLabel *pMaxLenMsg = new PaiLabel();
|
|
QVBoxLayout *pBobLayout = new QVBoxLayout();
|
|
pBobLayout->setSpacing(0);
|
|
pBobLayout->addWidget(m_WorkflowNameLEdit);
|
|
pBobLayout->addWidget(pMaxLenMsg);
|
|
|
|
m_WorkflowNameLEdit->SetPromptLabel(pMaxLenMsg);
|
|
|
|
m_WorkflowNameLEdit->setText(workflowName);
|
|
|
|
QHBoxLayout *horizontalLayout = new QHBoxLayout();
|
|
m_SaveBtn = new PaiPushButton(g_szSave, this);
|
|
m_SaveBtn->setFixedSize(85,25);
|
|
m_CancelBtn = new PaiPushButton("Cancel",this);
|
|
m_CancelBtn->setFixedSize(85,25);
|
|
|
|
horizontalLayout->addWidget(m_SaveBtn);
|
|
horizontalLayout->addWidget(m_CancelBtn);
|
|
horizontalLayout->setAlignment(Qt::AlignRight);
|
|
|
|
pSaveAsLayout->addWidget(label1);
|
|
pSaveAsLayout->addLayout(pSurveyLayout);
|
|
pSaveAsLayout->addWidget(label2);
|
|
pSaveAsLayout->addLayout(pBobLayout);
|
|
pSaveAsLayout->addLayout(horizontalLayout);
|
|
this->setMinimumHeight(minimumHeight());
|
|
this->setMaximumHeight(minimumHeight());
|
|
|
|
connect(m_SaveBtn, SIGNAL(clicked()), this, SLOT(accept()));
|
|
connect(m_CancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
|
|
connect(m_WorkflowNameLEdit, SIGNAL(textChanged(const QString &)), this, SLOT(CheckInput()));
|
|
connect(m_pProjectComboBox, SIGNAL(SurveyChanged()), this, SLOT(CheckInput()));
|
|
}
|
|
|
|
PaiSaveAsWorkflowDialog::~PaiSaveAsWorkflowDialog()
|
|
{
|
|
}
|
|
|
|
void PaiSaveAsWorkflowDialog::showEvent(QShowEvent *pEvent)
|
|
{
|
|
if(m_WorkflowNameLEdit != NULL)
|
|
{
|
|
m_WorkflowNameLEdit->selectAll();
|
|
m_WorkflowNameLEdit->setFocus();
|
|
}
|
|
QDialog::showEvent(pEvent);
|
|
}
|
|
|
|
void PaiSaveAsWorkflowDialog::ResetValidateNameEdit()
|
|
{
|
|
if (m_WorkflowNameLEdit != NULL)
|
|
{
|
|
QString maxLenMsg = tr(g_szNameLenght).arg(m_WorkflowNameLEdit->maxLength());
|
|
m_WorkflowNameLEdit->ShowPromptMessge(maxLenMsg, PaiLineEdit::PT_Information);
|
|
}
|
|
}
|
|
|
|
|
|
QString PaiSaveAsWorkflowDialog::GetSaveAsWorkflowName() const
|
|
{
|
|
if(m_WorkflowNameLEdit)
|
|
{
|
|
return m_WorkflowNameLEdit->text();
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
pai::objectmodel::PaiSurvey* PaiSaveAsWorkflowDialog::GetSelectedSurvey() const
|
|
{
|
|
if(m_pProjectComboBox != NULL)
|
|
{
|
|
return m_pProjectComboBox->GetSelectedSurvey();
|
|
}
|
|
else
|
|
{
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
void PaiSaveAsWorkflowDialog::CheckInput()
|
|
{
|
|
ResetValidateNameEdit();
|
|
bool bSurveyEmpty = false;
|
|
pai::objectmodel::PaiSurvey *pSurvey = GetSelectedSurvey();
|
|
if (!pSurvey || pSurvey->GetName().isEmpty())
|
|
{
|
|
bSurveyEmpty = true;
|
|
}
|
|
if(m_SaveBtn && m_WorkflowNameLEdit)
|
|
{
|
|
m_SaveBtn->setDisabled(m_WorkflowNameLEdit->text().isEmpty() || bSurveyEmpty);
|
|
}
|
|
}
|