Minor improvement and remove some use of ElementsCollectionItem and ElementsDefinition

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4407 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-03-29 17:23:58 +00:00
parent dd5d9c9504
commit 95e309ff18
8 changed files with 44 additions and 128 deletions

View File

@@ -16,9 +16,6 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "elementfactory.h"
#include "elementdefinition.h"
#include "elementscollectionitem.h"
#include "qetapp.h"
#include "QDomElement"
#include "simpleelement.h"
#include "reportelement.h"
@@ -26,7 +23,7 @@
#include "slaveelement.h"
#include "terminalelement.h"
ElementFactory* ElementFactory::factory_ = 0;
ElementFactory* ElementFactory::factory_ = nullptr;
/**
* @brief ElementFactory::createElement
* @param location create element at this location
@@ -36,20 +33,16 @@ ElementFactory* ElementFactory::factory_ = 0;
*/
Element * ElementFactory::createElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state)
{
// recupere la definition de l'element
ElementsCollectionItem *element_item = QETApp::collectionItem(location);
ElementDefinition *element_definition;
if (!element_item ||\
!element_item -> isElement() ||\
!(element_definition = qobject_cast<ElementDefinition *>(element_item)))
if (Q_UNLIKELY( !(location.isElement() && location.exist()) ))
{
if (state) *state = 1;
return 0;
if (state)
*state = 1;
return nullptr;
}
if (element_definition->xml().hasAttribute("link_type"))
if (location.xml().hasAttribute("link_type"))
{
QString link_type = element_definition->xml().attribute("link_type");
QString link_type = location.xml().attribute("link_type");
if (link_type == "next_report" || link_type == "previous_report") return (new ReportElement(location, link_type, qgi, state));
if (link_type == "master") return (new MasterElement (location, qgi, state));
if (link_type == "slave") return (new SlaveElement (location, qgi, state));