Moved BrowserCtrlPvt to it's own files.

--HG--
branch : gsoc2014-dfighter
This commit is contained in:
dfighter1985 2014-08-18 01:50:07 +02:00
parent fb5ce7baac
commit 6000fe187f
4 changed files with 210 additions and 164 deletions

View file

@ -16,7 +16,9 @@ SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h
georges_filesystem_model.h georges_filesystem_model.h
georges_treeview_dialog.h georges_treeview_dialog.h
expandable_headerview.h expandable_headerview.h
browser_ctrl.h) browser_ctrl.h
browser_ctrl_pvt.h
)
SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui
georges_dirtree_form.ui georges_dirtree_form.ui

View file

@ -7,169 +7,7 @@
#include "formitem.h" #include "formitem.h"
QVariant::Type getValueType( const NLGEORGES::UType *typ ) #include "browser_ctrl_pvt.h"
{
QVariant::Type t = QVariant::String;
NLGEORGES::UType::TType ttyp = NLGEORGES::UType::String;
if( typ != NULL )
ttyp = typ->getType();
switch( ttyp )
{
case NLGEORGES::UType::UnsignedInt: t = QVariant::UInt; break;
case NLGEORGES::UType::SignedInt: t = QVariant::Int; break;
case NLGEORGES::UType::Double: t = QVariant::Double; break;
case NLGEORGES::UType::Color: t = QVariant::Color; break;
case NLGEORGES::UType::String: t = QVariant::String; break;
}
return t;
}
class BrowserCtrlPvt
{
public:
BrowserCtrlPvt()
{
mgr = new QtVariantPropertyManager();
factory = new QtVariantEditorFactory();
m_currentNode = NULL;
m_rootNode = NULL;
}
~BrowserCtrlPvt()
{
delete mgr;
mgr = NULL;
delete factory;
factory = NULL;
m_browser = NULL;
}
void setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm )
{
QString key = elm.Name.c_str();
QString value = "";
QVariant::Type t = QVariant::String;
if( elm.Element != NULL )
{
t = getValueType( elm.Element->getType() );
std::string formName;
elm.Element->getFormName( formName, NULL );
std::string v;
m_rootNode->getValueByName( v, formName.c_str(), NLGEORGES::UFormElm::NoEval, NULL, 0 );
value = v.c_str();
}
QtVariantProperty *p = mgr->addProperty( t, key );
p->setValue( value );
m_browser->addProperty( p );
}
void setupArray( NLGEORGES::UFormElm *node )
{
NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( node );
uint size = 0;
arr->getArraySize( size );
QString key = QObject::tr( "Array size" );
QtVariantProperty *p = mgr->addProperty( QVariant::Int, key );
p->setValue( size );
m_browser->addProperty( p );
}
void setupStruct( NLGEORGES::UFormElm *node )
{
NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( 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 );
}
}
void setupNode( NLGEORGES::UFormElm *node )
{
if( node->isStruct() )
setupStruct( node );
else
if( node->isArray() )
setupArray( node );
else
return;
m_currentNode = node;
m_browser->setFactoryForManager( mgr, factory );
}
void clear()
{
m_browser->clear();
m_currentNode = NULL;
}
void setBrowser( QtTreePropertyBrowser *browser )
{
m_browser = browser;
}
void onStructValueChanged( QtProperty *p, const QVariant &value )
{
std::string k = p->propertyName().toUtf8().constData();
std::string v = value.toString().toUtf8().constData();
bool created = false;
m_currentNode->setValueByName( v.c_str(), k.c_str(), &created );
}
void onArrayValueChanged( QtProperty *p, const QVariant &value )
{
NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( m_currentNode );
std::string formName;
arr->getFormName( formName, NULL );
}
void onValueChanged( QtProperty *p, const QVariant &value )
{
if( m_currentNode == NULL )
return;
if( m_currentNode->isStruct() )
onStructValueChanged( p, value );
else
if( m_currentNode->isArray() )
onArrayValueChanged( p, value );
}
QtVariantPropertyManager* manager() const{ return mgr; }
void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; }
private:
QtVariantPropertyManager *mgr;
QtVariantEditorFactory *factory;
QtTreePropertyBrowser *m_browser;
NLGEORGES::UFormElm *m_currentNode;
NLGEORGES::CFormElm *m_rootNode;
};
BrowserCtrl::BrowserCtrl( QtTreePropertyBrowser *browser ) : BrowserCtrl::BrowserCtrl( QtTreePropertyBrowser *browser ) :
QObject( browser ) QObject( browser )

View file

@ -0,0 +1,156 @@
#include "browser_ctrl_pvt.h"
#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h"
#include "3rdparty/qtpropertybrowser/qtvariantproperty.h"
#include <QVariant>
namespace
{
QVariant::Type getValueType( const NLGEORGES::UType *typ )
{
QVariant::Type t = QVariant::String;
NLGEORGES::UType::TType ttyp = NLGEORGES::UType::String;
if( typ != NULL )
ttyp = typ->getType();
switch( ttyp )
{
case NLGEORGES::UType::UnsignedInt: t = QVariant::UInt; break;
case NLGEORGES::UType::SignedInt: t = QVariant::Int; break;
case NLGEORGES::UType::Double: t = QVariant::Double; break;
case NLGEORGES::UType::Color: t = QVariant::Color; break;
case NLGEORGES::UType::String: t = QVariant::String; break;
}
return t;
}
}
BrowserCtrlPvt::BrowserCtrlPvt( QObject *parent ) :
QObject( parent )
{
mgr = new QtVariantPropertyManager();
factory = new QtVariantEditorFactory();
m_currentNode = NULL;
m_rootNode = NULL;
}
BrowserCtrlPvt::~BrowserCtrlPvt()
{
delete mgr;
mgr = NULL;
delete factory;
factory = NULL;
m_browser = NULL;
}
void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm )
{
QString key = elm.Name.c_str();
QString value = "";
QVariant::Type t = QVariant::String;
if( elm.Element != NULL )
{
t = getValueType( elm.Element->getType() );
std::string formName;
elm.Element->getFormName( formName, NULL );
std::string v;
m_rootNode->getValueByName( v, formName.c_str(), NLGEORGES::UFormElm::NoEval, NULL, 0 );
value = v.c_str();
}
QtVariantProperty *p = mgr->addProperty( t, key );
p->setValue( value );
m_browser->addProperty( p );
}
void BrowserCtrlPvt::setupArray( NLGEORGES::UFormElm *node )
{
NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( node );
uint size = 0;
arr->getArraySize( size );
QString key = QObject::tr( "Array size" );
QtVariantProperty *p = mgr->addProperty( QVariant::Int, key );
p->setValue( size );
m_browser->addProperty( p );
}
void BrowserCtrlPvt::setupStruct( NLGEORGES::UFormElm *node )
{
NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( 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 );
}
}
void BrowserCtrlPvt::setupNode( NLGEORGES::UFormElm *node )
{
if( node->isStruct() )
setupStruct( node );
else
if( node->isArray() )
setupArray( node );
else
return;
m_currentNode = node;
m_browser->setFactoryForManager( mgr, factory );
}
void BrowserCtrlPvt::clear()
{
m_browser->clear();
m_currentNode = NULL;
}
void BrowserCtrlPvt::onStructValueChanged( QtProperty *p, const QVariant &value )
{
std::string k = p->propertyName().toUtf8().constData();
std::string v = value.toString().toUtf8().constData();
bool created = false;
m_currentNode->setValueByName( v.c_str(), k.c_str(), &created );
}
void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value )
{
NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( m_currentNode );
std::string formName;
arr->getFormName( formName, NULL );
}
void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value )
{
if( m_currentNode == NULL )
return;
if( m_currentNode->isStruct() )
onStructValueChanged( p, value );
else
if( m_currentNode->isArray() )
onArrayValueChanged( p, value );
}

View file

@ -0,0 +1,50 @@
#ifndef BROWSER_CTRL_PVT_H
#define BROWSER_CTRL_PVT_H
#include <QObject>
namespace NLGEORGES
{
class CFormElm;
class UFormElm;
class CFormElmStruct;
}
class QtVariantPropertyManager;
class QtVariantEditorFactory;
class QtTreePropertyBrowser;
class QVariant;
class QtProperty;
class BrowserCtrlPvt : public QObject
{
Q_OBJECT
public:
BrowserCtrlPvt( QObject *parent = NULL );
~BrowserCtrlPvt();
void clear();
void setupNode( NLGEORGES::UFormElm *node );
void onValueChanged( QtProperty *p, const QVariant &value );
QtVariantPropertyManager* manager() const{ return mgr; }
void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; }
void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; }
private:
void setupStruct( NLGEORGES::UFormElm *node );
void setupArray( NLGEORGES::UFormElm *node );
void setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm );
void onStructValueChanged( QtProperty *p, const QVariant &value );
void onArrayValueChanged( QtProperty *p, const QVariant &value );
QtVariantPropertyManager *mgr;
QtVariantEditorFactory *factory;
QtTreePropertyBrowser *m_browser;
NLGEORGES::UFormElm *m_currentNode;
NLGEORGES::CFormElm *m_rootNode;
};
#endif