diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 4c400f4bd..12fa11d22 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -936,6 +936,15 @@ QList Diagram::customElements() const { return(elements_list); } +QList Diagram::elements() const { + QList element_list; + foreach (QGraphicsItem *qgi, items()) { + if (Element *elmt = qgraphicsitem_cast(qgi)) + element_list < customElements() const; + QList elements() const; QSet selectedTexts() const; QSet selectedConductorTexts() const; QSet selectedConductors() const; diff --git a/sources/elementprovider.cpp b/sources/elementprovider.cpp new file mode 100644 index 000000000..57c5aaf9a --- /dev/null +++ b/sources/elementprovider.cpp @@ -0,0 +1,54 @@ +/* + Copyright 2006-2013 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 "elementprovider.h" + +/** + * @brief ElementProvider::ElementProvider Constructor + * @param prj the project where we must find element + * @param diagram the digram to exclude from the search + */ +ElementProvider::ElementProvider(QETProject *prj, Diagram *diagram) +{ + diag_list = prj->diagrams(); + diag_list.removeOne(diagram); +} + +/** + * @brief ElementProvider::FreeElement + * Search and return the asked element corresponding with the given filter + * All returned element are free, ie element aren't connected with another element + * @param filter + * the filter for search element + * (the filter must be the enum linkerType in Element.h) + * @return + */ +QList ElementProvider::FreeElement(int filter) { + QList free_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()) + if (elmt->isFree()) free_elmt << elmt; + } + } + return (free_elmt); +} diff --git a/sources/elementprovider.h b/sources/elementprovider.h new file mode 100644 index 000000000..7cc640086 --- /dev/null +++ b/sources/elementprovider.h @@ -0,0 +1,41 @@ +/* + Copyright 2006-2013 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 ELEMENTPROVIDER_H +#define ELEMENTPROVIDER_H + +#include "qetproject.h" +#include "diagram.h" +#include "qetgraphicsitem/element.h" + +/** + this class can search in the given diagram or project some kind of element + like 'folio report' or 'master' and return it. + We can get element element with specific status like 'free'. +*/ + +class ElementProvider +{ + public: + ElementProvider(QETProject *prj, Diagram *diagram=0); + QList FreeElement(int filter); + + private: + QList diag_list; +}; + +#endif // ELEMENTPROVIDER_H diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 2eb964ec3..8df049758 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -56,6 +56,7 @@ class Element : public QetGraphicsItem { QSize dimensions; QPoint hotspot_coord; QPixmap preview; + QList connected_elements; // methods public: @@ -79,6 +80,7 @@ class Element : public QetGraphicsItem { virtual int minTerminalsCount() const = 0; /// @return the maximum number of terminals for this element virtual int maxTerminalsCount() const = 0; + bool isFree () const; /** Draw this element */ @@ -131,6 +133,10 @@ class Element : public QetGraphicsItem { void updatePixmap(); }; +inline bool Element::isFree() const { + return (connected_elements.isEmpty()); +} + /** Indicate whether this element allows internal connections, i.e. whether its terminals can be linked together using a conductor. diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index a3ef21337..92d6ac0ac 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -93,8 +93,8 @@ void elementpropertieswidget::buildInterface() { case Element::simple: break; case Element::report: - w = new QComboBox(this); - tab_ -> addTab(w, tr("Report de folio")); + frp_ = new FolioReportProperties(element_, this); + tab_ -> addTab(frp_, tr("Report de folio")); break; case Element::master: break; diff --git a/sources/ui/elementpropertieswidget.h b/sources/ui/elementpropertieswidget.h index 36d29a770..2b17e7002 100644 --- a/sources/ui/elementpropertieswidget.h +++ b/sources/ui/elementpropertieswidget.h @@ -4,6 +4,7 @@ #include #include #include +#include class elementpropertieswidget : public QDialog { @@ -27,7 +28,7 @@ class elementpropertieswidget : public QDialog void editElement (); private: - QWidget *w; ///this widget is only for test + FolioReportProperties *frp_; QDialogButtonBox *dbb; Element *element_; Diagram *diagram_; diff --git a/sources/ui/folioreportproperties.cpp b/sources/ui/folioreportproperties.cpp new file mode 100644 index 000000000..a4f907433 --- /dev/null +++ b/sources/ui/folioreportproperties.cpp @@ -0,0 +1,34 @@ +#include "folioreportproperties.h" +#include "ui_folioreportproperties.h" + +#include +#include + +FolioReportProperties::FolioReportProperties(Element *elmt, QWidget *parent) : + QWidget(parent), + element_(elmt), + ui(new Ui::FolioReportProperties) +{ + ui->setupUi(this); + + ElementProvider ep(element_->diagram()->project(), element_->diagram()); + QList elmt_list = ep.FreeElement(Element::report); + + foreach (Element *elmt, elmt_list) { + if (elmt != element_) { + QString button_text; + button_text += elmt->name(); + button_text += QString(tr(" Folio\240: %1, ")).arg(elmt->diagram()->folioIndex() + 1); + button_text += QString(tr("Position\240: %1")).arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString()); + + QRadioButton *rb = new QRadioButton(button_text , this); + ui->available_report_layout->addWidget(rb); + } + } + ui->available_report_layout->addStretch(); +} + +FolioReportProperties::~FolioReportProperties() +{ + delete ui; +} diff --git a/sources/ui/folioreportproperties.h b/sources/ui/folioreportproperties.h new file mode 100644 index 000000000..3b506d549 --- /dev/null +++ b/sources/ui/folioreportproperties.h @@ -0,0 +1,24 @@ +#ifndef FOLIOREPORTPROPERTIES_H +#define FOLIOREPORTPROPERTIES_H + +#include +#include + +namespace Ui { + class FolioReportProperties; +} + +class FolioReportProperties : public QWidget +{ + Q_OBJECT + + public: + explicit FolioReportProperties(Element *elmt, QWidget *parent = 0); + ~FolioReportProperties(); + + private: + Element *element_; + Ui::FolioReportProperties *ui; +}; + +#endif // FOLIOREPORTPROPERTIES_H diff --git a/sources/ui/folioreportproperties.ui b/sources/ui/folioreportproperties.ui new file mode 100644 index 000000000..827971f71 --- /dev/null +++ b/sources/ui/folioreportproperties.ui @@ -0,0 +1,77 @@ + + + FolioReportProperties + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + + + + + Report de folio disponible : + + + + QLayout::SetMinimumSize + + + 0 + + + 2 + + + 0 + + + 0 + + + + + true + + + + + 0 + 0 + 370 + 258 + + + + + QLayout::SetMinimumSize + + + + + + + + + + + + + + +