First iteration of the property browser.
--HG-- branch : gsoc2014-dfighterhg/feature/cdb-packed
parent
9315b7229e
commit
a43c2f0a5e
@ -0,0 +1,89 @@
|
|||||||
|
#include "browser_ctrl.h"
|
||||||
|
#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h"
|
||||||
|
#include "3rdparty/qtpropertybrowser/qtvariantproperty.h"
|
||||||
|
#include <QModelIndex>
|
||||||
|
|
||||||
|
#include "nel/georges/form.h"
|
||||||
|
|
||||||
|
#include "formitem.h"
|
||||||
|
|
||||||
|
class BrowserCtrlPvt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BrowserCtrlPvt()
|
||||||
|
{
|
||||||
|
mgr = new QtVariantPropertyManager();
|
||||||
|
factory = new QtVariantEditorFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
~BrowserCtrlPvt()
|
||||||
|
{
|
||||||
|
delete mgr;
|
||||||
|
mgr = NULL;
|
||||||
|
delete factory;
|
||||||
|
factory = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QtVariantPropertyManager *mgr;
|
||||||
|
QtVariantEditorFactory *factory;
|
||||||
|
QtTreePropertyBrowser *m_browser;
|
||||||
|
};
|
||||||
|
|
||||||
|
BrowserCtrl::BrowserCtrl( QtTreePropertyBrowser *browser ) :
|
||||||
|
QObject( browser )
|
||||||
|
{
|
||||||
|
m_pvt = new BrowserCtrlPvt();
|
||||||
|
m_pvt->m_browser = browser;
|
||||||
|
}
|
||||||
|
|
||||||
|
BrowserCtrl::~BrowserCtrl()
|
||||||
|
{
|
||||||
|
delete m_pvt;
|
||||||
|
m_pvt = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BrowserCtrl::clicked( const QModelIndex &idx )
|
||||||
|
{
|
||||||
|
m_pvt->m_browser->clear();
|
||||||
|
|
||||||
|
GeorgesQt::CFormItem *item = static_cast< GeorgesQt::CFormItem* >( idx.internalPointer() );
|
||||||
|
NLGEORGES::UFormElm &root = m_form->getRootNode();
|
||||||
|
NLGEORGES::UFormElm *node = NULL;
|
||||||
|
bool b = false;
|
||||||
|
|
||||||
|
b = m_form->getRootNode().getNodeByName( &node, item->formName().c_str() );
|
||||||
|
|
||||||
|
if( !b || ( node == NULL ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( !node->isStruct() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( node );
|
||||||
|
for( int i = 0; i < st->Elements.size(); i++ )
|
||||||
|
{
|
||||||
|
NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ i ];
|
||||||
|
|
||||||
|
QString key = elm.Name.c_str();
|
||||||
|
QString value = "";
|
||||||
|
|
||||||
|
if( elm.Element != NULL )
|
||||||
|
{
|
||||||
|
const NLGEORGES::UType *typ = elm.Element->getType();
|
||||||
|
NLGEORGES::UType::TType ttyp = NLGEORGES::UType::String;
|
||||||
|
if( typ != NULL )
|
||||||
|
ttyp = typ->getType();
|
||||||
|
|
||||||
|
NLGEORGES::CFormElmAtom *atom = static_cast< NLGEORGES::CFormElmAtom* >( elm.Element );
|
||||||
|
std::string v;
|
||||||
|
atom->getValue( v, NLGEORGES::UFormElm::NoEval );
|
||||||
|
value = v.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
QtVariantProperty *p = m_pvt->mgr->addProperty( QVariant::String, key );
|
||||||
|
p->setValue( value );
|
||||||
|
m_pvt->m_browser->addProperty( p );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef BROWSER_CTRL_H
|
||||||
|
#define BROWSER_CTRL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace NLGEORGES
|
||||||
|
{
|
||||||
|
class UForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
class QtTreePropertyBrowser;
|
||||||
|
class QModelIndex;
|
||||||
|
|
||||||
|
class BrowserCtrlPvt;
|
||||||
|
|
||||||
|
class BrowserCtrl : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
BrowserCtrl( QtTreePropertyBrowser *browser );
|
||||||
|
~BrowserCtrl();
|
||||||
|
void setForm( NLGEORGES::UForm *form ){ m_form = form; }
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void clicked( const QModelIndex &idx );
|
||||||
|
|
||||||
|
private:
|
||||||
|
BrowserCtrlPvt *m_pvt;
|
||||||
|
|
||||||
|
NLGEORGES::UForm *m_form;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue