mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-27 17:26:16 +00:00
Moved BrowserCtrlPvt to it's own files.
This commit is contained in:
parent
ae0d05f5a4
commit
90e3d24c00
4 changed files with 210 additions and 164 deletions
|
@ -16,7 +16,9 @@ SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h
|
|||
georges_filesystem_model.h
|
||||
georges_treeview_dialog.h
|
||||
expandable_headerview.h
|
||||
browser_ctrl.h)
|
||||
browser_ctrl.h
|
||||
browser_ctrl_pvt.h
|
||||
)
|
||||
|
||||
SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui
|
||||
georges_dirtree_form.ui
|
||||
|
|
|
@ -7,169 +7,7 @@
|
|||
|
||||
#include "formitem.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
#include "browser_ctrl_pvt.h"
|
||||
|
||||
BrowserCtrl::BrowserCtrl( QtTreePropertyBrowser *browser ) :
|
||||
QObject( browser )
|
||||
|
|
156
code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp
Normal file
156
code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp
Normal 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 );
|
||||
}
|
||||
|
||||
|
50
code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h
Normal file
50
code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h
Normal 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
|
Loading…
Reference in a new issue