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

This commit is contained in:
dnk-88 2011-08-16 19:34:21 +03:00
parent 10c5d9183c
commit 4786379e85
5 changed files with 127 additions and 5 deletions

View file

@ -197,7 +197,7 @@ void PrimitivesView::save()
QModelIndex index = indexList.first();
RootPrimitiveNode *node = static_cast<RootPrimitiveNode *>(index.internalPointer());
if (node->data(Constants::PRIMITIVE_FILE_IS_CREATED).toBool())
{
if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), node->fileName().toStdString()))
@ -214,8 +214,8 @@ void PrimitivesView::saveAs()
nlassert(m_primitivesTreeModel);
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save NeL Ligo primitive file"), m_lastDir,
tr("NeL Ligo primitive file (*.primitive)"));
tr("Save NeL Ligo primitive file"), m_lastDir,
tr("NeL Ligo primitive file (*.primitive)"));
setCursor(Qt::WaitCursor);
if (!fileName.isEmpty())
@ -224,7 +224,7 @@ void PrimitivesView::saveAs()
QModelIndex index = indexList.first();
RootPrimitiveNode *node = static_cast<RootPrimitiveNode *>(index.internalPointer());
if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), fileName.toStdString()))
QMessageBox::warning(this, "World Editor Qt", QString("Error writing output file: %1").arg(fileName));
else

View file

@ -121,7 +121,7 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
for (int i = 0; i < sizeVec; ++i)
{
polygon << QPointF(vec->x, -vec->y + cellSize);
polygon << QPointF(vec->x, cellSize - vec->y);
++vec;
}
item = scene->addWorldItemZone(polygon);
@ -216,6 +216,49 @@ QList<QPolygonF> polygonsFromItems(const QList<QGraphicsItem *> &items)
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)
: QUndoCommand(parent),
m_fileName(fileName),
@ -451,6 +494,7 @@ void MoveWorldItemsCommand::undo()
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->moveBy(-m_offset.x(), -m_offset.y());
updateGraphicsData(item);
}
m_scene->setEnabledEditPoints(pointsMode);
}
@ -466,9 +510,20 @@ void MoveWorldItemsCommand::redo()
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->moveBy(m_offset.x(), m_offset.y());
updateGraphicsData(item);
}
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;
}
@ -498,6 +553,7 @@ void RotateWorldItemsCommand::undo()
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->rotateOn(m_pivot, -m_angle);
updateGraphicsData(item);
}
m_scene->setEnabledEditPoints(pointsMode);
}
@ -513,9 +569,20 @@ void RotateWorldItemsCommand::redo()
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->rotateOn(m_pivot, m_angle);
updateGraphicsData(item);
}
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;
}
@ -546,6 +613,7 @@ void ScaleWorldItemsCommand::undo()
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->scaleOn(m_pivot, m_invertFactor);
updateGraphicsData(item);
}
m_scene->setEnabledEditPoints(pointsMode);
}
@ -561,9 +629,20 @@ void ScaleWorldItemsCommand::redo()
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->scaleOn(m_pivot, m_factor);
updateGraphicsData(item);
}
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;
}
@ -592,6 +671,7 @@ void TurnWorldItemsCommand::undo()
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->turnOn(-m_angle);
updateGraphicsData(item);
}
m_scene->setEnabledEditPoints(pointsMode);
}
@ -607,9 +687,19 @@ void TurnWorldItemsCommand::redo()
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->turnOn(m_angle);
updateGraphicsData(item);
}
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;
}
@ -642,6 +732,7 @@ void ShapeWorldItemsCommand::undo()
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->setPolygon(m_redoPolygons.at(i));
updateGraphicsData(item);
}
m_scene->setEnabledEditPoints(pointsMode);
@ -659,9 +750,20 @@ void ShapeWorldItemsCommand::redo()
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->setPolygon(m_undoPolygons.at(i));
updateGraphicsData(item);
}
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;
}

View file

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

View file

@ -182,6 +182,17 @@ void WorldItemPoint::setColor(const QColor &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()
{
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_polygon = polygon;
setShapeChanged(true);
update();
}
@ -381,6 +393,7 @@ void WorldItemPath::addSubPoint(WorldItemSubPoint *subPoint)
break;
}
}
setShapeChanged(true);
}
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);
m_listLines.push_back(newLineItem);
subPoint->setFlag(ItemSendsScenePositionChanges, false);
setShapeChanged(true);
return true;
}

View file

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