Load DFN.

--HG--
branch : dfighter-tools
hg/feature/qt5
dfighter1985 10 years ago
parent 230159e2b6
commit e768506349

@ -1,2 +1,74 @@
#include "dfn_browser_ctrl.h" #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 );
}

@ -1,4 +1,38 @@
#ifndef DFN_BROWSER_CTRL #ifndef DFN_BROWSER_CTRL
#define DFN_BROWSER_CTRL #define DFN_BROWSER_CTRL
#include <QObject>
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 #endif

@ -2,6 +2,28 @@
#include <QInputDialog> #include <QInputDialog>
#include <QMessageBox> #include <QMessageBox>
#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 ) : GeorgesDFNDialog::GeorgesDFNDialog( QWidget *parent ) :
GeorgesDockWidget( parent ) GeorgesDockWidget( parent )
{ {
@ -10,10 +32,46 @@ GeorgesDockWidget( parent )
m_ui.addButton->setEnabled( false ); m_ui.addButton->setEnabled( false );
m_ui.removeButton->setEnabled( false ); m_ui.removeButton->setEnabled( false );
m_pvt = new GeorgesDFNDialogPvt();
m_pvt->ctrl->setBrowser( m_ui.browser );
} }
GeorgesDFNDialog::~GeorgesDFNDialog() 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() void GeorgesDFNDialog::onAddClicked()
@ -44,9 +102,18 @@ void GeorgesDFNDialog::onRemoveClicked()
delete item; delete item;
} }
void GeorgesDFNDialog::onCurrentRowChanged( int row )
{
if( row < 0 )
return;
m_pvt->ctrl->onElementSelected( row );
}
void GeorgesDFNDialog::setupConnections() void GeorgesDFNDialog::setupConnections()
{ {
connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) );
connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) );
connect( m_ui.list, SIGNAL( currentRowChanged( int ) ), this, SLOT( onCurrentRowChanged( int ) ) );
} }

@ -4,6 +4,8 @@
#include "georges_dock_widget.h" #include "georges_dock_widget.h"
#include "ui_georges_dfn_dialog.h" #include "ui_georges_dfn_dialog.h"
class GeorgesDFNDialogPvt;
class GeorgesDFNDialog : public GeorgesDockWidget class GeorgesDFNDialog : public GeorgesDockWidget
{ {
Q_OBJECT Q_OBJECT
@ -11,16 +13,19 @@ public:
GeorgesDFNDialog( QWidget *parent = NULL ); GeorgesDFNDialog( QWidget *parent = NULL );
~GeorgesDFNDialog(); ~GeorgesDFNDialog();
bool load( const QString &fileName );
void write(){} void write(){}
private Q_SLOTS: private Q_SLOTS:
void onAddClicked(); void onAddClicked();
void onRemoveClicked(); void onRemoveClicked();
void onCurrentRowChanged( int row );
private: private:
void setupConnections(); void setupConnections();
Ui::GeorgesDFNDialog m_ui; Ui::GeorgesDFNDialog m_ui;
GeorgesDFNDialogPvt *m_pvt;
}; };
#endif #endif

@ -258,6 +258,8 @@ namespace GeorgesQt
m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last());
} }
w->raise();
} }
void GeorgesEditorForm::closingTreeView() void GeorgesEditorForm::closingTreeView()
@ -320,7 +322,12 @@ namespace GeorgesQt
GeorgesDockWidget* GeorgesEditorForm::loadDfnDialog( const QString &fileName ) GeorgesDockWidget* GeorgesEditorForm::loadDfnDialog( const QString &fileName )
{ {
GeorgesDFNDialog *d = new GeorgesDFNDialog(); GeorgesDFNDialog *d = new GeorgesDFNDialog();
m_mainDock->addDockWidget( Qt::RightDockWidgetArea, d ); bool b = d->load( fileName );
if( !b )
{
delete d;
d = NULL;
}
return d; return d;
} }
@ -329,7 +336,7 @@ namespace GeorgesQt
{ {
QFileInfo info( fileName ); QFileInfo info( fileName );
CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog(m_mainDock); CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog();
// Retrieve the form and load the form. // Retrieve the form and load the form.
NLGEORGES::CForm *form; NLGEORGES::CForm *form;
@ -350,7 +357,6 @@ namespace GeorgesQt
QApplication::processEvents(); QApplication::processEvents();
connect(d, SIGNAL(modified()), connect(d, SIGNAL(modified()),
this, SLOT(setModified())); this, SLOT(setModified()));
d->raise();
connect(d, SIGNAL(changeFile(QString)), connect(d, SIGNAL(changeFile(QString)),
m_georgesDirTreeDialog, SLOT(changeFile(QString))); m_georgesDirTreeDialog, SLOT(changeFile(QString)));
} }

Loading…
Cancel
Save