QElectroTech  0.70
elementprovider.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 "elementprovider.h"
19 #include "qetproject.h"
20 #include "diagram.h"
22 
29 {
30  diag_list = prj->diagrams();
31  diag_list.removeOne(diagram);
32 }
33 
39  diag_list << diag;
40 }
41 
51 QList <Element *> ElementProvider::freeElement(const int filter) const{
52  QList <Element *> free_elmt;
53 
54  //serch in all diagram
55  foreach (Diagram *d, diag_list) {
56  //get all element in diagram d
57  QList <Element *> elmt_list;
58  elmt_list = d->elements();
59  foreach (Element *elmt, elmt_list) {
60  if (filter & elmt->linkType())
61  if (elmt->isFree()) free_elmt << elmt;
62  }
63  }
64  return (free_elmt);
65 }
66 
72 QList <Element *> ElementProvider::fromUuids(QList<QUuid> uuid_list) const {
73  QList <Element *> found_element;
74 
75  foreach (Diagram *d, diag_list) {
76  foreach(Element *elmt, d->elements()) {
77  if (uuid_list.contains(elmt->uuid())) {
78  found_element << elmt;
79  uuid_list.removeAll(elmt->uuid());
80  }
81  }
82  }
83  return found_element;
84 }
85 
93 QList <Element *> ElementProvider::find(const int filter) const {
94  QList <Element *> elmt_;
95 
96  //serch in all diagram
97  foreach (Diagram *d, diag_list) {
98  //get all element in diagram d
99  QList <Element *> elmt_list;
100  elmt_list = d->elements();
101  foreach (Element *elmt, elmt_list) {
102  if (filter & elmt->linkType())
103  elmt_ << elmt;
104  }
105  }
106  return (elmt_);
107 }
ElementProvider(QETProject *prj, Diagram *diagram=nullptr)
ElementProvider::ElementProvider Constructor.
QList< Element * > find(const int filter) const
ElementProvider::find Search and return the asked element corresponding with the given filter...
QList< Diagram * > diagrams() const
Definition: qetproject.cpp:210
virtual kind linkType() const
Definition: element.h:138
bool isFree() const
Definition: element.h:201
QUuid uuid() const
Element::uuid.
Definition: element.h:221
QList< Diagram * > diag_list
QList< Element * > fromUuids(QList< QUuid >) const
ElementProvider::fromUuids.
QList< Element * > freeElement(const int filter) const
ElementProvider::FreeElement Search and return the asked element corresponding with the given filter ...
QList< Element * > elements() const
Definition: diagram.cpp:1477