Changed: #1302 Added save/saveAs action for primitive item.

--HG--
branch : gsoc2011-worldeditorqt
hg/feature/sse2
dnk-88 13 years ago
parent 782425f9df
commit 82f6999b47

@ -121,7 +121,7 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
for (int i = 0; i < sizeVec; ++i) for (int i = 0; i < sizeVec; ++i)
{ {
polygon << QPointF(vec->x, -vec->y + cellSize); polygon << QPointF(vec->x, cellSize - vec->y);
++vec; ++vec;
} }
item = scene->addWorldItemZone(polygon); item = scene->addWorldItemZone(polygon);
@ -216,6 +216,49 @@ QList<QPolygonF> polygonsFromItems(const QList<QGraphicsItem *> &items)
return result; return result;
} }
void updateGraphicsData(AbstractWorldItem *item)
{
float cellSize = Utils::ligoConfig()->CellSize;
Node *node = qvariant_cast<Node *>(item->data(Constants::WORLD_EDITOR_NODE));
PrimitiveNode *primitiveNode = static_cast<PrimitiveNode *>(node);
if (primitiveNode != 0)
{
NLLIGO::IPrimitive *primitive = primitiveNode->primitive();
std::vector<NLLIGO::CPrimVector> vPoints;
QPolygonF polygon = item->polygon();
polygon.translate(item->pos());
for (int i = 0; i < polygon.size(); ++i)
{
NLMISC::CVector vec(polygon.at(i).x(), cellSize - polygon.at(i).y(), 0.0);
vPoints.push_back(NLLIGO::CPrimVector(vec));
}
switch (primitiveNode->primitiveClass()->Type)
{
case NLLIGO::CPrimitiveClass::Point:
{
NLLIGO::CPrimPoint *point = static_cast<NLLIGO::CPrimPoint *>(primitive);
point->Point = vPoints.front();
break;
}
case NLLIGO::CPrimitiveClass::Path:
{
NLLIGO::CPrimPath *path = static_cast<NLLIGO::CPrimPath *>(primitive);
path->VPoints = vPoints;
break;
}
case NLLIGO::CPrimitiveClass::Zone:
{
NLLIGO::CPrimZone *zone = static_cast<NLLIGO::CPrimZone *>(primitive);
zone->VPoints = vPoints;
break;
}
}
}
}
CreateWorldCommand::CreateWorldCommand(const QString &fileName, PrimitivesTreeModel *model, QUndoCommand *parent) CreateWorldCommand::CreateWorldCommand(const QString &fileName, PrimitivesTreeModel *model, QUndoCommand *parent)
: QUndoCommand(parent), : QUndoCommand(parent),
m_fileName(fileName), m_fileName(fileName),
@ -451,6 +494,7 @@ void MoveWorldItemsCommand::undo()
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->moveBy(-m_offset.x(), -m_offset.y()); item->moveBy(-m_offset.x(), -m_offset.y());
updateGraphicsData(item);
} }
m_scene->setEnabledEditPoints(pointsMode); m_scene->setEnabledEditPoints(pointsMode);
} }
@ -466,9 +510,20 @@ void MoveWorldItemsCommand::redo()
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->moveBy(m_offset.x(), m_offset.y()); item->moveBy(m_offset.x(), m_offset.y());
updateGraphicsData(item);
} }
m_scene->setEnabledEditPoints(pointsMode); m_scene->setEnabledEditPoints(pointsMode);
} }
else
{
for (int i = 0; i < m_listPaths.count(); ++i)
{
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
updateGraphicsData(item);
}
}
m_firstRun = false; m_firstRun = false;
} }
@ -498,6 +553,7 @@ void RotateWorldItemsCommand::undo()
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->rotateOn(m_pivot, -m_angle); item->rotateOn(m_pivot, -m_angle);
updateGraphicsData(item);
} }
m_scene->setEnabledEditPoints(pointsMode); m_scene->setEnabledEditPoints(pointsMode);
} }
@ -513,9 +569,20 @@ void RotateWorldItemsCommand::redo()
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->rotateOn(m_pivot, m_angle); item->rotateOn(m_pivot, m_angle);
updateGraphicsData(item);
} }
m_scene->setEnabledEditPoints(pointsMode); m_scene->setEnabledEditPoints(pointsMode);
} }
else
{
for (int i = 0; i < m_listPaths.count(); ++i)
{
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
updateGraphicsData(item);
}
}
m_firstRun = false; m_firstRun = false;
} }
@ -546,6 +613,7 @@ void ScaleWorldItemsCommand::undo()
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->scaleOn(m_pivot, m_invertFactor); item->scaleOn(m_pivot, m_invertFactor);
updateGraphicsData(item);
} }
m_scene->setEnabledEditPoints(pointsMode); m_scene->setEnabledEditPoints(pointsMode);
} }
@ -561,9 +629,20 @@ void ScaleWorldItemsCommand::redo()
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->scaleOn(m_pivot, m_factor); item->scaleOn(m_pivot, m_factor);
updateGraphicsData(item);
} }
m_scene->setEnabledEditPoints(pointsMode); m_scene->setEnabledEditPoints(pointsMode);
} }
else
{
for (int i = 0; i < m_listPaths.count(); ++i)
{
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
updateGraphicsData(item);
}
}
m_firstRun = false; m_firstRun = false;
} }
@ -592,6 +671,7 @@ void TurnWorldItemsCommand::undo()
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->turnOn(-m_angle); item->turnOn(-m_angle);
updateGraphicsData(item);
} }
m_scene->setEnabledEditPoints(pointsMode); m_scene->setEnabledEditPoints(pointsMode);
} }
@ -607,9 +687,19 @@ void TurnWorldItemsCommand::redo()
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->turnOn(m_angle); item->turnOn(m_angle);
updateGraphicsData(item);
} }
m_scene->setEnabledEditPoints(pointsMode); m_scene->setEnabledEditPoints(pointsMode);
} }
else
{
for (int i = 0; i < m_listPaths.count(); ++i)
{
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
updateGraphicsData(item);
}
}
m_firstRun = false; m_firstRun = false;
} }
@ -642,6 +732,7 @@ void ShapeWorldItemsCommand::undo()
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->setPolygon(m_redoPolygons.at(i)); item->setPolygon(m_redoPolygons.at(i));
updateGraphicsData(item);
} }
m_scene->setEnabledEditPoints(pointsMode); m_scene->setEnabledEditPoints(pointsMode);
@ -659,9 +750,20 @@ void ShapeWorldItemsCommand::redo()
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->setPolygon(m_undoPolygons.at(i)); item->setPolygon(m_undoPolygons.at(i));
updateGraphicsData(item);
} }
m_scene->setEnabledEditPoints(pointsMode); m_scene->setEnabledEditPoints(pointsMode);
} }
else
{
for (int i = 0; i < m_listPaths.count(); ++i)
{
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
updateGraphicsData(item);
}
}
m_firstRun = false; m_firstRun = false;
} }

@ -35,6 +35,7 @@ class ZoneBuilderBase;
namespace WorldEditor namespace WorldEditor
{ {
class WorldEditorScene; class WorldEditorScene;
class AbstractWorldItem;
// Auxiliary operations // Auxiliary operations
@ -50,6 +51,8 @@ QList<Path> graphicsItemsToPaths(const QList<QGraphicsItem *> &items, Primitives
QList<QPolygonF> polygonsFromItems(const QList<QGraphicsItem *> &items); QList<QPolygonF> polygonsFromItems(const QList<QGraphicsItem *> &items);
void updateGraphicsData(AbstractWorldItem *item);
/** /**
@class CreateWorldCommand @class CreateWorldCommand
@brief @brief

@ -182,6 +182,17 @@ void WorldItemPoint::setColor(const QColor &color)
m_brush.setColor(color); m_brush.setColor(color);
} }
void WorldItemPoint::setPolygon(const QPolygonF &polygon)
{
}
QPolygonF WorldItemPoint::polygon() const
{
QPolygonF polygon;
polygon << QPointF(0, 0);
return polygon;
}
void WorldItemPoint::createCircle() void WorldItemPoint::createCircle()
{ {
if (m_radius != 0) if (m_radius != 0)
@ -339,6 +350,7 @@ void WorldItemPath::moveSubPoint(WorldItemSubPoint *subPoint)
m_listLines.at(i).itemPoint->setPos((m_listLines.at(i).lineItem.first->pos() + m_listLines.at(i).lineItem.second->pos()) / 2); m_listLines.at(i).itemPoint->setPos((m_listLines.at(i).lineItem.first->pos() + m_listLines.at(i).lineItem.second->pos()) / 2);
m_polygon = polygon; m_polygon = polygon;
setShapeChanged(true);
update(); update();
} }
@ -381,6 +393,7 @@ void WorldItemPath::addSubPoint(WorldItemSubPoint *subPoint)
break; break;
} }
} }
setShapeChanged(true);
} }
bool WorldItemPath::removeSubPoint(WorldItemSubPoint *subPoint) bool WorldItemPath::removeSubPoint(WorldItemSubPoint *subPoint)
@ -427,6 +440,7 @@ bool WorldItemPath::removeSubPoint(WorldItemSubPoint *subPoint)
subPoint->setPos((newLineItem.lineItem.first->pos() + newLineItem.lineItem.second->pos()) / 2); subPoint->setPos((newLineItem.lineItem.first->pos() + newLineItem.lineItem.second->pos()) / 2);
m_listLines.push_back(newLineItem); m_listLines.push_back(newLineItem);
subPoint->setFlag(ItemSendsScenePositionChanges, false); subPoint->setFlag(ItemSendsScenePositionChanges, false);
setShapeChanged(true);
return true; return true;
} }

@ -121,6 +121,9 @@ public:
virtual void setColor(const QColor &color); virtual void setColor(const QColor &color);
virtual void setEnabledSubPoints(bool enabled) {} virtual void setEnabledSubPoints(bool enabled) {}
virtual void setPolygon(const QPolygonF &polygon);
virtual QPolygonF polygon() const;
virtual QRectF boundingRect() const; virtual QRectF boundingRect() const;
virtual QPainterPath shape() const; virtual QPainterPath shape() const;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

Loading…
Cancel
Save