add search function to parameter editor

This commit is contained in:
wmayer
2019-04-05 23:59:21 +02:00
parent 732eb6dbb5
commit 743e548363
7 changed files with 536 additions and 0 deletions

View File

@@ -270,6 +270,7 @@ set(Gui_MOC_HDRS
DlgMaterialPropertiesImp.h
DlgOnlineHelpImp.h
DlgParameterImp.h
DlgParameterFind.h
DlgPreferencesImp.h
DlgProjectInformationImp.h
DlgProjectUtility.h
@@ -389,6 +390,7 @@ SET(Gui_UIC_SRCS
DlgMaterialProperties.ui
DlgOnlineHelp.ui
DlgParameter.ui
DlgParameterFind.ui
DlgPreferences.ui
DlgProjectInformation.ui
DlgProjectUtility.ui
@@ -472,6 +474,7 @@ SET(Dialog_CPP_SRCS
DlgMacroRecordImp.cpp
DlgMaterialPropertiesImp.cpp
DlgParameterImp.cpp
DlgParameterFind.cpp
DlgProjectInformationImp.cpp
DlgProjectUtility.cpp
DlgPropertyLink.cpp
@@ -504,6 +507,7 @@ SET(Dialog_HPP_SRCS
DlgMacroRecordImp.h
DlgMaterialPropertiesImp.h
DlgParameterImp.h
DlgParameterFind.h
DlgProjectInformationImp.h
DlgProjectUtility.h
DlgPropertyLink.h
@@ -541,6 +545,7 @@ SET(Dialog_SRCS
DlgMacroRecord.ui
DlgMaterialProperties.ui
DlgParameter.ui
DlgParameterFind.ui
DlgProjectInformation.ui
DlgProjectUtility.ui
DlgPropertyLink.ui

View File

@@ -36,6 +36,13 @@
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="buttonFind" >
<property name="text" >
<string>Find...</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >

View File

@@ -0,0 +1,280 @@
/***************************************************************************
* Copyright (c) 2019 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QMessageBox>
# include <QPushButton>
#endif
#include "ui_DlgParameterFind.h"
#include "DlgParameterFind.h"
#include "DlgParameterImp.h"
using namespace Gui::Dialog;
/* TRANSLATOR Gui::Dialog::DlgParameterFind */
DlgParameterFind::DlgParameterFind(DlgParameterImp* parent)
: QDialog(parent)
, ui(new Ui_DlgParameterFind)
, dialog(parent)
{
ui->setupUi(this);
QPushButton* btn = ui->buttonBox->button(QDialogButtonBox::Ok);
if (btn) {
btn->setText(tr("Find Next"));
btn->setDisabled(true);
}
}
/**
* Destroys the object and frees any allocated resources
*/
DlgParameterFind::~DlgParameterFind()
{
// no need to delete child widgets, Qt does it all for us
delete ui;
}
void DlgParameterFind::on_lineEdit_textChanged(const QString& text)
{
QPushButton* btn = ui->buttonBox->button(QDialogButtonBox::Ok);
if (btn) {
bool ok = ui->checkGroups->isChecked() ||
ui->checkNames->isChecked() ||
ui->checkValues->isChecked();
btn->setDisabled(!ok || text.isEmpty());
}
}
void DlgParameterFind::on_checkGroups_toggled(bool)
{
QPushButton* btn = ui->buttonBox->button(QDialogButtonBox::Ok);
if (btn) {
bool ok = ui->checkGroups->isChecked() ||
ui->checkNames->isChecked() ||
ui->checkValues->isChecked();
QString text = ui->lineEdit->text();
btn->setDisabled(!ok || text.isEmpty());
}
}
void DlgParameterFind::on_checkNames_toggled(bool)
{
QPushButton* btn = ui->buttonBox->button(QDialogButtonBox::Ok);
if (btn) {
bool ok = ui->checkGroups->isChecked() ||
ui->checkNames->isChecked() ||
ui->checkValues->isChecked();
QString text = ui->lineEdit->text();
btn->setDisabled(!ok || text.isEmpty());
}
}
void DlgParameterFind::on_checkValues_toggled(bool)
{
QPushButton* btn = ui->buttonBox->button(QDialogButtonBox::Ok);
if (btn) {
bool ok = ui->checkGroups->isChecked() ||
ui->checkNames->isChecked() ||
ui->checkValues->isChecked();
QString text = ui->lineEdit->text();
btn->setDisabled(!ok || text.isEmpty());
}
}
bool DlgParameterFind::matches(QTreeWidgetItem* item, const Options& opt) const
{
// check the group name
if (opt.group) {
// whole word matches
if (opt.match) {
if (item->text(0).compare(opt.text, Qt::CaseInsensitive) == 0)
return true;
}
else {
if (item->text(0).indexOf(opt.text, 0, Qt::CaseInsensitive) >= 0)
return true;
}
}
if (opt.name || opt.value) {
ParameterGroupItem* group = static_cast<ParameterGroupItem*>(item);
Base::Reference<ParameterGrp> hGrp = group->_hcGrp;
auto boolMap = hGrp->GetBoolMap();
auto intMap = hGrp->GetIntMap();
auto uintMap = hGrp->GetUnsignedMap();
auto floatMap = hGrp->GetFloatMap();
auto asciiMap = hGrp->GetASCIIMap();
// check the name of an entry in the group
if (opt.name) {
if (opt.match) {
for (auto it : boolMap) {
QString text = QString::fromUtf8(it.first.c_str());
if (text.compare(opt.text, Qt::CaseInsensitive) == 0)
return true;
}
for (auto it : intMap) {
QString text = QString::fromUtf8(it.first.c_str());
if (text.compare(opt.text, Qt::CaseInsensitive) == 0)
return true;
}
for (auto it : uintMap) {
QString text = QString::fromUtf8(it.first.c_str());
if (text.compare(opt.text, Qt::CaseInsensitive) == 0)
return true;
}
for (auto it : floatMap) {
QString text = QString::fromUtf8(it.first.c_str());
if (text.compare(opt.text, Qt::CaseInsensitive) == 0)
return true;
}
for (auto it : asciiMap) {
QString text = QString::fromUtf8(it.first.c_str());
if (text.compare(opt.text, Qt::CaseInsensitive) == 0)
return true;
}
}
else {
for (auto it : boolMap) {
QString text = QString::fromUtf8(it.first.c_str());
if (text.indexOf(opt.text, 0, Qt::CaseInsensitive) >= 0)
return true;
}
for (auto it : intMap) {
QString text = QString::fromUtf8(it.first.c_str());
if (text.indexOf(opt.text, 0, Qt::CaseInsensitive) >= 0)
return true;
}
for (auto it : uintMap) {
QString text = QString::fromUtf8(it.first.c_str());
if (text.indexOf(opt.text, 0, Qt::CaseInsensitive) >= 0)
return true;
}
for (auto it : floatMap) {
QString text = QString::fromUtf8(it.first.c_str());
if (text.indexOf(opt.text, 0, Qt::CaseInsensitive) >= 0)
return true;
}
for (auto it : asciiMap) {
QString text = QString::fromUtf8(it.first.c_str());
if (text.indexOf(opt.text, 0, Qt::CaseInsensitive) >= 0)
return true;
}
}
}
// check the value of an entry in the group
if (opt.value) {
if (opt.match) {
for (auto it : asciiMap) {
QString text = QString::fromUtf8(it.second.c_str());
if (text.compare(opt.text, Qt::CaseInsensitive) == 0)
return true;
}
}
else {
for (auto it : asciiMap) {
QString text = QString::fromUtf8(it.second.c_str());
if (text.indexOf(opt.text, 0, Qt::CaseInsensitive) >= 0)
return true;
}
}
}
}
return false;
}
QTreeWidgetItem* DlgParameterFind::findItem(QTreeWidgetItem* root, const Options& opt) const
{
if (!root)
return nullptr;
if (matches(root, opt)) {
// if the root matches then only return if it's not the current element
// as otherwise it would never move forward
if (root->treeWidget()->currentItem() != root)
return root;
}
for (int i=0; i<root->childCount(); i++) {
QTreeWidgetItem* item = root->child(i);
if (matches(item, opt))
return item;
item = findItem(item, opt);
if (item)
return item;
}
return nullptr;
}
void DlgParameterFind::accept()
{
ParameterGroup* groupTree = dialog->findChild<ParameterGroup*>();
if (groupTree) {
Options opt;
opt.text = ui->lineEdit->text();
opt.group = ui->checkGroups->isChecked();
opt.name = ui->checkNames->isChecked();
opt.value = ui->checkValues->isChecked();
opt.match = ui->checkMatch->isChecked();
QTreeWidgetItem* current = groupTree->currentItem();
QTreeWidgetItem* next = findItem(current, opt);
while (!next && current) {
// go to the parent item and try again for each sibling after the current item
QTreeWidgetItem* parent = current->parent();
if (parent) {
int index = parent->indexOfChild(current);
for (int i=index+1; i<parent->childCount(); i++) {
next = findItem(parent->child(i), opt);
if (next)
break;
}
}
if (!next) {
current = parent;
}
}
// if search was successful then make it the current item
if (next)
groupTree->setCurrentItem(next);
else
QMessageBox::warning(this, tr("Not found"), tr("Can't find the text: %1").arg(opt.text));
}
}
void DlgParameterFind::reject()
{
QDialog::reject();
}
#include "moc_DlgParameterFind.cpp"

View File

@@ -0,0 +1,74 @@
/***************************************************************************
* Copyright (c) 2019 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_DIALOG_DLGPARAMETERFIND_H
#define GUI_DIALOG_DLGPARAMETERFIND_H
#include <QDialog>
#include <Base/Parameter.h>
class QTreeWidgetItem;
namespace Gui {
namespace Dialog {
class Ui_DlgParameterFind;
class DlgParameterImp;
class GuiExport DlgParameterFind : public QDialog
{
Q_OBJECT
public:
DlgParameterFind(DlgParameterImp* parent);
~DlgParameterFind();
void accept();
void reject();
private Q_SLOTS:
void on_lineEdit_textChanged(const QString&);
void on_checkGroups_toggled(bool);
void on_checkNames_toggled(bool);
void on_checkValues_toggled(bool);
private:
struct Options {
QString text;
bool group = true;
bool name = true;
bool value = true;
bool match = false;
};
QTreeWidgetItem* findItem(QTreeWidgetItem* root, const Options& opt) const;
bool matches(QTreeWidgetItem* item, const Options& opt) const;
private:
Ui_DlgParameterFind* ui;
DlgParameterImp* dialog;
};
} // namespace Dialog
} // namespace Gui
#endif // GUI_DIALOG_DLGPARAMETERFIND_H

151
src/Gui/DlgParameterFind.ui Normal file
View File

@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gui::Dialog::DlgParameterFind</class>
<widget class="QDialog" name="Gui::Dialog::DlgParameterFind">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>443</width>
<height>212</height>
</rect>
</property>
<property name="windowTitle">
<string>Find</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Find what:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="1" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Look at</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QCheckBox" name="checkGroups">
<property name="text">
<string>Groups</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkNames">
<property name="text">
<string>Names</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkValues">
<property name="text">
<string>Values</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="checkMatch">
<property name="text">
<string>Match whole string only</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Gui::Dialog::DlgParameterFind</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>433</x>
<y>202</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Gui::Dialog::DlgParameterFind</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>433</x>
<y>202</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -35,6 +35,7 @@
#include "ui_DlgParameter.h"
#include "DlgParameterImp.h"
#include "DlgParameterFind.h"
#include "DlgInputDialogImp.h"
#include "BitmapFactory.h"
#include "FileDialog.h"
@@ -117,6 +118,13 @@ DlgParameterImp::~DlgParameterImp()
delete ui;
}
void DlgParameterImp::on_buttonFind_clicked()
{
if (finder.isNull())
finder = new DlgParameterFind(this);
finder->show();
}
/**
* Sets the strings of the subwidgets using the current
* language.
@@ -561,6 +569,11 @@ void ParameterValue::setCurrentGroup( const Base::Reference<ParameterGrp>& hGrp
_hcGrp = hGrp;
}
Base::Reference<ParameterGrp> ParameterValue::currentGroup() const
{
return _hcGrp;
}
bool ParameterValue::edit ( const QModelIndex & index, EditTrigger trigger, QEvent * event )
{
if (index.column() > 0)

View File

@@ -29,11 +29,13 @@
#include <QTreeWidgetItem>
#include <QTreeWidget>
#include <QDialog>
#include <QPointer>
namespace Gui {
namespace Dialog {
class Ui_DlgParameter;
class DlgParameterFind;
/**
* The DlgParameterImp class implements a dialog showing all parameters in a list view.
@@ -54,6 +56,7 @@ public:
protected Q_SLOTS:
void onChangeParameterSet(int);
void on_buttonFind_clicked();
void on_buttonSaveToDisk_clicked();
void onGroupSelected(QTreeWidgetItem *);
@@ -68,6 +71,7 @@ protected:
QTreeWidget* paramGroup;
QTreeWidget* paramValue;
Ui_DlgParameter* ui;
QPointer<DlgParameterFind> finder;
};
// --------------------------------------------------------------------
@@ -139,6 +143,8 @@ public:
/** Sets the current parameter group that is displayed. */
void setCurrentGroup( const Base::Reference<ParameterGrp>& _hcGrp );
/** Returns the current parameter group that is displayed. */
Base::Reference<ParameterGrp> currentGroup() const;
protected:
/** Shows the context menu. */