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 # File with common stuff for whole project
include(../../../Valentina.pri) include(../../../Valentina.pri)
QT += core gui widgets
# Name of library # Name of library
TARGET = vlayout TARGET = vlayout

View File

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

View File

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

View File

@ -33,6 +33,7 @@
#include <QRectF> #include <QRectF>
#include <QImage> #include <QImage>
#include <QDir> #include <QDir>
#include <QGraphicsItem>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VLayoutGenerator::VLayoutGenerator(QObject *parent) VLayoutGenerator::VLayoutGenerator(QObject *parent)
@ -142,6 +143,17 @@ LayoutErrors VLayoutGenerator::State() const
return state; 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() void VLayoutGenerator::Abort()
{ {

View File

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

View File

@ -35,6 +35,7 @@
#include <QImage> #include <QImage>
#include <QDir> #include <QDir>
#include <QPainter> #include <QPainter>
#include <QGraphicsItem>
class BestResult class BestResult
{ {
@ -857,3 +858,17 @@ QPainterPath VLayoutPaper::DrawDetails() const
} }
return path; 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 QPolygonF;
class BestResult; class BestResult;
class QPainterPath; class QPainterPath;
class QGraphicsItem;
class VLayoutPaper class VLayoutPaper
{ {
@ -61,6 +62,8 @@ public:
bool ArrangeDetail(const VLayoutDetail &detail); bool ArrangeDetail(const VLayoutDetail &detail);
int Count() const; int Count() const;
QGraphicsItem *GetItem() const;
private: private:
QSharedDataPointer<VLayoutPaperData> d; QSharedDataPointer<VLayoutPaperData> d;