Return QGraphicsItems with sheet and all details for show on scene.

--HG--
branch : feature
This commit is contained in:
dismine 2015-01-13 12:38:51 +02:00
parent 166f2fbcdb
commit 3ed87757c4
7 changed files with 55 additions and 6 deletions

View File

@ -7,6 +7,8 @@
# File with common stuff for whole project
include(../../../Valentina.pri)
QT += core gui widgets
# Name of library
TARGET = vlayout

View File

@ -29,6 +29,7 @@
#include "vlayoutdetail.h"
#include "vlayoutdetail_p.h"
#include <QGraphicsItem>
#include <QPainterPath>
#include <QtMath>
@ -324,25 +325,27 @@ QPainterPath VLayoutDetail::ContourPath() const
QPainterPath path;
// contour
path.moveTo(d->contour[0]);
for (qint32 i = 1; i < d->contour.count(); ++i)
QVector<QPointF> points = Map(d->contour);
path.moveTo(points.at(0));
for (qint32 i = 1; i < points.count(); ++i)
{
path.lineTo(d->contour.at(i));
path.lineTo(points.at(i));
}
path.lineTo(d->contour.at(0));
path.lineTo(points.at(0));
// seam allowence
if (getSeamAllowance() == true)
{
QPainterPath ekv;
QVector<QPointF> p;
points = Map(d->seamAllowence);
if (getClosed() == true)
{
p = Equidistant(d->seamAllowence, EquidistantType::CloseEquidistant, getWidth());
p = Equidistant(points, EquidistantType::CloseEquidistant, getWidth());
}
else
{
p = Equidistant(d->seamAllowence, EquidistantType::OpenEquidistant, getWidth());
p = Equidistant(points, EquidistantType::OpenEquidistant, getWidth());
}
ekv.moveTo(p.at(0));
@ -357,3 +360,11 @@ QPainterPath VLayoutDetail::ContourPath() const
return path;
}
//---------------------------------------------------------------------------------------------------------------------
QGraphicsItem *VLayoutDetail::GetItem() const
{
QGraphicsPathItem *item = new QGraphicsPathItem();
item->setPath(ContourPath());
return item;
}

View File

@ -35,6 +35,7 @@
#include <QPointF>
class VLayoutDetailData;
class QGraphicsItem;
class VLayoutDetail :public VAbstractDetail
{
@ -72,6 +73,7 @@ public:
bool isNull() const;
qint64 Square() const;
QPainterPath ContourPath() const;
QGraphicsItem *GetItem() const;
private:
QSharedDataPointer<VLayoutDetailData> d;

View File

@ -33,6 +33,7 @@
#include <QRectF>
#include <QImage>
#include <QDir>
#include <QGraphicsItem>
//---------------------------------------------------------------------------------------------------------------------
VLayoutGenerator::VLayoutGenerator(QObject *parent)
@ -142,6 +143,17 @@ LayoutErrors VLayoutGenerator::State() const
return state;
}
//---------------------------------------------------------------------------------------------------------------------
QList<QGraphicsItem *> VLayoutGenerator::GetItems() const
{
QList<QGraphicsItem *> list;
for (int i=0; i < papers.count(); ++i)
{
list.append(papers.at(i).GetItem());
}
return list;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::Abort()
{

View File

@ -30,12 +30,14 @@
#define VLAYOUTGENERATOR_H
#include <QObject>
#include <QList>
#include "vlayoutdef.h"
#include "vbank.h"
class VLayoutPaper;
class VLayoutDetail;
class QGraphicsItem;
class VLayoutGenerator :public QObject
{
@ -62,6 +64,8 @@ public:
LayoutErrors State() const;
QList<QGraphicsItem *> GetItems() const;
signals:
void Start();
void Arranged(int count);

View File

@ -35,6 +35,7 @@
#include <QImage>
#include <QDir>
#include <QPainter>
#include <QGraphicsItem>
class BestResult
{
@ -857,3 +858,17 @@ QPainterPath VLayoutPaper::DrawDetails() const
}
return path;
}
//---------------------------------------------------------------------------------------------------------------------
QGraphicsItem *VLayoutPaper::GetItem() const
{
QGraphicsRectItem *paper = new QGraphicsRectItem(QRectF(0, 0, d->paperWidth, d->paperHeight));
paper->setPen(QPen(Qt::black, 1));
paper->setBrush(QBrush(Qt::white));
for (int i=0; i < d->details.count(); ++i)
{
QGraphicsItem *item = d->details.at(i).GetItem();
item->setParentItem(paper);
}
return paper;
}

View File

@ -38,6 +38,7 @@ class QLineF;
class QPolygonF;
class BestResult;
class QPainterPath;
class QGraphicsItem;
class VLayoutPaper
{
@ -61,6 +62,8 @@ public:
bool ArrangeDetail(const VLayoutDetail &detail);
int Count() const;
QGraphicsItem *GetItem() const;
private:
QSharedDataPointer<VLayoutPaperData> d;