Changed: #1302 Added preview properties (except ConstStringArray values).

This commit is contained in:
dnk-88 2012-02-05 02:31:56 +03:00
parent 83db0f0adf
commit 3c09ce3ee8
7 changed files with 287 additions and 88 deletions

View file

@ -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;

View file

@ -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;
};
/*

View file

@ -17,6 +17,7 @@
// Project includes
#include "property_editor_widget.h"
#include "world_editor_misc.h"
// NeL includes
#include <nel/misc/debug.h>
@ -38,13 +39,18 @@ 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);
}
@ -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<NLLIGO::CPrimitiveClass::CParameter> parameterList;
std::list<NLLIGO::CPrimitiveClass::CParameter> parameterList;
for (int i = 0; i < selected.size(); ++i)
PrimitiveNode *primNode = static_cast<PrimitiveNode *>(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<IPrimitive*>(_PropDlgLocators[i].Primitive)->removePropertyByName("name");
const_cast<IPrimitive*>(_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<IPrimitive*>(_PropDlgLocators[i].Primitive)->addPropertyByName("name",new CPropertyString (name));
const_cast<IPrimitive*>(_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<PrimitiveNode *>(selected.at(i));
const NLLIGO::IPrimitive *primitive = node->primitive();
const NLLIGO::CPrimitiveClass *primClass = node->primitiveClass();
// Get the property
std::string propertyName;
const NLLIGO::IProperty *prop;
nlverify(primitive->getProperty(p, propertyName, prop));
// Use the class or not ?
if (primClass)
{
QtProperty *groupNode;
groupNode = m_groupManager->addProperty(node->data(Qt::DisplayRole).toString());
m_ui.treePropertyBrowser->addProperty(groupNode);
// Add a default property
NLLIGO::CPrimitiveClass::CParameter defProp(*prop, propertyName.c_str());
// 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;
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());
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<NLLIGO::CPrimitiveClass::CParameter>::iterator ite = parameterList.begin ();
std::list<NLLIGO::CPrimitiveClass::CParameter>::iterator ite = parameterList.begin ();
while (ite != parameterList.end ())
{
// Next iterator
std::set<NLLIGO::CPrimitiveClass::CParameter>::iterator next = ite;
std::list<NLLIGO::CPrimitiveClass::CParameter>::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 &parameter = (*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 &parameter,
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 &parameter,
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<std::string, NLLIGO::CPrimitiveClass::CParameter::CConstStringValue>::const_iterator ite = parameter.ComboValues.find(context.c_str());
// TODO
//if (ite != parameter.ComboValues.end())
{
std::vector<std::string> pathList;
{
ite->second.appendFilePath(pathList);
/*std::vector<const NLLIGO::IPrimitive*> relativePrimPaths;
{
std::vector<const NLLIGO::IPrimitive*> 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 &parameter,
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 &parameter,
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<std::string> vectString;
if (primitive->getPropertyByName (parameter.Name.c_str (), ligoProperty))
{
const NLLIGO::CPropertyStringArray *const propStringArray = dynamic_cast<const NLLIGO::CPropertyStringArray *> (ligoProperty);
if (propStringArray)
{
const std::vector<std::string> &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 &parameter,
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 */

View file

@ -52,13 +52,29 @@ public Q_SLOTS:
void clearProperties();
/// Update of selections
void updateSelection(const NodeList &selected, const NodeList &deselected);
void updateSelection(Node *node);
private:
QtProperty *addBoolProperty(const NLLIGO::IProperty *property,
const NLLIGO::CPrimitiveClass::CParameter &parameter,
const NLLIGO::IPrimitive *primitive);
QtProperty *addConstStringProperty(const NLLIGO::IProperty *property,
const NLLIGO::CPrimitiveClass::CParameter &parameter,
const NLLIGO::IPrimitive *primitive);
QtProperty *addStringProperty(const NLLIGO::IProperty *property,
const NLLIGO::CPrimitiveClass::CParameter &parameter,
const NLLIGO::IPrimitive *primitive);
QtProperty *addStringArrayProperty(const NLLIGO::IProperty *property,
const NLLIGO::CPrimitiveClass::CParameter &parameter,
const NLLIGO::IPrimitive *primitive);
QtProperty *addConstStringArrayProperty(const NLLIGO::IProperty *property,
const NLLIGO::CPrimitiveClass::CParameter &parameter,
const NLLIGO::IPrimitive *primitive);
QtVariantPropertyManager *m_variantManager;
QtEnumPropertyManager *m_enumManager;
QtGroupPropertyManager *m_groupManager;
QtTextPropertyManager *m_stringArrayManager;
Ui::PropertyEditorWidget m_ui;
}; /* PropertyEditorWidget */

View file

@ -31,6 +31,11 @@ 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 = "<different values>";

View file

@ -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();
}

View file

@ -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<QGraphicsItem *> itemSelected;
Q_FOREACH(Node *node, nodesSelected)
@ -320,8 +328,17 @@ void WorldEditorWindow::selectedItemsInScene(const QList<QGraphicsItem *> &selec
selectionModel->select(itemSelection, QItemSelectionModel::Select);
// TODO: update property editor
// ...
// update property editor
if (!selected.isEmpty())
{
// only single selection
Node *node = qvariant_cast<Node *>(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)));