From c35a48feb771ec0e90eb62a1fd8784e8ea6eb7e5 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 29 Aug 2009 11:25:06 +0000 Subject: [PATCH] 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 --- retroshare-gui/src/gui/TrustView.cpp | 24 +++++++++++++------ retroshare-gui/src/gui/TrustView.h | 2 ++ .../src/gui/elastic/graphwidget.cpp | 3 ++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/retroshare-gui/src/gui/TrustView.cpp b/retroshare-gui/src/gui/TrustView.cpp index f13ae2f5a..8dbe3cb8d 100644 --- a/retroshare-gui/src/gui/TrustView.cpp +++ b/retroshare-gui/src/gui/TrustView.cpp @@ -35,6 +35,11 @@ TrustView::TrustView() update() ; } +void TrustView::showEvent(QShowEvent *e) +{ + QWidget::showEvent(e) ; + update() ; +} void TrustView::wheelEvent(QWheelEvent *e) { if(e->modifiers() & Qt::ShiftModifier) @@ -98,14 +103,14 @@ void TrustView::updateZoom(int z) // cout << "updated zoom" << endl; } -int TrustView::getRowColId(const string& name) +int TrustView::getRowColId(const string& peerid) { - static map nameToRow ; + static map peeridToRow ; - map::const_iterator itpr(nameToRow.find( name )) ; + map::const_iterator itpr(peeridToRow.find( peerid )) ; int i ; - if(itpr == nameToRow.end()) + if(itpr == peeridToRow.end()) { i = trustTableTW->columnCount() ; // cout << " -> peer not in table. Creating entry # " << i << endl ; @@ -113,7 +118,9 @@ int TrustView::getRowColId(const string& name) trustTableTW->insertColumn(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->setVerticalHeaderItem(i,new QTableWidgetItem(QString(name.c_str()))) ; @@ -131,6 +138,9 @@ void TrustView::update() { // collect info. + if(!isVisible()) + return ; + std::list neighs; if(!rsPeers->getOthersList(neighs)) @@ -150,11 +160,11 @@ void TrustView::update() // cout << "treating neigh = " << details.name << endl ; // cout << " signers = " ; - int i = getRowColId(details.name) ; + int i = getRowColId(details.id) ; for(list::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. int j = getRowColId(*it2) ; diff --git a/retroshare-gui/src/gui/TrustView.h b/retroshare-gui/src/gui/TrustView.h index 9078816fe..bbc5b6077 100644 --- a/retroshare-gui/src/gui/TrustView.h +++ b/retroshare-gui/src/gui/TrustView.h @@ -1,6 +1,7 @@ #include "ui_TrustView.h" class QWheelEvent ; +class QShowEvent ; class TrustView: public QWidget, public Ui::TrustView { @@ -11,6 +12,7 @@ class TrustView: public QWidget, public Ui::TrustView protected: virtual void wheelEvent(QWheelEvent *) ; + virtual void showEvent(QShowEvent *) ; public slots: void update() ; diff --git a/retroshare-gui/src/gui/elastic/graphwidget.cpp b/retroshare-gui/src/gui/elastic/graphwidget.cpp index 066132078..9848fe3b1 100644 --- a/retroshare-gui/src/gui/elastic/graphwidget.cpp +++ b/retroshare-gui/src/gui/elastic/graphwidget.cpp @@ -221,7 +221,8 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) void GraphWidget::timerEvent(QTimerEvent *event) { - Q_UNUSED(event); + if(!isVisible()) + return; QList nodes; foreach (QGraphicsItem *item, scene()->items()) {