QElectroTech  0.8-dev
elementpicturefactory.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef ELEMENTPICTUREFACTORY_H
19 #define ELEMENTPICTUREFACTORY_H
20 
21 #include <QMutex>
22 #include <QSharedPointer>
23 #include <QHash>
24 
25 class ElementsLocation;
26 class QPicture;
27 class QUuid;
28 class QDomElement;
29 class QPainter;
30 class QGraphicsSimpleTextItem;
31 
38 {
39  public :
40  struct primitives
41  {
42  QList<QLineF> m_lines;
43  QList<QRectF> m_rectangles;
44  QList<QRectF> m_circles;
45  QList<QVector<QPointF>> m_polygons;
46  QList<QVector<qreal>> m_arcs;
47  QList<QGraphicsSimpleTextItem*> m_texts;
48  };
49 
50 
56  {
57  static QMutex mutex;
58  if (!m_factory)
59  {
60  mutex.lock();
61  if (!m_factory) {
63  }
64  mutex.unlock();
65  }
66  return m_factory;
67  }
68 
73  static void dropInstance()
74  {
75  static QMutex mutex;
76  if (m_factory)
77  {
78  mutex.lock();
79  delete m_factory;
80  m_factory = nullptr;
81  mutex.unlock();
82  }
83  }
84 
85  void getPictures(const ElementsLocation &location, QPicture &picture, QPicture &low_picture);
86  QPixmap pixmap(const ElementsLocation &location);
88 
89  private:
94 
95  bool build(const ElementsLocation &location, QPicture *picture=nullptr, QPicture *low_picture=nullptr);
96  void parseElement(const QDomElement &dom, QPainter &painter, primitives &prim) const;
97  void parseLine (const QDomElement &dom, QPainter &painter, primitives &prim) const;
98  void parseRect (const QDomElement &dom, QPainter &painter, primitives &prim) const;
99  void parseEllipse(const QDomElement &dom, QPainter &painter, primitives &prim) const;
100  void parseCircle (const QDomElement &dom, QPainter &painter, primitives &prim) const;
101  void parseArc (const QDomElement &dom, QPainter &painter, primitives &prim) const;
102  void parsePolygon(const QDomElement &dom, QPainter &painter, primitives &prim) const;
103  void parseText (const QDomElement &dom, QPainter &painter, primitives &prim) const;
104  void setPainterStyle(const QDomElement &dom, QPainter &painter) const;
105 
106  QHash<QUuid, QPicture> m_pictures_H;
107  QHash<QUuid, QPicture> m_low_pictures_H;
108  QHash<QUuid, QPixmap> m_pixmap_H;
109  QHash<QUuid, primitives> m_primitives_H;
111 };
112 
113 #endif // ELEMENTPICTUREFACTORY_H
ElementsLocation::exist
bool exist() const
ElementsLocation::exist.
Definition: elementslocation.cpp:472
ElementPictureFactory::m_pictures_H
QHash< QUuid, QPicture > m_pictures_H
Definition: elementpicturefactory.h:106
ElementPictureFactory::parsePolygon
void parsePolygon(const QDomElement &dom, QPainter &painter, primitives &prim) const
Definition: elementpicturefactory.cpp:450
ElementPictureFactory::primitives::m_lines
QList< QLineF > m_lines
Definition: elementpicturefactory.h:42
elementpicturefactory.h
ElementPictureFactory::~ElementPictureFactory
~ElementPictureFactory()
Definition: elementpicturefactory.cpp:129
ElementPictureFactory::parseCircle
void parseCircle(const QDomElement &dom, QPainter &painter, primitives &prim) const
Definition: elementpicturefactory.cpp:406
QET::version
const QString version
QElectroTech version (as string, used to mark projects and elements XML documents)
Definition: qet.h:32
ElementPictureFactory::m_factory
static ElementPictureFactory * m_factory
Definition: elementpicturefactory.h:110
PartLine::requiredLengthForEndType
static uint requiredLengthForEndType(const Qet::EndType &)
PartLine::requiredLengthForEndType.
Definition: partline.cpp:54
ElementPictureFactory::m_low_pictures_H
QHash< QUuid, QPicture > m_low_pictures_H
Definition: elementpicturefactory.h:107
ElementPictureFactory::setPainterStyle
void setPainterStyle(const QDomElement &dom, QPainter &painter) const
ElementPictureFactory::setPainterStyle apply the style store in dom to painter.
Definition: elementpicturefactory.cpp:555
Qet::Simple
@ Simple
Base-less triangle.
Definition: qet.h:195
Qet::Diamond
@ Diamond
Diamond.
Definition: qet.h:198
ElementsLocation::uuid
QUuid uuid() const
ElementsLocation::uuid.
Definition: elementslocation.cpp:737
ElementPictureFactory::operator=
ElementPictureFactory operator=(const ElementPictureFactory &)
ElementPictureFactory::primitives::m_circles
QList< QRectF > m_circles
Definition: elementpicturefactory.h:44
partline.h
ElementPictureFactory::build
bool build(const ElementsLocation &location, QPicture *picture=nullptr, QPicture *low_picture=nullptr)
ElementPictureFactory::build Build the picture from location.
Definition: elementpicturefactory.cpp:147
ElementPictureFactory::primitives
Definition: elementpicturefactory.h:41
qetapp.h
ElementPictureFactory::dropInstance
static void dropInstance()
dropInstance Drop the instance of factory
Definition: elementpicturefactory.h:73
ElementPictureFactory::getPictures
void getPictures(const ElementsLocation &location, QPicture &picture, QPicture &low_picture)
ElementPictureFactory::getPictures Set the picture of the element at location. Note,...
Definition: elementpicturefactory.cpp:42
ElementPictureFactory::parseText
void parseText(const QDomElement &dom, QPainter &painter, primitives &prim) const
Definition: elementpicturefactory.cpp:487
qet.h
ElementPictureFactory::pixmap
QPixmap pixmap(const ElementsLocation &location)
ElementPictureFactory::pixmap.
Definition: elementpicturefactory.cpp:76
ElementPictureFactory::getPrimitives
ElementPictureFactory::primitives getPrimitives(const ElementsLocation &location)
ElementPictureFactory::getPrimitives.
Definition: elementpicturefactory.cpp:120
ElementsLocation::xml
QDomElement xml() const
ElementsLocation::xml.
Definition: elementslocation.cpp:575
ElementPictureFactory::primitives::m_texts
QList< QGraphicsSimpleTextItem * > m_texts
Definition: elementpicturefactory.h:47
elementslocation.h
ElementPictureFactory::primitives::m_rectangles
QList< QRectF > m_rectangles
Definition: elementpicturefactory.h:43
ElementPictureFactory::primitives::m_polygons
QList< QVector< QPointF > > m_polygons
Definition: elementpicturefactory.h:45
ElementPictureFactory::ElementPictureFactory
ElementPictureFactory()
Definition: elementpicturefactory.h:90
ElementPictureFactory::m_primitives_H
QHash< QUuid, primitives > m_primitives_H
Definition: elementpicturefactory.h:109
Qet::EndType
EndType
This enum lists the various available endings for line primitives when drawing an electrical element.
Definition: qet.h:193
ElementsLocation::pugiXml
pugi::xml_document pugiXml() const
ElementsLocation::pugiXml.
Definition: elementslocation.cpp:610
ElementPictureFactory::parseLine
void parseLine(const QDomElement &dom, QPainter &painter, primitives &prim) const
Definition: elementpicturefactory.cpp:259
ElementPictureFactory::primitives::m_arcs
QList< QVector< qreal > > m_arcs
Definition: elementpicturefactory.h:46
ElementPictureFactory
The ElementPictureFactory class This class is singleton factory, use to create and get the picture us...
Definition: elementpicturefactory.h:38
ElementPictureFactory::instance
static ElementPictureFactory * instance()
instance
Definition: elementpicturefactory.h:55
PartLine::fourEndPoints
static QList< QPointF > fourEndPoints(const QPointF &, const QPointF &, const qreal &)
PartLine::fourEndPoints Return the four interesting point needed to draw the shape at extremity of li...
Definition: partline.cpp:601
ElementsLocation
The ElementsLocation class This class represents the location, the location of an element or of a cat...
Definition: elementslocation.h:46
Qet::endTypeFromString
static Qet::EndType endTypeFromString(const QString &)
Definition: qet.cpp:506
Qet::Circle
@ Circle
Circle.
Definition: qet.h:197
ElementPictureFactory::m_pixmap_H
QHash< QUuid, QPixmap > m_pixmap_H
Definition: elementpicturefactory.h:108
ElementPictureFactory::ElementPictureFactory
ElementPictureFactory(const ElementPictureFactory &)
ElementPictureFactory::parseEllipse
void parseEllipse(const QDomElement &dom, QPainter &painter, primitives &prim) const
Definition: elementpicturefactory.cpp:382
QETApp::diagramTextsFont
static QFont diagramTextsFont(qreal=-1.0)
QETApp::diagramTextsFont The font to use By default the font is "sans Serif" and size 9.
Definition: qetapp.cpp:1111
QET::attributeIsAnInteger
bool attributeIsAnInteger(const QDomElement &, const QString &, int *=nullptr)
Definition: qet.cpp:210
ElementPictureFactory::parseArc
void parseArc(const QDomElement &dom, QPainter &painter, primitives &prim) const
Definition: elementpicturefactory.cpp:423
ElementPictureFactory::parseElement
void parseElement(const QDomElement &dom, QPainter &painter, primitives &prim) const
Definition: elementpicturefactory.cpp:248
Qet::Triangle
@ Triangle
Triangle.
Definition: qet.h:196
ElementPictureFactory::parseRect
void parseRect(const QDomElement &dom, QPainter &painter, primitives &prim) const
Definition: elementpicturefactory.cpp:358
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
QET::attributeIsAReal
bool attributeIsAReal(const QDomElement &, const QString &, qreal *=nullptr)
Definition: qet.cpp:231