From bc0d70e1eaf27be38077d485a4a8cbd330acb895 Mon Sep 17 00:00:00 2001 From: blacksun Date: Thu, 4 Dec 2014 10:54:38 +0000 Subject: [PATCH] Report link widget : each content show the string of the conductor and search field filter with this string. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3529 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/ui/elementselectorwidget.cpp | 80 ++++++++++++++++++++------ sources/ui/elementselectorwidget.h | 10 +++- sources/ui/linksingleelementwidget.cpp | 36 ++++++------ 3 files changed, 89 insertions(+), 37 deletions(-) diff --git a/sources/ui/elementselectorwidget.cpp b/sources/ui/elementselectorwidget.cpp index 5ad1e9d4c..3eb8be985 100644 --- a/sources/ui/elementselectorwidget.cpp +++ b/sources/ui/elementselectorwidget.cpp @@ -21,6 +21,9 @@ #include "qeticons.h" #include "diagram.h" #include "element.h" +#include "terminal.h" +#include "conductor.h" +#include "qet.h" /** * @brief ElementSelectorWidget::ElementSelectorWidget @@ -71,7 +74,8 @@ void ElementSelectorWidget::showElement(Element *elmt) { */ void ElementSelectorWidget::clear() { elements_list.clear(); - string_filter.clear(); + in_filter.clear(); + out_filter.clear(); if(showed_element) showed_element->setHighlighted(false); foreach(QWidget *w, content_list) { ui->scroll_layout_->removeWidget(w); @@ -116,8 +120,10 @@ void ElementSelectorWidget::buildInterface() { //label for the button QString button_text; - //if element is master and have label, add label to the string - //Also to comment + /* + * If element is master and have label, + * we add label and comment to the button text + */ if (elmt->linkType() & Element::Master) { DiagramContext dc = elmt -> elementInformations(); @@ -129,6 +135,42 @@ void ElementSelectorWidget::buildInterface() { if (!button_text.isEmpty()) button_text += "\n"; + + //Add the string for filter this widget + QString filter; + foreach(QString str, elmt->elementInformations().keys()){ + QString filter_str = elmt->elementInformations()[str].toString(); + filter += filter_str; + out_filter << filter_str; + } + in_filter << filter; + } + + /* + * If element is a folio report, have conductors docked to his terminal, + * and each conductor have the same text, + * we add this text to the button label and provide it through the filter + */ + if (elmt -> linkType() & Element::AllReport) { + //Report have one terminal, but we check it to prevent assert. + if (!elmt -> terminals().isEmpty()) { + //We must to have at least one conductor + if (!elmt -> terminals().first() -> conductors().isEmpty()) { + Conductor *cond = elmt->terminals().first()->conductors().first(); + QSet cdr_set = cond -> relatedPotentialConductors(); + cdr_set << cond; + + QStringList str_list; + foreach (Conductor* c, cdr_set) + str_list << c->properties().text; + + if (QET::eachStrIsEqual(str_list)) { + button_text = tr("N\260 fil : ") + str_list.first() + "\n"; + in_filter << str_list.first(); + out_filter << str_list.first(); + } + } + } } QString title = elmt->diagram()->title(); @@ -137,15 +179,15 @@ void ElementSelectorWidget::buildInterface() { .arg(title) .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString()); - //Widget that contain the buttons + //Widget that contain the buttons QWidget *widget = new QWidget(this); content_list << widget; - //Radio button for select element + //Radio button for select element QRadioButton *rb = new QRadioButton(button_text , widget); m_button_group -> addButton(rb); - //Push button to highlight element + //Push button to highlight element QPushButton *pb = new QPushButton(QET::Icons::ZoomDraw,"", widget); pb -> setToolTip(tr("Voir l'\351l\351ment")); @@ -156,17 +198,10 @@ void ElementSelectorWidget::buildInterface() { hl -> addWidget(pb); ui -> scroll_layout_ -> insertWidget(map_id, widget); - //Add the string for filter this widget - QString filter; - foreach(QString str, elmt->elementInformations().keys()){ - filter += elmt->elementInformations()[str].toString(); - } - string_filter << filter; - - //map the radio button signal + //map the radio button signal connect(rb, SIGNAL(clicked()), sm_, SLOT(map())); sm_ -> setMapping(rb, map_id); - //map the push button show diagram + //map the push button show diagram connect(pb, SIGNAL(clicked()), sm_show_, SLOT(map())); sm_show_->setMapping(pb, map_id); @@ -184,19 +219,28 @@ void ElementSelectorWidget::showElementFromList(const int i) { showElement(elements_list.at(i)); } +/** + * @brief ElementSelectorWidget::filter + * @return A stringlist with all available value + * to filter the content of this widget; + */ +QStringList ElementSelectorWidget::filter() const { + return out_filter; +} + /** * @brief ElementSelectorWidget::filter * Filter the content of the list. * Give an empty string remove all filter. * @param str string to filter */ -void ElementSelectorWidget::filter(const QString &str) { +void ElementSelectorWidget::filtered(const QString &str) { if(str.isEmpty()) { foreach (QWidget *w, content_list) w->setHidden(false); } else { - for (int i =0; isetHidden(false); else content_list.at(i)->setHidden(true); diff --git a/sources/ui/elementselectorwidget.h b/sources/ui/elementselectorwidget.h index 0da506bcf..971fe77c0 100644 --- a/sources/ui/elementselectorwidget.h +++ b/sources/ui/elementselectorwidget.h @@ -46,14 +46,16 @@ class ElementSelectorWidget : public QWidget void clear(); void setList(QList elmt_list); + QStringList filter () const; + public slots: - void filter(const QString &str); + void filtered(const QString &str); private: void buildInterface(); private slots: - void setSelectedElement(const int i) {selected_element = elements_list.at(i);} + void setSelectedElement (const int i) {selected_element = elements_list.at(i);} void showElementFromList (const int i); @@ -64,7 +66,9 @@ class ElementSelectorWidget : public QWidget QSignalMapper *sm_, *sm_show_; Element *selected_element, *showed_element; QList content_list; - QStringList string_filter; + QStringList in_filter, //In filter is used inside this class to filter the content of this widget + out_filter; //Out filter is used to return (with the method filter) a list of + //available string to filter the content of this widget QButtonGroup *m_button_group; }; diff --git a/sources/ui/linksingleelementwidget.cpp b/sources/ui/linksingleelementwidget.cpp index ff9dcb597..7eea68f25 100644 --- a/sources/ui/linksingleelementwidget.cpp +++ b/sources/ui/linksingleelementwidget.cpp @@ -94,8 +94,7 @@ void LinkSingleElementWidget::buildInterface() { ui->button_linked->setDisabled(true) : buildUnlinkButton(); - if(filter_ & Element::Master) - buildSearchField(); + buildSearchField(); } /** @@ -132,12 +131,22 @@ void LinkSingleElementWidget::buildUnlinkButton() { * like label or information */ void LinkSingleElementWidget::buildSearchField() { - search_field = new QLineEdit(this); + //If there isn't string to filter, we remove the search field + if (esw_->filter().isEmpty()) { + if (search_field) { + ui -> header_layout -> removeWidget(search_field); + delete search_field; + search_field = nullptr; + } + return; + } + + if(!search_field) search_field = new QLineEdit(this); #if QT_VERSION >= 0x040700 search_field -> setPlaceholderText(tr("Rechercher")); #endif setUpCompleter(); - connect(search_field, SIGNAL(textChanged(QString)), esw_, SLOT(filter(QString))); + connect(search_field, SIGNAL(textChanged(QString)), esw_, SLOT(filtered(QString))); ui->header_layout->addWidget(search_field); } @@ -177,21 +186,16 @@ QList LinkSingleElementWidget::availableElements() { /** * @brief LinkSingleElementWidget::setUpCompleter - * Setup the completer for the find_field + * Setup the completer of search_field */ void LinkSingleElementWidget::setUpCompleter() { if (search_field) { - search_field->clear(); - delete search_field->completer(); + search_field -> clear(); + delete search_field -> completer(); - QStringList list; - foreach (Element *elmt, availableElements()) - foreach(QString str, elmt->elementInformations().keys()) - list << elmt->elementInformations()[str].toString(); - - QCompleter *comp = new QCompleter(list, search_field); - comp->setCaseSensitivity(Qt::CaseInsensitive); - search_field->setCompleter(comp); + QCompleter *comp = new QCompleter(esw_ -> filter(), search_field); + comp -> setCaseSensitivity(Qt::CaseInsensitive); + search_field -> setCompleter(comp); } } @@ -201,7 +205,7 @@ void LinkSingleElementWidget::setUpCompleter() { */ void LinkSingleElementWidget::setNewList() { esw_->setList(availableElements()); - setUpCompleter(); + buildSearchField(); } /**