| 60 | } |
| 61 | |
| 62 | QVariant PeerTableModel::data(const QModelIndex& index, int role) const |
| 63 | { |
| 64 | if(!index.isValid()) |
| 65 | return QVariant(); |
| 66 | |
| 67 | CNodeCombinedStats *rec = static_cast<CNodeCombinedStats*>(index.internalPointer()); |
| 68 | |
| 69 | const auto column = static_cast<ColumnIndex>(index.column()); |
| 70 | if (role == Qt::DisplayRole) { |
| 71 | switch (column) { |
| 72 | case NetNodeId: |
| 73 | return (qint64)rec->nodeStats.nodeid; |
| 74 | case Address: |
| 75 | return QString::fromStdString(rec->nodeStats.m_addr_name); |
| 76 | case Direction: |
| 77 | return QString(rec->nodeStats.fInbound ? |
| 78 | //: An Inbound Connection from a Peer. |
| 79 | tr("Inbound") : |
| 80 | //: An Outbound Connection to a Peer. |
| 81 | tr("Outbound")); |
| 82 | case ConnectionType: |
| 83 | return GUIUtil::ConnectionTypeToQString(rec->nodeStats.m_conn_type, /* prepend_direction */ false); |
| 84 | case Network: |
| 85 | return GUIUtil::NetworkToQString(rec->nodeStats.m_network); |
| 86 | case Ping: |
| 87 | return GUIUtil::formatPingTime(rec->nodeStats.m_min_ping_time); |
| 88 | case Sent: |
| 89 | return GUIUtil::formatBytes(rec->nodeStats.nSendBytes); |
| 90 | case Received: |
| 91 | return GUIUtil::formatBytes(rec->nodeStats.nRecvBytes); |
| 92 | case Subversion: |
| 93 | return QString::fromStdString(rec->nodeStats.cleanSubVer); |
| 94 | } // no default case, so the compiler can warn about missing cases |
| 95 | assert(false); |
| 96 | } else if (role == Qt::TextAlignmentRole) { |
| 97 | switch (column) { |
| 98 | case NetNodeId: |
| 99 | return QVariant(Qt::AlignRight | Qt::AlignVCenter); |
| 100 | case Address: |
| 101 | return {}; |
| 102 | case Direction: |
| 103 | case ConnectionType: |
| 104 | case Network: |
| 105 | return QVariant(Qt::AlignCenter); |
| 106 | case Ping: |
| 107 | case Sent: |
| 108 | case Received: |
| 109 | return QVariant(Qt::AlignRight | Qt::AlignVCenter); |
| 110 | case Subversion: |
| 111 | return {}; |
| 112 | } // no default case, so the compiler can warn about missing cases |
| 113 | assert(false); |
| 114 | } else if (role == StatsRole) { |
| 115 | return QVariant::fromValue(rec); |
| 116 | } |
| 117 | |
| 118 | return QVariant(); |
| 119 | } |
nothing calls this directly
no test coverage detected