QSortFilterProxyModel -filterAcceptsRow()- filter parent Node and child Node
-
Sorry but from mine understanding I first need to check if the string matches the one I'm looking for.
So that's why I have the first if statement, and then I do what you said in the previous post.
@
f (!action.isEmpty())
{
QModelIndex index = sourceModel()->index(sourceRow,
ACTION, sourceParent);if (action != sourceModel()->data(index).toString()) return false; if ((QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent))) return true; return hasAcceptedChildren(sourceRow, sourceParent); }
@
Still trying to understand whats going wrong. -
Hi qties,
at the first time I read the post from André I was so happy to find the solution I am searching for.
But unfortunately I am to stupid to get it work. Maybe you can help me.If I use the standard QSortFilterProxyModel everything works good except the search at textChanged Signal.
But if I use the LeafFilterProxyModel (exactly as André has post it) an error occurs and I do not know what it means.I hope somebady can help me.
Thank you.@
LeafFilterProxyModel m_oProxyModel;
//QSortFilterProxyModel m_oProxyModel;
QStandardItemModel m_oItemModel; // manualy filledm_oProxyModel.setSourceModel(&m_oItemModel);
m_tvDBC->setModel(&m_oProxyModel); // TreeView
m_lvDBC->setModel(&m_oStringModel); // ListView
@@
void cClass::textChanged(QString text)
{
QRegExp::PatternSyntax pSyntax = QRegExp::PatternSyntax(QRegExp::FixedString);
QRegExp regExp(text, Qt::CaseInsensitive, pSyntax);m_oProxyModel.setFilterRegExp(regExp);
m_oProxyModel.setFilterKeyColumn(-1);
}
@@
Error 1 error LNK2001: unresolved external symbol "public: __thiscall
LeafFilterProxyModel::LeafFilterProxyModel(class QObject *)"
??0LeafFilterProxyModel@@QAE@PAVQObject@@@Z) myobject.obj
@ -
Sounds like you forgot to add the .h file to your HEADERS section in your .pro file, and the .cpp file to the SOURCES section?
-
What does _parent type in this string?
@bool filterAcceptsRow(int source_row, const QModelIndex &source;_parent) const;@
And wath does this argument do?
And second question:
source_parent is source->parent()?
And in advance sorry for stupid questions) -
There was an unfortunate bug at the time in DevNet, that sometimes inserted ; at the wrong places in code sections. The code listing I posted suffered from this. The argument is supposed to be a single argument source_parent. I'll try to fixup the original posting. Thanks for noticing.
-
It is clear.
One more thank you for your help! -
Thank you - this thread has been really helpful!
-
Esta implementación recorre todo los sub-Nodos del padre buscando que el filterRegExp coincida con el Qt::DisplayRole del sub-Nodo.
El algoritmo no utiliza recursividad :D
@bool SortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
QList<QModelIndex> children;
children << sourceModel()->index(source_row, 0, source_parent);bool show = false; for(int i = 0; i < children.length(); i++) { if(show) break; // Add sub Nodos // for(int c = 0; c < sourceModel()->rowCount(children[i]) ;c++) children.append(children[i].child(c,0)); QString type = sourceModel()->data(children[i], Qt::DisplayRole).toString(); show = type.contains(filterRegExp()); } return show;
}@
-
Could you keep posts to English in this forum please? There are specialized sub-forums for other languages.
-
Could you keep posts to English in this forum please? There are specialized sub-forums for other languages.