From 6954103b611c4a0fd69843a2204a08bed76937f8 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 19:11:38 +0200 Subject: [PATCH] A little refactoring, dialogs are now loaded using the full filepath. --- .../georges_editor/georges_dfn_dialog.cpp | 11 ++-- .../georges_editor/georges_dock_widget.h | 1 + .../georges_editor/georges_editor_form.cpp | 54 ++++++------------- .../georges_editor/georges_editor_form.h | 3 +- .../georges_treeview_dialog.cpp | 43 +++++++++++---- .../georges_editor/georges_treeview_dialog.h | 1 + .../georges_editor/georges_typ_dialog.cpp | 8 +-- 7 files changed, 60 insertions(+), 61 deletions(-) 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 fd1f8a19b..6ec7c80d2 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -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(); diff --git a/code/studio/src/plugins/georges_editor/georges_dock_widget.h b/code/studio/src/plugins/georges_editor/georges_dock_widget.h index 7551d8106..53e4f6841 100644 --- a/code/studio/src/plugins/georges_editor/georges_dock_widget.h +++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.h @@ -36,6 +36,7 @@ public: QString fileName() const{ return m_fileName; } + virtual bool load( const QString &fileName ) = 0; virtual void write() = 0; protected: 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 81691865b..e5136e82f 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -29,6 +29,7 @@ // NeL includes #include +#include // Qt includes #include @@ -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; } diff --git a/code/studio/src/plugins/georges_editor/georges_editor_form.h b/code/studio/src/plugins/georges_editor/georges_editor_form.h index 078daec74..a1a1a46e7 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.h +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.h @@ -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; diff --git a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp index 3a2113417..86c0fb8af 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -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(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 diff --git a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h index 765a70a21..0acb48941 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -69,6 +69,7 @@ namespace GeorgesQt void addParentForm(QString parentFormNm); + bool load( const QString &fileName ); void write ( ); QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; } diff --git a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp index ab4d2c302..123aa0fd4 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -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;