/* Copyright (C) 2053 * swift project Community / Contributors * * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, * or distributed except according to the terms contained in the LICENSE file. */ #include "listmodeldbobjects.h" #include "allmodelcontainers.h" #include "blackmisc/db/datastoreobjectlist.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/aircraftmodel.h" #include "blackmisc/simulation/distributorlist.h" #include "blackmisc/simulation/distributor.h" #include "blackmisc/aviation/aircrafticaocodelist.h" #include "blackmisc/aviation/aircrafticaocode.h" #include "blackmisc/aviation/aircraftcategorylist.h" #include "blackmisc/aviation/aircraftcategory.h" #include "blackmisc/aviation/airlineicaocodelist.h" #include "blackmisc/aviation/airlineicaocode.h" #include "blackmisc/aviation/liverylist.h" #include "blackmisc/aviation/livery.h" #include "blackmisc/countrylist.h" #include "blackmisc/country.h" #include "blackmisc/orderable.h" #include #include #include using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Db; namespace BlackGui { namespace Models { template CListModelDbObjects::CListModelDbObjects(const QString &translationContext, QObject *parent) : CListModelBase(translationContext, parent) { CListModelBaseNonTemplate::m_sortTieBreakers.push_front(ObjectType::keyIndex()); constexpr bool hasIntegerKey = std::is_base_of_v && std::is_same_v; constexpr bool hasStringKey = std::is_base_of_v && std::is_base_of_v; static_assert(hasIntegerKey || hasStringKey, "ObjectType needs to implement IDatastoreObjectWithXXXXKey and have appropriate KeyType"); } template QVariant CListModelDbObjects::data(const QModelIndex &index, int role) const { if (role != Qt::BackgroundRole) { return CListModelBase::data(index, role); } if (isHighlightedIndex(index)) { return QBrush(m_highlightColor); } return CListModelBase::data(index, role); } template K CListModelDbObjects::dbKeyForIndex(const QModelIndex &index) const { if (!index.isValid()) { return ObjectType::invalidDbKey(); } return this->at(index).getDbKey(); } template bool CListModelDbObjects::isHighlightedIndex(const QModelIndex &index) const { if (!index.isValid()) { return false; } if (m_highlightKeys.isEmpty()) { return false; } return m_highlightKeys.contains(dbKeyForIndex(index)); } template COrderableListModelDbObjects::COrderableListModelDbObjects(const QString &translationContext, QObject *parent) : CListModelDbObjects(translationContext, parent) { } template void COrderableListModelDbObjects::moveItems(const ContainerType &items, int position) { if (items.isEmpty()) { return; } ContainerType container(this->container()); int order = 0; if (position >= 0 && position < container.size()) { order = container[position].getOrder(); } this->setSortColumnToOrder(); container.moveTo(items, order); // update container this->updateContainerMaybeAsync(container); } template bool COrderableListModelDbObjects::setSortColumnToOrder() { // force sorted by order, otherwise display looks confusing return this->setSorting(IOrderable::IndexOrder); } template int COrderableListModelDbObjects::update(const ContainerType &container, bool sort) { if (container.needsOrder()) { ContainerType orderable(container); orderable.resetOrder(); return CListModelDbObjects::update(orderable, sort); } return CListModelDbObjects::update(container, sort); } template class CListModelDbObjects; template class CListModelDbObjects; template class CListModelDbObjects; template class CListModelDbObjects; template class CListModelDbObjects; template class CListModelDbObjects; template class CListModelDbObjects; template class COrderableListModelDbObjects; template class COrderableListModelDbObjects; } // namespace } // namespace