Merged default.

This commit is contained in:
dfighter1985 2014-09-05 22:28:11 +02:00
commit 15f6ed3c37
11 changed files with 233 additions and 30 deletions

View file

@ -454,6 +454,7 @@ public:
// Set the value, the elt been used
void setValue (const char *value);
std::string getValue() const;
private:
// The value

View file

@ -3056,6 +3056,13 @@ void CFormElmAtom::setValue (const char *value)
// ***************************************************************************
std::string CFormElmAtom::getValue() const
{
return Value;
}
// ***************************************************************************
void CFormElmAtom::getFormName (std::string &result, const CFormElm *child) const
{
// Must be NULL

View file

@ -26,7 +26,6 @@
namespace
{
QVariant::Type getValueType( const NLGEORGES::UType *typ )
{
QVariant::Type t = QVariant::String;
@ -47,6 +46,55 @@ namespace
return t;
}
QVariant::Type getValueTypeFromDfn( NLGEORGES::CFormElmStruct *st, int idx )
{
NLGEORGES::CFormDfn *cdfn = st->FormDfn;
NLGEORGES::CFormDfn::CEntry entry = cdfn->getEntry( idx );
return getValueType( entry.getTypePtr() );
}
QVariant::Type getValueTypeFromDfn( NLGEORGES::CFormElmAtom *atom )
{
QVariant::Type t = QVariant::String;
NLGEORGES::CFormElm *cparent = static_cast< NLGEORGES::CFormElm* >( atom->getParent() );
if( cparent->isArray() )
{
NLGEORGES::CFormElmStruct *aparent = static_cast< NLGEORGES::CFormElmStruct* >( cparent->getParent() );
NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( aparent->getStructDfn() );
int idx = -1;
for( idx = 0; idx < aparent->Elements.size(); idx++ )
{
if( aparent->Elements[ idx ].Element == cparent )
break;
}
NLGEORGES::CFormDfn::CEntry entry = cdfn->getEntry( idx );
return getValueType( entry.getTypePtr() );
}
else
if( cparent->isStruct() )
{
NLGEORGES::CFormElmStruct *sparent = static_cast< NLGEORGES::CFormElmStruct* >( cparent );
NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( cparent->getStructDfn() );
int idx = -1;
for( idx = 0; idx < sparent->Elements.size(); idx++ )
{
if( sparent->Elements[ idx ].Element == atom )
break;
}
NLGEORGES::CFormDfn::CEntry entry = cdfn->getEntry( idx );
return getValueType( entry.getTypePtr() );
}
return t;
}
NLGEORGES::UFormElm* getGeorgesNode( GeorgesQt::CFormItem *item )
{
NLGEORGES::UFormElm *n = NULL;
@ -73,8 +121,19 @@ BrowserCtrlPvt::~BrowserCtrlPvt()
m_browser = NULL;
}
void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm )
void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct *st, int idx )
{
NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ idx ];
if( ( elm.Element != NULL ) && !elm.Element->isAtom() )
return;
if( elm.Element == NULL )
{
NLGEORGES::CFormDfn::CEntry &entry = st->FormDfn->getEntry( idx );
if( entry.getArrayFlag() )
return;
}
QString key = elm.Name.c_str();
QString value = "";
QVariant::Type t = QVariant::String;
@ -90,6 +149,10 @@ void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &el
m_rootNode->getValueByName( v, formName.c_str(), NLGEORGES::UFormElm::NoEval, NULL, 0 );
value = v.c_str();
}
else
{
t = getValueTypeFromDfn( st, idx );
}
QtVariantProperty *p = mgr->addProperty( t, key );
p->setValue( value );
@ -102,18 +165,7 @@ void BrowserCtrlPvt::setupStruct( NLGEORGES::UFormElm *node )
for( int i = 0; i < st->Elements.size(); i++ )
{
NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ i ];
if( ( elm.Element != NULL ) && !elm.Element->isAtom() )
continue;
if( elm.Element == NULL )
{
NLGEORGES::CFormDfn::CEntry &entry = st->FormDfn->getEntry( i );
if( entry.getArrayFlag() )
continue;
}
setupAtom( elm );
setupAtom( st, i );
}
}
@ -146,6 +198,34 @@ void BrowserCtrlPvt::setupArray( GeorgesQt::CFormItem *node )
m_browser->addProperty( p );
}
void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node )
{
NLGEORGES::UFormElm *n = getGeorgesNode( node );
if( n == NULL )
return;
NLGEORGES::CFormElmAtom *atom = static_cast< NLGEORGES::CFormElmAtom* >( n );
std::string v = atom->getValue();
const NLGEORGES::CType *t = atom->getType();
QVariant::Type tt = QVariant::String;
if( t != NULL )
{
tt = getValueType( t );
}
else
{
tt = getValueTypeFromDfn( atom );
}
QtVariantProperty *p = mgr->addProperty( tt, "value" );
p->setValue( v.c_str() );
m_browser->addProperty( p );
m_currentNode.p = n;
}
void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node )
{
m_currentNode.clear();
@ -156,7 +236,11 @@ void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node )
if( node->isArray() )
setupArray( node );
else
if( node->isStruct() )
setupStruct( node );
else
if( node->isAtom() )
setupAtom( node );
m_browser->setFactoryForManager( mgr, factory );
}
@ -281,6 +365,15 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value )
m_currentNode.p = NULL;
}
void BrowserCtrlPvt::onAtomValueChanged( QtProperty *p, const QVariant &value )
{
NLGEORGES::CFormElmAtom *atom = static_cast< NLGEORGES::CFormElmAtom* >( m_currentNode.p );
atom->setValue( value.toString().toUtf8() );
Q_EMIT modified();
Q_EMIT valueChanged( m_currentNode.name, value.toString() );
}
void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value )
{
if( m_currentNode.p == NULL )
@ -297,6 +390,9 @@ void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value )
else
if( m_currentNode.p->isArray() )
onArrayValueChanged( p, value );
else
if( m_currentNode.p->isAtom() )
onAtomValueChanged( p, value );
}

View file

@ -61,13 +61,15 @@ Q_SIGNALS:
private:
void setupStruct( NLGEORGES::UFormElm *node );
void setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm );
void setupAtom( NLGEORGES::CFormElmStruct *st, int idx );
void setupStruct( GeorgesQt::CFormItem *node );
void setupArray( GeorgesQt::CFormItem *node );
void setupAtom( GeorgesQt::CFormItem *node );
void onStructValueChanged( QtProperty *p, const QVariant &value );
void onArrayValueChanged( QtProperty *p, const QVariant &value );
void onAtomValueChanged( QtProperty *p, const QVariant &value );
void createArray();
QtVariantPropertyManager *mgr;

View file

@ -40,7 +40,7 @@ namespace GeorgesQt
_StructId = 0;
_Slot = 0;
_Type = Null;
_Array = false;
_TType = TYPE_ATOM;
}
CFormItem::~CFormItem()
@ -113,7 +113,10 @@ namespace GeorgesQt
bool CFormItem::isArray()
{
return _Array;
if( _TType == TYPE_ARRAY )
return true;
else
return false;
}
bool CFormItem::isArrayMember()
@ -124,6 +127,30 @@ namespace GeorgesQt
return parentItem->isArray();
}
bool CFormItem::isStruct()
{
if( _TType == TYPE_STRUCT )
return true;
else
return false;
}
bool CFormItem::isVStruct()
{
if( _TType == TYPE_VSTRUCT )
return true;
else
return false;
}
bool CFormItem::isAtom()
{
if( _TType == TYPE_ATOM )
return true;
else
return false;
}
QIcon CFormItem::getItemImage(CFormItem *rootItem)
{
if(_Type == CFormItem::Null)
@ -211,7 +238,7 @@ namespace GeorgesQt
childItems.clear();
}
CFormItem *CFormItem::add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr, bool isArray)
CFormItem *CFormItem::add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr, TType itemType )
{
CFormItem *newNode = new CFormItem();
newNode->_Type = type;
@ -221,7 +248,7 @@ namespace GeorgesQt
newNode->_FormName = formName;
newNode->_Slot = slot;
newNode->m_form = formPtr;
newNode->_Array = isArray;
newNode->_TType = itemType;
appendChild(newNode);
return newNode;

View file

@ -41,12 +41,20 @@ namespace GeorgesQt
Form, // This node is a form
};
enum TType
{
TYPE_ARRAY,
TYPE_STRUCT,
TYPE_VSTRUCT,
TYPE_ATOM
};
CFormItem();
~CFormItem();
void appendChild(CFormItem *child);
CFormItem *add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr, bool isArray );
CFormItem *add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr, TType itemType );
CFormItem *child(int row);
int childCount() const;
@ -69,6 +77,9 @@ namespace GeorgesQt
bool isEditable(int column);
bool isArray();
bool isArrayMember();
bool isStruct();
bool isVStruct();
bool isAtom();
QIcon getItemImage(CFormItem *rootItem);
@ -95,7 +106,7 @@ namespace GeorgesQt
std::string _FormName;
TSub _Type;
uint _Slot;
bool _Array;
TType _TType;
}; // CFormItem

View file

@ -115,6 +115,8 @@ void GeorgesDFNDialog::newDocument( const QString &fileName )
m_pvt->dfn = new NLGEORGES::CFormDfn();
loadDfn();
log( "Created" );
}
void GeorgesDFNDialog::onAddClicked()

View file

@ -423,6 +423,8 @@ namespace GeorgesQt
setWindowTitle( info.fileName() + "*" );
setModified( true );
log( "Created" );
return true;
}

View file

@ -115,6 +115,8 @@ void GeorgesTypDialog::newDocument( const QString &fileName )
setModified( true );
loadTyp();
log( "Created" );
}
void GeorgesTypDialog::onAddClicked()

View file

@ -277,13 +277,20 @@ namespace GeorgesQt
const char *name,
uint structId,
const char *formName,
uint slot)
uint slot,
bool isVirtual)
{
// 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, false);
CFormItem::TType ttype;
if( isVirtual )
ttype = CFormItem::TYPE_VSTRUCT;
else
ttype = CFormItem::TYPE_STRUCT;
CFormItem *newNode = parent->add(CFormItem::Form, name, structId, formName, slot, m_form, ttype );
// Can be NULL in virtual DFN
if (parentDfn)
@ -367,7 +374,10 @@ namespace GeorgesQt
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( entry.getType() == NLGEORGES::UFormDfn::EntryVirtualDfn )
addStruct (newNode, nextForm, tmpDfn, entry.getName().c_str(), elm, entryName.c_str(), slot, true);
else
addStruct (newNode, nextForm, tmpDfn, entry.getName().c_str(), elm, entryName.c_str(), slot);
}
}
// Array of type ?
@ -418,7 +428,7 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
uint slot)
{
// Add the new node
CFormItem *newNode = parent->add (CFormItem::Form, name, structId, formName, slot, m_form, true);
CFormItem *newNode = parent->add (CFormItem::Form, name, structId, formName, slot, m_form, CFormItem::TYPE_ARRAY );
// The array exist
if (array)
@ -451,7 +461,7 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
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, false);
addAtom( newNode, elmPtr, rootDfn, formArrayName, elm, formArrayElmName );
}
}
}
@ -460,6 +470,39 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
}
CFormItem *CGeorgesFormModel::addAtom(CFormItem *parent, NLGEORGES::CFormElm *elm, NLGEORGES::CFormDfn *dfn, const char *name, uint id, const char *formName)
{
CFormItem *item = parent->add( CFormItem::Form, name, id, formName, 0, m_form, CFormItem::TYPE_ATOM );
return item;
}
CFormItem *CGeorgesFormModel::addItem(CFormItem *parent, NLGEORGES::CFormElm *elm, NLGEORGES::CFormDfn *dfn, const char *name, uint id, const char *formName)
{
CFormItem *item = NULL;
if( elm->isAtom() )
item = addAtom(parent, elm, dfn, name, id, formName );
else
if( elm->isStruct() || elm->isVirtualStruct() )
{
NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( elm );
if( st->isVirtualStruct() )
item = addStruct(parent, st, st->FormDfn, name, id, formName, 0, true);
else
item = addStruct(parent, st, st->FormDfn, name, id, formName, 0, false);
}
else
if( elm->isArray() )
{
NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( elm );
item = addArray(parent, arr, arr->FormDfn, name, id, formName, 0 );
}
return item;
}
void CGeorgesFormModel::arrayResized( const QString &name, int size )
{
CFormItem *item = m_rootItem->findItem( name );
@ -494,7 +537,9 @@ void CGeorgesFormModel::arrayResized( const QString &name, int size )
else
n = e.Name.c_str();
item->add( CFormItem::Form, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0, item->form(), false );
NLGEORGES::UFormDfn *udfn = e.Element->getStructDfn();
NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn );
addItem( item, e.Element, cdfn, n.toUtf8().constData(), i, formName.toUtf8().constData() );
}
if( celm->Elements.size() == 0 )
@ -566,7 +611,9 @@ void CGeorgesFormModel::appendArray( QModelIndex idx )
std::string formName;
node->getFormName( formName );
item->add( CFormItem::Form, name.c_str(), s, formName.c_str(), 0, item->form(), false );
NLGEORGES::CFormDfn *cdfn = const_cast< NLGEORGES::CFormDfn* >( nodeDfn );
addItem( item, node, cdfn, name.c_str(), s, formName.c_str() );
}
void CGeorgesFormModel::deleteArrayEntry( QModelIndex idx )
@ -608,7 +655,9 @@ void CGeorgesFormModel::deleteArrayEntry( QModelIndex idx )
else
n = e.Name.c_str();
item->add( CFormItem::Form, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0, item->form(), false );
NLGEORGES::UFormDfn *udfn = e.Element->getStructDfn();
NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn );
addItem( item, e.Element, cdfn, n.toUtf8().constData(), i, formName.toUtf8().constData() );
}
Q_EMIT endResetModel();

View file

@ -65,11 +65,15 @@ namespace GeorgesQt
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);
const char *name, uint structId, const char *formName, uint slot, bool isVirtual = false );
CFormItem *addArray(CFormItem *parent, NLGEORGES::CFormElmArray *array, NLGEORGES::CFormDfn *rootDfn,
const char *name, uint structId, const char *formName, uint slot);
CFormItem *addAtom(CFormItem *parent, NLGEORGES::CFormElm *elm, NLGEORGES::CFormDfn *dfn, const char *name, uint id, const char *formName);
CFormItem *addItem(CFormItem *parent, NLGEORGES::CFormElm *elm, NLGEORGES::CFormDfn *dfn, const char *name, uint id, const char *formName);
void emitDataChanged(const QModelIndex &index)
{
Q_EMIT dataChanged(index, index);