mirror of
https://github.com/tnodir/fort
synced 2024-11-15 06:15:15 +00:00
UI: ConnBlockListModel: Simplify updateConnIdRange()
This commit is contained in:
parent
e298544769
commit
05b8670e50
@ -70,7 +70,9 @@ int ConnBlockListModel::columnCount(const QModelIndex &parent) const
|
||||
|
||||
QVariant ConnBlockListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && (role == Qt::DisplayRole || role == Qt::ToolTipRole)) {
|
||||
const bool isDisplayRole = (role == Qt::DisplayRole || role == Qt::ToolTipRole);
|
||||
|
||||
if (orientation == Qt::Horizontal && isDisplayRole) {
|
||||
return headerDataDisplay(section, role);
|
||||
}
|
||||
return QVariant();
|
||||
@ -254,28 +256,7 @@ void ConnBlockListModel::updateConnIdRange()
|
||||
if (idMin == oldIdMin && idMax == oldIdMax)
|
||||
return;
|
||||
|
||||
if (idMin < oldIdMin || idMin >= oldIdMax || idMax < oldIdMax || oldIdMax == 0) {
|
||||
m_connIdMin = idMin, m_connIdMax = idMax;
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (idMin > oldIdMin) {
|
||||
const int removedCount = idMin - oldIdMin;
|
||||
beginRemoveRows({}, 0, removedCount - 1);
|
||||
m_connIdMin = idMin;
|
||||
invalidateRowCache();
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
if (idMax > oldIdMax) {
|
||||
const int addedCount = idMax - oldIdMax;
|
||||
const int endRow = oldIdMax - idMin + 1;
|
||||
beginInsertRows({}, endRow, endRow + addedCount - 1);
|
||||
m_connIdMax = idMax;
|
||||
invalidateRowCache();
|
||||
endInsertRows();
|
||||
}
|
||||
updateConnRows(oldIdMin, oldIdMax, idMin, idMax);
|
||||
}
|
||||
|
||||
bool ConnBlockListModel::updateTableRow(int row) const
|
||||
@ -363,3 +344,49 @@ QString ConnBlockListModel::formatIpPort(const ip_addr_t &ip, quint16 port, bool
|
||||
}
|
||||
return address + ':' + QString::number(port);
|
||||
}
|
||||
|
||||
void ConnBlockListModel::updateConnRows(
|
||||
qint64 oldIdMin, qint64 oldIdMax, qint64 idMin, qint64 idMax)
|
||||
{
|
||||
const bool isIdMinOut = (idMin < oldIdMin || idMin >= oldIdMax);
|
||||
const bool isIdMaxOut = (idMax < oldIdMax || oldIdMax == 0);
|
||||
|
||||
if (isIdMinOut || isIdMaxOut) {
|
||||
resetConnRows(idMin, idMax);
|
||||
return;
|
||||
}
|
||||
|
||||
const int removedCount = idMin - oldIdMin;
|
||||
if (removedCount > 0) {
|
||||
removeConnRows(idMin, removedCount);
|
||||
}
|
||||
|
||||
const int addedCount = idMax - oldIdMax;
|
||||
if (addedCount > 0) {
|
||||
const int endRow = oldIdMax - idMin + 1;
|
||||
insertConnRows(idMin, endRow, addedCount);
|
||||
}
|
||||
}
|
||||
|
||||
void ConnBlockListModel::resetConnRows(qint64 idMin, qint64 idMax)
|
||||
{
|
||||
m_connIdMin = idMin;
|
||||
m_connIdMax = idMax;
|
||||
reset();
|
||||
}
|
||||
|
||||
void ConnBlockListModel::removeConnRows(qint64 idMin, int count)
|
||||
{
|
||||
beginRemoveRows({}, 0, count - 1);
|
||||
m_connIdMin = idMin;
|
||||
invalidateRowCache();
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void ConnBlockListModel::insertConnRows(qint64 idMax, int endRow, int count)
|
||||
{
|
||||
beginInsertRows({}, endRow, endRow + count - 1);
|
||||
m_connIdMax = idMax;
|
||||
invalidateRowCache();
|
||||
endInsertRows();
|
||||
}
|
||||
|
@ -93,6 +93,11 @@ private:
|
||||
|
||||
QString formatIpPort(const ip_addr_t &ip, quint16 port, bool isIPv6) const;
|
||||
|
||||
void updateConnRows(qint64 oldIdMin, qint64 oldIdMax, qint64 idMin, qint64 idMax);
|
||||
void resetConnRows(qint64 idMin, qint64 idMax);
|
||||
void removeConnRows(qint64 idMin, int count);
|
||||
void insertConnRows(qint64 idMax, int endRow, int count);
|
||||
|
||||
private:
|
||||
uint m_resolveAddress : 1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user