Allow to clear, insert, and push values of the model.

This commit is contained in:
Klaus Basan
2014-02-05 21:23:54 +00:00
committed by Mathew Sutcliffe
parent f476388f8b
commit 576952b690
2 changed files with 43 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "listmodelbase.h"
#include "blackmisc/statusmessagelist.h"
#include "blackmisc/avatcstationlist.h"
#include "blackmisc/avaircraftlist.h"
#include "blackmisc/nwserverlist.h"
@@ -103,6 +104,39 @@ namespace BlackGui
return this->m_list.size();
}
/*
* Push back
*/
template <typename ObjectType, typename ListType>
void CListModelBase<ObjectType, ListType>::push_back(const ObjectType &object)
{
beginInsertRows(QModelIndex(), this->m_list.size(), this->m_list.size());
this->m_list.push_back(object);
endInsertRows();
}
/*
* Push back
*/
template <typename ObjectType, typename ListType>
void CListModelBase<ObjectType, ListType>::insert(const ObjectType &object)
{
beginInsertRows(QModelIndex(), 0, 0);
this->m_list.insert(this->m_list.begin(), object);
endInsertRows();
}
/*
* Clear
*/
template <typename ObjectType, typename ListType>
void CListModelBase<ObjectType, ListType>::clear()
{
beginResetModel();
this->m_list.clear();
endResetModel();
}
/*
* Sort
*/
@@ -145,6 +179,7 @@ namespace BlackGui
// see here for the reason of thess forward instantiations
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
template class CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
template class CListModelBase<BlackMisc::Aviation::CAtcStation, BlackMisc::Aviation::CAtcStationList>;
template class CListModelBase<BlackMisc::Aviation::CAircraft, BlackMisc::Aviation::CAircraftList>;
template class CListModelBase<BlackMisc::Network::CServer, BlackMisc::Network::CServerList>;

View File

@@ -155,6 +155,14 @@ namespace BlackGui
*/
virtual void sort(int column, Qt::SortOrder order);
//! \brief Similar to ListType::push_back
virtual void push_back(const ObjectType &object);
//! \brief Similar to ListType::insert here inserts at first position
virtual void insert(const ObjectType &object);
//! \brief clear the list
virtual void clear();
};
}
#endif // guard