[Qt-interest] Tree Item view Highlighter

Scott Aron Bloom Scott.Bloom at onshorecs.com
Tue Jan 4 20:56:39 CET 2011


Yes...

 

From: qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com [mailto:qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com] On Behalf Of Sajjad
Sent: Tuesday, January 04, 2011 11:50 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Tree Item view Highlighter

 

Hello Andre,

 

I think inside the slot i shall have to emit the dataChanged() as follows:

 

///////////////////////////////////////////////////////////////////

 

void H3DNodeListWidget::highlightRegExpChanged()
{
    QRegExp regExp(m_nodeHighlightingEditor->text(),Qt::CaseInsensitive,QRegExp::FixedString);
    m_highlightModel->setFilterRegExp(regExp);
    
 
    //in that case i have to send the QModleIndex parameters
 
    //to specify the range and how do i retrieve this
    emit m_highlightModel->dataChanged(m_modelIndexStart,m_modelIndexEnd);
}

 

 

///////////////////////////////////////////////////////////////////

 

 

Am i in the right track?

 

 

 

Regards

Sajjad

On Tue, Jan 4, 2011 at 8:34 PM, André Somers <andre at familiesomers.nl> wrote:



Verstuurd vanaf mijn iPhone


Op 4 jan. 2011 om 19:51 heeft Sajjad <dosto.walla at gmail.com> het volgende geschreven:

	Hello 

	 

	emitting the dataChanged() is done only when we re-implement the setData() function. Should i over-ride data() or the setData() function?

No, emitting dataChanged is done when data in the model changes. That happens often when setData is called, but that is not the only thing that can trigger it. In this case, changing your regexp changes the data. So, you override data() as explained earlier, and you emit dataChanged when the regexp changes. 

 

André





 

 

 

Regards

Sajjad

On Tue, Jan 4, 2011 at 6:53 PM, Scott Aron Bloom <Scott.Bloom at onshorecs.com> wrote:

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

	-----------------------

 

 

Yes, read the Qt documentation on model view programming...  and the signal/slot programming...

 

The dataChanged signal, allows you to send out a "square" of topLeft to bottomRight inclusive...  If topLeft == bottomRight, then only that cell is updated.

 

As to your update connection, you shouldn't have to, all views are automatically connected to the dataChanged signal

 

Scott

 

	_______________________________________________
	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/e99f66c8/attachment.html 


More information about the Qt-interest-old mailing list