From 1e4a4b6724539698b81b43aa6e5209edb2131346 Mon Sep 17 00:00:00 2001 From: aquiles Date: Sun, 14 Aug 2011 20:28:16 +0200 Subject: [PATCH] Changed: #1306 added basic sheet viewing --- .../plugins/core/general_settings_page.cpp | 2 + .../src/plugins/georges_editor/CMakeLists.txt | 9 +- .../src/plugins/georges_editor/formitem.cpp | 162 +++++ .../src/plugins/georges_editor/formitem.h | 69 ++ .../src/plugins/georges_editor/georges.cpp | 64 ++ .../src/plugins/georges_editor/georges.h | 69 ++ .../georges_editor/georges_dirtree_dialog.cpp | 34 +- .../georges_editor/georges_dirtree_dialog.h | 2 +- .../georges_editor/georges_dirtree_form.ui | 34 +- .../georges_editor/georges_editor_form.cpp | 279 +++++--- .../georges_editor/georges_editor_form.h | 8 + .../georges_editor/georges_editor_form.ui | 4 + .../georges_editor/georges_editor_plugin.cpp | 2 +- .../georges_filesystem_model.cpp | 65 ++ .../georges_editor/georges_filesystem_model.h | 69 +- .../georges_treeview_dialog.cpp | 411 +++++++++++ .../georges_editor/georges_treeview_dialog.h | 89 +++ .../georges_editor/georges_treeview_form.ui | 124 ++++ .../georges_editor/georgesform_model.cpp | 641 ++++++++++++++++++ .../georges_editor/georgesform_model.h | 79 +++ .../georgesform_proxy_model.cpp | 94 +++ .../georges_editor/georgesform_proxy_model.h | 45 ++ 22 files changed, 2218 insertions(+), 137 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/formitem.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/formitem.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_form.ui create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_proxy_model.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_proxy_model.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/general_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/general_settings_page.cpp index a050f4789..88bd3a298 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/general_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/general_settings_page.cpp @@ -87,9 +87,11 @@ void GeneralSettingsPage::applyGeneralSettings() settings->beginGroup(Core::Constants::DATA_PATH_SECTION); QString primitivePath = settings->value(Core::Constants::PRIMITIVES_PATH, "l:/primitives").toString(); QString ligoConfigFile = settings->value(Core::Constants::LIGOCONFIG_FILE, "l:/leveldesign/world_editor_files/world_editor_classes.xml").toString(); + QString leveldesignPath = settings->value(Core::Constants::LEVELDESIGN_PATH, "l:/leveldesign").toString(); NLMISC::CPath::addSearchPath(primitivePath.toStdString(), true, false); NLMISC::CPath::display(); NLMISC::CPath::addSearchFile(ligoConfigFile.toStdString()); + NLMISC::CPath::addSearchPath(leveldesignPath.toStdString(), true, false); settings->endGroup(); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/CMakeLists.txt index d1dd346ba..7c668ec8a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/CMakeLists.txt @@ -10,10 +10,13 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h georges_editor_form.h - georges_dirtree_dialog.h) + georges_dirtree_dialog.h + georges_filesystem_model.h + georges_treeview_dialog.h) SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui - georges_dirtree_form.ui) + georges_dirtree_form.ui + georges_treeview_form.ui) SET(OVQT_PLUGIN_GEORGES_EDITOR_RCS georges_editor.qrc) @@ -32,7 +35,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) ADD_LIBRARY(ovqt_plugin_georges_editor MODULE ${SRC} ${OVQT_PLUG_GEORGES_EDITOR_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_PLUG_GEORGES_EDITOR_UI_HDRS} ${OVQT_PLUGIN_GEORGES_EDITOR_RC_SRCS}) -TARGET_LINK_LIBRARIES(ovqt_plugin_georges_editor ovqt_plugin_core nelmisc ${QT_LIBRARIES}) +TARGET_LINK_LIBRARIES(ovqt_plugin_georges_editor ovqt_plugin_core nelmisc nelgeorges ${QT_LIBRARIES}) NL_DEFAULT_PROPS(ovqt_plugin_georges_editor "NeL, Tools, 3D: Object Viewer Qt Plugin: Georges Editor") NL_ADD_RUNTIME_FLAGS(ovqt_plugin_georges_editor) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/formitem.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/formitem.cpp new file mode 100644 index 000000000..205e18a52 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/formitem.cpp @@ -0,0 +1,162 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "formitem.h" + +// Qt includes + +// NeL includes +#include +#include +#include + +namespace Plugin +{ + + CFormItem::CFormItem(NLGEORGES::UFormElm* elm, const QList &data, CFormItem *parent, + NLGEORGES::UFormElm::TWhereIsValue wV, NLGEORGES::UFormElm::TWhereIsNode wN) + { + parentItem = parent; + itemData = data; + formElm = elm; + whereV = wV; + whereN = wN; + } + + CFormItem::~CFormItem() + { + qDeleteAll(childItems); + } + + void CFormItem::appendChild(CFormItem *item) + { + childItems.append(item); + } + + CFormItem *CFormItem::child(int row) + { + return childItems.value(row); + } + + int CFormItem::childCount() const + { + return childItems.count(); + } + + int CFormItem::columnCount() const + { + //nlinfo("columnCount %d",itemData.count()); + return itemData.count(); + } + + QVariant CFormItem::data(int column) const + { + return itemData.value(column); + } + + CFormItem *CFormItem::parent() + { + return parentItem; + } + + int CFormItem::row() const + { + if (parentItem) + return parentItem->childItems.indexOf(const_cast(this)); + + return 0; + } + + bool CFormItem::setData(int column, const QVariant &value) + { + if (column < 0 || column >= itemData.size()) + return false; + + // TODO: default values + if (!formElm) + return false; + + itemData[column] = value; + if (formElm->isAtom()) + { + const NLGEORGES::UType *type = formElm->getType(); + if (type) + { + switch (type->getType()) + { + case NLGEORGES::UType::UnsignedInt: + case NLGEORGES::UType::SignedInt: + case NLGEORGES::UType::Double: + case NLGEORGES::UType::String: + if (parentItem->formElm->isArray()) + { + //((NLGEORGES::CFormElm*)parentItem->formElm);//->arrayInsertNodeByName( + //if(parentItem->formElm->getArrayNode(elmName, num)) + //{ + //} + + bool ok; + // TODO: the node can be renamed from eg "#0" to "foobar" + int arrayIndex = itemData[0].toString().remove("#").toInt(&ok); + if(ok) + { + NLGEORGES::UFormElm *elmt = 0; + if(parentItem->formElm->getArrayNode(&elmt, arrayIndex) && elmt) + { + if (elmt->isAtom()) + { + ((NLGEORGES::CFormElmAtom*)elmt)->setValue(value.toString().toStdString().c_str()); + nldebug(QString("array element string %1 %2") + .arg(itemData[0].toString()).arg(value.toString()) + .toStdString().c_str()); + } + } + } + } + else + { + if(parentItem->formElm->setValueByName( + value.toString().toStdString().c_str(), + itemData[0].toString().toStdString().c_str())) + { + nldebug(QString("string %1 %2") + .arg(itemData[0].toString()).arg(value.toString()) + .toStdString().c_str()); + } + else + { + nldebug(QString("FAILED string %1 %2") + .arg(itemData[0].toString()).arg(value.toString()) + .toStdString().c_str()); + } + } + break; + case NLGEORGES::UType::Color: + nldebug("Color is TODO"); + break; + default: + break; + } + } + } + else + { + nldebug("setting sth other than Atom"); + } + //formElm->setValueByName(); + return true; + } +} diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/formitem.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/formitem.h new file mode 100644 index 000000000..b85b12275 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/formitem.h @@ -0,0 +1,69 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef FORMITEM_H +#define FORMITEM_H + +// NeL includes +#include + +// Qt includes +#include +#include + +namespace Plugin +{ + + class CFormItem + + { + public: + CFormItem(NLGEORGES::UFormElm *elm, const QList &data, + CFormItem *parent = 0, + NLGEORGES::UFormElm::TWhereIsValue = NLGEORGES::UFormElm::ValueForm, + NLGEORGES::UFormElm::TWhereIsNode = NLGEORGES::UFormElm::NodeForm); + ~CFormItem(); + + void appendChild(CFormItem *child); + + CFormItem *child(int row); + int childCount() const; + int columnCount() const; + QVariant data(int column) const; + int row() const; + CFormItem *parent(); + bool setData(int column, const QVariant &value); + NLGEORGES::UFormElm* getFormElm() {return formElm;} + NLGEORGES::UFormElm::TWhereIsValue valueFrom() + { + return whereV; + } + NLGEORGES::UFormElm::TWhereIsNode nodeFrom() + { + return whereN; + } + + private: + QList childItems; + QList itemData; + CFormItem *parentItem; + NLGEORGES::UFormElm* formElm; + NLGEORGES::UFormElm::TWhereIsValue whereV; + NLGEORGES::UFormElm::TWhereIsNode whereN; + }; // CFormItem + +} +#endif // FORMITEM_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges.cpp new file mode 100644 index 000000000..b93f93ec4 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges.cpp @@ -0,0 +1,64 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "georges.h" +#include "nel/misc/o_xml.h" + +// STL includes + +// NeL includes +#include +#include +#include + +// Project includes + +using namespace NLGEORGES; + +namespace Plugin +{ + + CGeorges::CGeorges(): FormLoader(0) + { + FormLoader = UFormLoader::createLoader(); + } + + CGeorges::~CGeorges() + { + } + + UForm *CGeorges::loadForm(std::string formName) + { + UForm *form = FormLoader->loadForm(formName.c_str()); + + return form; + } + + UFormDfn *CGeorges::loadFormDfn(std::string formName) + { + UFormDfn *formdfn = FormLoader->loadFormDfn(formName.c_str()); + + return formdfn; + } + + UType *CGeorges::loadFormType(std::string formName) + { + UType *type = FormLoader->loadFormType(formName.c_str()); + + return type; + } + +} /* namespace Plugin */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges.h new file mode 100644 index 000000000..eb9a6b7da --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges.h @@ -0,0 +1,69 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef GEORGES_H +#define GEORGES_H + +// Misc + +// STL includes +#include + +// NeL includes + +// Qt includes + +// Project includes + +namespace NLGEORGES +{ + class UType; + class UForm; + class UFormDfn; + class UFormLoader; +} + +using namespace NLGEORGES; + +namespace Plugin +{ + + /** + @class CGeorges + A CGeorges class loading and viewing sheets. + */ + class CGeorges + { + public: + /// Default constructor. + CGeorges(); + virtual ~CGeorges(); + + // Load the given form root + UForm* loadForm(std::string formName); + // Load a dfn + UFormDfn* loadFormDfn(std::string formName); + // Load a type + UType *loadFormType (std::string formName); + + // A form loader + UFormLoader *FormLoader; + + };/* class CGeorges */ + +} /* namespace Plugin */ + +#endif // GEORGES_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.cpp index f7e250cce..2a1151164 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.cpp @@ -23,24 +23,35 @@ // NeL includes -//using namespace NLMISC; - namespace Plugin { CGeorgesDirTreeDialog::CGeorgesDirTreeDialog(QString ldPath, QWidget *parent) - :QDockWidget(parent), m_ldPath(ldPath) + :QDockWidget(parent), + m_ldPath(ldPath), + m_proxyModel(0) { m_ui.setupUi(this); + m_ui.filterResetButton->setIcon( + QApplication::style()->standardIcon(QStyle::SP_DialogCancelButton)); + m_dirModel = new CGeorgesFileSystemModel(m_ldPath); - m_ui.dirTree->setModel(m_dirModel); + m_proxyModel = new CGeorgesFileSystemProxyModel(this); + + m_proxyModel->setSourceModel(m_dirModel); + m_ui.dirTree->setModel(m_proxyModel); + + // TODO: filtering in tree model is ... complicated - so hide it for now + m_ui.filterLineEdit->hide(); + m_ui.filterResetButton->hide(); + m_ui.label->hide(); if (m_dirModel->isCorrectLDPath()) { m_dirModel->setRootPath(m_ldPath); - m_ui.dirTree->setRootIndex(m_dirModel->index(m_ldPath)); + m_ui.dirTree->setRootIndex(m_proxyModel->mapFromSource(m_dirModel->index(m_ldPath))); } else { @@ -61,10 +72,9 @@ CGeorgesDirTreeDialog::~CGeorgesDirTreeDialog() void CGeorgesDirTreeDialog::fileSelected(QModelIndex index) { - QString name; - if (index.isValid() && !m_dirModel->isDir(index)) + if (index.isValid() && !m_dirModel->isDir(m_proxyModel->mapToSource(index))) { - Q_EMIT selectedForm(m_dirModel->fileName(index)); + Q_EMIT selectedForm(m_dirModel->fileName(m_proxyModel->mapToSource(index))); } } @@ -81,14 +91,18 @@ void CGeorgesDirTreeDialog::ldPathChanged(QString path) m_ldPath = path; delete m_dirModel; + delete m_proxyModel; m_dirModel = new CGeorgesFileSystemModel(m_ldPath); - m_ui.dirTree->setModel(m_dirModel); + m_proxyModel = new CGeorgesFileSystemProxyModel(this); + + m_proxyModel->setSourceModel(m_dirModel); + m_ui.dirTree->setModel(m_proxyModel); if (m_dirModel->isCorrectLDPath()) { m_dirModel->setRootPath(m_ldPath); - m_ui.dirTree->setRootIndex(m_dirModel->index(m_ldPath)); + m_ui.dirTree->setRootIndex(m_proxyModel->mapFromSource(m_dirModel->index(m_ldPath))); } else { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.h index 3079f76c2..d81897bf3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_dialog.h @@ -45,6 +45,7 @@ private: Ui::CGeorgesDirTreeDialog m_ui; CGeorgesFileSystemModel *m_dirModel; + CGeorgesFileSystemProxyModel *m_proxyModel; QString m_ldPath; Q_SIGNALS: @@ -54,7 +55,6 @@ private Q_SLOTS: void fileSelected(QModelIndex index); void changeFile(QString file); - friend class CMainWindow; }; /* CGEorgesDirTreeDialog */ } /* namespace NLQT */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_form.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_form.ui index 8731d1ca8..4a429af1f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_form.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_dirtree_form.ui @@ -19,7 +19,7 @@ 200 - 111 + 141 @@ -36,7 +36,7 @@ - + @@ -46,9 +46,37 @@ + + + + + + + ... + + + + :/images/ic_nel_georges_editor.png:/images/ic_nel_georges_editor.png + + + true + + + + + + + Filter + + + - + + + + + 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 aa614a161..21aa6d8c6 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 @@ -18,6 +18,7 @@ #include "georges_editor_form.h" #include "georges_editor_constants.h" #include "georges_dirtree_dialog.h" +#include "georges_treeview_dialog.h" #include "../core/icore.h" #include "../core/imenu_manager.h" @@ -30,110 +31,190 @@ #include #include #include +#include namespace Plugin { -GeorgesEditorForm::GeorgesEditorForm(QWidget *parent) - : QMainWindow(parent), - m_georgesDirTreeDialog(0) -{ - m_ui.setupUi(this); - - m_undoStack = new QUndoStack(this); - - _openAction = new QAction(tr("&Open..."), this); - _openAction->setIcon(QIcon(Core::Constants::ICON_OPEN)); - _openAction->setShortcut(QKeySequence::Open); - _openAction->setStatusTip(tr("Open an existing file")); - connect(_openAction, SIGNAL(triggered()), this, SLOT(open())); - - _newAction = new QAction(tr("&New..."), this); - _newAction->setIcon(QIcon(Core::Constants::ICON_NEW)); - _newAction->setShortcut(QKeySequence::New); - _newAction->setStatusTip(tr("Create a new file")); - connect(_newAction, SIGNAL(triggered()), this, SLOT(newFile())); - - _saveAction = new QAction(tr("&Save..."), this); - _saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); - _saveAction->setShortcut(QKeySequence::Save); - _saveAction->setStatusTip(tr("Save the current file")); - connect(_saveAction, SIGNAL(triggered()), this, SLOT(save())); - - _fileToolBar = addToolBar(tr("&File")); - _fileToolBar->addAction(_openAction); - _fileToolBar->addAction(_newAction); - _fileToolBar->addAction(_saveAction); - - readSettings(); - - // create leveldesign directory tree dockwidget - m_georgesDirTreeDialog = new CGeorgesDirTreeDialog(m_leveldesignPath, this); - addDockWidget(Qt::LeftDockWidgetArea, m_georgesDirTreeDialog); - //m_georgesDirTreeDialog->setVisible(false); - connect(Core::ICore::instance(), SIGNAL(changeSettings()), - this, SLOT(settingsChanged())); -} - -GeorgesEditorForm::~GeorgesEditorForm() -{ - writeSettings(); -} - -QUndoStack *GeorgesEditorForm::undoStack() const -{ - return m_undoStack; -} - -void GeorgesEditorForm::open() -{ - // TODO: FileDialog & loadFile(); - //QString fileName = QFileDialog::getOpenFileName(); - //loadFile(fileName); -} - -void GeorgesEditorForm::newFile() -{ - -} - -void GeorgesEditorForm::save() -{ - -} - -void GeorgesEditorForm::readSettings() -{ - QSettings *settings = Core::ICore::instance()->settings(); - settings->beginGroup(Constants::GEORGES_EDITOR_SECTION); - settings->endGroup(); - - settings->beginGroup(Core::Constants::DATA_PATH_SECTION); - m_leveldesignPath = settings->value(Core::Constants::LEVELDESIGN_PATH, "l:/leveldesign").toString(); - settings->endGroup(); -} - -void GeorgesEditorForm::writeSettings() -{ - QSettings *settings = Core::ICore::instance()->settings(); - settings->beginGroup(Constants::GEORGES_EDITOR_SECTION); - settings->endGroup(); - settings->sync(); -} - -void GeorgesEditorForm::settingsChanged() -{ - QSettings *settings = Core::ICore::instance()->settings(); - - settings->beginGroup(Core::Constants::DATA_PATH_SECTION); - QString oldLDPath = m_leveldesignPath; - m_leveldesignPath = settings->value(Core::Constants::LEVELDESIGN_PATH, "l:/leveldesign").toString(); - settings->endGroup(); - - if (oldLDPath != m_leveldesignPath) + GeorgesEditorForm::GeorgesEditorForm(QWidget *parent) + : QMainWindow(parent), + m_georgesDirTreeDialog(0), + m_emptyDock(0), + m_mainDock(0) { - m_georgesDirTreeDialog->ldPathChanged(m_leveldesignPath); + m_ui.setupUi(this); + + // background for the mainwindow + QString css = "QWidget#centralwidget {"; + css += "image: url(:/images/ic_nel_georges_editor.png);"; + css += "}"; + + // add new mainwindow for sheet dockwidgets + QWidget *widget = new QWidget(this); + widget->setObjectName("centralwidget"); + widget->setStyleSheet(css); + setCentralWidget(widget); + QGridLayout *layout = new QGridLayout(widget); + layout->setContentsMargins(0,0,0,0); + widget->setLayout(layout); + m_mainDock = new QMainWindow(this); + m_mainDock->setDockNestingEnabled(true); + layout->addWidget(m_mainDock); + + m_undoStack = new QUndoStack(this); + + Core::IMenuManager *menuManager = Core::ICore::instance()->menuManager(); + _openAction = menuManager->action(Core::Constants::OPEN); + + /*_openAction = new QAction(tr("&Open..."), this); + _openAction->setIcon(QIcon(Core::Constants::ICON_OPEN)); + _openAction->setShortcut(QKeySequence::Open); + _openAction->setStatusTip(tr("Open an existing file")); + connect(_openAction, SIGNAL(triggered()), this, SLOT(open()));*/ + + _newAction = new QAction(tr("&New..."), this); + _newAction->setIcon(QIcon(Core::Constants::ICON_NEW)); + _newAction->setShortcut(QKeySequence::New); + _newAction->setStatusTip(tr("Create a new file")); + connect(_newAction, SIGNAL(triggered()), this, SLOT(newFile())); + + _saveAction = new QAction(tr("&Save..."), this); + _saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); + _saveAction->setShortcut(QKeySequence::Save); + _saveAction->setStatusTip(tr("Save the current file")); + connect(_saveAction, SIGNAL(triggered()), this, SLOT(save())); + + _fileToolBar = addToolBar(tr("&File")); + _fileToolBar->addAction(_openAction); + _fileToolBar->addAction(_newAction); + _fileToolBar->addAction(_saveAction); + + //_openAction->setEnabled(false); + //_newAction->setEnabled(false); + //_saveAction->setEnabled(false); + + readSettings(); + + // create leveldesign directory tree dockwidget + m_georgesDirTreeDialog = new CGeorgesDirTreeDialog(m_leveldesignPath, this); + addDockWidget(Qt::LeftDockWidgetArea, m_georgesDirTreeDialog); + restoreDockWidget(m_georgesDirTreeDialog); + + connect(Core::ICore::instance(), SIGNAL(changeSettings()), + this, SLOT(settingsChanged())); + connect(m_georgesDirTreeDialog, SIGNAL(selectedForm(const QString)), + this, SLOT(loadFile(const QString))); + } + + GeorgesEditorForm::~GeorgesEditorForm() + { + writeSettings(); + } + + QUndoStack *GeorgesEditorForm::undoStack() const + { + return m_undoStack; + } + + void GeorgesEditorForm::open() + { + /*qDebug() << "GeorgesEditorForm::open()"; + if (!m_dockedWidgets.size()) + { + m_dockedWidgets.append(new CGeorgesTreeViewDialog(m_mainDock)); + m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); + } + else + { + m_dockedWidgets.append(new CGeorgesTreeViewDialog(m_mainDock)); + Q_ASSERT(m_dockedWidgets.size() > 1); + m_mainDock->tabifyDockWidget(m_dockedWidgets.at(m_dockedWidgets.size() - 2), m_dockedWidgets.last()); + }*/ + + // TODO: FileDialog & loadFile(); + //m_mainDock->addDockWidget(Qt::TopDockWidgetArea, new CGeorgesTreeViewDialog(m_mainDock, true)); + //m_mainDock->addDockWidget(Qt::LeftDockWidgetArea, new CGeorgesTreeViewDialog(m_mainDock, true)); + //QString fileName = QFileDialog::getOpenFileName(); + //loadFile(fileName); + } + + void GeorgesEditorForm::newFile() + { + + } + + void GeorgesEditorForm::save() + { + + } + + void GeorgesEditorForm::readSettings() + { + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup(Constants::GEORGES_EDITOR_SECTION); + + restoreGeometry(settings->value("geometry").toByteArray()); + restoreState(settings->value("windowState").toByteArray()); + + settings->endGroup(); + + settings->beginGroup(Core::Constants::DATA_PATH_SECTION); + m_leveldesignPath = settings->value(Core::Constants::LEVELDESIGN_PATH, "l:/leveldesign").toString(); + settings->endGroup(); + } + + void GeorgesEditorForm::writeSettings() + { + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup(Constants::GEORGES_EDITOR_SECTION); + + settings->setValue("geometry", saveGeometry()); + settings->setValue("windowState", saveState()); + + settings->endGroup(); + settings->sync(); + } + + void GeorgesEditorForm::settingsChanged() + { + QSettings *settings = Core::ICore::instance()->settings(); + + settings->beginGroup(Core::Constants::DATA_PATH_SECTION); + QString oldLDPath = m_leveldesignPath; + m_leveldesignPath = settings->value(Core::Constants::LEVELDESIGN_PATH, "l:/leveldesign").toString(); + settings->endGroup(); + + if (oldLDPath != m_leveldesignPath) + { + m_georgesDirTreeDialog->ldPathChanged(m_leveldesignPath); + } + } + + void GeorgesEditorForm::loadFile(const QString fileName) + { + QFileInfo info(fileName); + + if (!m_dockedWidgets.size()) + { + m_dockedWidgets.append(new CGeorgesTreeViewDialog(m_mainDock)); + m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); + } + else + { + m_dockedWidgets.append(new CGeorgesTreeViewDialog(m_mainDock)); + Q_ASSERT(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()); + if (form) + { + // delete newView; + // newView = createTreeView(fileName); + m_dockedWidgets.last()->setForm(form); + m_dockedWidgets.last()->loadFormIntoDialog(form); + //setCurrentFile(info.fileName()); + // return; + } } -} } /* namespace Plugin */ 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 96fceb4ed..9e938f62c 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 @@ -27,6 +27,7 @@ namespace Plugin { class CGeorgesDirTreeDialog; +class CGeorgesTreeViewDialog; class GeorgesEditorForm: public QMainWindow { Q_OBJECT @@ -42,6 +43,7 @@ public Q_SLOTS: void newFile(); void save(); void settingsChanged(); + void loadFile(const QString fileName); private: void readSettings(); @@ -57,6 +59,12 @@ private: QAction *_saveAction; QString m_leveldesignPath; + + QDockWidget *m_emptyDock; + QMainWindow *m_mainDock; + + QList m_dockedWidgets; + QList m_tabBars; }; /* class GeorgesEditorForm */ } /* namespace Plugin */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.ui index 905814cc7..3f8cde0f7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.ui @@ -13,12 +13,16 @@ Georges Editor + + + QWidget#centralwidget { image: url(:/images/ic_nel_georges_editor.png); } + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_plugin.cpp index a97188751..e6cad341d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_plugin.cpp @@ -74,7 +74,7 @@ QString GeorgesEditorPlugin::name() const QString GeorgesEditorPlugin::version() const { - return "0.2"; + return "0.3"; } QString GeorgesEditorPlugin::vendor() const diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.cpp index 20cb30b33..796b3c457 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.cpp @@ -28,6 +28,8 @@ CGeorgesFileSystemModel::CGeorgesFileSystemModel(QString ldPath, QObject *parent m_correct(false) { checkLDPath(); + connect(this, SIGNAL(directoryLoaded(QString)), + this, SLOT(dir(const QString))); } CGeorgesFileSystemModel::~CGeorgesFileSystemModel() @@ -35,6 +37,21 @@ CGeorgesFileSystemModel::~CGeorgesFileSystemModel() } +void CGeorgesFileSystemModel::dir(const QString &dir) +{ + QModelIndex i = index(dir); + + if (hasChildren(i)) { + int childCount = rowCount(i); + for (int c=0; cnode(parent); +// return (!indexNode->populatedChildren);*/ +//} + +CGeorgesFileSystemProxyModel::CGeorgesFileSystemProxyModel(QObject *parent) : QSortFilterProxyModel(parent) +{ + setFilterCaseSensitivity(Qt::CaseInsensitive); +} + +bool CGeorgesFileSystemProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +{ + // TODO this is not perfect as it could be + // eg it should filter all dirs which have no entry + QModelIndex idx = sourceModel()->index(source_row, 0, source_parent); + if (sourceModel()->hasChildren(idx)) + { + // QString d = sourceModel()->data(idx).toString(); + // //QModelIndex i = mapFromSource(source_parent); + // //if (hasChildren(i)) { + // int childCount = sourceModel()->rowCount(idx); + // for (int c=0; cindex(c, 0, idx); + // if (child.isValid()) { + // bool test = filterAcceptsRow(c, child); + // }*/ + // } + return true; + } + return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); +} + +//QVariant CGeorgesFileSystemProxyModel::data ( const QModelIndex & index, int role ) const +//{ +// if (role == Qt::DisplayRole) +// { +// QString test = QSortFilterProxyModel::data(index, role).toString(); +// return test.append(QString(" (%1/%2)")). +// arg(rowCount(index)). +// arg(sourceModel()->rowCount(mapToSource(index))); +// } +// return QSortFilterProxyModel::data(index, role); +//} } /* namespace NLQT */ /* end of file */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.h index 775dcb18d..8ee06b3ef 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_filesystem_model.h @@ -18,32 +18,61 @@ #define GEORGES_FILESYSTEM_MODEL_H #include +#include namespace Plugin { -class CGeorgesFileSystemModel : public QFileSystemModel -{ - QString m_ldPath; - -public: - CGeorgesFileSystemModel(QString ldPath, QObject *parent = 0); - ~CGeorgesFileSystemModel(); - - int columnCount(const QModelIndex &/*parent*/) const; - int rowCount(const QModelIndex &/*parent*/) const; - - QVariant data(const QModelIndex& index, int role) const ; - - bool isCorrectLDPath() + class CGeorgesFileSystemModel : public QFileSystemModel { - return m_correct; - } - void checkLDPath(); + Q_OBJECT -private: - bool m_correct; -};/* class CGeorgesFileSystemModel */ + public: + CGeorgesFileSystemModel(QString ldPath, QObject *parent = 0); + ~CGeorgesFileSystemModel(); + + int columnCount(const QModelIndex &/*parent*/) const; + int rowCount(const QModelIndex &/*parent*/) const; + + QVariant data(const QModelIndex& index, int role) const ; + + bool isCorrectLDPath() + { + return m_correct; + } + bool isInitialized() + { + return m_initialized; + } + void setInitialized( bool init) + { + m_initialized = init; + } + void checkLDPath(); + + private: + bool m_correct; + bool m_initialized; + QString m_ldPath; + +private Q_SLOTS: + void dir(const QString&); + };/* class CGeorgesFileSystemModel */ + + // A modified QSortFilterProxyModel that always accepts the root nodes in the tree + // so filtering is only done on the children. + class CGeorgesFileSystemProxyModel : public QSortFilterProxyModel + { + Q_OBJECT + + public: + CGeorgesFileSystemProxyModel(QObject *parent = 0); + + //QVariant data(const QModelIndex& index, int role) const ; + + protected: + bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + }; } /* namespace NLQT */ 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 new file mode 100644 index 000000000..2bcef52cb --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -0,0 +1,411 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "georges_treeview_dialog.h" + +// Qt includes +#include +#include +#include + +// NeL includes +#include +#include +#include +#include + +// Project includes +#include "georges.h" +#include "georgesform_model.h" +#include "georgesform_proxy_model.h" +//#include "formitem.h" +//#include "formdelegate.h" + +using namespace NLMISC; +using namespace NLGEORGES; + +namespace Plugin +{ + + CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/) + : QDockWidget(parent) + { + m_georges = new CGeorges; + + loadedForm = ""; + m_modified = false; + + m_ui.setupUi(this); + m_ui.treeView->header()->setResizeMode(QHeaderView::ResizeToContents); + m_ui.treeViewTabWidget->setTabEnabled (2,false); + + m_ui.checkBoxParent->setStyleSheet("background-color: rgba(0,255,0,30)"); + m_ui.checkBoxDefaults->setStyleSheet("background-color: rgba(255,0,0,30)"); + m_form = 0; + + //FormDelegate *formdelegate = new FormDelegate(this); + //_ui.treeView->setItemDelegateForColumn(1, formdelegate); + + + connect(m_ui.treeView, SIGNAL(doubleClicked (QModelIndex)), + this, SLOT(doubleClicked (QModelIndex))); + connect(m_ui.checkBoxParent, SIGNAL(toggled(bool)), + this, SLOT(filterRows())); + connect(m_ui.checkBoxDefaults, SIGNAL(toggled(bool)), + this, SLOT(filterRows())); + } + + CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog() + { + //delete _ui.treeView->itemDelegateForColumn(1); + delete m_form; + deleteLater(); + //QSettings settings("RyzomCore", "GeorgesQt"); + //settings.setValue("dirViewGeometry", saveGeometry()); + } + + void CGeorgesTreeViewDialog::setForm(const CForm *form) + { + m_form = (UForm*)form; + } + + CForm* CGeorgesTreeViewDialog::getFormByName(const QString formName) + { + if(NLMISC::CPath::exists(formName.toStdString())) + { + return (CForm*)m_georges->loadForm(formName.toStdString()); + } + //else + //{ + // CForm *form = 0; + // // Load the DFN + // std::string extStr = NLMISC::CFile::getExtension( formName.toStdString() ); + // QString dfnName = QString("%1.dfn").arg(extStr.c_str()); + // UFormDfn *formdfn; + // if (NLMISC::CPath::exists(dfnName.toStdString())) + // { + // formdfn = _georges->loadFormDfn (dfnName.toStdString()); + // if (!formdfn) + // { + // nlwarning("Failed to load dfn: %s", dfnName.toStdString().c_str()); + // return 0; + // } + // } + // else + // { + // nlwarning("Cannot find dfn: %s", dfnName.toStdString().c_str()); + // return 0; + // } + + // form = new CForm; + + // // Build the root element + // ((CFormElmStruct*)&form->getRootNode())->build((CFormDfn*)formdfn); + + // uint i; + // for (i=0; iHeldElements[i]))->build ((CFormDfn*)formdfn); + // } + // return form; + //} + return 0; + } + + void CGeorgesTreeViewDialog::loadFormIntoDialog(CForm *form) + { + + if(form) + m_form = form; + else + return; + + UFormElm *root = 0; + root = &m_form->getRootNode(); + + QStringList parents; + for (uint i = 0; i < m_form->getNumParent(); i++) + { + UForm *u = m_form->getParentForm(i); + parents << u->getFilename().c_str(); + } + + QString comments; + comments = m_form->getComment().c_str(); + + if (!comments.isEmpty()) + { + m_ui.treeViewTabWidget->setTabEnabled (1,true); + m_ui.commentEdit->setPlainText(comments); + } + + QStringList strList; + std::set dependencies; + m_form->getDependencies(dependencies); + + QMap< QString, QStringList> deps; + Q_FOREACH(std::string str, dependencies) + { + QString file = str.c_str(); + if (str == m_form->getFilename()) continue; + deps[file.remove(0,file.indexOf(".")+1)] << str.c_str(); + } + nlinfo("typ's %d",deps["typ"].count()); + nlinfo("dfn's %d",deps["dfn"].count()); + + //nlwarning(strList.join(";").toStdString().c_str()); + if (root) + { + loadedForm = m_form->getFilename().c_str(); + + CGeorgesFormModel *model = new CGeorgesFormModel(root,deps,comments,parents); + CGeorgesFormProxyModel *proxyModel = new CGeorgesFormProxyModel(); + proxyModel->setSourceModel(model); + m_ui.treeView->setModel(proxyModel); + m_ui.treeView->expandAll(); + // this is a debug output row + m_ui.treeView->hideColumn(3); + + filterRows(); + + // //_ui.treeView->setRowHidden(0,QModelIndex(),true); + // connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)), + // this, SLOT(modifiedFile())); + + setWindowTitle(loadedForm); + // //Modules::mainWin().getTabBar(); + } + } + + void CGeorgesTreeViewDialog::addParentForm(CForm *form) + { + //((CForm*)_form)->insertParent(((CForm*)_form)->getParentCount(), form->getFilename().c_str(), form); + } + + void CGeorgesTreeViewDialog::modifiedFile( ) + { + /*if (!_modified) + { + _modified = true; + setWindowTitle(windowTitle()+"*"); + Modules::mainWin().setWindowTitle(Modules::mainWin().windowTitle()+"*"); + Q_EMIT modified(_modified); + }*/ + } + + void CGeorgesTreeViewDialog::write( ) + { + + //COFile file; + //std::string s = CPath::lookup(loadedForm.toStdString(), false); + //if (file.open (s)) + //{ + // try + // { + // if (loadedForm.contains(".typ")) + // { + // //nlassert (Type != NULL); + + // //// Write the file + // //// Modified ? + // //if (IsModified ()) + // //{ + // // Type->Header.MinorVersion++; + // // flushValueChange (); + // //} + // //Type->write (xmlStream.getDocument (), theApp.Georges4CVS); + // //modify (NULL, NULL, false); + // //flushValueChange (); + // //UpdateAllViews (NULL); + // //return TRUE; + // } + // else if (loadedForm.contains(".dfn")) + // { + // //nlassert (Dfn != NULL); + + // //// Write the file + // //if (IsModified ()) + // //{ + // // Dfn->Header.MinorVersion++; + // // flushValueChange (); + // //} + // //Dfn->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS); + // //modify (NULL, NULL, false); + // //UpdateAllViews (NULL); + // //return TRUE; + // } + // else + // { + // nlassert (_form != NULL); + + // // Write the file + // /*if (IsModified ()) + // { + // ((CForm*)(UForm*)Form)->Header.MinorVersion++; + // }*/ + // //((CForm*)(UForm*)Form)->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS); + // _form->write(file, false); + // setWindowTitle(windowTitle().remove("*")); + // _modified = false; + // //if (strcmp (xmlStream.getErrorString (), "") != 0) + // //{ + // // char message[512]; + // // smprintf (message, 512, "Error while saving file: %s", xmlStream.getErrorString ()); + // //theApp.outputError (message); + // //} + // //modify (NULL, NULL, false); + // //flushValueChange (); + // //UpdateAllViews (NULL); + + // // Get the left view + // //CView* pView = getLeftView (); + // } + // } + // catch (Exception &e) + // { + // nlerror("Error while loading file: %s", e.what()); + // } + //} + //else + //{ //if (!file.open()) + // nlerror("Can't open the file %s for writing.", s.c_str()); + //} + } + + void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index ) + { + // TODO: this is messy :( perhaps this can be done better + //CGeorgesFormProxyModel * mp = + // dynamic_cast(_ui.treeView->model()); + //CGeorgesFormModel *m = + // dynamic_cast(mp->sourceModel()); + //QModelIndex in = mp->mapToSource(index); + + //// col containing additional stuff like icons + //if (index.column() == 2) + //{ + // QModelIndex in2 = m->index(in.row(),in.column()-1,in.parent()); + // CFormItem *item = m->getItem(in2); + // QString value = item->data(1).toString(); + + // QString path = CPath::lookup(value.toStdString(),false).c_str(); + + // if(value.contains(".tga") || value.contains(".png")) + // { + // QString file = QFileDialog::getOpenFileName( + // this, + // "Select a new image", + // path, + // "Images (*.png *.tga)" + // ); + // if (file.isNull()) + // return; + // QFileInfo info = QFileInfo(file); + + // // TODO? + // // right way would be another delegate but im too lazy :) + // // so for now i just call it directly + // m->setData(in2, info.fileName()); + // return; + // } + // else + // { + // if (path.contains(".shape") || path.contains(".ps")) + // { + // if (Modules::objViewInt()) + // { + // Modules::objViewInt()->resetScene(); + // //Modules::config().configRemapExtensions(); + // Modules::objViewInt()->loadMesh(path.toStdString(),""); + // } + // return; + // } + // } + + // // open eg parent files + // if (!path.isEmpty()) + // Q_EMIT changeFile(path); + + //} + } + + void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) + { + /*if (Modules::mainWin().getEmptyView() == this) + { + event->ignore(); + } + else + { + if(Modules::mainWin().getTreeViewList().size() == 1) + { + Modules::mainWin().createEmptyView( + Modules::mainWin().getTreeViewList().takeFirst()); + } + Modules::mainWin().getTreeViewList().removeOne(this); + deleteLater(); + }*/ + } + + void CGeorgesTreeViewDialog::filterRows() + { + nlinfo("CGeorgesTreeViewDialog::filterRows"); + CGeorgesFormProxyModel * mp = dynamic_cast(m_ui.treeView->model()); + CGeorgesFormModel *m = dynamic_cast(mp->sourceModel()); + if (m) { + m->setShowParents(m_ui.checkBoxParent->isChecked()); + m->setShowDefaults(m_ui.checkBoxDefaults->isChecked()); + } + + //CGeorgesFormProxyModel * mp = dynamic_cast(_ui.treeView->model()); + //CGeorgesFormModel *m = dynamic_cast(mp->sourceModel()); + + //for (int i = 0; i < m->rowCount(); i++) + //{ + // const QModelIndex in = m->index(i,0); + // if (m->getItem(in)->nodeFrom() == UFormElm::NodeParentForm) + // { + // if (newState == Qt::Checked) + // { + // _ui.treeView->setRowHidden(in.row(),in.parent(),false); + // } + // else + // { + // _ui.treeView->setRowHidden(in.row(),in.parent(),true); + // } + // } + // else + // { // search childs // recursive? + // for (int j = 0; j < m->rowCount(in); j++) + // { + // const QModelIndex in2 = m->index(j,0,in); + // if (m->getItem(in2)->nodeFrom() == UFormElm::NodeParentForm) + // { + // if (newState == Qt::Checked) + // { + // _ui.treeView->setRowHidden(in2.row(),in,false); + // } + // else + // { + // _ui.treeView->setRowHidden(in2.row(),in,true); + // } + // } + // } + // } // end of search childs + //} + } + +} /* namespace NLQT */ 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 new file mode 100644 index 000000000..dee1216ca --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.h @@ -0,0 +1,89 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef GEORGES_TREEVIEWER_DIALOG_H +#define GEORGES_TREEVIEWER_DIALOG_H + +#include "ui_georges_treeview_form.h" + +// Qt includes +#include + +// STL includes + +// NeL includes + +// Project includes + +namespace NLGEORGES +{ + class UForm; + class CForm; +} + +using namespace NLGEORGES; + +namespace Plugin +{ + + class CGeorges; + + class CGeorgesTreeViewDialog: public QDockWidget + { + Q_OBJECT + + public: + CGeorgesTreeViewDialog(QWidget *parent = 0); + ~CGeorgesTreeViewDialog(); + + bool modified() {return m_modified;} + void setModified(bool m) {m_modified = m;} + + CForm* getFormByName(const QString); + void addParentForm(CForm *form); + + void write ( ); + + QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; } + + QString loadedForm; + + protected: + void closeEvent(QCloseEvent *event); + + Q_SIGNALS: + void changeFile(QString); + void modified(bool); + public Q_SLOTS: + void setForm(const CForm*); + void loadFormIntoDialog(CForm *form = 0); + void modifiedFile( ); + private Q_SLOTS: + void doubleClicked ( const QModelIndex & index ); + void filterRows(); + + private: + Ui::CGeorgesTreeViewDialog m_ui; + UForm *m_form; + CGeorges *m_georges; + + bool m_modified; + + }; /* CGeorgesTreeViewDialog */ + +} /* namespace NLQT */ + +#endif // GEORGES_TREEVIEWER_DIALOG_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_form.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_form.ui new file mode 100644 index 000000000..71db74326 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_form.ui @@ -0,0 +1,124 @@ + + + CGeorgesTreeViewDialog + + + + 0 + 0 + 400 + 300 + + + + + 0 + 0 + + + + + 199 + 165 + + + + + + + + + + + QTabWidget::West + + + 0 + + + + Form + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + Parent + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Defaults + + + + + + + + Comment + + + + + + false + + + + + + + + Log + + + + + + + + + + + + + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp new file mode 100644 index 000000000..234c2d169 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp @@ -0,0 +1,641 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "georgesform_model.h" + +// NeL includes +#include +#include +#include +#include +#include +#include + +// Qt includes +#include +#include +#include +#include +#include + +// project includes +#include "formitem.h" +//#include "modules.h" + +using namespace NLGEORGES; + +namespace Plugin +{ + + CGeorgesFormModel::CGeorgesFormModel(UFormElm *rootElm, QMap< QString, QStringList> deps, + QString comment, QStringList parents, QObject *parent) : QAbstractItemModel(parent) + { + QList rootData; + rootData << "Value" << "Data" << "Extra";// << "Type"; + m_rootElm = rootElm; + m_rootItem = new CFormItem(m_rootElm, rootData); + m_dependencies = deps; + m_comments = comment; + m_parents = parents; + m_parentRows = new QList; + + setupModelData(); + } + + CGeorgesFormModel::~CGeorgesFormModel() + { + delete m_rootItem; + } + + /******************************************************************************/ + + QVariant CGeorgesFormModel::data(const QModelIndex &p_index, int p_role) const + { + if (!p_index.isValid()) + return QVariant(); + + switch (p_role) + { + case Qt::DisplayRole: + { + return getItem(p_index)->data(p_index.column()); + } + case Qt::BackgroundRole: + { + QBrush defaultBrush = QBrush(QColor(255,0,0,30)); + QBrush parentBrush = QBrush(QColor(0,255,0,30)); + + // if elm not existing it must be some kind of default or type value + if(!getItem(p_index)->getFormElm()) + { + return defaultBrush; + } + + // else it might be some parent elm + switch (getItem(p_index)->nodeFrom()) + { + case NLGEORGES::UFormElm::NodeParentForm: + { + return parentBrush; + } + case NLGEORGES::UFormElm::NodeForm: + { + switch (getItem(p_index)->valueFrom()) + { + case NLGEORGES::UFormElm::ValueParentForm: + { + return parentBrush; + } + default: + { + // parent status test kindof ugly, testing only 2 steps deep + // only needed for colorization as treeview default hides childs + // when parent is hidden + CFormItem *parent = getItem(p_index)->parent(); + if (parent) + { + if (parent->nodeFrom() == NLGEORGES::UFormElm::NodeParentForm) + { + return parentBrush; + } + + CFormItem *parentParent = parent->parent(); + if (parentParent) + { + if (parentParent->nodeFrom() == NLGEORGES::UFormElm::NodeParentForm) + { + return parentBrush; + } + } // endif parentParent + } // endif parent + } // end default + } // end switch valueFrom + } // end case nodeForm + } // end switch nodeFrom + return QVariant(); + } + case Qt::DecorationRole: + { + if (p_index.column() == 2) + { + //p_index. + QModelIndex in = index(p_index.row(),p_index.column()-1,p_index.parent()); + CFormItem *item = getItem(in); + + QString value = item->data(1).toString(); + //QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str(); + + /*if (value.contains(".shape")) + { + if (Modules::objViewInt()) + { + QIcon *icon = Modules::objViewInt()->saveOneImage(value.toStdString()); + if (icon) + { + if(icon->isNull()) + return QIcon(":/images/pqrticles.png"); + else + return QIcon(*icon); + } + else + { + return QIcon(); + } + } + }*/ + if(value.contains(".tga") || value.contains(".png")) + { + QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str(); + if(path.isEmpty()) + { + path = ":/images/pqrticles.png"; + } + return QIcon(path); + } + } + return QVariant(); + break; + } + case Qt::ToolTipRole: + { + if (p_index.column() == 2) + { + QModelIndex in = index(p_index.row(),p_index.column()-1,p_index.parent()); + CFormItem *item = getItem(in); + QString value = item->data(1).toString(); + + /*if (value.contains(".shape")) + { + if (Modules::objViewInt()) + { + QIcon *icon = Modules::objViewInt()->saveOneImage(value.toStdString()); + if (icon) + { + if(icon->isNull()) + return QIcon(":/images/pqrticles.png"); + else + return QIcon(*icon); + } + else + { + return QIcon(); + } + } + }*/ + if(value.contains(".tga") || value.contains(".png")) + { + QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str(); + if(path.isEmpty()) + { + path = ":/images/pqrticles.png"; + } + + QString imageTooltip = QString("").arg(path); + + return imageTooltip; + } + } + return QVariant(); + break; + } + default: + return QVariant(); + } + } + + /******************************************************************************/ + + CFormItem *CGeorgesFormModel::getItem(const QModelIndex &index) const + { + if (index.isValid()) + { + CFormItem *item = static_cast(index.internalPointer()); + if (item) + return item; + } + return m_rootItem; + } + + /******************************************************************************/ + + //bool CGeorgesFormModel::setData(const QModelIndex &index, const QVariant &value, + // int role) + //{ + + // if (role != Qt::EditRole) + // return false; + + // CFormItem *item = getItem(index); + // bool result = item->setData(index.column(), value); + + // // TODO: ugly hack for updating icon too + // if (result) + // Q_EMIT dataChanged(index, this->index(index.row(),index.column()+1,index.parent())); + + // setupModelData(); + // return result; + //} + + /******************************************************************************/ + + Qt::ItemFlags CGeorgesFormModel::flags(const QModelIndex& index) const { + + if (!index.isValid()) + return 0; + + Qt::ItemFlags returnValue = Qt::ItemIsSelectable | Qt::ItemIsEnabled; + + //if(index.column() == 1) + // returnValue |= Qt::ItemIsEditable; + // TODO? + // col 2 should go here too but i dont want to do another delegate + // so for now i just connected the dblClick in the dialog + + return returnValue; + + } + + /******************************************************************************/ + + QVariant CGeorgesFormModel::headerData(int section, + Qt::Orientation orientation, int role) const + { + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return m_rootItem->data(section); + + return QVariant(); + + } + + /******************************************************************************/ + + QModelIndex CGeorgesFormModel::index(int row, int column, const QModelIndex &parent) + const + { + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + CFormItem *parentItem; + + if (!parent.isValid()) + parentItem = m_rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + CFormItem *childItem = parentItem->child(row); + if (childItem) + return createIndex(row, column, childItem); + else + return QModelIndex(); + } + + /******************************************************************************/ + + QModelIndex CGeorgesFormModel::parent(const QModelIndex &index) const + { + if (!index.isValid()) + return QModelIndex(); + + CFormItem *childItem = static_cast(index.internalPointer()); + CFormItem *parentItem = childItem->parent(); + + if (parentItem == m_rootItem) + return QModelIndex(); + + return createIndex(parentItem->row(), 0, parentItem); + } + + /******************************************************************************/ + + int CGeorgesFormModel::rowCount(const QModelIndex &parent) const { + + CFormItem *parentItem; + if (parent.column() > 0) + return 0; + + if (!parent.isValid()) + parentItem = m_rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + return parentItem->childCount(); + + } + + /******************************************************************************/ + + int CGeorgesFormModel::columnCount(const QModelIndex &parent) const { + + if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + else + return m_rootItem->columnCount(); + + } + + /******************************************************************************/ + + void CGeorgesFormModel::loadFormData(UFormElm *root, CFormItem *parent) { + + if (!root) + return; + + uint num = 0; + + + if (root->isStruct()) + { + //((CFormElm*)root)->getForm()->getComment(); + uint structSize = 0; + root->getStructSize(structSize); + while (num < structSize) + { + UFormElm::TWhereIsNode *whereN = new UFormElm::TWhereIsNode; + UFormElm::TWhereIsValue *whereV = new UFormElm::TWhereIsValue; + // Append a new item to the current parent's list of children. + std::string elmName; + if(root->getStructNodeName(num, elmName)) + { + QList columnData; + //QVariant value; + std::string value; + //NLMISC::CRGBA value_color; + //uint value_uint; + //sint value_sint; + //double value_double; + QString elmtType = ""; + UFormElm *elmt = 0; + if(root->getNodeByName(&elmt, elmName.c_str(), whereN, true)) + { + if (elmt) + { + if (elmt->isArray()) + elmtType = "Array"; + if (elmt->isStruct()) + elmtType = "Struct"; + if (elmt->isAtom()) + { + elmtType = "Atom"; + uint numDefinitions = 0; + const UType *type = elmt->getType(); + if (type) + { + numDefinitions = type->getNumDefinition(); + root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV); + switch (type->getType()) + { + case UType::UnsignedInt: + value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble()).toStdString(); + elmtType.append("_uint");break; + case UType::SignedInt: + value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble()).toStdString(); + elmtType.append("_sint");break; + case UType::Double: + value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble(),0,'f',1).toStdString(); + elmtType.append("_double");break; + case UType::String: + elmtType.append("_string");break; + case UType::Color: + elmtType.append("_color");break; + default: + elmtType.append("_unknownType"); + } + } + else + { + elmtType.append("_noType"); + } + + if (numDefinitions) + { + std::string l, v; + QString tmpLabel, tmpValue; + for (uint i = 0; i < numDefinitions; i++) + { + type->getDefinition(i,l,v); + tmpLabel = l.c_str(); + tmpValue = v.c_str(); + if (type->getType() == UType::SignedInt) + { + if (QString("%1").arg(value.c_str()).toDouble() == tmpValue.toDouble()) { + value = l; + break; + } + } + if (type->getType() == UType::String) + { + if (QString(value.c_str()) == tmpValue) + { + value = l; + break; + } + } + } + } + } + if (elmt->isVirtualStruct()) + { + root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV); + elmtType = "VirtualStruct"; + } + switch (*whereN) + { + case UFormElm::NodeForm: + elmtType.append("_fromForm"); break; + case UFormElm::NodeParentForm: + elmtType.append("_fromParentForm"); break; + case UFormElm::NodeDfn: + elmtType.append("_isDFN"); break; + case UFormElm::NodeType: + elmtType.append("_isType"); break; + default: + elmtType.append("_noNode"); + } + switch (*whereV) + { + case UFormElm::ValueForm: + elmtType.append("_formValue"); break; + case UFormElm::ValueParentForm: + elmtType.append("_parentValue"); break; + case UFormElm::ValueDefaultDfn: + elmtType.append("_dfnValue"); break; + case UFormElm::ValueDefaultType: + elmtType.append("_typeValue"); break; + default: + elmtType.append("_noValue"); + } + columnData << QString(elmName.c_str()) << QString(value.c_str()) << "";// << elmtType; + parent->appendChild(new CFormItem(elmt, columnData, parent, *whereV, *whereN)); + //if (parents.last()->childCount() > 0) { + // parents << parents.last()->child(parents.last()->childCount()-1); + //} + loadFormData(elmt, parent->child(parent->childCount()-1)); + } + else + { + // add Defaults + // TODO: spams warnings for non ATOM values but i dont get type of non existing nodes + bool success = root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV); + switch (*whereN) + { + case UFormElm::NodeForm: + elmtType.append("_fromForm"); break; + case UFormElm::NodeParentForm: + elmtType.append("_fromParentForm"); break; + case UFormElm::NodeDfn: + elmtType.append("_isDFN"); break; + case UFormElm::NodeType: + elmtType.append("_isType"); break; + default: + elmtType.append("_noNode"); + } + switch (*whereV) + { + case UFormElm::ValueForm: + elmtType.append("_formValue"); break; + case UFormElm::ValueParentForm: + elmtType.append("_parentValue"); break; + case UFormElm::ValueDefaultDfn: + elmtType.append("_dfnValue"); break; + case UFormElm::ValueDefaultType: + elmtType.append("_typeValue"); break; + default: + elmtType.append("_noValue"); + } + + columnData << QString(elmName.c_str()) << QString(value.c_str()) << "";// << elmtType; + parent->appendChild(new CFormItem(elmt, columnData, parent, *whereV, *whereN)); + } + } + else + { + nlinfo("getNodeByName returned false"); + } + } + num++; + } + } + if (root->isArray()) + { + uint arraySize = 0; + root->getArraySize(arraySize); + while (num < arraySize) + { + std::string elmName; + if(root->getArrayNodeName(elmName, num)) + { + QList columnData; + std::string value; + QString elmtType = ""; + + UFormElm *elmt = 0; + if(root->getArrayNode(&elmt,0) && elmt) + { + if (elmt->isArray()) + elmtType = "Array"; + if (elmt->isStruct()) { + elmtType = "Struct"; + } + if (elmt->isAtom()) + { + elmt->getValue(value); + elmtType = "Atom"; + } + if (elmt->isVirtualStruct()) + elmtType = "VirtualStruct"; + + elmtType.append("_arrayValue"); + columnData << QString(elmName.c_str()) << QString(value.c_str()) << "";// << elmtType; + parent->appendChild(new CFormItem(elmt, columnData, parent)); + loadFormData(elmt, parent->child(parent->childCount()-1)); + } + } + num++; + } + } + } + + /******************************************************************************/ + + void CGeorgesFormModel::loadFormHeader() + { + + CFormItem *fi_pars = new CFormItem(m_rootElm, QList() << "parents", m_rootItem); + m_rootItem->appendChild(fi_pars); + + Q_FOREACH(QString str, m_parents) + { + fi_pars->appendChild(new CFormItem(m_rootElm, QList() << str, fi_pars)); + } + + /*QStringList dfns = _dependencies["dfn"]; + QStringList typs = _dependencies["typ"]; + + _dependencies.remove("dfn"); + _dependencies.remove("typ"); + + CFormItem *fi_dep = new CFormItem(_rootElm, QList() << "dependencies", _rootItem); + _rootItem->appendChild(fi_dep); + + if (!dfns.isEmpty()) { + CFormItem *fi_dfn = new CFormItem(_rootElm, QList() << "dfn", fi_dep); + fi_dep->appendChild(fi_dfn); + foreach(QString str, dfns) { + fi_dfn->appendChild(new CFormItem(_rootElm, QList() << str, fi_dfn)); + } + } + if (!typs.isEmpty()) { + CFormItem *fi_typ = new CFormItem(_rootElm, QList() << "typ", fi_dep); + fi_dep->appendChild(fi_typ); + foreach(QString str, typs) { + fi_typ->appendChild(new CFormItem(_rootElm, QList() << str, fi_typ)); + } + } + if (!_dependencies.isEmpty()) { + CFormItem *fi_other = new CFormItem(_rootElm, QList() << "other", fi_dep); + fi_dep->appendChild(fi_other); + foreach(QStringList list, _dependencies) { + foreach(QString str, list) { + fi_other->appendChild(new CFormItem(_rootElm, QList() << str, fi_other)); + } + } + }*/ + } + + /******************************************************************************/ + + void CGeorgesFormModel::setupModelData() + { + loadFormHeader(); + loadFormData(m_rootElm, m_rootItem); + } + + /******************************************************************************/ + + void CGeorgesFormModel::setShowParents( bool show ) { + m_showParents = show; + Q_EMIT layoutAboutToBeChanged(); + Q_EMIT layoutChanged(); + } + void CGeorgesFormModel::setShowDefaults( bool show ) + { + m_showDefaults = show; + Q_EMIT layoutAboutToBeChanged(); + Q_EMIT layoutChanged(); + } +} /* namespace Plugin */ + +/* end of file */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.h new file mode 100644 index 000000000..7668f9e7f --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.h @@ -0,0 +1,79 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef GEORGESFORM_MODEL_H +#define GEORGESFORM_MODEL_H + +// Qt includes +#include +#include +#include +#include + +// project includes + +namespace NLGEORGES { + class UFormElm; +} + +namespace Plugin +{ + + class CFormItem; + + class CGeorgesFormModel : public QAbstractItemModel + { + + public: + CGeorgesFormModel(NLGEORGES::UFormElm *root, QMap< QString, QStringList> deps, + QString comment, QStringList parents, QObject *parent = 0); + ~CGeorgesFormModel(); + + QVariant data(const QModelIndex &index, int role) const; + //bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + CFormItem *getItem(const QModelIndex &index) const; + CGeorgesFormModel *model() { return this; } + bool showParents() { return m_showParents;} + bool showDefaults() { return m_showDefaults;} + void setShowParents( bool show ); + void setShowDefaults( bool show ); + + private: + void setupModelData(); + void loadFormData(NLGEORGES::UFormElm *rootElm, CFormItem *parent); + void loadFormHeader(); + + CFormItem* m_rootItem; + NLGEORGES::UFormElm* m_rootElm; + QMap< QString, QStringList> m_dependencies; + QString m_comments; + QStringList m_parents; + QList* m_parentRows; + + bool m_showParents; + bool m_showDefaults; + + };/* class CGeorgesFormModel */ + +} /* namespace Plugin */ + +#endif // GEORGESFORM_MODEL_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_proxy_model.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_proxy_model.cpp new file mode 100644 index 000000000..0950e1b04 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_proxy_model.cpp @@ -0,0 +1,94 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "georgesform_proxy_model.h" +#include "georgesform_model.h" + +// NeL includes +#include +#include + +// project includes +#include "formitem.h" + +#include + +namespace Plugin +{ + + bool CGeorgesFormProxyModel::filterAcceptsRow(int sourceRow, + const QModelIndex &sourceParent) const + { + //nlinfo("CGeorgesFormProxyModel::filterAcceptsRow"); + + // column doesnt matter for item + CGeorgesFormModel *smodel = dynamic_cast(sourceModel()); + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + CFormItem *item = smodel->getItem(index); + + //qDebug() << smodel->showParents() << (item->valueFrom() == NLGEORGES::UFormElm::NodeParentForm); + //nlinfo("%s %d %d %d %d", item->data(index.column()).toString().toStdString().c_str(), + // item->valueFrom(), + // item->nodeFrom(), + // smodel->showParents(), + // (item->valueFrom() == NLGEORGES::UFormElm::NodeParentForm)); + + // if elm not existing it must be some kind of default or type value + if(!item->getFormElm()) + { + return smodel->showDefaults(); + } + + // else it might be some parent elm + switch (item->nodeFrom()) + { + case NLGEORGES::UFormElm::NodeParentForm: + { + return smodel->showParents(); + } + case NLGEORGES::UFormElm::NodeForm: + { + switch (item->valueFrom()) + { + case NLGEORGES::UFormElm::ValueParentForm: + { + return smodel->showParents(); + } + default: + { + CFormItem *parent = item->parent(); + if (parent && (parent->nodeFrom() == NLGEORGES::UFormElm::NodeParentForm)) + { + return smodel->showParents(); + } + } + } + } + } + return true; + } + +/******************************************************************************/ + + bool CGeorgesFormProxyModel::filterAcceptsColumn(int sourceRow, + const QModelIndex &sourceParent) const + { + //nlinfo("CGeorgesFormProxyModel::filterAcceptsColumn"); + return QSortFilterProxyModel::filterAcceptsColumn(sourceRow, sourceParent); + } +} /* namespace Plugin */ + +/* end of file */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_proxy_model.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_proxy_model.h new file mode 100644 index 000000000..570913dab --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_proxy_model.h @@ -0,0 +1,45 @@ +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef GEORGESFORM_PROXY_MODEL_H +#define GEORGESFORM_PROXY_MODEL_H + +// Qt includes +#include + +namespace Plugin +{ + + class CGeorgesFormProxyModel : public QSortFilterProxyModel + { + + public: + CGeorgesFormProxyModel(QObject *parent = 0): QSortFilterProxyModel(parent) + { + } + ~CGeorgesFormProxyModel() + { + } + + protected: + virtual bool filterAcceptsColumn ( int source_column, const QModelIndex & source_parent ) const ; + virtual bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const ; + + };/* class CGeorgesFormProxyModel */ + +} /* namespace NLQT */ + +#endif // GEORGESFORM_PROXY_MODEL_H