[qet] [2926] LinkSingleElementWidget: add line for filter available element. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2926
Author: blacksun
Date: 2014-03-15 21:49:05 +0100 (Sat, 15 Mar 2014)
Log Message:
-----------
LinkSingleElementWidget: add line for filter available element.
filter work with the information of element.
elementSelectorWidget: add filter method.
Modified Paths:
--------------
trunk/sources/ui/elementselectorwidget.cpp
trunk/sources/ui/elementselectorwidget.h
trunk/sources/ui/elementselectorwidget.ui
trunk/sources/ui/linksingleelementwidget.cpp
trunk/sources/ui/linksingleelementwidget.h
Modified: trunk/sources/ui/elementselectorwidget.cpp
===================================================================
--- trunk/sources/ui/elementselectorwidget.cpp 2014-03-14 20:38:34 UTC (rev 2925)
+++ trunk/sources/ui/elementselectorwidget.cpp 2014-03-15 20:49:05 UTC (rev 2926)
@@ -62,6 +62,34 @@
}
/**
+ * @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
* Build interface of this widget (fill all available element)
*/
@@ -84,14 +112,23 @@
.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);
+ QWidget *widget = new QWidget(this);
+ QHBoxLayout *hl = new QHBoxLayout(widget);
+ 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"));
hl->addWidget(rb);
hl->addStretch();
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
connect(rb, SIGNAL(clicked()), sm_, SLOT(map()));
@@ -102,7 +139,6 @@
map_id++; //increase the map_id for next button.
}
- ui->scroll_layout_->addStretch();
}
/**
@@ -114,3 +150,23 @@
if (elements_list.size() >= 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);
+ }
+ }
+}
Modified: trunk/sources/ui/elementselectorwidget.h
===================================================================
--- trunk/sources/ui/elementselectorwidget.h 2014-03-14 20:38:34 UTC (rev 2925)
+++ trunk/sources/ui/elementselectorwidget.h 2014-03-15 20:49:05 UTC (rev 2926)
@@ -41,7 +41,12 @@
~ElementSelectorWidget();
Element * selectedElement () const{return selected_element;}
void showElement(Element *elmt);
+ void clear();
+ void setList(QList <Element *> elmt_list);
+ public slots:
+ void filter(const QString &str);
+
private:
void buildInterface();
@@ -56,6 +61,8 @@
QList <Element *> elements_list;
QSignalMapper *sm_, *sm_show_;
Element *selected_element, *showed_element;
+ QList <QWidget *> content_list;
+ QStringList string_filter;
};
#endif // ELEMENTSELECTORWIDGET_H
Modified: trunk/sources/ui/elementselectorwidget.ui
===================================================================
--- trunk/sources/ui/elementselectorwidget.ui 2014-03-14 20:38:34 UTC (rev 2925)
+++ trunk/sources/ui/elementselectorwidget.ui 2014-03-15 20:49:05 UTC (rev 2926)
@@ -19,6 +19,9 @@
<property name="widgetResizable">
<bool>true</bool>
</property>
+ <property name="alignment">
+ <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
+ </property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
@@ -28,7 +31,21 @@
<height>280</height>
</rect>
</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>
</item>
Modified: trunk/sources/ui/linksingleelementwidget.cpp
===================================================================
--- trunk/sources/ui/linksingleelementwidget.cpp 2014-03-14 20:38:34 UTC (rev 2925)
+++ trunk/sources/ui/linksingleelementwidget.cpp 2014-03-15 20:49:05 UTC (rev 2926)
@@ -37,7 +37,8 @@
esw_(0),
diagram_list(element_->diagram()->project()->diagrams()),
unlink_widget(0),
- unlink_(false)
+ unlink_(false),
+ search_field(0)
{
ui->setupUi(this);
@@ -49,7 +50,7 @@
filter_ = Element::Simple;
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 @@
ui->folio_combo_box->addItem(title);
}
- //Element is free build list
- if(element_->isFree()) {
- buildList();
+ buildList();
+ if (!element_->isFree()) {
ui->button_linked->setDisabled(true);
- }
- //Element isn't free build an empty list and add 'unlink' button
- else {
buildUnlinkButton();
- QList <Element *> elmt_list;
- esw_ = new ElementSelectorWidget(elmt_list, this);
- ui->content_layout->addWidget(esw_);
}
+
+ if(filter_ & Element::Master)
+ buildSearchField();
}
/**
@@ -108,9 +105,52 @@
* required folio (folio selected with the combo box)
*/
void LinkSingleElementWidget::buildList() {
+ esw_ = new ElementSelectorWidget(availableElements(), 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::buildSearchField
+ * Build a line edit for search element by they information,
+ * like label or information
+ */
+void LinkSingleElementWidget::buildSearchField() {
+ search_field = new QLineEdit(this);
+ search_field -> setPlaceholderText(tr("Rechercher"));
+ setUpCompleter();
+ 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());
@@ -127,41 +167,39 @@
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_);
+ return elmt_list;
}
/**
- * @brief LinkSingleElementWidget::buildUnlinkButton
- * Build a widget with button 'unlink' if the edited
- * element is already linked with a master element
+ * @brief LinkSingleElementWidget::setUpCompleter
+ * Setup the completer for the find_field
*/
-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);
+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::reBuildList
- * Rebuild the list of element
+ * @brief LinkSingleElementWidget::setNewList
+ * Set the list according to the selected diagram in the combo_box
*/
-void LinkSingleElementWidget::reBuildList() {
- if (element_->isFree() || unlink_) {
- ui->content_layout->removeWidget(esw_);
- delete esw_;
- buildList();
- }
+void LinkSingleElementWidget::setNewList() {
+ esw_->setList(availableElements());
+ setUpCompleter();
}
/**
@@ -173,7 +211,7 @@
delete unlink_widget;
unlink_widget = 0;
unlink_ = true;
- reBuildList();
+ setNewList();
}
/**
Modified: trunk/sources/ui/linksingleelementwidget.h
===================================================================
--- trunk/sources/ui/linksingleelementwidget.h 2014-03-14 20:38:34 UTC (rev 2925)
+++ trunk/sources/ui/linksingleelementwidget.h 2014-03-15 20:49:05 UTC (rev 2926)
@@ -52,9 +52,12 @@
void buildInterface();
void buildList();
void buildUnlinkButton();
+ void buildSearchField();
+ QList <Element *> availableElements();
+ void setUpCompleter();
private slots:
- void reBuildList();
+ void setNewList();
void unlinkClicked();
void on_button_this_clicked();
void on_button_linked_clicked();
@@ -68,6 +71,7 @@
QWidget *unlink_widget;
bool unlink_;
Element::kind filter_;
+ QLineEdit *search_field;
};
#endif // LINKSINGLEELEMENTWIDGET_H