mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Search and replace : conductors properties can now be replaced
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5641 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Copyright 2006-2018 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
@@ -23,18 +23,12 @@
|
||||
#include "qetapp.h"
|
||||
#include "independenttextitem.h"
|
||||
#include "diagramcommands.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
|
||||
|
||||
SearchAndReplaceWorker::SearchAndReplaceWorker()
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief SearchAndReplaceWorker::clear
|
||||
* All registred properties
|
||||
*/
|
||||
void SearchAndReplaceWorker::clear()
|
||||
{
|
||||
m_titleblock_properties = TitleBlockProperties();
|
||||
m_conductor_properties = invalidConductorProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +162,7 @@ void SearchAndReplaceWorker::replaceElement(QList<Element *> list)
|
||||
}
|
||||
}
|
||||
|
||||
project_->undoStack()->beginMacro(QObject::tr("Chercher/remplacer les propriétés d'éléments"));
|
||||
project_->undoStack()->beginMacro(QObject::tr("Chercher/remplacer les propriétés d'éléments."));
|
||||
for (Element *elmt : list)
|
||||
{
|
||||
//We apply change only for master, slave, and terminal element.
|
||||
@@ -244,3 +238,134 @@ void SearchAndReplaceWorker::replaceIndiText(IndependentTextItem *text)
|
||||
list.append(text);
|
||||
replaceIndiText(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchAndReplaceWorker::replaceConductor
|
||||
* Replace all properties of each conductor in @list
|
||||
* All conductor must belong to the same project, if not this function do nothing.
|
||||
* All change are made through a undo command append to undo list of the project.
|
||||
* @param list
|
||||
*/
|
||||
void SearchAndReplaceWorker::replaceConductor(QList<Conductor *> list)
|
||||
{
|
||||
if (list.isEmpty() || !list.first()->diagram()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QETProject *project_ = list.first()->diagram()->project();
|
||||
for (Conductor *c : list) {
|
||||
if (!c->diagram() ||
|
||||
c->diagram()->project() != project_) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
project_->undoStack()->beginMacro(QObject::tr("Chercher/remplacer les propriétés de conducteurs."));
|
||||
for (Conductor *c : list)
|
||||
{
|
||||
ConductorProperties cp = applyChange(c->properties(), m_conductor_properties);
|
||||
|
||||
if (cp != c->properties())
|
||||
{
|
||||
QSet <Conductor *> conductors_list = c->relatedPotentialConductors(true);
|
||||
conductors_list << c;
|
||||
for (Conductor *cc : conductors_list)
|
||||
{
|
||||
QVariant old_value, new_value;
|
||||
old_value.setValue(cc->properties());
|
||||
new_value.setValue(cp);
|
||||
project_->undoStack()->push(new QPropertyUndoCommand(cc, "properties", old_value, new_value));
|
||||
}
|
||||
}
|
||||
}
|
||||
project_->undoStack()->endMacro();
|
||||
}
|
||||
|
||||
void SearchAndReplaceWorker::replaceConductor(Conductor *conductor)
|
||||
{
|
||||
QList<Conductor *>list;
|
||||
list.append(conductor);
|
||||
replaceConductor(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchAndReplaceWorker::setupLineEdit
|
||||
* With search and replace, when the variable to edit is a text,
|
||||
* the editor is always the same no matter if it is for a folio, element or conductor.
|
||||
* The editor is a QLineEdit to edit the text and checkbox to erase the text if checked.
|
||||
* This function fill the editor
|
||||
* @param l
|
||||
* @param cb
|
||||
* @param str
|
||||
*/
|
||||
void SearchAndReplaceWorker::setupLineEdit(QLineEdit *l, QCheckBox *cb, QString str)
|
||||
{
|
||||
l->setText(str);
|
||||
cb->setChecked(str == eraseText() ? true : false);
|
||||
}
|
||||
|
||||
ConductorProperties SearchAndReplaceWorker::invalidConductorProperties()
|
||||
{
|
||||
ConductorProperties cp;
|
||||
|
||||
//init with invalid value the conductor properties
|
||||
cp.text_size = 0;
|
||||
cp.text.clear();
|
||||
cp.m_vertical_alignment = Qt::AlignAbsolute;
|
||||
cp.m_horizontal_alignment = Qt::AlignAbsolute;
|
||||
cp.verti_rotate_text = -1;
|
||||
cp.horiz_rotate_text = -1;
|
||||
cp.color = QColor();
|
||||
cp.style = Qt::NoPen;
|
||||
cp.cond_size = 0;
|
||||
cp.m_color_2 = QColor();
|
||||
cp.m_dash_size = 0;
|
||||
|
||||
return cp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchAndReplaceWorker::applyChange
|
||||
* @param original : the original properties
|
||||
* @param change : the change properties, to be merged with @original
|
||||
* @return a new conductor properties with the change applyed.
|
||||
*/
|
||||
ConductorProperties SearchAndReplaceWorker::applyChange(const ConductorProperties &original, const ConductorProperties &change)
|
||||
{
|
||||
ConductorProperties new_properties = original;
|
||||
|
||||
if (change.text_size > 2) {new_properties.text_size = change.text_size;}
|
||||
new_properties.m_formula = applyChange(new_properties.m_formula, change.m_formula);
|
||||
new_properties.text = applyChange(new_properties.text, change.text);
|
||||
new_properties.m_show_text = change.m_show_text;
|
||||
new_properties.m_function = applyChange(new_properties.m_function, change.m_function);
|
||||
new_properties.m_tension_protocol = applyChange(new_properties.m_tension_protocol, change.m_tension_protocol);
|
||||
if(change.m_vertical_alignment == Qt::AlignLeft ||
|
||||
change.m_vertical_alignment == Qt::AlignRight) {new_properties.m_vertical_alignment = change.m_vertical_alignment;}
|
||||
if(change.m_horizontal_alignment == Qt::AlignTop ||
|
||||
change.m_horizontal_alignment == Qt::AlignBottom) {new_properties.m_horizontal_alignment = change.m_horizontal_alignment;}
|
||||
if (change.verti_rotate_text >= 0) {new_properties.verti_rotate_text = change.verti_rotate_text;}
|
||||
if (change.horiz_rotate_text >= 0) {new_properties.horiz_rotate_text = change.horiz_rotate_text;}
|
||||
if (change.color.isValid()) {new_properties.color = change.color;}
|
||||
if (change.style != Qt::NoPen) {new_properties.style = change.style;}
|
||||
if (change.cond_size >= 0.4) {new_properties.cond_size = change.cond_size;}
|
||||
new_properties.m_bicolor = change.m_bicolor;
|
||||
if (change.m_color_2.isValid()) {new_properties.m_color_2 = change.m_color_2;}
|
||||
if (change.m_dash_size >= 2) {new_properties.m_dash_size = change.m_dash_size;}
|
||||
new_properties.singleLineProperties = change.singleLineProperties;
|
||||
|
||||
return new_properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchAndReplaceWorker::applyChange
|
||||
* @param original : the original string
|
||||
* @param change : the changed string:
|
||||
* @return the string to be use in the properties
|
||||
*/
|
||||
QString SearchAndReplaceWorker::applyChange(const QString &original, const QString &change)
|
||||
{
|
||||
if (change.isEmpty()) {return original;}
|
||||
else if (change == eraseText()) {return QString();}
|
||||
else {return change;}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user