From 34b1f12bb838d325fbfed8dd57e442db4edd5d35 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Sun, 5 Feb 2012 02:31:56 +0300 Subject: [PATCH] Changed: #1302 Added preview properties (except ConstStringArray values). --HG-- branch : gsoc2011-worldeditorqt --- .../plugins/world_editor/primitive_item.cpp | 20 ++ .../src/plugins/world_editor/primitive_item.h | 7 + .../world_editor/property_editor_widget.cpp | 294 +++++++++++++----- .../world_editor/property_editor_widget.h | 20 +- .../world_editor/world_editor_constants.h | 7 +- .../world_editor/world_editor_scene.cpp | 2 +- .../world_editor/world_editor_window.cpp | 25 +- 7 files changed, 287 insertions(+), 88 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.cpp index c0d799401..12d3b994a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.cpp @@ -173,6 +173,26 @@ WorldEditNode::~WorldEditNode() { } +void WorldEditNode::setContext(const QString &name) +{ + m_context = name; +} + +QString WorldEditNode::context() const +{ + return m_context; +} + +void WorldEditNode::setDataPath(const QString &path) +{ + m_dataPath = path; +} + +QString WorldEditNode::dataPath() const +{ + return m_dataPath; +} + Node::NodeType WorldEditNode::type() const { return WorldEditNodeType; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.h index 7ebf4437f..519b40aaf 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.h @@ -112,9 +112,16 @@ public: WorldEditNode(const QString &name); virtual ~WorldEditNode(); + void setContext(const QString &name); + QString context() const; + void setDataPath(const QString &path); + QString dataPath() const; + virtual NodeType type() const; private: + QString m_context; + QString m_dataPath; }; /* diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/property_editor_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/property_editor_widget.cpp index 7b4224e04..c5e2a2e0d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/property_editor_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/property_editor_widget.cpp @@ -17,6 +17,7 @@ // Project includes #include "property_editor_widget.h" +#include "world_editor_misc.h" // NeL includes #include @@ -38,15 +39,20 @@ PropertyEditorWidget::PropertyEditorWidget(QWidget *parent) m_variantManager = new QtVariantPropertyManager(this); m_enumManager = new QtEnumPropertyManager(this); + m_stringArrayManager = new QtTextPropertyManager(this); + connect(m_variantManager, SIGNAL(valueChanged(QtProperty *, const QVariant &)), this, SLOT(valueChanged(QtProperty *, const QVariant &))); QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory(this); QtEnumEditorFactory *enumFactory = new QtEnumEditorFactory(this); + QtTextEditorFactory *textFactory = new QtTextEditorFactory(this); + m_ui.treePropertyBrowser->setFactoryForManager(m_variantManager, variantFactory); m_ui.treePropertyBrowser->setFactoryForManager(m_enumManager, enumFactory); + m_ui.treePropertyBrowser->setFactoryForManager(m_stringArrayManager, textFactory); - m_groupManager = new QtGroupPropertyManager(this); + m_groupManager = new QtGroupPropertyManager(this); } PropertyEditorWidget::~PropertyEditorWidget() @@ -58,110 +64,238 @@ void PropertyEditorWidget::clearProperties() m_ui.treePropertyBrowser->clear(); } -void PropertyEditorWidget::updateSelection(const NodeList &selected, const NodeList &deselected) +void PropertyEditorWidget::updateSelection(Node *node) { clearProperties(); + if ((node == 0) || (node->type() != Node::PrimitiveNodeType)) + return; + // The parameter list - std::set parameterList; + std::list parameterList; - for (int i = 0; i < selected.size(); ++i) + PrimitiveNode *primNode = static_cast(node); + const NLLIGO::IPrimitive *primitive = primNode->primitive(); + const NLLIGO::CPrimitiveClass *primClass = primNode->primitiveClass(); + + // Use the class or not ? + if (primClass) { - if (selected.at(i)->type() == Node::RootPrimitiveNodeType) + // For each properties of the class + for (uint p = 0; p < primClass->Parameters.size(); p++) { - /* - const_cast(_PropDlgLocators[i].Primitive)->removePropertyByName("name"); - const_cast(_PropDlgLocators[i].Primitive)->removePropertyByName("path"); - //TODO faire une fonction dans CWorldDoc pour recup m_strPathName - string name; - getDocument()->getPrimitiveDisplayName(name,_PropDlgLocators[i].getDatabaseIndex()); - string path; - getDocument()->getFilePath(_PropDlgLocators[i].getDatabaseIndex(),path); - - const_cast(_PropDlgLocators[i].Primitive)->addPropertyByName("name",new CPropertyString (name)); - const_cast(_PropDlgLocators[i].Primitive)->addPropertyByName("path",new CPropertyString (path)); - */ + // Is the parameter visible ? + if (primClass->Parameters[p].Visible) + { + if (primClass->Parameters[p].Name == "name") + parameterList.push_front(primClass->Parameters[p]); + else + parameterList.push_back(primClass->Parameters[p]); + } } - - if (selected.at(i)->type() == Node::PrimitiveNodeType) + } + else + { + // For each primitive property + uint numProp = primitive->getNumProperty(); + for (uint p = 0; p < numProp; p++) { - PrimitiveNode *node = static_cast(selected.at(i)); - const NLLIGO::IPrimitive *primitive = node->primitive(); - const NLLIGO::CPrimitiveClass *primClass = node->primitiveClass(); - - // Use the class or not ? - if (primClass) - { - QtProperty *groupNode; - groupNode = m_groupManager->addProperty(node->data(Qt::DisplayRole).toString()); - m_ui.treePropertyBrowser->addProperty(groupNode); - - // For each properties of the class - for (uint p = 0; p < primClass->Parameters.size(); p++) - { - // Is the parameter visible ? - if (primClass->Parameters[p].Visible) - { - QtProperty *param; + // Get the property + std::string propertyName; + const NLLIGO::IProperty *prop; + nlverify(primitive->getProperty(p, propertyName, prop)); - if (primClass->Parameters[p].Type == NLLIGO::CPrimitiveClass::CParameter::Boolean) - param = m_variantManager->addProperty(QVariant::Bool, primClass->Parameters[p].Name.c_str()); - else if (primClass->Parameters[p].Type == NLLIGO::CPrimitiveClass::CParameter::ConstString) - { - param = m_enumManager->addProperty(primClass->Parameters[p].Name.c_str()); - } - else if (primClass->Parameters[p].Type == NLLIGO::CPrimitiveClass::CParameter::String) - param = m_variantManager->addProperty(QVariant::String, primClass->Parameters[p].Name.c_str()); - else - param = m_variantManager->addProperty(QVariant::String, primClass->Parameters[p].Name.c_str()); + // Add a default property + NLLIGO::CPrimitiveClass::CParameter defProp(*prop, propertyName.c_str()); - groupNode->addSubProperty(param); - - parameterList.insert(primClass->Parameters[p]); - } - } - } + if (defProp.Name == "name") + parameterList.push_front(defProp); else - { - // For each primitive property - uint numProp = primitive->getNumProperty(); - for (uint p = 0; p < numProp; p++) - { - // Get the property - std::string propertyName; - const NLLIGO::IProperty *prop; - nlverify(primitive->getProperty (p, propertyName, prop)); - - // Add a default property - NLLIGO::CPrimitiveClass::CParameter defProp(*prop, propertyName.c_str()); - parameterList.insert(defProp); - } - } + parameterList.push_back(defProp); } } // Remove property class - std::set::iterator ite = parameterList.begin (); + std::list::iterator ite = parameterList.begin (); while (ite != parameterList.end ()) { - // Next iterator - std::set::iterator next = ite; + std::list::iterator next = ite; next++; - - // Property name ? if (ite->Name == "class") { - // Remove it - parameterList.erase (ite); + parameterList.erase(ite); } - ite = next; } - // Add the default parameter - NLLIGO::CPrimitiveClass::CParameter defaultParameter; - defaultParameter.Visible = true; - defaultParameter.Filename = false; + QtProperty *groupNode; + groupNode = m_groupManager->addProperty(QString("%1(%2)").arg(node->data(Qt::DisplayRole).toString()).arg(primClass->Name.c_str())); + m_ui.treePropertyBrowser->addProperty(groupNode); + + ite = parameterList.begin (); + while (ite != parameterList.end ()) + { + NLLIGO::CPrimitiveClass::CParameter ¶meter = (*ite); + QtProperty *prop; + NLLIGO::IProperty *ligoProperty; + primitive->getPropertyByName(parameter.Name.c_str(), ligoProperty); + + if (parameter.Type == NLLIGO::CPrimitiveClass::CParameter::ConstString) + prop = addConstStringProperty(ligoProperty, parameter, primitive); + else if (parameter.Type == NLLIGO::CPrimitiveClass::CParameter::String) + prop = addStringProperty(ligoProperty, parameter, primitive); + else if (parameter.Type == NLLIGO::CPrimitiveClass::CParameter::StringArray) + prop = addStringArrayProperty(ligoProperty, parameter, primitive); + else if (parameter.Type == NLLIGO::CPrimitiveClass::CParameter::ConstStringArray) + prop = addConstStringArrayProperty(ligoProperty, parameter, primitive); + else + // hmn? + prop = addBoolProperty(parameter, primitive); + + // Default value ? + if ((ligoProperty == NULL) || (ligoProperty->Default)) + prop->setModified(false); + else + prop->setModified(true); + + bool staticChildSelected = Utils::ligoConfig()->isStaticChild(*primitive); + if (parameter.ReadOnly || (staticChildSelected && (parameter.Name == "name"))) + prop->setEnabled(false); + + groupNode->addSubProperty(prop); + + ite++; + } +} + +QtProperty *PropertyEditorWidget::addBoolProperty(const NLLIGO::IProperty *property, + const NLLIGO::CPrimitiveClass::CParameter ¶meter, + const NLLIGO::IPrimitive *primitive) +{ + std::string value; + std::string name = parameter.Name.c_str(); + primitive->getPropertyByName(name.c_str(), value); + QtVariantProperty *prop = m_variantManager->addProperty(QVariant::Bool, name.c_str()); + // if (Default) + { + //DialogProperties->setDefaultValue (this, value); + prop->setValue(bool((value=="true")?1:0)); + } + return prop; +} + +QtProperty *PropertyEditorWidget::addConstStringProperty(const NLLIGO::IProperty *property, + const NLLIGO::CPrimitiveClass::CParameter ¶meter, + const NLLIGO::IPrimitive *primitive) +{ + std::string context("default"); + + std::string value; + std::string name = parameter.Name.c_str(); + primitive->getPropertyByName(name.c_str(), value); + QtProperty *prop = m_enumManager->addProperty(parameter.Name.c_str()); + + std::map::const_iterator ite = parameter.ComboValues.find(context.c_str()); + + // TODO + //if (ite != parameter.ComboValues.end()) + { + std::vector pathList; + { + ite->second.appendFilePath(pathList); + + /*std::vector relativePrimPaths; + { + std::vector startPrimPath; + for (uint locIndex = 0; locIndex<_PropDlgLocators.size(); locIndex++) + startPrimPath.push_back(_PropDlgLocators[locIndex].Primitive); + + ite->second.getPrimitivesForPrimPath(relativePrimPaths, startPrimPath); + } + ite->second.appendPrimPath(pathList, relativePrimPaths);*/ + } + + if (parameter.SortEntries) + std::sort(pathList.begin(), pathList.end()); + + int currentValue = 0; + QStringList listEnums; + for (size_t i = 0; i < pathList.size(); ++i) + { + listEnums.append(pathList[i].c_str()); + if (value == pathList[i]) + currentValue = i; + } + if (!pathList.empty()) + { + m_enumManager->setEnumNames(prop, listEnums); + m_enumManager->setValue(prop, currentValue); + } + } + return prop; +} + +QtProperty *PropertyEditorWidget::addStringProperty(const NLLIGO::IProperty *property, + const NLLIGO::CPrimitiveClass::CParameter ¶meter, + const NLLIGO::IPrimitive *primitive) +{ + std::string value; + std::string name = parameter.Name.c_str(); + primitive->getPropertyByName(name.c_str(), value); + QtVariantProperty *prop = m_variantManager->addProperty(QVariant::String, parameter.Name.c_str()); + prop->setValue(QString(value.c_str())); + return prop; +} + +QtProperty *PropertyEditorWidget::addStringArrayProperty(const NLLIGO::IProperty *property, + const NLLIGO::CPrimitiveClass::CParameter ¶meter, + const NLLIGO::IPrimitive *primitive) +{ + std::string name = parameter.Name.c_str(); + QtProperty *prop = m_stringArrayManager->addProperty(parameter.Name.c_str()); + + const NLLIGO::IProperty *ligoProperty; + std::vector vectString; + + if (primitive->getPropertyByName (parameter.Name.c_str (), ligoProperty)) + { + const NLLIGO::CPropertyStringArray *const propStringArray = dynamic_cast (ligoProperty); + if (propStringArray) + { + const std::vector &vectString = propStringArray->StringArray; + if (vectString.empty()) + { + //m_stringArrayManager->setValue(prop, "StringArray"); + } + else + { + std::string temp; + for (size_t i = 0; i < vectString.size(); i++) + { + temp += vectString[i]; + if (i != (vectString.size() - 1)) + temp += '\n'; + } + m_stringArrayManager->setValue(prop, temp.c_str()); + prop->setToolTip(temp.c_str()); + } + } + else + { + m_stringArrayManager->setValue(prop, "StringArray :("); + } + } + return prop; +} + +QtProperty *PropertyEditorWidget::addConstStringArrayProperty(const NLLIGO::IProperty *property, + const NLLIGO::CPrimitiveClass::CParameter ¶meter, + const NLLIGO::IPrimitive *primitive) +{ + std::string name = parameter.Name.c_str(); + QtVariantProperty *prop = m_variantManager->addProperty(QVariant::String, parameter.Name.c_str()); + prop->setValue("ConstStringArray"); + return prop; } } /* namespace WorldEditor */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/property_editor_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/property_editor_widget.h index 3a2506def..a4ccf9d5f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/property_editor_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/property_editor_widget.h @@ -51,14 +51,30 @@ public: public Q_SLOTS: void clearProperties(); - /// Update of selections - void updateSelection(const NodeList &selected, const NodeList &deselected); + /// Update of selections + void updateSelection(Node *node); private: + QtProperty *addBoolProperty(const NLLIGO::IProperty *property, + const NLLIGO::CPrimitiveClass::CParameter ¶meter, + const NLLIGO::IPrimitive *primitive); + QtProperty *addConstStringProperty(const NLLIGO::IProperty *property, + const NLLIGO::CPrimitiveClass::CParameter ¶meter, + const NLLIGO::IPrimitive *primitive); + QtProperty *addStringProperty(const NLLIGO::IProperty *property, + const NLLIGO::CPrimitiveClass::CParameter ¶meter, + const NLLIGO::IPrimitive *primitive); + QtProperty *addStringArrayProperty(const NLLIGO::IProperty *property, + const NLLIGO::CPrimitiveClass::CParameter ¶meter, + const NLLIGO::IPrimitive *primitive); + QtProperty *addConstStringArrayProperty(const NLLIGO::IProperty *property, + const NLLIGO::CPrimitiveClass::CParameter ¶meter, + const NLLIGO::IPrimitive *primitive); QtVariantPropertyManager *m_variantManager; QtEnumPropertyManager *m_enumManager; QtGroupPropertyManager *m_groupManager; + QtTextPropertyManager *m_stringArrayManager; Ui::PropertyEditorWidget m_ui; }; /* PropertyEditorWidget */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_constants.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_constants.h index d0617373e..7ca698697 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_constants.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_constants.h @@ -31,9 +31,14 @@ const int GRAPHICS_DATA_NEL3D = USER_TYPE + 4; const int PRIMITIVE_IS_MODIFIED = USER_TYPE + 5; const int PRIMITIVE_FILE_IS_CREATED = USER_TYPE + 6; const int PRIMITIVE_IS_VISIBLE = USER_TYPE + 7; +const int PRIMITIVE_IS_ENABLD = USER_TYPE + 8; +const int PRIMITIVE_FILE_NAME = USER_TYPE + 9; +const int PRIMITIVE_NON_REMOVABLE = USER_TYPE + 10; +const int ROOT_PRIMITIVE_CONTEXT = USER_TYPE + 20; +const int ROOT_PRIMITIVE_DATA_DIRECTORY = USER_TYPE + 21; //properties editor -const char *const DIFFERENT_VALUE_STRING = ""; +const char *const DIFFERENT_VALUE_STRING = ""; const char *const DIFFERENT_VALUE_MULTI_STRING = ""; //settings diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp index 9922daaf7..c58102ac2 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp @@ -274,7 +274,7 @@ void WorldEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) else m_editedSelectedItems = false; } - // Update render + // Update render (drawing selection area when enabled multiple selection mode) update(); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp index 30173b9d9..382b356c0 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp @@ -275,8 +275,16 @@ void WorldEditorWindow::updateSelection(const QItemSelection &selected, const QI nodesDeselected.push_back(node); } - // TODO: update property editor - m_ui.propertyEditWidget->updateSelection(nodesSelected, nodesDeselected); + // update property editor + if (nodesSelected.size() > 0) + { + // only single selection + m_ui.propertyEditWidget->updateSelection(nodesSelected.at(0)); + } + else + { + m_ui.propertyEditWidget->clearProperties(); + } QList itemSelected; Q_FOREACH(Node *node, nodesSelected) @@ -320,8 +328,17 @@ void WorldEditorWindow::selectedItemsInScene(const QList &selec selectionModel->select(itemSelection, QItemSelectionModel::Select); - // TODO: update property editor - // ... + // update property editor + if (!selected.isEmpty()) + { + // only single selection + Node *node = qvariant_cast(selected.at(0)->data(Constants::WORLD_EDITOR_NODE)); + m_ui.propertyEditWidget->updateSelection(node); + } + else + { + m_ui.propertyEditWidget->clearProperties(); + } connect(m_ui.treePrimitivesView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(updateSelection(QItemSelection, QItemSelection)));