Skip to content

Commit

Permalink
Updated the code to re-use TreeSearchFilters class.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 17, 2015
1 parent 36083c2 commit a1687e4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 88 deletions.
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -2523,6 +2523,7 @@ LibraryWidget::LibraryWidget(MainWindow *pMainWindow)
: QWidget(pMainWindow), mpMainWindow(pMainWindow)
{
setMinimumWidth(175);
// tree search filters
mpTreeSearchFilters = new TreeSearchFilters(this);
mpTreeSearchFilters->getSearchTextBox()->setPlaceholderText(Helper::searchClasses);
connect(mpTreeSearchFilters->getSearchTextBox(), SIGNAL(returnPressed()), SLOT(searchClasses()));
Expand Down
58 changes: 21 additions & 37 deletions OMEdit/OMEditGUI/Plotting/VariablesWidget.cpp
Expand Up @@ -760,27 +760,13 @@ VariablesWidget::VariablesWidget(MainWindow *pMainWindow)
{
setMinimumWidth(175);
mpMainWindow = pMainWindow;
// create the find text box
mpFindVariablesTextBox = new QLineEdit;
mpFindVariablesTextBox->setPlaceholderText(Helper::findVariables);
connect(mpFindVariablesTextBox, SIGNAL(returnPressed()), SLOT(findVariables()));
connect(mpFindVariablesTextBox, SIGNAL(textEdited(QString)), SLOT(findVariables()));
// create the case sensitivity checkbox
mpFindCaseSensitiveCheckBox = new QCheckBox(tr("Case Sensitive"));
connect(mpFindCaseSensitiveCheckBox, SIGNAL(toggled(bool)), SLOT(findVariables()));
// create the find syntax combobox
mpFindSyntaxComboBox = new QComboBox;
mpFindSyntaxComboBox->addItem(tr("Regular Expression"), QRegExp::RegExp);
mpFindSyntaxComboBox->setItemData(0, tr("A rich Perl-like pattern matching syntax."), Qt::ToolTipRole);
mpFindSyntaxComboBox->addItem(tr("Wildcard"), QRegExp::Wildcard);
mpFindSyntaxComboBox->setItemData(1, tr("A simple pattern matching syntax similar to that used by shells (command interpreters) for \"file globbing\"."), Qt::ToolTipRole);
mpFindSyntaxComboBox->addItem(tr("Fixed String"), QRegExp::FixedString);
mpFindSyntaxComboBox->setItemData(2, tr("Fixed string matching."), Qt::ToolTipRole);
connect(mpFindSyntaxComboBox, SIGNAL(currentIndexChanged(int)), SLOT(findVariables()));
// expand all button
mpExpandAllButton = new QPushButton(Helper::expandAll);
// collapse all button
mpCollapseAllButton = new QPushButton(Helper::collapseAll);
// tree search filters
mpTreeSearchFilters = new TreeSearchFilters(this);
mpTreeSearchFilters->getSearchTextBox()->setPlaceholderText(Helper::findVariables);
connect(mpTreeSearchFilters->getSearchTextBox(), SIGNAL(returnPressed()), SLOT(findVariables()));
connect(mpTreeSearchFilters->getSearchTextBox(), SIGNAL(textEdited(QString)), SLOT(findVariables()));
connect(mpTreeSearchFilters->getCaseSensitiveCheckBox(), SIGNAL(toggled(bool)), SLOT(findVariables()));
connect(mpTreeSearchFilters->getSyntaxComboBox(), SIGNAL(currentIndexChanged(int)), SLOT(findVariables()));
// create variables tree widget
mpVariablesTreeView = new VariablesTreeView(this);
mpVariablesTreeModel = new VariablesTreeModel(mpVariablesTreeView);
Expand All @@ -794,15 +780,12 @@ VariablesWidget::VariablesWidget(MainWindow *pMainWindow)
// create the layout
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setContentsMargins(0, 0, 0, 0);
pMainLayout->addWidget(mpFindVariablesTextBox, 0, 0, 1, 2);
pMainLayout->addWidget(mpFindCaseSensitiveCheckBox, 1, 0);
pMainLayout->addWidget(mpFindSyntaxComboBox, 1, 1);
pMainLayout->addWidget(mpExpandAllButton, 2, 0);
pMainLayout->addWidget(mpCollapseAllButton, 2, 1);
pMainLayout->addWidget(mpVariablesTreeView, 3, 0, 1, 2);
pMainLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pMainLayout->addWidget(mpTreeSearchFilters, 0, 0);
pMainLayout->addWidget(mpVariablesTreeView, 1, 0);
setLayout(pMainLayout);
connect(mpExpandAllButton, SIGNAL(clicked()), mpVariablesTreeView, SLOT(expandAll()));
connect(mpCollapseAllButton, SIGNAL(clicked()), mpVariablesTreeView, SLOT(collapseAll()));
connect(mpTreeSearchFilters->getExpandAllButton(), SIGNAL(clicked()), mpVariablesTreeView, SLOT(expandAll()));
connect(mpTreeSearchFilters->getCollapseAllButton(), SIGNAL(clicked()), mpVariablesTreeView, SLOT(collapseAll()));
connect(mpVariablesTreeModel, SIGNAL(rowsInserted(QModelIndex,int,int)), mpVariableTreeProxyModel, SLOT(invalidate()));
connect(mpVariablesTreeModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), mpVariableTreeProxyModel, SLOT(invalidate()));
connect(mpVariablesTreeModel, SIGNAL(itemChecked(QModelIndex,qreal,int)), SLOT(plotVariables(QModelIndex,qreal,int)));
Expand Down Expand Up @@ -1324,20 +1307,21 @@ void VariablesWidget::showContextMenu(QPoint point)
}
}

/*!
* \brief VariablesWidget::findVariables
* Finds the variables in the Variables Browser.
*/
void VariablesWidget::findVariables()
{
QString findText = mpFindVariablesTextBox->text();
if (mpFindVariablesTextBox->text().isEmpty())
{
findText = "";
}
QRegExp::PatternSyntax syntax = QRegExp::PatternSyntax(mpFindSyntaxComboBox->itemData(mpFindSyntaxComboBox->currentIndex()).toInt());
Qt::CaseSensitivity caseSensitivity = mpFindCaseSensitiveCheckBox->isChecked() ? Qt::CaseSensitive: Qt::CaseInsensitive;
QString findText = mpTreeSearchFilters->getSearchTextBox()->text();
QRegExp::PatternSyntax syntax = QRegExp::PatternSyntax(mpTreeSearchFilters->getSyntaxComboBox()->itemData(mpTreeSearchFilters->getSyntaxComboBox()->currentIndex()).toInt());
Qt::CaseSensitivity caseSensitivity = mpTreeSearchFilters->getCaseSensitiveCheckBox()->isChecked() ? Qt::CaseSensitive: Qt::CaseInsensitive;
QRegExp regExp(findText, caseSensitivity, syntax);
mpVariableTreeProxyModel->setFilterRegExp(regExp);
/* expand all so that the filtered items can be seen. */
if (!findText.isEmpty())
if (!findText.isEmpty()) {
mpVariablesTreeView->expandAll();
}
}

void VariablesWidget::directReSimulate()
Expand Down
6 changes: 1 addition & 5 deletions OMEdit/OMEditGUI/Plotting/VariablesWidget.h
Expand Up @@ -173,11 +173,7 @@ class VariablesWidget : public QWidget
void updateInitXmlFile(SimulationOptions simulationOptions);
private:
MainWindow *mpMainWindow;
QLineEdit *mpFindVariablesTextBox;
QComboBox *mpFindSyntaxComboBox;
QCheckBox *mpFindCaseSensitiveCheckBox;
QPushButton *mpExpandAllButton;
QPushButton *mpCollapseAllButton;
TreeSearchFilters *mpTreeSearchFilters;
VariableTreeProxyModel *mpVariableTreeProxyModel;
VariablesTreeModel *mpVariablesTreeModel;
VariablesTreeView *mpVariablesTreeView;
Expand Down
71 changes: 30 additions & 41 deletions OMEdit/OMEditGUI/TransformationalDebugger/TransformationsWidget.cpp
Expand Up @@ -466,27 +466,13 @@ TransformationsWidget::TransformationsWidget(QString infoXMLFullFileName, MainWi
/* Variables Heading */
Label *pVariablesBrowserLabel = new Label(Helper::variablesBrowser);
pVariablesBrowserLabel->setObjectName("LabelWithBorder");
// create the find text box
mpFindVariablesTextBox = new QLineEdit;
mpFindVariablesTextBox->setPlaceholderText(Helper::findVariables);
connect(mpFindVariablesTextBox, SIGNAL(returnPressed()), SLOT(findVariables()));
connect(mpFindVariablesTextBox, SIGNAL(textEdited(QString)), SLOT(findVariables()));
// create the case sensitivity checkbox
mpFindCaseSensitiveCheckBox = new QCheckBox(tr("Case Sensitive"));
connect(mpFindCaseSensitiveCheckBox, SIGNAL(toggled(bool)), SLOT(findVariables()));
// create the find syntax combobox
mpFindSyntaxComboBox = new QComboBox;
mpFindSyntaxComboBox->addItem(tr("Regular Expression"), QRegExp::RegExp);
mpFindSyntaxComboBox->setItemData(0, tr("A rich Perl-like pattern matching syntax."), Qt::ToolTipRole);
mpFindSyntaxComboBox->addItem(tr("Wildcard"), QRegExp::Wildcard);
mpFindSyntaxComboBox->setItemData(1, tr("A simple pattern matching syntax similar to that used by shells (command interpreters) for \"file globbing\"."), Qt::ToolTipRole);
mpFindSyntaxComboBox->addItem(tr("Fixed String"), QRegExp::FixedString);
mpFindSyntaxComboBox->setItemData(2, tr("Fixed string matching."), Qt::ToolTipRole);
connect(mpFindSyntaxComboBox, SIGNAL(currentIndexChanged(int)), SLOT(findVariables()));
// expand all button
mpExpandAllButton = new QPushButton(Helper::expandAll);
// collapse all button
mpCollapseAllButton = new QPushButton(Helper::collapseAll);
// tree search filters
mpTreeSearchFilters = new TreeSearchFilters(this);
mpTreeSearchFilters->getSearchTextBox()->setPlaceholderText(Helper::findVariables);
connect(mpTreeSearchFilters->getSearchTextBox(), SIGNAL(returnPressed()), SLOT(findVariables()));
connect(mpTreeSearchFilters->getSearchTextBox(), SIGNAL(textEdited(QString)), SLOT(findVariables()));
connect(mpTreeSearchFilters->getCaseSensitiveCheckBox(), SIGNAL(toggled(bool)), SLOT(findVariables()));
connect(mpTreeSearchFilters->getSyntaxComboBox(), SIGNAL(currentIndexChanged(int)), SLOT(findVariables()));
/* variables tree view */
mpTVariablesTreeView = new TVariablesTreeView(this);
mpTVariablesTreeModel = new TVariablesTreeModel(mpTVariablesTreeView);
Expand All @@ -496,18 +482,14 @@ TransformationsWidget::TransformationsWidget(QString infoXMLFullFileName, MainWi
mpTVariablesTreeView->setModel(mpTVariableTreeProxyModel);
mpTVariablesTreeView->setColumnWidth(2, 40); /* line number column */
connect(mpTVariablesTreeView, SIGNAL(doubleClicked(QModelIndex)), SLOT(fetchVariableData(QModelIndex)));
connect(mpExpandAllButton, SIGNAL(clicked()), mpTVariablesTreeView, SLOT(expandAll()));
connect(mpCollapseAllButton, SIGNAL(clicked()), mpTVariablesTreeView, SLOT(collapseAll()));
connect(mpTreeSearchFilters->getExpandAllButton(), SIGNAL(clicked()), mpTVariablesTreeView, SLOT(expandAll()));
connect(mpTreeSearchFilters->getCollapseAllButton(), SIGNAL(clicked()), mpTVariablesTreeView, SLOT(collapseAll()));
QGridLayout *pVariablesGridLayout = new QGridLayout;
pVariablesGridLayout->setSpacing(1);
pVariablesGridLayout->setContentsMargins(0, 0, 0, 0);
pVariablesGridLayout->addWidget(pVariablesBrowserLabel, 0, 0, 1, 2);
pVariablesGridLayout->addWidget(mpFindVariablesTextBox, 1, 0, 1, 2);
pVariablesGridLayout->addWidget(mpFindCaseSensitiveCheckBox, 2, 0);
pVariablesGridLayout->addWidget(mpFindSyntaxComboBox, 2, 1);
pVariablesGridLayout->addWidget(mpExpandAllButton, 3, 0);
pVariablesGridLayout->addWidget(mpCollapseAllButton, 3, 1);
pVariablesGridLayout->addWidget(mpTVariablesTreeView, 4, 0, 1, 2);
pVariablesGridLayout->addWidget(pVariablesBrowserLabel, 0, 0);
pVariablesGridLayout->addWidget(mpTreeSearchFilters, 1, 0);
pVariablesGridLayout->addWidget(mpTVariablesTreeView, 2, 0);
QFrame *pVariablesFrame = new QFrame;
pVariablesFrame->setLayout(pVariablesGridLayout);
/* Defined in tree widget */
Expand Down Expand Up @@ -1188,9 +1170,15 @@ void TransformationsWidget::reloadTransformations()
/* Clear the variable operations tree. */
clearTreeWidgetItems(mpVariableOperationsTreeWidget);
/* clear the variable tree filters. */
mpFindVariablesTextBox->setText(Helper::findVariables);
mpFindSyntaxComboBox->setCurrentIndex(0);
mpFindCaseSensitiveCheckBox->setChecked(false);
bool signalsState = mpTreeSearchFilters->getSearchTextBox()->blockSignals(true);
mpTreeSearchFilters->getSearchTextBox()->clear();
mpTreeSearchFilters->getSearchTextBox()->blockSignals(signalsState);
signalsState = mpTreeSearchFilters->getSyntaxComboBox()->blockSignals(true);
mpTreeSearchFilters->getSyntaxComboBox()->setCurrentIndex(0);
mpTreeSearchFilters->getSyntaxComboBox()->blockSignals(signalsState);
signalsState = mpTreeSearchFilters->getCaseSensitiveCheckBox()->blockSignals(true);
mpTreeSearchFilters->getCaseSensitiveCheckBox()->setChecked(false);
mpTreeSearchFilters->getCaseSensitiveCheckBox()->blockSignals(signalsState);
mpTVariableTreeProxyModel->setFilterRegExp(QRegExp());
/* clear equations tree */
clearTreeWidgetItems(mpEquationsTreeWidget);
Expand All @@ -1211,20 +1199,21 @@ void TransformationsWidget::reloadTransformations()
loadTransformations();
}

/*!
* \brief TransformationsWidget::findVariables
* Finds the variables in the TransformationsWidget Variables Browser.
*/
void TransformationsWidget::findVariables()
{
QString findText = mpFindVariablesTextBox->text();
if (mpFindVariablesTextBox->text().isEmpty() || (mpFindVariablesTextBox->text().compare(Helper::findVariables) == 0))
{
findText = "";
}
QRegExp::PatternSyntax syntax = QRegExp::PatternSyntax(mpFindSyntaxComboBox->itemData(mpFindSyntaxComboBox->currentIndex()).toInt());
Qt::CaseSensitivity caseSensitivity = mpFindCaseSensitiveCheckBox->isChecked() ? Qt::CaseSensitive: Qt::CaseInsensitive;
QString findText = mpTreeSearchFilters->getSearchTextBox()->text();
QRegExp::PatternSyntax syntax = QRegExp::PatternSyntax(mpTreeSearchFilters->getSyntaxComboBox()->itemData(mpTreeSearchFilters->getSyntaxComboBox()->currentIndex()).toInt());
Qt::CaseSensitivity caseSensitivity = mpTreeSearchFilters->getCaseSensitiveCheckBox()->isChecked() ? Qt::CaseSensitive: Qt::CaseInsensitive;
QRegExp regExp(findText, caseSensitivity, syntax);
mpTVariableTreeProxyModel->setFilterRegExp(regExp);
/* expand all so that the filtered items can be seen. */
if (!findText.isEmpty())
if (!findText.isEmpty()) {
mpTVariablesTreeView->expandAll();
}
}

void TransformationsWidget::fetchVariableData(const QModelIndex &index)
Expand Down
Expand Up @@ -188,11 +188,7 @@ class TransformationsWidget : public QWidget
QString mInfoXMLFullFileName, mProfJSONFullFileName, mProfilingDataRealFileName;
int profilingNumSteps;
MyHandler *mpInfoXMLFileHandler;
QLineEdit *mpFindVariablesTextBox;
QComboBox *mpFindSyntaxComboBox;
QCheckBox *mpFindCaseSensitiveCheckBox;
QPushButton *mpExpandAllButton;
QPushButton *mpCollapseAllButton;
TreeSearchFilters *mpTreeSearchFilters;
TVariablesTreeView *mpTVariablesTreeView;
TVariablesTreeModel *mpTVariablesTreeModel;
TVariableTreeProxyModel *mpTVariableTreeProxyModel;
Expand Down

0 comments on commit a1687e4

Please sign in to comment.