Display number of table rows in tab

* countChanged event
* applied in components
This commit is contained in:
Klaus Basan
2014-09-25 23:37:15 +02:00
parent 84b5cee7d8
commit ae0ef4283c
12 changed files with 119 additions and 23 deletions

View File

@@ -92,21 +92,15 @@ namespace BlackGui
if (station.getCallsign().isEmpty()) return;
if (added)
{
if (this->m_container.contains(&CAtcStation::getCallsign, station.getCallsign()))
{
this->m_container.replaceIf(&CAtcStation::getCallsign, station.getCallsign(), station);
}
else
{
this->insert(station);
}
bool c = this->m_container.contains(&CAtcStation::getCallsign, station.getCallsign());
if (!c) { this->insert(station); }
}
else
{
beginRemoveRows(QModelIndex(), 0, 0);
this->m_container.removeIf(&CAtcStation::getCallsign, station.getCallsign());
this->removeIf(&CAtcStation::getCallsign, station.getCallsign());
endRemoveRows();
}
}
}
}
} // namespace
} // namespace

View File

@@ -127,27 +127,22 @@ namespace BlackGui
template <typename ObjectType, typename ContainerType>
int CListModelBase<ObjectType, ContainerType>::update(const ContainerType &container, bool sort)
{
// KWB remove: qDebug() will be removed soon
qDebug() << "update" << this->objectName() << "size" << container.size() << "thread:" << QThread::currentThreadId();
QTime myTimer;
// Keep sorting out of begin/end reset model
ContainerType sortedContainer;
int oldSize = this->m_container.size();
bool performSort = sort && container.size() > 1 && this->hasValidSortColumn();
if (performSort)
{
myTimer.start();
sortedContainer = this->sortContainerByColumn(container, this->getSortColumn(), this->m_sortOrder);
qDebug() << this->objectName() << "Sort performed ms:" << myTimer.restart() << "thread:" << QThread::currentThreadId();
}
this->beginResetModel();
this->m_container = performSort ? sortedContainer : container;
this->endResetModel();
// TODO: KWB remove
qDebug() << this->objectName() << "Reset performed ms:" << myTimer.restart() << "objects:" << this->m_container.size() << "thread:" << QThread::currentThreadId();
return this->m_container.size();
int newSize = this->m_container.size();
if (oldSize != newSize) { rowCountChanged(newSize); }
return newSize;
}
/*
@@ -223,6 +218,7 @@ namespace BlackGui
beginInsertRows(QModelIndex(), this->m_container.size(), this->m_container.size());
this->m_container.push_back(object);
endInsertRows();
emit rowCountChanged(this->m_container.size());
}
/*
@@ -234,6 +230,8 @@ namespace BlackGui
beginInsertRows(QModelIndex(), 0, 0);
this->m_container.insert(this->m_container.begin(), object);
endInsertRows();
int newSize = this->m_container.size();
emit rowCountChanged(newSize);
}
/*
@@ -242,9 +240,12 @@ namespace BlackGui
template <typename ObjectType, typename ContainerType>
void CListModelBase<ObjectType, ContainerType>::remove(const ObjectType &object)
{
int oldSize = this->m_container.size();
beginRemoveRows(QModelIndex(), 0, 0);
this->m_container.remove(object);
endRemoveRows();
int newSize = this->m_container.size();
if (oldSize != newSize) { emit rowCountChanged(newSize); }
}
/*
@@ -252,9 +253,11 @@ namespace BlackGui
*/
template <typename ObjectType, typename ContainerType> void CListModelBase<ObjectType, ContainerType>::clear()
{
int oldSize = this->m_container.size();
beginResetModel();
this->m_container.clear();
endResetModel();
if (oldSize > 0) { emit rowCountChanged(0);}
}
/*

View File

@@ -83,6 +83,9 @@ namespace BlackGui
//! Asynchronous update finished
void asyncUpdateFinished();
//! Number of elements changed
void rowCountChanged(int count);
protected slots:
//! Helper method with template free signature
//! \param variant container is transferred in variant
@@ -113,7 +116,6 @@ namespace BlackGui
Qt::SortOrder m_sortOrder; //!< sort order (asc/desc)
};
/*!
* List model
*/
@@ -182,6 +184,15 @@ namespace BlackGui
//! Remove object
virtual void remove(const ObjectType &object);
//! \copydoc ContainerBase::removeIf
template <class K0, class V0, class... KeysValues>
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
{
int c = m_container.removeIf(BlackMisc::Predicates::MemberEqual(k0, v0, keysValues...));
if (c > 0) { emit rowCountChanged(this->rowCount());}
return c;
}
//! Clear the list
virtual void clear();