2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2008-02-06 19:40:45 +00:00
|
|
|
Copyright 2006-2008 Xavier Guerrin
|
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"
|
|
|
|
#include "diagramtextitem.h"
|
|
|
|
#include "conductor.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur par defaut. Ne contient rien.
|
|
|
|
*/
|
|
|
|
DiagramContent::DiagramContent() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur de copie.
|
|
|
|
*/
|
|
|
|
DiagramContent::DiagramContent(const DiagramContent &other) :
|
|
|
|
elements(other.elements),
|
|
|
|
textFields(other.textFields),
|
|
|
|
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 {
|
|
|
|
QList<Conductor *> result;
|
|
|
|
if (filter & ConductorsToMove) result += conductorsToMove;
|
|
|
|
if (filter & ConductorsToUpdate) result += conductorsToUpdate.keys();
|
|
|
|
if (filter & OtherConductors) result += otherConductors;
|
|
|
|
return(result);
|
2007-11-09 13:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Vide le conteneur
|
|
|
|
*/
|
|
|
|
void DiagramContent::clear() {
|
|
|
|
elements.clear();
|
|
|
|
textFields.clear();
|
|
|
|
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;
|
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;
|
|
|
|
if (filter & Elements) count += elements.count();
|
|
|
|
if (filter & TextFields) count += textFields.count();
|
|
|
|
if (filter & ConductorsToMove) count += conductorsToMove.count();
|
|
|
|
if (filter & ConductorsToUpdate) count += conductorsToUpdate.count();
|
|
|
|
if (filter & OtherConductors) count += otherConductors.count();
|
|
|
|
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;
|
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,
|
2007-11-11 16:12:45 +00:00
|
|
|
textfields_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
|
|
|
|
@param c Contenu de schema a debugger
|
|
|
|
*/
|
|
|
|
QDebug &operator<<(QDebug d, DiagramContent &c) {
|
|
|
|
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";
|
|
|
|
d << " conductorsToUpdate :" << c.conductorsToUpdate.keys() << "\n";
|
|
|
|
d << " conductorsToMove :" << c.conductorsToMove << "\n";
|
|
|
|
d << " otherConductors :" << c.otherConductors << "\n";
|
|
|
|
d << "}";
|
2008-07-09 21:14:30 +00:00
|
|
|
*/
|
2007-11-11 16:12:45 +00:00
|
|
|
return(d.space());
|
|
|
|
}
|