mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 02:35:38 +08:00
refs #568, specialized model class for models from DB
* support for keys * renamed to listmodeldbobjects (unified with views) * key type as template parameter * adjusted derived classes
This commit is contained in:
@@ -19,7 +19,7 @@ namespace BlackGui
|
|||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
CAircraftIcaoCodeListModel::CAircraftIcaoCodeListModel(QObject *parent) :
|
CAircraftIcaoCodeListModel::CAircraftIcaoCodeListModel(QObject *parent) :
|
||||||
CListModelBase("AircraftIcaoListModel", parent)
|
CListModelDbObjects("AircraftIcaoListModel", parent)
|
||||||
{
|
{
|
||||||
this->m_columns.addColumn(CColumn::standardString("id", CAircraftIcaoCode::IndexDbIntegerKey, CDefaultFormatter::alignRightVCenter()));
|
this->m_columns.addColumn(CColumn::standardString("id", CAircraftIcaoCode::IndexDbIntegerKey, CDefaultFormatter::alignRightVCenter()));
|
||||||
this->m_columns.addColumn(CColumn::standardValueObject("ICAO", CAircraftIcaoCode::IndexAircraftDesignator));
|
this->m_columns.addColumn(CColumn::standardValueObject("ICAO", CAircraftIcaoCode::IndexAircraftDesignator));
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include "blackmisc/aviation/aircrafticaocodelist.h"
|
#include "blackmisc/aviation/aircrafticaocodelist.h"
|
||||||
#include "blackgui/models/listmodelbase.h"
|
#include "blackgui/models/listmodeldbobjects.h"
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
@@ -23,7 +23,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
//! Airport list model
|
//! Airport list model
|
||||||
class BLACKGUI_EXPORT CAircraftIcaoCodeListModel :
|
class BLACKGUI_EXPORT CAircraftIcaoCodeListModel :
|
||||||
public CListModelBase<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList, true>
|
public CListModelDbObjects<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList, int, true>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace BlackGui
|
|||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
CAircraftModelListModel::CAircraftModelListModel(AircraftModelMode mode, QObject *parent) :
|
CAircraftModelListModel::CAircraftModelListModel(AircraftModelMode mode, QObject *parent) :
|
||||||
CModelsWithDbKeysBase("CAircraftModelListModel", parent)
|
CListModelDbObjects("CAircraftModelListModel", parent)
|
||||||
{
|
{
|
||||||
this->setAircraftModelMode(mode);
|
this->setAircraftModelMode(mode);
|
||||||
|
|
||||||
@@ -142,15 +142,12 @@ namespace BlackGui
|
|||||||
|
|
||||||
QVariant CAircraftModelListModel::data(const QModelIndex &index, int role) const
|
QVariant CAircraftModelListModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (role != Qt::BackgroundRole) { return CListModelBase::data(index, role); }
|
if (role != Qt::BackgroundRole) { return CListModelDbObjects::data(index, role); }
|
||||||
bool db = highlightDbData();
|
|
||||||
bool ms = highlightGivenModelStrings() && !m_highlightStrings.isEmpty();
|
bool ms = highlightGivenModelStrings() && !m_highlightStrings.isEmpty();
|
||||||
if (!db && !ms) { return CListModelBase::data(index, role); }
|
if (!ms) { return CListModelDbObjects::data(index, role); }
|
||||||
|
|
||||||
CAircraftModel model(this->at(index));
|
CAircraftModel model(this->at(index));
|
||||||
// highlight stashed first
|
// highlight stashed first
|
||||||
if (ms)
|
|
||||||
{
|
|
||||||
if (m_highlightStrings.contains(model.getModelString(), Qt::CaseInsensitive))
|
if (m_highlightStrings.contains(model.getModelString(), Qt::CaseInsensitive))
|
||||||
{
|
{
|
||||||
static const QBrush b(Qt::yellow);
|
static const QBrush b(Qt::yellow);
|
||||||
@@ -158,17 +155,5 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
// highlight DB models
|
|
||||||
if (db)
|
|
||||||
{
|
|
||||||
if (model.hasValidDbKey())
|
|
||||||
{
|
|
||||||
static const QBrush b(Qt::green);
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#define BLACKGUI_AIRCRAFTMODELLISTMODEL_H
|
#define BLACKGUI_AIRCRAFTMODELLISTMODEL_H
|
||||||
|
|
||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
#include "blackgui/models/modelswithdbkey.h"
|
#include "blackgui/models/listmodeldbobjects.h"
|
||||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
@@ -24,7 +24,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
//! Aircraft model list model
|
//! Aircraft model list model
|
||||||
class BLACKGUI_EXPORT CAircraftModelListModel :
|
class BLACKGUI_EXPORT CAircraftModelListModel :
|
||||||
public CModelsWithDbKeysBase<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList, int, true>
|
public CListModelDbObjects<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList, int, true>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! How to display
|
//! How to display
|
||||||
@@ -51,12 +51,6 @@ namespace BlackGui
|
|||||||
//! Mode
|
//! Mode
|
||||||
AircraftModelMode getModelMode() const { return m_mode; }
|
AircraftModelMode getModelMode() const { return m_mode; }
|
||||||
|
|
||||||
//! Highlight the DB models
|
|
||||||
bool highlightDbData() const { return m_highlightDbData; }
|
|
||||||
|
|
||||||
//! Highlight the DB models
|
|
||||||
void setHighlightDbData(bool highlightDbData) { m_highlightDbData = highlightDbData; }
|
|
||||||
|
|
||||||
//! Highlight models
|
//! Highlight models
|
||||||
bool highlightGivenModelStrings() const { return m_highlightModelStrings; }
|
bool highlightGivenModelStrings() const { return m_highlightModelStrings; }
|
||||||
|
|
||||||
@@ -72,13 +66,11 @@ namespace BlackGui
|
|||||||
//! Replace models with same model string, or just add
|
//! Replace models with same model string, or just add
|
||||||
void replaceOrAddByModelString(const BlackMisc::Simulation::CAircraftModelList &models);
|
void replaceOrAddByModelString(const BlackMisc::Simulation::CAircraftModelList &models);
|
||||||
|
|
||||||
protected:
|
|
||||||
//! \copydoc QAbstractItemModel::data
|
//! \copydoc QAbstractItemModel::data
|
||||||
virtual QVariant data(const QModelIndex &index, int role) const override;
|
virtual QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AircraftModelMode m_mode = NotSet; //!< current mode
|
AircraftModelMode m_mode = NotSet; //!< current mode
|
||||||
bool m_highlightDbData = false; //!< highlight if DB data entry (valid key)
|
|
||||||
bool m_highlightModelStrings = false; //!< highlight in in model strings
|
bool m_highlightModelStrings = false; //!< highlight in in model strings
|
||||||
QStringList m_highlightStrings; //!< model strings to highlight
|
QStringList m_highlightStrings; //!< model strings to highlight
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace BlackGui
|
|||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
CAirlineIcaoCodeListModel::CAirlineIcaoCodeListModel(QObject *parent) :
|
CAirlineIcaoCodeListModel::CAirlineIcaoCodeListModel(QObject *parent) :
|
||||||
CListModelBase("AircraftIcaoListModel", parent)
|
CListModelDbObjects("AircraftIcaoListModel", parent)
|
||||||
{
|
{
|
||||||
this->m_columns.addColumn(CColumn::standardString("id", CAirlineIcaoCode::IndexDbIntegerKey, CDefaultFormatter::alignRightVCenter()));
|
this->m_columns.addColumn(CColumn::standardString("id", CAirlineIcaoCode::IndexDbIntegerKey, CDefaultFormatter::alignRightVCenter()));
|
||||||
this->m_columns.addColumn(CColumn::standardValueObject("ICAO", CAirlineIcaoCode::IndexAirlineDesignator));
|
this->m_columns.addColumn(CColumn::standardValueObject("ICAO", CAirlineIcaoCode::IndexAirlineDesignator));
|
||||||
|
|||||||
@@ -15,14 +15,15 @@
|
|||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include "blackmisc/aviation/airlineicaocodelist.h"
|
#include "blackmisc/aviation/airlineicaocodelist.h"
|
||||||
#include "blackgui/models/listmodelbase.h"
|
#include "blackgui/models/listmodeldbobjects.h"
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
//! Airport list model
|
//! Airport list model
|
||||||
class BLACKGUI_EXPORT CAirlineIcaoCodeListModel : public CListModelBase<BlackMisc::Aviation::CAirlineIcaoCode, BlackMisc::Aviation::CAirlineIcaoCodeList, true>
|
class BLACKGUI_EXPORT CAirlineIcaoCodeListModel :
|
||||||
|
public CListModelDbObjects<BlackMisc::Aviation::CAirlineIcaoCode, BlackMisc::Aviation::CAirlineIcaoCodeList, int, true>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace BlackGui
|
|||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
CCountryListModel::CCountryListModel(QObject *parent) :
|
CCountryListModel::CCountryListModel(QObject *parent) :
|
||||||
CListModelBase("CountryListModel", parent)
|
CListModelDbObjects("CountryListModel", parent)
|
||||||
{
|
{
|
||||||
CColumn col("country", CCountry::IndexIcon);
|
CColumn col("country", CCountry::IndexIcon);
|
||||||
col.setSortPropertyIndex(CCountry::IndexIsoCode);
|
col.setSortPropertyIndex(CCountry::IndexIsoCode);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
#include "blackmisc/countrylist.h"
|
#include "blackmisc/countrylist.h"
|
||||||
#include "blackgui/models/listmodelbase.h"
|
#include "blackgui/models/listmodeldbobjects.h"
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
@@ -23,7 +23,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
//! Country list model
|
//! Country list model
|
||||||
class BLACKGUI_EXPORT CCountryListModel :
|
class BLACKGUI_EXPORT CCountryListModel :
|
||||||
public CListModelBase<BlackMisc::CCountry, BlackMisc::CCountryList, true>
|
public CListModelDbObjects<BlackMisc::CCountry, BlackMisc::CCountryList, QString, true>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace BlackGui
|
|||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
CDistributorListModel::CDistributorListModel(QObject *parent) :
|
CDistributorListModel::CDistributorListModel(QObject *parent) :
|
||||||
CListModelBase("ModelDistributorList", parent)
|
CListModelDbObjects("ModelDistributorList", parent)
|
||||||
{
|
{
|
||||||
this->m_columns.addColumn(CColumn::standardString("key", CDistributor::IndexDbStringKey));
|
this->m_columns.addColumn(CColumn::standardString("key", CDistributor::IndexDbStringKey));
|
||||||
this->m_columns.addColumn(CColumn::standardString("description", CDistributor::IndexDescription));
|
this->m_columns.addColumn(CColumn::standardString("description", CDistributor::IndexDescription));
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
#include "blackmisc/simulation/distributorlist.h"
|
#include "blackmisc/simulation/distributorlist.h"
|
||||||
#include "blackgui/models/listmodelbase.h"
|
#include "blackgui/models/listmodeldbobjects.h"
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
@@ -23,10 +23,9 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
//! Distributor list model
|
//! Distributor list model
|
||||||
class BLACKGUI_EXPORT CDistributorListModel :
|
class BLACKGUI_EXPORT CDistributorListModel :
|
||||||
public CListModelBase<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList, true>
|
public CListModelDbObjects<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList, QString, true>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
explicit CDistributorListModel(QObject *parent = nullptr);
|
explicit CDistributorListModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ namespace BlackGui
|
|||||||
int CListModelBase<ObjectType, ContainerType, UseCompare>::rowCount(const QModelIndex &parentIndex) const
|
int CListModelBase<ObjectType, ContainerType, UseCompare>::rowCount(const QModelIndex &parentIndex) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parentIndex);
|
Q_UNUSED(parentIndex);
|
||||||
return this->getContainerOrFilteredContainer().size();
|
return this->containerOrFilteredContainer().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
@@ -209,7 +209,7 @@ namespace BlackGui
|
|||||||
if (!formatter) { return QVariant(); }
|
if (!formatter) { return QVariant(); }
|
||||||
|
|
||||||
//! Formatted data
|
//! Formatted data
|
||||||
ObjectType obj = this->getContainerOrFilteredContainer()[index.row()];
|
ObjectType obj = this->containerOrFilteredContainer()[index.row()];
|
||||||
BlackMisc::CPropertyIndex propertyIndex = this->columnToPropertyIndex(index.column());
|
BlackMisc::CPropertyIndex propertyIndex = this->columnToPropertyIndex(index.column());
|
||||||
return formatter->data(role, obj.propertyByIndex(propertyIndex)).getQVariant();
|
return formatter->data(role, obj.propertyByIndex(propertyIndex)).getQVariant();
|
||||||
}
|
}
|
||||||
@@ -398,7 +398,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return this->getContainerOrFilteredContainer()[index.row()];
|
return this->containerOrFilteredContainer()[index.row()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,13 +478,16 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
const ContainerType &CListModelBase<ObjectType, ContainerType, UseCompare>::getContainerOrFilteredContainer() const
|
const ContainerType &CListModelBase<ObjectType, ContainerType, UseCompare>::containerOrFilteredContainer() const
|
||||||
{
|
{
|
||||||
if (!this->hasFilter())
|
if (this->hasFilter())
|
||||||
|
{
|
||||||
|
return this->m_containerFiltered;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return this->m_container;
|
return this->m_container;
|
||||||
}
|
}
|
||||||
return m_containerFiltered;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
@@ -503,7 +506,7 @@ namespace BlackGui
|
|||||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::emitRowCountChanged()
|
void CListModelBase<ObjectType, ContainerType, UseCompare>::emitRowCountChanged()
|
||||||
{
|
{
|
||||||
int n = this->getContainerOrFilteredContainer().size();
|
int n = this->containerOrFilteredContainer().size();
|
||||||
emit this->rowCountChanged(n, this->hasFilter());
|
emit this->rowCountChanged(n, this->hasFilter());
|
||||||
emit this->changed();
|
emit this->changed();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,6 +153,9 @@ namespace BlackGui
|
|||||||
//! Used container data
|
//! Used container data
|
||||||
const ContainerType &container() const;
|
const ContainerType &container() const;
|
||||||
|
|
||||||
|
//! Full container or cached filtered container as approproiate
|
||||||
|
const ContainerType &containerOrFilteredContainer() const;
|
||||||
|
|
||||||
//! \copydoc QStandardItemModel::data()
|
//! \copydoc QStandardItemModel::data()
|
||||||
virtual QVariant data(const QModelIndex &index, int role) const override;
|
virtual QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
|
||||||
@@ -168,6 +171,7 @@ namespace BlackGui
|
|||||||
virtual int rowCount(const QModelIndex &parentIndex = QModelIndex()) const override;
|
virtual int rowCount(const QModelIndex &parentIndex = QModelIndex()) const override;
|
||||||
|
|
||||||
//! Update by new container
|
//! Update by new container
|
||||||
|
//! \return int size after update
|
||||||
//! \remarks a sorting is performed only if a valid sort column is set
|
//! \remarks a sorting is performed only if a valid sort column is set
|
||||||
virtual int update(const ContainerType &container, bool sort = true);
|
virtual int update(const ContainerType &container, bool sort = true);
|
||||||
|
|
||||||
@@ -247,22 +251,19 @@ namespace BlackGui
|
|||||||
void takeFilterOwnership(std::unique_ptr<IModelFilter<ContainerType> > &filter);
|
void takeFilterOwnership(std::unique_ptr<IModelFilter<ContainerType> > &filter);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<IModelFilter<ContainerType> > m_filter; //!< Used filter
|
|
||||||
|
|
||||||
//! \copydoc CListModelBaseNonTemplate::CListModelBaseNonTemplate
|
//! \copydoc CListModelBaseNonTemplate::CListModelBaseNonTemplate
|
||||||
CListModelBase(const QString &translationContext, QObject *parent = nullptr);
|
CListModelBase(const QString &translationContext, QObject *parent = nullptr);
|
||||||
|
|
||||||
//! \copydoc CModelBaseNonTemplate::performUpdateContainer
|
//! \copydoc CModelBaseNonTemplate::performUpdateContainer
|
||||||
virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort) override;
|
virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort) override;
|
||||||
|
|
||||||
//! Full container or cached filtered container as approproiate
|
|
||||||
const ContainerType &getContainerOrFilteredContainer() const;
|
|
||||||
|
|
||||||
//! Update filtered container
|
//! Update filtered container
|
||||||
void updateFilteredContainer();
|
void updateFilteredContainer();
|
||||||
|
|
||||||
//! Row count changed
|
//! Row count changed
|
||||||
void emitRowCountChanged();
|
void emitRowCountChanged();
|
||||||
|
|
||||||
|
std::unique_ptr<IModelFilter<ContainerType> > m_filter; //!< Used filter
|
||||||
ContainerType m_container; //!< used container
|
ContainerType m_container; //!< used container
|
||||||
ContainerType m_containerFiltered; //!< cache for filtered container data
|
ContainerType m_containerFiltered; //!< cache for filtered container data
|
||||||
};
|
};
|
||||||
|
|||||||
70
src/blackgui/models/listmodeldbobjects.cpp
Normal file
70
src/blackgui/models/listmodeldbobjects.cpp
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/* 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 and at http://www.swift-project.org/license.html. 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"
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
using namespace BlackMisc::Aviation;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
// void
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||||
|
QVariant CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (role != Qt::BackgroundRole) { return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role); }
|
||||||
|
|
||||||
|
if (isHighlightIndex(index)) { return QBrush(m_highlightColor); }
|
||||||
|
if (!highlightDbData()) { return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role); }
|
||||||
|
|
||||||
|
ObjectType obj(this->at(index));
|
||||||
|
// highlight DB models
|
||||||
|
if (obj.hasValidDbKey())
|
||||||
|
{
|
||||||
|
static const QBrush b(Qt::green);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||||
|
KeyType CListModelDbObjects<ObjectType, ContainerType, KeyType, 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>::isHighlightIndex(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (!index.isValid()) { return false; }
|
||||||
|
if (m_highlightKeys.isEmpty()) { return false; }
|
||||||
|
return m_highlightKeys.contains(dbKeyForIndex(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
// see here for the reason of thess forward instantiations
|
||||||
|
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||||
|
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>;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
@@ -9,25 +9,32 @@
|
|||||||
|
|
||||||
//! \file
|
//! \file
|
||||||
|
|
||||||
#ifndef BLACKGUI_MODELSWITHDBKEY_H
|
#ifndef BLACKGUI_LISTMODELDBOBJECTS_H
|
||||||
#define BLACKGUI_MODELSWITHDBKEY_H
|
#define BLACKGUI_LISTMODELDBOBJECTS_H
|
||||||
|
|
||||||
#include "listmodelbase.h"
|
#include "listmodelbase.h"
|
||||||
|
#include "blackgui/blackguiexport.h"
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
//! Base class for models with DB keys
|
//! List model for DB objects
|
||||||
template <typename ObjectType, typename ContainerType, typename KeyType = int, bool UseCompare = false>
|
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare = false> class CListModelDbObjects :
|
||||||
class CModelsWithDbKeysBase : public CListModelBase<ObjectType, ContainerType, UseCompare>
|
public CListModelBase<ObjectType, ContainerType, UseCompare>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CModelsWithDbKeysBase() {}
|
virtual ~CListModelDbObjects() {}
|
||||||
|
|
||||||
|
//! Highlight the DB models
|
||||||
|
bool highlightDbData() const { return m_highlightDbData; }
|
||||||
|
|
||||||
|
//! Highlight the DB models
|
||||||
|
void setHighlightDbData(bool highlightDbData) { m_highlightDbData = highlightDbData; }
|
||||||
|
|
||||||
//! Keys to be highlighted
|
//! Keys to be highlighted
|
||||||
void setHighlightDbKeys(const QList<KeyType> &keys) { m_highlightIntKeys = keys; }
|
void setHighlightDbKeys(const QList<KeyType> &keys) { m_highlightKeys = keys; }
|
||||||
|
|
||||||
//! Set color for highlighting
|
//! Set color for highlighting
|
||||||
void setHighlightColor(QColor color) { m_highlightColor = color; }
|
void setHighlightColor(QColor color) { m_highlightColor = color; }
|
||||||
@@ -42,13 +49,15 @@ namespace BlackGui
|
|||||||
bool isHighlightIndex(const QModelIndex &index) const;
|
bool isHighlightIndex(const QModelIndex &index) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! \copydoc CListModelBase::CListModelBase
|
//! \copydoc CListModelDbObjectsNonTemplate::CListModelDbObjectsNonTemplate
|
||||||
CModelsWithDbKeysBase(const QString &translationContext, QObject *parent = nullptr);
|
CListModelDbObjects(const QString &translationContext, QObject *parent = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<KeyType> m_highlightIntKeys; //!< keys to be highlighted
|
bool m_highlightDbData = false; //!< highlight if DB data entry (valid key)
|
||||||
|
QList<KeyType> m_highlightKeys; //!< keys to be highlighted
|
||||||
QColor m_highlightColor = Qt::green;
|
QColor m_highlightColor = Qt::green;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif // guard
|
#endif // guard
|
||||||
@@ -21,7 +21,7 @@ namespace BlackGui
|
|||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
CLiveryListModel::CLiveryListModel(QObject *parent) :
|
CLiveryListModel::CLiveryListModel(QObject *parent) :
|
||||||
CListModelBase("ModelLiveryList", parent)
|
CListModelDbObjects("ModelLiveryList", parent)
|
||||||
{
|
{
|
||||||
this->m_columns.addColumn(CColumn::standardString("id", CLivery::IndexDbIntegerKey, CDefaultFormatter::alignRightVCenter()));
|
this->m_columns.addColumn(CColumn::standardString("id", CLivery::IndexDbIntegerKey, CDefaultFormatter::alignRightVCenter()));
|
||||||
this->m_columns.addColumn(CColumn::standardString("code", CLivery::IndexCombinedCode));
|
this->m_columns.addColumn(CColumn::standardString("code", CLivery::IndexCombinedCode));
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
#include "blackmisc/aviation/liverylist.h"
|
#include "blackmisc/aviation/liverylist.h"
|
||||||
#include "blackgui/models/listmodelbase.h"
|
#include "blackgui/models/listmodeldbobjects.h"
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
@@ -23,10 +23,9 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
//! Distributor list model
|
//! Distributor list model
|
||||||
class BLACKGUI_EXPORT CLiveryListModel :
|
class BLACKGUI_EXPORT CLiveryListModel :
|
||||||
public CListModelBase<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList, true>
|
public CListModelDbObjects<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList, int, true>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
explicit CLiveryListModel(QObject *parent = nullptr);
|
explicit CLiveryListModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
/* Copyright (C) 2015
|
|
||||||
* 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 and at http://www.swift-project.org/license.html. 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 "modelswithdbkey.h"
|
|
||||||
#include "allmodelcontainers.h"
|
|
||||||
|
|
||||||
namespace BlackGui
|
|
||||||
{
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
|
||||||
CModelsWithDbKeysBase<ObjectType, ContainerType, KeyType, UseCompare>::CModelsWithDbKeysBase(const QString &translationContext, QObject *parent) :
|
|
||||||
CListModelBase<ObjectType, ContainerType, UseCompare>(translationContext, parent)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
|
||||||
QVariant CModelsWithDbKeysBase<ObjectType, ContainerType, KeyType, UseCompare>::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
|
||||||
if (role == Qt::BackgroundRole)
|
|
||||||
{
|
|
||||||
if (isHighlightIndex(index)) { return QBrush(m_highlightColor); }
|
|
||||||
}
|
|
||||||
return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
|
||||||
KeyType CModelsWithDbKeysBase<ObjectType, ContainerType, KeyType, 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 CModelsWithDbKeysBase<ObjectType, ContainerType, KeyType, UseCompare>::isHighlightIndex(const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
if (!index.isValid()) { return false; }
|
|
||||||
if (m_highlightIntKeys.isEmpty()) { return false; }
|
|
||||||
return m_highlightIntKeys.contains(dbKeyForIndex(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
// see here for the reason of thess forward instantiations
|
|
||||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
|
||||||
template class CModelsWithDbKeysBase<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList, int, true>;
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace
|
|
||||||
Reference in New Issue
Block a user