QElectroTech  0.70
elementfactory.cpp
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 #include "elementfactory.h"
19 #include "QDomElement"
20 #include "simpleelement.h"
21 #include "reportelement.h"
22 #include "masterelement.h"
23 #include "slaveelement.h"
24 #include "terminalelement.h"
25 
34 Element * ElementFactory::createElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state)
35 {
36  if (Q_UNLIKELY( !(location.isElement() && location.exist()) ))
37  {
38  if (state)
39  *state = 1;
40  return nullptr;
41  }
42 
43  if (location.xml().hasAttribute("link_type"))
44  {
45  QString link_type = location.xml().attribute("link_type");
46  if (link_type == "next_report" || link_type == "previous_report") return (new ReportElement(location, link_type, qgi, state));
47  if (link_type == "master") return (new MasterElement (location, qgi, state));
48  if (link_type == "slave") return (new SlaveElement (location, qgi, state));
49  if (link_type == "terminal") return (new TerminalElement (location, qgi, state));
50  }
51 
52  //default if nothing match for link_type
53  return (new SimpleElement(location, qgi, state));
54 }
The ReportElement class this class represent an element that can be linked to an other ReportElement ...
Definition: reportelement.h:28
The ElementFactory class this class is a pattern factory and also a singleton factory. this class create new instance of herited class element like simple element or report element.
The MasterElement class This class is a custom element, with extended behavior to be a master element...
Definition: masterelement.h:31
Element * createElement(const ElementsLocation &, QGraphicsItem *=nullptr, int *=nullptr)
ElementFactory::createElement.
The SimpleElement class this class represente a simple element with no specific attribute.
Definition: simpleelement.h:29
QDomElement xml() const
ElementsLocation::xml.
static ElementFactory * factory_
bool exist() const
ElementsLocation::exist.
bool isElement() const
ElementsLocation::isElement.