Monitor
|
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (qt-info@nokia.com) 00006 ** 00007 ** This file is part of the examples of the Qt Toolkit. 00008 ** 00009 ** $QT_BEGIN_LICENSE:BSD$ 00010 ** You may use this file under the terms of the BSD license as follows: 00011 ** 00012 ** "Redistribution and use in source and binary forms, with or without 00013 ** modification, are permitted provided that the following conditions are 00014 ** met: 00015 ** * Redistributions of source code must retain the above copyright 00016 ** notice, this list of conditions and the following disclaimer. 00017 ** * Redistributions in binary form must reproduce the above copyright 00018 ** notice, this list of conditions and the following disclaimer in 00019 ** the documentation and/or other materials provided with the 00020 ** distribution. 00021 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor 00022 ** the names of its contributors may be used to endorse or promote 00023 ** products derived from this software without specific prior written 00024 ** permission. 00025 ** 00026 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00027 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00028 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00029 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00030 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00031 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00032 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00033 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00034 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00035 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00036 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 00037 ** $QT_END_LICENSE$ 00038 ** 00039 ****************************************************************************/ 00040 00041 #ifndef GRAPHWIDGET_H 00042 #define GRAPHWIDGET_H 00043 00044 #include <QtGui/QGraphicsView> 00045 #include <QList> 00046 #include <QLabel> 00047 #include <vector> 00048 00049 #include "stub/my-commmodel.h" 00050 #include "mainwindow.h" 00051 #include "point.h" 00052 00053 #define CIRCLE_RADIUS 200 00054 #define PI 3.14159265 00055 00063 std::vector<Point*> *getNPointsOnCircle(Point *center, int radius, int numNodes); 00064 00065 class Node; 00066 class MainWindow; 00067 00071 class GraphWidget : public QGraphicsView 00072 { 00073 Q_OBJECT 00074 00075 public: 00076 GraphWidget(QWidget *parent = 0, CommModel *comm = 0); 00077 void itemMoved(); 00078 void updateGraph(std::vector<node *> _nodes); 00079 void setSelectedIP(uint32_t newIP); 00080 uint32_t getSelectedIP(); 00081 00082 void setSourceMac(mac_t newMac); 00083 mac_t getSourceMac(); 00084 00085 void setDestinationMac(mac_t newMac); 00086 mac_t getDestinationMac(); 00087 00088 QList<Node *> allNodes; 00089 void updateNodesAndEdges(); 00090 MainWindow * getMainWindow(); 00091 void setMainWindow(MainWindow * _mainWindow); 00092 bool sameMacAddr(node* n1, node* n2); 00093 void plotNodes (); 00094 00095 void setDoPhysics(bool val); 00096 bool getDoPhysics(); 00097 void highlightPath(std::vector<node*> path); 00098 00099 protected: 00100 void timerEvent(QTimerEvent *event); 00101 void drawBackground(QPainter *painter, const QRectF &rect); 00102 bool checkIp(uint32_t ip_addr); 00103 bool checkMac(node* nx); 00104 Node * getNode(node * n); 00105 bool hasEdge(Node * n, node * nb); 00106 00107 // circle plotting code 00108 bool _doPhysics; 00110 private: 00111 int timerId; 00112 Node *centerNode; 00113 uint32_t selectedIP; 00114 mac_t sourceMac; 00115 mac_t destMac; 00116 //QList<Node *> allNodes; 00117 CommModel *comm; 00118 QGraphicsScene * scenex; 00119 MainWindow * mainWindow; 00120 bool sourceSet; 00121 bool destSet; 00122 }; 00123 00124 #endif