Skip to content

Commit

Permalink
filter out non-modelica items by checking flag showOnlyModelica.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 7, 2016
1 parent 609a89d commit d763c77
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 40 deletions.
61 changes: 23 additions & 38 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -825,10 +825,11 @@ void LibraryTreeItem::handleIconUpdated()
* \brief LibraryTreeProxyModel::LibraryTreeProxyModel
* \param pLibraryWidget
*/
LibraryTreeProxyModel::LibraryTreeProxyModel(LibraryWidget *pLibraryWidget)
LibraryTreeProxyModel::LibraryTreeProxyModel(LibraryWidget *pLibraryWidget, bool showOnlyModelica)
: QSortFilterProxyModel(pLibraryWidget)
{
mpLibraryWidget = pLibraryWidget;
mShowOnlyModelica = showOnlyModelica;
}

/*!
Expand All @@ -841,48 +842,32 @@ LibraryTreeProxyModel::LibraryTreeProxyModel(LibraryWidget *pLibraryWidget)
*/
bool LibraryTreeProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if (!filterRegExp().isEmpty()) {
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
if (index.isValid()) {
// if any of children matches the filter, then current index matches the filter as well
int rows = sourceModel()->rowCount(index);
for (int i = 0 ; i < rows ; ++i) {
if (filterAcceptsRow(i, index)) {
return true;
}
}
// check current index itself
LibraryTreeItem *pLibraryTreeItem = static_cast<LibraryTreeItem*>(index.internalPointer());
if (pLibraryTreeItem) {
if (pLibraryTreeItem->isProtected() && !mpLibraryWidget->getMainWindow()->getOptionsDialog()->getGeneralSettingsPage()->getShowProtectedClasses()) {
return false;
} else {
return pLibraryTreeItem->getNameStructure().contains(filterRegExp());
}
} else {
return sourceModel()->data(index).toString().contains(filterRegExp());
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
if (index.isValid()) {
LibraryTreeItem *pLibraryTreeItem = static_cast<LibraryTreeItem*>(index.internalPointer());
// if showOnlyModelica flag is enabled then filter out all other types of LibraryTreeItem e.g., TLM & Text.
if (mShowOnlyModelica && pLibraryTreeItem && pLibraryTreeItem->getLibraryType() != LibraryTreeItem::Modelica) {
return false;
}
// if any of children matches the filter, then current index matches the filter as well
int rows = sourceModel()->rowCount(index);
for (int i = 0 ; i < rows ; ++i) {
if (filterAcceptsRow(i, index)) {
return true;
}
QString key = sourceModel()->data(index, filterRole()).toString();
return key.contains(filterRegExp());
} else {
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
} else {
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
if (index.isValid()) {
LibraryTreeItem *pLibraryTreeItem = static_cast<LibraryTreeItem*>(index.internalPointer());
if (pLibraryTreeItem) {
if (pLibraryTreeItem->isProtected() && !mpLibraryWidget->getMainWindow()->getOptionsDialog()->getGeneralSettingsPage()->getShowProtectedClasses()) {
return false;
} else {
return pLibraryTreeItem->getNameStructure().contains(filterRegExp());
}
// check current index itself
if (pLibraryTreeItem) {
if (pLibraryTreeItem->isProtected() && !mpLibraryWidget->getMainWindow()->getOptionsDialog()->getGeneralSettingsPage()->getShowProtectedClasses()) {
return false;
} else {
return sourceModel()->data(index).toString().contains(filterRegExp());
return pLibraryTreeItem->getNameStructure().contains(filterRegExp());
}
} else {
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
return sourceModel()->data(index).toString().contains(filterRegExp());
}
} else {
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
}

Expand Down Expand Up @@ -2850,7 +2835,7 @@ LibraryWidget::LibraryWidget(MainWindow *pMainWindow)
mpTreeSearchFilters->getCollapseAllButton()->hide();
// create tree view
mpLibraryTreeModel = new LibraryTreeModel(this);
mpLibraryTreeProxyModel = new LibraryTreeProxyModel(this);
mpLibraryTreeProxyModel = new LibraryTreeProxyModel(this, false);
mpLibraryTreeProxyModel->setDynamicSortFilter(true);
mpLibraryTreeProxyModel->setSourceModel(mpLibraryTreeModel);
mpLibraryTreeView = new LibraryTreeView(this);
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -200,9 +200,10 @@ class LibraryTreeProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
LibraryTreeProxyModel(LibraryWidget *pLibraryWidget);
LibraryTreeProxyModel(LibraryWidget *pLibraryWidget, bool showOnlyModelica);
private:
LibraryWidget *mpLibraryWidget;
bool mShowOnlyModelica;
protected:
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
};
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Modeling/ModelicaClassDialog.cpp
Expand Up @@ -57,7 +57,7 @@ LibraryBrowseDialog::LibraryBrowseDialog(QString title, QLineEdit *pLineEdit, Li
connect(mpTreeSearchFilters->getCaseSensitiveCheckBox(), SIGNAL(toggled(bool)), SLOT(searchClasses()));
connect(mpTreeSearchFilters->getSyntaxComboBox(), SIGNAL(currentIndexChanged(int)), SLOT(searchClasses()));
// create the tree
mpLibraryTreeProxyModel = new LibraryTreeProxyModel(mpLibraryWidget);
mpLibraryTreeProxyModel = new LibraryTreeProxyModel(mpLibraryWidget, true);
mpLibraryTreeProxyModel->setDynamicSortFilter(true);
mpLibraryTreeProxyModel->setSourceModel(mpLibraryWidget->getLibraryTreeModel());
mpLibraryTreeView = new QTreeView;
Expand Down

0 comments on commit d763c77

Please sign in to comment.