2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2013-06-18 11:10:19 +00:00
|
|
|
Copyright 2006-2013 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-11-09 13:06:51 +00:00
|
|
|
#include "diagramcontent.h"
|
|
|
|
#include <QGraphicsItem>
|
|
|
|
#include "element.h"
|
2010-04-18 17:59:54 +00:00
|
|
|
#include "independenttextitem.h"
|
2007-11-09 13:06:51 +00:00
|
|
|
#include "conductor.h"
|
2013-08-24 15:18:45 +00:00
|
|
|
#include "diagramimageitem.h"
|
2007-11-09 13:06:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur par defaut. Ne contient rien.
|
|
|
|
*/
|
|
|
|
DiagramContent::DiagramContent() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur de copie.
|
|
|
|
*/
|
|
|
|
DiagramContent::DiagramContent(const DiagramContent &other) :
|
|
|
|
elements(other.elements),
|
|
|
|
textFields(other.textFields),
|
2013-08-24 15:18:45 +00:00
|
|
|
images(other.images),
|
2007-11-09 13:06:51 +00:00
|
|
|
conductorsToUpdate(other.conductorsToUpdate),
|
2007-11-11 16:12:45 +00:00
|
|
|
conductorsToMove(other.conductorsToMove),
|
|
|
|
otherConductors(other.otherConductors)
|
2007-11-09 13:06:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
*/
|
|
|
|
DiagramContent::~DiagramContent() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-11 16:12:45 +00:00
|
|
|
@param filter Types de conducteurs desires
|
2007-11-09 13:06:51 +00:00
|
|
|
@return tous les conducteurs
|
|
|
|
*/
|
2007-11-11 16:12:45 +00:00
|
|
|
QList<Conductor *> DiagramContent::conductors(int filter) const {
|
2010-05-08 21:24:43 +00:00
|
|
|
QSet<Conductor *> result;
|
2007-11-11 16:12:45 +00:00
|
|
|
if (filter & ConductorsToMove) result += conductorsToMove;
|
2010-05-04 20:18:30 +00:00
|
|
|
if (filter & ConductorsToUpdate) result += conductorsToUpdate;
|
2007-11-11 16:12:45 +00:00
|
|
|
if (filter & OtherConductors) result += otherConductors;
|
2009-05-17 02:13:40 +00:00
|
|
|
if (filter & SelectedOnly) {
|
|
|
|
foreach(Conductor *conductor, result) {
|
2010-05-08 21:24:43 +00:00
|
|
|
if (!conductor -> isSelected()) result.remove(conductor);
|
2009-05-17 02:13:40 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-08 21:24:43 +00:00
|
|
|
return(result.toList());
|
2007-11-09 13:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Vide le conteneur
|
|
|
|
*/
|
|
|
|
void DiagramContent::clear() {
|
|
|
|
elements.clear();
|
|
|
|
textFields.clear();
|
2013-08-24 15:18:45 +00:00
|
|
|
images.clear();
|
2007-11-09 13:06:51 +00:00
|
|
|
conductorsToUpdate.clear();
|
|
|
|
conductorsToMove.clear();
|
2007-11-11 16:12:45 +00:00
|
|
|
otherConductors.clear();
|
2007-11-09 13:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-11 16:12:45 +00:00
|
|
|
@param filter Types desires
|
2007-11-09 13:06:51 +00:00
|
|
|
@return la liste des items formant le contenu du schema
|
|
|
|
*/
|
2007-11-11 16:12:45 +00:00
|
|
|
QList<QGraphicsItem *> DiagramContent::items(int filter) const {
|
2007-11-09 13:06:51 +00:00
|
|
|
QList<QGraphicsItem *> items_list;
|
2007-11-11 16:12:45 +00:00
|
|
|
foreach(QGraphicsItem *qgi, conductors(filter)) items_list << qgi;
|
|
|
|
if (filter & Elements) foreach(QGraphicsItem *qgi, elements) items_list << qgi;
|
|
|
|
if (filter & TextFields) foreach(QGraphicsItem *qgi, textFields) items_list << qgi;
|
2013-08-24 15:18:45 +00:00
|
|
|
if (filter & Images) foreach(QGraphicsItem *qgi, images) items_list << qgi;
|
2009-05-17 02:13:40 +00:00
|
|
|
if (filter & SelectedOnly) {
|
|
|
|
foreach(QGraphicsItem *qgi, items_list) {
|
|
|
|
if (!qgi -> isSelected()) items_list.removeOne(qgi);
|
|
|
|
}
|
|
|
|
}
|
2007-11-09 13:06:51 +00:00
|
|
|
return(items_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-11 16:12:45 +00:00
|
|
|
@param filter Types desires
|
2007-11-09 13:06:51 +00:00
|
|
|
@return le nombre d'items formant le contenu du schema
|
|
|
|
*/
|
2007-11-11 16:12:45 +00:00
|
|
|
int DiagramContent::count(int filter) const {
|
|
|
|
int count = 0;
|
2013-08-25 11:55:23 +00:00
|
|
|
if (filter == SelectedOnly) {
|
|
|
|
if (filter == Elements) foreach(Element *element, elements) { if (element -> isSelected()) ++ count; }
|
|
|
|
if (filter == TextFields) foreach(DiagramTextItem *dti, textFields) { if (dti -> isSelected()) ++ count; }
|
2013-09-19 21:53:28 +00:00
|
|
|
if (filter == Images) foreach(DiagramImageItem *dii, images) { if (dii -> isSelected()) ++ count; }
|
2013-08-25 11:55:23 +00:00
|
|
|
if (filter == ConductorsToMove) foreach(Conductor *conductor, conductorsToMove) { if (conductor -> isSelected()) ++ count; }
|
|
|
|
if (filter == ConductorsToUpdate) foreach(Conductor *conductor, conductorsToUpdate) { if (conductor -> isSelected()) ++ count; }
|
|
|
|
if (filter == OtherConductors) foreach(Conductor *conductor, otherConductors) { if (conductor -> isSelected()) ++ count; }
|
2013-08-25 22:28:06 +00:00
|
|
|
} else if (filter == All) {
|
|
|
|
count += elements.count();
|
|
|
|
count += textFields.count();
|
|
|
|
count += images.count();
|
|
|
|
count += conductorsToMove.count();
|
|
|
|
count += conductorsToUpdate.count();
|
|
|
|
count += otherConductors.count();
|
2009-05-17 02:13:40 +00:00
|
|
|
} else {
|
2013-09-19 16:16:25 +00:00
|
|
|
if (filter & Elements) count += elements.count();
|
2013-09-19 16:33:02 +00:00
|
|
|
if (filter & TextFields) count += textFields.count();
|
2013-09-19 21:53:28 +00:00
|
|
|
if (filter == Images) count += images.count();
|
2013-09-19 19:34:26 +00:00
|
|
|
if (filter & ConductorsToMove) count += conductorsToMove.count();
|
|
|
|
if (filter & ConductorsToUpdate) count += conductorsToUpdate.count();
|
|
|
|
if (filter & OtherConductors) count += otherConductors.count();
|
2009-05-17 02:13:40 +00:00
|
|
|
}
|
2007-11-11 16:12:45 +00:00
|
|
|
return(count);
|
2007-11-09 13:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de composer rapidement la proposition "x elements, y conducteurs et
|
|
|
|
z champs de texte".
|
2007-11-11 16:12:45 +00:00
|
|
|
@param filter Types desires
|
2007-11-09 13:06:51 +00:00
|
|
|
@return la proposition decrivant le contenu.
|
|
|
|
*/
|
2007-11-11 16:12:45 +00:00
|
|
|
QString DiagramContent::sentence(int filter) const {
|
|
|
|
int elements_count = (filter & Elements) ? elements.count() : 0;
|
|
|
|
int conductors_count = conductors(filter).count();
|
|
|
|
int textfields_count = (filter & TextFields) ? textFields.count() : 0;
|
2013-08-24 15:18:45 +00:00
|
|
|
int images_count = (filter & Images) ? images.count() : 0;
|
2007-11-09 13:06:51 +00:00
|
|
|
|
|
|
|
return(
|
|
|
|
QET::ElementsAndConductorsSentence(
|
2007-11-11 16:12:45 +00:00
|
|
|
elements_count,
|
2007-11-09 13:06:51 +00:00
|
|
|
conductors_count,
|
2013-08-24 15:18:45 +00:00
|
|
|
textfields_count,
|
|
|
|
images_count
|
2007-11-09 13:06:51 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2007-11-11 16:12:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de debugger un contenu de schema
|
|
|
|
@param d Object QDebug a utiliser pour l'affichage des informations de debug
|
2009-11-22 16:12:22 +00:00
|
|
|
@param content Contenu de schema a debugger
|
2007-11-11 16:12:45 +00:00
|
|
|
*/
|
2009-11-22 16:12:22 +00:00
|
|
|
QDebug &operator<<(QDebug d, DiagramContent &content) {
|
|
|
|
Q_UNUSED(content);
|
2007-11-11 16:12:45 +00:00
|
|
|
d << "DiagramContent {" << "\n";
|
2008-07-09 21:14:30 +00:00
|
|
|
/*
|
|
|
|
FIXME Le double-heritage QObject / QGraphicsItem a casse cet operateur
|
2007-11-11 16:12:45 +00:00
|
|
|
d << " elements :" << c.elements << "\n";
|
2010-05-04 20:18:30 +00:00
|
|
|
d << " conductorsToUpdate :" << c.conductorsToUpdate << "\n";
|
2007-11-11 16:12:45 +00:00
|
|
|
d << " conductorsToMove :" << c.conductorsToMove << "\n";
|
|
|
|
d << " otherConductors :" << c.otherConductors << "\n";
|
2008-07-09 21:14:30 +00:00
|
|
|
*/
|
2008-07-30 12:44:57 +00:00
|
|
|
d << "}";
|
2007-11-11 16:12:45 +00:00
|
|
|
return(d.space());
|
|
|
|
}
|