From 9e1a368061b654ffb9c38117fe083ba3627428db Mon Sep 17 00:00:00 2001 From: electron128 Date: Thu, 4 Jun 2015 13:36:34 +0000 Subject: [PATCH] added search and highlighting to network graph (patch from Chozabu) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8368 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/NetworkView.cpp | 5 ++ retroshare-gui/src/gui/NetworkView.h | 1 + retroshare-gui/src/gui/NetworkView.ui | 47 +++++++++++++------ .../src/gui/elastic/graphwidget.cpp | 27 +++++++++++ retroshare-gui/src/gui/elastic/graphwidget.h | 1 + retroshare-gui/src/gui/elastic/node.cpp | 5 +- retroshare-gui/src/gui/elastic/node.h | 10 +++- 7 files changed, 78 insertions(+), 18 deletions(-) diff --git a/retroshare-gui/src/gui/NetworkView.cpp b/retroshare-gui/src/gui/NetworkView.cpp index 70a5d6579..ea095a39e 100644 --- a/retroshare-gui/src/gui/NetworkView.cpp +++ b/retroshare-gui/src/gui/NetworkView.cpp @@ -58,6 +58,7 @@ NetworkView::NetworkView(QWidget *parent) connect( ui.maxFriendLevelSB, SIGNAL(valueChanged(int)), this, SLOT(setMaxFriendLevel(int))); connect( ui.edgeLengthSB, SIGNAL(valueChanged(int)), this, SLOT(setEdgeLength(int))); connect( ui.freezeCheckBox, SIGNAL(toggled(bool)), this, SLOT(setFreezeState(bool))); + connect( ui.nameBox, SIGNAL(textChanged(QString)), this, SLOT(setNameSearch(QString))); _should_update = true ; } @@ -72,6 +73,10 @@ void NetworkView::setEdgeLength(int l) { ui.graphicsView->setEdgeLength(l); } +void NetworkView::setNameSearch(QString s) +{ + ui.graphicsView->setNameSearch(s); +} void NetworkView::setMaxFriendLevel(int m) { ui.graphicsView->snapshotNodesPositions() ; diff --git a/retroshare-gui/src/gui/NetworkView.h b/retroshare-gui/src/gui/NetworkView.h index aec295898..6ac5f8a5f 100644 --- a/retroshare-gui/src/gui/NetworkView.h +++ b/retroshare-gui/src/gui/NetworkView.h @@ -47,6 +47,7 @@ class NetworkView : public RsAutoUpdatePage void setMaxFriendLevel(int) ; void setEdgeLength(int) ; + void setNameSearch(QString) ; void changedFoFCheckBox( ); void redraw(); diff --git a/retroshare-gui/src/gui/NetworkView.ui b/retroshare-gui/src/gui/NetworkView.ui index 8805ddc44..c62e05881 100644 --- a/retroshare-gui/src/gui/NetworkView.ui +++ b/retroshare-gui/src/gui/NetworkView.ui @@ -11,15 +11,24 @@ + + 0 + + + 0 + + + 0 + + + 0 + 6 2 - - 0 - @@ -31,14 +40,21 @@ 6 - - + + - Redraw + Edge length: - + + + + Freeze + + + + Qt::Horizontal @@ -84,17 +100,20 @@ - - + + - Edge length: + Redraw - - - - Freeze + + + + + 100 + 0 + diff --git a/retroshare-gui/src/gui/elastic/graphwidget.cpp b/retroshare-gui/src/gui/elastic/graphwidget.cpp index a24a0d445..a8dffb0bc 100644 --- a/retroshare-gui/src/gui/elastic/graphwidget.cpp +++ b/retroshare-gui/src/gui/elastic/graphwidget.cpp @@ -388,6 +388,33 @@ void GraphWidget::setEdgeLength(uint32_t l) } } + +void GraphWidget::setNameSearch(QString s) +{ + if (s.length() == 0){ + for(uint32_t i=0;i<_nodes.size();++i) + _nodes[i]->setNodeDrawSize(20); + forceRedraw(); + return; + } + std::string qs = s.toLower().toStdString(); + for(uint32_t i=0;i<_nodes.size();++i){ + Node* ni = _nodes[i]; + //std::cout << ni->descString() << std::endl; + std::string ns = QString::fromStdString(ni->descString()).toLower().toStdString(); + + if (ns.find(qs) != std::string::npos) { + std::cout << "found!" << '\n'; + ni->setNodeDrawSize(22); + //std::cout << ni->getNodeDrawSize() << '\n'; + } else { + ni->setNodeDrawSize(12); + + } + } + forceRedraw(); +} + void GraphWidget::forceRedraw() { for(uint32_t i=0;i<_nodes.size();++i) diff --git a/retroshare-gui/src/gui/elastic/graphwidget.h b/retroshare-gui/src/gui/elastic/graphwidget.h index b9c72c541..7983c5c25 100644 --- a/retroshare-gui/src/gui/elastic/graphwidget.h +++ b/retroshare-gui/src/gui/elastic/graphwidget.h @@ -86,6 +86,7 @@ public: virtual void itemMoved(); void setEdgeLength(uint32_t l) ; + void setNameSearch(QString) ; uint32_t edgeLength() const { return _edge_length ; } void forceRedraw() ; diff --git a/retroshare-gui/src/gui/elastic/node.cpp b/retroshare-gui/src/gui/elastic/node.cpp index aabdab33c..418a54104 100644 --- a/retroshare-gui/src/gui/elastic/node.cpp +++ b/retroshare-gui/src/gui/elastic/node.cpp @@ -78,6 +78,7 @@ Node::Node(const std::string& node_string,GraphWidget::NodeType type,GraphWidget setZValue(1); mDeterminedBB = false ; mBBWidth = 0 ; + mNodeDrawSize = 20; _speedx=_speedy=0; _steps=0; @@ -284,7 +285,7 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid painter->setPen(Qt::NoPen); painter->setBrush(Qt::darkGray); - painter->drawEllipse(-7, -7, 20, 20); + painter->drawEllipse(-7, -7, mNodeDrawSize, mNodeDrawSize); QRadialGradient gradient(-3, -3, 10); if (option->state & QStyle::State_Sunken) @@ -311,7 +312,7 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid } painter->setBrush(gradient); painter->setPen(QPen(Qt::black, 0)); - painter->drawEllipse(-10, -10, 20, 20); + painter->drawEllipse(-10, -10, mNodeDrawSize, mNodeDrawSize); painter->drawText(-10, 0, QString::fromUtf8(_desc_string.c_str())); if (!mDeterminedBB) diff --git a/retroshare-gui/src/gui/elastic/node.h b/retroshare-gui/src/gui/elastic/node.h index c8d89565c..d7bcd5ff6 100644 --- a/retroshare-gui/src/gui/elastic/node.h +++ b/retroshare-gui/src/gui/elastic/node.h @@ -72,14 +72,19 @@ public: void addEdge(Edge *edge); const QList& edges() const; - int type() const { return Type; } - std::string idString() const { return _gpg_id.toStdString() ; } + int type() const { return Type; } + std::string idString() const { return _gpg_id.toStdString() ; } + std::string descString() const { return _desc_string ; } void calculateForces(const double *data,int width,int height,int W,int H,float x,float y,float speedf); bool advance(); QRectF boundingRect() const; QPainterPath shape() const; + + void setNodeDrawSize(int nds){mNodeDrawSize = nds;} + int getNodeDrawSize(){return mNodeDrawSize;} + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); int n_edges() const { return edgeList.size() ; } @@ -106,6 +111,7 @@ private: GraphWidget::AuthType _auth ; bool mDeterminedBB ; int mBBWidth ; + int mNodeDrawSize; static Node *_selected_node ;