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:
blacksun
2017-08-03 17:36:08 +00:00
parent 0df5391491
commit 3ef55906a4
33 changed files with 2222 additions and 863 deletions

View File

@@ -0,0 +1,83 @@
/*
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 "addelementtextcommand.h"
#include "element.h"
#include "dynamicelementtextitem.h"
#include <QGraphicsScene>
AddElementTextCommand::AddElementTextCommand(Element *element, DynamicElementTextItem *deti, QUndoCommand *parent):
QUndoCommand(parent),
m_element(element),
m_text(deti)
{
setText(QObject::tr("Ajouter un texte d'élément"));
}
AddElementTextCommand::~AddElementTextCommand()
{
if(!m_element->dynamicTextItems().contains(m_text))
delete m_text;
}
void AddElementTextCommand::undo()
{
m_element->removeDynamicTextItem(m_text);
m_text->setParentItem(nullptr);
if(m_text->scene())
m_text->scene()->removeItem(m_text);
}
void AddElementTextCommand::redo()
{
m_text->setParentItem(m_element);
m_element->addDynamicTextItem(m_text);
}
//RemoveElementTextCommand::RemoveElementTextCommand(DynamicElementTextItem *deti, QUndoCommand *parent) :
// QUndoCommand(parent),
// m_text(deti)
//{
// setText(QObject::tr("Supprimer un texte d'élément"));
// m_element = deti->ParentElement();
//}
//RemoveElementTextCommand::~RemoveElementTextCommand()
//{
// if(m_element && !m_element->dynamicTextItems().contains(m_text))
// delete m_text;
//}
//void RemoveElementTextCommand::undo()
//{
// if(m_element)
// {
// m_text->setParentItem(m_element);
// m_element->addDynamicTextItem(m_text);
// }
//}
//void RemoveElementTextCommand::redo()
//{
// if(m_element && m_text->scene())
// {
// m_element->removeDynamicTextItem(m_text);
// m_text->setParentItem(nullptr);
// m_text->scene()->removeItem(m_text);
// }
//}

View File

@@ -0,0 +1,54 @@
/*
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/>.
*/
#ifndef ADDELEMENTTEXTCOMMAND_H
#define ADDELEMENTTEXTCOMMAND_H
#include <QUndoCommand>
class Element;
class DynamicElementTextItem;
class AddElementTextCommand : public QUndoCommand
{
public:
AddElementTextCommand(Element *element, DynamicElementTextItem *deti, QUndoCommand *parent = nullptr);
virtual ~AddElementTextCommand();
virtual void undo();
virtual void redo();
private:
Element *m_element = nullptr;
DynamicElementTextItem *m_text = nullptr;
};
//class RemoveElementTextCommand : public QUndoCommand
//{
// public:
// RemoveElementTextCommand(DynamicElementTextItem *deti, QUndoCommand *parent = nullptr);
// virtual ~RemoveElementTextCommand();
// virtual void undo();
// virtual void redo();
// private:
// Element *m_element = nullptr;
// DynamicElementTextItem *m_text = nullptr;
//};
#endif // ADDELEMENTTEXTCOMMAND_H

View 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);
}

View File

@@ -0,0 +1,46 @@
/*
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/>.
*/
#ifndef DELETEQGRAPHICSITEMCOMMAND_H
#define DELETEQGRAPHICSITEMCOMMAND_H
#include <QUndoCommand>
#include "diagramcontent.h"
class Diagram;
class DeleteQGraphicsItemCommand : public QUndoCommand
{
public:
DeleteQGraphicsItemCommand(Diagram *diagram, const DiagramContent &content, QUndoCommand * parent = nullptr);
virtual ~DeleteQGraphicsItemCommand() override;
private:
DeleteQGraphicsItemCommand(const DeleteQGraphicsItemCommand &);
public:
virtual void undo() override;
virtual void redo() override;
// attributes
private:
DiagramContent m_removed_contents;
Diagram *m_diagram;
QHash <Element *, QList<Element *> > m_link_hash; /// keep linked element for each removed element linked to other element.
QHash <DynamicElementTextItem *, Element *> m_elmt_text_hash; /// Keep the parent element of each deleted dynamic element text item
};
#endif // DELETEQGRAPHICSITEMCOMMAND_H