diff --git a/qelectrotech.pro b/qelectrotech.pro index 1cfcd1c52..e3154f57b 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -61,10 +61,11 @@ DEFINES += QET_ALLOW_OVERRIDE_CD_OPTION TEMPLATE = app DEPENDPATH += . -INCLUDEPATH += sources sources/editor sources/titleblock +INCLUDEPATH += sources sources/editor sources/titleblock sources/ui sources/qetgraphicsitem sources/richtext sources/factory # Fichiers sources HEADERS += sources/*.h sources/ui/*.h sources/editor/*.h sources/titleblock/*.h sources/richtext/*.h sources/qetgraphicsitem/*.h sources/factory/*.cpp + SOURCES += sources/*.cpp sources/editor/*.cpp sources/titleblock/*.cpp sources/richtext/*.cpp sources/ui/*.cpp sources/qetgraphicsitem/*.cpp sources/factory/*.cpp # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt @@ -80,7 +81,9 @@ TRANSLATIONS += lang/qet_en.ts lang/qet_es.ts lang/qet_fr.ts lang/qet_ru.ts lang QT += xml svg network sql # UI DESIGNER FILES AND GENERATION SOURCES FILES -FORMS += sources/richtext/addlinkdialog.ui sources/ui/*.ui +FORMS += sources/richtext/addlinkdialog.ui sources/ui/*.ui \ + sources/ui/slavepropertieswidget.ui \ + sources/ui/linksingleelementwidget.ui UI_SOURCES_DIR = sources/ui/ UI_HEADERS_DIR = sources/ui/ diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index 05d551c9f..dad684b74 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -1250,7 +1250,6 @@ LinkElementsCommand::LinkElementsCommand(Element *elmt1, Element *elmt2, QUndoCo QUndoCommand(parent), diagram_(elmt1->diagram()), element_(elmt1), - previous_report(0), first_redo(true) { elmt_list << elmt2; @@ -1258,12 +1257,12 @@ LinkElementsCommand::LinkElementsCommand(Element *elmt1, Element *elmt2, QUndoCo elmt2->linkType() & Element::AllReport) { setText(QObject::tr("Lier deux reports de folio", "title for undo LinkElementsCommand if two elements are folio report")); - if(!elmt1->isFree()) - previous_report = elmt1->linkedElements().first(); } - else if (element_->linkType() & Element::Master) + else if (element_->linkType() & (Element::Master|Element::Slave)) setText(QObject::tr("Editer les r\351f\351rence crois\351", "edite the cross reference")); else setText(QObject::tr("Lier deux éléments")); + + previous_linked = elmt1->linkedElements(); } LinkElementsCommand::LinkElementsCommand(Element *elmt1, QList &elmtList, QUndoCommand *parent) : @@ -1271,12 +1270,12 @@ LinkElementsCommand::LinkElementsCommand(Element *elmt1, QList &elmtL diagram_(elmt1->diagram()), element_(elmt1), elmt_list(elmtList), - previous_report(0), first_redo(true) { - if (element_->linkType() & Element::Master) + if (element_->linkType() & (Element::Master|Element::Slave)) setText(QObject::tr("Editer les r\351f\351rence crois\351")); else setText(QObject::tr("Lier deux éléments")); + previous_linked = elmt1->linkedElements(); } /** @@ -1295,8 +1294,9 @@ void LinkElementsCommand::undo() { foreach (Element *elmt, elmt_list) element_->unlinkElement(elmt); - if (previous_report) - element_->linkToElement(previous_report); + foreach (Element *elmt, previous_linked) + element_->linkToElement(elmt); + QUndoCommand::undo(); } diff --git a/sources/diagramcommands.h b/sources/diagramcommands.h index 206f81d59..0fe5b0f22 100644 --- a/sources/diagramcommands.h +++ b/sources/diagramcommands.h @@ -648,8 +648,9 @@ class LinkElementsCommand : public QUndoCommand { private: //attributes Diagram *diagram_; - Element *element_, *previous_report; + Element *element_; QList elmt_list; + QList previous_linked; bool first_redo; }; diff --git a/sources/elementprovider.cpp b/sources/elementprovider.cpp index bf1194bdc..85345b610 100644 --- a/sources/elementprovider.cpp +++ b/sources/elementprovider.cpp @@ -21,7 +21,7 @@ /** * @brief ElementProvider::ElementProvider Constructor * @param prj the project where we must find element - * @param diagram the digram to exclude from the search + * @param diagram the diagram to exclude from the search */ ElementProvider::ElementProvider(QETProject *prj, Diagram *diagram) { @@ -29,6 +29,14 @@ ElementProvider::ElementProvider(QETProject *prj, Diagram *diagram) diag_list.removeOne(diagram); } +/** + * @brief ElementProvider::ElementProvider Constructor + * @param diag Diagram to search + */ +ElementProvider::ElementProvider(Diagram *diag) { + diag_list << diag; +} + /** * @brief ElementProvider::FreeElement * Search and return the asked element corresponding with the given filter @@ -72,3 +80,26 @@ QList ElementProvider::fromUuids(QList uuid_list) const { } return found_element; } + +/** + * @brief ElementProvider::find + * Search and return the asked element corresponding with the given filter + * @param filter + * the filter for search element + * (You can find all filter with the #define in Element.h) + */ +QList ElementProvider::find(const int filter) const { + QList elmt_; + + //serch in all diagram + foreach (Diagram *d, diag_list) { + //get all element in diagram d + QList elmt_list; + elmt_list = d->elements(); + foreach (Element *elmt, elmt_list) { + if (filter & elmt->linkType()) + elmt_ << elmt; + } + } + return (elmt_); +} diff --git a/sources/elementprovider.h b/sources/elementprovider.h index d8d065fba..106bebd92 100644 --- a/sources/elementprovider.h +++ b/sources/elementprovider.h @@ -32,8 +32,10 @@ class ElementProvider { public: ElementProvider(QETProject *prj, Diagram *diagram=0); + ElementProvider(Diagram *diag); QList freeElement(const int filter) const; QList fromUuids(QList ) const; + QList find(const int filter) const; private: QList diag_list; diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index de2f365a6..f4fd16702 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -16,9 +16,9 @@ along with QElectroTech. If not, see . */ #include "elementpropertieswidget.h" -#include -#include -#include +#include "qetgraphicsitem/ghostelement.h" +#include "qeticons.h" +#include "diagramposition.h" /** * @brief elementpropertieswidget::elementpropertieswidget @@ -31,9 +31,9 @@ elementpropertieswidget::elementpropertieswidget(Element *elmt, QWidget *parent) element_ (elmt), diagram_ (elmt->diagram()) { - frp_ = 0; eiw_ = 0; mpw_ = 0; + lsew_ = 0; buildInterface(); } @@ -114,12 +114,12 @@ void elementpropertieswidget::buildInterface() { tab_ -> addTab(eiw_, tr("Information")); break; case Element::NextReport: - frp_ = new FolioReportProperties(element_, this); - tab_ -> addTab(frp_, tr("Report de folio")); + lsew_ = new LinkSingleElementWidget(element_, this); + tab_ -> addTab(lsew_, tr("Report de folio")); break; case Element::PreviousReport: - frp_ = new FolioReportProperties(element_, this); - tab_ -> addTab(frp_, tr("Report de folio")); + lsew_ = new LinkSingleElementWidget(element_, this); + tab_ -> addTab(lsew_, tr("Report de folio")); break; case Element::Master: mpw_ = new MasterPropertiesWidget(element_, this); @@ -128,6 +128,8 @@ void elementpropertieswidget::buildInterface() { tab_ -> addTab(eiw_, tr("Information")); break; case Element::Slave: + lsew_ = new LinkSingleElementWidget(element_, this); + tab_ -> addTab(lsew_, tr("R\351f\351rence crois\351e (esclave)")); break; case Element::Bornier: break; @@ -161,9 +163,9 @@ void elementpropertieswidget::standardButtonClicked(QAbstractButton *button) { if (mpw_) mpw_->reset(); break; case QDialogButtonBox::ApplyRole: - if (frp_) frp_->Apply(); //folio report widget if (eiw_) eiw_->apply(); //element information widget if (mpw_) mpw_->apply(); //master property widget + if (lsew_) lsew_->apply(); //link sigle element widget this->accept(); case QDialogButtonBox::RejectRole: this->reject(); diff --git a/sources/ui/elementpropertieswidget.h b/sources/ui/elementpropertieswidget.h index 26a698230..a48301879 100644 --- a/sources/ui/elementpropertieswidget.h +++ b/sources/ui/elementpropertieswidget.h @@ -19,11 +19,11 @@ #define ELEMENTPROPERTIESWIDGET_H #include -#include -#include -#include -#include -#include +#include "qetgraphicsitem/element.h" +#include "diagram.h" +#include "elementinfowidget.h" +#include "masterpropertieswidget.h" +#include "linksingleelementwidget.h" class elementpropertieswidget : public QDialog { @@ -47,9 +47,9 @@ class elementpropertieswidget : public QDialog void editElement (); private: - FolioReportProperties *frp_; ElementInfoWidget *eiw_; MasterPropertiesWidget *mpw_; + LinkSingleElementWidget *lsew_; QDialogButtonBox *dbb; Element *element_; Diagram *diagram_; diff --git a/sources/ui/elementselectorwidget.cpp b/sources/ui/elementselectorwidget.cpp new file mode 100644 index 000000000..4451dcab1 --- /dev/null +++ b/sources/ui/elementselectorwidget.cpp @@ -0,0 +1,116 @@ +/* + Copyright 2006-2014 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 . +*/ +#include "elementselectorwidget.h" +#include "ui_elementselectorwidget.h" +#include "diagramposition.h" +#include "qeticons.h" + +/** + * @brief ElementSelectorWidget::ElementSelectorWidget + * Default constructor + * @param elmt_list + * List of element to be displayed by the selector + * @param parent + * Parent widget + */ +ElementSelectorWidget::ElementSelectorWidget(QList elmt_list, QWidget *parent) : + QWidget(parent), + ui(new Ui::ElementSelectorWidget), + elements_list(elmt_list), + selected_element(0), + showed_element(0) +{ + ui->setupUi(this); + buildInterface(); +} + +/** + * @brief ElementSelectorWidget::~ElementSelectorWidget + * Default destructor + */ +ElementSelectorWidget::~ElementSelectorWidget() +{ + if (showed_element) showed_element->setHighlighted(false); + delete ui; +} + +/** + * @brief ElementSelectorWidget::showElement + * Show the element given by parametre + * @param elmt + */ +void ElementSelectorWidget::showElement(Element *elmt) { + if (showed_element) showed_element->setHighlighted(false); + elmt->diagram()->showMe(); + elmt->setHighlighted(true); + showed_element = elmt; +} + +/** + * @brief ElementSelectorWidget::buildInterface + * Build interface of this widget (fill all available element) + */ +void ElementSelectorWidget::buildInterface() { + //Setup the signal mapper + int map_id = 0; //this int is used to map the signal + sm_ = new QSignalMapper(this); + connect(sm_, SIGNAL(mapped(int)), this, SLOT(setSelectedElement(int))); + sm_show_ = new QSignalMapper(this); + connect(sm_show_, SIGNAL(mapped(int)), this, SLOT(showElementFromList(int))); + + //Build the list + foreach (Element *elmt, elements_list) { + //label for the button + QString button_text; + QString title = elmt->diagram()->title(); + if (title.isEmpty()) title = tr("Sans titre"); + button_text += QString(tr("Folio\240 %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1) + .arg(title) + .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString()); + + //add the button himself + QHBoxLayout *hl = new QHBoxLayout(); + QRadioButton *rb = new QRadioButton(button_text , this); + QPushButton *pb = new QPushButton(QET::Icons::ZoomDraw,"", this); + pb->setToolTip(tr("Voir l'\351l\351ment")); + hl->addWidget(rb); + hl->addStretch(); + hl->addWidget(pb); + ui->scroll_layout_->addLayout(hl); + + //map the radio button signal + connect(rb, SIGNAL(clicked()), sm_, SLOT(map())); + sm_ -> setMapping(rb, map_id); + //map the push button show diagram + connect(pb, SIGNAL(clicked()), sm_show_, SLOT(map())); + sm_show_->setMapping(pb, map_id); + + map_id++; //increase the map_id for next button. + } + ui->scroll_layout_->addStretch(); +} + +/** + * @brief ElementSelectorWidget::showElementFromList + * Show the element at the position i in @elements_list + * @param i + */ +void ElementSelectorWidget::showElementFromList(const int i) { + if (elements_list.size() >= i) + showElement(elements_list.at(i)); +} diff --git a/sources/ui/folioreportproperties.h b/sources/ui/elementselectorwidget.h similarity index 51% rename from sources/ui/folioreportproperties.h rename to sources/ui/elementselectorwidget.h index 4dc49f6a0..87d2ae076 100644 --- a/sources/ui/folioreportproperties.h +++ b/sources/ui/elementselectorwidget.h @@ -1,62 +1,61 @@ /* Copyright 2006-2014 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 . */ -#ifndef FOLIOREPORTPROPERTIES_H -#define FOLIOREPORTPROPERTIES_H +#ifndef ELEMENTSELECTORWIDGET_H +#define ELEMENTSELECTORWIDGET_H #include -#include +#include "qetgraphicsitem/element.h" namespace Ui { - class FolioReportProperties; + class ElementSelectorWidget; } /** - * @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. + * @brief The ElementSelectorWidget class + * This class provide a widget with a list of element. + * User can select an element in the list and higligth it. + * For know what element is selected, call selectedElement. */ -class FolioReportProperties : public QWidget +class ElementSelectorWidget : public QWidget { Q_OBJECT + ///Methods public: - explicit FolioReportProperties(Element *elmt, QWidget *parent = 0); - ~FolioReportProperties(); - void Apply(); - - private slots: - void linkToElement(const int i) {element_to_link = element_list.at(i);} - void unlinkClicked(); + explicit ElementSelectorWidget(QList elmt_list, QWidget *parent = 0); + ~ElementSelectorWidget(); + Element * selectedElement () const{return selected_element;} void showElement(Element *elmt); - void showElementFromList (const int i); - void on_button_this_clicked(); - void on_button_linked_clicked(); private: - void buildRadioList(); - void buildUnlinkButton(); + void buildInterface(); - Element *element_, *element_to_link; - QList element_list; - Ui::FolioReportProperties *ui; + private slots: + void setSelectedElement(const int i) {selected_element = elements_list.at(i);} + void showElementFromList (const int i); + + + ///Attributes + private: + Ui::ElementSelectorWidget *ui; + QList elements_list; QSignalMapper *sm_, *sm_show_; - QWidget *unlink_widget; - bool unlink; + Element *selected_element, *showed_element; }; -#endif // FOLIOREPORTPROPERTIES_H +#endif // ELEMENTSELECTORWIDGET_H diff --git a/sources/ui/elementselectorwidget.ui b/sources/ui/elementselectorwidget.ui new file mode 100644 index 000000000..5a26f585b --- /dev/null +++ b/sources/ui/elementselectorwidget.ui @@ -0,0 +1,39 @@ + + + ElementSelectorWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + true + + + + + 0 + 0 + 380 + 280 + + + + + + + + + + + diff --git a/sources/ui/folioreportproperties.cpp b/sources/ui/folioreportproperties.cpp deleted file mode 100644 index bb34ce99e..000000000 --- a/sources/ui/folioreportproperties.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - Copyright 2006-2014 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 . -*/ -#include "folioreportproperties.h" -#include "ui_folioreportproperties.h" - -#include -#include -#include -#include -#include "qeticons.h" - -/** - * @brief FolioReportProperties::FolioReportProperties : Construcor - * @param elmt : The edited element - * @param parent : Parent widget - */ -FolioReportProperties::FolioReportProperties(Element *elmt, QWidget *parent) : - QWidget(parent), - element_(elmt), - element_to_link(0), - ui(new Ui::FolioReportProperties) -{ - ui->setupUi(this); - unlink = false; - if(element_->isFree()) { - buildRadioList(); - ui->button_linked->setDisabled(true); - } - else buildUnlinkButton(); -} - -/** - * @brief FolioReportProperties::~FolioReportProperties : Destructor - */ -FolioReportProperties::~FolioReportProperties() -{ - delete ui; -} - -/** - * @brief FolioReportProperties::BuildRadioList : build the radio list for each available folio report - */ -void FolioReportProperties::buildRadioList() { - sm_ = new QSignalMapper(this); - connect(sm_, SIGNAL(mapped(int)), this, SLOT(linkToElement(int))); - sm_show_ = new QSignalMapper(this); - connect(sm_show_, SIGNAL(mapped(int)), this, SLOT(showElementFromList(int))); - - //Research the invert report of @element_ - int rep = element_->linkType() == Element::NextReport? Element::PreviousReport : Element::NextReport; - ElementProvider ep(element_->diagram()->project()); - QList elmt_list = ep.freeElement(rep); - - foreach (Element *elmt, elmt_list) { - if (elmt != element_) { - //label for the button - QString button_text; - QString title = elmt->diagram()->title(); - if (title.isEmpty()) title = tr("Sans titre"); - button_text += QString(tr("Folio\240 %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1) - .arg(title) - .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString()); - - //button himself - QHBoxLayout *hl = new QHBoxLayout(); - QRadioButton *rb = new QRadioButton(button_text , this); - QPushButton *pb = new QPushButton(QET::Icons::ZoomDraw,"",this); - hl->addWidget(rb); - hl->addStretch(); - hl->addWidget(pb); - ui->available_report_layout->addLayout(hl); - element_list << elmt; - //map the radio button signal - connect(rb, SIGNAL(clicked()), sm_, SLOT(map())); - sm_ -> setMapping(rb, element_list.size()-1); - //map the push button show diagram - connect(pb, SIGNAL(clicked()), sm_show_, SLOT(map())); - sm_show_->setMapping(pb, element_list.size()-1); - } - } - ui->available_report_layout->addStretch(); -} - -/** - * @brief FolioReportProperties::buildUnlinkButton - *build button for ask user if want to unlink this element - */ -void FolioReportProperties::buildUnlinkButton() { - unlink_widget = new QWidget(this); - QHBoxLayout *unlink_layout = new QHBoxLayout(unlink_widget); - QLabel *lb = new QLabel(tr("Ce report est d\351j\340 li\351."), unlink_widget); - QPushButton *pb = new QPushButton(tr("D\351lier"), unlink_widget); - connect(pb, SIGNAL(clicked()), this, SLOT(unlinkClicked())); - unlink_layout->addWidget(lb); - unlink_layout->addStretch(); - unlink_layout->addWidget(pb); - ui->v_main_layout->insertWidget(0, unlink_widget); -} - -/** - * @brief FolioReportProperties::Apply - * Apply the new properties for this folio report - */ -void FolioReportProperties::Apply() { - if (unlink && !element_to_link) - element_->diagram()->undoStack().push(new unlinkElementsCommand(element_)); - else if (element_to_link) - element_->diagram()->undoStack().push(new LinkElementsCommand(element_, element_to_link)); -} - -/** - * @brief FolioReportProperties::unlinkClicked - *this slot remove unlink_layout and call buildRadioList - */ -void FolioReportProperties::unlinkClicked() { - ui->v_main_layout->removeWidget(unlink_widget); - delete unlink_widget; - unlink = true; - buildRadioList(); -} - -/** - * @brief FolioReportProperties::showElement - * Show the required element - * @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(); - elmt->setSelected(true); -} - -/** - * @brief FolioReportProperties::showElementFromList - * Show element at the position @i from @element_list - * @param i position of element to be displayed - */ -void FolioReportProperties::showElementFromList(const int i) { - if (element_list.size() > i) - showElement(element_list.at(i)); -} - -/** - * @brief FolioReportProperties::on_button_this_clicked - * Action when push button "this report" is clicked - */ -void FolioReportProperties::on_button_this_clicked() { - showElement(element_); -} - -/** - * @brief FolioReportProperties::on_button_linked_clicked - * Action when push button "linked report" is clicked - */ -void FolioReportProperties::on_button_linked_clicked() { - if (element_->isFree()) return; - showElement(element_->linkedElements().first()); -} diff --git a/sources/ui/folioreportproperties.ui b/sources/ui/folioreportproperties.ui deleted file mode 100644 index 4e9ccde50..000000000 --- a/sources/ui/folioreportproperties.ui +++ /dev/null @@ -1,101 +0,0 @@ - - - FolioReportProperties - - - - 0 - 0 - 400 - 300 - - - - Form - - - - 9 - - - - - - - - - - - - - Report de folio disponible : - - - - QLayout::SetMinimumSize - - - 0 - - - 2 - - - 0 - - - 0 - - - - - true - - - - - 0 - 0 - 370 - 224 - - - - - QLayout::SetMinimumSize - - - 0 - - - - - - - - - - - - - - Voir ce report - - - - - - - Voir le report lié - - - - - - - - - - - - diff --git a/sources/ui/linksingleelementwidget.cpp b/sources/ui/linksingleelementwidget.cpp new file mode 100644 index 000000000..39dea8a64 --- /dev/null +++ b/sources/ui/linksingleelementwidget.cpp @@ -0,0 +1,194 @@ +/* + Copyright 2006-2014 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 . +*/ +#include "linksingleelementwidget.h" +#include "ui_linksingleelementwidget.h" +#include "diagram.h" +#include "element.h" +#include "elementprovider.h" +#include "diagramcommands.h" + +/** + * @brief LinkSingleElementWidget::LinkSingleElementWidget + * Default constructor + * @param elmt + * the edited element + * @param parent + * the parent widget + */ +LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent) : + QWidget(parent), + ui(new Ui::LinkSingleElementWidget), + element_(elmt), + esw_(0), + diagram_list(element_->diagram()->project()->diagrams()), + unlink_widget(0), + unlink_(false) +{ + ui->setupUi(this); + + if (elmt->linkType() & Element::Slave) + filter_ = Element::Master; + else if (elmt->linkType() & Element::AllReport) + filter_ = elmt->linkType() == Element::NextReport? Element::PreviousReport : Element::NextReport; + else + filter_ = Element::Simple; + + buildInterface(); + connect(ui->folio_combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(reBuildList())); +} + +/** + * @brief LinkSingleElementWidget::~LinkSingleElementWidget + * Default destructor + */ +LinkSingleElementWidget::~LinkSingleElementWidget() +{ + delete ui; +} + +/** + * @brief LinkSingleElementWidget::apply + * Apply the new property of the edited element + */ +void LinkSingleElementWidget::apply() { + if (esw_->selectedElement()) + element_->diagram()->undoStack().push(new LinkElementsCommand(element_, esw_->selectedElement())); + else if (unlink_) + element_->diagram()->undoStack().push(new unlinkElementsCommand(element_)); +} + +/** + * @brief LinkSingleElementWidget::buildInterface + * Build the interface of this widget + */ +void LinkSingleElementWidget::buildInterface() { + ui->folio_combo_box->addItem(tr("Tous")); + + //Fill the combo box for filter the result by folio + foreach (Diagram *d, diagram_list) { + QString title = d->title(); + if (title.isEmpty()) title = tr("Sans titre"); + title.prepend(QString::number(d->folioIndex() + 1) + " "); + ui->folio_combo_box->addItem(title); + } + + //Element is free build list + if(element_->isFree()) { + buildList(); + ui->button_linked->setDisabled(true); + } + //Element isn't free build an empty list and add 'unlink' button + else { + buildUnlinkButton(); + QList elmt_list; + esw_ = new ElementSelectorWidget(elmt_list, this); + ui->content_layout->addWidget(esw_); + } +} + +/** + * @brief LinkSingleElementWidget::buildList + * Build the element list of this widget, + * the list is fill with the element find in the + * required folio (folio selected with the combo box) + */ +void LinkSingleElementWidget::buildList() { + QList elmt_list; + int i = ui->folio_combo_box->currentIndex(); + + //find in all diagram of this project + if (i == 0) { + ElementProvider ep(element_->diagram()->project()); + if (filter_ & Element::AllReport) + elmt_list = ep.freeElement(filter_); + else + elmt_list = ep.find(filter_); + } + //find in single diagram + else { + ElementProvider ep (diagram_list.at(i-1)); + if (filter_ & Element::AllReport) + elmt_list = ep.freeElement(filter_); + else + elmt_list = ep.find(filter_); + } + + //If element is linked, remove is parent from the list + if(!element_->isFree()) elmt_list.removeAll(element_->linkedElements().first()); + + esw_ = new ElementSelectorWidget(elmt_list, this); + ui->content_layout->addWidget(esw_); +} + +/** + * @brief LinkSingleElementWidget::buildUnlinkButton + * Build a widget with button 'unlink' if the edited + * element is already linked with a master element + */ +void LinkSingleElementWidget::buildUnlinkButton() { + unlink_widget = new QWidget(this); + QHBoxLayout *unlink_layout = new QHBoxLayout(unlink_widget); + QLabel *lb = new QLabel(tr("Cet \351l\351ment est d\351j\340 li\351."), unlink_widget); + QPushButton *pb = new QPushButton(tr("D\351lier"), unlink_widget); + connect(pb, SIGNAL(clicked()), this, SLOT(unlinkClicked())); + unlink_layout->addWidget(lb); + unlink_layout->addStretch(); + unlink_layout->addWidget(pb); + ui->main_layout->insertWidget(0, unlink_widget); +} + +/** + * @brief LinkSingleElementWidget::reBuildList + * Rebuild the list of element + */ +void LinkSingleElementWidget::reBuildList() { + if (element_->isFree() || unlink_) { + ui->content_layout->removeWidget(esw_); + delete esw_; + buildList(); + } +} + +/** + * @brief LinkSingleElementWidget::unlinkClicked + * Action when 'unlink' button is clicked + */ +void LinkSingleElementWidget::unlinkClicked() { + ui->main_layout->removeWidget(unlink_widget); + delete unlink_widget; + unlink_widget = 0; + unlink_ = true; + reBuildList(); +} + +/** + * @brief FolioReportProperties::on_button_this_clicked + * Action when push button "this report" is clicked + */ +void LinkSingleElementWidget::on_button_this_clicked() { + esw_->showElement(element_); +} + +/** + * @brief FolioReportProperties::on_button_linked_clicked + * Action when push button "linked report" is clicked + */ +void LinkSingleElementWidget::on_button_linked_clicked() { + if (element_->isFree()) return; + esw_->showElement(element_->linkedElements().first()); +} diff --git a/sources/ui/linksingleelementwidget.h b/sources/ui/linksingleelementwidget.h new file mode 100644 index 000000000..11fdc9ee5 --- /dev/null +++ b/sources/ui/linksingleelementwidget.h @@ -0,0 +1,73 @@ +/* + Copyright 2006-2014 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 . +*/ +#ifndef LINKSINGLEELEMENTWIDGET_H +#define LINKSINGLEELEMENTWIDGET_H + +#include +#include "elementselectorwidget.h" + +class Element; +class Diagram; + +namespace Ui { + class LinkSingleElementWidget; +} + +/** +* @brief The LinkSingleElementWidget class + * this class provide a widget to select an element to be linked + * to the element given in the constructor. + * The element given in constructor must be linked with only one other element (like report or slave element). + * This widget detect automaticaly the kind of element given in the constructor and + * search all element that can be linked with it. + * If the element is already linked, the widget ask user to unlink. + * This widget embedded the diagram command for undo/redo the action + */ +class LinkSingleElementWidget : public QWidget +{ + Q_OBJECT + + ///Methods + public: + explicit LinkSingleElementWidget(Element *elmt, QWidget *parent = 0); + ~LinkSingleElementWidget(); + void apply(); + + private: + void buildInterface(); + void buildList(); + void buildUnlinkButton(); + + private slots: + void reBuildList(); + void unlinkClicked(); + void on_button_this_clicked(); + void on_button_linked_clicked(); + + ///Attributes + private: + Ui::LinkSingleElementWidget *ui; + Element *element_; + ElementSelectorWidget *esw_; + QList diagram_list; + QWidget *unlink_widget; + bool unlink_; + Element::kind filter_; +}; + +#endif // LINKSINGLEELEMENTWIDGET_H diff --git a/sources/ui/linksingleelementwidget.ui b/sources/ui/linksingleelementwidget.ui new file mode 100644 index 000000000..c98398339 --- /dev/null +++ b/sources/ui/linksingleelementwidget.ui @@ -0,0 +1,69 @@ + + + LinkSingleElementWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + Rechercher dans le folio : + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + Voir cet élément + + + + + + + Voir l'élément lié + + + + + + + + + +