QElectroTech  0.70
elementpicturefactory.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 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
void parseCircle(const QDomElement &dom, QPainter &painter, primitives &prim) const
static ElementPictureFactory * m_factory
QHash< QUuid, primitives > m_primitives_H
QHash< QUuid, QPicture > m_pictures_H
static ElementPictureFactory * instance()
instance
void parseEllipse(const QDomElement &dom, QPainter &painter, primitives &prim) const
void parseElement(const QDomElement &dom, QPainter &painter, primitives &prim) const
void setPainterStyle(const QDomElement &dom, QPainter &painter) const
ElementPictureFactory::setPainterStyle apply the style store in dom to painter.
void parseText(const QDomElement &dom, QPainter &painter, primitives &prim) const
void parseArc(const QDomElement &dom, QPainter &painter, primitives &prim) const
void getPictures(const ElementsLocation &location, QPicture &picture, QPicture &low_picture)
ElementPictureFactory::getPictures Set the picture of the element at location. Note, picture can be null.
void parseRect(const QDomElement &dom, QPainter &painter, primitives &prim) const
ElementPictureFactory::primitives getPrimitives(const ElementsLocation &location)
ElementPictureFactory::getPrimitives.
ElementPictureFactory operator=(const ElementPictureFactory &)
QPixmap pixmap(const ElementsLocation &location)
ElementPictureFactory::pixmap.
static void dropInstance()
dropInstance Drop the instance of factory
QHash< QUuid, QPixmap > m_pixmap_H
QList< QVector< QPointF > > m_polygons
QList< QGraphicsSimpleTextItem * > m_texts
void parseLine(const QDomElement &dom, QPainter &painter, primitives &prim) const
bool build(const ElementsLocation &location, QPicture *picture=nullptr, QPicture *low_picture=nullptr)
ElementPictureFactory::build Build the picture from location.
void parsePolygon(const QDomElement &dom, QPainter &painter, primitives &prim) const
The ElementPictureFactory class This class is singleton factory, use to create and get the picture us...
QHash< QUuid, QPicture > m_low_pictures_H