mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
First step for the dynamic element text : Now user can add directly from the diagram editor an editable text of an element.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5005 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
119
sources/undocommand/deleteqgraphicsitemcommand.cpp
Normal file
119
sources/undocommand/deleteqgraphicsitemcommand.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
Copyright 2006-2017 The QElectroTech Team
|
||||
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/>.
|
||||
*/
|
||||
#include "deleteqgraphicsitemcommand.h"
|
||||
#include "dynamicelementtextitem.h"
|
||||
#include "diagram.h"
|
||||
#include "element.h"
|
||||
#include "conductor.h"
|
||||
#include "conductortextitem.h"
|
||||
|
||||
/**
|
||||
* @brief DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand
|
||||
* @param diagram : deigram where this undo work
|
||||
* @param content : content to remove
|
||||
* @param parent : parent undo
|
||||
*/
|
||||
DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand(Diagram *diagram, const DiagramContent &content, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_removed_contents(content),
|
||||
m_diagram(diagram)
|
||||
{
|
||||
//If parent element of a dynamic element text item is also in @m_removed_content,
|
||||
//we remove it, because when the element will be removed from the scene every child's will also be removed.
|
||||
const QSet<DynamicElementTextItem *> elmt_set = m_removed_contents.m_element_texts;
|
||||
for(DynamicElementTextItem *deti : elmt_set)
|
||||
{
|
||||
if (m_removed_contents.m_elements.contains(deti->ParentElement()))
|
||||
m_removed_contents.m_element_texts.remove(deti);
|
||||
|
||||
}
|
||||
|
||||
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
|
||||
m_elmt_text_hash.insert(deti, deti->ParentElement());
|
||||
|
||||
setText(QString(QObject::tr("supprimer %1", "undo caption - %1 is a sentence listing the removed content")).arg(m_removed_contents.sentence(DiagramContent::All)));
|
||||
m_diagram->qgiManager().manage(m_removed_contents.items(DiagramContent::All));
|
||||
}
|
||||
|
||||
DeleteQGraphicsItemCommand::~DeleteQGraphicsItemCommand() {
|
||||
m_diagram->qgiManager().release(m_removed_contents.items(DiagramContent::All));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeleteQGraphicsItemCommand::undo
|
||||
* Undo this command
|
||||
*/
|
||||
void DeleteQGraphicsItemCommand::undo()
|
||||
{
|
||||
m_diagram->showMe();
|
||||
|
||||
for(QGraphicsItem *item : m_removed_contents.items())
|
||||
m_diagram->addItem(item);
|
||||
|
||||
//We relink element after every element was added to diagram
|
||||
for(Element *e : m_removed_contents.m_elements)
|
||||
for(Element *elmt : m_link_hash[e])
|
||||
e->linkToElement(elmt);
|
||||
|
||||
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
|
||||
{
|
||||
deti->setParentItem(m_elmt_text_hash.value(deti));
|
||||
m_elmt_text_hash.value(deti)->addDynamicTextItem(deti);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeleteQGraphicsItemCommand::redo
|
||||
* Redo the delete command
|
||||
*/
|
||||
void DeleteQGraphicsItemCommand::redo()
|
||||
{
|
||||
m_diagram -> showMe();
|
||||
|
||||
for(Conductor *c : m_removed_contents.conductors(DiagramContent::AnyConductor))
|
||||
{
|
||||
//If option one text per folio is enable, and the text item of
|
||||
//current conductor is visible (that mean the conductor have the single displayed text)
|
||||
//We call adjustTextItemPosition to other conductor at the same potential to keep
|
||||
//a visible text on this potential.
|
||||
if (m_diagram -> defaultConductorProperties.m_one_text_per_folio && c -> textItem() -> isVisible())
|
||||
{
|
||||
QList <Conductor *> conductor_list;
|
||||
conductor_list << c -> relatedPotentialConductors(false).toList();
|
||||
if (conductor_list.count())
|
||||
conductor_list.first() -> calculateTextItemPosition();
|
||||
}
|
||||
}
|
||||
|
||||
for(Element *e : m_removed_contents.m_elements)
|
||||
{
|
||||
//Get linked element, for relink it at undo
|
||||
if (!e->linkedElements().isEmpty())
|
||||
m_link_hash.insert(e, e->linkedElements());
|
||||
}
|
||||
|
||||
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
|
||||
{
|
||||
deti->ParentElement()->removeDynamicTextItem(deti);
|
||||
deti->setParentItem(nullptr);
|
||||
}
|
||||
|
||||
|
||||
for(QGraphicsItem *item : m_removed_contents.items())
|
||||
m_diagram->removeItem(item);
|
||||
}
|
||||
Reference in New Issue
Block a user