2014-09-02 18:41:25 +00:00
|
|
|
/*
|
2017-01-20 10:55:49 +00:00
|
|
|
Copyright 2006-2017 The QElectroTech Team
|
2014-09-02 18:41:25 +00:00
|
|
|
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 "conductorpropertiesdialog.h"
|
|
|
|
#include "ui_conductorpropertiesdialog.h"
|
|
|
|
#include "conductor.h"
|
|
|
|
#include "conductorpropertieswidget.h"
|
|
|
|
#include "diagram.h"
|
2015-08-09 12:06:31 +00:00
|
|
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
2014-09-02 18:41:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ConductorPropertiesDialog::ConductorPropertiesDialog
|
|
|
|
* Constructor
|
|
|
|
* @param conductor, conductor to edit propertie
|
|
|
|
* @param parent, parent widget
|
|
|
|
*/
|
|
|
|
ConductorPropertiesDialog::ConductorPropertiesDialog(Conductor *conductor, QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::ConductorPropertiesDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
m_cpw = new ConductorPropertiesWidget(conductor->properties());
|
2014-10-03 17:02:01 +00:00
|
|
|
m_cpw -> setHiddenOneTextPerFolio(true);
|
2017-02-27 16:58:05 +00:00
|
|
|
m_cpw->setHiddenAvailableAutonum(true);
|
2014-10-13 18:42:38 +00:00
|
|
|
if (conductor -> diagram() -> defaultConductorProperties.m_one_text_per_folio == true &&
|
|
|
|
conductor -> relatedPotentialConductors().size()) {
|
|
|
|
m_cpw->setDisabledShowText();
|
|
|
|
}
|
2015-08-26 21:46:47 +00:00
|
|
|
ui -> main_layout -> insertWidget(0, m_cpw);
|
2014-09-02 18:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ConductorPropertiesDialog::~ConductorPropertiesDialog
|
|
|
|
*/
|
|
|
|
ConductorPropertiesDialog::~ConductorPropertiesDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ConductorPropertiesDialog::PropertiesDialog
|
|
|
|
* Static method for open and apply properties.
|
|
|
|
* @param conductor, conductor to edit propertie
|
|
|
|
* @param parent, parent widget
|
|
|
|
*/
|
2015-08-09 12:06:31 +00:00
|
|
|
void ConductorPropertiesDialog::PropertiesDialog(Conductor *conductor, QWidget *parent)
|
|
|
|
{
|
2014-09-02 18:41:25 +00:00
|
|
|
ConductorPropertiesDialog cpd (conductor, parent);
|
|
|
|
|
2015-08-22 13:18:20 +00:00
|
|
|
if (cpd.exec() == QDialog::Rejected || cpd.properties() == conductor->properties()) return;
|
|
|
|
|
|
|
|
QVariant old_value, new_value;
|
|
|
|
old_value.setValue(conductor->properties());
|
|
|
|
new_value.setValue(cpd.properties());
|
2014-09-02 18:41:25 +00:00
|
|
|
|
2015-08-22 13:18:20 +00:00
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(conductor, "properties", old_value, new_value);
|
|
|
|
undo->setText(tr("Modifier les propriétés d'un conducteur", "undo caption"));
|
|
|
|
|
2015-08-29 14:18:30 +00:00
|
|
|
if (!conductor->relatedPotentialConductors().isEmpty() && cpd.applyAll())
|
2015-08-22 13:18:20 +00:00
|
|
|
{
|
|
|
|
undo->setText(tr("Modifier les propriétés de plusieurs conducteurs", "undo caption"));
|
2014-09-02 18:41:25 +00:00
|
|
|
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (Conductor *potential_conductor, conductor->relatedPotentialConductors())
|
2015-08-09 12:06:31 +00:00
|
|
|
{
|
2015-08-29 14:18:30 +00:00
|
|
|
old_value.setValue(potential_conductor->properties());
|
|
|
|
new QPropertyUndoCommand (potential_conductor, "properties", old_value, new_value, undo);
|
2014-09-02 18:41:25 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-22 13:18:20 +00:00
|
|
|
|
|
|
|
conductor->diagram()->undoStack().push(undo);
|
2014-09-02 18:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ConductorPropertiesDialog::properties
|
|
|
|
* @return the edited properties
|
|
|
|
*/
|
|
|
|
ConductorProperties ConductorPropertiesDialog::properties() const {
|
|
|
|
return m_cpw -> properties();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ConductorPropertiesDialog::applyAll
|
|
|
|
* @return
|
|
|
|
* true -> must apply the propertie to all conductor at the same potential
|
|
|
|
* false -> must apply properties only for the edited conductor
|
|
|
|
*/
|
|
|
|
bool ConductorPropertiesDialog::applyAll() const {
|
|
|
|
return ui -> m_apply_all_cb -> isChecked();
|
|
|
|
}
|