Changed: #1302 Added "unload primitive" and "unload landscape" undo command. Update doxygen comments.

--HG--
branch : gsoc2011-worldeditorqt
hg/feature/sse2
dnk-88 13 years ago
parent 3ccb85e0a4
commit 0c8bbd7e5b

@ -399,7 +399,7 @@ QString ZoneBuilder::dataPath() const
bool ZoneBuilder::getZoneMask(sint32 x, sint32 y) bool ZoneBuilder::getZoneMask(sint32 x, sint32 y)
{ {
if ((x < m_minX) || (x > m_maxX) || if ((x < m_minX) || (x > m_maxX) ||
(y < m_minY) || (y > m_maxY)) (y < m_minY) || (y > m_maxY))
return true; return true;
else else
return m_zoneMask[(x - m_minX) + (y - m_minY) * (1 + m_maxX - m_minX)]; return m_zoneMask[(x - m_minX) + (y - m_minY) * (1 + m_maxX - m_minX)];

@ -178,7 +178,9 @@ Node::NodeType WorldEditNode::type() const
return WorldEditNodeType; return WorldEditNodeType;
} }
LandscapeNode::LandscapeNode(const QString &name) LandscapeNode::LandscapeNode(const QString &name, int id)
: m_id(id),
m_fileName(name)
{ {
setData(Qt::DisplayRole, name); setData(Qt::DisplayRole, name);
setData(Qt::DecorationRole, QIcon(LandscapeEditor::Constants::ICON_ZONE_ITEM)); setData(Qt::DecorationRole, QIcon(LandscapeEditor::Constants::ICON_ZONE_ITEM));
@ -188,6 +190,16 @@ LandscapeNode::~LandscapeNode()
{ {
} }
QString LandscapeNode::fileName() const
{
return m_fileName;
}
int LandscapeNode::id() const
{
return m_id;
}
Node::NodeType LandscapeNode::type() const Node::NodeType LandscapeNode::type() const
{ {
return LandscapeNodeType; return LandscapeNodeType;

@ -128,12 +128,18 @@ private:
class LandscapeNode: public Node class LandscapeNode: public Node
{ {
public: public:
LandscapeNode(const QString &name); LandscapeNode(const QString &name, int id);
virtual ~LandscapeNode(); virtual ~LandscapeNode();
int id() const;
QString fileName() const;
virtual NodeType type() const; virtual NodeType type() const;
private: private:
QString m_fileName;
int m_id;
}; };
/* /*

@ -200,17 +200,29 @@ void PrimitivesTreeModel::deleteWorldEditNode()
endResetModel(); endResetModel();
} }
Path PrimitivesTreeModel::createLandscapeNode(const QString &fileName) bool PrimitivesTreeModel::isWorldEditNodeLoaded() const
{
if (m_worldEditNode == 0)
return false;
else
return true;
}
Path PrimitivesTreeModel::createLandscapeNode(const QString &fileName, int id, int pos)
{ {
if (m_worldEditNode == 0) if (m_worldEditNode == 0)
createWorldEditNode("NewWorldEdit"); createWorldEditNode("NewWorldEdit");
QModelIndex parentIndex = index(0, 0, QModelIndex()); QModelIndex parentIndex = index(0, 0, QModelIndex());
beginInsertRows(parentIndex, 0, 0); int insPos = pos;
LandscapeNode *newNode = new LandscapeNode(fileName); if (pos == -1)
m_worldEditNode->prependChildNode(newNode); insPos = 0;
beginInsertRows(parentIndex, insPos, insPos);
LandscapeNode *newNode = new LandscapeNode(fileName, id);
m_worldEditNode->insertChildNode(insPos, newNode);
endInsertRows(); endInsertRows();
return pathFromIndex(index(0, 0, index(0, 0, QModelIndex()))); return pathFromIndex(index(0, 0, index(insPos, 0, QModelIndex())));
} }

@ -69,18 +69,17 @@ public:
/// Convert QModelIndex to the persistent index - @Path. /// Convert QModelIndex to the persistent index - @Path.
/// @Path is a list of [row,column] pairs showing us the way through the model. /// @Path is a list of [row,column] pairs showing us the way through the model.
Path pathFromIndex(const QModelIndex &index); Path pathFromIndex(const QModelIndex &index);
Path pathFromNode(Node *node);
QModelIndex pathToIndex(const Path &path); QModelIndex pathToIndex(const Path &path);
Path pathFromNode(Node *node);
Node *pathToNode(const Path &path); Node *pathToNode(const Path &path);
void createWorldEditNode(const QString &fileName); void createWorldEditNode(const QString &fileName);
void deleteWorldEditNode(); void deleteWorldEditNode();
bool isWorldEditNodeLoaded() const;
/// Add new landscape node in tree model. /// Add new landscape node in tree model.
Path createLandscapeNode(const QString &fileName); Path createLandscapeNode(const QString &fileName, int id, int pos = AtTheEnd);
/// Add new root primitive node and all sub-primitives in the tree model. /// Add new root primitive node and all sub-primitives in the tree model.
Path createRootPrimitiveNode(const QString &fileName, NLLIGO::CPrimitives *primitives, int pos = AtTheEnd); Path createRootPrimitiveNode(const QString &fileName, NLLIGO::CPrimitives *primitives, int pos = AtTheEnd);

@ -33,6 +33,7 @@
// Qt includes // Qt includes
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QMessageBox> #include <QMessageBox>
#include <QApplication>
#include <QtGui/QMenu> #include <QtGui/QMenu>
#include <QtGui/QFileDialog> #include <QtGui/QFileDialog>
@ -49,7 +50,6 @@ PrimitivesView::PrimitivesView(QWidget *parent)
setContextMenuPolicy(Qt::DefaultContextMenu); setContextMenuPolicy(Qt::DefaultContextMenu);
m_unloadAction = new QAction("Unload", this); m_unloadAction = new QAction("Unload", this);
m_unloadAction->setEnabled(false);
m_saveAction = new QAction("Save", this); m_saveAction = new QAction("Save", this);
m_saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); m_saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE));
@ -66,7 +66,6 @@ PrimitivesView::PrimitivesView(QWidget *parent)
m_newPrimitiveAction = new QAction("New primitive", this); m_newPrimitiveAction = new QAction("New primitive", this);
m_deleteAction = new QAction("Delete", this); m_deleteAction = new QAction("Delete", this);
//m_deleteAction->setEnabled(false);
m_selectChildrenAction = new QAction("Select children", this); m_selectChildrenAction = new QAction("Select children", this);
@ -86,6 +85,9 @@ PrimitivesView::PrimitivesView(QWidget *parent)
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deletePrimitives())); connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deletePrimitives()));
connect(m_saveAction, SIGNAL(triggered()), this, SLOT(save())); connect(m_saveAction, SIGNAL(triggered()), this, SLOT(save()));
connect(m_saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs())); connect(m_saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs()));
connect(m_unloadAction, SIGNAL(triggered()), this, SLOT(unload()));
connect(m_showAction, SIGNAL(triggered()), this, SLOT(showPrimitive()));
connect(m_hideAction, SIGNAL(triggered()), this, SLOT(hidePrimitive()));
#ifdef Q_OS_DARWIN #ifdef Q_OS_DARWIN
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
@ -186,7 +188,10 @@ void PrimitivesView::selectChildren()
QModelIndex parentIndex = indexList.first(); QModelIndex parentIndex = indexList.first();
selectionModel()->clearSelection(); selectionModel()->clearSelection();
selectChildren(parentIndex);
QItemSelection itemSelection;
selectChildren(parentIndex, itemSelection);
selectionModel()->select(itemSelection, QItemSelectionModel::Select);
} }
void PrimitivesView::save() void PrimitivesView::save()
@ -253,6 +258,41 @@ void PrimitivesView::deletePrimitives()
} }
void PrimitivesView::unload()
{
nlassert(m_undoStack);
nlassert(m_primitivesTreeModel);
QModelIndexList indexList = selectionModel()->selectedRows();
QModelIndex index = indexList.first();
Node *node = static_cast<Node *>(index.internalPointer());
switch (node->type())
{
case Node::WorldEditNodeType:
{
break;
}
case Node::LandscapeNodeType:
{
m_undoStack->push(new UnloadLandscapeCommand(index, m_primitivesTreeModel, m_zoneBuilder));
break;
}
case Node::RootPrimitiveNodeType:
{
m_undoStack->push(new UnloadRootPrimitiveCommand(index, m_worldEditorScene, m_primitivesTreeModel, this));
break;
}
}
}
void PrimitivesView::showPrimitive()
{
}
void PrimitivesView::hidePrimitive()
{
}
void PrimitivesView::addNewPrimitiveByClass(int value) void PrimitivesView::addNewPrimitiveByClass(int value)
{ {
nlassert(m_undoStack); nlassert(m_undoStack);
@ -311,21 +351,24 @@ void PrimitivesView::contextMenuEvent(QContextMenuEvent *event)
event->accept(); event->accept();
} }
void PrimitivesView::selectChildren(const QModelIndex &parent) void PrimitivesView::selectChildren(const QModelIndex &parent, QItemSelection &itemSelection)
{ {
const int rowCount = model()->rowCount(parent); const int rowCount = model()->rowCount(parent);
QItemSelection mergeItemSelection(parent.child(0, 0), parent.child(rowCount - 1, 0));
itemSelection.merge(mergeItemSelection, QItemSelectionModel::Select);
for (int i = 0; i < rowCount; ++i) for (int i = 0; i < rowCount; ++i)
{ {
QModelIndex childIndex = parent.child(i, 0); QModelIndex childIndex = parent.child(i, 0);
selectionModel()->select(childIndex, QItemSelectionModel::Select); if (model()->rowCount(childIndex) != 0)
selectChildren(childIndex); selectChildren(childIndex, itemSelection);
} }
} }
void PrimitivesView::fillMenu_WorldEdit(QMenu *menu) void PrimitivesView::fillMenu_WorldEdit(QMenu *menu)
{ {
menu->addAction(m_unloadAction); //menu->addAction(m_unloadAction);
//menu->addAction(m_saveAction); //menu->addAction(m_saveAction);
//menu->addAction(m_saveAsAction); //menu->addAction(m_saveAsAction);
menu->addSeparator(); menu->addSeparator();

@ -70,6 +70,9 @@ private Q_SLOTS:
void save(); void save();
void saveAs(); void saveAs();
void deletePrimitives(); void deletePrimitives();
void unload();
void showPrimitive();
void hidePrimitive();
void addNewPrimitiveByClass(int value); void addNewPrimitiveByClass(int value);
void generatePrimitives(int value); void generatePrimitives(int value);
void openItem(int value); void openItem(int value);
@ -78,7 +81,7 @@ protected:
void contextMenuEvent(QContextMenuEvent *event); void contextMenuEvent(QContextMenuEvent *event);
private: private:
void selectChildren(const QModelIndex &parent); void selectChildren(const QModelIndex &parent, QItemSelection &itemSelection);
void fillMenu_WorldEdit(QMenu *menu); void fillMenu_WorldEdit(QMenu *menu);
void fillMenu_Landscape(QMenu *menu); void fillMenu_Landscape(QMenu *menu);
void fillMenu_RootPrimitive(QMenu *menu, const QModelIndex &index); void fillMenu_RootPrimitive(QMenu *menu, const QModelIndex &index);

@ -16,12 +16,14 @@
// Project includes // Project includes
#include "project_settings_dialog.h" #include "project_settings_dialog.h"
#include "world_editor_misc.h"
#include "../core/icore.h" #include "../core/icore.h"
#include "../core/core_constants.h" #include "../core/core_constants.h"
// NeL includes // NeL includes
#include <nel/misc/debug.h> #include <nel/misc/debug.h>
#include <nel/ligo/ligo_config.h>
// Qt includes // Qt includes
#include <QtCore/QSettings> #include <QtCore/QSettings>
@ -36,6 +38,13 @@ ProjectSettingsDialog::ProjectSettingsDialog(const QString &dataPath, QWidget *p
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
m_ui.pathLineEdit->setText(dataPath); m_ui.pathLineEdit->setText(dataPath);
m_ui.contextComboBox->addItem("empty");
// Init the combo box
const std::vector<std::string> &contexts = Utils::ligoConfig()->getContextString();
for (uint i = 0; i < contexts.size(); i++)
m_ui.contextComboBox->addItem(QString(contexts[i].c_str()));
setFixedHeight(sizeHint().height()); setFixedHeight(sizeHint().height());
connect(m_ui.selectPathButton, SIGNAL(clicked()), this, SLOT(selectPath())); connect(m_ui.selectPathButton, SIGNAL(clicked()), this, SLOT(selectPath()));
} }

@ -218,7 +218,7 @@ CreateWorldCommand::CreateWorldCommand(const QString &fileName, PrimitivesTreeMo
m_fileName(fileName), m_fileName(fileName),
m_model(model) m_model(model)
{ {
setText("Create new world"); setText(QObject::tr("Create new world"));
} }
CreateWorldCommand::~CreateWorldCommand() CreateWorldCommand::~CreateWorldCommand()
@ -243,7 +243,7 @@ LoadLandscapeCommand::LoadLandscapeCommand(const QString &fileName, PrimitivesTr
m_model(model), m_model(model),
m_zoneBuilder(zoneBuilder) m_zoneBuilder(zoneBuilder)
{ {
setText("Load land file"); setText(QObject::tr("Load land file"));
} }
LoadLandscapeCommand::~LoadLandscapeCommand() LoadLandscapeCommand::~LoadLandscapeCommand()
@ -263,7 +263,41 @@ void LoadLandscapeCommand::redo()
else else
m_zoneBuilder->loadZoneRegion(m_fileName, m_id); m_zoneBuilder->loadZoneRegion(m_fileName, m_id);
landIndex = m_model->createLandscapeNode(m_fileName); landIndex = m_model->createLandscapeNode(m_fileName, m_id);
}
UnloadLandscapeCommand::UnloadLandscapeCommand(const QModelIndex &index, PrimitivesTreeModel *model,
LandscapeEditor::ZoneBuilderBase *zoneBuilder, QUndoCommand *parent)
: QUndoCommand(parent),
m_model(model),
m_zoneBuilder(zoneBuilder)
{
setText(QObject::tr("Unload land file"));
m_path = m_model->pathFromIndex(index);
}
UnloadLandscapeCommand::~UnloadLandscapeCommand()
{
}
void UnloadLandscapeCommand::undo()
{
m_zoneBuilder->loadZoneRegion(m_fileName, m_id);
m_model->createLandscapeNode(m_fileName, m_id, m_path.back().first);
}
void UnloadLandscapeCommand::redo()
{
QModelIndex index = m_model->pathToIndex(m_path);
LandscapeNode *node = static_cast<LandscapeNode *>(index.internalPointer());
m_id = node->id();
m_fileName = node->fileName();
m_zoneBuilder->deleteZoneRegion(m_id);
m_model->deleteNode(m_path);
} }
CreateRootPrimitiveCommand::CreateRootPrimitiveCommand(const QString &fileName, PrimitivesTreeModel *model, QUndoCommand *parent) CreateRootPrimitiveCommand::CreateRootPrimitiveCommand(const QString &fileName, PrimitivesTreeModel *model, QUndoCommand *parent)
@ -271,7 +305,7 @@ CreateRootPrimitiveCommand::CreateRootPrimitiveCommand(const QString &fileName,
m_fileName(fileName), m_fileName(fileName),
m_model(model) m_model(model)
{ {
setText("Create new primitive"); setText(QObject::tr("Create new primitive"));
} }
CreateRootPrimitiveCommand::~CreateRootPrimitiveCommand() CreateRootPrimitiveCommand::~CreateRootPrimitiveCommand()
@ -304,7 +338,7 @@ LoadRootPrimitiveCommand::LoadRootPrimitiveCommand(const QString &fileName, Worl
m_model(model), m_model(model),
m_view(view) m_view(view)
{ {
setText("Load primitive file"); setText(QObject::tr("Load primitive file"));
} }
LoadRootPrimitiveCommand::~LoadRootPrimitiveCommand() LoadRootPrimitiveCommand::~LoadRootPrimitiveCommand()
@ -358,6 +392,47 @@ void LoadRootPrimitiveCommand::redo()
addNewGraphicsItems(m_model->pathToIndex(m_rootPrimIndex), m_model, m_scene); addNewGraphicsItems(m_model->pathToIndex(m_rootPrimIndex), m_model, m_scene);
} }
UnloadRootPrimitiveCommand::UnloadRootPrimitiveCommand(const QModelIndex &index, WorldEditorScene *scene,
PrimitivesTreeModel *model, QTreeView *view, QUndoCommand *parent)
: QUndoCommand(parent),
m_scene(scene),
m_model(model),
m_view(view)
{
setText(QObject::tr("Unload primitive file"));
m_path = m_model->pathFromIndex(index);
}
UnloadRootPrimitiveCommand::~UnloadRootPrimitiveCommand()
{
}
void UnloadRootPrimitiveCommand::undo()
{
// Disable edit points mode
m_scene->setEnabledEditPoints(false);
m_path = m_model->createRootPrimitiveNode(m_fileName, m_primitives, m_path.back().first);
addNewGraphicsItems(m_model->pathToIndex(m_path), m_model, m_scene);
}
void UnloadRootPrimitiveCommand::redo()
{
m_scene->setEnabledEditPoints(false);
m_view->selectionModel()->clearSelection();
QModelIndex index = m_model->pathToIndex(m_path);
RootPrimitiveNode *node = static_cast<RootPrimitiveNode *>(index.internalPointer());
m_fileName = node->fileName();
m_primitives = node->primitives();
removeGraphicsItems(index, m_model, m_scene);
m_model->deleteNode(m_path);
}
AddPrimitiveByClassCommand::AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex, AddPrimitiveByClassCommand::AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex,
WorldEditorScene *scene, PrimitivesTreeModel *model, QTreeView *view, QUndoCommand *parent) WorldEditorScene *scene, PrimitivesTreeModel *model, QTreeView *view, QUndoCommand *parent)
: QUndoCommand(parent), : QUndoCommand(parent),
@ -367,7 +442,7 @@ AddPrimitiveByClassCommand::AddPrimitiveByClassCommand(const QString &className,
m_model(model), m_model(model),
m_view(view) m_view(view)
{ {
setText(QString("Add %1").arg(m_className)); setText(QObject::tr("Add %1").arg(m_className));
QGraphicsView *graphicsView = m_scene->views().first(); QGraphicsView *graphicsView = m_scene->views().first();
@ -437,7 +512,7 @@ DeletePrimitiveCommand::DeletePrimitiveCommand(const QModelIndex &index, Primiti
m_model(model), m_model(model),
m_view(view) m_view(view)
{ {
setText("Delete primitive"); setText(QObject::tr("Delete primitive"));
// Save path to primitive // Save path to primitive
m_path = m_model->pathFromIndex(index); m_path = m_model->pathFromIndex(index);
@ -629,7 +704,7 @@ MoveWorldItemsCommand::MoveWorldItemsCommand(const QList<QGraphicsItem *> &items
: AbstractWorldItemCommand(items, scene, model, parent), : AbstractWorldItemCommand(items, scene, model, parent),
m_offset(offset) m_offset(offset)
{ {
setText("Move item(s)"); setText(QObject::tr("Move item(s)"));
} }
MoveWorldItemsCommand::~MoveWorldItemsCommand() MoveWorldItemsCommand::~MoveWorldItemsCommand()
@ -652,7 +727,7 @@ RotateWorldItemsCommand::RotateWorldItemsCommand(const QList<QGraphicsItem *> &i
m_angle(angle), m_angle(angle),
m_pivot(pivot) m_pivot(pivot)
{ {
setText("Rotate item(s)"); setText(QObject::tr("Rotate item(s)"));
} }
RotateWorldItemsCommand::~RotateWorldItemsCommand() RotateWorldItemsCommand::~RotateWorldItemsCommand()
@ -675,7 +750,7 @@ ScaleWorldItemsCommand::ScaleWorldItemsCommand(const QList<QGraphicsItem *> &ite
m_factor(factor), m_factor(factor),
m_pivot(pivot) m_pivot(pivot)
{ {
setText("Scale item(s)"); setText(QObject::tr("Scale item(s)"));
} }
ScaleWorldItemsCommand::~ScaleWorldItemsCommand() ScaleWorldItemsCommand::~ScaleWorldItemsCommand()
@ -698,7 +773,7 @@ TurnWorldItemsCommand::TurnWorldItemsCommand(const QList<QGraphicsItem *> &items
: AbstractWorldItemCommand(items, scene, model, parent), : AbstractWorldItemCommand(items, scene, model, parent),
m_angle(angle) m_angle(angle)
{ {
setText("Turn item(s)"); setText(QObject::tr("Turn item(s)"));
} }
TurnWorldItemsCommand::~TurnWorldItemsCommand() TurnWorldItemsCommand::~TurnWorldItemsCommand()
@ -722,7 +797,7 @@ ShapeWorldItemsCommand::ShapeWorldItemsCommand(const QList<QGraphicsItem *> &ite
m_redoPolygons(polygons), m_redoPolygons(polygons),
m_undoPolygons(polygonsFromItems(items)) m_undoPolygons(polygonsFromItems(items))
{ {
setText("Change shape"); setText(QObject::tr("Change shape"));
} }
ShapeWorldItemsCommand::~ShapeWorldItemsCommand() ShapeWorldItemsCommand::~ShapeWorldItemsCommand()

@ -95,6 +95,34 @@ private:
LandscapeEditor::ZoneBuilderBase *const m_zoneBuilder; LandscapeEditor::ZoneBuilderBase *const m_zoneBuilder;
}; };
/**
@class UnloadLandscapeCommand
@brief
@details
*/
class UnloadLandscapeCommand: public QUndoCommand
{
public:
UnloadLandscapeCommand(const QModelIndex &index, PrimitivesTreeModel *model,
LandscapeEditor::ZoneBuilderBase *zoneBuilder, QUndoCommand *parent = 0);
virtual ~UnloadLandscapeCommand();
virtual void undo();
virtual void redo();
private:
Path m_path;
int m_id;
QString m_fileName;
PrimitivesTreeModel *const m_model;
LandscapeEditor::ZoneBuilderBase *const m_zoneBuilder;
};
/**
@class CreateRootPrimitiveCommand
@brief
@details
*/
class CreateRootPrimitiveCommand: public QUndoCommand class CreateRootPrimitiveCommand: public QUndoCommand
{ {
public: public:
@ -112,7 +140,7 @@ private:
}; };
/** /**
@class LoadPrimitiveCommand @class LoadRootPrimitiveCommand
@brief @brief
@details @details
*/ */
@ -136,7 +164,32 @@ private:
}; };
/** /**
@class AddPrimitiveCommand @class UnloadRootPrimitiveCommand
@brief
@details
*/
class UnloadRootPrimitiveCommand: public QUndoCommand
{
public:
UnloadRootPrimitiveCommand(const QModelIndex &index, WorldEditorScene *scene,
PrimitivesTreeModel *model, QTreeView *view,
QUndoCommand *parent = 0);
virtual ~UnloadRootPrimitiveCommand();
virtual void undo();
virtual void redo();
private:
Path m_path;
QString m_fileName;
NLLIGO::CPrimitives *m_primitives;
WorldEditorScene *const m_scene;
PrimitivesTreeModel *const m_model;
QTreeView *m_view;
};
/**
@class AddPrimitiveByClassCommand
@brief @brief
@details @details
*/ */

@ -67,6 +67,8 @@ AbstractWorldItem *WorldEditorScene::addWorldItemPoint(const QPointF &point, con
{ {
WorldItemPoint *item = new WorldItemPoint(point, angle, radius, showArrow); WorldItemPoint *item = new WorldItemPoint(point, angle, radius, showArrow);
addItem(item); addItem(item);
m_worldItems.push_back(item);
return item; return item;
} }
@ -74,6 +76,8 @@ AbstractWorldItem *WorldEditorScene::addWorldItemPath(const QPolygonF &polyline,
{ {
WorldItemPath *item = new WorldItemPath(polyline); WorldItemPath *item = new WorldItemPath(polyline);
addItem(item); addItem(item);
m_worldItems.push_back(item);
return item; return item;
} }
@ -81,6 +85,8 @@ AbstractWorldItem *WorldEditorScene::addWorldItemZone(const QPolygonF &polygon)
{ {
WorldItemZone *item = new WorldItemZone(polygon); WorldItemZone *item = new WorldItemZone(polygon);
addItem(item); addItem(item);
m_worldItems.push_back(item);
return item; return item;
} }
@ -90,6 +96,10 @@ void WorldEditorScene::removeWorldItem(QGraphicsItem *item)
m_selectedItems.clear(); m_selectedItems.clear();
m_editedSelectedItems = false; m_editedSelectedItems = false;
m_firstSelection = false; m_firstSelection = false;
// TODO
AbstractWorldItem *worldItem = qgraphicsitem_cast<AbstractWorldItem *>(item);
m_worldItems.removeOne(worldItem);
delete item; delete item;
} }

@ -34,8 +34,8 @@ class AbstractWorldItem;
/* /*
@class WorldEditorScene @class WorldEditorScene
@brief @brief The WorldEditorScene provides a surface for managing a large number of 2D world items(point/path/zone).
@details @details WorldEditorScene also provides 'selections model' functionality, which differs from standart selection model.
*/ */
class WORLD_EDITOR_EXPORT WorldEditorScene : public LandscapeEditor::LandscapeSceneBase class WORLD_EDITOR_EXPORT WorldEditorScene : public LandscapeEditor::LandscapeSceneBase
{ {
@ -56,22 +56,38 @@ public:
QUndoStack *undoStack, QObject *parent = 0); QUndoStack *undoStack, QObject *parent = 0);
virtual ~WorldEditorScene(); virtual ~WorldEditorScene();
/// Create WorldItemPoint and add in scene.
AbstractWorldItem *addWorldItemPoint(const QPointF &point, const qreal angle, AbstractWorldItem *addWorldItemPoint(const QPointF &point, const qreal angle,
const qreal radius, bool showArrow); const qreal radius, bool showArrow);
/// Create WorldItemPath and add in scene.
AbstractWorldItem *addWorldItemPath(const QPolygonF &polyline, bool showArrow); AbstractWorldItem *addWorldItemPath(const QPolygonF &polyline, bool showArrow);
/// Create WorldItemZone and add in scene.
AbstractWorldItem *addWorldItemZone(const QPolygonF &polygon); AbstractWorldItem *addWorldItemZone(const QPolygonF &polygon);
/// Remove a world item from the scene.
void removeWorldItem(QGraphicsItem *item); void removeWorldItem(QGraphicsItem *item);
/// Set current mode editing(select/move/rotate/scale/turn), above world items.
void setModeEdit(WorldEditorScene::ModeEdit mode); void setModeEdit(WorldEditorScene::ModeEdit mode);
WorldEditorScene::ModeEdit editMode() const; WorldEditorScene::ModeEdit editMode() const;
/// @return true if edit points mode is enabled, else false.
bool isEnabledEditPoints() const; bool isEnabledEditPoints() const;
Q_SIGNALS: Q_SIGNALS:
/// This signal is emitted by WorldEditorScene when the selections changes.
/// The @selected value contains a list of all selected items.
void updateSelectedItems(const QList<QGraphicsItem *> &selected); void updateSelectedItems(const QList<QGraphicsItem *> &selected);
public Q_SLOTS: public Q_SLOTS:
/// Enable/disable edit points mode (user can change shape of WorldItemZone and WorldItemPath)
///
void setEnabledEditPoints(bool enabled); void setEnabledEditPoints(bool enabled);
/// Update of selections
void updateSelection(const QList<QGraphicsItem *> &selected, const QList<QGraphicsItem *> &deselected); void updateSelection(const QList<QGraphicsItem *> &selected, const QList<QGraphicsItem *> &deselected);
protected: protected:
@ -102,6 +118,7 @@ private:
qreal m_firstPickX, m_firstPickY, m_angle; qreal m_firstPickX, m_firstPickY, m_angle;
QList<QGraphicsItem *> m_selectedItems; QList<QGraphicsItem *> m_selectedItems;
QList<QGraphicsItem *> m_selectedPoints; QList<QGraphicsItem *> m_selectedPoints;
QList<AbstractWorldItem *> m_worldItems;
QList<QPolygonF> m_polygons; QList<QPolygonF> m_polygons;
bool m_editedSelectedItems, m_firstSelection; bool m_editedSelectedItems, m_firstSelection;
uint m_lastPickedPrimitive; uint m_lastPickedPrimitive;

@ -53,8 +53,8 @@ const int EDGE_POINT_LAYER = 201;
const int SIZE_ARROW = 20; const int SIZE_ARROW = 20;
/* /*
@class WorldItemPoint @class AbstractWorldItem
@brief @brief Abstract class for graphics item
@details @details
*/ */
class AbstractWorldItem: public QGraphicsItem class AbstractWorldItem: public QGraphicsItem
@ -65,13 +65,21 @@ public:
enum { Type = QGraphicsItem::UserType + 1 }; enum { Type = QGraphicsItem::UserType + 1 };
/// Rotate item around @pivot point on &deltaAngle (deg).
virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle) {}; virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle) {};
/// Scales item relatively @pivot point
// TODO: add modes: IgnoreAspectRatio, KeepAspectRatio // TODO: add modes: IgnoreAspectRatio, KeepAspectRatio
virtual void scaleOn(const QPointF &pivot, const QPointF &factor) {}; virtual void scaleOn(const QPointF &pivot, const QPointF &factor) {};
/// Rotate arrow on angle (deg). (only for WorldItemPoint)
virtual void turnOn(const qreal angle) {}; virtual void turnOn(const qreal angle) {};
virtual void radiusOn(const qreal radius) {}; virtual void radiusOn(const qreal radius) {};
/// Change color
virtual void setColor(const QColor &color) = 0; virtual void setColor(const QColor &color) = 0;
/// Enable/disable the mode edit shape (only for WorldItemPath and WorldItemPath)
virtual void setEnabledSubPoints(bool enabled) = 0; virtual void setEnabledSubPoints(bool enabled) = 0;
virtual void moveSubPoint(WorldItemSubPoint *subPoint) {} virtual void moveSubPoint(WorldItemSubPoint *subPoint) {}
@ -103,7 +111,8 @@ protected:
/* /*
@class WorldItemPoint @class WorldItemPoint
@brief @brief WorldItemPoint class provides a dot item with arrow and circle(@radius)
that you can add to a WorldEditorScene.
@details @details
*/ */
class WorldItemPoint: public AbstractWorldItem class WorldItemPoint: public AbstractWorldItem
@ -148,7 +157,7 @@ private:
/* /*
@class WorldItemPath @class WorldItemPath
@brief @brief WorldItemPath class provides a polyline item that you can add to a WorldEditorScene.
@details @details
*/ */
class WorldItemPath: public AbstractWorldItem class WorldItemPath: public AbstractWorldItem
@ -188,7 +197,7 @@ private:
/* /*
@class WorldItemZone @class WorldItemZone
@brief @brief The WorldItemZone class provides a polygon item that you can add to a WorldEditorScene.
@details @details
*/ */
class WorldItemZone: public AbstractWorldItem class WorldItemZone: public AbstractWorldItem

@ -165,6 +165,9 @@ void WorldEditorWindow::open()
void WorldEditorWindow::loadWorldEditFile(const QString &fileName) void WorldEditorWindow::loadWorldEditFile(const QString &fileName)
{ {
if (m_primitivesModel->isWorldEditNodeLoaded())
return;
Utils::WorldEditList worldEditList; Utils::WorldEditList worldEditList;
if (!Utils::loadWorldEditFile(fileName.toStdString(), worldEditList)) if (!Utils::loadWorldEditFile(fileName.toStdString(), worldEditList))
{ {

Loading…
Cancel
Save