mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
refs #501, compareByPropertyIndex (performance for sort)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
1e57ce7ecb
commit
0c94922bd6
@@ -19,7 +19,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
CAircraftIcaoCodeListModel::CAircraftIcaoCodeListModel(QObject *parent) :
|
||||
CListModelBase<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList>("AircraftIcaoListModel", parent)
|
||||
CListModelBase("AircraftIcaoListModel", parent)
|
||||
{
|
||||
this->m_columns.addColumn(CColumn::standardString("id", CAircraftIcaoCode::IndexDbIntegerKey, CDefaultFormatter::alignRightVCenter()));
|
||||
this->m_columns.addColumn(CColumn::standardValueObject("ICAO", CAircraftIcaoCode::IndexAircraftDesignator));
|
||||
|
||||
@@ -21,13 +21,11 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
|
||||
//! Airport list model
|
||||
class BLACKGUI_EXPORT CAircraftIcaoCodeListModel : public CListModelBase<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList>
|
||||
class BLACKGUI_EXPORT CAircraftIcaoCodeListModel :
|
||||
public CListModelBase<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList, true>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Constructor
|
||||
explicit CAircraftIcaoCodeListModel(QObject *parent = nullptr);
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
CAircraftModelListModel::CAircraftModelListModel(AircraftModelMode mode, QObject *parent) : CListModelBase("CAircraftModelListModel", parent)
|
||||
CAircraftModelListModel::CAircraftModelListModel(AircraftModelMode mode, QObject *parent) :
|
||||
CListModelBase("CAircraftModelListModel", parent)
|
||||
{
|
||||
this->setAircraftModelMode(mode);
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Aircraft model list model
|
||||
class BLACKGUI_EXPORT CAircraftModelListModel : public CListModelBase<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList>
|
||||
class BLACKGUI_EXPORT CAircraftModelListModel :
|
||||
public CListModelBase<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList, true>
|
||||
{
|
||||
public:
|
||||
//! How to display
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
CAirlineIcaoCodeListModel::CAirlineIcaoCodeListModel(QObject *parent) :
|
||||
CListModelBase<BlackMisc::Aviation::CAirlineIcaoCode, BlackMisc::Aviation::CAirlineIcaoCodeList>("AircraftIcaoListModel", parent)
|
||||
CListModelBase("AircraftIcaoListModel", parent)
|
||||
{
|
||||
this->m_columns.addColumn(CColumn::standardString("id", CAirlineIcaoCode::IndexDbIntegerKey, CDefaultFormatter::alignRightVCenter()));
|
||||
this->m_columns.addColumn(CColumn::standardValueObject("ICAO", CAirlineIcaoCode::IndexAirlineDesignator));
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Airport list model
|
||||
class BLACKGUI_EXPORT CAirlineIcaoCodeListModel : public CListModelBase<BlackMisc::Aviation::CAirlineIcaoCode, BlackMisc::Aviation::CAirlineIcaoCodeList>
|
||||
class BLACKGUI_EXPORT CAirlineIcaoCodeListModel : public CListModelBase<BlackMisc::Aviation::CAirlineIcaoCode, BlackMisc::Aviation::CAirlineIcaoCodeList, true>
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
CAirportListModel::CAirportListModel(QObject *parent) :
|
||||
CListModelBase<BlackMisc::Aviation::CAirport, BlackMisc::Aviation::CAirportList>("AirportListModel", parent)
|
||||
CListModelBase("AirportListModel", parent)
|
||||
{
|
||||
this->m_columns.addColumn(CColumn::standardValueObject("ICAO", CAirport::IndexIcao));
|
||||
this->m_columns.addColumn(CColumn("distance", CAirport::IndexDistanceToOwnAircraft, new CAirspaceDistanceFormatter()));
|
||||
|
||||
@@ -22,7 +22,8 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Airport list model
|
||||
class BLACKGUI_EXPORT CAirportListModel : public CListModelBase<BlackMisc::Aviation::CAirport, BlackMisc::Aviation::CAirportList>
|
||||
class BLACKGUI_EXPORT CAirportListModel :
|
||||
public CListModelBase<BlackMisc::Aviation::CAirport, BlackMisc::Aviation::CAirportList, true>
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
CCountryListModel::CCountryListModel(QObject *parent) :
|
||||
CListModelBase<BlackMisc::CCountry, BlackMisc::CCountryList>("CountryListModel", parent)
|
||||
CListModelBase("CountryListModel", parent)
|
||||
{
|
||||
CColumn col("country", CCountry::IndexIcon);
|
||||
col.setSortPropertyIndex(CCountry::IndexIsoCode);
|
||||
|
||||
@@ -22,9 +22,9 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Country list model
|
||||
class BLACKGUI_EXPORT CCountryListModel : public CListModelBase<BlackMisc::CCountry, BlackMisc::CCountryList>
|
||||
class BLACKGUI_EXPORT CCountryListModel :
|
||||
public CListModelBase<BlackMisc::CCountry, BlackMisc::CCountryList, true>
|
||||
{
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CCountryListModel(QObject *parent = nullptr);
|
||||
@@ -32,6 +32,6 @@ namespace BlackGui
|
||||
//! Destructor
|
||||
virtual ~CCountryListModel() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
#endif // guard
|
||||
|
||||
@@ -22,7 +22,8 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Distributor list model
|
||||
class BLACKGUI_EXPORT CDistributorListModel : public CListModelBase<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList>
|
||||
class BLACKGUI_EXPORT CDistributorListModel :
|
||||
public CListModelBase<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList, true>
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/json.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
#include <QMimeData>
|
||||
#include <QJsonDocument>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -160,23 +163,23 @@ namespace BlackGui
|
||||
this->setObjectName(translationContext);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
int CListModelBase<ObjectType, ContainerType>::rowCount(const QModelIndex &parentIndex) const
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
int CListModelBase<ObjectType, ContainerType, UseCompare>::rowCount(const QModelIndex &parentIndex) const
|
||||
{
|
||||
Q_UNUSED(parentIndex);
|
||||
return this->getContainerOrFilteredContainer().size();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
bool CListModelBase<ObjectType, ContainerType>::isValidIndex(const QModelIndex &index) const
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, 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>
|
||||
QVariant CListModelBase<ObjectType, ContainerType>::data(const QModelIndex &index, int role) const
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
QVariant CListModelBase<ObjectType, ContainerType, UseCompare>::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
// check / init
|
||||
if (!this->isValidIndex(index)) { return QVariant(); }
|
||||
@@ -190,8 +193,8 @@ namespace BlackGui
|
||||
return formatter->data(role, obj.propertyByIndex(propertyIndex)).getQVariant();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
bool CListModelBase<ObjectType, ContainerType>::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, 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))
|
||||
@@ -234,8 +237,8 @@ namespace BlackGui
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
int CListModelBase<ObjectType, ContainerType>::update(const ContainerType &container, bool sort)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
int CListModelBase<ObjectType, ContainerType, UseCompare>::update(const ContainerType &container, bool sort)
|
||||
{
|
||||
if (m_modelDestroyed) { return 0; }
|
||||
|
||||
@@ -262,8 +265,8 @@ namespace BlackGui
|
||||
return newSize;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::update(const QModelIndex &index, const ObjectType &object)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::update(const QModelIndex &index, const ObjectType &object)
|
||||
{
|
||||
if (m_modelDestroyed) { return; }
|
||||
if (index.row() >= this->m_container.size()) { return; }
|
||||
@@ -274,14 +277,14 @@ namespace BlackGui
|
||||
emit this->dataChanged(i1, i2); // which range has been changed
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::update(int rowIndex, const ObjectType &object)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::update(int rowIndex, const ObjectType &object)
|
||||
{
|
||||
this->update(this->index(rowIndex, 0), object);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
CWorker *CListModelBase<ObjectType, ContainerType>::updateAsync(const ContainerType &container, bool sort)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
CWorker *CListModelBase<ObjectType, ContainerType, UseCompare>::updateAsync(const ContainerType &container, bool sort)
|
||||
{
|
||||
Q_UNUSED(sort);
|
||||
if (m_modelDestroyed) { return nullptr; }
|
||||
@@ -291,7 +294,7 @@ namespace BlackGui
|
||||
{
|
||||
return this->sortContainerByColumn(container, sortColumn, sortOrder);
|
||||
});
|
||||
worker->thenWithResult<ContainerType>(this, [this](const ContainerType &sortedContainer)
|
||||
worker->thenWithResult<ContainerType>(this, [this](const ContainerType & sortedContainer)
|
||||
{
|
||||
if (this->m_modelDestroyed) { return; }
|
||||
this->ps_updateContainer(CVariant::from(sortedContainer), false);
|
||||
@@ -300,8 +303,8 @@ namespace BlackGui
|
||||
return worker;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::updateContainerMaybeAsync(const ContainerType &container, bool sort)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::updateContainerMaybeAsync(const ContainerType &container, bool sort)
|
||||
{
|
||||
if (m_modelDestroyed) { return; }
|
||||
if (container.size() > asyncThreshold && sort)
|
||||
@@ -315,14 +318,14 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
bool CListModelBase<ObjectType, ContainerType>::hasFilter() const
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::hasFilter() const
|
||||
{
|
||||
return m_filter && m_filter->isValid() ? true : false;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::removeFilter()
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::removeFilter()
|
||||
{
|
||||
if (!this->hasFilter()) { return; }
|
||||
this->m_filter.reset(nullptr);
|
||||
@@ -332,8 +335,8 @@ namespace BlackGui
|
||||
this->emitRowCountChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::takeFilterOwnership(std::unique_ptr<IModelFilter<ContainerType> > &filter)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::takeFilterOwnership(std::unique_ptr<IModelFilter<ContainerType> > &filter)
|
||||
{
|
||||
if (!filter)
|
||||
{
|
||||
@@ -354,8 +357,8 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
const ObjectType &CListModelBase<ObjectType, ContainerType>::at(const QModelIndex &index) const
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
const ObjectType &CListModelBase<ObjectType, ContainerType, UseCompare>::at(const QModelIndex &index) const
|
||||
{
|
||||
if (index.row() < 0 || index.row() >= this->rowCount())
|
||||
{
|
||||
@@ -368,14 +371,14 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
const ContainerType &CListModelBase<ObjectType, ContainerType>::getContainer() const
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
const ContainerType &CListModelBase<ObjectType, ContainerType, UseCompare>::getContainer() const
|
||||
{
|
||||
return this->m_container;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::push_back(const ObjectType &object)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::push_back(const ObjectType &object)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), this->m_container.size(), this->m_container.size());
|
||||
this->m_container.push_back(object);
|
||||
@@ -384,8 +387,8 @@ namespace BlackGui
|
||||
this->emitRowCountChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::insert(const ObjectType &object)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::insert(const ObjectType &object)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), 0, 0);
|
||||
this->m_container.insert(this->m_container.begin(), object);
|
||||
@@ -400,8 +403,8 @@ namespace BlackGui
|
||||
this->emitRowCountChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::remove(const ObjectType &object)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::remove(const ObjectType &object)
|
||||
{
|
||||
int oldSize = this->m_container.size();
|
||||
beginRemoveRows(QModelIndex(), 0, 0);
|
||||
@@ -420,8 +423,8 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::clear()
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::clear()
|
||||
{
|
||||
beginResetModel();
|
||||
this->m_container.clear();
|
||||
@@ -430,21 +433,21 @@ namespace BlackGui
|
||||
this->emitRowCountChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
bool CListModelBase<ObjectType, ContainerType>::isEmpty() const
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::isEmpty() const
|
||||
{
|
||||
return this->m_container.isEmpty();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
int CListModelBase<ObjectType, ContainerType>::performUpdateContainer(const BlackMisc::CVariant &variant, bool sort)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
int CListModelBase<ObjectType, ContainerType, UseCompare>::performUpdateContainer(const BlackMisc::CVariant &variant, bool sort)
|
||||
{
|
||||
ContainerType c(variant.to<ContainerType>());
|
||||
return this->update(c, sort);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
const ContainerType &CListModelBase<ObjectType, ContainerType>::getContainerOrFilteredContainer() const
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
const ContainerType &CListModelBase<ObjectType, ContainerType, UseCompare>::getContainerOrFilteredContainer() const
|
||||
{
|
||||
if (!this->hasFilter())
|
||||
{
|
||||
@@ -453,8 +456,8 @@ namespace BlackGui
|
||||
return m_containerFiltered;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::updateFilteredContainer()
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::updateFilteredContainer()
|
||||
{
|
||||
if (this->hasFilter())
|
||||
{
|
||||
@@ -466,21 +469,21 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::emitRowCountChanged()
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::emitRowCountChanged()
|
||||
{
|
||||
int n = this->getContainerOrFilteredContainer().size();
|
||||
emit this->rowCountChanged(n, this->hasFilter());
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::sort()
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::sort()
|
||||
{
|
||||
this->sort(this->getSortColumn(), this->getSortOrder());
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::sort(int column, Qt::SortOrder order)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
if (column == this->m_sortedColumn && order == this->m_sortOrder) { return; }
|
||||
|
||||
@@ -496,8 +499,8 @@ namespace BlackGui
|
||||
this->updateContainerMaybeAsync(this->m_container, true);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::truncate(int maxNumber, bool forceSort)
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::truncate(int maxNumber, bool forceSort)
|
||||
{
|
||||
if (this->rowCount() <= maxNumber) { return; }
|
||||
if (forceSort)
|
||||
@@ -509,8 +512,8 @@ namespace BlackGui
|
||||
this->updateContainerMaybeAsync(container, false);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
ContainerType CListModelBase<ObjectType, ContainerType>::sortContainerByColumn(const ContainerType &container, int column, Qt::SortOrder order) const
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
ContainerType CListModelBase<ObjectType, ContainerType, UseCompare>::sortContainerByColumn(const ContainerType &container, int column, Qt::SortOrder order) const
|
||||
{
|
||||
if (m_modelDestroyed) { return container; }
|
||||
if (container.size() < 2 || !this->m_columns.isSortable(column))
|
||||
@@ -527,19 +530,23 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
// sort the values
|
||||
std::integral_constant<bool, UseCompare> marker {};
|
||||
const auto p = [ = ](const ObjectType & a, const ObjectType & b) -> bool
|
||||
{
|
||||
BlackMisc::CVariant aQv = a.propertyByIndex(propertyIndex);
|
||||
BlackMisc::CVariant bQv = b.propertyByIndex(propertyIndex);
|
||||
return (order == Qt::AscendingOrder) ? (aQv < bQv) : (bQv < aQv);
|
||||
return Private::compareForModelSort<ObjectType>(a, b, order, propertyIndex, marker);
|
||||
};
|
||||
|
||||
//! \todo Time measurement will be removed
|
||||
QTime t;
|
||||
t.start();
|
||||
const ContainerType sorted = container.sorted(p);
|
||||
int te = t.elapsed();
|
||||
CLogMessage(this).info("Sorted %1 in %2") << typeid(ObjectType).name() << te;
|
||||
return sorted;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
QMimeData *CListModelBase<ObjectType, ContainerType>::mimeData(const QModelIndexList &indexes) const
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
QMimeData *CListModelBase<ObjectType, ContainerType, UseCompare>::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
QMimeData *mimeData = new QMimeData();
|
||||
if (indexes.isEmpty()) { return mimeData; }
|
||||
@@ -567,22 +574,22 @@ namespace BlackGui
|
||||
|
||||
// see here for the reason of thess forward instantiations
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
template class CListModelBase<BlackMisc::CIdentifier, BlackMisc::CIdentifierList>;
|
||||
template class CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
||||
template class CListModelBase<BlackMisc::CNameVariantPair, BlackMisc::CNameVariantPairList>;
|
||||
template class CListModelBase<BlackMisc::CCountry, BlackMisc::CCountryList>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAtcStation, BlackMisc::Aviation::CAtcStationList>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAirport, BlackMisc::Aviation::CAirportList>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAirlineIcaoCode, BlackMisc::Aviation::CAirlineIcaoCodeList>;
|
||||
template class CListModelBase<BlackMisc::Network::CServer, BlackMisc::Network::CServerList>;
|
||||
template class CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList>;
|
||||
template class CListModelBase<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>;
|
||||
template class CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::Simulation::CSimulatedAircraftList>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList, true>;
|
||||
template class CListModelBase<BlackMisc::CIdentifier, BlackMisc::CIdentifierList, false>;
|
||||
template class CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList, false>;
|
||||
template class CListModelBase<BlackMisc::CNameVariantPair, BlackMisc::CNameVariantPairList, false>;
|
||||
template class CListModelBase<BlackMisc::CCountry, BlackMisc::CCountryList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAtcStation, BlackMisc::Aviation::CAtcStationList, false>;
|
||||
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::Network::CServer, BlackMisc::Network::CServerList, false>;
|
||||
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::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>;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
#include "blackgui/models/columns.h"
|
||||
#include "blackgui/models/modelfilter.h"
|
||||
#include "blackmisc/worker.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include <QAbstractItemModel>
|
||||
#include <QThread>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -128,9 +128,8 @@ namespace BlackGui
|
||||
};
|
||||
|
||||
//! List model
|
||||
template <typename ObjectType, typename ContainerType> class CListModelBase : public CListModelBaseNonTemplate
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare = false> class CListModelBase : public CListModelBaseNonTemplate
|
||||
{
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
virtual ~CListModelBase() {}
|
||||
@@ -249,6 +248,28 @@ namespace BlackGui
|
||||
ContainerType m_containerFiltered; //!< cache for filtered container data
|
||||
};
|
||||
|
||||
namespace Private
|
||||
{
|
||||
//! Sort with compare function
|
||||
template<class ObjectType>
|
||||
bool compareForModelSort(const ObjectType &a, const ObjectType &b, Qt::SortOrder order, const BlackMisc::CPropertyIndex &index, std::true_type)
|
||||
{
|
||||
int c = a.comparePropertyByIndex(b, index);
|
||||
if (c == 0) { return false; }
|
||||
return (order == Qt::AscendingOrder) ? (c > 0) : (c < 0);
|
||||
}
|
||||
|
||||
//! Sort without compare function
|
||||
template <typename ObjectType>
|
||||
bool compareForModelSort(const ObjectType &a, const ObjectType &b, Qt::SortOrder order, const BlackMisc::CPropertyIndex &index, std::false_type)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
BlackMisc::CVariant aQv = a.propertyByIndex(index);
|
||||
BlackMisc::CVariant bQv = b.propertyByIndex(index);
|
||||
return (order == Qt::AscendingOrder) ? (aQv < bQv) : (bQv < aQv);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
#endif // guard
|
||||
|
||||
@@ -22,7 +22,8 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Distributor list model
|
||||
class BLACKGUI_EXPORT CLiveryListModel : public CListModelBase<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList>
|
||||
class BLACKGUI_EXPORT CLiveryListModel :
|
||||
public CListModelBase<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList, true>
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ namespace BlackGui
|
||||
{
|
||||
|
||||
//! Aircraft list model
|
||||
class BLACKGUI_EXPORT CSimulatedAircraftListModel : public CListModelBase<BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::Simulation::CSimulatedAircraftList>
|
||||
class BLACKGUI_EXPORT CSimulatedAircraftListModel :
|
||||
public CListModelBase<BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::Simulation::CSimulatedAircraftList, true>
|
||||
{
|
||||
|
||||
public:
|
||||
//! Model modes
|
||||
enum AircraftMode
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace BlackGui
|
||||
* Constructor
|
||||
*/
|
||||
CUserListModel::CUserListModel(UserMode userMode, QObject *parent) :
|
||||
CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList>("ModelUserList", parent), m_userMode(NotSet)
|
||||
CListModelBase("ModelUserList", parent), m_userMode(NotSet)
|
||||
{
|
||||
this->setUserMode(userMode);
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ namespace BlackGui
|
||||
/*!
|
||||
* User list model
|
||||
*/
|
||||
class BLACKGUI_EXPORT CUserListModel : public CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList>
|
||||
class BLACKGUI_EXPORT CUserListModel :
|
||||
public CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList, true>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! What level of detail
|
||||
|
||||
Reference in New Issue
Block a user