A little refactoring, dialogs are now loaded using the full filepath.

--HG--
branch : dfighter-tools
This commit is contained in:
dfighter1985 2014-09-03 19:11:38 +02:00
parent 7206f060a7
commit 84853839f8
7 changed files with 60 additions and 61 deletions

View file

@ -72,7 +72,8 @@ bool GeorgesDFNDialog::load( const QString &fileName )
if( udfn == NULL ) if( udfn == NULL )
return false; return false;
setWindowTitle( fileName ); QFileInfo info( fileName );
setWindowTitle( info.fileName() );
NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn ); NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn );
m_pvt->dfn = cdfn; m_pvt->dfn = cdfn;
@ -105,18 +106,14 @@ void GeorgesDFNDialog::write()
m_pvt->dfn->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData(); m_pvt->dfn->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData();
std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false );
if( path.empty() )
return;
NLMISC::COFile file; NLMISC::COFile file;
if( !file.open( path, false, true, false ) ) if( !file.open( m_fileName.toUtf8().constData(), false, true, false ) )
return; return;
NLMISC::COXml xml; NLMISC::COXml xml;
xml.init( &file ); xml.init( &file );
m_pvt->dfn->write( xml.getDocument(), path.c_str() ); m_pvt->dfn->write( xml.getDocument(), m_fileName.toUtf8().constData() );
xml.flush(); xml.flush();
file.close(); file.close();

View file

@ -36,6 +36,7 @@ public:
QString fileName() const{ return m_fileName; } QString fileName() const{ return m_fileName; }
virtual bool load( const QString &fileName ) = 0;
virtual void write() = 0; virtual void write() = 0;
protected: protected:

View file

@ -29,6 +29,7 @@
// NeL includes // NeL includes
#include <nel/misc/debug.h> #include <nel/misc/debug.h>
#include <nel/misc/path.h>
// Qt includes // Qt includes
#include <QSettings> #include <QSettings>
@ -205,20 +206,19 @@ namespace GeorgesQt
} }
void GeorgesEditorForm::loadFile(const QString &fileName) void GeorgesEditorForm::loadFile(const QString &fileName)
{
loadFile(fileName, false);
}
void GeorgesEditorForm::loadFile(const QString &fileName, bool loadFromDfn)
{ {
QFileInfo info(fileName); std::string path = NLMISC::CPath::lookup( fileName.toUtf8().constData(), false );
if( path.empty() )
return;
QFileInfo info( path.c_str() );
// Check to see if the form is already loaded, if it is just raise it. // Check to see if the form is already loaded, if it is just raise it.
if (m_dockedWidgets.size()) if (m_dockedWidgets.size())
{ {
Q_FOREACH(GeorgesDockWidget *wgt, m_dockedWidgets) Q_FOREACH(GeorgesDockWidget *wgt, m_dockedWidgets)
{ {
if (info.fileName() == wgt->fileName()) if ( QString( path.c_str() ) == wgt->fileName())
{ {
wgt->raise(); wgt->raise();
return; return;
@ -230,16 +230,16 @@ namespace GeorgesQt
if( info.suffix() == "dfn" ) if( info.suffix() == "dfn" )
{ {
w = loadDfnDialog( fileName ); w = loadDfnDialog( path.c_str() );
} }
else else
if( info.suffix() == "typ" ) if( info.suffix() == "typ" )
{ {
w = loadTypDialog( fileName ); w = loadTypDialog( path.c_str() );
} }
else else
{ {
w = loadFormDialog( fileName, loadFromDfn ); w = loadFormDialog( path.c_str() );
} }
if( w == NULL ) if( w == NULL )
@ -352,40 +352,18 @@ namespace GeorgesQt
return d; return d;
} }
GeorgesDockWidget* GeorgesEditorForm::loadFormDialog( const QString &fileName, bool loadFromDFN ) GeorgesDockWidget* GeorgesEditorForm::loadFormDialog( const QString &fileName )
{ {
QFileInfo info( fileName );
CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog(); CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog();
if( !d->load( fileName ) )
// Retrieve the form and load the form.
NLGEORGES::CForm *form;
if(loadFromDFN)
{
// Get the form by DFN name.
form = d->getFormByDfnName(info.fileName());
}
else
{
form = d->getFormByName(info.fileName());
}
if (form)
{
d->setForm(form);
d->loadFormIntoDialog(form);
QApplication::processEvents();
connect(d, SIGNAL(modified()),
this, SLOT(setModified()));
connect(d, SIGNAL(changeFile(QString)),
m_georgesDirTreeDialog, SLOT(changeFile(QString)));
}
else
{ {
delete d; delete d;
d = NULL; return NULL;
} }
connect(d, SIGNAL(modified()), this, SLOT(setModified()));
connect(d, SIGNAL(changeFile(QString)), m_georgesDirTreeDialog, SLOT(changeFile(QString)));
return d; return d;
} }

View file

@ -45,7 +45,6 @@ public:
public Q_SLOTS: public Q_SLOTS:
void open(); void open();
void loadFile(const QString &fileName); void loadFile(const QString &fileName);
void loadFile(const QString &fileName, bool loadFromDfn);
void newTyp(); void newTyp();
void newDfn(); void newDfn();
@ -64,7 +63,7 @@ private:
GeorgesDockWidget* loadTypDialog(const QString &fileName); GeorgesDockWidget* loadTypDialog(const QString &fileName);
GeorgesDockWidget* loadDfnDialog(const QString &fileName); GeorgesDockWidget* loadDfnDialog(const QString &fileName);
GeorgesDockWidget* loadFormDialog(const QString &fileName, bool loadFromDFN ); GeorgesDockWidget* loadFormDialog(const QString &fileName);
Ui::GeorgesEditorForm m_ui; Ui::GeorgesEditorForm m_ui;

View file

@ -120,11 +120,7 @@ namespace GeorgesQt
NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByName(const QString formName) NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByName(const QString formName)
{ {
if(NLMISC::CPath::exists(formName.toAscii().data())) return (NLGEORGES::CForm *)m_georges->loadForm(formName.toAscii().data());
{
//NLGEORGES::CForm *form = dynamic_cast<NLGEORGES::CForm*>(m_georges->loadForm(formName.toAscii().data()));
return (NLGEORGES::CForm *)m_georges->loadForm(formName.toAscii().data());
}
//else //else
//{ //{
// CForm *form = 0; // CForm *form = 0;
@ -159,7 +155,6 @@ namespace GeorgesQt
// } // }
// return form; // return form;
//} //}
nlinfo("File '%s' does not exist!", formName.toAscii().data());
return 0; return 0;
} }
@ -271,9 +266,6 @@ namespace GeorgesQt
connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)), connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),
this, SLOT(modifiedFile())); this, SLOT(modifiedFile()));
setWindowTitle(loadedForm);
// //Modules::mainWin().getTabBar();
m_model = model; m_model = model;
} }
} }
@ -317,13 +309,44 @@ namespace GeorgesQt
Q_EMIT modified(); Q_EMIT modified();
} }
bool CGeorgesTreeViewDialog::load( const QString &fileName )
{
bool loadFromDFN = false;
// Retrieve the form and load the form.
NLGEORGES::CForm *form;
if(loadFromDFN)
{
// Get the form by DFN name.
form = getFormByDfnName(fileName);
}
else
{
form = getFormByName(fileName);
}
if( form == NULL )
return false;
setForm(form);
loadFormIntoDialog(form);
QApplication::processEvents();
m_fileName = fileName;
QFileInfo info( fileName );
setWindowTitle( info.fileName() );
return true;
}
void CGeorgesTreeViewDialog::write( ) void CGeorgesTreeViewDialog::write( )
{ {
NLGEORGES::CForm *form = static_cast< NLGEORGES::CForm* >( m_form ); NLGEORGES::CForm *form = static_cast< NLGEORGES::CForm* >( m_form );
form->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData(); form->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData();
NLMISC::COFile file; NLMISC::COFile file;
std::string s = NLMISC::CPath::lookup(loadedForm.toAscii().data(), false); std::string s = m_fileName.toUtf8().constData();
if(file.open (s)) if(file.open (s))
{ {
try try

View file

@ -69,6 +69,7 @@ namespace GeorgesQt
void addParentForm(QString parentFormNm); void addParentForm(QString parentFormNm);
bool load( const QString &fileName );
void write ( ); void write ( );
QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; } QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; }

View file

@ -78,7 +78,9 @@ bool GeorgesTypDialog::load( const QString &fileName )
loadTyp(); loadTyp();
m_fileName = fileName; m_fileName = fileName;
setWindowTitle( fileName );
QFileInfo info( fileName );
setWindowTitle( info.fileName() );
return true; return true;
} }
@ -86,10 +88,8 @@ bool GeorgesTypDialog::load( const QString &fileName )
void GeorgesTypDialog::write() void GeorgesTypDialog::write()
{ {
std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false );
NLMISC::COFile file; NLMISC::COFile file;
if( !file.open( path.c_str(), false, true, false ) ) if( !file.open( m_fileName.toUtf8().constData(), false, true, false ) )
return; return;
NLMISC::COXml xml; NLMISC::COXml xml;