merging legacy dfn-based method into geqt. Warning: broke the build.

This commit is contained in:
sfb 2012-09-17 15:12:01 -05:00
parent 7598d90e90
commit dafbfef00f
7 changed files with 1140 additions and 724 deletions

View file

@ -23,6 +23,8 @@
#include <nel/georges/u_type.h>
#include <nel/georges/form.h>
using namespace NLGEORGES;
namespace GeorgesQt
{
@ -159,4 +161,198 @@ namespace GeorgesQt
//formElm->setValueByName();
return true;
}
// CFormItem *CFormItem::add (/*TSub type,*/ const char *name, uint structId, const char *formName, uint slot)
// {
// Add at the end
// uint index = _Children.size();
// _Children.push_back (new CGeorgesEditDocSub);
// _Children[index]->_Type = type;
// _Children[index]->_Name = name;
// _Children[index]->_Parent = this;
// _Children[index]->_StructId = structId;
// _Children[index]->_FormName = formName;
// _Children[index]->_Slot = slot;
// return _Children[index];
// CFormItem *newNode = new CFormItem();
// appendChild(newNode);
// return NULL;
// }
CFormItem *CFormItem::add(NLGEORGES::UFormElm* root, std::string elmName)
{
CFormItem *newItem = NULL;
UFormElm::TWhereIsNode *whereN = new UFormElm::TWhereIsNode;
UFormElm::TWhereIsValue *whereV = new UFormElm::TWhereIsValue;
// Append a new item to the current parent's list of children.
// std::string elmName;
// if(root->getStructNodeName(num, elmName))
// {
QList<QVariant> columnData;
//QVariant value;
std::string value;
//NLMISC::CRGBA value_color;
//uint value_uint;
//sint value_sint;
//double value_double;
QString elmtType = "";
UFormElm *elmt = 0;
if(root->getNodeByName(&elmt, elmName.c_str(), whereN, true))
{
if (elmt)
{
if (elmt->isArray())
elmtType = "Array";
if (elmt->isStruct())
elmtType = "Struct";
if (elmt->isAtom())
{
elmtType = "Atom";
uint numDefinitions = 0;
const UType *type = elmt->getType();
if (type)
{
numDefinitions = type->getNumDefinition();
root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
switch (type->getType())
{
case UType::UnsignedInt:
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble()).toStdString();
elmtType.append("_uint");break;
case UType::SignedInt:
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble()).toStdString();
elmtType.append("_sint");break;
case UType::Double:
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble(),0,'f',1).toStdString();
elmtType.append("_double");break;
case UType::String:
elmtType.append("_string");break;
case UType::Color:
elmtType.append("_color");break;
default:
elmtType.append("_unknownType");
}
}
else
{
elmtType.append("_noType");
}
if (numDefinitions)
{
std::string l, v;
QString tmpLabel, tmpValue;
for (uint i = 0; i < numDefinitions; i++)
{
type->getDefinition(i,l,v);
tmpLabel = l.c_str();
tmpValue = v.c_str();
if (type->getType() == UType::SignedInt)
{
if (QString("%1").arg(value.c_str()).toDouble() == tmpValue.toDouble()) {
value = l;
break;
}
}
if (type->getType() == UType::String)
{
if (QString(value.c_str()) == tmpValue)
{
value = l;
break;
}
}
}
}
}
if (elmt->isVirtualStruct())
{
root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
elmtType = "VirtualStruct";
}
switch (*whereN)
{
case UFormElm::NodeForm:
elmtType.append("_fromForm"); break;
case UFormElm::NodeParentForm:
elmtType.append("_fromParentForm"); break;
case UFormElm::NodeDfn:
elmtType.append("_isDFN"); break;
case UFormElm::NodeType:
elmtType.append("_isType"); break;
default:
elmtType.append("_noNode");
}
switch (*whereV)
{
case UFormElm::ValueForm:
elmtType.append("_formValue"); break;
case UFormElm::ValueParentForm:
elmtType.append("_parentValue"); break;
case UFormElm::ValueDefaultDfn:
elmtType.append("_dfnValue"); break;
case UFormElm::ValueDefaultType:
elmtType.append("_typeValue"); break;
default:
elmtType.append("_noValue");
}
columnData << QString(elmName.c_str()) << QString(value.c_str()) << "";// << elmtType;
newItem = new CFormItem(elmt, columnData, this, *whereV, *whereN);
this->appendChild(newItem);
return newItem;
//if (parents.last()->childCount() > 0) {
// parents << parents.last()->child(parents.last()->childCount()-1);
//}
// The building of the tree should be haoppening in the mode,.
//loadFormData(elmt, parent->child(parent->childCount()-1));
}
else
{
// add Defaults
// TODO: spams warnings for non ATOM values but i dont get type of non existing nodes
bool success = root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
switch (*whereN)
{
case UFormElm::NodeForm:
elmtType.append("_fromForm"); break;
case UFormElm::NodeParentForm:
elmtType.append("_fromParentForm"); break;
case UFormElm::NodeDfn:
elmtType.append("_isDFN"); break;
case UFormElm::NodeType:
elmtType.append("_isType"); break;
default:
elmtType.append("_noNode");
}
switch (*whereV)
{
case UFormElm::ValueForm:
elmtType.append("_formValue"); break;
case UFormElm::ValueParentForm:
elmtType.append("_parentValue"); break;
case UFormElm::ValueDefaultDfn:
elmtType.append("_dfnValue"); break;
case UFormElm::ValueDefaultType:
elmtType.append("_typeValue"); break;
default:
elmtType.append("_noValue");
}
columnData << QString(elmName.c_str()) << QString(value.c_str()) << "";// << elmtType;
newItem = new CFormItem(elmt, columnData, this, *whereV, *whereN);
this->appendChild(newItem);
return newItem;
}
// }
// else
// {
// nlinfo("getNodeByName returned false");
// }
}
}
}

View file

@ -33,11 +33,13 @@ namespace GeorgesQt
public:
CFormItem(NLGEORGES::UFormElm *elm, const QList<QVariant> &data,
CFormItem *parent = 0,
NLGEORGES::UFormElm::TWhereIsValue = NLGEORGES::UFormElm::ValueForm,
NLGEORGES::UFormElm::TWhereIsNode = NLGEORGES::UFormElm::NodeForm);
NLGEORGES::UFormElm::TWhereIsValue wV = NLGEORGES::UFormElm::ValueForm,
NLGEORGES::UFormElm::TWhereIsNode wN = NLGEORGES::UFormElm::NodeForm);
~CFormItem();
void appendChild(CFormItem *child);
//CFormItem *add (/*TSub type,*/ const char *name, uint structId, const char *formName, uint slot);
CFormItem *add(NLGEORGES::UFormElm* root, std::string elmName);
CFormItem *child(int row);
int childCount() const;
@ -56,7 +58,12 @@ namespace GeorgesQt
return whereN;
}
void setValueFrom(NLGEORGES::UFormElm::TWhereIsValue wV) { whereV = wV; }
void setNodeFrom(NLGEORGES::UFormElm::TWhereIsNode wN) { whereN = wN; }
private:
//CFormItem() { whereV = NLGEORGES::UFormElm::ValueForm; whereN = NLGEORGES::UFormElm::NodeForm; }
QList<CFormItem*> childItems;
QList<QVariant> itemData;
CFormItem *parentItem;

View file

@ -219,6 +219,7 @@ namespace GeorgesQt
UFormElm *root = 0;
root = &m_form->getRootNode();
// Extract the parent forms into the list of parents in the dialog.
QStringList parents;
uint cnt = form->getParentCount();
for (uint i = 0; i < cnt /*form->getParentCount()*/; i++)
@ -227,6 +228,7 @@ namespace GeorgesQt
parents << u->getFilename().c_str();
}
// Exact the comment box for the dialog.
QString comments;
comments = m_form->getComment().c_str();
@ -255,7 +257,7 @@ namespace GeorgesQt
{
loadedForm = m_form->getFilename().c_str();
CGeorgesFormModel *model = new CGeorgesFormModel(root,deps,comments,parents,m_header->expanded());
CGeorgesFormModel *model = new CGeorgesFormModel(m_form,deps,comments,parents,m_header->expanded());
CGeorgesFormProxyModel *proxyModel = new CGeorgesFormProxyModel();
proxyModel->setSourceModel(model);
m_ui.treeView->setModel(proxyModel);

View file

@ -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);
}
/******************************************************************************/

View file

@ -27,6 +27,10 @@
namespace NLGEORGES {
class UFormElm;
class UForm;
class CFormElmStruct;
class CFormDfn;
class CFormElmArray;
}
namespace GeorgesQt
@ -38,7 +42,7 @@ namespace GeorgesQt
{
public:
CGeorgesFormModel(NLGEORGES::UFormElm *root, QMap< QString, QStringList> deps,
CGeorgesFormModel(NLGEORGES::UForm *form, QMap< QString, QStringList> deps,
QString comment, QStringList parents, bool* expanded, QObject *parent = 0);
~CGeorgesFormModel();
@ -60,11 +64,18 @@ namespace GeorgesQt
void removeParentForm(QString parentForm);
NLGEORGES::UFormElm *getRootForm() { return m_rootElm; }
CFormItem *addStruct (CFormItem *parent, NLGEORGES::CFormElmStruct *_struct, NLGEORGES::CFormDfn *parentDfn,
const char *name, uint structId, const char *formName, uint slot);
CFormItem *addArray(CFormItem *parent, NLGEORGES::CFormElmArray *array, NLGEORGES::CFormDfn *rootDfn,
const char *name, uint structId, const char *formName, uint slot);
private:
void setupModelData();
void loadFormData(NLGEORGES::UFormElm *rootElm, CFormItem *parent);
void loadFormHeader();
NLGEORGES::UForm* m_form;
CFormItem* m_rootItem;
NLGEORGES::UFormElm* m_rootElm;
QList<QVariant> m_rootData;

View file

@ -66,7 +66,7 @@ CMainWindow::CMainWindow(QWidget *parent)
_isGraphicsInitialized(false),
_isGraphicsEnabled(false),
_isSoundInitialized(false),
_isSoundEnabled(true),
_isSoundEnabled(false), // MTR workaround for sheet id nonsense
_GraphicsViewport(NULL),
_lastDir("."),
_mouseMode(NL3D::U3dMouseListener::edit3d)