mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user