QElectroTech  0.70
qgimanager.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 "qgimanager.h"
19 
24 QGIManager::QGIManager(QGraphicsScene *sc) :
25  scene(sc),
26  destroy_qgi_on_delete(true)
27 {
28 }
29 
38  if (!destroy_qgi_on_delete) return;
39  foreach(QGraphicsItem *qgi, qgi_manager.keys()) {
40  if (!scene -> items().contains(qgi)) delete qgi;
41  }
42 }
43 
48 void QGIManager::manage(QGraphicsItem *qgi) {
49  if (qgi -> parentItem()) return;
50  if (qgi_manager.contains(qgi)) ++ qgi_manager[qgi];
51  else qgi_manager.insert(qgi, 1);
52 }
53 
60 void QGIManager::release(QGraphicsItem *qgi) {
61  if (!qgi_manager.contains(qgi)) return;
62  -- qgi_manager[qgi];
63  if (qgi_manager[qgi] <= 0 && !(scene -> items().contains(qgi))) {
64  delete qgi;
65  qgi_manager.remove(qgi);
66  }
67 }
68 
73 void QGIManager::manage(const QList<QGraphicsItem *> &qgis) {
74  foreach(QGraphicsItem *qgi, qgis) manage(qgi);
75 }
76 
84 void QGIManager::release(const QList<QGraphicsItem *> &qgis) {
85  foreach(QGraphicsItem *qgi, qgis) release(qgi);
86 }
87 
94 }
95 
101 bool QGIManager::manages(QGraphicsItem *qgi) const {
102  return(qgi_manager.contains(qgi));
103 }
void release(QGraphicsItem *)
Definition: qgimanager.cpp:60
QGIManager(QGraphicsScene *)
Definition: qgimanager.cpp:24
virtual ~QGIManager()
Definition: qgimanager.cpp:37
void setDestroyQGIOnDelete(bool)
Definition: qgimanager.cpp:92
QGraphicsScene * scene
Definition: qgimanager.h:37
bool destroy_qgi_on_delete
Definition: qgimanager.h:39
QHash< QGraphicsItem *, int > qgi_manager
Definition: qgimanager.h:38
void manage(QGraphicsItem *)
Definition: qgimanager.cpp:48
bool manages(QGraphicsItem *) const
Definition: qgimanager.cpp:101