Changed: #1306 Radically changed the plugin in a new branch to match the way classic GE loads forms.

- Refactored the tree view to show only structs, arrays, vstructs and eliminated atoms from its view.
- Refactored the form view to have a Qt Properties Browser
- Refactored the loader to use the classic GE addStruct/addArray.
- Moved some functionality into CFormItem.
- Added icons from classic GE and configured model/item to return them appropriately.
- Getting read for changes via undo commands.
- Eliminating/ignoring the hold/slots business from classic GE code.
This commit is contained in:
sfb 2012-09-20 16:39:21 -05:00
parent e527bfdeaa
commit 51705fd800
20 changed files with 481 additions and 916 deletions

View file

@ -1,12 +1,14 @@
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${LIBXML2_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR}
${QT_INCLUDES}) ${QT_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/qtpropertybrowser)
FILE(GLOB SRC *.cpp *.h) FILE(GLOB SRC *.cpp *.h)
SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.h SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.h
${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_manager.h
${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h
${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h)
SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h
georges_editor_form.h georges_editor_form.h
@ -36,7 +38,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC})
ADD_LIBRARY(ovqt_plugin_georges_editor MODULE ${SRC} ${OVQT_PLUG_GEORGES_EDITOR_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_PLUG_GEORGES_EDITOR_UI_HDRS} ${OVQT_PLUGIN_GEORGES_EDITOR_RC_SRCS}) ADD_LIBRARY(ovqt_plugin_georges_editor MODULE ${SRC} ${OVQT_PLUG_GEORGES_EDITOR_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_PLUG_GEORGES_EDITOR_UI_HDRS} ${OVQT_PLUGIN_GEORGES_EDITOR_RC_SRCS})
TARGET_LINK_LIBRARIES(ovqt_plugin_georges_editor ovqt_plugin_core nelmisc nelgeorges ${QT_LIBRARIES}) TARGET_LINK_LIBRARIES(ovqt_plugin_georges_editor ovqt_plugin_core nelmisc nelgeorges qt_property_browser ${QT_LIBRARIES})
NL_DEFAULT_PROPS(ovqt_plugin_georges_editor "NeL, Tools, 3D: Object Viewer Qt Plugin: Georges Editor") NL_DEFAULT_PROPS(ovqt_plugin_georges_editor "NeL, Tools, 3D: Object Viewer Qt Plugin: Georges Editor")
NL_ADD_RUNTIME_FLAGS(ovqt_plugin_georges_editor) NL_ADD_RUNTIME_FLAGS(ovqt_plugin_georges_editor)

View file

@ -0,0 +1,17 @@
// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2011 Adrian Jaekel <aj at elane2k dot com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// 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 "actions.h"

View file

@ -0,0 +1,20 @@
// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2011 Adrian Jaekel <aj at elane2k dot com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// 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/>.
#ifndef ACTIONS_H
#define ACTIONS_H
#endif // ACTIONS_H

View file

@ -37,6 +37,8 @@
#include "georgesform_proxy_model.h" #include "georgesform_proxy_model.h"
#include "formitem.h" #include "formitem.h"
#if 0
namespace GeorgesQt namespace GeorgesQt
{ {
@ -276,3 +278,5 @@ namespace GeorgesQt
editor->setGeometry(r); editor->setGeometry(r);
} }
} /* namespace GeorgesQt */ } /* namespace GeorgesQt */
#endif // 0

View file

@ -19,6 +19,8 @@
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#if 0
namespace GeorgesQt namespace GeorgesQt
{ {
@ -38,4 +40,6 @@ namespace GeorgesQt
}; };
} }
#endif // 0
#endif // FORMDELEGATE_H #endif // FORMDELEGATE_H

View file

@ -17,9 +17,11 @@
#include "formitem.h" #include "formitem.h"
// Qt includes // Qt includes
#include <QIcon>
// NeL includes // NeL includes
#include <nel/misc/o_xml.h> #include <nel/misc/o_xml.h>
#include <nel/misc/debug.h>
#include <nel/georges/u_type.h> #include <nel/georges/u_type.h>
#include <nel/georges/form.h> #include <nel/georges/form.h>
@ -27,15 +29,8 @@ using namespace NLGEORGES;
namespace GeorgesQt namespace GeorgesQt
{ {
CFormItem::CFormItem()
CFormItem::CFormItem(NLGEORGES::UFormElm* elm, const QList<QVariant> &data, CFormItem *parent,
NLGEORGES::UFormElm::TWhereIsValue wV, NLGEORGES::UFormElm::TWhereIsNode wN)
{ {
parentItem = parent;
itemData = data;
formElm = elm;
whereV = wV;
whereN = wN;
} }
CFormItem::~CFormItem() CFormItem::~CFormItem()
@ -61,12 +56,14 @@ namespace GeorgesQt
int CFormItem::columnCount() const int CFormItem::columnCount() const
{ {
//nlinfo("columnCount %d",itemData.count()); //nlinfo("columnCount %d",itemData.count());
return itemData.count(); //return itemData.count();
return 1;
} }
QVariant CFormItem::data(int column) const QVariant CFormItem::data(int column) const
{ {
return itemData.value(column); //return itemData.value(column);
return QVariant(_Name.c_str());
} }
CFormItem *CFormItem::parent() CFormItem *CFormItem::parent()
@ -84,275 +81,146 @@ namespace GeorgesQt
bool CFormItem::setData(int column, const QVariant &value) bool CFormItem::setData(int column, const QVariant &value)
{ {
if (column < 0 || column >= itemData.size()) if (column != 0)
return false; return false;
// TODO: default values bool deleteInsert = false;
if (!formElm)
return false;
itemData[column] = value;
if (formElm->isAtom())
{
const NLGEORGES::UType *type = formElm->getType();
if (type)
{
switch (type->getType())
{
case NLGEORGES::UType::UnsignedInt:
case NLGEORGES::UType::SignedInt:
case NLGEORGES::UType::Double:
case NLGEORGES::UType::String:
if (parentItem->formElm->isArray())
{
//((NLGEORGES::CFormElm*)parentItem->formElm);//->arrayInsertNodeByName(
//if(parentItem->formElm->getArrayNode(elmName, num))
//{
//}
bool ok;
// TODO: the node can be renamed from eg "#0" to "foobar" // Get the parent node
int arrayIndex = itemData[0].toString().remove("#").toInt(&ok); const NLGEORGES::CFormDfn *parentDfn;
if(ok) uint indexDfn;
{ const NLGEORGES::CFormDfn *nodeDfn;
NLGEORGES::UFormElm *elmt = 0; const NLGEORGES::CType *nodeType;
if(parentItem->formElm->getArrayNode(&elmt, arrayIndex) && elmt) NLGEORGES::CFormElm *parentNode;
{ NLGEORGES::UFormDfn::TEntryType type;
if (elmt->isAtom()) bool array;
{ bool parentVDfnArray;
((NLGEORGES::CFormElmAtom*)elmt)->setValue(value.toString().toStdString().c_str()); NLGEORGES::CForm *form=static_cast<NLGEORGES::CForm*>(m_form);
nldebug(QString("array element string %1 %2") NLGEORGES::CFormElm *elm = static_cast<CFormElm*>(&form->getRootNode());
.arg(itemData[0].toString()).arg(value.toString()) nlverify ( elm->getNodeByName (_FormName.c_str(), &parentDfn, indexDfn, &nodeDfn, &nodeType, &parentNode, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) );
.toStdString().c_str());
} if (parentItem && parentItem->nodeType () == CFormItem::Form)
}
}
}
else
{
if(parentItem->formElm->setValueByName(
value.toString().toStdString().c_str(),
itemData[0].toString().toStdString().c_str()))
{
nldebug(QString("string %1 %2")
.arg(itemData[0].toString()).arg(value.toString())
.toStdString().c_str());
}
else
{
nldebug(QString("FAILED string %1 %2")
.arg(itemData[0].toString()).arg(value.toString())
.toStdString().c_str());
}
}
break;
case NLGEORGES::UType::Color:
nldebug("Color is TODO");
break;
default:
break;
}
}
}
else
{ {
nldebug("setting sth other than Atom"); std::string newName = value.toString().toStdString();
_Name = newName;
// Create an action to update the form.
} }
//formElm->setValueByName();
return true; return true;
} }
// CFormItem *CFormItem::add (/*TSub type,*/ const char *name, uint structId, const char *formName, uint slot) bool CFormItem::isEditable(int column)
// { {
// Add at the end // Ensure only valid types can be edited.
// uint index = _Children.size(); if(_Type == Null)
// _Children.push_back (new CGeorgesEditDocSub); return false;
// _Children[index]->_Type = type; // Make sure only the first column (name) can be editted.
// _Children[index]->_Name = name; if (column != 0)
// _Children[index]->_Parent = this; return false;
// _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 *parent = this->parent();
// If it wasn't a root node then lets check the node type.
const NLGEORGES::CFormDfn *parentDfn;
uint indexDfn;
const NLGEORGES::CFormDfn *nodeDfn;
const NLGEORGES::CType *nodeType;
NLGEORGES::CFormElm *parentNode;
NLGEORGES::UFormDfn::TEntryType type;
bool array;
bool parentVDfnArray;
NLGEORGES::CForm *form = static_cast<CForm*>(m_form);
NLGEORGES::CFormElm *elm = static_cast<CFormElm*>(&form->getRootNode());
nlverify ( elm->getNodeByName (parent->formName ().c_str (), &parentDfn, indexDfn,
&nodeDfn, &nodeType, &parentNode, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) );
if(array && parentNode)
return true;
return false;
}
QIcon CFormItem::getItemImage(CFormItem *rootItem)
{
if(_Type == CFormItem::Null)
{
return QIcon(":/images/root.ico");
}
else if(_Type == CFormItem::Form)
{
// If the parent is the root item then this is the content.
if(parentItem == rootItem)
return QIcon(":/images/root.ico");
// If it wasn't a root node then lets check the node type.
const NLGEORGES::CFormDfn *parentDfn;
uint indexDfn;
const NLGEORGES::CFormDfn *nodeDfn;
const NLGEORGES::CType *nodeType;
NLGEORGES::CFormElm *node;
NLGEORGES::UFormDfn::TEntryType type;
bool array;
bool parentVDfnArray;
NLGEORGES::CForm *form = static_cast<CForm*>(m_form);
NLGEORGES::CFormElm *elm = static_cast<CFormElm*>(&form->getRootNode());
nlverify ( elm->getNodeByName (_FormName.c_str(), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) );
if(array)
{
return QIcon(":/images/array.ico");
}
else
{
if(type == NLGEORGES::UFormDfn::EntryType)
{
if(parentDfn)
{
// Not sure what the hell to do with this. Gets filename from parent dfn?
}
return QIcon(":/images/zfee51.ico");
}
else if(type == NLGEORGES::UFormDfn::EntryDfn)
{
if(parentDfn)
{
// Not sure what the hell to do with this. Gets filename from parent dfn?
}
return QIcon(":/images/struct.ico");
}
else if(type == NLGEORGES::UFormDfn::EntryVirtualDfn)
{
if(node)
{
// Not sure what the hell to do with this. Gets filename from parent dfn?
std::string dfnName;
NLMISC::safe_cast<NLGEORGES::CFormElmVirtualStruct*>(node)->getDfnName(dfnName);
// return dfnName.c_str() ?
}
return QIcon(":/images/vstruct.ico");
}
}
//return QIcon(":/images/struct.ico");
}
return QIcon();
}
CFormItem *CFormItem::add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr)
{ {
CFormItem *newItem = NULL; CFormItem *newNode = new CFormItem();
UFormElm::TWhereIsNode *whereN = new UFormElm::TWhereIsNode; newNode->_Type = type;
UFormElm::TWhereIsValue *whereV = new UFormElm::TWhereIsValue; newNode->_Name = name;
// Append a new item to the current parent's list of children. newNode->parentItem = this;
// std::string elmName; newNode->_StructId = structId;
// if(root->getStructNodeName(num, elmName)) newNode->_FormName = formName;
// { newNode->_Slot = slot;
QList<QVariant> columnData; newNode->m_form = formPtr;
//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) appendChild(newNode);
{ return newNode;
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

@ -18,6 +18,7 @@
#define FORMITEM_H #define FORMITEM_H
// NeL includes // NeL includes
#include <nel/georges/u_form.h>
#include <nel/georges/u_form_elm.h> #include <nel/georges/u_form_elm.h>
// Qt includes // Qt includes
@ -28,18 +29,24 @@ namespace GeorgesQt
{ {
class CFormItem class CFormItem
{ {
public: public:
CFormItem(NLGEORGES::UFormElm *elm, const QList<QVariant> &data, // What is the sub object ?
CFormItem *parent = 0, enum TSub
NLGEORGES::UFormElm::TWhereIsValue wV = NLGEORGES::UFormElm::ValueForm, {
NLGEORGES::UFormElm::TWhereIsNode wN = NLGEORGES::UFormElm::NodeForm); Null, // Nothing in this node (root ?)
Header, // Header node
Type, // This node is a type
Dfn, // This node is a dfn
Form, // This node is a form
};
CFormItem();
~CFormItem(); ~CFormItem();
void appendChild(CFormItem *child); 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 *add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr);
CFormItem *child(int row); CFormItem *child(int row);
int childCount() const; int childCount() const;
@ -48,28 +55,29 @@ namespace GeorgesQt
int row() const; int row() const;
CFormItem *parent(); CFormItem *parent();
bool setData(int column, const QVariant &value); bool setData(int column, const QVariant &value);
NLGEORGES::UFormElm* getFormElm() {return formElm;}
NLGEORGES::UFormElm::TWhereIsValue valueFrom()
{
return whereV;
}
NLGEORGES::UFormElm::TWhereIsNode nodeFrom()
{
return whereN;
}
void setValueFrom(NLGEORGES::UFormElm::TWhereIsValue wV) { whereV = wV; } TSub nodeType() { return _Type; }
void setNodeFrom(NLGEORGES::UFormElm::TWhereIsNode wN) { whereN = wN; } std::string formName() { return _FormName; }
std::string name() { return _Name; }
uint structId() { return _StructId; }
bool isEditable(int column);
QIcon getItemImage(CFormItem *rootItem);
private: private:
//CFormItem() { whereV = NLGEORGES::UFormElm::ValueForm; whereN = NLGEORGES::UFormElm::NodeForm; }
QList<CFormItem*> childItems; QList<CFormItem*> childItems;
QList<QVariant> itemData; QList<QVariant> itemData;
CFormItem *parentItem; CFormItem *parentItem;
NLGEORGES::UFormElm* formElm; NLGEORGES::UFormElm* formElm;
NLGEORGES::UFormElm::TWhereIsValue whereV; NLGEORGES::UForm *m_form;
NLGEORGES::UFormElm::TWhereIsNode whereN;
uint _StructId;
std::string _Name;
std::string _FormName;
TSub _Type;
uint _Slot;
}; // CFormItem }; // CFormItem
} }

View file

@ -1,5 +1,12 @@
<RCC> <RCC>
<qresource> <qresource>
<file>images/array.ico</file>
<file>images/header.ico</file>
<file>images/hold.ico</file>
<file>images/root.ico</file>
<file>images/struct.ico</file>
<file>images/vstruct.ico</file>
<file>images/zfee51.ico</file>
<file>images/ic_nel_georges_editor.png</file> <file>images/ic_nel_georges_editor.png</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -72,23 +72,10 @@ namespace GeorgesQt
m_ui.treeView->header()->setStretchLastSection(true); m_ui.treeView->header()->setStretchLastSection(true);
m_ui.treeViewTabWidget->setTabEnabled (2,false); m_ui.treeViewTabWidget->setTabEnabled (2,false);
m_ui.checkBoxParent->setStyleSheet("background-color: rgba(0,255,0,30)");
m_ui.checkBoxDefaults->setStyleSheet("background-color: rgba(255,0,0,30)");
m_form = 0; m_form = 0;
FormDelegate *formdelegate = new FormDelegate(this);
m_ui.treeView->setItemDelegateForColumn(1, formdelegate);
// Set up custom context menu.
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint&)));
connect(m_ui.treeView, SIGNAL(doubleClicked (QModelIndex)), connect(m_ui.treeView, SIGNAL(doubleClicked (QModelIndex)),
this, SLOT(doubleClicked (QModelIndex))); this, SLOT(doubleClicked (QModelIndex)));
connect(m_ui.checkBoxParent, SIGNAL(toggled(bool)),
this, SLOT(filterRows()));
connect(m_ui.checkBoxDefaults, SIGNAL(toggled(bool)),
this, SLOT(filterRows()));
connect(m_header, SIGNAL(headerClicked(int)), connect(m_header, SIGNAL(headerClicked(int)),
this, SLOT(headerClicked(int))); this, SLOT(headerClicked(int)));
} }
@ -258,16 +245,9 @@ namespace GeorgesQt
loadedForm = m_form->getFilename().c_str(); loadedForm = m_form->getFilename().c_str();
CGeorgesFormModel *model = new CGeorgesFormModel(m_form,deps,comments,parents,m_header->expanded()); CGeorgesFormModel *model = new CGeorgesFormModel(m_form,deps,comments,parents,m_header->expanded());
CGeorgesFormProxyModel *proxyModel = new CGeorgesFormProxyModel(); m_ui.treeView->setModel(model);
proxyModel->setSourceModel(model);
m_ui.treeView->setModel(proxyModel);
m_ui.treeView->expandAll(); m_ui.treeView->expandAll();
// this is a debug output row
m_ui.treeView->hideColumn(3);
filterRows();
// //_ui.treeView->setRowHidden(0,QModelIndex(),true);
connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)), connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),
this, SLOT(modifiedFile())); this, SLOT(modifiedFile()));
@ -283,8 +263,7 @@ namespace GeorgesQt
NLGEORGES::CForm *parentForm = dynamic_cast<NLGEORGES::CForm*>(uParentForm); NLGEORGES::CForm *parentForm = dynamic_cast<NLGEORGES::CForm*>(uParentForm);
NLGEORGES::CForm *mainForm = static_cast<NLGEORGES::CForm*>(m_form); NLGEORGES::CForm *mainForm = static_cast<NLGEORGES::CForm*>(m_form);
CGeorgesFormProxyModel * proxyModel = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model()); CGeorgesFormModel *model = dynamic_cast<CGeorgesFormModel *>(m_ui.treeView->model());
CGeorgesFormModel *model = dynamic_cast<CGeorgesFormModel *>(proxyModel->sourceModel());
if(parentForm) if(parentForm)
{ {
@ -397,19 +376,15 @@ namespace GeorgesQt
void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index ) void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index )
{ {
// TODO: this is messy :( perhaps this can be done better //CGeorgesFormModel *model =
CGeorgesFormProxyModel * proxyModel = // dynamic_cast<CGeorgesFormModel *>((m_ui.treeView->model());
dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model());
CGeorgesFormModel *model =
dynamic_cast<CGeorgesFormModel *>(proxyModel->sourceModel());
QModelIndex sourceIndex = proxyModel->mapToSource(index);
CFormItem *item = model->getItem(sourceIndex); //CFormItem *item = model->getItem(index);
if (item->parent() && item->parent()->data(0) == "parents") //if (item->parent() && item->parent()->data(0) == "parents")
{ //{
Q_EMIT changeFile(CPath::lookup(item->data(0).toString().toStdString(),false).c_str()); // Q_EMIT changeFile(CPath::lookup(item->data(0).toString().toStdString(),false).c_str());
} //}
//// col containing additional stuff like icons //// col containing additional stuff like icons
//if (index.column() == 2) //if (index.column() == 2)
@ -475,129 +450,129 @@ namespace GeorgesQt
void CGeorgesTreeViewDialog::filterRows() void CGeorgesTreeViewDialog::filterRows()
{ {
CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model()); //CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model());
CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel()); //CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel());
if (m) { //if (m) {
m->setShowParents(m_ui.checkBoxParent->isChecked()); // m->setShowParents(m_ui.checkBoxParent->isChecked());
m->setShowDefaults(m_ui.checkBoxDefaults->isChecked()); // m->setShowDefaults(m_ui.checkBoxDefaults->isChecked());
} //}
} }
void CGeorgesTreeViewDialog::showContextMenu(const QPoint &pos) void CGeorgesTreeViewDialog::showContextMenu(const QPoint &pos)
{ {
QMenu contextMenu; //QMenu contextMenu;
QMenu *structContext = NULL; //QMenu *structContext = NULL;
QPoint globalPos = this->mapToGlobal(pos); //QPoint globalPos = this->mapToGlobal(pos);
//
//// Fisrt we're going to see if we've right clicked on a new item and select it.
//const QModelIndex &index = this->m_ui.treeView->currentIndex();
// Fisrt we're going to see if we've right clicked on a new item and select it. //if(!index.isValid())
const QModelIndex &index = this->m_ui.treeView->currentIndex(); // return;
if(!index.isValid()) //CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model());
return; //CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel());
//QModelIndex sourceIndex = mp->mapToSource(index);
CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model()); //if (m)
CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel()); //{
QModelIndex sourceIndex = mp->mapToSource(index); //
// CFormItem *item = m->getItem(sourceIndex);
if (m) // // Right click on the "parents" item
{ // if (item->data(0) == "parents")
// contextMenu.addAction("Add parent...");
// // Right click on a parent item
// else if(item->parent() && item->parent()->data(0) == "parents")
// {
// contextMenu.addAction("Add parent...");
// contextMenu.addAction("Remove parent");
// }
// else if(item->getFormElm()->isArray())
// contextMenu.addAction("Add array entry...");
// else if(item->getFormElm()->isStruct())
// {
// QMenu *structContext = new QMenu("Add struct element...", this);
// contextMenu.addMenu(structContext);
CFormItem *item = m->getItem(sourceIndex); // NLGEORGES::UFormDfn *defn = item->getFormElm()->getStructDfn();
// if(defn)
// {
// for(uint defnNum=0; defnNum < defn->getNumEntry(); defnNum++)
// {
// std::string entryName;
// std::string dummy;
// UFormElm::TWhereIsValue *whereV = new UFormElm::TWhereIsValue;
// bool result = defn->getEntryName(defnNum, entryName);
// bool result2 = item->getFormElm()->getValueByName(dummy, entryName.c_str(), NLGEORGES::UFormElm::Eval, whereV);
// Right click on the "parents" item //
if (item->data(0) == "parents") // if(result2 && *whereV != UFormElm::ValueForm)
contextMenu.addAction("Add parent..."); // {
// Right click on a parent item // structContext->addAction(entryName.c_str());
else if(item->parent() && item->parent()->data(0) == "parents") // }
{ // delete whereV;
contextMenu.addAction("Add parent..."); // }
contextMenu.addAction("Remove parent"); // }
} // }
else if(item->getFormElm()->isArray()) // else if(item->getFormElm()->isAtom() && item->valueFrom() == NLGEORGES::UFormElm::ValueForm)
contextMenu.addAction("Add array entry..."); // contextMenu.addAction("Revert to parent/default...");
else if(item->getFormElm()->isStruct())
{
QMenu *structContext = new QMenu("Add struct element...", this);
contextMenu.addMenu(structContext);
NLGEORGES::UFormDfn *defn = item->getFormElm()->getStructDfn(); // QAction *selectedItem = contextMenu.exec(globalPos);
if(defn) // if(selectedItem)
{ // {
for(uint defnNum=0; defnNum < defn->getNumEntry(); defnNum++) // if(selectedItem->text() == "Add parent...")
{ // {
std::string entryName; // // Get the file extension of the form so we can build a dialog pattern.
std::string dummy; // QString file = m_form->getFilename().c_str();
UFormElm::TWhereIsValue *whereV = new UFormElm::TWhereIsValue; // file = file.remove(0,file.indexOf(".")+1);
bool result = defn->getEntryName(defnNum, entryName); // QString filePattern = "Parent Sheets (*."+file+")";
bool result2 = item->getFormElm()->getValueByName(dummy, entryName.c_str(), NLGEORGES::UFormElm::Eval, whereV); //
// nlinfo("parent defn name '%s'", file.toStdString().c_str());
// QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select parent sheets..."), m_lastSheetDir, filePattern);
// if(!fileNames.isEmpty())
// {
// Q_FOREACH(QString fileToParent, fileNames)
// {
// // Get just the filename. Georges doesn't want the path.
// QFileInfo pathInfo( fileToParent );
// QString tmpFileName( pathInfo.fileName() );
// nlinfo("requesting to add parent form '%s'", tmpFileName.toStdString().c_str());
//
// // Call to add the form and load it into the Georges form.
// addParentForm(tmpFileName);
if(result2 && *whereV != UFormElm::ValueForm) // // Save the file lookup path for future dialog boxes.
{ // m_lastSheetDir = pathInfo.absolutePath();
structContext->addAction(entryName.c_str()); // }
} // }
delete whereV; // m_ui.treeView->expandAll();
} // }
} // else if(selectedItem->text() == "Remove parent")
} // {
else if(item->getFormElm()->isAtom() && item->valueFrom() == NLGEORGES::UFormElm::ValueForm) // NLGEORGES::CForm *form = static_cast<NLGEORGES::CForm *>(m_form);
contextMenu.addAction("Revert to parent/default..."); // QString parentFileName = item->data(0).toString();
QAction *selectedItem = contextMenu.exec(globalPos); // for(uint num = 0; num < form->getParentCount(); num++)
if(selectedItem) // {
{ // QString curParentName = form->getParent(num)->getFilename().c_str();
if(selectedItem->text() == "Add parent...") // if(parentFileName == curParentName)
{ // {
// Get the file extension of the form so we can build a dialog pattern. // form->removeParent(num);
QString file = m_form->getFilename().c_str(); // m->removeParentForm(parentFileName);
file = file.remove(0,file.indexOf(".")+1); // break;
QString filePattern = "Parent Sheets (*."+file+")"; // }
// }
nlinfo("parent defn name '%s'", file.toStdString().c_str()); // m_ui.treeView->expandAll();
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select parent sheets..."), m_lastSheetDir, filePattern); // }
if(!fileNames.isEmpty())
{
Q_FOREACH(QString fileToParent, fileNames)
{
// Get just the filename. Georges doesn't want the path.
QFileInfo pathInfo( fileToParent );
QString tmpFileName( pathInfo.fileName() );
nlinfo("requesting to add parent form '%s'", tmpFileName.toStdString().c_str()); // } // if selected context menu item is valid.
//} // if 'm' model valid.
// Call to add the form and load it into the Georges form. //if(structContext)
addParentForm(tmpFileName); // delete structContext;
// Save the file lookup path for future dialog boxes.
m_lastSheetDir = pathInfo.absolutePath();
}
}
m_ui.treeView->expandAll();
}
else if(selectedItem->text() == "Remove parent")
{
NLGEORGES::CForm *form = static_cast<NLGEORGES::CForm *>(m_form);
QString parentFileName = item->data(0).toString();
for(uint num = 0; num < form->getParentCount(); num++)
{
QString curParentName = form->getParent(num)->getFilename().c_str();
if(parentFileName == curParentName)
{
form->removeParent(num);
m->removeParentForm(parentFileName);
break;
}
}
m_ui.treeView->expandAll();
}
} // if selected context menu item is valid.
} // if 'm' model valid.
if(structContext)
delete structContext;
} }
} /* namespace GeorgesQt */ } /* namespace GeorgesQt */

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>564</width>
<height>300</height> <height>525</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -18,8 +18,8 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>199</width> <width>280</width>
<height>165</height> <height>242</height>
</size> </size>
</property> </property>
<property name="focusPolicy"> <property name="focusPolicy">
@ -29,9 +29,21 @@
<string/> <string/>
</property> </property>
<widget class="QWidget" name="dockWidgetContents"> <widget class="QWidget" name="dockWidgetContents">
<layout class="QGridLayout" name="gridLayout"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QTabWidget" name="treeViewTabWidget"> <widget class="QTabWidget" name="treeViewTabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="tabPosition"> <property name="tabPosition">
<enum>QTabWidget::West</enum> <enum>QTabWidget::West</enum>
</property> </property>
@ -39,60 +51,40 @@
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="form_tab"> <widget class="QWidget" name="form_tab">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<attribute name="title"> <attribute name="title">
<string>Form</string> <string>Form</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="bottomMargin"> <item>
<number>0</number> <widget class="QSplitter" name="splitter">
</property>
<item row="0" column="0" colspan="4">
<widget class="QTreeView" name="treeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBoxParent">
<property name="text">
<string>Parent</string>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <widget class="QTreeView" name="treeView">
<size> <property name="sizePolicy">
<width>40</width> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<height>20</height> <horstretch>0</horstretch>
</size> <verstretch>0</verstretch>
</property> </sizepolicy>
</spacer> </property>
</item> <property name="minimumSize">
<item row="1" column="1"> <size>
<widget class="QCheckBox" name="checkBoxDefaults"> <width>0</width>
<property name="text"> <height>0</height>
<string>Defaults</string> </size>
</property> </property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
<widget class="QtTreePropertyBrowser" name="propertiesBrowser" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -126,8 +118,14 @@
</layout> </layout>
</widget> </widget>
</widget> </widget>
<resources> <customwidgets>
<include location="georges_editor.qrc"/> <customwidget>
</resources> <class>QtTreePropertyBrowser</class>
<extends>QWidget</extends>
<header>qttreepropertybrowser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/> <connections/>
</ui> </ui>

View file

@ -53,7 +53,7 @@ namespace GeorgesQt
{ {
m_form = form; m_form = form;
m_rootData << "Value" << "Data" << "Extra";// << "Type"; m_rootData << "Value" << "Data" << "Extra";// << "Type";
m_rootItem = new CFormItem(m_rootElm, m_rootData); m_rootItem = new CFormItem();
m_dependencies = deps; m_dependencies = deps;
m_comments = comment; m_comments = comment;
m_parents = parents; m_parents = parents;
@ -81,144 +81,12 @@ namespace GeorgesQt
{ {
return getItem(p_index)->data(p_index.column()); return getItem(p_index)->data(p_index.column());
} }
case Qt::BackgroundRole: case Qt::DecorationRole:
{ {
QBrush defaultBrush = QBrush(QColor(255,0,0,30)); // Based on the _Type return a QIcon from resources.
QBrush parentBrush = QBrush(QColor(0,255,0,30)); CFormItem *item = getItem(p_index);
return item->getItemImage(m_rootItem);
// 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.toStdString(),false).c_str();
/*if (value.contains(".shape"))
{
if (Modules::objViewInt())
{
QIcon *icon = Modules::objViewInt()->saveOneImage(value.toStdString());
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.toStdString(),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.toStdString());
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.toStdString(),false).c_str();
if(path.isEmpty())
{
path = ":/images/pqrticles.png";
}
QString imageTooltip = QString("<img src='%1'>").arg(path);
return imageTooltip;
}
}
return QVariant();
break;
}
default: default:
return QVariant(); return QVariant();
} }
@ -239,14 +107,17 @@ namespace GeorgesQt
/******************************************************************************/ /******************************************************************************/
bool CGeorgesFormModel::setData(const QModelIndex &index, const QVariant &value, bool CGeorgesFormModel::setData(const QModelIndex &index, const QVariant &value, int role)
int role)
{ {
if (role != Qt::EditRole) if (role != Qt::EditRole)
return false; return false;
CFormItem *item = getItem(index); CFormItem *item = getItem(index);
if(!item->isEditable(index.column()))
return false;
bool result = item->setData(index.column(), value); bool result = item->setData(index.column(), value);
Q_EMIT dataChanged(index, index); Q_EMIT dataChanged(index, index);
@ -264,8 +135,12 @@ namespace GeorgesQt
Qt::ItemFlags returnValue = Qt::ItemIsSelectable | Qt::ItemIsEnabled; Qt::ItemFlags returnValue = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
if(index.column() == 1) CFormItem *item = getItem(index);
returnValue |= Qt::ItemIsEditable;
if(item->isEditable(index.column()))
{
returnValue |= Qt::ItemIsEditable;
}
return returnValue; return returnValue;
@ -383,223 +258,7 @@ namespace GeorgesQt
/******************************************************************************/ /******************************************************************************/
void CGeorgesFormModel::loadFormData(UFormElm *root, CFormItem *parent) { void CGeorgesFormModel::loadFormData(UFormElm *root, CFormItem *parent) {
return;
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:
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;
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));
}
}
else
{
nlinfo("getNodeByName returned false");
}
}
num++;
}
}
if (root->isArray())
{
uint arraySize = 0;
root->getArraySize(arraySize);
while (num < arraySize)
{
std::string elmName;
if(root->getArrayNodeName(elmName, num))
{
QList<QVariant> columnData;
std::string value;
QString elmtType = "";
UFormElm *elmt = 0;
if(root->getArrayNode(&elmt,0) && elmt)
{
if (elmt->isArray())
elmtType = "Array";
if (elmt->isStruct()) {
elmtType = "Struct";
}
if (elmt->isAtom())
{
elmt->getValue(value);
elmtType = "Atom";
}
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));
}
}
num++;
}
}
} }
CFormItem *CGeorgesFormModel::addStruct (CFormItem *parent, CFormItem *CGeorgesFormModel::addStruct (CFormItem *parent,
@ -614,8 +273,9 @@ namespace GeorgesQt
NLGEORGES::CForm *formPtr = static_cast<NLGEORGES::CForm*>(m_form); NLGEORGES::CForm *formPtr = static_cast<NLGEORGES::CForm*>(m_form);
// Add the new node // Add the new node
// CFormItem *newNode = parent->add(/*CGeorgesEditDocSub::Form,*/ name, structId, formName, slot); CFormItem *newNode = parent->add(CFormItem::Form, name, structId, formName, slot, m_form);
CFormItem *newNode = parent->add(_struct, name);
nlinfo("Added form %s : %s", name, formName);
// Can be NULL in virtual DFN // Can be NULL in virtual DFN
if (parentDfn) if (parentDfn)
@ -750,8 +410,7 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
uint slot) uint slot)
{ {
// Add the new node // Add the new node
//CFormItem *newNode = parent->add (/*CGeorgesEditDocSub::Form,*/ name, structId, formName, slot); CFormItem *newNode = parent->add (CFormItem::Form, name, structId, formName, slot, m_form);
CFormItem *newNode = parent->add (array, name);
// The array exist // The array exist
if (array) if (array)
@ -778,14 +437,13 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
if (rootDfn) if (rootDfn)
{ {
// Get struct ptr // Get struct ptr
NLGEORGES::CFormElmStruct *elmPtr = array->Elements[elm].Element ? NLMISC::safe_cast<NLGEORGES::CFormElmStruct*>(array->Elements[elm].Element) : NULL; NLGEORGES::CFormElmStruct *elmPtr = array->Elements[elm].Element ? static_cast<NLGEORGES::CFormElmStruct*>(array->Elements[elm].Element) : NULL;
addStruct (newNode, elmPtr, rootDfn, formArrayName, elm, formArrayElmName, slot); addStruct (newNode, elmPtr, rootDfn, formArrayName, elm, formArrayElmName, slot);
} }
else else
{ {
NLGEORGES::CFormElmArray *elmPtr = array->Elements[elm].Element ? NLMISC::safe_cast<NLGEORGES::CFormElmArray*>(array->Elements[elm].Element) : NULL; NLGEORGES::CFormElmArray *elmPtr = array->Elements[elm].Element ? static_cast<NLGEORGES::CFormElmArray*>(array->Elements[elm].Element) : NULL;
newNode->add (elmPtr, formArrayElmName); newNode->add (CFormItem::Form, formArrayName, elm, formArrayElmName, slot, m_form);
//newNode->add (/*CGeorgesEditDocSub::Form,*/ formArrayName, elm, formArrayElmName, slot);
} }
} }
} }
@ -800,7 +458,7 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
void CGeorgesFormModel::loadFormHeader() void CGeorgesFormModel::loadFormHeader()
{ {
if (m_parents.size()) /* if (m_parents.size())
{ {
CFormItem *fi_pars = new CFormItem(m_rootElm, QList<QVariant>() << "parents" << "" << "", m_rootItem); CFormItem *fi_pars = new CFormItem(m_rootElm, QList<QVariant>() << "parents" << "" << "", m_rootItem);
m_rootItem->appendChild(fi_pars); m_rootItem->appendChild(fi_pars);
@ -809,7 +467,7 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
{ {
fi_pars->appendChild(new CFormItem(m_rootElm, QList<QVariant>() << str << "" << "", fi_pars)); fi_pars->appendChild(new CFormItem(m_rootElm, QList<QVariant>() << str << "" << "", fi_pars));
} }
} }*/
/*QStringList dfns = _dependencies["dfn"]; /*QStringList dfns = _dependencies["dfn"];
QStringList typs = _dependencies["typ"]; QStringList typs = _dependencies["typ"];
@ -851,7 +509,7 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
{ {
m_rootElm = &((NLGEORGES::CForm*)m_form)->Elements; m_rootElm = &((NLGEORGES::CForm*)m_form)->Elements;
NLGEORGES::CFormElmStruct *rootstruct = &((NLGEORGES::CForm*)m_form)->Elements; NLGEORGES::CFormElmStruct *rootstruct = &((NLGEORGES::CForm*)m_form)->Elements;
loadFormHeader(); //loadFormHeader();
addStruct(m_rootItem, rootstruct, rootstruct->FormDfn, "Content", 0xffffffff, "", 0); addStruct(m_rootItem, rootstruct, rootstruct->FormDfn, "Content", 0xffffffff, "", 0);
//loadFormData(m_rootElm, m_rootItem); //loadFormData(m_rootElm, m_rootItem);
} }
@ -875,7 +533,7 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
beginResetModel(); beginResetModel();
m_parents.push_back(parentForm); m_parents.push_back(parentForm);
delete m_rootItem; delete m_rootItem;
m_rootItem = new CFormItem(m_rootElm, m_rootData); m_rootItem = new CFormItem();
setupModelData(); setupModelData();
endResetModel(); endResetModel();
} }
@ -886,7 +544,7 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
m_parents.removeOne(parentForm); m_parents.removeOne(parentForm);
delete m_rootItem; delete m_rootItem;
m_rootItem = new CFormItem(m_rootElm, m_rootData); m_rootItem = new CFormItem();
setupModelData(); setupModelData();
endResetModel(); endResetModel();
} }

View file

@ -23,6 +23,8 @@
#include "georgesform_proxy_model.h" #include "georgesform_proxy_model.h"
#include "georgesform_model.h" #include "georgesform_model.h"
#if 0
namespace GeorgesQt namespace GeorgesQt
{ {
@ -78,4 +80,5 @@ namespace GeorgesQt
} }
} /* namespace GeorgesQt */ } /* namespace GeorgesQt */
#endif // 0
/* end of file */ /* end of file */

View file

@ -20,6 +20,7 @@
// Qt includes // Qt includes
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#if 0
namespace GeorgesQt namespace GeorgesQt
{ {
@ -41,5 +42,5 @@ namespace GeorgesQt
};/* class CGeorgesFormProxyModel */ };/* class CGeorgesFormProxyModel */
} /* namespace GeorgesQt */ } /* namespace GeorgesQt */
#endif // 0
#endif // GEORGESFORM_PROXY_MODEL_H #endif // GEORGESFORM_PROXY_MODEL_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB