Added a search box to the PropertyLink dialog

This commit is contained in:
Yorik van Havre 2017-01-20 00:03:42 -02:00
parent c241beda67
commit 7c15e1407f
3 changed files with 38 additions and 5 deletions

View File

@ -93,6 +93,7 @@ void DlgPropertyLink::findObjects(bool on)
QString docName = link[0];
QString objName = link[1];
QString parName = link[3];
QString searchText = ui->searchBox->text();
App::Document* doc = App::GetApplication().getDocument((const char*)docName.toLatin1());
if (doc) {
@ -128,7 +129,13 @@ void DlgPropertyLink::findObjects(bool on)
std::vector<App::DocumentObject*> obj = doc->getObjectsOfType(baseType);
for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) {
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(*it);
if (vp) {
bool nameOk = true;
if (!searchText.isEmpty()) {
QString label = QString::fromUtf8((*it)->Label.getValue());
if (!label.contains(searchText,Qt::CaseInsensitive))
nameOk = false;
}
if (vp && nameOk) {
// filter out the objects
if (std::find(outList.begin(), outList.end(), *it) == outList.end()) {
QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
@ -148,4 +155,11 @@ void DlgPropertyLink::on_checkObjectType_toggled(bool on)
findObjects(on);
}
void DlgPropertyLink::on_searchBox_textChanged(const QString& search)
{
ui->listWidget->clear();
bool on = ui->checkObjectType->isChecked();
findObjects(on);
}
#include "moc_DlgPropertyLink.cpp"

View File

@ -42,6 +42,7 @@ public:
private Q_SLOTS:
void on_checkObjectType_toggled(bool);
void on_searchBox_textChanged(const QString&);
private:
void findObjects(bool on);

View File

@ -14,17 +14,35 @@
<string>Link</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QListWidget" name="listWidget"/>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Search</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="searchBox">
<property name="toolTip">
<string>A search pattern to filter the results above</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="checkObjectType">
<property name="text">
<string>Show all object types</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="0" column="0">
<widget class="QListWidget" name="listWidget"/>
</item>
<item row="5" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>