NodeModel Class Reference

#include <NodeModel.h> [code]

Inherits QAbstractTableModel.

Inheritance diagram for NodeModel:

Inheritance graph
[legend]
Collaboration diagram for NodeModel:

Collaboration graph
[legend]
List of all members.

Detailed Description

This class encapsulates the data to be presented to the user regarding network nodes.

For building our GUI we are heavily using the Qt's Model/View Framework. It enables us to program the data representation and the way it is displayed to the user (almost) completely independantly.

Our NodeModel represents a list of nodes for each of which a nuber of properties are stored. This model can be visualized by any of the standard Qt view classes (QTableView, QTreeView).

Definition at line 48 of file NodeModel.h.

Public Types

enum  Status {
  Connecting,
  Handshaking,
  Connected,
  Disconnecting,
  Disconnected
}
 Status of a node. More...
enum  Type {
  Undetermined,
  Peer,
  Ultrapeer,
  Leaf
}
 Type of a node. More...

Public Slots

void nodeConnecting (Connection *, NodeAddress)
 Adds a new node to the list.
void setHandshaking (Connection *)
void setConnected (Connection *, NodeInfo)
void setDisconnected (QObject *)

Public Member Functions

 NodeModel ()
 Constructor.
 ~NodeModel ()
int rowCount (const QModelIndex &parent=QModelIndex()) const
int columnCount (const QModelIndex &parent=QModelIndex()) const
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const

Private Types

typedef QList< NodeData * > NodeInfos
enum  Constants {
  ModelRefreshInterval = 1000,
  AddressIndex = 0,
  PortIndex,
  DurationIndex,
  TypeIndex,
  ServentIndex,
  ColumnCount
}
 Some constants. More...

Private Slots

void refreshModel ()
 Refreshes the whole model.

Private Member Functions

bool setNodeStatus (ConnectionId id, Status status)
 Sets the node's status.
bool setNodeType (ConnectionId id, Type type)
 Sets the node's type.
bool setNodeServent (ConnectionId id, const QString &servent)
 Sets the node's servent name/version.
bool setNodePort (ConnectionId id, quint16 port)
 Sets the node's port.
bool nodeDisconnected (ConnectionId id)
 Removes a node from the list.
int nodeIndex (ConnectionId id)
 Returns the row index of the node with id.

Private Attributes

NodeInfos nodeInfos
 The list of node info fields.
QTimer updateTimer
 View update timer.
QSignalMapper mapper

Classes

struct  NodeData
 The struct storing all node info fields. More...


Member Typedef Documentation

typedef QList<NodeData *> NodeModel::NodeInfos [private]
 

Definition at line 139 of file NodeModel.h.


Member Enumeration Documentation

enum NodeModel::Constants [private]
 

Some constants.

Enumerator:
ModelRefreshInterval  How often to refresh the view.

Todo:
move to the view.
AddressIndex  Column index of the address field.
PortIndex  Column index of the port field.
DurationIndex  Column index of the connection duration field.
TypeIndex  Column index of the node type field.
ServentIndex  Column index of the servent name/version field.
ColumnCount  Total column count.

Definition at line 109 of file NodeModel.h.

enum NodeModel::Status
 

Status of a node.

Enumerator:
Connecting  Connecting to the node.
Handshaking  Handhsaking with the node.
Connected  Handshaking succeeded, we are connected with the node.
Disconnecting  We are in the process of closing the connection with the node.
Disconnected  The node is disconnected.

Definition at line 55 of file NodeModel.h.

enum NodeModel::Type
 

Type of a node.

Todo:
Do we really need an enum for the type field? What is when we add support to eDonkey for example? We should extend the Type enum. Why don't we simply make this field a QString and let each protocol provide the strings itself. This way the NodeModel wouldn't have to know the different protocols. The same thoughts would be valid for the Status enum.
Enumerator:
Undetermined  The node type is unknown.
Peer  The node is a Gnutella Peer.
Ultrapeer  The node is a Gnutella Ultrapeer.
Leaf  The node is a Gnutella Leaf.

Definition at line 72 of file NodeModel.h.


Constructor & Destructor Documentation

NodeModel::NodeModel  ) 
 

Constructor.

Definition at line 31 of file NodeModel.cpp.

NodeModel::~NodeModel  ) 
 

Definition at line 42 of file NodeModel.cpp.


Member Function Documentation

int NodeModel::columnCount const QModelIndex &  parent = QModelIndex()  )  const
 

Definition at line 70 of file NodeModel.cpp.

QVariant NodeModel::data const QModelIndex &  index,
int  role = Qt::DisplayRole
const
 

Definition at line 75 of file NodeModel.cpp.

QVariant NodeModel::headerData int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole
const
 

Definition at line 114 of file NodeModel.cpp.

void NodeModel::nodeConnecting Connection ,
NodeAddress 
[slot]
 

Adds a new node to the list.

bool NodeModel::nodeDisconnected ConnectionId  id  )  [private]
 

Removes a node from the list.

Definition at line 178 of file NodeModel.cpp.

int NodeModel::nodeIndex ConnectionId  id  )  [private]
 

Returns the row index of the node with id.

Definition at line 50 of file NodeModel.cpp.

void NodeModel::refreshModel  )  [private, slot]
 

Refreshes the whole model.

Todo:
Move to the view!

Definition at line 60 of file NodeModel.cpp.

int NodeModel::rowCount const QModelIndex &  parent = QModelIndex()  )  const
 

Definition at line 65 of file NodeModel.cpp.

void NodeModel::setConnected Connection ,
NodeInfo 
[slot]
 

void NodeModel::setDisconnected QObject  )  [slot]
 

Definition at line 173 of file NodeModel.cpp.

void NodeModel::setHandshaking Connection  )  [slot]
 

bool NodeModel::setNodePort ConnectionId  id,
quint16  port
[private]
 

Sets the node's port.

Definition at line 239 of file NodeModel.cpp.

bool NodeModel::setNodeServent ConnectionId  id,
const QString &  servent
[private]
 

Sets the node's servent name/version.

Definition at line 228 of file NodeModel.cpp.

bool NodeModel::setNodeStatus ConnectionId  id,
Status  status
[private]
 

Sets the node's status.

Sets the status of the node with id. If the status set is Status::Connected, then NodeInfo::startDateTime for the node is set to the current time and the duration field will show the duration of the established connection.

Todo:
Ensure that the connections are sorted by their lifetime, i.e. not have a connection established half a second after the next in the list (due to different timings in the handshaking).
See also:
NodeInfo::startDateTime

Definition at line 202 of file NodeModel.cpp.

bool NodeModel::setNodeType ConnectionId  id,
Type  type
[private]
 

Sets the node's type.

Definition at line 217 of file NodeModel.cpp.


Member Data Documentation

QSignalMapper NodeModel::mapper [private]
 

Definition at line 145 of file NodeModel.h.

NodeInfos NodeModel::nodeInfos [private]
 

The list of node info fields.

Definition at line 143 of file NodeModel.h.

QTimer NodeModel::updateTimer [private]
 

View update timer.

Todo:
Move to view.

Definition at line 144 of file NodeModel.h.


The documentation for this class was generated from the following files: