Instead of storing the node, store the name and the node type.

--HG--
branch : dfighter-tools
This commit is contained in:
dfighter1985 2014-09-10 00:28:03 +02:00
parent 53357ca9ec
commit e47d480170
3 changed files with 37 additions and 33 deletions

View file

@ -101,6 +101,7 @@ namespace
item->form()->getRootNode().getNodeByName( &n, item->formName().c_str() ); item->form()->getRootNode().getNodeByName( &n, item->formName().c_str() );
return n; return n;
} }
} }
@ -121,6 +122,19 @@ BrowserCtrlPvt::~BrowserCtrlPvt()
m_browser = NULL; m_browser = NULL;
} }
NLGEORGES::UFormElm* BrowserCtrlPvt::getNode( const QString &name )
{
NLGEORGES::UFormElm *node = NULL;
m_rootNode->getNodeByName( &node, name.toUtf8().constData(), NULL, true );
return node;
}
NLGEORGES::UFormElm* BrowserCtrlPvt::getCurrentNode()
{
return getNode( m_currentNode.name );
}
void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct *st, int idx ) void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct *st, int idx )
{ {
NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ idx ]; NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ idx ];
@ -178,8 +192,6 @@ void BrowserCtrlPvt::setupStruct( GeorgesQt::CFormItem *node )
if( n == NULL ) if( n == NULL )
return; return;
m_currentNode.p = n;
setupStruct( n ); setupStruct( n );
} }
@ -189,8 +201,6 @@ void BrowserCtrlPvt::setupVStruct( GeorgesQt::CFormItem *node )
if( n == NULL ) if( n == NULL )
return; return;
m_currentNode.p = n;
NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( n ); NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( n );
QtVariantProperty *p = mgr->addProperty( QVariant::String, "Dfn filename" ); QtVariantProperty *p = mgr->addProperty( QVariant::String, "Dfn filename" );
@ -209,7 +219,6 @@ void BrowserCtrlPvt::setupArray( GeorgesQt::CFormItem *node )
{ {
NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( n ); NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( n );
arr->getArraySize( size ); arr->getArraySize( size );
m_currentNode.p = n;
} }
QString key = QObject::tr( "Array size" ); QString key = QObject::tr( "Array size" );
@ -242,14 +251,13 @@ void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node )
QtVariantProperty *p = mgr->addProperty( tt, "value" ); QtVariantProperty *p = mgr->addProperty( tt, "value" );
p->setValue( v.c_str() ); p->setValue( v.c_str() );
m_browser->addProperty( p ); m_browser->addProperty( p );
m_currentNode.p = n;
} }
void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node )
{ {
m_currentNode.clear(); m_currentNode.clear();
m_currentNode.name = node->formName().c_str(); m_currentNode.name = node->formName().c_str();
m_currentNode.type = node->type();
m_rootNode = dynamic_cast< NLGEORGES::CFormElm* >( &(node->form()->getRootNode()) ); m_rootNode = dynamic_cast< NLGEORGES::CFormElm* >( &(node->form()->getRootNode()) );
@ -280,8 +288,10 @@ void BrowserCtrlPvt::onStructValueChanged( QtProperty *p, const QVariant &value
std::string k = p->propertyName().toUtf8().constData(); std::string k = p->propertyName().toUtf8().constData();
std::string v = value.toString().toUtf8().constData(); std::string v = value.toString().toUtf8().constData();
NLGEORGES::UFormElm *node = getCurrentNode();
bool created = false; bool created = false;
m_currentNode.p->setValueByName( v.c_str(), k.c_str(), &created ); node->setValueByName( v.c_str(), k.c_str(), &created );
QString key = m_currentNode.name + "." + p->propertyName(); QString key = m_currentNode.name + "." + p->propertyName();
@ -297,7 +307,7 @@ void BrowserCtrlPvt::onVStructValueChanged( QtProperty *p, const QVariant &value
return; return;
} }
NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( m_currentNode.p ); NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( getCurrentNode() );
vs->DfnFilename = value.toString().toUtf8().constData(); vs->DfnFilename = value.toString().toUtf8().constData();
QString key = m_currentNode.name + "." + p->propertyName(); QString key = m_currentNode.name + "." + p->propertyName();
@ -323,8 +333,6 @@ void BrowserCtrlPvt::createArray()
if( !created ) if( !created )
return; return;
m_currentNode.p = node;
NLGEORGES::CFormElmArray *arr = dynamic_cast< NLGEORGES::CFormElmArray* >( node ); NLGEORGES::CFormElmArray *arr = dynamic_cast< NLGEORGES::CFormElmArray* >( node );
QString idx = "[0]"; QString idx = "[0]";
arr->createNodeByName( idx.toUtf8().constData(), &parentDfn, indexDfn, &nodeDfn, &type, &node, entryType, isArray, created ); arr->createNodeByName( idx.toUtf8().constData(), &parentDfn, indexDfn, &nodeDfn, &type, &node, entryType, isArray, created );
@ -344,7 +352,10 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value )
if( newSize < 0 ) if( newSize < 0 )
return; return;
if( m_currentNode.p == NULL )
NLGEORGES::UFormElm *node = getCurrentNode();
if( node == NULL )
{ {
if( newSize != 1 ) if( newSize != 1 )
return; return;
@ -352,7 +363,7 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value )
return; return;
} }
NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( m_currentNode.p ); NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( node );
std::string formName; std::string formName;
arr->getFormName( formName, NULL ); arr->getFormName( formName, NULL );
@ -401,14 +412,11 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value )
QString name = formName.c_str(); QString name = formName.c_str();
Q_EMIT arrayResized( name, newSize ); Q_EMIT arrayResized( name, newSize );
Q_EMIT modified(); Q_EMIT modified();
if( newSize == 0 )
m_currentNode.p = NULL;
} }
void BrowserCtrlPvt::onAtomValueChanged( QtProperty *p, const QVariant &value ) void BrowserCtrlPvt::onAtomValueChanged( QtProperty *p, const QVariant &value )
{ {
NLGEORGES::CFormElmAtom *atom = static_cast< NLGEORGES::CFormElmAtom* >( m_currentNode.p ); NLGEORGES::CFormElmAtom *atom = static_cast< NLGEORGES::CFormElmAtom* >( getCurrentNode() );
atom->setValue( value.toString().toUtf8() ); atom->setValue( value.toString().toUtf8() );
Q_EMIT modified(); Q_EMIT modified();
@ -417,25 +425,16 @@ void BrowserCtrlPvt::onAtomValueChanged( QtProperty *p, const QVariant &value )
void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value ) void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value )
{ {
if( m_currentNode.p == NULL ) if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_VSTRUCT )
{
if( m_currentNode.name.isEmpty() )
return;
onArrayValueChanged( p, value );
return;
}
if( m_currentNode.p->isVirtualStruct() )
onVStructValueChanged( p, value ); onVStructValueChanged( p, value );
else else
if( m_currentNode.p->isStruct() ) if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_STRUCT )
onStructValueChanged( p, value ); onStructValueChanged( p, value );
else else
if( m_currentNode.p->isArray() ) if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_ARRAY )
onArrayValueChanged( p, value ); onArrayValueChanged( p, value );
else else
if( m_currentNode.p->isAtom() ) if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_ATOM )
onAtomValueChanged( p, value ); onAtomValueChanged( p, value );
} }

View file

@ -61,6 +61,9 @@ Q_SIGNALS:
void vstructChanged( const QString &name ); void vstructChanged( const QString &name );
private: private:
NLGEORGES::UFormElm* getNode( const QString &name );
NLGEORGES::UFormElm* getCurrentNode();
void setupStruct( NLGEORGES::UFormElm *node ); void setupStruct( NLGEORGES::UFormElm *node );
void setupAtom( NLGEORGES::CFormElmStruct *st, int idx ); void setupAtom( NLGEORGES::CFormElmStruct *st, int idx );
@ -91,12 +94,12 @@ private:
void clear() void clear()
{ {
p = NULL; type = -1;
name = ""; name = "";
} }
QString name; QString name;
NLGEORGES::UFormElm *p; int type;
}; };
CurrentNode m_currentNode; CurrentNode m_currentNode;

View file

@ -81,6 +81,8 @@ namespace GeorgesQt
bool isVStruct(); bool isVStruct();
bool isAtom(); bool isAtom();
TType type() const{ return _TType; }
QIcon getItemImage(CFormItem *rootItem); QIcon getItemImage(CFormItem *rootItem);
CFormItem* findItem( const QString &formName ); CFormItem* findItem( const QString &formName );