Added support for creating new form documents

This commit is contained in:
dfighter1985 2014-09-03 19:55:46 +02:00
parent 256d72fe62
commit 6457ab90eb
3 changed files with 71 additions and 32 deletions

View file

@ -173,6 +173,39 @@ namespace GeorgesQt
void GeorgesEditorForm::newForm()
{
QString dfnFileName = QFileDialog::getOpenFileName( this,
tr( "New Form" ),
"",
"Definition files (*.dfn)" );
if( dfnFileName.isEmpty() )
return;
QFileInfo dfnInfo( dfnFileName );
QString baseName = dfnInfo.baseName();
QString filter;
filter += baseName;
filter += " files (*.";
filter += baseName;
filter += ")";
QString fileName = QFileDialog::getSaveFileName( this,
tr( "New Form" ),
"",
filter );
if( fileName.isEmpty() )
return;
CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog();
if( !d->newDocument( fileName, dfnFileName ) )
{
QMessageBox::information( this,
tr( "Failed to create new form" ),
tr( "Failed to create new form!" ) );
return;
}
addGeorgesWidget( d );
setModified();
}
void GeorgesEditorForm::save()

View file

@ -159,8 +159,6 @@ namespace GeorgesQt
}
NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByDfnName(const QString dfnName)
{
if(NLMISC::CPath::exists(dfnName.toAscii().data()))
{
// Create a new form object.
NLGEORGES::CForm *form = new NLGEORGES::CForm();
@ -182,9 +180,6 @@ namespace GeorgesQt
return form;
}
nlinfo("File '%s' does not exist!", dfnName.toAscii().data());
return NULL;
}
NLGEORGES::CFormElm *CGeorgesTreeViewDialog::getRootNode(uint slot)
{
@ -311,19 +306,9 @@ namespace GeorgesQt
bool CGeorgesTreeViewDialog::load( const QString &fileName )
{
bool loadFromDFN = false;
// Retrieve the form and load the form.
NLGEORGES::CForm *form;
if(loadFromDFN)
{
// Get the form by DFN name.
form = getFormByDfnName(fileName);
}
else
{
form = getFormByName(fileName);
}
NLGEORGES::CForm *form = getFormByName(fileName);
if( form == NULL )
return false;
@ -421,6 +406,26 @@ namespace GeorgesQt
}
}
bool CGeorgesTreeViewDialog::newDocument( const QString &fileName, const QString &dfn )
{
NLGEORGES::CForm *form = getFormByDfnName(dfn);
if( form == NULL )
return false;
setForm(form);
loadFormIntoDialog(form);
QApplication::processEvents();
m_fileName = fileName;
QFileInfo info( fileName );
setWindowTitle( info.fileName() + "*" );
setModified( true );
return true;
}
void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index )
{
//CGeorgesFormModel *model =

View file

@ -71,6 +71,7 @@ namespace GeorgesQt
bool load( const QString &fileName );
void write ( );
bool newDocument( const QString &fileName, const QString &dfn );
QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; }