From bf707cca2e7f245144803eed2a7cf0b408646cff Mon Sep 17 00:00:00 2001 From: blacksun Date: Wed, 26 Feb 2014 23:57:22 +0000 Subject: [PATCH] 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 --- sources/diagramcommands.cpp | 58 +++++++++++--- sources/diagramcommands.h | 5 +- sources/ui/elementpropertieswidget.cpp | 6 +- sources/ui/folioreportproperties.cpp | 4 +- sources/ui/folioreportproperties.h | 5 ++ sources/ui/masterpropertieswidget.cpp | 104 +++++++++++++++++++++++++ sources/ui/masterpropertieswidget.h | 11 +++ 7 files changed, 180 insertions(+), 13 deletions(-) diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index bf14d009c..e2854cc4e 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -1152,11 +1152,11 @@ void ImageResizerCommand::redo() { LinkElementsCommand::LinkElementsCommand(Element *elmt1, Element *elmt2, QUndoCommand *parent) : QUndoCommand(parent), diagram_(elmt1->diagram()), - elmt_1(elmt1), - elmt_2(elmt2), + element_(elmt1), previous_report(0), first_redo(true) { + elmt_list << elmt2; if (elmt1->linkType() & Element::AllReport && elmt2->linkType() & Element::AllReport) { setText(QObject::tr("Lier deux reports de folio", @@ -1164,6 +1164,21 @@ LinkElementsCommand::LinkElementsCommand(Element *elmt1, Element *elmt2, QUndoCo if(!elmt1->isFree()) 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 &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")); } @@ -1179,9 +1194,13 @@ LinkElementsCommand::~LinkElementsCommand(){} */ void LinkElementsCommand::undo() { diagram_->showMe(); - elmt_1->unlinkElement(elmt_2); + + foreach (Element *elmt, elmt_list) + element_->unlinkElement(elmt); + if (previous_report) - elmt_1->linkToElement(previous_report); + element_->linkToElement(previous_report); + QUndoCommand::undo(); } /** @@ -1190,14 +1209,18 @@ void LinkElementsCommand::undo() { */ void LinkElementsCommand::redo() { diagram_->showMe(); - elmt_1->linkToElement(elmt_2); - //Check if text of this potential is identical. - if (first_redo) { - if(elmt_1->conductors().count() && elmt_2->conductors().count()) { - ConductorAutoNumerotation::checkPotential(elmt_1->conductors().first()); + + foreach (Element *elmt, elmt_list) + element_->linkToElement(elmt); + + //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; } + 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())); } +/** + * @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 &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 * destructor @@ -1230,6 +1268,7 @@ unlinkElementsCommand::~unlinkElementsCommand(){} void unlinkElementsCommand::undo() { foreach (Element *elmt, elmt_list) element_->linkToElement(elmt); + QUndoCommand::undo(); } /** @@ -1239,4 +1278,5 @@ void unlinkElementsCommand::undo() { void unlinkElementsCommand::redo() { foreach (Element *elmt, elmt_list) element_->unlinkElement(elmt); + QUndoCommand::redo(); } diff --git a/sources/diagramcommands.h b/sources/diagramcommands.h index b4291655f..383b8bc82 100644 --- a/sources/diagramcommands.h +++ b/sources/diagramcommands.h @@ -591,6 +591,7 @@ class LinkElementsCommand : public QUndoCommand { public: // constructor destructor LinkElementsCommand (Element *elmt1, Element *elmt2, QUndoCommand *parent = 0); + LinkElementsCommand (Element *elmt1, QList &elmtList, QUndoCommand *parent = 0); virtual ~LinkElementsCommand(); //methods virtual void undo(); @@ -599,7 +600,8 @@ class LinkElementsCommand : public QUndoCommand { private: //attributes Diagram *diagram_; - Element *elmt_1, *elmt_2, *previous_report; + Element *element_, *previous_report; + QList elmt_list; bool first_redo; }; @@ -607,6 +609,7 @@ class unlinkElementsCommand : public QUndoCommand { public: //constructor destructor unlinkElementsCommand (Element *elmt1, Element *elmt2 = 0, QUndoCommand *parent = 0); + unlinkElementsCommand (Element *elmt1, QList &elmtList, QUndoCommand *parent = 0); virtual ~unlinkElementsCommand(); //methods virtual void undo(); diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index 4e26f323e..de2f365a6 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -158,10 +158,12 @@ void elementpropertieswidget::standardButtonClicked(QAbstractButton *button) { switch (answer) { case QDialogButtonBox::ResetRole: + if (mpw_) mpw_->reset(); break; case QDialogButtonBox::ApplyRole: - if (frp_) frp_->Apply(); //folio report widget - else if (eiw_) eiw_->apply(); //element information widget + if (frp_) frp_->Apply(); //folio report widget + if (eiw_) eiw_->apply(); //element information widget + if (mpw_) mpw_->apply(); //master property widget this->accept(); case QDialogButtonBox::RejectRole: this->reject(); diff --git a/sources/ui/folioreportproperties.cpp b/sources/ui/folioreportproperties.cpp index eb70a367d..bb34ce99e 100644 --- a/sources/ui/folioreportproperties.cpp +++ b/sources/ui/folioreportproperties.cpp @@ -140,8 +140,10 @@ void FolioReportProperties::unlinkClicked() { * @param elmt: element to be displayed */ void FolioReportProperties::showElement(Element *elmt) { + QList elmt_list = element_list; + elmt_list << element_->linkedElements() << element_; + foreach (Element *elmt, elmt_list) elmt->setSelected(false); elmt->diagram()->showMe(); - foreach (QGraphicsItem *qgi, elmt->diagram()->selectedItems()) qgi->setSelected(false); elmt->setSelected(true); } diff --git a/sources/ui/folioreportproperties.h b/sources/ui/folioreportproperties.h index 37fd9d711..4dc49f6a0 100644 --- a/sources/ui/folioreportproperties.h +++ b/sources/ui/folioreportproperties.h @@ -25,6 +25,11 @@ namespace Ui { 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 { Q_OBJECT diff --git a/sources/ui/masterpropertieswidget.cpp b/sources/ui/masterpropertieswidget.cpp index 0f8e0014b..56070bd1b 100644 --- a/sources/ui/masterpropertieswidget.cpp +++ b/sources/ui/masterpropertieswidget.cpp @@ -20,7 +20,14 @@ #include #include #include +#include +/** + * @brief MasterPropertiesWidget::MasterPropertiesWidget + * Default constructor + * @param elmt + * @param parent + */ MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) : QWidget(parent), ui(new Ui::MasterPropertiesWidget), @@ -28,14 +35,80 @@ MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) : { ui->setupUi(this); 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() { + foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false); delete ui; } +/** + * @brief MasterPropertiesWidget::apply + * Do what we need when apply new conf + */ +void MasterPropertiesWidget::apply() { + QList to_link; + QList linked_ = element_->linkedElements(); + + for (int i=0; ilinked_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() { + //build the free list ElementProvider elmt_prov(element_->diagram()->project()); foreach(Element *elmt, elmt_prov.freeElement(Element::Slave)) { @@ -47,8 +120,23 @@ void MasterPropertiesWidget::buildInterface() { .arg(title) .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString()); QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text); + lwi_hash.insert(lwi_, elmt); 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())); } +/** + * @brief MasterPropertiesWidget::on_unlink_button_clicked + * move curent item in linked_list to free_list + */ void MasterPropertiesWidget::on_unlink_button_clicked() { //take the curent item from linked_list and push it to free_list ui->free_list->addItem( ui->linked_list->takeItem( 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); +} diff --git a/sources/ui/masterpropertieswidget.h b/sources/ui/masterpropertieswidget.h index dc5f00b71..92b131f89 100644 --- a/sources/ui/masterpropertieswidget.h +++ b/sources/ui/masterpropertieswidget.h @@ -25,6 +25,12 @@ namespace Ui { 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 { Q_OBJECT @@ -33,16 +39,21 @@ class MasterPropertiesWidget : public QWidget explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0); ~MasterPropertiesWidget(); + void apply(); + void reset(); + private: void buildInterface(); private slots: void on_link_button_clicked(); void on_unlink_button_clicked(); + void showElementFromLWI(QListWidgetItem *lwi); private: Ui::MasterPropertiesWidget *ui; Element *element_; + QHash lwi_hash; }; #endif // MASTERPROPERTIESWIDGET_H