Fix code style

This commit is contained in:
Simon De Backer
2020-10-13 17:44:08 +02:00
parent 106b17cf2f
commit 364012848c

View File

@@ -1,17 +1,17 @@
/* /*
Copyright 2006-2020 The QElectroTech Team Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech. This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or the Free Software Foundation, either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
QElectroTech is distributed in the hope that it will be useful, QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -94,7 +94,8 @@ ElementScene::~ElementScene()
@brief ElementScene::mouseMoveEvent @brief ElementScene::mouseMoveEvent
@param e @param e
*/ */
void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
{
if (m_event_interface) { if (m_event_interface) {
if (m_event_interface -> mouseMoveEvent(e)) { if (m_event_interface -> mouseMoveEvent(e)) {
if (m_event_interface->isFinish()) { if (m_event_interface->isFinish()) {
@@ -109,7 +110,7 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
QPointF event_pos = e -> scenePos(); QPointF event_pos = e -> scenePos();
if (!(e -> modifiers() & Qt::ControlModifier)) if (!(e -> modifiers() & Qt::ControlModifier))
event_pos = snapToGrid(event_pos); event_pos = snapToGrid(event_pos);
if (m_behavior == PasteArea) { if (m_behavior == PasteArea) {
QRectF current_rect(m_paste_area -> rect()); QRectF current_rect(m_paste_area -> rect());
current_rect.moveCenter(event_pos); current_rect.moveCenter(event_pos);
@@ -118,14 +119,15 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
} }
QGraphicsScene::mouseMoveEvent(e); QGraphicsScene::mouseMoveEvent(e);
} }
/** /**
@brief ElementScene::mousePressEvent @brief ElementScene::mousePressEvent
@param e @param e
*/ */
void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
if (m_event_interface) { if (m_event_interface) {
if (m_event_interface -> mousePressEvent(e)) { if (m_event_interface -> mousePressEvent(e)) {
if (m_event_interface->isFinish()) { if (m_event_interface->isFinish()) {
@@ -144,7 +146,8 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
@brief ElementScene::mouseReleaseEvent @brief ElementScene::mouseReleaseEvent
@param e @param e
*/ */
void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
{
if (m_event_interface) { if (m_event_interface) {
if (m_event_interface -> mouseReleaseEvent(e)) { if (m_event_interface -> mouseReleaseEvent(e)) {
if (m_event_interface->isFinish()) { if (m_event_interface->isFinish()) {
@@ -155,7 +158,7 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
return; return;
} }
} }
if (m_behavior == PasteArea) { if (m_behavior == PasteArea) {
m_defined_paste_area = m_paste_area -> rect(); m_defined_paste_area = m_paste_area -> rect();
removeItem(m_paste_area); removeItem(m_paste_area);
@@ -171,7 +174,8 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
@brief ElementScene::mouseDoubleClickEvent @brief ElementScene::mouseDoubleClickEvent
@param event @param event
*/ */
void ElementScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { void ElementScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if (m_event_interface) { if (m_event_interface) {
if (m_event_interface -> mouseDoubleClickEvent(event)) { if (m_event_interface -> mouseDoubleClickEvent(event)) {
if (m_event_interface->isFinish()) { if (m_event_interface->isFinish()) {
@@ -206,7 +210,7 @@ void ElementScene::keyPressEvent(QKeyEvent *event)
return; return;
} }
} }
if(selectedItems().size() == 1) if(selectedItems().size() == 1)
{ {
if(selectedItems().first()->type() == PartText::Type) if(selectedItems().first()->type() == PartText::Type)
@@ -218,15 +222,15 @@ void ElementScene::keyPressEvent(QKeyEvent *event)
return; return;
} }
} }
QGraphicsObject *qgo = selectedItems().first()->toGraphicsObject(); QGraphicsObject *qgo = selectedItems().first()->toGraphicsObject();
if(qgo) if(qgo)
{ {
QPointF original_pos = qgo->pos(); QPointF original_pos = qgo->pos();
QPointF p = qgo->pos(); QPointF p = qgo->pos();
if (event->modifiers() & Qt::ControlModifier) { if (event->modifiers() & Qt::ControlModifier) {
int k = event->key(); int k = event->key();
if(k == Qt::Key_Right) if(k == Qt::Key_Right)
p.rx() += 0.1; p.rx() += 0.1;
@@ -238,7 +242,7 @@ void ElementScene::keyPressEvent(QKeyEvent *event)
p.ry() += 0.1; p.ry() += 0.1;
} }
else { else {
int k = event->key(); int k = event->key();
if(k == Qt::Key_Right) if(k == Qt::Key_Right)
p.rx() += 1; p.rx() += 1;
@@ -249,13 +253,11 @@ void ElementScene::keyPressEvent(QKeyEvent *event)
else if (k == Qt::Key_Down) else if (k == Qt::Key_Down)
p.ry() += 1; p.ry() += 1;
} }
qgo->setPos(p); qgo->setPos(p);
QPropertyUndoCommand *undo = QPropertyUndoCommand *undo =
new QPropertyUndoCommand(qgo, new QPropertyUndoCommand(
"pos", qgo,"pos",QVariant(original_pos),QVariant(p));
QVariant(original_pos),
QVariant(p));
undo->setText(tr("Déplacer une primitive")); undo->setText(tr("Déplacer une primitive"));
undo->enableAnimation(); undo->enableAnimation();
undoStack().push(undo); undoStack().push(undo);
@@ -263,7 +265,7 @@ void ElementScene::keyPressEvent(QKeyEvent *event)
return; return;
} }
} }
QGraphicsScene::keyPressEvent(event); QGraphicsScene::keyPressEvent(event);
} }
@@ -277,7 +279,7 @@ void ElementScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QGraphicsScene::contextMenuEvent(event); QGraphicsScene::contextMenuEvent(event);
if(event->isAccepted()) if(event->isAccepted())
return; return;
if (m_behavior == ElementScene::Normal) if (m_behavior == ElementScene::Normal)
m_element_editor -> contextMenu(event->screenPos()); m_element_editor -> contextMenu(event->screenPos());
} }
@@ -343,7 +345,8 @@ void ElementScene::clearEventInterface()
\~French Modifie the current behavior of this scene \~French Modifie the current behavior of this scene
\~ @param b \~ @param b
*/ */
void ElementScene::setBehavior(ElementScene::Behavior b) { void ElementScene::setBehavior(ElementScene::Behavior b)
{
m_behavior = b; m_behavior = b;
} }
@@ -379,7 +382,8 @@ int ElementScene::yGrid() const
\~ @param y_g : Vertical grid size \~ @param y_g : Vertical grid size
\~French Taille verticale de la grille \~French Taille verticale de la grille
*/ */
void ElementScene::setGrid(int x_g, int y_g) { void ElementScene::setGrid(int x_g, int y_g)
{
m_x_grid = x_g ? x_g : 1; m_x_grid = x_g ? x_g : 1;
m_y_grid = y_g ? y_g : 1; m_y_grid = y_g ? y_g : 1;
} }
@@ -438,7 +442,7 @@ const QDomDocument ElementScene::toXml(bool all_parts)
QDomElement uuid = xml_document.createElement("uuid"); QDomElement uuid = xml_document.createElement("uuid");
uuid.setAttribute("uuid", QUuid::createUuid().toString()); uuid.setAttribute("uuid", QUuid::createUuid().toString());
root.appendChild(uuid); root.appendChild(uuid);
//names of element //names of element
root.appendChild(m_names_list.toXml(xml_document)); root.appendChild(m_names_list.toXml(xml_document));
@@ -448,7 +452,7 @@ const QDomDocument ElementScene::toXml(bool all_parts)
m_elmt_kindInfo.toXml(kindInfo, "kindInformation"); m_elmt_kindInfo.toXml(kindInfo, "kindInformation");
root.appendChild(kindInfo); root.appendChild(kindInfo);
} }
if( if(
m_elmt_type == "simple" m_elmt_type == "simple"
|| m_elmt_type == "master" || m_elmt_type == "master"
@@ -458,12 +462,12 @@ const QDomDocument ElementScene::toXml(bool all_parts)
m_elmt_information.toXml(element_info, "elementInformation"); m_elmt_information.toXml(element_info, "elementInformation");
root.appendChild(element_info); root.appendChild(element_info);
} }
//complementary information about the element //complementary information about the element
QDomElement informations_element = xml_document.createElement("informations"); QDomElement informations_element = xml_document.createElement("informations");
root.appendChild(informations_element); root.appendChild(informations_element);
informations_element.appendChild(xml_document.createTextNode(informations())); informations_element.appendChild(xml_document.createTextNode(informations()));
QDomElement description = xml_document.createElement("description"); QDomElement description = xml_document.createElement("description");
//the graphic description of the element //the graphic description of the element
@@ -478,7 +482,7 @@ const QDomDocument ElementScene::toXml(bool all_parts)
} }
} }
root.appendChild(description); root.appendChild(description);
xml_document.appendChild(root); xml_document.appendChild(root);
return(xml_document); return(xml_document);
} }
@@ -490,20 +494,21 @@ const QDomDocument ElementScene::toXml(bool all_parts)
\~ @return the boundingRect of the element's content \~ @return the boundingRect of the element's content
\~French le boundingRect du contenu de l'element \~French le boundingRect du contenu de l'element
*/ */
QRectF ElementScene::boundingRectFromXml(const QDomDocument &xml_document) { QRectF ElementScene::boundingRectFromXml(const QDomDocument &xml_document)
{
// load parts from XML document // load parts from XML document
// charge les parties depuis le document XML // charge les parties depuis le document XML
ElementContent loaded_content = loadContent(xml_document); ElementContent loaded_content = loadContent(xml_document);
if (loaded_content.isEmpty()) return(QRectF()); if (loaded_content.isEmpty()) return(QRectF());
// calcule the boundingRect // calcule the boundingRect
// calcule le boundingRect // calcule le boundingRect
QRectF bounding_rect = elementContentBoundingRect(loaded_content); QRectF bounding_rect = elementContentBoundingRect(loaded_content);
// destroy charged parties // destroy charged parties
// detruit les parties chargees // detruit les parties chargees
qDeleteAll(loaded_content); qDeleteAll(loaded_content);
return(bounding_rect); return(bounding_rect);
} }
@@ -531,18 +536,19 @@ QRectF ElementScene::boundingRectFromXml(const QDomDocument &xml_document) {
\~French si ce pointeur vers un ElementContent est different de 0, \~French si ce pointeur vers un ElementContent est different de 0,
il sera rempli avec le contenu ajoute a l'element par le fromXml il sera rempli avec le contenu ajoute a l'element par le fromXml
*/ */
void ElementScene::fromXml(const QDomDocument &xml_document, void ElementScene::fromXml(
const QPointF &position, const QDomDocument &xml_document,
bool consider_informations, const QPointF &position,
ElementContent *content_ptr) bool consider_informations,
ElementContent *content_ptr)
{ {
bool state = true; bool state = true;
//Consider the informations of the element //Consider the informations of the element
if (consider_informations) { if (consider_informations) {
state = applyInformations(xml_document); state = applyInformations(xml_document);
} }
if (state) if (state)
{ {
ElementContent loaded_content = loadContent(xml_document); ElementContent loaded_content = loadContent(xml_document);
@@ -550,7 +556,7 @@ void ElementScene::fromXml(const QDomDocument &xml_document,
addContentAtPos(loaded_content, position); addContentAtPos(loaded_content, position);
else else
addContent(loaded_content); addContent(loaded_content);
if (content_ptr) if (content_ptr)
*content_ptr = loaded_content; *content_ptr = loaded_content;
} }
@@ -563,7 +569,8 @@ void ElementScene::fromXml(const QDomDocument &xml_document,
It is different from itemsBoundingRect() because it is not supposed It is different from itemsBoundingRect() because it is not supposed
to imply any margin. to imply any margin.
*/ */
QRectF ElementScene::elementSceneGeometricRect() const{ QRectF ElementScene::elementSceneGeometricRect() const
{
QRectF esgr; QRectF esgr;
foreach (QGraphicsItem *qgi, items()) { foreach (QGraphicsItem *qgi, items()) {
if (qgi->type() == ElementPrimitiveDecorator::Type) continue; if (qgi->type() == ElementPrimitiveDecorator::Type) continue;
@@ -585,8 +592,10 @@ QRectF ElementScene::elementSceneGeometricRect() const{
*/ */
bool ElementScene::containsTerminals() const bool ElementScene::containsTerminals() const
{ {
foreach(QGraphicsItem *qgi,items()) { foreach(QGraphicsItem *qgi,items())
if (qgraphicsitem_cast<PartTerminal *>(qgi)) { {
if (qgraphicsitem_cast<PartTerminal *>(qgi))
{
return(true); return(true);
} }
} }
@@ -635,7 +644,8 @@ bool ElementScene::clipboardMayContainElement()
true if clipboard_content has been copied from this element. true if clipboard_content has been copied from this element.
\~French true si clipboard_content a ete copie depuis cet element. \~French true si clipboard_content a ete copie depuis cet element.
*/ */
bool ElementScene::wasCopiedFromThisElement(const QString &clipboard_content) { bool ElementScene::wasCopiedFromThisElement(const QString &clipboard_content)
{
return(clipboard_content == m_last_copied); return(clipboard_content == m_last_copied);
} }
@@ -665,16 +675,16 @@ void ElementScene::copy()
{ {
// accede au presse-papier // accede au presse-papier
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
// genere la description XML de la selection // genere la description XML de la selection
QString clipboard_content = toXml(false).toString(4); QString clipboard_content = toXml(false).toString(4);
// met la description XML dans le presse-papier // met la description XML dans le presse-papier
if (clipboard -> supportsSelection()) { if (clipboard -> supportsSelection()) {
clipboard -> setText(clipboard_content, QClipboard::Selection); clipboard -> setText(clipboard_content, QClipboard::Selection);
} }
clipboard -> setText(clipboard_content); clipboard -> setText(clipboard_content);
// retient le dernier contenu copie // retient le dernier contenu copie
m_last_copied = clipboard_content; m_last_copied = clipboard_content;
} }
@@ -710,7 +720,7 @@ void ElementScene::setElementInfo(const DiagramContext& dc)
void ElementScene::slot_select(const ElementContent &content) void ElementScene::slot_select(const ElementContent &content)
{ {
blockSignals(true); blockSignals(true);
/* Befor clear selection, /* Befor clear selection,
* we must to remove the handlers items in @content, * we must to remove the handlers items in @content,
* because if in @content there are a selected item, * because if in @content there are a selected item,
@@ -728,7 +738,7 @@ void ElementScene::slot_select(const ElementContent &content)
foreach(QGraphicsItem *qgi, items_list) foreach(QGraphicsItem *qgi, items_list)
qgi -> setSelected(true); qgi -> setSelected(true);
blockSignals(false); blockSignals(false);
emit(selectionChanged()); emit(selectionChanged());
} }
@@ -776,11 +786,11 @@ void ElementScene::slot_delete()
// verifie qu'il y a qqc de selectionne // verifie qu'il y a qqc de selectionne
QList<QGraphicsItem *> selected_items = selectedItems(); QList<QGraphicsItem *> selected_items = selectedItems();
if (selected_items.isEmpty()) return; if (selected_items.isEmpty()) return;
// erase everything that is selected // erase everything that is selected
// efface tout ce qui est selectionne // efface tout ce qui est selectionne
m_undo_stack.push(new DeletePartsCommand(this, selected_items)); m_undo_stack.push(new DeletePartsCommand(this, selected_items));
// removing items does not trigger QGraphicsScene::selectionChanged() // removing items does not trigger QGraphicsScene::selectionChanged()
emit(partsRemoved()); emit(partsRemoved());
emit(selectionChanged()); emit(selectionChanged());
@@ -798,7 +808,7 @@ void ElementScene::slot_delete()
void ElementScene::slot_editAuthorInformations() void ElementScene::slot_editAuthorInformations()
{ {
bool is_read_only = m_element_editor && m_element_editor -> isReadOnly(); bool is_read_only = m_element_editor && m_element_editor -> isReadOnly();
// create a dialogue // create a dialogue
// cree un dialogue // cree un dialogue
QDialog dialog_author(m_element_editor); QDialog dialog_author(m_element_editor);
@@ -807,9 +817,10 @@ void ElementScene::slot_editAuthorInformations()
dialog_author.setWindowFlags(Qt::Sheet); dialog_author.setWindowFlags(Qt::Sheet);
#endif #endif
dialog_author.setMinimumSize(400, 260); dialog_author.setMinimumSize(400, 260);
dialog_author.setWindowTitle(tr("Éditer les informations sur l'auteur", "window title")); dialog_author.setWindowTitle(
tr("Éditer les informations sur l'auteur", "window title"));
QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_author); QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_author);
// adds an explanatory field to the dialogue // adds an explanatory field to the dialogue
// ajoute un champ explicatif au dialogue // ajoute un champ explicatif au dialogue
QLabel *information_label = new QLabel(tr("Vous pouvez utiliser ce champ libre pour mentionner les auteurs de l'élément, sa licence, ou tout autre renseignement que vous jugerez utile.")); QLabel *information_label = new QLabel(tr("Vous pouvez utiliser ce champ libre pour mentionner les auteurs de l'élément, sa licence, ou tout autre renseignement que vous jugerez utile."));
@@ -824,22 +835,25 @@ void ElementScene::slot_editAuthorInformations()
text_field -> setPlainText(informations()); text_field -> setPlainText(informations());
text_field -> setReadOnly(is_read_only); text_field -> setReadOnly(is_read_only);
dialog_layout -> addWidget(text_field); dialog_layout -> addWidget(text_field);
// ajoute deux boutons au dialogue // ajoute deux boutons au dialogue
QDialogButtonBox *dialog_buttons = new QDialogButtonBox( QDialogButtonBox *dialog_buttons = new QDialogButtonBox(
is_read_only ? QDialogButtonBox::Ok : is_read_only ? QDialogButtonBox::Ok :
QDialogButtonBox::Ok QDialogButtonBox::Ok
| QDialogButtonBox::Cancel); | QDialogButtonBox::Cancel);
dialog_layout -> addWidget(dialog_buttons); dialog_layout -> addWidget(dialog_buttons);
connect(dialog_buttons, SIGNAL(accepted()),&dialog_author, SLOT(accept())); connect(dialog_buttons, SIGNAL(accepted()),&dialog_author, SLOT(accept()));
connect(dialog_buttons, SIGNAL(rejected()),&dialog_author, SLOT(reject())); connect(dialog_buttons, SIGNAL(rejected()),&dialog_author, SLOT(reject()));
// start the dialogue // start the dialogue
// lance le dialogue // lance le dialogue
if (dialog_author.exec() == QDialog::Accepted && !is_read_only) { if (dialog_author.exec() == QDialog::Accepted && !is_read_only)
{
QString new_infos = text_field -> toPlainText().remove(QChar(13)); // CR-less text QString new_infos = text_field -> toPlainText().remove(QChar(13)); // CR-less text
if (new_infos != informations()) { if (new_infos != informations())
undoStack().push(new ChangeInformationsCommand(this, informations(), new_infos)); {
undoStack().push(new ChangeInformationsCommand(
this, informations(), new_infos));
} }
} }
} }
@@ -853,17 +867,17 @@ void ElementScene::slot_editProperties()
QString type = m_elmt_type; QString type = m_elmt_type;
DiagramContext kind_info = m_elmt_kindInfo; DiagramContext kind_info = m_elmt_kindInfo;
DiagramContext elmt_info = m_elmt_information; DiagramContext elmt_info = m_elmt_information;
ElementPropertiesEditorWidget epew(type, kind_info, elmt_info); ElementPropertiesEditorWidget epew(type, kind_info, elmt_info);
epew.exec(); epew.exec();
if (type != m_elmt_type || if (type != m_elmt_type ||
kind_info != m_elmt_kindInfo || kind_info != m_elmt_kindInfo ||
elmt_info != m_elmt_information) elmt_info != m_elmt_information)
undoStack().push(new ChangePropertiesCommand(this, undoStack().push(new ChangePropertiesCommand(this,
type, type,
kind_info, kind_info,
elmt_info)); elmt_info));
} }
/** /**
@@ -873,19 +887,19 @@ void ElementScene::slot_editProperties()
void ElementScene::slot_editNames() void ElementScene::slot_editNames()
{ {
bool is_read_only = m_element_editor && m_element_editor -> isReadOnly(); bool is_read_only = m_element_editor && m_element_editor -> isReadOnly();
NameListDialog dialog_(m_element_editor); NameListDialog dialog_(m_element_editor);
dialog_.setModal(true); dialog_.setModal(true);
dialog_.setMinimumSize(400, 330); dialog_.setMinimumSize(400, 330);
dialog_.setWindowTitle(tr("Éditer les noms", "window title")); dialog_.setWindowTitle(tr("Éditer les noms", "window title"));
dialog_.setInformationText(tr("Vous pouvez spécifier le nom de l'élément dans plusieurs langues.")); dialog_.setInformationText(tr("Vous pouvez spécifier le nom de l'élément dans plusieurs langues."));
NameListWidget *nlw_ = dialog_.namelistWidget(); NameListWidget *nlw_ = dialog_.namelistWidget();
nlw_->setNames(m_names_list); nlw_->setNames(m_names_list);
nlw_->setReadOnly(is_read_only); nlw_->setReadOnly(is_read_only);
if (dialog_.exec() == QDialog::Accepted && !is_read_only && !nlw_->isEmpty()) if (dialog_.exec() == QDialog::Accepted && !is_read_only && !nlw_->isEmpty())
{ {
NamesList new_names = nlw_->names(); NamesList new_names = nlw_->names();
@@ -904,8 +918,10 @@ void ElementScene::slot_editNames()
QList<CustomElementPart *> ElementScene::primitives() const QList<CustomElementPart *> ElementScene::primitives() const
{ {
QList<CustomElementPart *> primitives_list; QList<CustomElementPart *> primitives_list;
foreach (QGraphicsItem *item, items()) { foreach (QGraphicsItem *item, items())
if (CustomElementPart *primitive = dynamic_cast<CustomElementPart *>(item)) { {
if (CustomElementPart *primitive = dynamic_cast<CustomElementPart *>(item))
{
primitives_list << primitive; primitives_list << primitive;
} }
} }
@@ -923,14 +939,15 @@ QList<QGraphicsItem *> ElementScene::zItems(ItemOptions options) const
// handle dummy request, i.e. when neither Selected nor NonSelected are set // handle dummy request, i.e. when neither Selected nor NonSelected are set
if (!(options & ElementScene::Selected) if (!(options & ElementScene::Selected)
&& &&
!(options & ElementScene::NonSelected)) { !(options & ElementScene::NonSelected))
{
return(QList<QGraphicsItem *>()); return(QList<QGraphicsItem *>());
} }
// retrieve all items // retrieve all items
QList<QGraphicsItem *> all_items_list(items()); QList<QGraphicsItem *> all_items_list(items());
QMutableListIterator<QGraphicsItem *> i(all_items_list); QMutableListIterator<QGraphicsItem *> i(all_items_list);
// remove unrequired items // remove unrequired items
if ((options & ElementScene::SelectedOrNot) if ((options & ElementScene::SelectedOrNot)
!= ElementScene::SelectedOrNot) { != ElementScene::SelectedOrNot) {
@@ -941,10 +958,11 @@ QList<QGraphicsItem *> ElementScene::zItems(ItemOptions options) const
} }
} }
} }
QList<QGraphicsItem *> terminals; QList<QGraphicsItem *> terminals;
QList<QGraphicsItem *> helpers; QList<QGraphicsItem *> helpers;
for (i.toFront(); i.hasNext(); ) { for (i.toFront(); i.hasNext(); )
{
i.next(); i.next();
QGraphicsItem *qgi = i.value(); QGraphicsItem *qgi = i.value();
if ( if (
@@ -955,26 +973,31 @@ QList<QGraphicsItem *> ElementScene::zItems(ItemOptions options) const
i.remove(); i.remove();
helpers << qgi; helpers << qgi;
} }
else if (qgraphicsitem_cast<PartTerminal *>(qgi)) { else if (qgraphicsitem_cast<PartTerminal *>(qgi))
{
i.remove(); i.remove();
terminals << qgi; terminals << qgi;
} }
} }
// orders the parts by their zValue // orders the parts by their zValue
// ordonne les parties par leur zValue // ordonne les parties par leur zValue
if (options & SortByZValue) { if (options & SortByZValue)
std::sort (all_items_list.begin(), {
all_items_list.end(), std::sort (
ElementScene::zValueLessThan); all_items_list.begin(),
all_items_list.end(),
ElementScene::zValueLessThan);
} }
// possibly add the limits // possibly add the limits
// rajoute eventuellement les bornes // rajoute eventuellement les bornes
if (options & ElementScene::IncludeTerminals) { if (options & ElementScene::IncludeTerminals)
{
all_items_list += terminals; all_items_list += terminals;
} }
if (options & ElementScene::IncludeHelperItems) { if (options & ElementScene::IncludeHelperItems)
{
all_items_list += helpers; all_items_list += helpers;
} }
return(all_items_list); return(all_items_list);
@@ -988,7 +1011,8 @@ QList<QGraphicsItem *> ElementScene::zItems(ItemOptions options) const
ElementContent ElementScene::selectedContent() const ElementContent ElementScene::selectedContent() const
{ {
ElementContent content; ElementContent content;
foreach(QGraphicsItem *qgi, zItems()) { foreach(QGraphicsItem *qgi, zItems())
{
if (qgi -> isSelected()) content << qgi; if (qgi -> isSelected()) content << qgi;
} }
return(content); return(content);
@@ -1001,7 +1025,8 @@ ElementContent ElementScene::selectedContent() const
\~ @return the rectangle where you will have to glue these parts \~ @return the rectangle where you will have to glue these parts
\~French le rectangle ou il faudra coller ces parties \~French le rectangle ou il faudra coller ces parties
*/ */
void ElementScene::getPasteArea(const QRectF &to_paste) { void ElementScene::getPasteArea(const QRectF &to_paste)
{
// we draw it on the stage // we draw it on the stage
// on le dessine sur la scene // on le dessine sur la scene
m_paste_area -> setRect(to_paste); m_paste_area -> setRect(to_paste);
@@ -1028,7 +1053,7 @@ void ElementScene::reset()
if(qgi->type() != QetGraphicsHandlerItem::Type) if(qgi->type() != QetGraphicsHandlerItem::Type)
items_list << qgi; items_list << qgi;
} }
for (QGraphicsItem *qgi : items_list) for (QGraphicsItem *qgi : items_list)
{ {
removeItem(qgi); removeItem(qgi);
@@ -1079,7 +1104,7 @@ bool ElementScene::applyInformations(const QDomDocument &xml_document)
{ {
// Root must be an element definition // Root must be an element definition
QDomElement root = xml_document.documentElement(); QDomElement root = xml_document.documentElement();
if ( if (
root.tagName() != "definition" root.tagName() != "definition"
|| ||
@@ -1098,12 +1123,12 @@ bool ElementScene::applyInformations(const QDomDocument &xml_document)
//Extract names of xml definition //Extract names of xml definition
m_names_list.fromXml(root); m_names_list.fromXml(root);
//extract additional informations //extract additional informations
setInformations(QString()); setInformations(QString());
for (QDomNode node = root.firstChild() ; for (QDomNode node = root.firstChild() ;
!node.isNull() ; !node.isNull() ;
node = node.nextSibling()) node = node.nextSibling())
{ {
QDomElement elmt = node.toElement(); QDomElement elmt = node.toElement();
if (elmt.isNull()) continue; if (elmt.isNull()) continue;
@@ -1113,7 +1138,7 @@ bool ElementScene::applyInformations(const QDomDocument &xml_document)
break; break;
} }
} }
return(true); return(true);
} }
@@ -1126,20 +1151,20 @@ bool ElementScene::applyInformations(const QDomDocument &xml_document)
ElementContent ElementScene::loadContent(const QDomDocument &xml_document) ElementContent ElementScene::loadContent(const QDomDocument &xml_document)
{ {
ElementContent loaded_parts; ElementContent loaded_parts;
// The root is supposed to be an element definition // The root is supposed to be an element definition
QDomElement root = xml_document.documentElement(); QDomElement root = xml_document.documentElement();
if (root.tagName() != "definition" || root.attribute("type") != "element") if (root.tagName() != "definition" || root.attribute("type") != "element")
return(loaded_parts); return(loaded_parts);
//Load the graphic description of the element //Load the graphic description of the element
for (QDomNode node = root.firstChild() ; !node.isNull() ; node = node.nextSibling()) for (QDomNode node = root.firstChild() ; !node.isNull() ; node = node.nextSibling())
{ {
QDomElement elmts = node.toElement(); QDomElement elmts = node.toElement();
if (elmts.isNull()) if (elmts.isNull())
continue; continue;
if (elmts.tagName() == "description") if (elmts.tagName() == "description")
{ {
int z = 1; int z = 1;
@@ -1150,7 +1175,7 @@ ElementContent ElementScene::loadContent(const QDomDocument &xml_document)
continue; continue;
CustomElementPart *cep = nullptr; CustomElementPart *cep = nullptr;
PartDynamicTextField *pdtf = nullptr; PartDynamicTextField *pdtf = nullptr;
if (qde.tagName() == "line") cep = new PartLine (m_element_editor); if (qde.tagName() == "line") cep = new PartLine (m_element_editor);
else if (qde.tagName() == "rect") cep = new PartRectangle(m_element_editor); else if (qde.tagName() == "rect") cep = new PartRectangle(m_element_editor);
else if (qde.tagName() == "ellipse") cep = new PartEllipse (m_element_editor); else if (qde.tagName() == "ellipse") cep = new PartEllipse (m_element_editor);
@@ -1163,14 +1188,14 @@ ElementContent ElementScene::loadContent(const QDomDocument &xml_document)
//For the input (aka the old text field) we try to convert it to the new partDynamicTextField //For the input (aka the old text field) we try to convert it to the new partDynamicTextField
else if (qde.tagName() == "input") cep = pdtf = new PartDynamicTextField(m_element_editor); else if (qde.tagName() == "input") cep = pdtf = new PartDynamicTextField(m_element_editor);
else continue; else continue;
if (QGraphicsItem *qgi = dynamic_cast<QGraphicsItem *>(cep)) if (QGraphicsItem *qgi = dynamic_cast<QGraphicsItem *>(cep))
{ {
if (!qgi->zValue()) if (!qgi->zValue())
qgi->setZValue(z++); qgi->setZValue(z++);
loaded_parts<<qgi; loaded_parts<<qgi;
if(pdtf) if(pdtf)
pdtf->fromTextFieldXml(qde); pdtf->fromTextFieldXml(qde);
else else
@@ -1181,7 +1206,7 @@ ElementContent ElementScene::loadContent(const QDomDocument &xml_document)
} }
} }
} }
return(loaded_parts); return(loaded_parts);
} }
@@ -1195,7 +1220,8 @@ ElementContent ElementScene::loadContent(const QDomDocument &xml_document)
\~ @return Content adds \~ @return Content adds
\~French Le contenu ajoute \~French Le contenu ajoute
*/ */
ElementContent ElementScene::addContent(const ElementContent &content) { ElementContent ElementScene::addContent(const ElementContent &content)
{
foreach(QGraphicsItem *part, content) { foreach(QGraphicsItem *part, content) {
addPrimitive(part); addPrimitive(part);
} }
@@ -1215,19 +1241,21 @@ ElementContent ElementScene::addContent(const ElementContent &content) {
\~ @return Content adds \~ @return Content adds
\~French Le contenu ajoute \~French Le contenu ajoute
*/ */
ElementContent ElementScene::addContentAtPos(const ElementContent &content, ElementContent ElementScene::addContentAtPos(
const QPointF &pos) { const ElementContent &content,
const QPointF &pos)
{
// calculate the boundingRect of the content to add // calculate the boundingRect of the content to add
// calcule le boundingRect du contenu a ajouter // calcule le boundingRect du contenu a ajouter
QRectF bounding_rect = elementContentBoundingRect(content); QRectF bounding_rect = elementContentBoundingRect(content);
/* deduced the offset to be applied to the parts to place /* deduced the offset to be applied to the parts to place
* them at the point requested * them at the point requested
* en deduit le decalage a appliquer aux parties pour les poser * en deduit le decalage a appliquer aux parties pour les poser
* au point demander * au point demander
*/ */
QPointF offset = pos - bounding_rect.topLeft(); QPointF offset = pos - bounding_rect.topLeft();
// add the parts with the correct offset // add the parts with the correct offset
// ajoute les parties avec le decalage adequat // ajoute les parties avec le decalage adequat
foreach(QGraphicsItem *part, content) { foreach(QGraphicsItem *part, content) {
@@ -1243,7 +1271,8 @@ ElementContent ElementScene::addContentAtPos(const ElementContent &content,
ElementPrimitiveDecorator group. ElementPrimitiveDecorator group.
@param primitive @param primitive
*/ */
void ElementScene::addPrimitive(QGraphicsItem *primitive) { void ElementScene::addPrimitive(QGraphicsItem *primitive)
{
if (!primitive) return; if (!primitive) return;
addItem(primitive); addItem(primitive);
} }
@@ -1257,15 +1286,15 @@ void ElementScene::initPasteArea()
{ {
m_paste_area = new QGraphicsRectItem(); m_paste_area = new QGraphicsRectItem();
m_paste_area -> setZValue(1000000); m_paste_area -> setZValue(1000000);
QPen paste_area_pen; QPen paste_area_pen;
paste_area_pen.setStyle(Qt::DashDotLine); paste_area_pen.setStyle(Qt::DashDotLine);
paste_area_pen.setColor(QColor(30, 56, 86, 255)); paste_area_pen.setColor(QColor(30, 56, 86, 255));
QBrush paste_area_brush; QBrush paste_area_brush;
paste_area_brush.setStyle(Qt::SolidPattern); paste_area_brush.setStyle(Qt::SolidPattern);
paste_area_brush.setColor(QColor(90, 167, 255, 64)); paste_area_brush.setColor(QColor(90, 167, 255, 64));
m_paste_area -> setPen(paste_area_pen); m_paste_area -> setPen(paste_area_pen);
m_paste_area -> setBrush(paste_area_brush); m_paste_area -> setBrush(paste_area_brush);
} }
@@ -1281,7 +1310,8 @@ void ElementScene::initPasteArea()
\~French une reference vers un QPointF. Cet objet sera modifie. \~French une reference vers un QPointF. Cet objet sera modifie.
\~ @return point \~ @return point
*/ */
QPointF ElementScene::snapToGrid(QPointF point) { QPointF ElementScene::snapToGrid(QPointF point)
{
point.rx() = qRound(point.x() / m_x_grid) * m_x_grid; point.rx() = qRound(point.x() / m_x_grid) * m_x_grid;
point.ry() = qRound(point.y() / m_y_grid) * m_y_grid; point.ry() = qRound(point.y() / m_y_grid) * m_y_grid;
return point; return point;
@@ -1293,7 +1323,8 @@ QPointF ElementScene::snapToGrid(QPointF point) {
@param item2 : QGraphicsItem @param item2 : QGraphicsItem
@return true if \a item1's zValue() is less than \a item2's. @return true if \a item1's zValue() is less than \a item2's.
*/ */
bool ElementScene::zValueLessThan(QGraphicsItem *item1, QGraphicsItem *item2) { bool ElementScene::zValueLessThan(QGraphicsItem *item1, QGraphicsItem *item2)
{
return(item1-> zValue() < item2 -> zValue()); return(item1-> zValue() < item2 -> zValue());
} }
@@ -1335,7 +1366,7 @@ void ElementScene::managePrimitivesGroups()
//this function is not supposed to be reentrant //this function is not supposed to be reentrant
if (!m_decorator_lock->tryLock()) if (!m_decorator_lock->tryLock())
return; return;
if (!m_decorator) if (!m_decorator)
{ {
m_decorator = new ElementPrimitiveDecorator(); m_decorator = new ElementPrimitiveDecorator();
@@ -1345,7 +1376,7 @@ void ElementScene::managePrimitivesGroups()
addItem(m_decorator); addItem(m_decorator);
m_decorator -> hide(); m_decorator -> hide();
} }
// should we hide the decorator? // should we hide the decorator?
QList<QGraphicsItem *> selected_items = zItems( QList<QGraphicsItem *> selected_items = zItems(
ElementScene::Selected ElementScene::Selected
@@ -1376,13 +1407,14 @@ void ElementScene::managePrimitivesGroups()
Push the provided \a command on the undo stack. Push the provided \a command on the undo stack.
@param command @param command
*/ */
void ElementScene::stackAction(ElementEditionCommand *command) { void ElementScene::stackAction(ElementEditionCommand *command)
{
if (command -> elementScene()) { if (command -> elementScene()) {
if (command -> elementScene() != this) return; if (command -> elementScene() != this) return;
} else { } else {
command -> setElementScene(this); command -> setElementScene(this);
} }
if (!command -> elementView()) { if (!command -> elementView()) {
foreach (QGraphicsView *view, views()) { foreach (QGraphicsView *view, views()) {
if (ElementView *element_view = if (ElementView *element_view =
@@ -1392,6 +1424,6 @@ void ElementScene::stackAction(ElementEditionCommand *command) {
} }
} }
} }
undoStack().push(command); undoStack().push(command);
} }