mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
master propertie widget:
can link/unlink slave to master can show element by double clic item on the list reset modification git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2878 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1152,11 +1152,11 @@ void ImageResizerCommand::redo() {
|
|||||||
LinkElementsCommand::LinkElementsCommand(Element *elmt1, Element *elmt2, QUndoCommand *parent) :
|
LinkElementsCommand::LinkElementsCommand(Element *elmt1, Element *elmt2, QUndoCommand *parent) :
|
||||||
QUndoCommand(parent),
|
QUndoCommand(parent),
|
||||||
diagram_(elmt1->diagram()),
|
diagram_(elmt1->diagram()),
|
||||||
elmt_1(elmt1),
|
element_(elmt1),
|
||||||
elmt_2(elmt2),
|
|
||||||
previous_report(0),
|
previous_report(0),
|
||||||
first_redo(true)
|
first_redo(true)
|
||||||
{
|
{
|
||||||
|
elmt_list << elmt2;
|
||||||
if (elmt1->linkType() & Element::AllReport &&
|
if (elmt1->linkType() & Element::AllReport &&
|
||||||
elmt2->linkType() & Element::AllReport) {
|
elmt2->linkType() & Element::AllReport) {
|
||||||
setText(QObject::tr("Lier deux reports de folio",
|
setText(QObject::tr("Lier deux reports de folio",
|
||||||
@@ -1164,6 +1164,21 @@ LinkElementsCommand::LinkElementsCommand(Element *elmt1, Element *elmt2, QUndoCo
|
|||||||
if(!elmt1->isFree())
|
if(!elmt1->isFree())
|
||||||
previous_report = elmt1->linkedElements().first();
|
previous_report = elmt1->linkedElements().first();
|
||||||
}
|
}
|
||||||
|
else if (element_->linkType() & Element::Master)
|
||||||
|
setText(QObject::tr("Editer les r\351f\351rence crois\351", "edite the cross reference"));
|
||||||
|
else setText(QObject::tr("Lier deux éléments"));
|
||||||
|
}
|
||||||
|
|
||||||
|
LinkElementsCommand::LinkElementsCommand(Element *elmt1, QList<Element *> &elmtList, QUndoCommand *parent) :
|
||||||
|
QUndoCommand(parent),
|
||||||
|
diagram_(elmt1->diagram()),
|
||||||
|
element_(elmt1),
|
||||||
|
elmt_list(elmtList),
|
||||||
|
previous_report(0),
|
||||||
|
first_redo(true)
|
||||||
|
{
|
||||||
|
if (element_->linkType() & Element::Master)
|
||||||
|
setText(QObject::tr("Editer les r\351f\351rence crois\351"));
|
||||||
else setText(QObject::tr("Lier deux éléments"));
|
else setText(QObject::tr("Lier deux éléments"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1179,9 +1194,13 @@ LinkElementsCommand::~LinkElementsCommand(){}
|
|||||||
*/
|
*/
|
||||||
void LinkElementsCommand::undo() {
|
void LinkElementsCommand::undo() {
|
||||||
diagram_->showMe();
|
diagram_->showMe();
|
||||||
elmt_1->unlinkElement(elmt_2);
|
|
||||||
|
foreach (Element *elmt, elmt_list)
|
||||||
|
element_->unlinkElement(elmt);
|
||||||
|
|
||||||
if (previous_report)
|
if (previous_report)
|
||||||
elmt_1->linkToElement(previous_report);
|
element_->linkToElement(previous_report);
|
||||||
|
QUndoCommand::undo();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1190,14 +1209,18 @@ void LinkElementsCommand::undo() {
|
|||||||
*/
|
*/
|
||||||
void LinkElementsCommand::redo() {
|
void LinkElementsCommand::redo() {
|
||||||
diagram_->showMe();
|
diagram_->showMe();
|
||||||
elmt_1->linkToElement(elmt_2);
|
|
||||||
//Check if text of this potential is identical.
|
foreach (Element *elmt, elmt_list)
|
||||||
if (first_redo) {
|
element_->linkToElement(elmt);
|
||||||
if(elmt_1->conductors().count() && elmt_2->conductors().count()) {
|
|
||||||
ConductorAutoNumerotation::checkPotential(elmt_1->conductors().first());
|
//If element are report, check if text of this potential is identical.
|
||||||
|
if ((element_->linkType() &Element::AllReport) && first_redo) {
|
||||||
|
if(element_->conductors().count() && elmt_list.first()->conductors().count()) {
|
||||||
|
ConductorAutoNumerotation::checkPotential(element_->conductors().first());
|
||||||
}
|
}
|
||||||
first_redo = false;
|
first_redo = false;
|
||||||
}
|
}
|
||||||
|
QUndoCommand::redo();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1217,6 +1240,21 @@ unlinkElementsCommand::unlinkElementsCommand(Element *elmt1, Element *elmt2, QUn
|
|||||||
setText(QObject::tr("D\351lier %n \351l\351ment(s)", "", elmt_list.size()));
|
setText(QObject::tr("D\351lier %n \351l\351ment(s)", "", elmt_list.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief unlinkElementsCommand::unlinkElementsCommand
|
||||||
|
* @param elmt1 Element to set the link
|
||||||
|
* @param elmtList list of all element to be linked to elmt1
|
||||||
|
* @param parent undo command
|
||||||
|
*/
|
||||||
|
unlinkElementsCommand::unlinkElementsCommand(Element *elmt1, QList<Element *> &elmtList, QUndoCommand *parent):
|
||||||
|
QUndoCommand(parent),
|
||||||
|
diagram_(elmt1->diagram()),
|
||||||
|
element_(elmt1),
|
||||||
|
elmt_list(elmtList)
|
||||||
|
{
|
||||||
|
setText(QObject::tr("D\351lier %n \351l\351ment(s)", "", elmt_list.size()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief unlinkElementsCommand::~unlinkElementsCommand
|
* @brief unlinkElementsCommand::~unlinkElementsCommand
|
||||||
* destructor
|
* destructor
|
||||||
@@ -1230,6 +1268,7 @@ unlinkElementsCommand::~unlinkElementsCommand(){}
|
|||||||
void unlinkElementsCommand::undo() {
|
void unlinkElementsCommand::undo() {
|
||||||
foreach (Element *elmt, elmt_list)
|
foreach (Element *elmt, elmt_list)
|
||||||
element_->linkToElement(elmt);
|
element_->linkToElement(elmt);
|
||||||
|
QUndoCommand::undo();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1239,4 +1278,5 @@ void unlinkElementsCommand::undo() {
|
|||||||
void unlinkElementsCommand::redo() {
|
void unlinkElementsCommand::redo() {
|
||||||
foreach (Element *elmt, elmt_list)
|
foreach (Element *elmt, elmt_list)
|
||||||
element_->unlinkElement(elmt);
|
element_->unlinkElement(elmt);
|
||||||
|
QUndoCommand::redo();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -591,6 +591,7 @@ class LinkElementsCommand : public QUndoCommand {
|
|||||||
public:
|
public:
|
||||||
// constructor destructor
|
// constructor destructor
|
||||||
LinkElementsCommand (Element *elmt1, Element *elmt2, QUndoCommand *parent = 0);
|
LinkElementsCommand (Element *elmt1, Element *elmt2, QUndoCommand *parent = 0);
|
||||||
|
LinkElementsCommand (Element *elmt1, QList <Element *> &elmtList, QUndoCommand *parent = 0);
|
||||||
virtual ~LinkElementsCommand();
|
virtual ~LinkElementsCommand();
|
||||||
//methods
|
//methods
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
@@ -599,7 +600,8 @@ class LinkElementsCommand : public QUndoCommand {
|
|||||||
private:
|
private:
|
||||||
//attributes
|
//attributes
|
||||||
Diagram *diagram_;
|
Diagram *diagram_;
|
||||||
Element *elmt_1, *elmt_2, *previous_report;
|
Element *element_, *previous_report;
|
||||||
|
QList <Element *> elmt_list;
|
||||||
bool first_redo;
|
bool first_redo;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -607,6 +609,7 @@ class unlinkElementsCommand : public QUndoCommand {
|
|||||||
public:
|
public:
|
||||||
//constructor destructor
|
//constructor destructor
|
||||||
unlinkElementsCommand (Element *elmt1, Element *elmt2 = 0, QUndoCommand *parent = 0);
|
unlinkElementsCommand (Element *elmt1, Element *elmt2 = 0, QUndoCommand *parent = 0);
|
||||||
|
unlinkElementsCommand (Element *elmt1, QList <Element *> &elmtList, QUndoCommand *parent = 0);
|
||||||
virtual ~unlinkElementsCommand();
|
virtual ~unlinkElementsCommand();
|
||||||
//methods
|
//methods
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
|
|||||||
@@ -158,10 +158,12 @@ void elementpropertieswidget::standardButtonClicked(QAbstractButton *button) {
|
|||||||
|
|
||||||
switch (answer) {
|
switch (answer) {
|
||||||
case QDialogButtonBox::ResetRole:
|
case QDialogButtonBox::ResetRole:
|
||||||
|
if (mpw_) mpw_->reset();
|
||||||
break;
|
break;
|
||||||
case QDialogButtonBox::ApplyRole:
|
case QDialogButtonBox::ApplyRole:
|
||||||
if (frp_) frp_->Apply(); //folio report widget
|
if (frp_) frp_->Apply(); //folio report widget
|
||||||
else if (eiw_) eiw_->apply(); //element information widget
|
if (eiw_) eiw_->apply(); //element information widget
|
||||||
|
if (mpw_) mpw_->apply(); //master property widget
|
||||||
this->accept();
|
this->accept();
|
||||||
case QDialogButtonBox::RejectRole:
|
case QDialogButtonBox::RejectRole:
|
||||||
this->reject();
|
this->reject();
|
||||||
|
|||||||
@@ -140,8 +140,10 @@ void FolioReportProperties::unlinkClicked() {
|
|||||||
* @param elmt: element to be displayed
|
* @param elmt: element to be displayed
|
||||||
*/
|
*/
|
||||||
void FolioReportProperties::showElement(Element *elmt) {
|
void FolioReportProperties::showElement(Element *elmt) {
|
||||||
|
QList <Element *> elmt_list = element_list;
|
||||||
|
elmt_list << element_->linkedElements() << element_;
|
||||||
|
foreach (Element *elmt, elmt_list) elmt->setSelected(false);
|
||||||
elmt->diagram()->showMe();
|
elmt->diagram()->showMe();
|
||||||
foreach (QGraphicsItem *qgi, elmt->diagram()->selectedItems()) qgi->setSelected(false);
|
|
||||||
elmt->setSelected(true);
|
elmt->setSelected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ namespace Ui {
|
|||||||
class FolioReportProperties;
|
class FolioReportProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The FolioReportProperties class
|
||||||
|
* This class is a widget for make link between two reports element.
|
||||||
|
* This class embendded the undo/redo command when apply new connection.
|
||||||
|
*/
|
||||||
class FolioReportProperties : public QWidget
|
class FolioReportProperties : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
@@ -20,7 +20,14 @@
|
|||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include <diagramposition.h>
|
#include <diagramposition.h>
|
||||||
#include <elementprovider.h>
|
#include <elementprovider.h>
|
||||||
|
#include <diagramcommands.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MasterPropertiesWidget::MasterPropertiesWidget
|
||||||
|
* Default constructor
|
||||||
|
* @param elmt
|
||||||
|
* @param parent
|
||||||
|
*/
|
||||||
MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
|
MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::MasterPropertiesWidget),
|
ui(new Ui::MasterPropertiesWidget),
|
||||||
@@ -28,14 +35,80 @@ MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
buildInterface();
|
buildInterface();
|
||||||
|
connect(ui->free_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
|
||||||
|
connect(ui->linked_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MasterPropertiesWidget::~MasterPropertiesWidget
|
||||||
|
* Destructor
|
||||||
|
*/
|
||||||
MasterPropertiesWidget::~MasterPropertiesWidget()
|
MasterPropertiesWidget::~MasterPropertiesWidget()
|
||||||
{
|
{
|
||||||
|
foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false);
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MasterPropertiesWidget::apply
|
||||||
|
* Do what we need when apply new conf
|
||||||
|
*/
|
||||||
|
void MasterPropertiesWidget::apply() {
|
||||||
|
QList <Element *> to_link;
|
||||||
|
QList <Element *> linked_ = element_->linkedElements();
|
||||||
|
|
||||||
|
for (int i=0; i<ui->linked_list->count(); i++) {
|
||||||
|
to_link << lwi_hash[ui->linked_list->item(i)];
|
||||||
|
}
|
||||||
|
|
||||||
|
//If same element are find in to_link and linked, that means
|
||||||
|
// element are already linked, so we remove element on the two list
|
||||||
|
//if linked_ contains element at the end of the operation,
|
||||||
|
//that means this element must be unlinked from @element_
|
||||||
|
foreach (Element *elmt, to_link) {
|
||||||
|
if(linked_.contains(elmt)) {
|
||||||
|
to_link.removeAll(elmt);
|
||||||
|
linked_.removeAll(elmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if two list, contain element, we link and unlink @element_ with corresponding
|
||||||
|
//undo command, and add first command for parent of the second, user see only one
|
||||||
|
//undo command
|
||||||
|
if (linked_.count() && to_link.count()) {
|
||||||
|
LinkElementsCommand *lec = new LinkElementsCommand(element_, to_link);
|
||||||
|
new unlinkElementsCommand(element_, linked_, lec);
|
||||||
|
element_->diagram()->undoStack().push(lec);
|
||||||
|
}
|
||||||
|
//Else do the single undo command corresponding to the link.
|
||||||
|
else if (to_link.count()) {
|
||||||
|
LinkElementsCommand *lec = new LinkElementsCommand(element_, to_link);
|
||||||
|
element_->diagram()->undoStack().push(lec);
|
||||||
|
}
|
||||||
|
else if (linked_.count()) {
|
||||||
|
unlinkElementsCommand *uec = new unlinkElementsCommand(element_, linked_);
|
||||||
|
element_->diagram()->undoStack().push(uec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MasterPropertiesWidget::reset
|
||||||
|
* Reset curent widget, clear eveything and rebuild widget.
|
||||||
|
*/
|
||||||
|
void MasterPropertiesWidget::reset() {
|
||||||
|
foreach (QListWidgetItem *lwi, lwi_hash.keys()) {
|
||||||
|
delete lwi;
|
||||||
|
}
|
||||||
|
lwi_hash.clear();
|
||||||
|
buildInterface();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MasterPropertiesWidget::buildInterface
|
||||||
|
* Build the interface of the widget
|
||||||
|
*/
|
||||||
void MasterPropertiesWidget::buildInterface() {
|
void MasterPropertiesWidget::buildInterface() {
|
||||||
|
//build the free list
|
||||||
ElementProvider elmt_prov(element_->diagram()->project());
|
ElementProvider elmt_prov(element_->diagram()->project());
|
||||||
|
|
||||||
foreach(Element *elmt, elmt_prov.freeElement(Element::Slave)) {
|
foreach(Element *elmt, elmt_prov.freeElement(Element::Slave)) {
|
||||||
@@ -47,8 +120,23 @@ void MasterPropertiesWidget::buildInterface() {
|
|||||||
.arg(title)
|
.arg(title)
|
||||||
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
|
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
|
||||||
QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text);
|
QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text);
|
||||||
|
lwi_hash.insert(lwi_, elmt);
|
||||||
ui->free_list->addItem(lwi_);
|
ui->free_list->addItem(lwi_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//build the linked list
|
||||||
|
foreach(Element *elmt, element_->linkedElements()) {
|
||||||
|
//label for list widget
|
||||||
|
QString widget_text;
|
||||||
|
QString title = elmt->diagram()->title();
|
||||||
|
if (title.isEmpty()) title = tr("Sans titre");
|
||||||
|
widget_text += QString(tr("Folio\240 %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1)
|
||||||
|
.arg(title)
|
||||||
|
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
|
||||||
|
QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text);
|
||||||
|
lwi_hash.insert(lwi_, elmt);
|
||||||
|
ui->linked_list->addItem(lwi_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,9 +150,25 @@ void MasterPropertiesWidget::on_link_button_clicked() {
|
|||||||
ui->free_list->currentRow()));
|
ui->free_list->currentRow()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MasterPropertiesWidget::on_unlink_button_clicked
|
||||||
|
* move curent item in linked_list to free_list
|
||||||
|
*/
|
||||||
void MasterPropertiesWidget::on_unlink_button_clicked() {
|
void MasterPropertiesWidget::on_unlink_button_clicked() {
|
||||||
//take the curent item from linked_list and push it to free_list
|
//take the curent item from linked_list and push it to free_list
|
||||||
ui->free_list->addItem(
|
ui->free_list->addItem(
|
||||||
ui->linked_list->takeItem(
|
ui->linked_list->takeItem(
|
||||||
ui->linked_list->currentRow()));
|
ui->linked_list->currentRow()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MasterPropertiesWidget::showElementFromLWI
|
||||||
|
* Show the element corresponding to the given QListWidgetItem
|
||||||
|
* @param lwi
|
||||||
|
*/
|
||||||
|
void MasterPropertiesWidget::showElementFromLWI(QListWidgetItem *lwi) {
|
||||||
|
foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false);
|
||||||
|
Element *elmt = lwi_hash[lwi];
|
||||||
|
elmt->diagram()->showMe();
|
||||||
|
elmt->setHighlighted(true);
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ namespace Ui {
|
|||||||
class MasterPropertiesWidget;
|
class MasterPropertiesWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The MasterPropertiesWidget class
|
||||||
|
* This class is a widget for make link between a master element with several slave element.
|
||||||
|
* This class embenddedthe undo/redo command when apply new connection.
|
||||||
|
*/
|
||||||
|
|
||||||
class MasterPropertiesWidget : public QWidget
|
class MasterPropertiesWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -33,16 +39,21 @@ class MasterPropertiesWidget : public QWidget
|
|||||||
explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0);
|
explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0);
|
||||||
~MasterPropertiesWidget();
|
~MasterPropertiesWidget();
|
||||||
|
|
||||||
|
void apply();
|
||||||
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildInterface();
|
void buildInterface();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_link_button_clicked();
|
void on_link_button_clicked();
|
||||||
void on_unlink_button_clicked();
|
void on_unlink_button_clicked();
|
||||||
|
void showElementFromLWI(QListWidgetItem *lwi);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MasterPropertiesWidget *ui;
|
Ui::MasterPropertiesWidget *ui;
|
||||||
Element *element_;
|
Element *element_;
|
||||||
|
QHash <QListWidgetItem *, Element *> lwi_hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MASTERPROPERTIESWIDGET_H
|
#endif // MASTERPROPERTIESWIDGET_H
|
||||||
|
|||||||
Reference in New Issue
Block a user