Multipaste dialog : add 'autonum pasted conductors' check box

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5339 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2018-04-23 13:50:36 +00:00
parent 5fe1389f8b
commit 9d2124f593
8 changed files with 94 additions and 21 deletions

View File

@@ -1000,7 +1000,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
// remplissage des listes facultatives // remplissage des listes facultatives
if (content_ptr) { if (content_ptr) {
content_ptr -> m_elements = added_elements; content_ptr -> m_elements = added_elements;
content_ptr -> m_conductors_to_move = added_conductors.toSet(); content_ptr -> m_conductors_to_move = added_conductors;
content_ptr -> m_text_fields = added_texts.toSet(); content_ptr -> m_text_fields = added_texts.toSet();
content_ptr -> m_images = added_images.toSet(); content_ptr -> m_images = added_images.toSet();
content_ptr -> m_shapes = added_shapes.toSet(); content_ptr -> m_shapes = added_shapes.toSet();

View File

@@ -109,7 +109,7 @@ void PasteDiagramCommand::redo()
e -> rElementInformations().addValue("location", ""); e -> rElementInformations().addValue("location", "");
//Reset the text of conductors //Reset the text of conductors
const QList <Conductor *> conductors_list = content.m_conductors_to_move.toList(); const QList <Conductor *> conductors_list = content.m_conductors_to_move;
for (Conductor *c : conductors_list) for (Conductor *c : conductors_list)
{ {
ConductorProperties cp = c -> properties(); ConductorProperties cp = c -> properties();

View File

@@ -81,9 +81,9 @@ DiagramContent::DiagramContent(Diagram *diagram) :
other_terminal = conductor->terminal1; other_terminal = conductor->terminal1;
//If the two elements of conductor are movable //If the two elements of conductor are movable
if (m_elements.contains(other_terminal -> parentElement())) if (m_elements.contains(other_terminal -> parentElement()) && !m_conductors_to_move.contains(conductor))
m_conductors_to_move << conductor; m_conductors_to_move << conductor;
else else if (!m_conductors_to_update.contains(conductor))
m_conductors_to_update << conductor; m_conductors_to_update << conductor;
} }
} }
@@ -160,16 +160,18 @@ QList<ElementTextItemGroup *> DiagramContent::selectedTextsGroup() const
*/ */
QList<Conductor *> DiagramContent::conductors(int filter) const QList<Conductor *> DiagramContent::conductors(int filter) const
{ {
QSet<Conductor *> result; QList<Conductor *> result;
if (filter & ConductorsToMove) result += m_conductors_to_move; if (filter & ConductorsToMove) result += m_conductors_to_move;
if (filter & ConductorsToUpdate) result += m_conductors_to_update; if (filter & ConductorsToUpdate) result += m_conductors_to_update;
if (filter & OtherConductors) result += m_other_conductors; if (filter & OtherConductors) result += m_other_conductors;
if (filter & SelectedOnly) { if (filter & SelectedOnly) {
for(Conductor *conductor : result) { for(Conductor *conductor : result)
if (!conductor->isSelected()) result.remove(conductor); {
if (!conductor->isSelected())
result.removeAll(conductor);
} }
} }
return(result.toList()); return(result);
} }
/** /**

View File

@@ -68,9 +68,9 @@ class DiagramContent
QSet<IndependentTextItem *> m_text_fields; QSet<IndependentTextItem *> m_text_fields;
QSet<DiagramImageItem *> m_images; QSet<DiagramImageItem *> m_images;
QSet<QetShapeItem *> m_shapes; QSet<QetShapeItem *> m_shapes;
QSet<Conductor *> m_conductors_to_update; QList<Conductor *> m_conductors_to_update;
QSet<Conductor *> m_conductors_to_move; QList<Conductor *> m_conductors_to_move;
QSet<Conductor *> m_other_conductors; QList<Conductor *> m_other_conductors;
QSet<DynamicElementTextItem *> m_element_texts; QSet<DynamicElementTextItem *> m_element_texts;
QSet<ElementTextItemGroup *> m_texts_groups; QSet<ElementTextItemGroup *> m_texts_groups;
QList<QGraphicsItem *> m_selected_items; QList<QGraphicsItem *> m_selected_items;

View File

@@ -194,4 +194,5 @@ void ElementsMover::endMovement()
// There is no movement in progress now // There is no movement in progress now
movement_running_ = false; movement_running_ = false;
m_moved_content.clear();
} }

View File

@@ -1,3 +1,20 @@
/*
Copyright 2006-2018 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 "multipastedialog.h" #include "multipastedialog.h"
#include "ui_multipastedialog.h" #include "ui_multipastedialog.h"
#include "diagram.h" #include "diagram.h"
@@ -76,6 +93,8 @@ void MultiPasteDialog::on_m_button_box_accepted()
{ {
if(m_pasted_content.count()) if(m_pasted_content.count())
{ {
m_diagram->undoStack().beginMacro(tr("Multi-collage"));
QSettings settings; QSettings settings;
bool erase_label = settings.value("diagramcommands/erase-label-on-copy", true).toBool(); bool erase_label = settings.value("diagramcommands/erase-label-on-copy", true).toBool();
//Ensure when 'auto_num' is checked, the settings 'save_label' is to true. //Ensure when 'auto_num' is checked, the settings 'save_label' is to true.
@@ -88,9 +107,7 @@ void MultiPasteDialog::on_m_button_box_accepted()
m_diagram->clearSelection(); m_diagram->clearSelection();
m_diagram->undoStack().push(new PasteDiagramCommand(m_diagram, m_pasted_content));
QUndoCommand *undo = new QUndoCommand(tr("Multi-collage"));
new PasteDiagramCommand(m_diagram, m_pasted_content, undo);
//Auto-connection //Auto-connection
if(ui->m_auto_connection_cb->isChecked()) if(ui->m_auto_connection_cb->isChecked())
@@ -102,10 +119,10 @@ void MultiPasteDialog::on_m_button_box_accepted()
QPair <Terminal *, Terminal *> pair = elmt->AlignedFreeTerminals().takeFirst(); QPair <Terminal *, Terminal *> pair = elmt->AlignedFreeTerminals().takeFirst();
Conductor *conductor = new Conductor(pair.first, pair.second); Conductor *conductor = new Conductor(pair.first, pair.second);
new AddItemCommand<Conductor *>(conductor, m_diagram, QPointF(), undo); m_diagram->undoStack().push(new AddItemCommand<Conductor *>(conductor, m_diagram, QPointF()));
//Autonum the new conductor, the undo command associated for this, have for parent undo_object //Autonum the new conductor, the undo command associated for this, have for parent undo_object
ConductorAutoNumerotation can (conductor, m_diagram, undo); ConductorAutoNumerotation can (conductor, m_diagram);
can.numerate(); can.numerate();
if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors()) { if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors()) {
conductor->setFreezeLabel(true); conductor->setFreezeLabel(true);
@@ -114,8 +131,6 @@ void MultiPasteDialog::on_m_button_box_accepted()
} }
} }
m_diagram->undoStack().push(undo);
//Set up the label of element //Set up the label of element
//Instead of use the current autonum of project, //Instead of use the current autonum of project,
//we try to fetch the same formula of the pasted element, in the several autonum of the project //we try to fetch the same formula of the pasted element, in the several autonum of the project
@@ -142,8 +157,39 @@ void MultiPasteDialog::on_m_button_box_accepted()
} }
} }
} }
//Like elements, we compare formula of pasted conductor with the autonums available in the project.
if(ui->m_auto_num_cond_cb->isChecked())
{
for(Conductor *c : m_pasted_content.conductors())
{
QString formula = c->properties().m_formula;
if(!formula.isEmpty())
{
QHash <QString, NumerotationContext> autonums = m_diagram->project()->conductorAutoNum();
QHashIterator <QString, NumerotationContext> hash_iterator(autonums);
while (hash_iterator.hasNext())
{
hash_iterator.next();
if(autonum::numerotationContextToFormula(hash_iterator.value()) == formula)
{
m_diagram->project()->setCurrentConductorAutoNum(hash_iterator.key());
c->rSequenceNum().clear();
ConductorAutoNumerotation can(c, m_diagram);
can.numerate();
if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors())
{
c->setFreezeLabel(true);
}
}
}
}
}
}
m_diagram->adjustSceneRect(); m_diagram->adjustSceneRect();
m_accept = true; m_accept = true;
settings.setValue("diagramcommands/erase-label-on-copy", erase_label); settings.setValue("diagramcommands/erase-label-on-copy", erase_label);
m_diagram->undoStack().endMacro();
} }
} }

View File

@@ -1,3 +1,20 @@
/*
Copyright 2006-2018 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 MULTIPASTEDIALOG_H #ifndef MULTIPASTEDIALOG_H
#define MULTIPASTEDIALOG_H #define MULTIPASTEDIALOG_H
@@ -16,7 +33,7 @@ class MultiPasteDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit MultiPasteDialog(Diagram *diagram, QWidget *parent = 0); explicit MultiPasteDialog(Diagram *diagram, QWidget *parent = nullptr);
~MultiPasteDialog(); ~MultiPasteDialog();
void updatePreview(); void updatePreview();

View File

@@ -101,6 +101,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="m_auto_num_cond_cb">
<property name="text">
<string>Auto-numérotation des conducteurs</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">