|
|
|
@ -14,17 +14,20 @@
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
#include "stdpch.h"
|
|
|
|
|
#include "georgesform_model.h"
|
|
|
|
|
#include "formitem.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>
|
|
|
|
@ -37,18 +40,22 @@
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
|
|
|
|
|
// project includes
|
|
|
|
|
#include "formitem.h"
|
|
|
|
|
#include "georges_editor_form.h"
|
|
|
|
|
#include "actions.h"
|
|
|
|
|
|
|
|
|
|
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_rootItem = new CFormItem();
|
|
|
|
|
m_dependencies = deps;
|
|
|
|
|
m_comments = comment;
|
|
|
|
|
m_parents = parents;
|
|
|
|
@ -76,143 +83,11 @@ namespace GeorgesQt
|
|
|
|
|
{
|
|
|
|
|
return getItem(p_index)->data(p_index.column());
|
|
|
|
|
}
|
|
|
|
|
case Qt::BackgroundRole:
|
|
|
|
|
{
|
|
|
|
|
QBrush defaultBrush = QBrush(QColor(255,0,0,30));
|
|
|
|
|
QBrush parentBrush = QBrush(QColor(0,255,0,30));
|
|
|
|
|
|
|
|
|
|
// if elm not existing it must be some kind of default or type value
|
|
|
|
|
if(!getItem(p_index)->getFormElm())
|
|
|
|
|
{
|
|
|
|
|
return defaultBrush;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// else it might be some parent elm
|
|
|
|
|
switch (getItem(p_index)->nodeFrom())
|
|
|
|
|
{
|
|
|
|
|
case NLGEORGES::UFormElm::NodeParentForm:
|
|
|
|
|
{
|
|
|
|
|
return parentBrush;
|
|
|
|
|
}
|
|
|
|
|
case NLGEORGES::UFormElm::NodeForm:
|
|
|
|
|
{
|
|
|
|
|
switch (getItem(p_index)->valueFrom())
|
|
|
|
|
{
|
|
|
|
|
case NLGEORGES::UFormElm::ValueParentForm:
|
|
|
|
|
{
|
|
|
|
|
return parentBrush;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
// parent status test kindof ugly, testing only 2 steps deep
|
|
|
|
|
// only needed for colorization as treeview default hides childs
|
|
|
|
|
// when parent is hidden
|
|
|
|
|
CFormItem *parent = getItem(p_index)->parent();
|
|
|
|
|
if (parent)
|
|
|
|
|
{
|
|
|
|
|
if (parent->nodeFrom() == NLGEORGES::UFormElm::NodeParentForm)
|
|
|
|
|
{
|
|
|
|
|
return parentBrush;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CFormItem *parentParent = parent->parent();
|
|
|
|
|
if (parentParent)
|
|
|
|
|
{
|
|
|
|
|
if (parentParent->nodeFrom() == NLGEORGES::UFormElm::NodeParentForm)
|
|
|
|
|
{
|
|
|
|
|
return parentBrush;
|
|
|
|
|
}
|
|
|
|
|
} // endif parentParent
|
|
|
|
|
} // endif parent
|
|
|
|
|
} // end default
|
|
|
|
|
} // end switch valueFrom
|
|
|
|
|
} // end case nodeForm
|
|
|
|
|
} // end switch nodeFrom
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
case Qt::DecorationRole:
|
|
|
|
|
{
|
|
|
|
|
if (p_index.column() == 2)
|
|
|
|
|
{
|
|
|
|
|
//p_index.
|
|
|
|
|
QModelIndex in = index(p_index.row(),p_index.column()-1,p_index.parent());
|
|
|
|
|
CFormItem *item = getItem(in);
|
|
|
|
|
|
|
|
|
|
QString value = item->data(1).toString();
|
|
|
|
|
//QString path = NLMISC::CPath::lookup(value.toUtf8().constData(),false).c_str();
|
|
|
|
|
|
|
|
|
|
/*if (value.contains(".shape"))
|
|
|
|
|
{
|
|
|
|
|
if (Modules::objViewInt())
|
|
|
|
|
{
|
|
|
|
|
QIcon *icon = Modules::objViewInt()->saveOneImage(value.toUtf8().constData());
|
|
|
|
|
if (icon)
|
|
|
|
|
{
|
|
|
|
|
if(icon->isNull())
|
|
|
|
|
return QIcon(":/images/pqrticles.png");
|
|
|
|
|
else
|
|
|
|
|
return QIcon(*icon);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return QIcon();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
if(value.contains(".tga") || value.contains(".png"))
|
|
|
|
|
{
|
|
|
|
|
QString path = NLMISC::CPath::lookup(value.toUtf8().constData(),false).c_str();
|
|
|
|
|
if(path.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
path = ":/images/pqrticles.png";
|
|
|
|
|
}
|
|
|
|
|
return QIcon(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
|
{
|
|
|
|
|
if (p_index.column() == 2)
|
|
|
|
|
{
|
|
|
|
|
QModelIndex in = index(p_index.row(),p_index.column()-1,p_index.parent());
|
|
|
|
|
CFormItem *item = getItem(in);
|
|
|
|
|
QString value = item->data(1).toString();
|
|
|
|
|
|
|
|
|
|
/*if (value.contains(".shape"))
|
|
|
|
|
{
|
|
|
|
|
if (Modules::objViewInt())
|
|
|
|
|
{
|
|
|
|
|
QIcon *icon = Modules::objViewInt()->saveOneImage(value.toUtf8().constData());
|
|
|
|
|
if (icon)
|
|
|
|
|
{
|
|
|
|
|
if(icon->isNull())
|
|
|
|
|
return QIcon(":/images/pqrticles.png");
|
|
|
|
|
else
|
|
|
|
|
return QIcon(*icon);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return QIcon();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
if(value.contains(".tga") || value.contains(".png"))
|
|
|
|
|
{
|
|
|
|
|
QString path = NLMISC::CPath::lookup(value.toUtf8().constData(),false).c_str();
|
|
|
|
|
if(path.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
path = ":/images/pqrticles.png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString imageTooltip = QString("<img src='%1'>").arg(path);
|
|
|
|
|
|
|
|
|
|
return imageTooltip;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
break;
|
|
|
|
|
// Based on the _Type return a QIcon from resources.
|
|
|
|
|
CFormItem *item = getItem(p_index);
|
|
|
|
|
return item->getItemImage(m_rootItem);
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return QVariant();
|
|
|
|
@ -234,20 +109,23 @@ namespace GeorgesQt
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
bool CGeorgesFormModel::setData(const QModelIndex &index, const QVariant &value,
|
|
|
|
|
int role)
|
|
|
|
|
bool CGeorgesFormModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (role != Qt::EditRole)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
CFormItem *item = getItem(index);
|
|
|
|
|
bool result = item->setData(index.column(), value);
|
|
|
|
|
|
|
|
|
|
if(!item->isEditable(index.column()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
GeorgesEditorForm::UndoStack->push(new CUndoFormArrayRenameCommand(this,item,value));
|
|
|
|
|
|
|
|
|
|
Q_EMIT dataChanged(index, index);
|
|
|
|
|
|
|
|
|
|
//setupModelData();
|
|
|
|
|
return result;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
@ -259,8 +137,12 @@ namespace GeorgesQt
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags returnValue = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
|
|
|
|
|
|
|
|
if(index.column() == 1)
|
|
|
|
|
CFormItem *item = getItem(index);
|
|
|
|
|
|
|
|
|
|
if(item->isEditable(index.column()))
|
|
|
|
|
{
|
|
|
|
|
returnValue |= Qt::ItemIsEditable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
|
|
|
|
|
@ -331,6 +213,14 @@ namespace GeorgesQt
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex CGeorgesFormModel::index(int row, int column, CFormItem *item) const
|
|
|
|
|
{
|
|
|
|
|
if(item == m_rootItem)
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
|
|
return createIndex(row, 0, item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
QModelIndex CGeorgesFormModel::parent(const QModelIndex &index) const
|
|
|
|
@ -378,241 +268,205 @@ namespace GeorgesQt
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
void CGeorgesFormModel::loadFormData(UFormElm *root, CFormItem *parent) {
|
|
|
|
|
|
|
|
|
|
if (!root)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
uint num = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (root->isStruct())
|
|
|
|
|
{
|
|
|
|
|
//((CFormElm*)root)->getForm()->getComment();
|
|
|
|
|
uint structSize = 0;
|
|
|
|
|
root->getStructSize(structSize);
|
|
|
|
|
while (num < structSize)
|
|
|
|
|
{
|
|
|
|
|
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:
|
|
|
|
|
{
|
|
|
|
|
uint v;
|
|
|
|
|
NLMISC::fromString(value, v);
|
|
|
|
|
value = NLMISC::toString(v);
|
|
|
|
|
elmtType.append("_uint");break;
|
|
|
|
|
}
|
|
|
|
|
case UType::SignedInt:
|
|
|
|
|
{
|
|
|
|
|
sint v;
|
|
|
|
|
NLMISC::fromString(value, v);
|
|
|
|
|
value = NLMISC::toString(v);
|
|
|
|
|
elmtType.append("_sint");break;
|
|
|
|
|
}
|
|
|
|
|
case UType::Double:
|
|
|
|
|
float v;
|
|
|
|
|
NLMISC::fromString(value, v);
|
|
|
|
|
value = NLMISC::toString(v);
|
|
|
|
|
elmtType.append("_double");break;
|
|
|
|
|
case UType::String:
|
|
|
|
|
elmtType.append("_string");break;
|
|
|
|
|
case UType::Color:
|
|
|
|
|
elmtType.append("_color");break;
|
|
|
|
|
default:
|
|
|
|
|
elmtType.append("_unknownType");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
CFormItem *CGeorgesFormModel::addStruct (CFormItem *parent,
|
|
|
|
|
NLGEORGES::CFormElmStruct *_struct,
|
|
|
|
|
NLGEORGES::CFormDfn *parentDfn,
|
|
|
|
|
const char *name,
|
|
|
|
|
uint structId,
|
|
|
|
|
const char *formName,
|
|
|
|
|
uint slot)
|
|
|
|
|
{
|
|
|
|
|
elmtType.append("_noType");
|
|
|
|
|
}
|
|
|
|
|
// The form pointer
|
|
|
|
|
NLGEORGES::CForm *formPtr = static_cast<NLGEORGES::CForm*>(m_form);
|
|
|
|
|
|
|
|
|
|
// Add the new node
|
|
|
|
|
CFormItem *newNode = parent->add(CFormItem::Form, name, structId, formName, slot, m_form);
|
|
|
|
|
|
|
|
|
|
if (numDefinitions)
|
|
|
|
|
// Can be NULL in virtual DFN
|
|
|
|
|
if (parentDfn)
|
|
|
|
|
{
|
|
|
|
|
std::string l, v;
|
|
|
|
|
QString tmpLabel, tmpValue;
|
|
|
|
|
for (uint i = 0; i < numDefinitions; i++)
|
|
|
|
|
// 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++)
|
|
|
|
|
{
|
|
|
|
|
type->getDefinition(i,l,v);
|
|
|
|
|
tmpLabel = l.c_str();
|
|
|
|
|
tmpValue = v.c_str();
|
|
|
|
|
if (type->getType() == UType::SignedInt)
|
|
|
|
|
for (uint i=0; i<arrayDfn[dfn]->getNumEntry (); i++)
|
|
|
|
|
{
|
|
|
|
|
if (QString("%1").arg(value.c_str()).toDouble() == tmpValue.toDouble()) {
|
|
|
|
|
value = l;
|
|
|
|
|
break;
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (type->getType() == UType::String)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add the new struct
|
|
|
|
|
addArray (newNode, nextArray, entry.getDfnPtr (), entry.getName().c_str(), elm, entryName.c_str (), slot);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (QString(value.c_str()) == tmpValue)
|
|
|
|
|
// 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++)
|
|
|
|
|
{
|
|
|
|
|
value = l;
|
|
|
|
|
break;
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (elmt->isVirtualStruct())
|
|
|
|
|
// Array of type ?
|
|
|
|
|
else if ( entry.getArrayFlag () )
|
|
|
|
|
{
|
|
|
|
|
root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
|
|
|
|
|
elmtType = "VirtualStruct";
|
|
|
|
|
}
|
|
|
|
|
switch (*whereN)
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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");
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
columnData << QString(elmName.c_str()) << QString(value.c_str()) << "";// << elmtType;
|
|
|
|
|
parent->appendChild(new CFormItem(elmt, columnData, parent, *whereV, *whereN));
|
|
|
|
|
//if (parents.last()->childCount() > 0) {
|
|
|
|
|
// parents << parents.last()->child(parents.last()->childCount()-1);
|
|
|
|
|
//}
|
|
|
|
|
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;
|
|
|
|
|
parent->appendChild(new CFormItem(elmt, columnData, parent, *whereV, *whereN));
|
|
|
|
|
// Add the new array
|
|
|
|
|
addArray ( newNode, nextArray, NULL, entry.getName().c_str(), elm, entryName.c_str(), slot );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nlinfo("getNodeByName returned false");
|
|
|
|
|
|
|
|
|
|
// Next element
|
|
|
|
|
elm++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
num++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newNode;
|
|
|
|
|
}
|
|
|
|
|
if (root->isArray())
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
|
|
|
|
|
|
CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
|
|
|
|
|
NLGEORGES::CFormElmArray *array,
|
|
|
|
|
NLGEORGES::CFormDfn *rootDfn,
|
|
|
|
|
const char *name,
|
|
|
|
|
uint structId,
|
|
|
|
|
const char *formName,
|
|
|
|
|
uint slot)
|
|
|
|
|
{
|
|
|
|
|
uint arraySize = 0;
|
|
|
|
|
root->getArraySize(arraySize);
|
|
|
|
|
while (num < arraySize)
|
|
|
|
|
// Add the new node
|
|
|
|
|
CFormItem *newNode = parent->add (CFormItem::Form, name, structId, formName, slot, m_form);
|
|
|
|
|
|
|
|
|
|
// The array exist
|
|
|
|
|
if (array)
|
|
|
|
|
{
|
|
|
|
|
std::string elmName;
|
|
|
|
|
if(root->getArrayNodeName(elmName, num))
|
|
|
|
|
// For each array element
|
|
|
|
|
for (uint elm=0; elm<array->Elements.size(); elm++)
|
|
|
|
|
{
|
|
|
|
|
QList<QVariant> columnData;
|
|
|
|
|
std::string value;
|
|
|
|
|
QString elmtType;
|
|
|
|
|
// The form name
|
|
|
|
|
char formArrayElmName[512];
|
|
|
|
|
NLMISC::smprintf (formArrayElmName, 512, "%s[%d]", formName, elm);
|
|
|
|
|
|
|
|
|
|
UFormElm *elmt = 0;
|
|
|
|
|
if(root->getArrayNode(&elmt,0) && elmt)
|
|
|
|
|
// The name
|
|
|
|
|
char formArrayName[512];
|
|
|
|
|
if (array->Elements[elm].Name.empty ())
|
|
|
|
|
{
|
|
|
|
|
if (elmt->isArray())
|
|
|
|
|
elmtType = "Array";
|
|
|
|
|
if (elmt->isStruct()) {
|
|
|
|
|
elmtType = "Struct";
|
|
|
|
|
NLMISC::smprintf (formArrayName, 512, "#%d", elm);
|
|
|
|
|
}
|
|
|
|
|
if (elmt->isAtom())
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
elmt->getValue(value);
|
|
|
|
|
elmtType = "Atom";
|
|
|
|
|
NLMISC::smprintf (formArrayName, 512, "%s", array->Elements[elm].Name.c_str());
|
|
|
|
|
}
|
|
|
|
|
if (elmt->isVirtualStruct())
|
|
|
|
|
elmtType = "VirtualStruct";
|
|
|
|
|
|
|
|
|
|
elmtType.append("_arrayValue");
|
|
|
|
|
columnData << QString(elmName.c_str()) << QString(value.c_str()) << "";// << elmtType;
|
|
|
|
|
parent->appendChild(new CFormItem(elmt, columnData, parent));
|
|
|
|
|
loadFormData(elmt, parent->child(parent->childCount()-1));
|
|
|
|
|
// Is a struct
|
|
|
|
|
if (rootDfn)
|
|
|
|
|
{
|
|
|
|
|
// Get struct ptr
|
|
|
|
|
NLGEORGES::CFormElmStruct *elmPtr = array->Elements[elm].Element ? static_cast<NLGEORGES::CFormElmStruct*>(array->Elements[elm].Element) : NULL;
|
|
|
|
|
addStruct (newNode, elmPtr, rootDfn, formArrayName, elm, formArrayElmName, slot);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NLGEORGES::CFormElmArray *elmPtr = array->Elements[elm].Element ? static_cast<NLGEORGES::CFormElmArray*>(array->Elements[elm].Element) : NULL;
|
|
|
|
|
newNode->add (CFormItem::Form, formArrayName, elm, formArrayElmName, slot, m_form);
|
|
|
|
|
}
|
|
|
|
|
num++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
void CGeorgesFormModel::loadFormHeader()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (m_parents.size())
|
|
|
|
|
/* if (m_parents.size())
|
|
|
|
|
{
|
|
|
|
|
CFormItem *fi_pars = new CFormItem(m_rootElm, QList<QVariant>() << "parents" << "" << "", m_rootItem);
|
|
|
|
|
m_rootItem->appendChild(fi_pars);
|
|
|
|
@ -621,7 +475,7 @@ namespace GeorgesQt
|
|
|
|
|
{
|
|
|
|
|
fi_pars->appendChild(new CFormItem(m_rootElm, QList<QVariant>() << str << "" << "", fi_pars));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
/*QStringList dfns = _dependencies["dfn"];
|
|
|
|
|
QStringList typs = _dependencies["typ"];
|
|
|
|
@ -661,8 +515,11 @@ namespace GeorgesQt
|
|
|
|
|
|
|
|
|
|
void CGeorgesFormModel::setupModelData()
|
|
|
|
|
{
|
|
|
|
|
loadFormHeader();
|
|
|
|
|
loadFormData(m_rootElm, m_rootItem);
|
|
|
|
|
m_rootElm = &((NLGEORGES::CForm*)m_form)->Elements;
|
|
|
|
|
NLGEORGES::CFormElmStruct *rootstruct = &((NLGEORGES::CForm*)m_form)->Elements;
|
|
|
|
|
//loadFormHeader();
|
|
|
|
|
addStruct(m_rootItem, rootstruct, rootstruct->FormDfn, "Content", 0xffffffff, "", 0);
|
|
|
|
|
//loadFormData(m_rootElm, m_rootItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
@ -684,7 +541,7 @@ namespace GeorgesQt
|
|
|
|
|
beginResetModel();
|
|
|
|
|
m_parents.push_back(parentForm);
|
|
|
|
|
delete m_rootItem;
|
|
|
|
|
m_rootItem = new CFormItem(m_rootElm, m_rootData);
|
|
|
|
|
m_rootItem = new CFormItem();
|
|
|
|
|
setupModelData();
|
|
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
@ -695,7 +552,7 @@ namespace GeorgesQt
|
|
|
|
|
m_parents.removeOne(parentForm);
|
|
|
|
|
|
|
|
|
|
delete m_rootItem;
|
|
|
|
|
m_rootItem = new CFormItem(m_rootElm, m_rootData);
|
|
|
|
|
m_rootItem = new CFormItem();
|
|
|
|
|
setupModelData();
|
|
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
|