mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Revamp some code
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4047 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
27117ef9d1
commit
c31ae41910
@ -861,131 +861,78 @@ void Diagram::initElementsLinks() {
|
||||
|
||||
/**
|
||||
* @brief Diagram::addItem
|
||||
* Add element to diagram
|
||||
* @param element
|
||||
*/
|
||||
void Diagram::addItem(Element *element) {
|
||||
if (!element || isReadOnly()) return;
|
||||
|
||||
if (element -> scene() != this)
|
||||
QGraphicsScene::addItem(element);
|
||||
foreach(ElementTextItem *eti, element -> texts()) {
|
||||
connect(
|
||||
eti,
|
||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
||||
this,
|
||||
SLOT(diagramTextChanged(DiagramTextItem *, const QString &, const QString &))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::addItem
|
||||
* Add conductor to scene.
|
||||
* @param conductor
|
||||
*/
|
||||
void Diagram::addItem(Conductor *conductor) {
|
||||
if (!conductor || isReadOnly()) return;
|
||||
|
||||
if (conductor -> scene() != this) {
|
||||
QGraphicsScene::addItem(conductor);
|
||||
conductor -> terminal1 -> addConductor(conductor);
|
||||
conductor -> terminal2 -> addConductor(conductor);
|
||||
conductor -> calculateTextItemPosition();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::addItem
|
||||
* Add text item to diagram
|
||||
* @param iti
|
||||
*/
|
||||
void Diagram::addItem(IndependentTextItem *iti) {
|
||||
if (!iti || isReadOnly()) return;
|
||||
|
||||
if (iti -> scene() != this)
|
||||
QGraphicsScene::addItem(iti);
|
||||
|
||||
connect(
|
||||
iti,
|
||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
||||
this,
|
||||
SLOT(diagramTextChanged(DiagramTextItem *, const QString &, const QString &))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::addItem
|
||||
* Generique method to add item to scene
|
||||
* Réimplemented from QGraphicsScene::addItem(QGraphicsItem *item)
|
||||
* Do some specific operation if item need it (for exemple an element)
|
||||
* @param item
|
||||
*/
|
||||
void Diagram::addItem(QGraphicsItem *item) {
|
||||
void Diagram::addItem(QGraphicsItem *item)
|
||||
{
|
||||
if (!item || isReadOnly() || item->scene() == this) return;
|
||||
QGraphicsScene::addItem(item);
|
||||
|
||||
switch (item->type())
|
||||
{
|
||||
case Element::Type:
|
||||
{
|
||||
const Element *elmt = static_cast<const Element*>(item);
|
||||
foreach(ElementTextItem *eti, elmt->texts())
|
||||
connect (eti, &ElementTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
|
||||
}
|
||||
break;
|
||||
|
||||
case Conductor::Type:
|
||||
{
|
||||
Conductor *conductor = static_cast<Conductor *>(item);
|
||||
conductor->terminal1->addConductor(conductor);
|
||||
conductor->terminal2->addConductor(conductor);
|
||||
conductor->calculateTextItemPosition();
|
||||
}
|
||||
break;
|
||||
|
||||
case IndependentTextItem::Type:
|
||||
{
|
||||
const IndependentTextItem *text = static_cast<const IndependentTextItem *>(item);
|
||||
connect(text, &IndependentTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::removeItem
|
||||
* Réimplemented from QGraphicsScene::removeItem(QGraphicsItem *item)
|
||||
* Do some specific operation if item need it (for exemple an element)
|
||||
* @param item
|
||||
*/
|
||||
void Diagram::removeItem(QGraphicsItem *item)
|
||||
{
|
||||
if (!item || isReadOnly()) return;
|
||||
if (item -> scene() != this)
|
||||
QGraphicsScene::addItem(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::removeItem
|
||||
* Remove an element from the scene
|
||||
* @param element
|
||||
*/
|
||||
void Diagram::removeItem(Element *element) {
|
||||
if (!element || isReadOnly()) return;
|
||||
switch (item->type())
|
||||
{
|
||||
case Element::Type:
|
||||
{
|
||||
Element *elmt = static_cast<Element *>(item);
|
||||
elmt->unlinkAllElements();
|
||||
foreach(ElementTextItem *text, elmt->texts())
|
||||
disconnect(text, &ElementTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
|
||||
}
|
||||
break;
|
||||
|
||||
// remove all links of element
|
||||
element->unlinkAllElements();
|
||||
case Conductor::Type:
|
||||
{
|
||||
Conductor *conductor = static_cast<Conductor *>(item);
|
||||
conductor->terminal1->removeConductor(conductor);
|
||||
conductor->terminal2->removeConductor(conductor);
|
||||
}
|
||||
break;
|
||||
|
||||
QGraphicsScene::removeItem(element);
|
||||
|
||||
foreach(ElementTextItem *eti, element -> texts()) {
|
||||
disconnect(
|
||||
eti,
|
||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
||||
this,
|
||||
SLOT(diagramTextChanged(DiagramTextItem *, const QString &, const QString &))
|
||||
);
|
||||
case IndependentTextItem::Type:
|
||||
{
|
||||
const IndependentTextItem *text = static_cast<const IndependentTextItem *>(item);
|
||||
disconnect(text, &IndependentTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::removeItem
|
||||
* Remove a conductor from diagram
|
||||
* @param conductor
|
||||
*/
|
||||
void Diagram::removeItem(Conductor *conductor) {
|
||||
if (!conductor || isReadOnly()) return;
|
||||
|
||||
conductor -> terminal1 -> removeConductor(conductor);
|
||||
conductor -> terminal2 -> removeConductor(conductor);
|
||||
|
||||
QGraphicsScene::removeItem(conductor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::removeItem
|
||||
* Remove text field from diagram
|
||||
* @param iti
|
||||
*/
|
||||
void Diagram::removeItem(IndependentTextItem *iti) {
|
||||
if (!iti || isReadOnly()) return;
|
||||
|
||||
QGraphicsScene::removeItem(iti);
|
||||
|
||||
disconnect(
|
||||
iti,
|
||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
||||
this,
|
||||
SLOT(diagramTextChanged(DiagramTextItem *, const QString &, const QString &))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::removeItem
|
||||
* Generique methode to remove QGraphicsItem from diagram
|
||||
* @param item
|
||||
*/
|
||||
void Diagram::removeItem(QGraphicsItem *item) {
|
||||
QGraphicsScene::removeItem(item);
|
||||
}
|
||||
|
||||
|
@ -152,17 +152,10 @@ class Diagram : public QGraphicsScene
|
||||
bool wasWritten() const;
|
||||
QDomElement writeXml(QDomDocument &) const;
|
||||
|
||||
// methods related to graphics items addition/removal on the diagram
|
||||
// methods related to graphics items addition/removal on the diagram
|
||||
void initElementsLinks();
|
||||
virtual void addItem (Element *element);
|
||||
virtual void addItem (Conductor *conductor);
|
||||
virtual void addItem (IndependentTextItem *iti);
|
||||
virtual void addItem (QGraphicsItem *item);
|
||||
|
||||
virtual void removeItem (Element *element);
|
||||
virtual void removeItem (Conductor *conductor);
|
||||
virtual void removeItem (IndependentTextItem *iti);
|
||||
virtual void removeItem (QGraphicsItem *item);
|
||||
virtual void addItem (QGraphicsItem *item);
|
||||
virtual void removeItem (QGraphicsItem *item);
|
||||
|
||||
// methods related to graphics options
|
||||
ExportProperties applyProperties(const ExportProperties &);
|
||||
|
@ -74,140 +74,101 @@ DeleteElementsCommand::~DeleteElementsCommand() {
|
||||
diagram -> qgiManager().release(removed_content.items(DiagramContent::All));
|
||||
}
|
||||
|
||||
/// annule les suppressions
|
||||
void DeleteElementsCommand::undo() {
|
||||
/**
|
||||
* @brief DeleteElementsCommand::undo
|
||||
* Undo this command
|
||||
*/
|
||||
void DeleteElementsCommand::undo()
|
||||
{
|
||||
diagram -> showMe();
|
||||
|
||||
foreach(Element *e, removed_content.elements) {
|
||||
diagram -> addItem(e);
|
||||
}
|
||||
foreach(QGraphicsItem *item, removed_content.items())
|
||||
diagram->addItem(item);
|
||||
|
||||
//We relink element after every element was added to diagram
|
||||
foreach(Element *e, removed_content.elements) {
|
||||
foreach (Element *elmt, m_link_hash[e]) {
|
||||
//We relink element after every element was added to diagram
|
||||
foreach(Element *e, removed_content.elements)
|
||||
foreach (Element *elmt, m_link_hash[e])
|
||||
e -> linkToElement(elmt);
|
||||
}
|
||||
}
|
||||
|
||||
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
||||
diagram -> addItem(c);
|
||||
}
|
||||
|
||||
foreach(IndependentTextItem *t, removed_content.textFields) {
|
||||
diagram -> addItem(t);
|
||||
}
|
||||
|
||||
foreach(DiagramImageItem *dii, removed_content.images) {
|
||||
diagram -> addItem(dii);
|
||||
}
|
||||
|
||||
foreach(QetShapeItem *dsi, removed_content.shapes) {
|
||||
diagram -> addItem(dsi);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeleteElementsCommand::redo
|
||||
* Redo the delete command
|
||||
*/
|
||||
void DeleteElementsCommand::redo() {
|
||||
void DeleteElementsCommand::redo()
|
||||
{
|
||||
diagram -> showMe();
|
||||
|
||||
// Remove Conductor
|
||||
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
||||
diagram -> removeItem(c);
|
||||
|
||||
//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 (diagram -> defaultConductorProperties.m_one_text_per_folio && c -> textItem() -> isVisible()) {
|
||||
foreach(Conductor *c, removed_content.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 (diagram -> defaultConductorProperties.m_one_text_per_folio && c -> textItem() -> isVisible())
|
||||
{
|
||||
QList <Conductor *> conductor_list;
|
||||
conductor_list << c -> relatedPotentialConductors(false).toList();
|
||||
if (conductor_list.count()) {
|
||||
if (conductor_list.count())
|
||||
conductor_list.first() -> calculateTextItemPosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove elements
|
||||
foreach(Element *e, removed_content.elements) {
|
||||
//Get linked element, for relink it at undo
|
||||
foreach(Element *e, removed_content.elements)
|
||||
{
|
||||
//Get linked element, for relink it at undo
|
||||
if (!e->linkedElements().isEmpty())
|
||||
m_link_hash.insert(e, e->linkedElements());
|
||||
diagram -> removeItem(e);
|
||||
}
|
||||
|
||||
// Remove texts
|
||||
foreach(IndependentTextItem *t, removed_content.textFields) {
|
||||
diagram -> removeItem(t);
|
||||
}
|
||||
|
||||
// Remove images
|
||||
foreach(DiagramImageItem *dii, removed_content.images) {
|
||||
diagram -> removeItem(dii);
|
||||
}
|
||||
|
||||
// Remove shapes
|
||||
foreach(QetShapeItem *dsi, removed_content.shapes) {
|
||||
diagram -> removeItem(dsi);
|
||||
}
|
||||
foreach(QGraphicsItem *item, removed_content.items())
|
||||
diagram->removeItem(item);
|
||||
}
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param dia Schema sur lequel on colle les elements et conducteurs
|
||||
@param c Contenu a coller sur le schema
|
||||
@param parent QUndoCommand parent
|
||||
*/
|
||||
PasteDiagramCommand::PasteDiagramCommand(
|
||||
Diagram *dia,
|
||||
const DiagramContent &c,
|
||||
QUndoCommand *parent
|
||||
) :
|
||||
* @brief PasteDiagramCommand::PasteDiagramCommand
|
||||
* Constructor
|
||||
* @param dia : diagram where we must to paste
|
||||
* @param c : content to past
|
||||
* @param parent : parent undo command
|
||||
*/
|
||||
PasteDiagramCommand::PasteDiagramCommand( Diagram *dia, const DiagramContent &c, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
content(c),
|
||||
diagram(dia),
|
||||
filter(DiagramContent::Elements|DiagramContent::TextFields|DiagramContent::Images|DiagramContent::ConductorsToMove | DiagramContent::Shapes),
|
||||
first_redo(true)
|
||||
{
|
||||
|
||||
setText(
|
||||
QString(
|
||||
QObject::tr(
|
||||
"coller %1",
|
||||
"undo caption - %1 is a sentence listing the content to paste"
|
||||
).arg(content.sentence(filter))
|
||||
)
|
||||
);
|
||||
setText(QObject::tr("coller %1", "undo caption - %1 is a sentence listing the content to paste").arg(content.sentence(filter)));
|
||||
diagram -> qgiManager().manage(content.items(filter));
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
/**
|
||||
* @brief PasteDiagramCommand::~PasteDiagramCommand
|
||||
* Destructor
|
||||
*/
|
||||
PasteDiagramCommand::~PasteDiagramCommand() {
|
||||
diagram -> qgiManager().release(content.items(filter));
|
||||
}
|
||||
|
||||
/// annule le coller
|
||||
void PasteDiagramCommand::undo() {
|
||||
/**
|
||||
* @brief PasteDiagramCommand::undo
|
||||
* Undo this command
|
||||
*/
|
||||
void PasteDiagramCommand::undo()
|
||||
{
|
||||
diagram -> showMe();
|
||||
// remove the conductors
|
||||
foreach(Conductor *c, content.conductorsToMove) diagram -> removeItem(c);
|
||||
|
||||
// remove the elements
|
||||
foreach(Element *e, content.elements) diagram -> removeItem(e);
|
||||
|
||||
// remove the texts
|
||||
foreach(IndependentTextItem *t, content.textFields) diagram -> removeItem(t);
|
||||
|
||||
// remove the images and shapes
|
||||
foreach(QGraphicsItem *qgi, content.items(DiagramContent::Images | DiagramContent::Shapes)) diagram -> removeItem(qgi);
|
||||
foreach(QGraphicsItem *item, content.items(filter))
|
||||
diagram->removeItem(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PasteDiagramCommand::redo
|
||||
* Redo this commnand
|
||||
*/
|
||||
void PasteDiagramCommand::redo() {
|
||||
void PasteDiagramCommand::redo()
|
||||
{
|
||||
diagram -> showMe();
|
||||
|
||||
if (first_redo) {
|
||||
@ -240,18 +201,10 @@ void PasteDiagramCommand::redo() {
|
||||
c -> setProperties(cp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// paste the elements
|
||||
foreach(Element *e, content.elements) diagram -> addItem(e);
|
||||
|
||||
// paste the conductors
|
||||
foreach(Conductor *c, content.conductorsToMove) diagram -> addItem(c);
|
||||
|
||||
// paste the texts
|
||||
foreach(IndependentTextItem *t, content.textFields) diagram -> addItem(t);
|
||||
|
||||
// paste the images and shapes
|
||||
foreach(QGraphicsItem *qgi, content.items(DiagramContent::Images | DiagramContent::Shapes)) diagram -> addItem(qgi);
|
||||
else
|
||||
{
|
||||
foreach (QGraphicsItem *item, content.items(filter))
|
||||
diagram->addItem(item);
|
||||
}
|
||||
foreach (QGraphicsItem *qgi, content.items()) qgi -> setSelected(true);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user