mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-14 20:33:05 +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
|
* @brief Diagram::addItem
|
||||||
* Add element to diagram
|
* Réimplemented from QGraphicsScene::addItem(QGraphicsItem *item)
|
||||||
* @param element
|
* Do some specific operation if item need it (for exemple an 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
|
|
||||||
* @param item
|
* @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 || isReadOnly()) return;
|
||||||
if (item -> scene() != this)
|
|
||||||
QGraphicsScene::addItem(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
switch (item->type())
|
||||||
* @brief Diagram::removeItem
|
{
|
||||||
* Remove an element from the scene
|
case Element::Type:
|
||||||
* @param element
|
{
|
||||||
*/
|
Element *elmt = static_cast<Element *>(item);
|
||||||
void Diagram::removeItem(Element *element) {
|
elmt->unlinkAllElements();
|
||||||
if (!element || isReadOnly()) return;
|
foreach(ElementTextItem *text, elmt->texts())
|
||||||
|
disconnect(text, &ElementTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// remove all links of element
|
case Conductor::Type:
|
||||||
element->unlinkAllElements();
|
{
|
||||||
|
Conductor *conductor = static_cast<Conductor *>(item);
|
||||||
|
conductor->terminal1->removeConductor(conductor);
|
||||||
|
conductor->terminal2->removeConductor(conductor);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
QGraphicsScene::removeItem(element);
|
case IndependentTextItem::Type:
|
||||||
|
{
|
||||||
foreach(ElementTextItem *eti, element -> texts()) {
|
const IndependentTextItem *text = static_cast<const IndependentTextItem *>(item);
|
||||||
disconnect(
|
disconnect(text, &IndependentTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
|
||||||
eti,
|
}
|
||||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
|
||||||
this,
|
|
||||||
SLOT(diagramTextChanged(DiagramTextItem *, const QString &, const QString &))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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);
|
QGraphicsScene::removeItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,17 +152,10 @@ class Diagram : public QGraphicsScene
|
|||||||
bool wasWritten() const;
|
bool wasWritten() const;
|
||||||
QDomElement writeXml(QDomDocument &) 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();
|
void initElementsLinks();
|
||||||
virtual void addItem (Element *element);
|
virtual void addItem (QGraphicsItem *item);
|
||||||
virtual void addItem (Conductor *conductor);
|
virtual void removeItem (QGraphicsItem *item);
|
||||||
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);
|
|
||||||
|
|
||||||
// methods related to graphics options
|
// methods related to graphics options
|
||||||
ExportProperties applyProperties(const ExportProperties &);
|
ExportProperties applyProperties(const ExportProperties &);
|
||||||
|
@ -74,140 +74,101 @@ DeleteElementsCommand::~DeleteElementsCommand() {
|
|||||||
diagram -> qgiManager().release(removed_content.items(DiagramContent::All));
|
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();
|
diagram -> showMe();
|
||||||
|
|
||||||
foreach(Element *e, removed_content.elements) {
|
foreach(QGraphicsItem *item, removed_content.items())
|
||||||
diagram -> addItem(e);
|
diagram->addItem(item);
|
||||||
}
|
|
||||||
|
|
||||||
//We relink element after every element was added to diagram
|
//We relink element after every element was added to diagram
|
||||||
foreach(Element *e, removed_content.elements) {
|
foreach(Element *e, removed_content.elements)
|
||||||
foreach (Element *elmt, m_link_hash[e]) {
|
foreach (Element *elmt, m_link_hash[e])
|
||||||
e -> linkToElement(elmt);
|
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
|
* @brief DeleteElementsCommand::redo
|
||||||
* Redo the delete command
|
* Redo the delete command
|
||||||
*/
|
*/
|
||||||
void DeleteElementsCommand::redo() {
|
void DeleteElementsCommand::redo()
|
||||||
|
{
|
||||||
diagram -> showMe();
|
diagram -> showMe();
|
||||||
|
|
||||||
// Remove Conductor
|
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor))
|
||||||
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)
|
||||||
//If option one text per folio is enable, and the text item of
|
//We call adjustTextItemPosition to other conductor at the same potential to keep
|
||||||
//current conductor is visible (that mean the conductor have the single displayed text)
|
//a visible text on this potential.
|
||||||
//We call adjustTextItemPosition to other conductor at the same potential to keep
|
if (diagram -> defaultConductorProperties.m_one_text_per_folio && c -> textItem() -> isVisible())
|
||||||
//a visible text on this potential.
|
{
|
||||||
if (diagram -> defaultConductorProperties.m_one_text_per_folio && c -> textItem() -> isVisible()) {
|
|
||||||
QList <Conductor *> conductor_list;
|
QList <Conductor *> conductor_list;
|
||||||
conductor_list << c -> relatedPotentialConductors(false).toList();
|
conductor_list << c -> relatedPotentialConductors(false).toList();
|
||||||
if (conductor_list.count()) {
|
if (conductor_list.count())
|
||||||
conductor_list.first() -> calculateTextItemPosition();
|
conductor_list.first() -> calculateTextItemPosition();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove elements
|
foreach(Element *e, removed_content.elements)
|
||||||
foreach(Element *e, removed_content.elements) {
|
{
|
||||||
//Get linked element, for relink it at undo
|
//Get linked element, for relink it at undo
|
||||||
if (!e->linkedElements().isEmpty())
|
if (!e->linkedElements().isEmpty())
|
||||||
m_link_hash.insert(e, e->linkedElements());
|
m_link_hash.insert(e, e->linkedElements());
|
||||||
diagram -> removeItem(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove texts
|
foreach(QGraphicsItem *item, removed_content.items())
|
||||||
foreach(IndependentTextItem *t, removed_content.textFields) {
|
diagram->removeItem(item);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
* @brief PasteDiagramCommand::PasteDiagramCommand
|
||||||
@param dia Schema sur lequel on colle les elements et conducteurs
|
* Constructor
|
||||||
@param c Contenu a coller sur le schema
|
* @param dia : diagram where we must to paste
|
||||||
@param parent QUndoCommand parent
|
* @param c : content to past
|
||||||
*/
|
* @param parent : parent undo command
|
||||||
PasteDiagramCommand::PasteDiagramCommand(
|
*/
|
||||||
Diagram *dia,
|
PasteDiagramCommand::PasteDiagramCommand( Diagram *dia, const DiagramContent &c, QUndoCommand *parent) :
|
||||||
const DiagramContent &c,
|
|
||||||
QUndoCommand *parent
|
|
||||||
) :
|
|
||||||
QUndoCommand(parent),
|
QUndoCommand(parent),
|
||||||
content(c),
|
content(c),
|
||||||
diagram(dia),
|
diagram(dia),
|
||||||
filter(DiagramContent::Elements|DiagramContent::TextFields|DiagramContent::Images|DiagramContent::ConductorsToMove | DiagramContent::Shapes),
|
filter(DiagramContent::Elements|DiagramContent::TextFields|DiagramContent::Images|DiagramContent::ConductorsToMove | DiagramContent::Shapes),
|
||||||
first_redo(true)
|
first_redo(true)
|
||||||
{
|
{
|
||||||
|
setText(QObject::tr("coller %1", "undo caption - %1 is a sentence listing the content to paste").arg(content.sentence(filter)));
|
||||||
setText(
|
|
||||||
QString(
|
|
||||||
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));
|
diagram -> qgiManager().manage(content.items(filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/**
|
||||||
|
* @brief PasteDiagramCommand::~PasteDiagramCommand
|
||||||
|
* Destructor
|
||||||
|
*/
|
||||||
PasteDiagramCommand::~PasteDiagramCommand() {
|
PasteDiagramCommand::~PasteDiagramCommand() {
|
||||||
diagram -> qgiManager().release(content.items(filter));
|
diagram -> qgiManager().release(content.items(filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// annule le coller
|
/**
|
||||||
void PasteDiagramCommand::undo() {
|
* @brief PasteDiagramCommand::undo
|
||||||
|
* Undo this command
|
||||||
|
*/
|
||||||
|
void PasteDiagramCommand::undo()
|
||||||
|
{
|
||||||
diagram -> showMe();
|
diagram -> showMe();
|
||||||
// remove the conductors
|
|
||||||
foreach(Conductor *c, content.conductorsToMove) diagram -> removeItem(c);
|
|
||||||
|
|
||||||
// remove the elements
|
foreach(QGraphicsItem *item, content.items(filter))
|
||||||
foreach(Element *e, content.elements) diagram -> removeItem(e);
|
diagram->removeItem(item);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PasteDiagramCommand::redo
|
* @brief PasteDiagramCommand::redo
|
||||||
|
* Redo this commnand
|
||||||
*/
|
*/
|
||||||
void PasteDiagramCommand::redo() {
|
void PasteDiagramCommand::redo()
|
||||||
|
{
|
||||||
diagram -> showMe();
|
diagram -> showMe();
|
||||||
|
|
||||||
if (first_redo) {
|
if (first_redo) {
|
||||||
@ -240,18 +201,10 @@ void PasteDiagramCommand::redo() {
|
|||||||
c -> setProperties(cp);
|
c -> setProperties(cp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
// paste the elements
|
{
|
||||||
foreach(Element *e, content.elements) diagram -> addItem(e);
|
foreach (QGraphicsItem *item, content.items(filter))
|
||||||
|
diagram->addItem(item);
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
foreach (QGraphicsItem *qgi, content.items()) qgi -> setSelected(true);
|
foreach (QGraphicsItem *qgi, content.items()) qgi -> setSelected(true);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user