Split up listmodelbase

This is to reduce the number of symbols per single object file which caused MinGW 32 bit build to fail.
- Moved CListModelBaseNonTemplate into its own file
- Separated the template instantiations into domain specific source files
This commit is contained in:
Roland Rossgotterer
2018-12-10 15:54:14 +01:00
committed by Klaus Basan
parent 2bf9ff6d8b
commit 11f328b5c3
9 changed files with 513 additions and 348 deletions

View File

@@ -10,25 +10,16 @@
// Drag and drop docu:
// http://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views
#include "blackgui/models/columnformatters.h"
#include "blackgui/models/listmodelbase.h"
#include "blackgui/models/allmodelcontainers.h"
#include "blackgui/guiutility.h"
#include "blackmisc/compare.h"
#include "blackmisc/predicates.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/fileutils.h"
#include "blackmisc/sequence.h"
#include "blackmisc/variant.h"
#include "blackmisc/verify.h"
#include "blackmisc/worker.h"
#include <QFlags>
#include <QJsonDocument>
#include <QList>
#include <QMimeData>
#include <QtGlobal>
#include <QFileInfo>
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
@@ -37,172 +28,6 @@ namespace BlackGui
{
namespace Models
{
int CListModelBaseNonTemplate::columnCount(const QModelIndex &modelIndex) const
{
Q_UNUSED(modelIndex);
int c = m_columns.size();
return c;
}
QVariant CListModelBaseNonTemplate::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation != Qt::Horizontal) { return QVariant(); }
const bool handled = (role == Qt::DisplayRole || role == Qt::ToolTipRole || role == Qt::InitialSortOrderRole);
if (!handled) { return QVariant(); }
if (section < 0 || section >= m_columns.size()) { return QVariant(); }
if (role == Qt::DisplayRole)
{
const QString header = m_columns.at(section).getColumnName(false);
return QVariant(header);
}
if (role == Qt::ToolTipRole)
{
const QString header = m_columns.at(section).getColumnToolTip(false);
return header.isEmpty() ? QVariant() : QVariant(header);
}
return QVariant();
}
QModelIndex CListModelBaseNonTemplate::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
return QStandardItemModel::createIndex(row, column);
}
QModelIndex CListModelBaseNonTemplate::parent(const QModelIndex &child) const
{
Q_UNUSED(child);
return QModelIndex();
}
CPropertyIndex CListModelBaseNonTemplate::columnToPropertyIndex(int column) const
{
return m_columns.columnToPropertyIndex(column);
}
int CListModelBaseNonTemplate::propertyIndexToColumn(const CPropertyIndex &propertyIndex) const
{
return m_columns.propertyIndexToColumn(propertyIndex);
}
CPropertyIndex CListModelBaseNonTemplate::modelIndexToPropertyIndex(const QModelIndex &index) const
{
return this->columnToPropertyIndex(index.column());
}
void CListModelBaseNonTemplate::sortByPropertyIndex(const CPropertyIndex &propertyIndex, Qt::SortOrder order)
{
const int column = this->propertyIndexToColumn(propertyIndex);
this->sort(column, order);
}
bool CListModelBaseNonTemplate::setSortColumnByPropertyIndex(const CPropertyIndex &propertyIndex)
{
const int column = m_columns.propertyIndexToColumn(propertyIndex);
if (m_sortColumn == column) { return false; } // not changed
m_sortColumn = column;
return true; // changed
}
bool CListModelBaseNonTemplate::setSorting(const CPropertyIndex &propertyIndex, Qt::SortOrder order)
{
const bool changedColumn = this->setSortColumnByPropertyIndex(propertyIndex);
const bool changedOrder = (m_sortOrder == order);
m_sortOrder = order;
return changedColumn || changedOrder;
}
bool CListModelBaseNonTemplate::hasValidSortColumn() const
{
if (!(m_sortColumn >= 0 && m_sortColumn < m_columns.size())) { return false; }
return m_columns.isSortable(m_sortColumn);
}
Qt::ItemFlags CListModelBaseNonTemplate::flags(const QModelIndex &index) const
{
Qt::ItemFlags f = QStandardItemModel::flags(index);
if (!index.isValid()) { return f; }
const bool editable = m_columns.isEditable(index);
f = editable ? (f | Qt::ItemIsEditable) : (f & ~Qt::ItemIsEditable);
// flags from formatter
const CDefaultFormatter *formatter = m_columns.getFormatter(index);
if (formatter) { f = formatter->flags(f, editable); }
// drag and drop
f = f | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
return f;
}
const QString &CListModelBaseNonTemplate::getTranslationContext() const
{
return m_columns.getTranslationContext();
}
Qt::DropActions CListModelBaseNonTemplate::supportedDragActions() const
{
return isOrderable() ? Qt::CopyAction | Qt::MoveAction : Qt::CopyAction;
}
Qt::DropActions CListModelBaseNonTemplate::supportedDropActions() const
{
return m_dropActions;
}
QStringList CListModelBaseNonTemplate::mimeTypes() const
{
static const QStringList mimes({ "application/swift.container.json" });
return mimes;
}
void CListModelBaseNonTemplate::markDestroyed()
{
m_modelDestroyed = true;
}
bool CListModelBaseNonTemplate::isModelDestroyed()
{
return m_modelDestroyed;
}
void CListModelBaseNonTemplate::clearHighlighting()
{
// can be overridden to delete highlighting
}
bool CListModelBaseNonTemplate::hasHighlightedRows() const
{
return false;
// can be overridden to enable highlighting based operations
}
void CListModelBaseNonTemplate::emitDataChanged(int startRowIndex, int endRowIndex)
{
BLACK_VERIFY_X(startRowIndex <= endRowIndex, Q_FUNC_INFO, "check rows");
BLACK_VERIFY_X(startRowIndex >= 0 && endRowIndex >= 0, Q_FUNC_INFO, "check rows");
const int columns = columnCount();
const int rows = rowCount();
if (columns < 1) { return; }
if (startRowIndex < 0) { startRowIndex = 0; }
if (endRowIndex >= rows) { endRowIndex = rows - 1; }
const QModelIndex topLeft(createIndex(startRowIndex, 0));
const QModelIndex bottomRight(createIndex(endRowIndex, columns - 1));
emit this->dataChanged(topLeft, bottomRight);
}
CListModelBaseNonTemplate::CListModelBaseNonTemplate(const QString &translationContext, QObject *parent)
: QStandardItemModel(parent), m_columns(translationContext), m_sortColumn(-1), m_sortOrder(Qt::AscendingOrder)
{
// non unique default name, set translation context as default
this->setObjectName(translationContext);
// connect
connect(this, &CListModelBaseNonTemplate::dataChanged, this, &CListModelBaseNonTemplate::onDataChanged);
}
template <typename ObjectType, typename ContainerType, bool UseCompare>
CListModelBase<ObjectType, ContainerType, UseCompare>::CListModelBase(const QString &translationContext, QObject *parent)
: CListModelBaseNonTemplate(translationContext, parent)
@@ -770,33 +595,5 @@ namespace BlackGui
return false;
}
// 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::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::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::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::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>;
} // namespace
} // namespace