CPoiMapSidebar: Make use of ranged for
This commit is contained in:
parent
d8817d8cb2
commit
872fe90a41
|
@ -77,20 +77,20 @@ void CPoiMapSidebar::HighlightPoiModels(const QModelIndex& rkIndex)
|
||||||
bool Important = IsImportant(SourceIndex);
|
bool Important = IsImportant(SourceIndex);
|
||||||
|
|
||||||
// Highlight the meshes
|
// Highlight the meshes
|
||||||
for (int iMdl = 0; iMdl < rkModels.size(); iMdl++)
|
for (auto& model : rkModels)
|
||||||
{
|
{
|
||||||
rkModels[iMdl]->SetScanOverlayEnabled(true);
|
model->SetScanOverlayEnabled(true);
|
||||||
rkModels[iMdl]->SetScanOverlayColor(Important ? skImportantColor : skNormalColor);
|
model->SetScanOverlayColor(Important ? skImportantColor : skNormalColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPoiMapSidebar::UnhighlightPoiModels(const QModelIndex& rkIndex)
|
void CPoiMapSidebar::UnhighlightPoiModels(const QModelIndex& rkIndex)
|
||||||
{
|
{
|
||||||
QModelIndex SourceIndex = mModel.mapToSource(rkIndex);
|
const QModelIndex SourceIndex = mModel.mapToSource(rkIndex);
|
||||||
const QList<CModelNode*>& rkModels = mSourceModel.GetPoiMeshList(SourceIndex);
|
const QList<CModelNode*>& rkModels = mSourceModel.GetPoiMeshList(SourceIndex);
|
||||||
|
|
||||||
for (int iMdl = 0; iMdl < rkModels.size(); iMdl++)
|
for (const auto& model : rkModels)
|
||||||
RevertModelOverlay(rkModels[iMdl]);
|
RevertModelOverlay(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPoiMapSidebar::HighlightModel(const QModelIndex& rkIndex, CModelNode *pNode)
|
void CPoiMapSidebar::HighlightModel(const QModelIndex& rkIndex, CModelNode *pNode)
|
||||||
|
@ -115,8 +115,9 @@ void CPoiMapSidebar::RevertModelOverlay(CModelNode *pModel)
|
||||||
QModelIndex Selected = GetSelectedRow();
|
QModelIndex Selected = GetSelectedRow();
|
||||||
|
|
||||||
if (mSourceModel.IsModelMapped(Selected, pModel))
|
if (mSourceModel.IsModelMapped(Selected, pModel))
|
||||||
|
{
|
||||||
HighlightModel(Selected, pModel);
|
HighlightModel(Selected, pModel);
|
||||||
|
}
|
||||||
// If it's not mapped to the selected POI, then check whether it's mapped to any others.
|
// If it's not mapped to the selected POI, then check whether it's mapped to any others.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -134,7 +135,6 @@ void CPoiMapSidebar::RevertModelOverlay(CModelNode *pModel)
|
||||||
UnhighlightModel(pModel);
|
UnhighlightModel(pModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (mHighlightMode == EHighlightMode::HighlightSelected)
|
else if (mHighlightMode == EHighlightMode::HighlightSelected)
|
||||||
{
|
{
|
||||||
QModelIndex Index = GetSelectedRow();
|
QModelIndex Index = GetSelectedRow();
|
||||||
|
@ -144,10 +144,11 @@ void CPoiMapSidebar::RevertModelOverlay(CModelNode *pModel)
|
||||||
else
|
else
|
||||||
UnhighlightModel(pModel);
|
UnhighlightModel(pModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
UnhighlightModel(pModel);
|
UnhighlightModel(pModel);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CPoiMapSidebar::EPickType CPoiMapSidebar::GetRealPickType(bool AltPressed) const
|
CPoiMapSidebar::EPickType CPoiMapSidebar::GetRealPickType(bool AltPressed) const
|
||||||
|
@ -241,14 +242,14 @@ void CPoiMapSidebar::OnSelectionChanged(const QItemSelection& rkSelected, const
|
||||||
// Clear highlight on deselected models
|
// Clear highlight on deselected models
|
||||||
QModelIndexList DeselectedIndices = rkDeselected.indexes();
|
QModelIndexList DeselectedIndices = rkDeselected.indexes();
|
||||||
|
|
||||||
for (int iIdx = 0; iIdx < DeselectedIndices.size(); iIdx++)
|
for (const auto& index : DeselectedIndices)
|
||||||
UnhighlightPoiModels(DeselectedIndices[iIdx]);
|
UnhighlightPoiModels(index);
|
||||||
|
|
||||||
// Highlight newly selected models
|
// Highlight newly selected models
|
||||||
QModelIndexList SelectedIndices = rkSelected.indexes();
|
const QModelIndexList SelectedIndices = rkSelected.indexes();
|
||||||
|
|
||||||
for (int iIdx = 0; iIdx < SelectedIndices.size(); iIdx++)
|
for (const auto& index : SelectedIndices)
|
||||||
HighlightPoiModels(SelectedIndices[iIdx]);
|
HighlightPoiModels(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,38 +376,40 @@ void CPoiMapSidebar::OnPoiPicked(const SRayIntersection& rkIntersect, QMouseEven
|
||||||
|
|
||||||
void CPoiMapSidebar::OnModelPicked(const SRayIntersection& rkRayIntersect, QMouseEvent* pEvent)
|
void CPoiMapSidebar::OnModelPicked(const SRayIntersection& rkRayIntersect, QMouseEvent* pEvent)
|
||||||
{
|
{
|
||||||
if (!rkRayIntersect.pNode) return;
|
if (!rkRayIntersect.pNode)
|
||||||
|
return;
|
||||||
|
|
||||||
// Check for valid selection
|
// Check for valid selection
|
||||||
QModelIndexList Indices = ui->ListView->selectionModel()->selectedRows();
|
const QModelIndexList Indices = ui->ListView->selectionModel()->selectedRows();
|
||||||
if (Indices.isEmpty()) return;
|
if (Indices.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
// Map selection to source model
|
// Map selection to source model
|
||||||
QModelIndexList SourceIndices;
|
QModelIndexList SourceIndices;
|
||||||
for (auto it = Indices.begin(); it != Indices.end(); it++)
|
SourceIndices.reserve(Indices.size());
|
||||||
SourceIndices << mModel.mapToSource(*it);
|
for (const auto& index : Indices)
|
||||||
|
SourceIndices.push_back(mModel.mapToSource(index));
|
||||||
|
|
||||||
// If alt is pressed, invert the pick mode
|
// If alt is pressed, invert the pick mode
|
||||||
CModelNode *pModel = static_cast<CModelNode*>(rkRayIntersect.pNode);
|
CModelNode *pModel = static_cast<CModelNode*>(rkRayIntersect.pNode);
|
||||||
|
|
||||||
bool AltPressed = (pEvent->modifiers() & Qt::AltModifier) != 0;
|
const bool AltPressed = (pEvent->modifiers() & Qt::AltModifier) != 0;
|
||||||
EPickType PickType = GetRealPickType(AltPressed);
|
const EPickType PickType = GetRealPickType(AltPressed);
|
||||||
|
|
||||||
// Add meshes
|
// Add meshes
|
||||||
if (PickType == EPickType::AddMeshes)
|
if (PickType == EPickType::AddMeshes)
|
||||||
{
|
{
|
||||||
for (auto it = SourceIndices.begin(); it != SourceIndices.end(); it++)
|
for (const auto& index : SourceIndices)
|
||||||
mSourceModel.AddMapping(*it, pModel);
|
mSourceModel.AddMapping(index, pModel);
|
||||||
|
|
||||||
if (mHighlightMode != EHighlightMode::HighlightNone)
|
if (mHighlightMode != EHighlightMode::HighlightNone)
|
||||||
HighlightModel(SourceIndices.front(), pModel);
|
HighlightModel(SourceIndices.front(), pModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove meshes
|
// Remove meshes
|
||||||
else if (PickType == EPickType::RemoveMeshes)
|
else if (PickType == EPickType::RemoveMeshes)
|
||||||
{
|
{
|
||||||
for (auto it = SourceIndices.begin(); it != SourceIndices.end(); it++)
|
for (const auto& index : SourceIndices)
|
||||||
mSourceModel.RemoveMapping(*it, pModel);
|
mSourceModel.RemoveMapping(index, pModel);
|
||||||
|
|
||||||
if (mHighlightMode != EHighlightMode::HighlightNone)
|
if (mHighlightMode != EHighlightMode::HighlightNone)
|
||||||
RevertModelOverlay(mpHoverModel);
|
RevertModelOverlay(mpHoverModel);
|
||||||
|
@ -425,10 +428,10 @@ void CPoiMapSidebar::OnModelHover(const SRayIntersection& rkIntersect, QMouseEve
|
||||||
|
|
||||||
// If the left mouse button is pressed, treat this as a click.
|
// If the left mouse button is pressed, treat this as a click.
|
||||||
if (pEvent->buttons() & Qt::LeftButton)
|
if (pEvent->buttons() & Qt::LeftButton)
|
||||||
|
{
|
||||||
OnModelPicked(rkIntersect, pEvent);
|
OnModelPicked(rkIntersect, pEvent);
|
||||||
|
}
|
||||||
// Otherwise, process as a mouseover
|
else // Otherwise, process as a mouseover
|
||||||
else
|
|
||||||
{
|
{
|
||||||
QModelIndex Index = GetSelectedRow();
|
QModelIndex Index = GetSelectedRow();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue