From e768506349558972956659690da1df94c2a2e4c6 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 31 Aug 2014 22:42:49 +0200 Subject: [PATCH] Load DFN. --HG-- branch : dfighter-tools --- .../georges_editor/dfn_browser_ctrl.cpp | 72 +++++++++++++++++++ .../plugins/georges_editor/dfn_browser_ctrl.h | 34 +++++++++ .../georges_editor/georges_dfn_dialog.cpp | 67 +++++++++++++++++ .../georges_editor/georges_dfn_dialog.h | 5 ++ .../georges_editor/georges_editor_form.cpp | 12 +++- 5 files changed, 187 insertions(+), 3 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp index 4183e6f6c..e1efa46e5 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp @@ -1,2 +1,74 @@ #include "dfn_browser_ctrl.h" +#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" +#include "3rdparty/qtpropertybrowser/qtvariantproperty.h" + +#include "nel/georges/form_dfn.h" + +DFNBrowserCtrl::DFNBrowserCtrl( QObject *parent ) : +QObject( parent ) +{ + m_browser = NULL; + m_dfn = NULL; + + m_manager = new QtVariantPropertyManager(); + m_factory = new QtVariantEditorFactory(); +} + +DFNBrowserCtrl::~DFNBrowserCtrl() +{ + m_browser = NULL; + m_dfn = NULL; + + delete m_manager; + m_manager = NULL; + delete m_factory; + m_factory = NULL; +} + +void DFNBrowserCtrl::onElementSelected( int idx ) +{ + NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( idx ); + + m_browser->clear(); + m_browser->setFactoryForManager( m_manager, m_factory ); + + QtVariantProperty *p = NULL; + + p = m_manager->addProperty( QVariant::String, "name" ); + p->setValue( entry.getName().c_str() ); + m_browser->addProperty( p ); + + + NLGEORGES::UFormDfn::TEntryType et = entry.getType(); + bool isArray = entry.getArrayFlag(); + QString type = ""; + + switch( et ) + { + case NLGEORGES::UFormDfn::EntryType: type = "type"; break; + case NLGEORGES::UFormDfn::EntryDfn: type = "DFN"; break; + case NLGEORGES::UFormDfn::EntryVirtualDfn: type = "Virtual DFN"; break; + } + + if( isArray ) + type += " array"; + + p = m_manager->addProperty( QVariant::String, "type" ); + p->setValue( type ); + m_browser->addProperty( p ); + + p = m_manager->addProperty( QVariant::String, "value" ); + p->setValue( entry.getFilename().c_str() ); + m_browser->addProperty( p ); + + p = m_manager->addProperty( QVariant::String, "default" ); + p->setValue( entry.getDefault().c_str() ); + m_browser->addProperty( p ); + + p = m_manager->addProperty( QVariant::String, "extension" ); + p->setValue( entry.getFilenameExt().c_str() ); + m_browser->addProperty( p ); +} + + diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h index fae44bd1e..0ac8ecd4f 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h @@ -1,4 +1,38 @@ #ifndef DFN_BROWSER_CTRL #define DFN_BROWSER_CTRL + +#include + +namespace NLGEORGES +{ + class CFormDfn; +} + +class QtVariantPropertyManager; +class QtVariantEditorFactory; +class QtTreePropertyBrowser; +class QVariant; +class QtProperty; + +class DFNBrowserCtrl : public QObject +{ + Q_OBJECT +public: + DFNBrowserCtrl( QObject *parent = NULL ); + ~DFNBrowserCtrl(); + + void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; } + void setDFN( NLGEORGES::CFormDfn *dfn ){ m_dfn = dfn; } + + void onElementSelected( int idx ); + +private: + QtTreePropertyBrowser *m_browser; + NLGEORGES::CFormDfn *m_dfn; + + QtVariantPropertyManager *m_manager; + QtVariantEditorFactory *m_factory; +}; + #endif diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp index c3b579737..a3021563d 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -2,6 +2,28 @@ #include #include +#include "georges.h" +#include "dfn_browser_ctrl.h" + +class GeorgesDFNDialogPvt +{ +public: + GeorgesDFNDialogPvt() + { + dfn = NULL; + ctrl = new DFNBrowserCtrl(); + } + + ~GeorgesDFNDialogPvt() + { + delete ctrl; + ctrl = NULL; + } + + NLGEORGES::CFormDfn *dfn; + DFNBrowserCtrl *ctrl; +}; + GeorgesDFNDialog::GeorgesDFNDialog( QWidget *parent ) : GeorgesDockWidget( parent ) { @@ -10,10 +32,46 @@ GeorgesDockWidget( parent ) m_ui.addButton->setEnabled( false ); m_ui.removeButton->setEnabled( false ); + + m_pvt = new GeorgesDFNDialogPvt(); + m_pvt->ctrl->setBrowser( m_ui.browser ); } GeorgesDFNDialog::~GeorgesDFNDialog() { + delete m_pvt; + m_pvt = NULL; +} + +bool GeorgesDFNDialog::load( const QString &fileName ) +{ + GeorgesQt::CGeorges georges; + NLGEORGES::UFormDfn *udfn = georges.loadFormDfn( fileName.toUtf8().constData() ); + if( udfn == NULL ) + return false; + + setWindowTitle( fileName ); + + NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn ); + m_pvt->dfn = cdfn; + m_pvt->ctrl->setDFN( cdfn ); + + uint c = m_pvt->dfn->getNumEntry(); + for( uint i = 0; i < c; i++ ) + { + NLGEORGES::CFormDfn::CEntry &entry = m_pvt->dfn->getEntry( i ); + m_ui.list->addItem( entry.getName().c_str() ); + } + + if( c > 0 ) + { + m_ui.list->setCurrentRow( 0 ); + } + + m_ui.commentsEdit->setPlainText( cdfn->getComment().c_str() ); + m_ui.logEdit->setPlainText( cdfn->Header.Log.c_str() ); + + return true; } void GeorgesDFNDialog::onAddClicked() @@ -44,9 +102,18 @@ void GeorgesDFNDialog::onRemoveClicked() delete item; } +void GeorgesDFNDialog::onCurrentRowChanged( int row ) +{ + if( row < 0 ) + return; + + m_pvt->ctrl->onElementSelected( row ); +} + void GeorgesDFNDialog::setupConnections() { connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); + connect( m_ui.list, SIGNAL( currentRowChanged( int ) ), this, SLOT( onCurrentRowChanged( int ) ) ); } diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h index bffe45368..f88433448 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -4,6 +4,8 @@ #include "georges_dock_widget.h" #include "ui_georges_dfn_dialog.h" +class GeorgesDFNDialogPvt; + class GeorgesDFNDialog : public GeorgesDockWidget { Q_OBJECT @@ -11,16 +13,19 @@ public: GeorgesDFNDialog( QWidget *parent = NULL ); ~GeorgesDFNDialog(); + bool load( const QString &fileName ); void write(){} private Q_SLOTS: void onAddClicked(); void onRemoveClicked(); + void onCurrentRowChanged( int row ); private: void setupConnections(); Ui::GeorgesDFNDialog m_ui; + GeorgesDFNDialogPvt *m_pvt; }; #endif diff --git a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp index 708e710d2..b12b73b2d 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -258,6 +258,8 @@ namespace GeorgesQt m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); } + w->raise(); + } void GeorgesEditorForm::closingTreeView() @@ -320,7 +322,12 @@ namespace GeorgesQt GeorgesDockWidget* GeorgesEditorForm::loadDfnDialog( const QString &fileName ) { GeorgesDFNDialog *d = new GeorgesDFNDialog(); - m_mainDock->addDockWidget( Qt::RightDockWidgetArea, d ); + bool b = d->load( fileName ); + if( !b ) + { + delete d; + d = NULL; + } return d; } @@ -329,7 +336,7 @@ namespace GeorgesQt { QFileInfo info( fileName ); - CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog(m_mainDock); + CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog(); // Retrieve the form and load the form. NLGEORGES::CForm *form; @@ -350,7 +357,6 @@ namespace GeorgesQt QApplication::processEvents(); connect(d, SIGNAL(modified()), this, SLOT(setModified())); - d->raise(); connect(d, SIGNAL(changeFile(QString)), m_georgesDirTreeDialog, SLOT(changeFile(QString))); }