From 7932d4b7fca9f3d43318660c0a4005d5b0ce2e68 Mon Sep 17 00:00:00 2001 From: sfb Date: Tue, 15 May 2012 13:51:48 -0500 Subject: [PATCH] Changed: #1306 Added basic new form creation. Lots of bugs still. --- .../georges_editor/georges_editor_form.cpp | 82 +++++++++++++------ .../georges_editor/georges_editor_form.h | 8 ++ .../georges_treeview_dialog.cpp | 58 ++++++++++++- .../georges_editor/georges_treeview_dialog.h | 13 ++- 4 files changed, 131 insertions(+), 30 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp index 5cf3eb9ce..c54c41638 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp @@ -92,6 +92,13 @@ namespace GeorgesQt addDockWidget(Qt::LeftDockWidgetArea, m_georgesDirTreeDialog); restoreDockWidget(m_georgesDirTreeDialog); + // Set the default sheet dir dir to the level design path. + m_lastSheetDir = "."; + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup(Core::Constants::DATA_PATH_SECTION); + m_lastSheetDir = settings->value(Core::Constants::LEVELDESIGN_PATH, "l:/leveldesign").toString(); + settings->endGroup(); + connect(Core::ICore::instance(), SIGNAL(changeSettings()), this, SLOT(settingsChanged())); connect(m_georgesDirTreeDialog, SIGNAL(selectedForm(const QString)), @@ -117,9 +124,19 @@ namespace GeorgesQt loadFile(fileName); } - void GeorgesEditorForm::newFile() + void GeorgesEditorForm::newFile() { + // Assume it is a form, for now. We'll have to retrieve the DFN we'll be using as a base. + QString fileName = QFileDialog::getOpenFileName(this, tr("Select Base Form Definition"), m_lastSheetDir, "Form Definition (*.dfn)"); + if(!fileName.isNull()) + { + // Use the file loader to create the new form. + loadFile(fileName, true); + // Save the folder we just opened for future dialogs. + QFileInfo pathInfo( fileName ); + m_lastSheetDir = pathInfo.absolutePath(); + } } void GeorgesEditorForm::save() @@ -171,26 +188,18 @@ 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); - if (!m_dockedWidgets.size()) + // Check to see if the form is already loaded, if it is just raise it. + if (m_dockedWidgets.size()) { - CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock); - dock->setUndoStack(m_undoStack); - m_lastActiveDock = dock; - m_dockedWidgets.append(dock); - - m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); - connect(m_dockedWidgets.last(), SIGNAL(closing()), - this, SLOT(closingTreeView())); - connect(m_dockedWidgets.last(), SIGNAL(visibilityChanged(bool)), - m_dockedWidgets.last(), SLOT(checkVisibility(bool))); - } - else - { - Q_FOREACH(CGeorgesTreeViewDialog *wgt, m_dockedWidgets) { if (info.fileName() == wgt->loadedForm) @@ -199,18 +208,38 @@ namespace GeorgesQt return; } } - CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock); - dock->setUndoStack(m_undoStack); - m_dockedWidgets.append(dock); + } - connect(m_dockedWidgets.last(), SIGNAL(closing()), - this, SLOT(closingTreeView())); - connect(m_dockedWidgets.last(), SIGNAL(visibilityChanged(bool)), - m_dockedWidgets.last(), SLOT(checkVisibility(bool))); - Q_ASSERT(m_dockedWidgets.size() > 1); + CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock); + dock->setUndoStack(m_undoStack); + m_lastActiveDock = dock; + m_dockedWidgets.append(dock); + + connect(m_dockedWidgets.last(), SIGNAL(closing()), this, SLOT(closingTreeView())); + connect(m_dockedWidgets.last(), SIGNAL(visibilityChanged(bool)), m_dockedWidgets.last(), SLOT(checkVisibility(bool))); + + // If there is more than one form open - tabify the new form. If this is the first form open add it to the dock. + if(m_dockedWidgets.size() > 1) + { m_mainDock->tabifyDockWidget(m_dockedWidgets.at(m_dockedWidgets.size() - 2), m_dockedWidgets.last()); } - CForm *form = m_dockedWidgets.last()->getFormByName(info.fileName()); + else + { + m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); + } + + // Retrieve the form and load the form. + NLGEORGES::CForm *form; + if(loadFromDfn) + { + // Get the form by DFN name. + form = m_dockedWidgets.last()->getFormByDfnName(info.fileName()); + } + else + { + form = m_dockedWidgets.last()->getFormByName(info.fileName()); + } + if (form) { m_dockedWidgets.last()->setForm(form); @@ -224,6 +253,7 @@ namespace GeorgesQt } else { + nlwarning("Failed to load form: %s", info.fileName().toStdString().c_str()); m_dockedWidgets.last()->close(); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h index c991f8b9f..77fdd1ec8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h @@ -41,6 +41,7 @@ public: public Q_SLOTS: void open(); void loadFile(const QString fileName); + void loadFile(const QString fileName, bool loadFromDfn); void newFile(); void save(); void settingsChanged(); @@ -66,8 +67,15 @@ private: QMainWindow *m_mainDock; + /// Contains a list of all of the open forms. QList m_dockedWidgets; + + /// Contains a pointer to the last known focal change for active documents. CGeorgesTreeViewDialog *m_lastActiveDock; + + /// Contains a record of the last directory a sheet file dialog was opened for. + QString m_lastSheetDir; + }; /* class GeorgesEditorForm */ } /* namespace GeorgesQt */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.cpp index f7386cd60..5a38c4ecf 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -61,6 +61,7 @@ namespace GeorgesQt // Set the default sheet dir dir to the level design path. m_lastSheetDir = "."; QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup(Core::Constants::DATA_PATH_SECTION); m_lastSheetDir = settings->value(Core::Constants::LEVELDESIGN_PATH, "l:/leveldesign").toString(); settings->endGroup(); @@ -114,11 +115,12 @@ namespace GeorgesQt m_form = (UForm*)form; } - CForm* CGeorgesTreeViewDialog::getFormByName(const QString formName) + NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByName(const QString formName) { if(NLMISC::CPath::exists(formName.toStdString())) { - return (CForm*)m_georges->loadForm(formName.toStdString()); + //NLGEORGES::CForm *form = dynamic_cast(m_georges->loadForm(formName.toStdString())); + return (NLGEORGES::CForm *)m_georges->loadForm(formName.toStdString()); } //else //{ @@ -154,9 +156,58 @@ namespace GeorgesQt // } // return form; //} + nlinfo("File '%s' does not exist!", formName.toStdString().c_str()); return 0; } + NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByDfnName(const QString dfnName) + { + if(NLMISC::CPath::exists(dfnName.toStdString())) + { + // Create a new form object. + NLGEORGES::CForm *form = new NLGEORGES::CForm(); + m_form = form; + + // Retrieve a copy of the root definition. + NLGEORGES::CFormDfn *formDfn = dynamic_cast(m_georges->loadFormDfn(dfnName.toStdString())); + + // Next we'll use the root node to build a new form. + NLGEORGES::CFormElmStruct *fes = dynamic_cast(getRootNode(0)); + fes->build(formDfn); + + // And then initialize the held elements; + for(uint i = 0; i(getRootNode(i+1)); + fes->build(formDfn); + } + + return form; + } + nlinfo("File '%s' does not exist!", dfnName.toStdString().c_str()); + return NULL; + } + + NLGEORGES::CFormElm *CGeorgesTreeViewDialog::getRootNode(uint slot) + { + NLGEORGES::CForm *form = getFormPtr(); + + if(slot == 0) + { + const NLGEORGES::UFormElm &formElm = form->getRootNode(); + return (NLGEORGES::CFormElm *)&formElm; + } + + // Make sure the slot value is valid and then return the corresponding element. + nlassert(slot < NLGEORGES::CForm::HeldElementCount+1); + return getFormPtr()->HeldElements[slot-1]; + } + + NLGEORGES::CForm *CGeorgesTreeViewDialog::getFormPtr() + { + return dynamic_cast(m_form); + } + void CGeorgesTreeViewDialog::loadFormIntoDialog(CForm *form) { @@ -169,7 +220,8 @@ namespace GeorgesQt root = &m_form->getRootNode(); QStringList parents; - for (uint i = 0; i < m_form->getNumParent(); i++) + uint cnt = form->getParentCount(); + for (uint i = 0; i < cnt /*form->getParentCount()*/; i++) { UForm *u = m_form->getParentForm(i); parents << u->getFilename().c_str(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.h index a7ff4c375..53e36ec22 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.h @@ -36,6 +36,7 @@ namespace NLGEORGES { class UForm; class CForm; + class CFormElm; } using namespace NLGEORGES; @@ -56,7 +57,15 @@ namespace GeorgesQt bool isModified() {return m_modified;} void setModified(bool m) {m_modified = m;} - CForm* getFormByName(const QString); + NLGEORGES::CForm* getFormByName(const QString formName); + NLGEORGES::CForm* getFormByDfnName(const QString dfnName); + + /// Retrieves the root element based on the slot (document or held elements.) + NLGEORGES::CFormElm *getRootNode(uint slot); + + /// Returns the form as a CForm pointer. + NLGEORGES::CForm *getFormPtr(); + void addParentForm(QString parentFormNm); void write ( ); @@ -67,6 +76,8 @@ namespace GeorgesQt m_undoStack = stack; } + + QString loadedForm; protected: