Get type info from DFN.

--HG--
branch : dfighter-tools
This commit is contained in:
dfighter1985 2014-09-05 21:42:14 +02:00
parent ff0df2bf50
commit 3a94909a92
2 changed files with 71 additions and 15 deletions

View file

@ -26,7 +26,6 @@
namespace namespace
{ {
QVariant::Type getValueType( const NLGEORGES::UType *typ ) QVariant::Type getValueType( const NLGEORGES::UType *typ )
{ {
QVariant::Type t = QVariant::String; QVariant::Type t = QVariant::String;
@ -47,6 +46,55 @@ namespace
return t; 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* getGeorgesNode( GeorgesQt::CFormItem *item )
{ {
NLGEORGES::UFormElm *n = NULL; NLGEORGES::UFormElm *n = NULL;
@ -73,8 +121,19 @@ BrowserCtrlPvt::~BrowserCtrlPvt()
m_browser = NULL; 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 key = elm.Name.c_str();
QString value = ""; QString value = "";
QVariant::Type t = QVariant::String; 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 ); m_rootNode->getValueByName( v, formName.c_str(), NLGEORGES::UFormElm::NoEval, NULL, 0 );
value = v.c_str(); value = v.c_str();
} }
else
{
t = getValueTypeFromDfn( st, idx );
}
QtVariantProperty *p = mgr->addProperty( t, key ); QtVariantProperty *p = mgr->addProperty( t, key );
p->setValue( value ); p->setValue( value );
@ -102,18 +165,7 @@ void BrowserCtrlPvt::setupStruct( NLGEORGES::UFormElm *node )
for( int i = 0; i < st->Elements.size(); i++ ) for( int i = 0; i < st->Elements.size(); i++ )
{ {
NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ i ]; setupAtom( st, 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 );
} }
} }
@ -162,6 +214,10 @@ void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node )
{ {
tt = getValueType( t ); tt = getValueType( t );
} }
else
{
tt = getValueTypeFromDfn( atom );
}
QtVariantProperty *p = mgr->addProperty( tt, "value" ); QtVariantProperty *p = mgr->addProperty( tt, "value" );
p->setValue( v.c_str() ); p->setValue( v.c_str() );

View file

@ -61,7 +61,7 @@ Q_SIGNALS:
private: private:
void setupStruct( NLGEORGES::UFormElm *node ); void setupStruct( NLGEORGES::UFormElm *node );
void setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm ); void setupAtom( NLGEORGES::CFormElmStruct *st, int idx );
void setupStruct( GeorgesQt::CFormItem *node ); void setupStruct( GeorgesQt::CFormItem *node );
void setupArray( GeorgesQt::CFormItem *node ); void setupArray( GeorgesQt::CFormItem *node );