[Qgis-developer] updating data from multiple algos simultaneously on canvas

nitin quick quick.nitin at gmail.com
Wed Jul 5 06:04:28 EDT 2006


hello everybody
i am using QGIS 0.7.9
Aim of my plugin: To display points received from various algorithms
simultaneously on canvas.

Situation is like on top of map i am displaying location of points received
from a client-socket using TCP/IP. It works fine till only one such socket
is opened and read from .Updation and movement of points goes well. But as
soon as i start reading from multiple client/sockets and try to display data
, all situation goes awery. Then only data from recently activated
socket/client is updated and displayed. This is where i am looking for help.

How i have implemented: For storing data from various socket i am using
QHash with key as socket Descriptor id and Value as in a QList.
For each readyRead() received signal i gets i add in hash with correspondent
socket descriptor as key.
here is part of code i am putting:

// this slot will be called for newConnection() signal
void tcpCock::activatingNewConnection()
{
     tcpSocket=tcpServer->nextPendingConnection();
    connect( tcpSocket, SIGNAL(disconnected()),tcpSocket,
SLOT(deleteLater()));
    connect( tcpSocket,SIGNAL(readyRead()),this,SLOT(updatePixmap()));
    //provide a connect for linking socket exiting status to one of slo
which disconnects drawShape() from refresh signal.
    connect(
tcpSocket,SIGNAL(disconnected()),this,SLOT(socketDisconnected()));
    pIntQlist= new QList<int> ;
    hash.insert(tcpSocket->socketDescriptor(),pIntQlist);
}


//drawshape() function defination for QgsMapCanvasItem's pure virtual one
void tcpCock::drawShape(QPainter & p)
{
    //load the pixamap to be displayed
    QString myFileNameQString= "/home1/qgis/images/cock/cock.png";
    QPixmap myQPixmap;
    myQPixmap.load(myFileNameQString);


    QHashIterator<int, QList<int>* > itr(hash);
    while ( itr.hasNext())
    {    itr.next() ;//possible outcome of error
        //tempList=itr.value();

        QListIterator<int> tempListItr(*itr.value());
        tempListItr.toBack();
        y=tempListItr.previous();
        x=tempListItr.previous();
        QgsPoint qpt(x,y);
        QPoint pt=toCanvasCoords(qpt);
        move(pt.x(),pt.y());// added to check for movement of all
elements-questionable
        p.drawPixmap(pt.x(),pt.y(),myQPixmap);
      }
}


//This slot will be called for every readyRead()signal
void tcpCock::updatePixmap()
{

    QTcpSocket *tempSock=dynamic_cast<QTcpSocket *>(sender());
    if(tempSock)
    {
    QHash<int, QList<int>* >::const_iterator itr=hash.find
(tempSock->socketDescriptor());

    QString st;
    QDataStream in(tcpSocket);
    in.setVersion(QDataStream::Qt_4_0);
    if( tempSock->bytesAvailable() <= 0 )// changed from tcpSocket since
tcpsocket will look for newely activeted connection only
    {
        //cout<<"\nNothing    Available for reading";
        return;
    }
    in >>st;
    int i=0;
    QChar *data = st.data();
    while (*data!=' ')
    {
        ++data;
        i++;
    }
    QString s1=st.left(i);
    x=s1.toInt();
    QString s2=st.mid(i+1);
    y=s2.toInt();
    itr.value()->append(x);
    itr.value()->append(y);

    move(x,y);
    QgsRect r=mQGisApp->getMapCanvas()->fullExtent();
    setRect(r);
    show();
    updateCanvas();
    }
}

What i feel is not ok with this piece of code is i am not able to address to
canvas item corresponding to  data received from each client.  To avoid it
i am  drawing  each  canvas item again  at their last available location in
hash.value() ie list. But output is that only newely created socket -canvs
item is updated.
While using gdb i observed with 3 client connections. Every canvas item
starts again from location provided by newly activated client. and after
that all follow the path.
kindly help me in this matter.

regards
quick nitin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20060705/b2bf640e/attachment.html


More information about the Qgis-developer mailing list