Safely sort view layers
Changing view order of only some layers can cause overwriting of the
original layer if not pre-staged
Fixes https://gitlab.com/kicad/code/kicad/issues/10283
(cherry picked from commit 3e6bf7814b
)
This commit is contained in:
parent
fd9d923bb7
commit
ac9693bb8d
|
@ -679,19 +679,13 @@ void VIEW::ReorderLayerData( std::unordered_map<int, int> aReorderMap )
|
||||||
std::vector<VIEW_LAYER> new_map;
|
std::vector<VIEW_LAYER> new_map;
|
||||||
new_map.reserve( m_layers.size() );
|
new_map.reserve( m_layers.size() );
|
||||||
|
|
||||||
for( int ii = 0; ii < VIEW_MAX_LAYERS; ++ii )
|
|
||||||
new_map.emplace_back();
|
|
||||||
|
|
||||||
for( const VIEW_LAYER& layer : m_layers )
|
for( const VIEW_LAYER& layer : m_layers )
|
||||||
|
new_map.push_back( layer );
|
||||||
|
|
||||||
|
for( auto& pair : aReorderMap )
|
||||||
{
|
{
|
||||||
int orig_idx = layer.id;
|
new_map[pair.second] = m_layers[pair.first];
|
||||||
int new_idx = orig_idx;
|
new_map[pair.second].id = pair.second;
|
||||||
|
|
||||||
if( aReorderMap.count( orig_idx ) )
|
|
||||||
new_idx = aReorderMap.at( orig_idx );
|
|
||||||
|
|
||||||
new_map[new_idx] = layer;
|
|
||||||
new_map[new_idx].id = new_idx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_layers = new_map;
|
m_layers = new_map;
|
||||||
|
|
Loading…
Reference in New Issue