|
|
|
@ -16,13 +16,18 @@
|
|
|
|
|
|
|
|
|
|
#include "georgesform_model.h"
|
|
|
|
|
|
|
|
|
|
// System Includes
|
|
|
|
|
#include <libxml/parser.h>
|
|
|
|
|
|
|
|
|
|
// NeL includes
|
|
|
|
|
#include <nel/misc/types_nl.h>
|
|
|
|
|
#include <nel/misc/rgba.h>
|
|
|
|
|
#include <nel/misc/path.h>
|
|
|
|
|
#include <nel/misc/debug.h>
|
|
|
|
|
#include <nel/georges/u_form_elm.h>
|
|
|
|
|
#include <nel/georges/u_type.h>
|
|
|
|
|
#include <nel/georges/u_form_dfn.h>
|
|
|
|
|
#include <nel/georges/form.h>
|
|
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
|
#include <QColor>
|
|
|
|
@ -43,12 +48,11 @@ using namespace NLGEORGES;
|
|
|
|
|
namespace GeorgesQt
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
CGeorgesFormModel::CGeorgesFormModel(UFormElm *rootElm, QMap< QString, QStringList> deps,
|
|
|
|
|
CGeorgesFormModel::CGeorgesFormModel(UForm *form, QMap< QString, QStringList> deps,
|
|
|
|
|
QString comment, QStringList parents, bool *expanded, QObject *parent) : QAbstractItemModel(parent)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
m_form = form;
|
|
|
|
|
m_rootData << "Value" << "Data" << "Extra";// << "Type";
|
|
|
|
|
m_rootElm = rootElm;
|
|
|
|
|
m_rootItem = new CFormItem(m_rootElm, m_rootData);
|
|
|
|
|
m_dependencies = deps;
|
|
|
|
|
m_comments = comment;
|
|
|
|
@ -598,6 +602,199 @@ namespace GeorgesQt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CFormItem *CGeorgesFormModel::addStruct (CFormItem *parent,
|
|
|
|
|
NLGEORGES::CFormElmStruct *_struct,
|
|
|
|
|
NLGEORGES::CFormDfn *parentDfn,
|
|
|
|
|
const char *name,
|
|
|
|
|
uint structId,
|
|
|
|
|
const char *formName,
|
|
|
|
|
uint slot)
|
|
|
|
|
{
|
|
|
|
|
// The form pointer
|
|
|
|
|
NLGEORGES::CForm *formPtr = static_cast<NLGEORGES::CForm*>(m_form);
|
|
|
|
|
|
|
|
|
|
// Add the new node
|
|
|
|
|
// CFormItem *newNode = parent->add(/*CGeorgesEditDocSub::Form,*/ name, structId, formName, slot);
|
|
|
|
|
CFormItem *newNode = parent->add(_struct, name);
|
|
|
|
|
|
|
|
|
|
// Can be NULL in virtual DFN
|
|
|
|
|
if (parentDfn)
|
|
|
|
|
{
|
|
|
|
|
// Get the parents
|
|
|
|
|
std::vector<NLGEORGES::CFormDfn *> arrayDfn;
|
|
|
|
|
arrayDfn.reserve (parentDfn->countParentDfn ());
|
|
|
|
|
parentDfn->getParentDfn (arrayDfn);
|
|
|
|
|
|
|
|
|
|
// For each child
|
|
|
|
|
uint elm=0;
|
|
|
|
|
for (uint dfn=0; dfn<arrayDfn.size(); dfn++)
|
|
|
|
|
{
|
|
|
|
|
for (uint i=0; i<arrayDfn[dfn]->getNumEntry (); i++)
|
|
|
|
|
{
|
|
|
|
|
// Get the entry ref
|
|
|
|
|
NLGEORGES::CFormDfn::CEntry &entry = arrayDfn[dfn]->getEntry (i);
|
|
|
|
|
|
|
|
|
|
// Form entry name
|
|
|
|
|
std::string entryName = (std::string (formName)+"."+entry.getName ());
|
|
|
|
|
|
|
|
|
|
// Is a struct ?
|
|
|
|
|
if ( (entry.getType () == NLGEORGES::UFormDfn::EntryDfn) || (entry.getType () == NLGEORGES::UFormDfn::EntryVirtualDfn) )
|
|
|
|
|
{
|
|
|
|
|
// Is an array of struct ?
|
|
|
|
|
if (entry.getArrayFlag ())
|
|
|
|
|
{
|
|
|
|
|
// Get it from the form
|
|
|
|
|
CFormElmArray *nextArray = NULL;
|
|
|
|
|
if (_struct && _struct->Elements[elm].Element)
|
|
|
|
|
nextArray = NLMISC::safe_cast<NLGEORGES::CFormElmArray*> (_struct->Elements[elm].Element);
|
|
|
|
|
|
|
|
|
|
// Else, get it from the parent if we are not a virtual DFN (don't inheritate)
|
|
|
|
|
|
|
|
|
|
// todo array of virtual struct
|
|
|
|
|
if (!nextArray && (entry.getType () != NLGEORGES::UFormDfn::EntryVirtualDfn) )
|
|
|
|
|
{
|
|
|
|
|
// For each parent form
|
|
|
|
|
for (uint parent=0; parent<formPtr->getParentCount (); parent++)
|
|
|
|
|
{
|
|
|
|
|
// Get the node by name
|
|
|
|
|
NLGEORGES::UFormElm *uNode;
|
|
|
|
|
if (formPtr->getParent (parent)->getRootNode ().getNodeByName (&uNode, entryName.c_str(), NULL, false) && uNode)
|
|
|
|
|
{
|
|
|
|
|
nextArray = NLMISC::safe_cast<NLGEORGES::CFormElmArray*> (uNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add the new struct
|
|
|
|
|
addArray (newNode, nextArray, entry.getDfnPtr (), entry.getName().c_str(), elm, entryName.c_str (), slot);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Add it
|
|
|
|
|
NLGEORGES::CFormElmStruct *nextForm = NULL;
|
|
|
|
|
|
|
|
|
|
// Get it from the form
|
|
|
|
|
if (_struct && _struct->Elements[elm].Element)
|
|
|
|
|
nextForm = NLMISC::safe_cast<NLGEORGES::CFormElmStruct*> (_struct->Elements[elm].Element);
|
|
|
|
|
|
|
|
|
|
// Else, get it from the parent
|
|
|
|
|
if (!nextForm)
|
|
|
|
|
{
|
|
|
|
|
// For each parent form
|
|
|
|
|
for (uint parent=0; parent<formPtr->getParentCount (); parent++)
|
|
|
|
|
{
|
|
|
|
|
// Get the node by name
|
|
|
|
|
NLGEORGES::UFormElm *uNode;
|
|
|
|
|
if (formPtr->getParent (parent)->getRootNode ().getNodeByName (&uNode, entryName.c_str(), NULL, false) && uNode)
|
|
|
|
|
{
|
|
|
|
|
nextForm = NLMISC::safe_cast<NLGEORGES::CFormElmStruct*> (uNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Virtual Dfn pointer
|
|
|
|
|
NLGEORGES::CFormElmVirtualStruct *vStruct = ((entry.getType () == NLGEORGES::UFormDfn::EntryVirtualDfn) && nextForm) ?
|
|
|
|
|
NLMISC::safe_cast<NLGEORGES::CFormElmVirtualStruct*> (nextForm) : NULL;
|
|
|
|
|
|
|
|
|
|
NLGEORGES::CFormDfn *tmpDfn = vStruct ?
|
|
|
|
|
((NLGEORGES::CFormDfn*)vStruct->FormDfn) : entry.getDfnPtr();
|
|
|
|
|
// Add the new struct
|
|
|
|
|
addStruct (newNode, nextForm, tmpDfn, entry.getName().c_str(), elm, entryName.c_str(), slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Array of type ?
|
|
|
|
|
else if ( entry.getArrayFlag () )
|
|
|
|
|
{
|
|
|
|
|
NLGEORGES::CFormElmArray *nextArray = NULL;
|
|
|
|
|
|
|
|
|
|
// Get it from the form
|
|
|
|
|
if (_struct && _struct->Elements[elm].Element)
|
|
|
|
|
nextArray = NLMISC::safe_cast<NLGEORGES::CFormElmArray*> (_struct->Elements[elm].Element);
|
|
|
|
|
|
|
|
|
|
// Else, get it from the parent
|
|
|
|
|
if (!nextArray)
|
|
|
|
|
{
|
|
|
|
|
// For each parent form
|
|
|
|
|
for (uint parent=0; parent<formPtr->getParentCount (); parent++)
|
|
|
|
|
{
|
|
|
|
|
// Get the node by name
|
|
|
|
|
NLGEORGES::UFormElm *uNode;
|
|
|
|
|
if (formPtr->getParent (parent)->getRootNode ().getNodeByName (&uNode, entryName.c_str(), NULL, false) && uNode)
|
|
|
|
|
{
|
|
|
|
|
nextArray = NLMISC::safe_cast<NLGEORGES::CFormElmArray*> (uNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add the new array
|
|
|
|
|
addArray ( newNode, nextArray, NULL, entry.getName().c_str(), elm, entryName.c_str(), slot );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Next element
|
|
|
|
|
elm++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
|
|
|
|
|
|
CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
|
|
|
|
|
NLGEORGES::CFormElmArray *array,
|
|
|
|
|
NLGEORGES::CFormDfn *rootDfn,
|
|
|
|
|
const char *name,
|
|
|
|
|
uint structId,
|
|
|
|
|
const char *formName,
|
|
|
|
|
uint slot)
|
|
|
|
|
{
|
|
|
|
|
// Add the new node
|
|
|
|
|
//CFormItem *newNode = parent->add (/*CGeorgesEditDocSub::Form,*/ name, structId, formName, slot);
|
|
|
|
|
CFormItem *newNode = parent->add (array, name);
|
|
|
|
|
|
|
|
|
|
// The array exist
|
|
|
|
|
if (array)
|
|
|
|
|
{
|
|
|
|
|
// For each array element
|
|
|
|
|
for (uint elm=0; elm<array->Elements.size(); elm++)
|
|
|
|
|
{
|
|
|
|
|
// The form name
|
|
|
|
|
char formArrayElmName[512];
|
|
|
|
|
NLMISC::smprintf (formArrayElmName, 512, "%s[%d]", formName, elm);
|
|
|
|
|
|
|
|
|
|
// The name
|
|
|
|
|
char formArrayName[512];
|
|
|
|
|
if (array->Elements[elm].Name.empty ())
|
|
|
|
|
{
|
|
|
|
|
NLMISC::smprintf (formArrayName, 512, "#%d", elm);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NLMISC::smprintf (formArrayName, 512, "%s", array->Elements[elm].Name.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Is a struct
|
|
|
|
|
if (rootDfn)
|
|
|
|
|
{
|
|
|
|
|
// Get struct ptr
|
|
|
|
|
NLGEORGES::CFormElmStruct *elmPtr = array->Elements[elm].Element ? NLMISC::safe_cast<NLGEORGES::CFormElmStruct*>(array->Elements[elm].Element) : NULL;
|
|
|
|
|
addStruct (newNode, elmPtr, rootDfn, formArrayName, elm, formArrayElmName, slot);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NLGEORGES::CFormElmArray *elmPtr = array->Elements[elm].Element ? NLMISC::safe_cast<NLGEORGES::CFormElmArray*>(array->Elements[elm].Element) : NULL;
|
|
|
|
|
newNode->add (elmPtr, formArrayElmName);
|
|
|
|
|
//newNode->add (/*CGeorgesEditDocSub::Form,*/ formArrayName, elm, formArrayElmName, slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
void CGeorgesFormModel::loadFormHeader()
|
|
|
|
@ -652,8 +849,11 @@ namespace GeorgesQt
|
|
|
|
|
|
|
|
|
|
void CGeorgesFormModel::setupModelData()
|
|
|
|
|
{
|
|
|
|
|
m_rootElm = &((NLGEORGES::CForm*)m_form)->Elements;
|
|
|
|
|
NLGEORGES::CFormElmStruct *rootstruct = &((NLGEORGES::CForm*)m_form)->Elements;
|
|
|
|
|
loadFormHeader();
|
|
|
|
|
loadFormData(m_rootElm, m_rootItem);
|
|
|
|
|
addStruct(m_rootItem, rootstruct, rootstruct->FormDfn, "Content", 0xffffffff, "", 0);
|
|
|
|
|
//loadFormData(m_rootElm, m_rootItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|