Changeset View
Changeset View
Standalone View
Standalone View
src/qt/bantablemodel.cpp
Show All 16 Lines | |||||
#include <QDebug> | #include <QDebug> | ||||
#include <QList> | #include <QList> | ||||
bool BannedNodeLessThan::operator()(const CCombinedBan &left, | bool BannedNodeLessThan::operator()(const CCombinedBan &left, | ||||
const CCombinedBan &right) const { | const CCombinedBan &right) const { | ||||
const CCombinedBan *pLeft = &left; | const CCombinedBan *pLeft = &left; | ||||
const CCombinedBan *pRight = &right; | const CCombinedBan *pRight = &right; | ||||
if (order == Qt::DescendingOrder) std::swap(pLeft, pRight); | if (order == Qt::DescendingOrder) { | ||||
std::swap(pLeft, pRight); | |||||
} | |||||
switch (column) { | switch (column) { | ||||
case BanTableModel::Address: | case BanTableModel::Address: | ||||
return pLeft->subnet.ToString().compare(pRight->subnet.ToString()) < | return pLeft->subnet.ToString().compare(pRight->subnet.ToString()) < | ||||
0; | 0; | ||||
case BanTableModel::Bantime: | case BanTableModel::Bantime: | ||||
return pLeft->banEntry.nBanUntil < pRight->banEntry.nBanUntil; | return pLeft->banEntry.nBanUntil < pRight->banEntry.nBanUntil; | ||||
} | } | ||||
Show All 31 Lines | void refreshBanlist(interfaces::Node &node) { | ||||
std::stable_sort(cachedBanlist.begin(), cachedBanlist.end(), | std::stable_sort(cachedBanlist.begin(), cachedBanlist.end(), | ||||
BannedNodeLessThan(sortColumn, sortOrder)); | BannedNodeLessThan(sortColumn, sortOrder)); | ||||
} | } | ||||
} | } | ||||
int size() const { return cachedBanlist.size(); } | int size() const { return cachedBanlist.size(); } | ||||
CCombinedBan *index(int idx) { | CCombinedBan *index(int idx) { | ||||
if (idx >= 0 && idx < cachedBanlist.size()) return &cachedBanlist[idx]; | if (idx >= 0 && idx < cachedBanlist.size()) { | ||||
return &cachedBanlist[idx]; | |||||
} | |||||
return 0; | return 0; | ||||
} | } | ||||
}; | }; | ||||
BanTableModel::BanTableModel(interfaces::Node &node, ClientModel *parent) | BanTableModel::BanTableModel(interfaces::Node &node, ClientModel *parent) | ||||
: QAbstractTableModel(parent), m_node(node), clientModel(parent) { | : QAbstractTableModel(parent), m_node(node), clientModel(parent) { | ||||
columns << tr("IP/Netmask") << tr("Banned Until"); | columns << tr("IP/Netmask") << tr("Banned Until"); | ||||
Show All 13 Lines | |||||
} | } | ||||
int BanTableModel::columnCount(const QModelIndex &parent) const { | int BanTableModel::columnCount(const QModelIndex &parent) const { | ||||
Q_UNUSED(parent); | Q_UNUSED(parent); | ||||
return columns.length(); | return columns.length(); | ||||
} | } | ||||
QVariant BanTableModel::data(const QModelIndex &index, int role) const { | QVariant BanTableModel::data(const QModelIndex &index, int role) const { | ||||
if (!index.isValid()) return QVariant(); | if (!index.isValid()) { | ||||
return QVariant(); | |||||
} | |||||
CCombinedBan *rec = static_cast<CCombinedBan *>(index.internalPointer()); | CCombinedBan *rec = static_cast<CCombinedBan *>(index.internalPointer()); | ||||
if (role == Qt::DisplayRole) { | if (role == Qt::DisplayRole) { | ||||
switch (index.column()) { | switch (index.column()) { | ||||
case Address: | case Address: | ||||
return QString::fromStdString(rec->subnet.ToString()); | return QString::fromStdString(rec->subnet.ToString()); | ||||
case Bantime: | case Bantime: | ||||
Show All 12 Lines | if (orientation == Qt::Horizontal) { | ||||
if (role == Qt::DisplayRole && section < columns.size()) { | if (role == Qt::DisplayRole && section < columns.size()) { | ||||
return columns[section]; | return columns[section]; | ||||
} | } | ||||
} | } | ||||
return QVariant(); | return QVariant(); | ||||
} | } | ||||
Qt::ItemFlags BanTableModel::flags(const QModelIndex &index) const { | Qt::ItemFlags BanTableModel::flags(const QModelIndex &index) const { | ||||
if (!index.isValid()) return 0; | if (!index.isValid()) { | ||||
return 0; | |||||
} | |||||
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled; | Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled; | ||||
return retval; | return retval; | ||||
} | } | ||||
QModelIndex BanTableModel::index(int row, int column, | QModelIndex BanTableModel::index(int row, int column, | ||||
const QModelIndex &parent) const { | const QModelIndex &parent) const { | ||||
Q_UNUSED(parent); | Q_UNUSED(parent); | ||||
CCombinedBan *data = priv->index(row); | CCombinedBan *data = priv->index(row); | ||||
if (data) return createIndex(row, column, data); | if (data) { | ||||
return createIndex(row, column, data); | |||||
} | |||||
return QModelIndex(); | return QModelIndex(); | ||||
} | } | ||||
void BanTableModel::refresh() { | void BanTableModel::refresh() { | ||||
Q_EMIT layoutAboutToBeChanged(); | Q_EMIT layoutAboutToBeChanged(); | ||||
priv->refreshBanlist(m_node); | priv->refreshBanlist(m_node); | ||||
Q_EMIT layoutChanged(); | Q_EMIT layoutChanged(); | ||||
} | } | ||||
Show All 10 Lines |