First iteration of the property browser.

This commit is contained in:
dfighter1985 2014-08-12 19:26:55 +02:00
parent 340684e1d6
commit 63fd3faad6
6 changed files with 137 additions and 2 deletions

View file

@ -15,7 +15,8 @@ SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h
georges_dirtree_dialog.h
georges_filesystem_model.h
georges_treeview_dialog.h
expandable_headerview.h)
expandable_headerview.h
browser_ctrl.h)
SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui
georges_dirtree_form.ui

View file

@ -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 );
}
}

View file

@ -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

View file

@ -43,6 +43,7 @@
#include "formitem.h"
#include "formdelegate.h"
#include "expandable_headerview.h"
#include "browser_ctrl.h"
using namespace NLMISC;
using namespace NLGEORGES;
@ -76,16 +77,22 @@ namespace GeorgesQt
m_ui.treeView->setContextMenuPolicy(Qt::CustomContextMenu);
m_browserCtrl = new BrowserCtrl( m_ui.propertiesBrowser );
connect(m_ui.treeView, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(showContextMenu(const QPoint&)));
connect(m_ui.treeView, SIGNAL(doubleClicked (QModelIndex)),
this, SLOT(doubleClicked (QModelIndex)));
connect(m_ui.treeView, SIGNAL(clicked(const QModelIndex&)),
m_browserCtrl, SLOT(clicked(const QModelIndex&)));
connect(m_header, SIGNAL(headerClicked(int)),
this, SLOT(headerClicked(int)));
}
CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog()
{
m_browserCtrl = NULL;
delete m_form;
qDebug() << "DTOR";
}
@ -104,6 +111,7 @@ namespace GeorgesQt
void CGeorgesTreeViewDialog::setForm(const CForm *form)
{
m_form = (UForm*)form;
m_browserCtrl->setForm( (UForm*)form );
}
NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByName(const QString formName)

View file

@ -32,6 +32,8 @@
// Project includes
class BrowserCtrl;
namespace NLGEORGES
{
class UForm;
@ -113,6 +115,8 @@ namespace GeorgesQt
bool m_modified;
BrowserCtrl *m_browserCtrl;
}; /* CGeorgesTreeViewDialog */
} /* namespace GeorgesQt */

View file

@ -307,7 +307,7 @@ namespace GeorgesQt
// Is a struct ?
if ( (entry.getType () == NLGEORGES::UFormDfn::EntryDfn) || (entry.getType () == NLGEORGES::UFormDfn::EntryVirtualDfn) )
{
{
// Is an array of struct ?
if (entry.getArrayFlag ())
{