Changed: #1302 Added initial database of primitives (model/view) (loading of *. primitive file)
--HG-- branch : gsoc2011-worldeditorqthg/feature/sse2
parent
2baa68b89c
commit
29f78e79fe
@ -0,0 +1,145 @@
|
||||
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Project includes
|
||||
#include "primitive_item.h"
|
||||
|
||||
// Qt includes
|
||||
#include <QStringList>
|
||||
|
||||
namespace WorldEditor
|
||||
{
|
||||
|
||||
BaseTreeItem::BaseTreeItem(BaseTreeItem *parent)
|
||||
{
|
||||
m_parentItem = parent;
|
||||
m_itemData << QIcon() << "" << "" << "";
|
||||
}
|
||||
|
||||
BaseTreeItem::BaseTreeItem(const QList<QVariant> &data, BaseTreeItem *parent)
|
||||
{
|
||||
m_parentItem = parent;
|
||||
m_itemData = data;
|
||||
}
|
||||
|
||||
BaseTreeItem::~BaseTreeItem()
|
||||
{
|
||||
qDeleteAll(m_childItems);
|
||||
}
|
||||
|
||||
void BaseTreeItem::appendChild(BaseTreeItem *item)
|
||||
{
|
||||
m_childItems.append(item);
|
||||
}
|
||||
|
||||
BaseTreeItem *BaseTreeItem::child(int row)
|
||||
{
|
||||
return m_childItems.value(row);
|
||||
}
|
||||
|
||||
int BaseTreeItem::childCount() const
|
||||
{
|
||||
return m_childItems.count();
|
||||
}
|
||||
|
||||
int BaseTreeItem::columnCount() const
|
||||
{
|
||||
return m_itemData.count();
|
||||
}
|
||||
|
||||
QVariant BaseTreeItem::data(int column) const
|
||||
{
|
||||
return m_itemData.value(column);
|
||||
}
|
||||
|
||||
void BaseTreeItem::setData(int column, const QVariant &data)
|
||||
{
|
||||
m_itemData[column] = data;
|
||||
}
|
||||
|
||||
BaseTreeItem *BaseTreeItem::parent()
|
||||
{
|
||||
return m_parentItem;
|
||||
}
|
||||
|
||||
int BaseTreeItem::row() const
|
||||
{
|
||||
if (m_parentItem)
|
||||
return m_parentItem->m_childItems.indexOf(const_cast<BaseTreeItem *>(this));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BaseTreeItem::setModified(bool value)
|
||||
{
|
||||
m_modified = value;
|
||||
}
|
||||
|
||||
bool BaseTreeItem::isModified() const
|
||||
{
|
||||
return m_modified;
|
||||
}
|
||||
|
||||
PrimitiveItem::PrimitiveItem(NLLIGO::IPrimitive *primitive, BaseTreeItem *parent)
|
||||
: BaseTreeItem(parent),
|
||||
m_primitive(primitive)
|
||||
{
|
||||
setData(1, QString(m_primitive->getName().c_str()));
|
||||
setData(2, QString(m_primitive->getClassName().c_str()));
|
||||
|
||||
std::string className;
|
||||
m_primitive->getPropertyByName("class", className);
|
||||
|
||||
// Set Icon
|
||||
QIcon icon(QString("./old_ico/%1.ico").arg(className.c_str()));
|
||||
if (primitive->getParent() == NULL)
|
||||
icon = QIcon("./old_ico/root.ico");
|
||||
if (icon.isNull())
|
||||
{
|
||||
if (primitive->getNumChildren() == 0)
|
||||
icon = QIcon("./old_ico/property.ico");
|
||||
else
|
||||
icon = QIcon("./old_ico/folder_h.ico");
|
||||
}
|
||||
setData(0, icon);
|
||||
|
||||
setData(3, QString(className.c_str()));
|
||||
}
|
||||
/*
|
||||
PrimitiveItem::PrimitiveItem(const PrimitiveItem &other)
|
||||
{
|
||||
}
|
||||
*/
|
||||
PrimitiveItem::~PrimitiveItem()
|
||||
{
|
||||
}
|
||||
|
||||
PrimitivesItem::PrimitivesItem(const QString &name, NLLIGO::CPrimitives *primitives, BaseTreeItem *parent)
|
||||
: PrimitiveItem(primitives->RootNode, parent),
|
||||
m_primitives(primitives)
|
||||
{
|
||||
setData(1, name);
|
||||
}
|
||||
/*
|
||||
PrimitivesItem::PrimitivesItem(const PrimitiveItem &other)
|
||||
{
|
||||
}
|
||||
*/
|
||||
PrimitivesItem::~PrimitivesItem()
|
||||
{
|
||||
}
|
||||
|
||||
} /* namespace WorldEditor */
|
@ -0,0 +1,99 @@
|
||||
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef PRIMITIVE_ITEM_H
|
||||
#define PRIMITIVE_ITEM_H
|
||||
|
||||
// Project includes
|
||||
|
||||
// NeL includes
|
||||
#include <nel/ligo/primitive.h>
|
||||
|
||||
// Qt includes
|
||||
#include <QList>
|
||||
#include <QIcon>
|
||||
#include <QVariant>
|
||||
|
||||
namespace WorldEditor
|
||||
{
|
||||
|
||||
/*
|
||||
@class BaseTreeItem
|
||||
@brief
|
||||
@details
|
||||
*/
|
||||
class BaseTreeItem
|
||||
{
|
||||
public:
|
||||
BaseTreeItem(BaseTreeItem *parent = 0);
|
||||
BaseTreeItem(const QList<QVariant> &data, BaseTreeItem *parent = 0);
|
||||
virtual ~BaseTreeItem();
|
||||
|
||||
void appendChild(BaseTreeItem *child);
|
||||
|
||||
BaseTreeItem *child(int row);
|
||||
int childCount() const;
|
||||
int columnCount() const;
|
||||
QVariant data(int column) const;
|
||||
void setData(int column, const QVariant &data);
|
||||
int row() const;
|
||||
BaseTreeItem *parent();
|
||||
void setModified(bool value);
|
||||
bool isModified() const;
|
||||
|
||||
private:
|
||||
|
||||
bool m_modified;
|
||||
QList<BaseTreeItem *> m_childItems;
|
||||
QList<QVariant> m_itemData;
|
||||
BaseTreeItem *m_parentItem;
|
||||
};
|
||||
|
||||
/*
|
||||
@class PrimitiveItem
|
||||
@brief
|
||||
@details
|
||||
*/
|
||||
class PrimitiveItem: public BaseTreeItem
|
||||
{
|
||||
public:
|
||||
PrimitiveItem(NLLIGO::IPrimitive *primitive, BaseTreeItem *parent);
|
||||
PrimitiveItem(const PrimitiveItem &other);
|
||||
virtual ~PrimitiveItem();
|
||||
|
||||
private:
|
||||
NLLIGO::IPrimitive *m_primitive;
|
||||
};
|
||||
|
||||
/*
|
||||
@class PrimitivesItem
|
||||
@brief
|
||||
@details
|
||||
*/
|
||||
class PrimitivesItem: public PrimitiveItem
|
||||
{
|
||||
public:
|
||||
PrimitivesItem(const QString &name, NLLIGO::CPrimitives *primitives, BaseTreeItem *parent);
|
||||
PrimitivesItem(const PrimitiveItem &other);
|
||||
virtual ~PrimitivesItem();
|
||||
|
||||
private:
|
||||
NLLIGO::CPrimitives *m_primitives;
|
||||
};
|
||||
|
||||
} /* namespace WorldEditor */
|
||||
|
||||
#endif // PRIMITIVE_ITEM_H
|
@ -0,0 +1,172 @@
|
||||
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <nel/ligo/primitive.h>
|
||||
#include <nel/ligo/ligo_config.h>
|
||||
#include <nel/ligo/primitive_class.h>
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "primitive_item.h"
|
||||
#include "primitives_model.h"
|
||||
|
||||
namespace WorldEditor
|
||||
{
|
||||
|
||||
PrimitivesTreeModel::PrimitivesTreeModel(QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
{
|
||||
QList<QVariant> rootData;
|
||||
rootData << "Name" << "Class" << "Class";
|
||||
m_rootItem = new BaseTreeItem(rootData);
|
||||
}
|
||||
|
||||
PrimitivesTreeModel::~PrimitivesTreeModel()
|
||||
{
|
||||
delete m_rootItem;
|
||||
}
|
||||
|
||||
int PrimitivesTreeModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return static_cast<BaseTreeItem *>(parent.internalPointer())->columnCount();
|
||||
else
|
||||
return m_rootItem->columnCount();
|
||||
}
|
||||
|
||||
QVariant PrimitivesTreeModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
BaseTreeItem *item = static_cast<BaseTreeItem *>(index.internalPointer());
|
||||
switch (role)
|
||||
{
|
||||
// case Qt::TextAlignmentRole:
|
||||
// return int(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
case Qt::DisplayRole:
|
||||
return item->data(index.column() + 1);
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
if (index.column() == 0)
|
||||
return qVariantFromValue(item->data(0));
|
||||
else
|
||||
return QVariant();
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
Qt::ItemFlags PrimitivesTreeModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
QVariant PrimitivesTreeModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
return m_rootItem->data(section);
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QModelIndex PrimitivesTreeModel::index(int row, int column, const QModelIndex &parent)
|
||||
const
|
||||
{
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
|
||||
BaseTreeItem *parentItem;
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = m_rootItem;
|
||||
else
|
||||
parentItem = static_cast<BaseTreeItem *>(parent.internalPointer());
|
||||
|
||||
BaseTreeItem *childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex PrimitivesTreeModel::parent(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
BaseTreeItem *childItem = static_cast<BaseTreeItem *>(index.internalPointer());
|
||||
BaseTreeItem *parentItem = childItem->parent();
|
||||
|
||||
if (parentItem == m_rootItem)
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
|
||||
int PrimitivesTreeModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
BaseTreeItem *parentItem;
|
||||
if (parent.column() > 0)
|
||||
return 0;
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = m_rootItem;
|
||||
else
|
||||
parentItem = static_cast<BaseTreeItem *>(parent.internalPointer());
|
||||
|
||||
return parentItem->childCount();
|
||||
}
|
||||
|
||||
void PrimitivesTreeModel::addPrimitives(const QString &name, NLLIGO::CPrimitives *primitives)
|
||||
{
|
||||
beginResetModel();
|
||||
PrimitivesItem *newPrimitives = new PrimitivesItem(name, primitives, m_rootItem);
|
||||
m_rootItem->appendChild(newPrimitives);
|
||||
for (uint i = 0; i < primitives->RootNode->getNumChildren(); ++i)
|
||||
{
|
||||
NLLIGO::IPrimitive *childPrim;
|
||||
primitives->RootNode->getChild(childPrim, i);
|
||||
scanPrimitive(childPrim, newPrimitives);
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void PrimitivesTreeModel::scanPrimitive(NLLIGO::IPrimitive *prim, BaseTreeItem *parent)
|
||||
{
|
||||
// const NLLIGO::CPrimitiveClass *primClass = NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig->getPrimitiveClass(*prim);
|
||||
// nlassert (primClass);
|
||||
// if (primClass->Type == NLLIGO::CPrimitiveClass::Alias)
|
||||
// return;
|
||||
if (prim->getClassName() == "CPrimAlias")
|
||||
return;
|
||||
|
||||
PrimitiveItem *newItem = new PrimitiveItem(prim, parent);
|
||||
parent->appendChild(newItem);
|
||||
for (uint i = 0; i < prim->getNumChildren(); ++i)
|
||||
{
|
||||
NLLIGO::IPrimitive *childPrim;
|
||||
prim->getChild(childPrim, i);
|
||||
scanPrimitive(childPrim, newItem);
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace WorldEditor */
|
@ -0,0 +1,65 @@
|
||||
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef PRIMITIVES_MODEL_H
|
||||
#define PRIMITIVES_MODEL_H
|
||||
|
||||
#include <nel/ligo/primitive.h>
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QModelIndex>
|
||||
#include <QVariant>
|
||||
|
||||
namespace WorldEditor
|
||||
{
|
||||
|
||||
class BaseTreeItem;
|
||||
|
||||
/**
|
||||
@class PrimitivesTreeModel
|
||||
@brief
|
||||
@details
|
||||
*/
|
||||
class PrimitivesTreeModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PrimitivesTreeModel(QObject *parent = 0);
|
||||
~PrimitivesTreeModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
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;
|
||||
|
||||
void addPrimitives(const QString &name, NLLIGO::CPrimitives *primitives);
|
||||
|
||||
private:
|
||||
void scanPrimitive(NLLIGO::IPrimitive *prim, BaseTreeItem *parent = 0);
|
||||
|
||||
BaseTreeItem *m_rootItem;
|
||||
};
|
||||
|
||||
} /* namespace WorldEditor */
|
||||
|
||||
#endif // PRIMITIVES_MODEL_H
|
@ -0,0 +1,47 @@
|
||||
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Project includes
|
||||
#include "world_editor_actions.h"
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/debug.h>
|
||||
|
||||
// Qt includes
|
||||
|
||||
namespace WorldEditor
|
||||
{
|
||||
|
||||
OpenLandscapeCommand::OpenLandscapeCommand(const QString &fileName, QUndoCommand *parent)
|
||||
: QUndoCommand(parent),
|
||||
m_fileName(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
OpenLandscapeCommand::~OpenLandscapeCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void OpenLandscapeCommand::undo()
|
||||
{
|
||||
}
|
||||
|
||||
void OpenLandscapeCommand::redo()
|
||||
{
|
||||
}
|
||||
|
||||
} /* namespace WorldEditor */
|
@ -0,0 +1,48 @@
|
||||
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef WORLD_EDITOR_ACTIONS_H
|
||||
#define WORLD_EDITOR_ACTIONS_H
|
||||
|
||||
// Project includes
|
||||
|
||||
// NeL includes
|
||||
|
||||
// Qt includes
|
||||
#include <QtGui/QUndoCommand>
|
||||
#include <QtGui/QGraphicsScene>
|
||||
#include <QtGui/QGraphicsItem>
|
||||
|
||||
namespace WorldEditor
|
||||
{
|
||||
|
||||
class OpenLandscapeCommand: public QUndoCommand
|
||||
{
|
||||
public:
|
||||
OpenLandscapeCommand(const QString &fileName, QUndoCommand *parent = 0);
|
||||
virtual ~OpenLandscapeCommand();
|
||||
|
||||
virtual void undo();
|
||||
virtual void redo();
|
||||
private:
|
||||
|
||||
QString m_fileName;
|
||||
};
|
||||
|
||||
} /* namespace WorldEditor */
|
||||
|
||||
#endif // WORLD_EDITOR_ACTIONS_H
|
Loading…
Reference in New Issue