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

This commit is contained in:
dfighter1985 2014-09-10 00:28:03 +02:00
parent f9e539dbef
commit 8decd3cb57
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() );
return n;
}
}
@ -121,6 +122,19 @@ BrowserCtrlPvt::~BrowserCtrlPvt()
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 )
{
NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ idx ];
@ -178,8 +192,6 @@ void BrowserCtrlPvt::setupStruct( GeorgesQt::CFormItem *node )
if( n == NULL )
return;
m_currentNode.p = n;
setupStruct( n );
}
@ -189,8 +201,6 @@ void BrowserCtrlPvt::setupVStruct( GeorgesQt::CFormItem *node )
if( n == NULL )
return;
m_currentNode.p = n;
NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( n );
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 );
arr->getArraySize( size );
m_currentNode.p = n;
}
QString key = QObject::tr( "Array size" );
@ -242,15 +251,14 @@ void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node )
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();
m_currentNode.name = node->formName().c_str();
m_currentNode.type = node->type();
m_rootNode = dynamic_cast< NLGEORGES::CFormElm* >( &(node->form()->getRootNode()) );
if( node->isArray() )
@ -280,8 +288,10 @@ void BrowserCtrlPvt::onStructValueChanged( QtProperty *p, const QVariant &value
std::string k = p->propertyName().toUtf8().constData();
std::string v = value.toString().toUtf8().constData();
NLGEORGES::UFormElm *node = getCurrentNode();
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();
@ -297,7 +307,7 @@ void BrowserCtrlPvt::onVStructValueChanged( QtProperty *p, const QVariant &value
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();
QString key = m_currentNode.name + "." + p->propertyName();
@ -323,8 +333,6 @@ void BrowserCtrlPvt::createArray()
if( !created )
return;
m_currentNode.p = node;
NLGEORGES::CFormElmArray *arr = dynamic_cast< NLGEORGES::CFormElmArray* >( node );
QString idx = "[0]";
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 )
return;
if( m_currentNode.p == NULL )
NLGEORGES::UFormElm *node = getCurrentNode();
if( node == NULL )
{
if( newSize != 1 )
return;
@ -352,7 +363,7 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value )
return;
}
NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( m_currentNode.p );
NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( node );
std::string formName;
arr->getFormName( formName, NULL );
@ -401,14 +412,11 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value )
QString name = formName.c_str();
Q_EMIT arrayResized( name, newSize );
Q_EMIT modified();
if( newSize == 0 )
m_currentNode.p = NULL;
}
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() );
Q_EMIT modified();
@ -417,25 +425,16 @@ void BrowserCtrlPvt::onAtomValueChanged( QtProperty *p, const QVariant &value )
void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value )
{
if( m_currentNode.p == NULL )
{
if( m_currentNode.name.isEmpty() )
return;
onArrayValueChanged( p, value );
return;
}
if( m_currentNode.p->isVirtualStruct() )
if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_VSTRUCT )
onVStructValueChanged( p, value );
else
if( m_currentNode.p->isStruct() )
if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_STRUCT )
onStructValueChanged( p, value );
else
if( m_currentNode.p->isArray() )
if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_ARRAY )
onArrayValueChanged( p, value );
else
if( m_currentNode.p->isAtom() )
if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_ATOM )
onAtomValueChanged( p, value );
}

View file

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

View file

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