View/Model support push_back

This commit is contained in:
Klaus Basan
2018-05-11 23:48:59 +02:00
parent 6addfb5fd8
commit 4c2aaf73e1
4 changed files with 68 additions and 1 deletions

View File

@@ -509,7 +509,31 @@ namespace BlackGui
beginInsertRows(QModelIndex(), m_container.size(), m_container.size()); beginInsertRows(QModelIndex(), m_container.size(), m_container.size());
m_container.push_back(object); m_container.push_back(object);
endInsertRows(); endInsertRows();
if (this->hasFilter())
{
// this will change the whole used model as we cannot predict the filter
this->beginResetModel();
this->updateFilteredContainer(); this->updateFilteredContainer();
this->endResetModel();
}
this->emitModelDataChanged();
}
template<typename ObjectType, typename ContainerType, bool UseCompare>
void CListModelBase<ObjectType, ContainerType, UseCompare>::push_back(const ContainerType &container)
{
beginInsertRows(QModelIndex(), m_container.size(), m_container.size());
m_container.push_back(container);
endInsertRows();
if (this->hasFilter())
{
// this will change the whole used model as we cannot predict the filter
this->beginResetModel();
this->updateFilteredContainer();
this->endResetModel();
}
this->emitModelDataChanged(); this->emitModelDataChanged();
} }
@@ -522,6 +546,7 @@ namespace BlackGui
if (this->hasFilter()) if (this->hasFilter())
{ {
// this will change the whole used model as we cannot predict the filter
this->beginResetModel(); this->beginResetModel();
this->updateFilteredContainer(); this->updateFilteredContainer();
this->endResetModel(); this->endResetModel();
@@ -539,6 +564,7 @@ namespace BlackGui
if (this->hasFilter()) if (this->hasFilter())
{ {
// this will change the whole used model as we cannot predict the filter
this->beginResetModel(); this->beginResetModel();
this->updateFilteredContainer(); this->updateFilteredContainer();
this->endResetModel(); this->endResetModel();

View File

@@ -255,6 +255,9 @@ namespace BlackGui
//! Similar to ContainerType::push_back //! Similar to ContainerType::push_back
virtual void push_back(const ObjectType &object); virtual void push_back(const ObjectType &object);
//! Similar to ContainerType::push_back
virtual void push_back(const ContainerType &container);
//! Similar to ContainerType::insert here inserts at first position //! Similar to ContainerType::insert here inserts at first position
virtual void insert(const ObjectType &object); virtual void insert(const ObjectType &object);

View File

@@ -972,6 +972,38 @@ namespace BlackGui
} }
} }
template <class ModelClass, class ContainerType, class ObjectType>
void CViewBase<ModelClass, ContainerType, ObjectType>::push_back(const ObjectType &value, bool resize)
{
Q_ASSERT(m_model);
if (this->rowCount() < 1)
{
// this allows presizing
this->updateContainerMaybeAsync(ContainerType({value}), true, resize);
}
else
{
m_model->push_back(value);
if (resize) { this->performModeBasedResizeToContent(); }
}
}
template <class ModelClass, class ContainerType, class ObjectType>
void CViewBase<ModelClass, ContainerType, ObjectType>::push_back(const ContainerType &container, bool resize)
{
Q_ASSERT(m_model);
if (this->rowCount() < 1)
{
// this allows presizing
this->updateContainerMaybeAsync(container, true, resize);
}
else
{
m_model->push_back(container);
if (resize) { this->performModeBasedResizeToContent(); }
}
}
template <class ModelClass, class ContainerType, class ObjectType> template <class ModelClass, class ContainerType, class ObjectType>
const ObjectType &CViewBase<ModelClass, ContainerType, ObjectType>::at(const QModelIndex &index) const const ObjectType &CViewBase<ModelClass, ContainerType, ObjectType>::at(const QModelIndex &index) const
{ {

View File

@@ -580,6 +580,12 @@ namespace BlackGui
//! Insert //! Insert
void insert(const ContainerType &container, bool resize = true); void insert(const ContainerType &container, bool resize = true);
//! Push back
void push_back(const ObjectType &value, bool resize = true);
//! Push back
void push_back(const ContainerType &container, bool resize = true);
//! Value object at //! Value object at
const ObjectType &at(const QModelIndex &index) const; const ObjectType &at(const QModelIndex &index) const;