Skip to content

Commit

Permalink
Don't apply the filter using the path
Browse files Browse the repository at this point in the history
When opening the browse for classes dialog don't apply the filter using the path instead just select the class specified by the path
  • Loading branch information
adeas31 committed Jan 9, 2020
1 parent f89d5be commit f60ffbd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
47 changes: 29 additions & 18 deletions OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.cpp
Expand Up @@ -52,7 +52,7 @@ LibraryBrowseDialog::LibraryBrowseDialog(QString title, QLineEdit *pLineEdit, Li
: QDialog(0)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(QString(Helper::applicationName).append(" - ").append(title));
setWindowTitle(QString("%1 - %2").arg(Helper::applicationName, title));
resize(250, 500);
mpLineEdit = pLineEdit;
mpLibraryWidget = pLibraryWidget;
Expand All @@ -79,9 +79,10 @@ LibraryBrowseDialog::LibraryBrowseDialog(QString title, QLineEdit *pLineEdit, Li
connect(mpTreeSearchFilters->getExpandAllButton(), SIGNAL(clicked()), mpLibraryTreeView, SLOT(expandAll()));
connect(mpTreeSearchFilters->getCollapseAllButton(), SIGNAL(clicked()), mpLibraryTreeView, SLOT(collapseAll()));
connect(mpLibraryTreeView, SIGNAL(doubleClicked(QModelIndex)), SLOT(useModelicaClass()));
// try to automatically select of user has something in the text box.
mpTreeSearchFilters->getFilterTextBox()->setText(mpLineEdit->text());
searchClasses();
// try to automatically select if user has something in the text box.
if (!mpLineEdit->text().isEmpty()) {
findAndSelectLibraryTreeItem(QRegExp(mpLineEdit->text()));
}
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
Expand All @@ -102,6 +103,29 @@ LibraryBrowseDialog::LibraryBrowseDialog(QString title, QLineEdit *pLineEdit, Li
setLayout(pMainLayout);
}

/*!
* \brief LibraryBrowseDialog::findAndSelectLibraryTreeItem
* Finds the LibraryTreeItem and selects it.
* \param regExp
*/
void LibraryBrowseDialog::findAndSelectLibraryTreeItem(const QRegExp &regExp)
{
QModelIndex proxyIndex = mpLibraryTreeProxyModel->index(0, 0);
if (proxyIndex.isValid()) {
QModelIndex modelIndex = mpLibraryTreeProxyModel->mapToSource(proxyIndex);
LibraryTreeItem *pLibraryTreeItem = mpLibraryWidget->getLibraryTreeModel()->findLibraryTreeItem(regExp, static_cast<LibraryTreeItem*>(modelIndex.internalPointer()));
if (pLibraryTreeItem) {
modelIndex = mpLibraryWidget->getLibraryTreeModel()->libraryTreeItemIndex(pLibraryTreeItem);
proxyIndex = mpLibraryTreeProxyModel->mapFromSource(modelIndex);
mpLibraryTreeView->selectionModel()->select(proxyIndex, QItemSelectionModel::Select);
while (proxyIndex.parent().isValid()) {
proxyIndex = proxyIndex.parent();
mpLibraryTreeView->expand(proxyIndex);
}
}
}
}

/*!
* \brief LibraryBrowseDialog::searchClasses
* Searches the classes.
Expand All @@ -116,20 +140,7 @@ void LibraryBrowseDialog::searchClasses()
mpLibraryTreeProxyModel->setFilterRegExp(regExp);
// if we have really searched something
if (!searchText.isEmpty()) {
QModelIndex proxyIndex = mpLibraryTreeProxyModel->index(0, 0);
if (proxyIndex.isValid()) {
QModelIndex modelIndex = mpLibraryTreeProxyModel->mapToSource(proxyIndex);
LibraryTreeItem *pLibraryTreeItem = mpLibraryWidget->getLibraryTreeModel()->findLibraryTreeItem(regExp, static_cast<LibraryTreeItem*>(modelIndex.internalPointer()));
if (pLibraryTreeItem) {
modelIndex = mpLibraryWidget->getLibraryTreeModel()->libraryTreeItemIndex(pLibraryTreeItem);
proxyIndex = mpLibraryTreeProxyModel->mapFromSource(modelIndex);
mpLibraryTreeView->selectionModel()->select(proxyIndex, QItemSelectionModel::Select);
while (proxyIndex.parent().isValid()) {
proxyIndex = proxyIndex.parent();
mpLibraryTreeView->expand(proxyIndex);
}
}
}
findAndSelectLibraryTreeItem(regExp);
}
}

Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.h
Expand Up @@ -68,6 +68,8 @@ class LibraryBrowseDialog : public QDialog
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;

void findAndSelectLibraryTreeItem(const QRegExp &regExp);
private slots:
void searchClasses();
void useModelicaClass();
Expand Down

0 comments on commit f60ffbd

Please sign in to comment.