[Qt-interest] Tree Item view Highlighter
Sajjad
dosto.walla at gmail.com
Tue Jan 4 18:44:29 CET 2011
On Tue, Jan 4, 2011 at 10:21 AM, Andre Somers <andre at familiesomers.nl>wrote:
> Op Di, 4 januari, 2011 9:21 am, schreef Sajjad:
>
> >> Is there anything missing up there? I removed the other function that i
> >> over-rid mentioned in the previous post.
> >>
> >> I am still not getting any effect. The textchanged() signal is
> >> connected
> >> to the slot as before.
> >>
> >> Ah, of course... Sorry about that.
> >>
> >> First of all: are you getting an effect if you set a fixed regexp to
> >> begin
> >> with? If not, then something is wrong in the code above. Set a
> >> breakpoint
> >> where you return the color and see if you ever arrive there at all...
> >>
> >
> > I set the breakpoint at the slot
> >
> > void H3DNodeListWidget::highlightRegExpChanged()
> >
> > {
> >
> > QRegExp
> >
> regExp(m_nodeHighlightingEditor->text(),Qt::CaseInsensitive,QRegExp::FixedString);
> >
> > m_highlightModel->setFilterRegExp(regExp);
> >
> > }
> >
> I meant setting the breakpoint in the data() function.
>
The breakpoint has been set there as well.
>
> > And i did not reach the data() function while stepping into the code.
> I can imagine it did not.
>
> >> However, I think the problem is, that you need to notify your view that
> >> the
> >> data has changed if your regexp changes. For testing, just emit reset(),
> >> but
> >> in your real implementation, you should probably be a bit nicer and emit
> >> dataChanged() with the right modelindexes.
> >>
>
i believ ethat the dataChanged() signal two model indexes as input
parameter. I need to highlight only one tree item that maches the expression
in the line edit. In that case how should i set the value for the signal
that takes 2 input parameters. Should it be the same source index specified
twice? I tried something as follows:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
QVariant H3DHighlighterProxyModel::data(const QModelIndex &index,
int role) const
{
//get the handle to the underlyiing data
QModelIndex sourceIndex = mapToSource(index);
if(!sourceIndex.isValid())
{
return QVariant();
}
if(role == Qt::BackgroundRole)
{
if(sourceModel()->data(sourceIndex).toString().contains(filterRegExp()))
{
//the following statement gives error because the virtual
function itself
//declared const
emit dataChanged(sourceIndex,sourceIndex);
return Qt::cyan;
}
else
{
//return the default background color
//whatever may it be
return QVariant();
}
}
else
{
return sourceIndex.data(role);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
And then if i have to set the connection as follows, i believe that it will
not be valid:
connect(m_proxyMode,dataChanged(QModelIndex,QModelIndex),m_treeView,SLOT(update(QModelIndex))));
As you can see that the parameters are not matching.
>From all the discussions you can imagine that i am having trouble to grasp
the basic idea of model.view programming.
Could you provide some references where these issues are well discussed?
Regards
Sajjad
> >
> > I did not understand that part. A bit more elaboration might be helpful.
>
> Ok, let me try. If you set a new regexp, you expect part of the data to
> change (the background color for some of the items in your model). But how
> is the view to know that? It needs to be told that the data has changed,
> so it can redraw itself. Of course, Qt uses signals and slots for that.
> The elegant way to do it is to tell the view exactly which items have
> changed by emitting the (proxy-) models changedData signal with the range
> of items that have changed. The more course that range is, the more
> repainting and requerying of the model the view may have to do. The most
> course way is to reset the model completely. This will cause a complete
> reset of the view, including the current selection, the current view
> position, etc.
>
> You need to signal that change from the slot where you set the new regexp.
> That should trigger the view to start requerying the model for the updated
> data, and redraw the view appropriately.
>
> André
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110104/7f29fc5c/attachment.html
More information about the Qt-interest-old
mailing list