Teaked the TrustView and NetworkView so that they only update when visible. Doing so, the CPU overload is only present when strictly needed.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1571 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-08-29 11:25:06 +00:00
parent d31bc2055f
commit c35a48feb7
3 changed files with 21 additions and 8 deletions

View File

@ -35,6 +35,11 @@ TrustView::TrustView()
update() ; update() ;
} }
void TrustView::showEvent(QShowEvent *e)
{
QWidget::showEvent(e) ;
update() ;
}
void TrustView::wheelEvent(QWheelEvent *e) void TrustView::wheelEvent(QWheelEvent *e)
{ {
if(e->modifiers() & Qt::ShiftModifier) if(e->modifiers() & Qt::ShiftModifier)
@ -98,14 +103,14 @@ void TrustView::updateZoom(int z)
// cout << "updated zoom" << endl; // cout << "updated zoom" << endl;
} }
int TrustView::getRowColId(const string& name) int TrustView::getRowColId(const string& peerid)
{ {
static map<string,int> nameToRow ; static map<string,int> peeridToRow ;
map<string,int>::const_iterator itpr(nameToRow.find( name )) ; map<string,int>::const_iterator itpr(peeridToRow.find( peerid )) ;
int i ; int i ;
if(itpr == nameToRow.end()) if(itpr == peeridToRow.end())
{ {
i = trustTableTW->columnCount() ; i = trustTableTW->columnCount() ;
// cout << " -> peer not in table. Creating entry # " << i << endl ; // cout << " -> peer not in table. Creating entry # " << i << endl ;
@ -113,7 +118,9 @@ int TrustView::getRowColId(const string& name)
trustTableTW->insertColumn(i) ; trustTableTW->insertColumn(i) ;
trustTableTW->insertRow(i) ; trustTableTW->insertRow(i) ;
nameToRow[name] = i ; peeridToRow[peerid] = i ;
std::string name = rsPeers->getPeerName(peerid) ;
trustTableTW->setHorizontalHeaderItem(i,new QTableWidgetItem(QString(name.c_str()))) ; trustTableTW->setHorizontalHeaderItem(i,new QTableWidgetItem(QString(name.c_str()))) ;
trustTableTW->setVerticalHeaderItem(i,new QTableWidgetItem(QString(name.c_str()))) ; trustTableTW->setVerticalHeaderItem(i,new QTableWidgetItem(QString(name.c_str()))) ;
@ -131,6 +138,9 @@ void TrustView::update()
{ {
// collect info. // collect info.
if(!isVisible())
return ;
std::list<std::string> neighs; std::list<std::string> neighs;
if(!rsPeers->getOthersList(neighs)) if(!rsPeers->getOthersList(neighs))
@ -150,11 +160,11 @@ void TrustView::update()
// cout << "treating neigh = " << details.name << endl ; // cout << "treating neigh = " << details.name << endl ;
// cout << " signers = " ; // cout << " signers = " ;
int i = getRowColId(details.name) ; int i = getRowColId(details.id) ;
for(list<string>::const_iterator it2(details.signers.begin());it2!=details.signers.end();++it2) for(list<string>::const_iterator it2(details.signers.begin());it2!=details.signers.end();++it2)
{ {
// cout << *it2 << " " ; cout << *it2 << " " ;
// Signers are identified by there name, so if we have twice the same signers, this gets crappy. // Signers are identified by there name, so if we have twice the same signers, this gets crappy.
int j = getRowColId(*it2) ; int j = getRowColId(*it2) ;

View File

@ -1,6 +1,7 @@
#include "ui_TrustView.h" #include "ui_TrustView.h"
class QWheelEvent ; class QWheelEvent ;
class QShowEvent ;
class TrustView: public QWidget, public Ui::TrustView class TrustView: public QWidget, public Ui::TrustView
{ {
@ -11,6 +12,7 @@ class TrustView: public QWidget, public Ui::TrustView
protected: protected:
virtual void wheelEvent(QWheelEvent *) ; virtual void wheelEvent(QWheelEvent *) ;
virtual void showEvent(QShowEvent *) ;
public slots: public slots:
void update() ; void update() ;

View File

@ -221,7 +221,8 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
void GraphWidget::timerEvent(QTimerEvent *event) void GraphWidget::timerEvent(QTimerEvent *event)
{ {
Q_UNUSED(event); if(!isVisible())
return;
QList<Node *> nodes; QList<Node *> nodes;
foreach (QGraphicsItem *item, scene()->items()) { foreach (QGraphicsItem *item, scene()->items()) {