mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 06:20:53 +01:00
LinkSingleElementWidget: add line for filter available element.
filter work with the information of element. elementSelectorWidget: add filter method. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2926 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -61,6 +61,34 @@ void ElementSelectorWidget::showElement(Element *elmt) {
|
|||||||
showed_element = elmt;
|
showed_element = elmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementSelectorWidget::clear
|
||||||
|
* Clear the curent list and the widget
|
||||||
|
*/
|
||||||
|
void ElementSelectorWidget::clear() {
|
||||||
|
elements_list.clear();
|
||||||
|
string_filter.clear();
|
||||||
|
if(showed_element) showed_element->setHighlighted(false);
|
||||||
|
foreach(QWidget *w, content_list) {
|
||||||
|
ui->scroll_layout_->removeWidget(w);
|
||||||
|
delete w;
|
||||||
|
}
|
||||||
|
content_list.clear();
|
||||||
|
delete sm_;
|
||||||
|
delete sm_show_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementSelectorWidget::setList
|
||||||
|
* Set new list of elements
|
||||||
|
* @param elmt_list the new elements list
|
||||||
|
*/
|
||||||
|
void ElementSelectorWidget::setList(QList<Element *> elmt_list) {
|
||||||
|
clear();
|
||||||
|
elements_list << elmt_list;
|
||||||
|
buildInterface();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementSelectorWidget::buildInterface
|
* @brief ElementSelectorWidget::buildInterface
|
||||||
* Build interface of this widget (fill all available element)
|
* Build interface of this widget (fill all available element)
|
||||||
@@ -84,14 +112,23 @@ void ElementSelectorWidget::buildInterface() {
|
|||||||
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
|
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
|
||||||
|
|
||||||
//add the button himself
|
//add the button himself
|
||||||
QHBoxLayout *hl = new QHBoxLayout();
|
QWidget *widget = new QWidget(this);
|
||||||
QRadioButton *rb = new QRadioButton(button_text , this);
|
QHBoxLayout *hl = new QHBoxLayout(widget);
|
||||||
QPushButton *pb = new QPushButton(QET::Icons::ZoomDraw,"", this);
|
hl->setContentsMargins(0,0,0,0);
|
||||||
|
QRadioButton *rb = new QRadioButton(button_text , widget);
|
||||||
|
QPushButton *pb = new QPushButton(QET::Icons::ZoomDraw,"", widget);
|
||||||
pb->setToolTip(tr("Voir l'\351l\351ment"));
|
pb->setToolTip(tr("Voir l'\351l\351ment"));
|
||||||
hl->addWidget(rb);
|
hl->addWidget(rb);
|
||||||
hl->addStretch();
|
hl->addStretch();
|
||||||
hl->addWidget(pb);
|
hl->addWidget(pb);
|
||||||
ui->scroll_layout_->addLayout(hl);
|
ui->scroll_layout_->insertWidget(map_id, widget);
|
||||||
|
content_list << 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()));
|
connect(rb, SIGNAL(clicked()), sm_, SLOT(map()));
|
||||||
@@ -102,7 +139,6 @@ void ElementSelectorWidget::buildInterface() {
|
|||||||
|
|
||||||
map_id++; //increase the map_id for next button.
|
map_id++; //increase the map_id for next button.
|
||||||
}
|
}
|
||||||
ui->scroll_layout_->addStretch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,3 +150,23 @@ void ElementSelectorWidget::showElementFromList(const int i) {
|
|||||||
if (elements_list.size() >= i)
|
if (elements_list.size() >= i)
|
||||||
showElement(elements_list.at(i));
|
showElement(elements_list.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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) {
|
||||||
|
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))
|
||||||
|
content_list.at(i)->setHidden(false);
|
||||||
|
else
|
||||||
|
content_list.at(i)->setHidden(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ class ElementSelectorWidget : public QWidget
|
|||||||
~ElementSelectorWidget();
|
~ElementSelectorWidget();
|
||||||
Element * selectedElement () const{return selected_element;}
|
Element * selectedElement () const{return selected_element;}
|
||||||
void showElement(Element *elmt);
|
void showElement(Element *elmt);
|
||||||
|
void clear();
|
||||||
|
void setList(QList <Element *> elmt_list);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void filter(const QString &str);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildInterface();
|
void buildInterface();
|
||||||
@@ -56,6 +61,8 @@ class ElementSelectorWidget : public QWidget
|
|||||||
QList <Element *> elements_list;
|
QList <Element *> elements_list;
|
||||||
QSignalMapper *sm_, *sm_show_;
|
QSignalMapper *sm_, *sm_show_;
|
||||||
Element *selected_element, *showed_element;
|
Element *selected_element, *showed_element;
|
||||||
|
QList <QWidget *> content_list;
|
||||||
|
QStringList string_filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ELEMENTSELECTORWIDGET_H
|
#endif // ELEMENTSELECTORWIDGET_H
|
||||||
|
|||||||
@@ -19,6 +19,9 @@
|
|||||||
<property name="widgetResizable">
|
<property name="widgetResizable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
|
||||||
|
</property>
|
||||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
@@ -28,7 +31,21 @@
|
|||||||
<height>280</height>
|
<height>280</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="scroll_layout_"/>
|
<layout class="QVBoxLayout" name="scroll_layout_">
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent)
|
|||||||
esw_(0),
|
esw_(0),
|
||||||
diagram_list(element_->diagram()->project()->diagrams()),
|
diagram_list(element_->diagram()->project()->diagrams()),
|
||||||
unlink_widget(0),
|
unlink_widget(0),
|
||||||
unlink_(false)
|
unlink_(false),
|
||||||
|
search_field(0)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent)
|
|||||||
filter_ = Element::Simple;
|
filter_ = Element::Simple;
|
||||||
|
|
||||||
buildInterface();
|
buildInterface();
|
||||||
connect(ui->folio_combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(reBuildList()));
|
connect(ui->folio_combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(setNewList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,18 +88,14 @@ void LinkSingleElementWidget::buildInterface() {
|
|||||||
ui->folio_combo_box->addItem(title);
|
ui->folio_combo_box->addItem(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Element is free build list
|
|
||||||
if(element_->isFree()) {
|
|
||||||
buildList();
|
buildList();
|
||||||
|
if (!element_->isFree()) {
|
||||||
ui->button_linked->setDisabled(true);
|
ui->button_linked->setDisabled(true);
|
||||||
}
|
|
||||||
//Element isn't free build an empty list and add 'unlink' button
|
|
||||||
else {
|
|
||||||
buildUnlinkButton();
|
buildUnlinkButton();
|
||||||
QList <Element *> elmt_list;
|
|
||||||
esw_ = new ElementSelectorWidget(elmt_list, this);
|
|
||||||
ui->content_layout->addWidget(esw_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(filter_ & Element::Master)
|
||||||
|
buildSearchField();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,30 +105,7 @@ void LinkSingleElementWidget::buildInterface() {
|
|||||||
* required folio (folio selected with the combo box)
|
* required folio (folio selected with the combo box)
|
||||||
*/
|
*/
|
||||||
void LinkSingleElementWidget::buildList() {
|
void LinkSingleElementWidget::buildList() {
|
||||||
QList <Element *> elmt_list;
|
esw_ = new ElementSelectorWidget(availableElements(), this);
|
||||||
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_);
|
ui->content_layout->addWidget(esw_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,15 +127,79 @@ void LinkSingleElementWidget::buildUnlinkButton() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief LinkSingleElementWidget::reBuildList
|
* @brief LinkSingleElementWidget::buildSearchField
|
||||||
* Rebuild the list of element
|
* Build a line edit for search element by they information,
|
||||||
|
* like label or information
|
||||||
*/
|
*/
|
||||||
void LinkSingleElementWidget::reBuildList() {
|
void LinkSingleElementWidget::buildSearchField() {
|
||||||
if (element_->isFree() || unlink_) {
|
search_field = new QLineEdit(this);
|
||||||
ui->content_layout->removeWidget(esw_);
|
search_field -> setPlaceholderText(tr("Rechercher"));
|
||||||
delete esw_;
|
setUpCompleter();
|
||||||
buildList();
|
connect(search_field, SIGNAL(textChanged(QString)), esw_, SLOT(filter(QString)));
|
||||||
|
ui->header_layout->addWidget(search_field);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief LinkSingleElementWidget::availableElements
|
||||||
|
* @return A QList with all available element
|
||||||
|
* to be linked with the edited element.
|
||||||
|
* This methode take care of the combo box "find in diagram"
|
||||||
|
*/
|
||||||
|
QList <Element *> LinkSingleElementWidget::availableElements() {
|
||||||
|
QList <Element *> elmt_list;
|
||||||
|
//if element isn't free and unlink isn't pressed, return an empty list
|
||||||
|
if (!element_->isFree() && !unlink_) return 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());
|
||||||
|
|
||||||
|
return elmt_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief LinkSingleElementWidget::setUpCompleter
|
||||||
|
* Setup the completer for the find_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);
|
||||||
|
comp->setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
search_field->setCompleter(comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief LinkSingleElementWidget::setNewList
|
||||||
|
* Set the list according to the selected diagram in the combo_box
|
||||||
|
*/
|
||||||
|
void LinkSingleElementWidget::setNewList() {
|
||||||
|
esw_->setList(availableElements());
|
||||||
|
setUpCompleter();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,7 +211,7 @@ void LinkSingleElementWidget::unlinkClicked() {
|
|||||||
delete unlink_widget;
|
delete unlink_widget;
|
||||||
unlink_widget = 0;
|
unlink_widget = 0;
|
||||||
unlink_ = true;
|
unlink_ = true;
|
||||||
reBuildList();
|
setNewList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -52,9 +52,12 @@ class LinkSingleElementWidget : public QWidget
|
|||||||
void buildInterface();
|
void buildInterface();
|
||||||
void buildList();
|
void buildList();
|
||||||
void buildUnlinkButton();
|
void buildUnlinkButton();
|
||||||
|
void buildSearchField();
|
||||||
|
QList <Element *> availableElements();
|
||||||
|
void setUpCompleter();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void reBuildList();
|
void setNewList();
|
||||||
void unlinkClicked();
|
void unlinkClicked();
|
||||||
void on_button_this_clicked();
|
void on_button_this_clicked();
|
||||||
void on_button_linked_clicked();
|
void on_button_linked_clicked();
|
||||||
@@ -68,6 +71,7 @@ class LinkSingleElementWidget : public QWidget
|
|||||||
QWidget *unlink_widget;
|
QWidget *unlink_widget;
|
||||||
bool unlink_;
|
bool unlink_;
|
||||||
Element::kind filter_;
|
Element::kind filter_;
|
||||||
|
QLineEdit *search_field;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LINKSINGLEELEMENTWIDGET_H
|
#endif // LINKSINGLEELEMENTWIDGET_H
|
||||||
|
|||||||
Reference in New Issue
Block a user