mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
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
This commit is contained in:
@@ -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 <Conductor *> 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();
|
||||
@@ -156,13 +198,6 @@ 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
|
||||
connect(rb, SIGNAL(clicked()), sm_, SLOT(map()));
|
||||
sm_ -> setMapping(rb, 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; i<string_filter.size(); i++) {
|
||||
if (string_filter.at(i).contains(str, Qt::CaseInsensitive))
|
||||
for (int i =0; i<in_filter.size(); i++) {
|
||||
if (in_filter.at(i).contains(str, Qt::CaseInsensitive))
|
||||
content_list.at(i)->setHidden(false);
|
||||
else
|
||||
content_list.at(i)->setHidden(true);
|
||||
|
||||
@@ -46,8 +46,10 @@ class ElementSelectorWidget : public QWidget
|
||||
void clear();
|
||||
void setList(QList <Element *> elmt_list);
|
||||
|
||||
QStringList filter () const;
|
||||
|
||||
public slots:
|
||||
void filter(const QString &str);
|
||||
void filtered(const QString &str);
|
||||
|
||||
private:
|
||||
void buildInterface();
|
||||
@@ -64,7 +66,9 @@ class ElementSelectorWidget : public QWidget
|
||||
QSignalMapper *sm_, *sm_show_;
|
||||
Element *selected_element, *showed_element;
|
||||
QList <QWidget *> 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;
|
||||
};
|
||||
|
||||
|
||||
@@ -94,7 +94,6 @@ void LinkSingleElementWidget::buildInterface() {
|
||||
ui->button_linked->setDisabled(true) :
|
||||
buildUnlinkButton();
|
||||
|
||||
if(filter_ & Element::Master)
|
||||
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,19 +186,14 @@ QList <Element *> 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();
|
||||
|
||||
QStringList list;
|
||||
foreach (Element *elmt, availableElements())
|
||||
foreach(QString str, elmt->elementInformations().keys())
|
||||
list << elmt->elementInformations()[str].toString();
|
||||
|
||||
QCompleter *comp = new QCompleter(list, search_field);
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user