mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-27 11:20:54 +00:00
Added support for creating new form documents
--HG-- branch : dfighter-tools
This commit is contained in:
parent
37bbb6be32
commit
916810c35d
3 changed files with 71 additions and 32 deletions
|
@ -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()
|
||||
|
|
|
@ -160,30 +160,25 @@ 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();
|
||||
m_form = form;
|
||||
|
||||
// Retrieve a copy of the root definition.
|
||||
NLGEORGES::CFormDfn *formDfn = dynamic_cast<NLGEORGES::CFormDfn *>(m_georges->loadFormDfn(dfnName.toAscii().data()));
|
||||
|
||||
// Next we'll use the root node to build a new form.
|
||||
NLGEORGES::CFormElmStruct *fes = dynamic_cast<NLGEORGES::CFormElmStruct *>(getRootNode(0));
|
||||
fes->build(formDfn);
|
||||
|
||||
// And then initialize the held elements;
|
||||
for(uint i = 0; i<NLGEORGES::CForm::HeldElementCount; i++)
|
||||
{
|
||||
// Create a new form object.
|
||||
NLGEORGES::CForm *form = new NLGEORGES::CForm();
|
||||
m_form = form;
|
||||
|
||||
// Retrieve a copy of the root definition.
|
||||
NLGEORGES::CFormDfn *formDfn = dynamic_cast<NLGEORGES::CFormDfn *>(m_georges->loadFormDfn(dfnName.toAscii().data()));
|
||||
|
||||
// Next we'll use the root node to build a new form.
|
||||
NLGEORGES::CFormElmStruct *fes = dynamic_cast<NLGEORGES::CFormElmStruct *>(getRootNode(0));
|
||||
fes = dynamic_cast<NLGEORGES::CFormElmStruct *>(getRootNode(i+1));
|
||||
fes->build(formDfn);
|
||||
|
||||
// And then initialize the held elements;
|
||||
for(uint i = 0; i<NLGEORGES::CForm::HeldElementCount; i++)
|
||||
{
|
||||
fes = dynamic_cast<NLGEORGES::CFormElmStruct *>(getRootNode(i+1));
|
||||
fes->build(formDfn);
|
||||
}
|
||||
|
||||
return form;
|
||||
}
|
||||
nlinfo("File '%s' does not exist!", dfnName.toAscii().data());
|
||||
return NULL;
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
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 =
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue