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

--HG--
branch : branch-features-geqt-plugin
This commit is contained in:
sfb 2012-09-17 15:12:01 -05:00
parent 2007b33189
commit df07598a45
7 changed files with 1140 additions and 724 deletions

View file

@ -23,11 +23,13 @@
#include <nel/georges/u_type.h>
#include <nel/georges/form.h>
using namespace NLGEORGES;
namespace GeorgesQt
{
CFormItem::CFormItem(NLGEORGES::UFormElm* elm, const QList<QVariant> &data, CFormItem *parent,
NLGEORGES::UFormElm::TWhereIsValue wV, NLGEORGES::UFormElm::TWhereIsNode wN)
NLGEORGES::UFormElm::TWhereIsValue wV, NLGEORGES::UFormElm::TWhereIsNode wN)
{
parentItem = parent;
itemData = data;
@ -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,13 +58,18 @@ namespace GeorgesQt
return whereN;
}
private:
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;
NLGEORGES::UFormElm* formElm;
NLGEORGES::UFormElm::TWhereIsValue whereV;
NLGEORGES::UFormElm::TWhereIsNode whereN;
NLGEORGES::UFormElm::TWhereIsValue whereV;
NLGEORGES::UFormElm::TWhereIsNode whereN;
}; // CFormItem
}

View file

@ -61,7 +61,7 @@ namespace GeorgesQt
// Set the default sheet dir dir to the level design path.
m_lastSheetDir = ".";
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
m_lastSheetDir = settings->value(Core::Constants::LEVELDESIGN_PATH, "l:/leveldesign").toString();
settings->endGroup();
@ -102,12 +102,12 @@ namespace GeorgesQt
void CGeorgesTreeViewDialog::headerClicked(int section)
{
if (section == 0)
{
{
if (*(m_header->expanded()))
m_ui.treeView->expandAll();
else
m_ui.treeView->collapseAll();
}
}
}
void CGeorgesTreeViewDialog::setForm(const CForm *form)
@ -119,8 +119,8 @@ namespace GeorgesQt
{
if(NLMISC::CPath::exists(formName.toStdString()))
{
//NLGEORGES::CForm *form = dynamic_cast<NLGEORGES::CForm*>(m_georges->loadForm(formName.toStdString()));
return (NLGEORGES::CForm *)m_georges->loadForm(formName.toStdString());
//NLGEORGES::CForm *form = dynamic_cast<NLGEORGES::CForm*>(m_georges->loadForm(formName.toStdString()));
return (NLGEORGES::CForm *)m_georges->loadForm(formName.toStdString());
}
//else
//{
@ -156,56 +156,56 @@ namespace GeorgesQt
// }
// return form;
//}
nlinfo("File '%s' does not exist!", formName.toStdString().c_str());
nlinfo("File '%s' does not exist!", formName.toStdString().c_str());
return 0;
}
NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByDfnName(const QString dfnName)
{
if(NLMISC::CPath::exists(dfnName.toStdString()))
{
// Create a new form object.
NLGEORGES::CForm *form = new NLGEORGES::CForm();
m_form = form;
if(NLMISC::CPath::exists(dfnName.toStdString()))
{
// 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.toStdString()));
// Retrieve a copy of the root definition.
NLGEORGES::CFormDfn *formDfn = dynamic_cast<NLGEORGES::CFormDfn *>(m_georges->loadFormDfn(dfnName.toStdString()));
// Next we'll use the root node to build a new form.
NLGEORGES::CFormElmStruct *fes = dynamic_cast<NLGEORGES::CFormElmStruct *>(getRootNode(0));
fes->build(formDfn);
// 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++)
{
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.toStdString().c_str());
return NULL;
return form;
}
nlinfo("File '%s' does not exist!", dfnName.toStdString().c_str());
return NULL;
}
NLGEORGES::CFormElm *CGeorgesTreeViewDialog::getRootNode(uint slot)
{
NLGEORGES::CForm *form = getFormPtr();
NLGEORGES::CForm *form = getFormPtr();
if(slot == 0)
{
const NLGEORGES::UFormElm &formElm = form->getRootNode();
return (NLGEORGES::CFormElm *)&formElm;
}
if(slot == 0)
{
const NLGEORGES::UFormElm &formElm = form->getRootNode();
return (NLGEORGES::CFormElm *)&formElm;
}
// Make sure the slot value is valid and then return the corresponding element.
nlassert(slot < NLGEORGES::CForm::HeldElementCount+1);
return getFormPtr()->HeldElements[slot-1];
// Make sure the slot value is valid and then return the corresponding element.
nlassert(slot < NLGEORGES::CForm::HeldElementCount+1);
return getFormPtr()->HeldElements[slot-1];
}
NLGEORGES::CForm *CGeorgesTreeViewDialog::getFormPtr()
{
return dynamic_cast<NLGEORGES::CForm *>(m_form);
return dynamic_cast<NLGEORGES::CForm *>(m_form);
}
void CGeorgesTreeViewDialog::loadFormIntoDialog(CForm *form)
@ -219,14 +219,16 @@ 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++)
uint cnt = form->getParentCount();
for (uint i = 0; i < cnt /*form->getParentCount()*/; i++)
{
UForm *u = m_form->getParentForm(i);
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);
@ -317,12 +319,12 @@ namespace GeorgesQt
void CGeorgesTreeViewDialog::write( )
{
NLMISC::COFile file;
std::string s = NLMISC::CPath::lookup(loadedForm.toStdString(), false);
if(file.open (s))
{
try
{
NLMISC::COFile file;
std::string s = NLMISC::CPath::lookup(loadedForm.toStdString(), false);
if(file.open (s))
{
try
{
// if (loadedForm.contains(".typ"))
// {
// //nlassert (Type != NULL);
@ -335,7 +337,7 @@ namespace GeorgesQt
// // flushValueChange ();
// //}
// //Type->write (xmlStream.getDocument (), theApp.Georges4CVS);
// //modify (NULL, NULL, false);
// //modify (NULL, NULL, false);
// //flushValueChange ();
// //UpdateAllViews (NULL);
// //return TRUE;
@ -357,17 +359,17 @@ namespace GeorgesQt
// }
// else
// {
nlassert (m_form != NULL);
nlassert (m_form != NULL);
// Write the file
// Write the file
// /*if (IsModified ())
// {
// ((CForm*)(UForm*)Form)->Header.MinorVersion++;
// }*/
// //((CForm*)(UForm*)Form)->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS);
m_form->write(file, false);
setWindowTitle(windowTitle().remove("*"));
m_modified = false;
m_form->write(file, false);
setWindowTitle(windowTitle().remove("*"));
m_modified = false;
// //if (strcmp (xmlStream.getErrorString (), "") != 0)
// //{
// // char message[512];
@ -381,16 +383,16 @@ namespace GeorgesQt
// // Get the left view
// //CView* pView = getLeftView ();
// }
}
catch (Exception &e)
{
nlerror("Error while loading file: %s", e.what());
}
}
else
{
nlerror("Can't open the file %s for writing.", s.c_str());
}
}
catch (Exception &e)
{
nlerror("Error while loading file: %s", e.what());
}
}
else
{
nlerror("Can't open the file %s for writing.", s.c_str());
}
}
void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index )

View file

@ -57,14 +57,14 @@ namespace GeorgesQt
bool isModified() {return m_modified;}
void setModified(bool m) {m_modified = m;}
NLGEORGES::CForm* getFormByName(const QString formName);
NLGEORGES::CForm* getFormByDfnName(const QString dfnName);
NLGEORGES::CForm* getFormByName(const QString formName);
NLGEORGES::CForm* getFormByDfnName(const QString dfnName);
/// Retrieves the root element based on the slot (document or held elements.)
NLGEORGES::CFormElm *getRootNode(uint slot);
/// Retrieves the root element based on the slot (document or held elements.)
NLGEORGES::CFormElm *getRootNode(uint slot);
/// Returns the form as a CForm pointer.
NLGEORGES::CForm *getFormPtr();
/// Returns the form as a CForm pointer.
NLGEORGES::CForm *getFormPtr();
void addParentForm(QString parentFormNm);

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();
@ -58,15 +62,22 @@ namespace GeorgesQt
void setShowDefaults( bool show );
void addParentForm(QString parentForm);
void removeParentForm(QString parentForm);
NLGEORGES::UFormElm *getRootForm() { return m_rootElm; }
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;
NLGEORGES::UFormElm* m_rootElm;
QList<QVariant> m_rootData;
QMap< QString, QStringList> m_dependencies;
QString m_comments;

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)