Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+174
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* AreaModel
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Norbert Thoden, NLE, 2020-06-29
|
||||
*/
|
||||
|
||||
#include "participant_shootback_area_model.h"
|
||||
|
||||
#include <LtsUtilsCore/variant_operators.h>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
#include <ParticipantManagement/ppm_translation.h>
|
||||
|
||||
#include <QApplication> // pixelMetric
|
||||
#include <QBuffer>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
//---------------------------------
|
||||
// AreaModel
|
||||
//---------------------------------
|
||||
AreaModel::AreaModel(QObject *parent)
|
||||
: BaseClass(
|
||||
{
|
||||
tr("Id"),
|
||||
tr("Name"),
|
||||
|
||||
// main config
|
||||
tr("Coords")
|
||||
},
|
||||
parent)
|
||||
, m_logger(getLogger("AreaModel"))
|
||||
{}
|
||||
|
||||
|
||||
bool AreaModel::initModel(const TargetInformation &targetInformation)
|
||||
{
|
||||
// insert Model
|
||||
INFO_LOG(m_logger) << "initModel - #AreaModel: " << targetInformation.shootbackAreas().size();
|
||||
|
||||
for (auto singleArea : qAsConst(targetInformation.shootbackAreas()))
|
||||
onShootbackAreaChanged(singleArea, DataModification::eAdded);
|
||||
|
||||
// updateColumnFilter
|
||||
connect(this, &AreaModel::rowsInserted, this, &AreaModel::updateColumnFilter);
|
||||
connect(this, &AreaModel::rowsRemoved, this, &AreaModel::updateColumnFilter);
|
||||
connect(this, &AreaModel::modelReset, this, &AreaModel::updateColumnFilter);
|
||||
// in case of changing value like hitsToKill:
|
||||
connect(this, &AreaModel::dataChanged, this, &AreaModel::updateColumnFilter);
|
||||
updateColumnFilter();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant AreaModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role == LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole &&
|
||||
orientation == Qt::Horizontal)
|
||||
{
|
||||
// a few QSet<QString> ==>
|
||||
const auto processString = [](const QSet<QString> &usedXYCont) -> QVariant
|
||||
{
|
||||
LtsWidgets::ComboboxFilterContent cfc;
|
||||
cfc.data.reserve(usedXYCont.size());
|
||||
LtsWidgets::ComboboxFilterData cfd;
|
||||
|
||||
for (const QString &value : usedXYCont)
|
||||
{
|
||||
cfd.data = value;
|
||||
cfd.text = value;
|
||||
cfc.data.push_back(cfd);
|
||||
}
|
||||
cfc.sortItems = true;
|
||||
return cfc.toVariant();
|
||||
};
|
||||
|
||||
if (section == Name)
|
||||
return processString(m_usedNames);
|
||||
}
|
||||
return BaseClass::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
QVariant AreaModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << " role=" << role
|
||||
<< " index = " << index.column();
|
||||
|
||||
if (!indexIsValid(index))
|
||||
return QVariant();
|
||||
if (role != Qt::DisplayRole &&
|
||||
role != Qt::DecorationRole &&
|
||||
role != Qt::ToolTipRole &&
|
||||
role != LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole)
|
||||
return QVariant();
|
||||
|
||||
const ShootbackArea &shootbackArea = m_vecData.at(index.row());
|
||||
|
||||
if (role == LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole)
|
||||
{
|
||||
if (index.column() == Name)
|
||||
return QString::fromStdString(shootbackArea.identifier());
|
||||
}
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
case Id:
|
||||
return 0; // shootbackArea.id();
|
||||
case Name:
|
||||
return QString::fromStdString(shootbackArea.identifier());
|
||||
case Coords:
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
} // switch
|
||||
|
||||
QPolygonF poly;
|
||||
|
||||
return QVariant(poly);
|
||||
}
|
||||
|
||||
void AreaModel::onShootbackAreaChanged(const ShootbackArea &data,
|
||||
const DataModification modType)
|
||||
{
|
||||
BaseClass::onDataChanged(data, modType);
|
||||
emit signalAreaNamesChanged();
|
||||
}
|
||||
|
||||
void AreaModel::updateColumnFilter()
|
||||
{
|
||||
m_usedNames.clear();
|
||||
for (const ShootbackArea &item : qAsConst(m_vecData))
|
||||
m_usedNames.insert(QString::fromStdString(item.identifier()));
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------
|
||||
// AreaProxyModel
|
||||
// --------------------------------------------------------
|
||||
void AreaProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
||||
{
|
||||
m_sourceModel = qobject_cast<AreaModel *>(sourceModel);
|
||||
BaseClass::setSourceModel(sourceModel);
|
||||
}
|
||||
|
||||
bool AreaProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
||||
{
|
||||
if (!m_sourceModel ||
|
||||
source_left.column() != source_right.column() ||
|
||||
source_left.row() < 0 || source_left.row() >= m_sourceModel->m_vecData.size() ||
|
||||
source_right.row() < 0 || source_right.row() >= m_sourceModel->m_vecData.size()
|
||||
)
|
||||
return BaseClass::lessThan(source_left, source_right);
|
||||
|
||||
const ShootbackArea &left = m_sourceModel->m_vecData.at(source_left.row());
|
||||
const ShootbackArea &right = m_sourceModel->m_vecData.at(source_right.row());
|
||||
switch (source_left.column())
|
||||
{
|
||||
// case AreaModel::Columns::Id:
|
||||
//return left.id() < right.id();
|
||||
case AreaModel::Columns::Name:
|
||||
return left.identifier() < right.identifier();
|
||||
|
||||
// case AreaModel::Columns::Center:
|
||||
// QString compare
|
||||
default:
|
||||
return LtsUtils::lessThan(source_left.data(), source_right.data());
|
||||
}
|
||||
return BaseClass::lessThan(source_left, source_right);
|
||||
}
|
||||
|
||||
} // namespace ParticipantManagement
|
||||
Reference in new issue
Block a user