mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
CListModelBase and CViewBase: reduce the number of template parameters
by relying on what can easily be deduced from the first parameter(s).
This commit is contained in:
@@ -23,7 +23,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Airport list model
|
||||
class BLACKGUI_EXPORT CAircraftIcaoCodeListModel :
|
||||
public CListModelDbObjects<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList, int, true>
|
||||
public CListModelDbObjects<BlackMisc::Aviation::CAircraftIcaoCodeList, int, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Aircraft model list model
|
||||
class BLACKGUI_EXPORT CAircraftModelListModel :
|
||||
public COrderableListModelDbObjects<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList, int, true>
|
||||
public COrderableListModelDbObjects<BlackMisc::Simulation::CAircraftModelList, int, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
CAircraftPartsListModel::CAircraftPartsListModel(QObject *parent) :
|
||||
CListModelTimestampWithOffsetObjects<CAircraftParts, CAircraftPartsList, true>("ViewAircraftPartsList", parent)
|
||||
CListModelTimestampWithOffsetObjects<CAircraftPartsList, true>("ViewAircraftPartsList", parent)
|
||||
{
|
||||
this->addTimestampOffsetColumns();
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Aircraft parts list model
|
||||
class BLACKGUI_EXPORT CAircraftPartsListModel : public CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList, true>
|
||||
class BLACKGUI_EXPORT CAircraftPartsListModel : public CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftPartsList, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
CAircraftSituationChangeListModel::CAircraftSituationChangeListModel(QObject *parent) :
|
||||
CListModelTimestampWithOffsetObjects<CAircraftSituationChange, CAircraftSituationChangeList, true>("ViewAircraftPartsList", parent)
|
||||
CListModelTimestampWithOffsetObjects<CAircraftSituationChangeList, true>("ViewAircraftPartsList", parent)
|
||||
{
|
||||
this->addTimestampOffsetColumns();
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Aircraft situation changes list model
|
||||
class BLACKGUI_EXPORT CAircraftSituationChangeListModel : public CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftSituationChange, BlackMisc::Aviation::CAircraftSituationChangeList, true>
|
||||
class BLACKGUI_EXPORT CAircraftSituationChangeListModel : public CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftSituationChangeList, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
CAircraftSituationListModel::CAircraftSituationListModel(QObject *parent) :
|
||||
CListModelTimestampWithOffsetObjects<CAircraftSituation, CAircraftSituationList, true>("ViewAircraftPartsList", parent)
|
||||
CListModelTimestampWithOffsetObjects<CAircraftSituationList, true>("ViewAircraftPartsList", parent)
|
||||
{
|
||||
this->addTimestampOffsetColumns();
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Client list model
|
||||
class BLACKGUI_EXPORT CAircraftSituationListModel : public CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList, true>
|
||||
class BLACKGUI_EXPORT CAircraftSituationListModel : public CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftSituationList, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Airport list model
|
||||
class BLACKGUI_EXPORT CAirlineIcaoCodeListModel :
|
||||
public CListModelDbObjects<BlackMisc::Aviation::CAirlineIcaoCode, BlackMisc::Aviation::CAirlineIcaoCodeList, int, true>
|
||||
public CListModelDbObjects<BlackMisc::Aviation::CAirlineIcaoCodeList, int, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Airport list model
|
||||
class BLACKGUI_EXPORT CAirportListModel :
|
||||
public CListModelBase<BlackMisc::Aviation::CAirport, BlackMisc::Aviation::CAirportList, true>
|
||||
public CListModelBase<BlackMisc::Aviation::CAirportList, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Application info list model
|
||||
class BLACKGUI_EXPORT CApplicationInfoListModel : public CListModelBase<BlackMisc::CApplicationInfo, BlackMisc::CApplicationInfoList, true>
|
||||
class BLACKGUI_EXPORT CApplicationInfoListModel : public CListModelBase<BlackMisc::CApplicationInfoList, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace BlackGui
|
||||
class CAtcStationTreeModel;
|
||||
|
||||
//! ATC list model
|
||||
class BLACKGUI_EXPORT CAtcStationListModel : public CListModelCallsignObjects<BlackMisc::Aviation::CAtcStation, BlackMisc::Aviation::CAtcStationList, true>
|
||||
class BLACKGUI_EXPORT CAtcStationListModel : public CListModelCallsignObjects<BlackMisc::Aviation::CAtcStationList, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
CClientListModel::CClientListModel(QObject *parent) :
|
||||
CListModelBase<CClient, CClientList>("ViewClientList", parent)
|
||||
CListModelBase<CClientList>("ViewClientList", parent)
|
||||
{
|
||||
m_columns.addColumn(CColumn("client", CClient::IndexIcon));
|
||||
m_columns.addColumn(CColumn::standardValueObject("callsign", CClient::IndexCallsign));
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Client list model
|
||||
class BLACKGUI_EXPORT CClientListModel : public CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>
|
||||
class BLACKGUI_EXPORT CClientListModel : public CListModelBase<BlackMisc::Network::CClientList>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Cloud layer list model
|
||||
class BLACKGUI_EXPORT CCloudLayerListModel :
|
||||
public CListModelBase<BlackMisc::Weather::CCloudLayer, BlackMisc::Weather::CCloudLayerList, false>
|
||||
public CListModelBase<BlackMisc::Weather::CCloudLayerList, false>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Country list model
|
||||
class BLACKGUI_EXPORT CCountryListModel :
|
||||
public CListModelDbObjects<BlackMisc::CCountry, BlackMisc::CCountryList, QString, true>
|
||||
public CListModelDbObjects<BlackMisc::CCountryList, QString, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Distributor list model
|
||||
class BLACKGUI_EXPORT CDistributorListModel :
|
||||
public COrderableListModelDbObjects<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList, QString, true>
|
||||
public COrderableListModelDbObjects<BlackMisc::Simulation::CDistributorList, QString, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Originator list model
|
||||
class BLACKGUI_EXPORT CIdentifierListModel : public CListModelBase<BlackMisc::CIdentifier, BlackMisc::CIdentifierList>
|
||||
class BLACKGUI_EXPORT CIdentifierListModel : public CListModelBase<BlackMisc::CIdentifierList>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Country list model
|
||||
class BLACKGUI_EXPORT CInterpolationSetupListModel :
|
||||
public CListModelCallsignObjects<BlackMisc::Simulation::CInterpolationAndRenderingSetupPerCallsign, BlackMisc::Simulation::CInterpolationSetupList, false>
|
||||
public CListModelCallsignObjects<BlackMisc::Simulation::CInterpolationSetupList, false>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -28,20 +28,20 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
CListModelBase<ObjectType, ContainerType, UseCompare>::CListModelBase(const QString &translationContext, QObject *parent)
|
||||
template <typename T, bool UseCompare>
|
||||
CListModelBase<T, UseCompare>::CListModelBase(const QString &translationContext, QObject *parent)
|
||||
: CListModelBaseNonTemplate(translationContext, parent)
|
||||
{ }
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
int CListModelBase<ObjectType, ContainerType, UseCompare>::rowCount(const QModelIndex &parentIndex) const
|
||||
template <typename T, bool UseCompare>
|
||||
int CListModelBase<T, UseCompare>::rowCount(const QModelIndex &parentIndex) const
|
||||
{
|
||||
Q_UNUSED(parentIndex);
|
||||
return this->containerOrFilteredContainer().size();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
|
||||
template <typename T, bool UseCompare>
|
||||
bool CListModelBase<T, UseCompare>::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
Q_UNUSED(row);
|
||||
@@ -52,8 +52,8 @@ namespace BlackGui
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
||||
template <typename T, bool UseCompare>
|
||||
bool CListModelBase<T, UseCompare>::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
||||
{
|
||||
Q_UNUSED(row);
|
||||
Q_UNUSED(column);
|
||||
@@ -73,16 +73,16 @@ namespace BlackGui
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::isValidIndex(const QModelIndex &index) const
|
||||
template <typename T, bool UseCompare>
|
||||
bool CListModelBase<T, UseCompare>::isValidIndex(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) { return false; }
|
||||
return (index.row() >= 0 && index.row() < this->rowCount(index) &&
|
||||
index.column() >= 0 && index.column() < this->columnCount(index));
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
QVariant CListModelBase<ObjectType, ContainerType, UseCompare>::data(const QModelIndex &index, int role) const
|
||||
template <typename T, bool UseCompare>
|
||||
QVariant CListModelBase<T, UseCompare>::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
// check / init
|
||||
if (!this->isValidIndex(index)) { return QVariant(); }
|
||||
@@ -113,8 +113,8 @@ namespace BlackGui
|
||||
return formatter->data(role, obj.propertyByIndex(propertyIndex)).getQVariant();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
template <typename T, bool UseCompare>
|
||||
bool CListModelBase<T, UseCompare>::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
Qt::ItemDataRole dataRole = static_cast<Qt::ItemDataRole>(role);
|
||||
if (!(dataRole == Qt::UserRole || dataRole == Qt::EditRole)) { return false; }
|
||||
@@ -145,8 +145,8 @@ namespace BlackGui
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::setInContainer(const QModelIndex &index, const ObjectType &obj)
|
||||
template <typename T, bool UseCompare>
|
||||
bool CListModelBase<T, UseCompare>::setInContainer(const QModelIndex &index, const ObjectType &obj)
|
||||
{
|
||||
if (!index.isValid()) { return false; }
|
||||
int row = index.row();
|
||||
@@ -155,8 +155,8 @@ namespace BlackGui
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
int CListModelBase<ObjectType, ContainerType, UseCompare>::update(const ContainerType &container, bool sort)
|
||||
template <typename T, bool UseCompare>
|
||||
int CListModelBase<T, UseCompare>::update(const ContainerType &container, bool sort)
|
||||
{
|
||||
if (m_modelDestroyed) { return 0; }
|
||||
|
||||
@@ -192,8 +192,8 @@ namespace BlackGui
|
||||
return newSize;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::update(const QModelIndex &index, const ObjectType &object)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::update(const QModelIndex &index, const ObjectType &object)
|
||||
{
|
||||
if (m_modelDestroyed) { return; }
|
||||
if (index.row() >= m_container.size()) { return; }
|
||||
@@ -204,14 +204,14 @@ namespace BlackGui
|
||||
emit this->dataChanged(i1, i2); // which range has been changed
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::update(int rowIndex, const ObjectType &object)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::update(int rowIndex, const ObjectType &object)
|
||||
{
|
||||
this->update(this->index(rowIndex, 0), object);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
CWorker *CListModelBase<ObjectType, ContainerType, UseCompare>::updateAsync(const ContainerType &container, bool sort)
|
||||
template <typename T, bool UseCompare>
|
||||
CWorker *CListModelBase<T, UseCompare>::updateAsync(const ContainerType &container, bool sort)
|
||||
{
|
||||
Q_UNUSED(sort);
|
||||
if (m_modelDestroyed) { return nullptr; }
|
||||
@@ -230,8 +230,8 @@ namespace BlackGui
|
||||
return worker;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::updateContainerMaybeAsync(const ContainerType &container, bool sort)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::updateContainerMaybeAsync(const ContainerType &container, bool sort)
|
||||
{
|
||||
if (m_modelDestroyed) { return; }
|
||||
if (container.size() > asyncThreshold && sort)
|
||||
@@ -245,15 +245,15 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::hasFilter() const
|
||||
template <typename T, bool UseCompare>
|
||||
bool CListModelBase<T, UseCompare>::hasFilter() const
|
||||
{
|
||||
const bool f = m_filter && m_filter->isValid();
|
||||
return f;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::removeFilter()
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::removeFilter()
|
||||
{
|
||||
if (!this->hasFilter()) { return; }
|
||||
m_filter.reset(nullptr);
|
||||
@@ -263,8 +263,8 @@ namespace BlackGui
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::takeFilterOwnership(std::unique_ptr<IModelFilter<ContainerType> > &filter)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::takeFilterOwnership(std::unique_ptr<IModelFilter<ContainerType> > &filter)
|
||||
{
|
||||
if (!filter)
|
||||
{
|
||||
@@ -286,8 +286,8 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
const ObjectType &CListModelBase<ObjectType, ContainerType, UseCompare>::at(const QModelIndex &index) const
|
||||
template <typename T, bool UseCompare>
|
||||
const typename CListModelBase<T, UseCompare>::ObjectType &CListModelBase<T, UseCompare>::at(const QModelIndex &index) const
|
||||
{
|
||||
if (index.row() < 0 || index.row() >= this->rowCount())
|
||||
{
|
||||
@@ -300,20 +300,20 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
const ContainerType &CListModelBase<ObjectType, ContainerType, UseCompare>::container() const
|
||||
template <typename T, bool UseCompare>
|
||||
const typename CListModelBase<T, UseCompare>::ContainerType &CListModelBase<T, UseCompare>::container() const
|
||||
{
|
||||
return m_container;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
const ContainerType &CListModelBase<ObjectType, ContainerType, UseCompare>::containerFiltered() const
|
||||
template <typename T, bool UseCompare>
|
||||
const typename CListModelBase<T, UseCompare>::ContainerType &CListModelBase<T, UseCompare>::containerFiltered() const
|
||||
{
|
||||
return m_containerFiltered;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
const ContainerType &CListModelBase<ObjectType, ContainerType, UseCompare>::containerOrFilteredContainer(bool *filtered) const
|
||||
template <typename T, bool UseCompare>
|
||||
const typename CListModelBase<T, UseCompare>::ContainerType &CListModelBase<T, UseCompare>::containerOrFilteredContainer(bool *filtered) const
|
||||
{
|
||||
if (this->hasFilter())
|
||||
{
|
||||
@@ -327,8 +327,8 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::push_back(const ObjectType &object)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::push_back(const ObjectType &object)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), m_container.size(), m_container.size());
|
||||
m_container.push_back(object);
|
||||
@@ -344,8 +344,8 @@ namespace BlackGui
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template<typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::push_back(const ContainerType &container)
|
||||
template<typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::push_back(const ContainerType &container)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), m_container.size(), m_container.size());
|
||||
m_container.push_back(container);
|
||||
@@ -361,8 +361,8 @@ namespace BlackGui
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::insert(const ObjectType &object)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::insert(const ObjectType &object)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), 0, 0);
|
||||
m_container.insert(m_container.begin(), object);
|
||||
@@ -378,8 +378,8 @@ namespace BlackGui
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::insert(const ContainerType &container)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::insert(const ContainerType &container)
|
||||
{
|
||||
if (container.isEmpty()) { return; }
|
||||
beginInsertRows(QModelIndex(), 0, 0);
|
||||
@@ -396,8 +396,8 @@ namespace BlackGui
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::remove(const ObjectType &object)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::remove(const ObjectType &object)
|
||||
{
|
||||
int oldSize = m_container.size();
|
||||
beginRemoveRows(QModelIndex(), 0, 0);
|
||||
@@ -416,8 +416,8 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::clear()
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::clear()
|
||||
{
|
||||
beginResetModel();
|
||||
m_container.clear();
|
||||
@@ -426,14 +426,14 @@ namespace BlackGui
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::isEmpty() const
|
||||
template <typename T, bool UseCompare>
|
||||
bool CListModelBase<T, UseCompare>::isEmpty() const
|
||||
{
|
||||
return m_container.isEmpty();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::updateFilteredContainer()
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::updateFilteredContainer()
|
||||
{
|
||||
if (this->hasFilter())
|
||||
{
|
||||
@@ -445,16 +445,16 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::emitModelDataChanged()
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::emitModelDataChanged()
|
||||
{
|
||||
const int n = this->containerOrFilteredContainer().size();
|
||||
emit this->modelDataChanged(n, this->hasFilter());
|
||||
emit this->changed();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||
{
|
||||
// underlying base class changed
|
||||
Q_UNUSED(topLeft);
|
||||
@@ -463,30 +463,30 @@ namespace BlackGui
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::onChangedDigest()
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::onChangedDigest()
|
||||
{
|
||||
const int n = this->containerOrFilteredContainer().size();
|
||||
emit this->changedDigest();
|
||||
emit this->modelDataChangedDigest(n, this->hasFilter());
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::moveItems(const ContainerType &items, int position)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::moveItems(const ContainerType &items, int position)
|
||||
{
|
||||
// overridden in specialized class
|
||||
Q_UNUSED(items);
|
||||
Q_UNUSED(position);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::sort()
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::sort()
|
||||
{
|
||||
this->sort(this->getSortColumn(), this->getSortOrder());
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::sort(int column, Qt::SortOrder order)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
if (column == m_sortColumn && order == m_sortOrder) { return; }
|
||||
|
||||
@@ -502,8 +502,8 @@ namespace BlackGui
|
||||
this->updateContainerMaybeAsync(m_container, true);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::truncate(int maxNumber, bool forceSort)
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::truncate(int maxNumber, bool forceSort)
|
||||
{
|
||||
if (this->rowCount() <= maxNumber) { return; }
|
||||
if (forceSort)
|
||||
@@ -515,8 +515,8 @@ namespace BlackGui
|
||||
this->updateContainerMaybeAsync(container, false);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
ContainerType CListModelBase<ObjectType, ContainerType, UseCompare>::sortContainerByColumn(const ContainerType &container, int column, Qt::SortOrder order) const
|
||||
template <typename T, bool UseCompare>
|
||||
typename CListModelBase<T, UseCompare>::ContainerType CListModelBase<T, UseCompare>::sortContainerByColumn(const ContainerType &container, int column, Qt::SortOrder order) const
|
||||
{
|
||||
if (m_modelDestroyed) { return container; }
|
||||
if (container.size() < 2 || !m_columns.isSortable(column))
|
||||
@@ -542,8 +542,8 @@ namespace BlackGui
|
||||
return container.sorted(p);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
QMimeData *CListModelBase<ObjectType, ContainerType, UseCompare>::mimeData(const QModelIndexList &indexes) const
|
||||
template <typename T, bool UseCompare>
|
||||
QMimeData *CListModelBase<T, UseCompare>::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
QMimeData *mimeData = new QMimeData();
|
||||
if (indexes.isEmpty()) { return mimeData; }
|
||||
@@ -569,8 +569,8 @@ namespace BlackGui
|
||||
return mimeData;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
QJsonObject CListModelBase<ObjectType, ContainerType, UseCompare>::toJson(bool selectedOnly) const
|
||||
template <typename T, bool UseCompare>
|
||||
QJsonObject CListModelBase<T, UseCompare>::toJson(bool selectedOnly) const
|
||||
{
|
||||
const CVariant variant = CVariant::fromValue(
|
||||
selectedOnly && m_selectionModel ?
|
||||
@@ -579,8 +579,8 @@ namespace BlackGui
|
||||
return variant.toJson();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
QString CListModelBase<ObjectType, ContainerType, UseCompare>::toJsonString(QJsonDocument::JsonFormat format, bool selectedOnly) const
|
||||
template <typename T, bool UseCompare>
|
||||
QString CListModelBase<T, UseCompare>::toJsonString(QJsonDocument::JsonFormat format, bool selectedOnly) const
|
||||
{
|
||||
const CVariant variant = CVariant::fromValue(
|
||||
selectedOnly && m_selectionModel ?
|
||||
@@ -589,8 +589,8 @@ namespace BlackGui
|
||||
return variant.toJsonString(format);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::isOrderable() const
|
||||
template <typename T, bool UseCompare>
|
||||
bool CListModelBase<T, UseCompare>::isOrderable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -39,9 +39,16 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! List model
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare = false> class CListModelBase : public CListModelBaseNonTemplate
|
||||
template <typename T, bool UseCompare = false>
|
||||
class CListModelBase : public CListModelBaseNonTemplate
|
||||
{
|
||||
public:
|
||||
//! Container type
|
||||
using ContainerType = T;
|
||||
|
||||
//! Container element type
|
||||
using ObjectType = typename T::value_type;
|
||||
|
||||
//! Destructor
|
||||
virtual ~CListModelBase() {}
|
||||
|
||||
|
||||
@@ -15,13 +15,13 @@ namespace BlackGui
|
||||
{
|
||||
// see here for the reason of thess forward instantiations
|
||||
// https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
|
||||
template class CListModelBase<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAtcStation, BlackMisc::Aviation::CAtcStationList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAirport, BlackMisc::Aviation::CAirportList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAirlineIcaoCode, BlackMisc::Aviation::CAirlineIcaoCodeList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftSituationChange, BlackMisc::Aviation::CAircraftSituationChangeList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CLiveryList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAtcStationList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAirportList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftIcaoCodeList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAirlineIcaoCodeList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftPartsList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftSituationList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftSituationChangeList, true>;
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -15,11 +15,11 @@ namespace BlackGui
|
||||
{
|
||||
// see here for the reason of thess forward instantiations
|
||||
// https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
|
||||
template class CListModelBase<BlackMisc::CIdentifier, BlackMisc::CIdentifierList, false>;
|
||||
template class CListModelBase<BlackMisc::CApplicationInfo, BlackMisc::CApplicationInfoList, true>;
|
||||
template class CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList, true>;
|
||||
template class CListModelBase<BlackMisc::CNameVariantPair, BlackMisc::CNameVariantPairList, false>;
|
||||
template class CListModelBase<BlackMisc::CCountry, BlackMisc::CCountryList, true>;
|
||||
template class CListModelBase<BlackMisc::CIdentifierList, false>;
|
||||
template class CListModelBase<BlackMisc::CApplicationInfoList, true>;
|
||||
template class CListModelBase<BlackMisc::CStatusMessageList, true>;
|
||||
template class CListModelBase<BlackMisc::CNameVariantPairList, false>;
|
||||
template class CListModelBase<BlackMisc::CCountryList, true>;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace BlackGui
|
||||
{
|
||||
// see here for the reason of thess forward instantiations
|
||||
// https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
|
||||
template class CListModelBase<BlackMisc::Network::CServer, BlackMisc::Network::CServerList, true>;
|
||||
template class CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList, true>;
|
||||
template class CListModelBase<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList, false>;
|
||||
template class CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList, false>;
|
||||
template class CListModelBase<BlackMisc::Network::CServerList, true>;
|
||||
template class CListModelBase<BlackMisc::Network::CUserList, true>;
|
||||
template class CListModelBase<BlackMisc::Network::CTextMessageList, false>;
|
||||
template class CListModelBase<BlackMisc::Network::CClientList, false>;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -15,11 +15,11 @@ namespace BlackGui
|
||||
{
|
||||
// see here for the reason of thess forward instantiations
|
||||
// https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
|
||||
template class CListModelBase<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList, true>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::Simulation::CSimulatedAircraftList, true>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList, true>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CInterpolationAndRenderingSetupPerCallsign, BlackMisc::Simulation::CInterpolationSetupList, false>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CMatchingStatisticsEntry, BlackMisc::Simulation::CMatchingStatistics, true>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CAircraftModelList, true>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CSimulatedAircraftList, true>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CDistributorList, true>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CInterpolationSetupList, false>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CMatchingStatistics, true>;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace BlackGui
|
||||
{
|
||||
// see here for the reason of thess forward instantiations
|
||||
// https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
|
||||
template class CListModelBase<BlackMisc::Weather::CCloudLayer, BlackMisc::Weather::CCloudLayerList, false>;
|
||||
template class CListModelBase<BlackMisc::Weather::CTemperatureLayer, BlackMisc::Weather::CTemperatureLayerList, false>;
|
||||
template class CListModelBase<BlackMisc::Weather::CWindLayer, BlackMisc::Weather::CWindLayerList, false>;
|
||||
template class CListModelBase<BlackMisc::Weather::CCloudLayerList, false>;
|
||||
template class CListModelBase<BlackMisc::Weather::CTemperatureLayerList, false>;
|
||||
template class CListModelBase<BlackMisc::Weather::CWindLayerList, false>;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -22,28 +22,28 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
CListModelCallsignObjects<ObjectType, ContainerType, UseCompare>::CListModelCallsignObjects(const QString &translationContext, QObject *parent) :
|
||||
CListModelBase<ObjectType, ContainerType, UseCompare>(translationContext, parent)
|
||||
template <typename T, bool UseCompare>
|
||||
CListModelCallsignObjects<T, UseCompare>::CListModelCallsignObjects(const QString &translationContext, QObject *parent) :
|
||||
CListModelBase<ContainerType, UseCompare>(translationContext, parent)
|
||||
{ }
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
QVariant CListModelCallsignObjects<ObjectType, ContainerType, UseCompare>::data(const QModelIndex &index, int role) const
|
||||
template <typename T, bool UseCompare>
|
||||
QVariant CListModelCallsignObjects<T, UseCompare>::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role != Qt::BackgroundRole) { return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role); }
|
||||
if (role != Qt::BackgroundRole) { return CListModelBase<ContainerType, UseCompare>::data(index, role); }
|
||||
if (isHighlightedIndex(index)) { return QBrush(m_highlightColor); }
|
||||
return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role);
|
||||
return CListModelBase<ContainerType, UseCompare>::data(index, role);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
BlackMisc::Aviation::CCallsign CListModelCallsignObjects<ObjectType, ContainerType, UseCompare>::callsignForIndex(const QModelIndex &index) const
|
||||
template <typename T, bool UseCompare>
|
||||
BlackMisc::Aviation::CCallsign CListModelCallsignObjects<T, UseCompare>::callsignForIndex(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) { return CCallsign(); }
|
||||
return this->at(index).getCallsign();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelCallsignObjects<ObjectType, ContainerType, UseCompare>::isHighlightedIndex(const QModelIndex &index) const
|
||||
template <typename T, bool UseCompare>
|
||||
bool CListModelCallsignObjects<T, UseCompare>::isHighlightedIndex(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) { return false; }
|
||||
if (m_highlightCallsigns.isEmpty()) { return false; }
|
||||
@@ -52,8 +52,8 @@ namespace BlackGui
|
||||
|
||||
// see here for the reason of thess forward instantiations
|
||||
// https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
|
||||
template class CListModelCallsignObjects<BlackMisc::Aviation::CAtcStation, BlackMisc::Aviation::CAtcStationList, true>;
|
||||
template class CListModelCallsignObjects<BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::Simulation::CSimulatedAircraftList, true>;
|
||||
template class CListModelCallsignObjects<BlackMisc::Simulation::CInterpolationAndRenderingSetupPerCallsign, BlackMisc::Simulation::CInterpolationSetupList, false>;
|
||||
template class CListModelCallsignObjects<BlackMisc::Aviation::CAtcStationList, true>;
|
||||
template class CListModelCallsignObjects<BlackMisc::Simulation::CSimulatedAircraftList, true>;
|
||||
template class CListModelCallsignObjects<BlackMisc::Simulation::CInterpolationSetupList, false>;
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -29,10 +29,16 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! List model for callsign based objects (callsign is unique key)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare = false> class CListModelCallsignObjects :
|
||||
public CListModelBase<ObjectType, ContainerType, UseCompare>
|
||||
template <typename T, bool UseCompare = false> class CListModelCallsignObjects :
|
||||
public CListModelBase<T, UseCompare>
|
||||
{
|
||||
public:
|
||||
//! Container type
|
||||
using ContainerType = T;
|
||||
|
||||
//! Container element type
|
||||
using ObjectType = typename T::value_type;
|
||||
|
||||
//! Destructor
|
||||
virtual ~CListModelCallsignObjects() {}
|
||||
|
||||
@@ -46,7 +52,7 @@ namespace BlackGui
|
||||
virtual void clearHighlighting() override
|
||||
{
|
||||
this->clearHighlightedCallsigns();
|
||||
CListModelBase<ObjectType, ContainerType, UseCompare>::clearHighlighting();
|
||||
CListModelBase<ContainerType, UseCompare>::clearHighlighting();
|
||||
}
|
||||
|
||||
//! Set color for highlighting
|
||||
|
||||
@@ -36,45 +36,45 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||
CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::CListModelDbObjects(const QString &translationContext, QObject *parent) :
|
||||
CListModelBase<ObjectType, ContainerType, UseCompare>(translationContext, parent)
|
||||
template <typename T, typename K, bool UseCompare>
|
||||
CListModelDbObjects<T, K, UseCompare>::CListModelDbObjects(const QString &translationContext, QObject *parent) :
|
||||
CListModelBase<ContainerType, UseCompare>(translationContext, parent)
|
||||
{
|
||||
constexpr bool hasIntegerKey = std::is_base_of<IDatastoreObjectWithIntegerKey, ObjectType>::value && std::is_same<int, KeyType>::value;
|
||||
constexpr bool hasStringKey = std::is_base_of<IDatastoreObjectWithStringKey, ObjectType>::value && std::is_base_of<QString, KeyType>::value;
|
||||
static_assert(hasIntegerKey || hasStringKey, "ObjectType needs to implement IDatastoreObjectWithXXXXKey and have appropriate KeyType");
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||
QVariant CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::data(const QModelIndex &index, int role) const
|
||||
template <typename T, typename K, bool UseCompare>
|
||||
QVariant CListModelDbObjects<T, K, UseCompare>::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role != Qt::BackgroundRole) { return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role); }
|
||||
if (role != Qt::BackgroundRole) { return CListModelBase<ContainerType, UseCompare>::data(index, role); }
|
||||
if (isHighlightedIndex(index) ) { return QBrush(m_highlightColor); }
|
||||
return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role);
|
||||
return CListModelBase<ContainerType, UseCompare>::data(index, role);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||
KeyType CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::dbKeyForIndex(const QModelIndex &index) const
|
||||
template <typename T, typename K, bool UseCompare>
|
||||
K CListModelDbObjects<T, K, UseCompare>::dbKeyForIndex(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) { return ObjectType::invalidDbKey(); }
|
||||
return this->at(index).getDbKey();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||
bool CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::isHighlightedIndex(const QModelIndex &index) const
|
||||
template <typename T, typename K, bool UseCompare>
|
||||
bool CListModelDbObjects<T, K, UseCompare>::isHighlightedIndex(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) { return false; }
|
||||
if (m_highlightKeys.isEmpty()) { return false; }
|
||||
return m_highlightKeys.contains(dbKeyForIndex(index));
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||
COrderableListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::COrderableListModelDbObjects(const QString &translationContext, QObject *parent)
|
||||
: CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>(translationContext, parent)
|
||||
template <typename T, typename K, bool UseCompare>
|
||||
COrderableListModelDbObjects<T, K, UseCompare>::COrderableListModelDbObjects(const QString &translationContext, QObject *parent)
|
||||
: CListModelDbObjects<ContainerType, KeyType, UseCompare>(translationContext, parent)
|
||||
{ }
|
||||
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||
void COrderableListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::moveItems(const ContainerType &items, int position)
|
||||
template <typename T, typename K, bool UseCompare>
|
||||
void COrderableListModelDbObjects<T, K, UseCompare>::moveItems(const ContainerType &items, int position)
|
||||
{
|
||||
if (items.isEmpty()) { return; }
|
||||
ContainerType container(this->container());
|
||||
@@ -90,33 +90,33 @@ namespace BlackGui
|
||||
this->updateContainerMaybeAsync(container);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||
bool COrderableListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::setSortColumnToOrder()
|
||||
template <typename T, typename K, bool UseCompare>
|
||||
bool COrderableListModelDbObjects<T, K, UseCompare>::setSortColumnToOrder()
|
||||
{
|
||||
// force sorted by order, otherwise display looks confusing
|
||||
return this->setSorting(IOrderable::IndexOrder);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||
int COrderableListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::update(const ContainerType &container, bool sort)
|
||||
template <typename T, typename K, bool UseCompare>
|
||||
int COrderableListModelDbObjects<T, K, UseCompare>::update(const ContainerType &container, bool sort)
|
||||
{
|
||||
if (container.needsOrder())
|
||||
{
|
||||
ContainerType orderable(container);
|
||||
orderable.resetOrder();
|
||||
return CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::update(orderable, sort);
|
||||
return CListModelDbObjects<ContainerType, KeyType, UseCompare>::update(orderable, sort);
|
||||
}
|
||||
return CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::update(container, sort);
|
||||
return CListModelDbObjects<ContainerType, KeyType, UseCompare>::update(container, sort);
|
||||
}
|
||||
|
||||
template class CListModelDbObjects<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::CCountry, BlackMisc::CCountryList, QString, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Aviation::CAirlineIcaoCode, BlackMisc::Aviation::CAirlineIcaoCodeList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList, QString, true>;
|
||||
template class COrderableListModelDbObjects<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList, int, true>;
|
||||
template class COrderableListModelDbObjects<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList, QString, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Aviation::CLiveryList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::CCountryList, QString, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Aviation::CAircraftIcaoCodeList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Aviation::CAirlineIcaoCodeList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Simulation::CAircraftModelList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Simulation::CDistributorList, QString, true>;
|
||||
template class COrderableListModelDbObjects<BlackMisc::Simulation::CAircraftModelList, int, true>;
|
||||
template class COrderableListModelDbObjects<BlackMisc::Simulation::CDistributorList, QString, true>;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -28,10 +28,19 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! List model for DB objects
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare = false> class CListModelDbObjects :
|
||||
public CListModelBase<ObjectType, ContainerType, UseCompare>
|
||||
template <typename T, typename K, bool UseCompare = false> class CListModelDbObjects :
|
||||
public CListModelBase<T, UseCompare>
|
||||
{
|
||||
public:
|
||||
//! Container type
|
||||
using ContainerType = T;
|
||||
|
||||
//! Container element type
|
||||
using ObjectType = typename T::value_type;
|
||||
|
||||
//! DB key type
|
||||
using KeyType = K;
|
||||
|
||||
//! Destructor
|
||||
virtual ~CListModelDbObjects() {}
|
||||
|
||||
@@ -45,7 +54,7 @@ namespace BlackGui
|
||||
virtual void clearHighlighting() override
|
||||
{
|
||||
this->clearHighlightedDbKeys();
|
||||
CListModelBase<ObjectType, ContainerType, UseCompare>::clearHighlighting();
|
||||
CListModelBase<ContainerType, UseCompare>::clearHighlighting();
|
||||
}
|
||||
|
||||
//! \copydoc BlackGui::Models::CListModelBaseNonTemplate::hasHighlightedRows
|
||||
@@ -76,10 +85,19 @@ namespace BlackGui
|
||||
};
|
||||
|
||||
//! List model for DB objects
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare = false> class COrderableListModelDbObjects :
|
||||
public CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>
|
||||
template <typename T, typename K, bool UseCompare = false> class COrderableListModelDbObjects :
|
||||
public CListModelDbObjects<T, K, UseCompare>
|
||||
{
|
||||
public:
|
||||
//! Container type
|
||||
using ContainerType = T;
|
||||
|
||||
//! Container element type
|
||||
using ObjectType = typename T::value_type;
|
||||
|
||||
//! DB key type
|
||||
using KeyType = K;
|
||||
|
||||
//! Destructor
|
||||
virtual ~COrderableListModelDbObjects() {}
|
||||
|
||||
|
||||
@@ -20,46 +20,46 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
CListModelTimestampObjects<ObjectType, ContainerType, UseCompare>::CListModelTimestampObjects(const QString &translationContext, QObject *parent) :
|
||||
CListModelBase<ObjectType, ContainerType, UseCompare>(translationContext, parent)
|
||||
template <typename T, bool UseCompare>
|
||||
CListModelTimestampObjects<T, UseCompare>::CListModelTimestampObjects(const QString &translationContext, QObject *parent) :
|
||||
CListModelBase<ContainerType, UseCompare>(translationContext, parent)
|
||||
{ }
|
||||
|
||||
template<typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelTimestampObjects<ObjectType, ContainerType, UseCompare>::addTimestampColumns()
|
||||
template<typename T, bool UseCompare>
|
||||
void CListModelTimestampObjects<T, UseCompare>::addTimestampColumns()
|
||||
{
|
||||
CListModelBaseNonTemplate::m_columns.addColumn(CColumn::standardString("timestamp", ObjectType::IndexUtcTimestampFormattedMdhmsz));
|
||||
CListModelBaseNonTemplate::m_columns.addColumn(CColumn("timestamp ms", "milliseconds since epoch", ObjectType::IndexMSecsSinceEpoch, new CIntegerFormatter()));
|
||||
}
|
||||
|
||||
template class CListModelTimestampObjects<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList, true>;
|
||||
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList, true>;
|
||||
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList, true>;
|
||||
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftSituationChange, BlackMisc::Aviation::CAircraftSituationChangeList, true>;
|
||||
template class CListModelTimestampObjects<BlackMisc::CStatusMessageList, true>;
|
||||
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftPartsList, true>;
|
||||
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftSituationList, true>;
|
||||
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftSituationChangeList, true>;
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
CListModelTimestampWithOffsetObjects<ObjectType, ContainerType, UseCompare>::CListModelTimestampWithOffsetObjects(const QString &translationContext, QObject *parent) :
|
||||
CListModelTimestampObjects<ObjectType, ContainerType, UseCompare>(translationContext, parent)
|
||||
template <typename T, bool UseCompare>
|
||||
CListModelTimestampWithOffsetObjects<T, UseCompare>::CListModelTimestampWithOffsetObjects(const QString &translationContext, QObject *parent) :
|
||||
CListModelTimestampObjects<ContainerType, UseCompare>(translationContext, parent)
|
||||
{ }
|
||||
|
||||
template<typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelTimestampWithOffsetObjects<ObjectType, ContainerType, UseCompare>::push_frontKeepLatestAdjustedFirst(const ObjectType &object, int max)
|
||||
template<typename T, bool UseCompare>
|
||||
void CListModelTimestampWithOffsetObjects<T, UseCompare>::push_frontKeepLatestAdjustedFirst(const ObjectType &object, int max)
|
||||
{
|
||||
this->beginInsertRows(QModelIndex(), 0, 0);
|
||||
CListModelBase<ObjectType, ContainerType, UseCompare>::m_container.push_frontKeepLatestAdjustedFirst(object, max);
|
||||
CListModelBase<ContainerType, UseCompare>::m_container.push_frontKeepLatestAdjustedFirst(object, max);
|
||||
this->endInsertRows();
|
||||
}
|
||||
|
||||
template<typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelTimestampWithOffsetObjects<ObjectType, ContainerType, UseCompare>::addTimestampOffsetColumns()
|
||||
template<typename T, bool UseCompare>
|
||||
void CListModelTimestampWithOffsetObjects<T, UseCompare>::addTimestampOffsetColumns()
|
||||
{
|
||||
CListModelTimestampObjects<ObjectType, ContainerType, UseCompare>::addTimestampColumns();
|
||||
CListModelTimestampObjects<ContainerType, UseCompare>::addTimestampColumns();
|
||||
CListModelBaseNonTemplate::m_columns.addColumn(CColumn("ms adj.", "milliseconds adjusted", ObjectType::IndexAdjustedMsWithOffset, new CIntegerFormatter()));
|
||||
CListModelBaseNonTemplate::m_columns.addColumn(CColumn("t.os.", "time offset", ObjectType::IndexOffsetMs, new CIntegerFormatter()));
|
||||
}
|
||||
|
||||
template class CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList, true>;
|
||||
template class CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList, true>;
|
||||
template class CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftSituationChange, BlackMisc::Aviation::CAircraftSituationChangeList, true>;
|
||||
template class CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftPartsList, true>;
|
||||
template class CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftSituationList, true>;
|
||||
template class CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftSituationChangeList, true>;
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -26,9 +26,16 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! List model for timestamp based objects with offset
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare = false> class CListModelTimestampObjects :
|
||||
public CListModelBase<ObjectType, ContainerType, UseCompare>
|
||||
template <typename T, bool UseCompare = false> class CListModelTimestampObjects :
|
||||
public CListModelBase<T, UseCompare>
|
||||
{
|
||||
public:
|
||||
//! Container type
|
||||
using ContainerType = T;
|
||||
|
||||
//! Container element type
|
||||
using ObjectType = typename T::value_type;
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CListModelTimestampObjects(const QString &translationContext, QObject *parent = nullptr);
|
||||
@@ -38,10 +45,16 @@ namespace BlackGui
|
||||
};
|
||||
|
||||
//! List model for timestamp based objects with offset
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare = false> class CListModelTimestampWithOffsetObjects :
|
||||
public CListModelTimestampObjects<ObjectType, ContainerType, UseCompare>
|
||||
template <typename T, bool UseCompare = false> class CListModelTimestampWithOffsetObjects :
|
||||
public CListModelTimestampObjects<T, UseCompare>
|
||||
{
|
||||
public:
|
||||
//! Container type
|
||||
using ContainerType = T;
|
||||
|
||||
//! Container element type
|
||||
using ObjectType = typename T::value_type;
|
||||
|
||||
//! Destructor
|
||||
virtual ~CListModelTimestampWithOffsetObjects() {}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Distributor list model
|
||||
class BLACKGUI_EXPORT CLiveryListModel :
|
||||
public CListModelDbObjects<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList, int, true>
|
||||
public CListModelDbObjects<BlackMisc::Aviation::CLiveryList, int, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Matching statistics entry
|
||||
class BLACKGUI_EXPORT CMatchingStatisticsModel : public CListModelBase<BlackMisc::Simulation::CMatchingStatisticsEntry, BlackMisc::Simulation::CMatchingStatistics, true>
|
||||
class BLACKGUI_EXPORT CMatchingStatisticsModel : public CListModelBase<BlackMisc::Simulation::CMatchingStatistics, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace BlackGui
|
||||
{
|
||||
|
||||
//! Simple model displaying name / variant values
|
||||
class BLACKGUI_EXPORT CNameVariantPairModel : public CListModelBase<BlackMisc::CNameVariantPair, BlackMisc::CNameVariantPairList>
|
||||
class BLACKGUI_EXPORT CNameVariantPairModel : public CListModelBase<BlackMisc::CNameVariantPairList>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Server list model
|
||||
class BLACKGUI_EXPORT CServerListModel : public CListModelBase<BlackMisc::Network::CServer, BlackMisc::Network::CServerList, true>
|
||||
class BLACKGUI_EXPORT CServerListModel : public CListModelBase<BlackMisc::Network::CServerList, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Aircraft list model
|
||||
class BLACKGUI_EXPORT CSimulatedAircraftListModel :
|
||||
public CListModelCallsignObjects<BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::Simulation::CSimulatedAircraftList, true>
|
||||
public CListModelCallsignObjects<BlackMisc::Simulation::CSimulatedAircraftList, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
CStatusMessageListModel::CStatusMessageListModel(QObject *parent) :
|
||||
CListModelTimestampObjects<CStatusMessage, CStatusMessageList, true>("ViewStatusMessageList", parent)
|
||||
CListModelTimestampObjects<CStatusMessageList, true>("ViewStatusMessageList", parent)
|
||||
{
|
||||
this->setMode(Detailed);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace BlackGui
|
||||
* Status message list model
|
||||
*/
|
||||
class BLACKGUI_EXPORT CStatusMessageListModel :
|
||||
public CListModelTimestampObjects<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList, true>
|
||||
public CListModelTimestampObjects<BlackMisc::CStatusMessageList, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Temperature layer list model
|
||||
class BLACKGUI_EXPORT CTemperatureLayerListModel :
|
||||
public CListModelBase<BlackMisc::Weather::CTemperatureLayer, BlackMisc::Weather::CTemperatureLayerList, false>
|
||||
public CListModelBase<BlackMisc::Weather::CTemperatureLayerList, false>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Text message list model
|
||||
class BLACKGUI_EXPORT CTextMessageListModel : public CListModelBase<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>
|
||||
class BLACKGUI_EXPORT CTextMessageListModel : public CListModelBase<BlackMisc::Network::CTextMessageList>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace BlackGui
|
||||
* User list model
|
||||
*/
|
||||
class BLACKGUI_EXPORT CUserListModel :
|
||||
public CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList, true>
|
||||
public CListModelBase<BlackMisc::Network::CUserList, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Wind layer list model
|
||||
class BLACKGUI_EXPORT CWindLayerListModel :
|
||||
public CListModelBase<BlackMisc::Weather::CWindLayer, BlackMisc::Weather::CWindLayerList, false>
|
||||
public CListModelBase<BlackMisc::Weather::CWindLayerList, false>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
Reference in New Issue
Block a user