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

This commit is contained in:
dfighter1985 2014-09-03 19:11:38 +02:00
parent ec20f009e7
commit 6954103b61
7 changed files with 60 additions and 61 deletions

View file

@ -72,7 +72,8 @@ bool GeorgesDFNDialog::load( const QString &fileName )
if( udfn == NULL )
return false;
setWindowTitle( fileName );
QFileInfo info( fileName );
setWindowTitle( info.fileName() );
NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn );
m_pvt->dfn = cdfn;
@ -105,18 +106,14 @@ void GeorgesDFNDialog::write()
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;
if( !file.open( path, false, true, false ) )
if( !file.open( m_fileName.toUtf8().constData(), false, true, false ) )
return;
NLMISC::COXml xml;
xml.init( &file );
m_pvt->dfn->write( xml.getDocument(), path.c_str() );
m_pvt->dfn->write( xml.getDocument(), m_fileName.toUtf8().constData() );
xml.flush();
file.close();

View file

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

View file

@ -29,6 +29,7 @@
// NeL includes
#include <nel/misc/debug.h>
#include <nel/misc/path.h>
// Qt includes
#include <QSettings>
@ -205,20 +206,19 @@ namespace GeorgesQt
}
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.
if (m_dockedWidgets.size())
{
Q_FOREACH(GeorgesDockWidget *wgt, m_dockedWidgets)
{
if (info.fileName() == wgt->fileName())
if ( QString( path.c_str() ) == wgt->fileName())
{
wgt->raise();
return;
@ -230,16 +230,16 @@ namespace GeorgesQt
if( info.suffix() == "dfn" )
{
w = loadDfnDialog( fileName );
w = loadDfnDialog( path.c_str() );
}
else
if( info.suffix() == "typ" )
{
w = loadTypDialog( fileName );
w = loadTypDialog( path.c_str() );
}
else
{
w = loadFormDialog( fileName, loadFromDfn );
w = loadFormDialog( path.c_str() );
}
if( w == NULL )
@ -352,40 +352,18 @@ namespace GeorgesQt
return d;
}
GeorgesDockWidget* GeorgesEditorForm::loadFormDialog( const QString &fileName, bool loadFromDFN )
GeorgesDockWidget* GeorgesEditorForm::loadFormDialog( const QString &fileName )
{
QFileInfo info( fileName );
CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog();
// 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
if( !d->load( fileName ) )
{
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;
}

View file

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

View file

@ -120,11 +120,7 @@ namespace GeorgesQt
NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByName(const QString formName)
{
if(NLMISC::CPath::exists(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());
}
return (NLGEORGES::CForm *)m_georges->loadForm(formName.toAscii().data());
//else
//{
// CForm *form = 0;
@ -159,7 +155,6 @@ namespace GeorgesQt
// }
// return form;
//}
nlinfo("File '%s' does not exist!", formName.toAscii().data());
return 0;
}
@ -271,9 +266,6 @@ namespace GeorgesQt
connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),
this, SLOT(modifiedFile()));
setWindowTitle(loadedForm);
// //Modules::mainWin().getTabBar();
m_model = model;
}
}
@ -317,13 +309,44 @@ namespace GeorgesQt
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( )
{
NLGEORGES::CForm *form = static_cast< NLGEORGES::CForm* >( m_form );
form->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData();
NLMISC::COFile file;
std::string s = NLMISC::CPath::lookup(loadedForm.toAscii().data(), false);
std::string s = m_fileName.toUtf8().constData();
if(file.open (s))
{
try

View file

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

View file

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