More double- and triple-pointer erradication.

This commit is contained in:
Jeff Young 2021-01-06 14:37:38 +00:00
parent 426536c381
commit 366c7096b3
1 changed files with 29 additions and 37 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2020 Oleg Endo <olegendo@gcc.gnu.org>
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -289,24 +289,20 @@ public:
return r;
}
DATA_MODEL( DIALOG_NET_INSPECTOR& parent ) : m_parent( parent )
{
}
unsigned int columnCount() const
{
return columnDesc().size();
}
unsigned int itemCount() const
{
return m_items.size();
}
wxVariant valueAt( unsigned int aCol, unsigned int aRow ) const
{
wxVariant r;
@ -314,13 +310,11 @@ public:
return r;
}
const LIST_ITEM& itemAt( unsigned int aRow ) const
{
return *m_items.at( aRow );
}
OPT<LIST_ITEM_ITER> findItem( int aNetCode )
{
auto i = std::lower_bound(
@ -560,14 +554,12 @@ public:
}
}
void updateAllItems()
{
for( std::unique_ptr<LIST_ITEM>& i : m_items )
ItemChanged( wxDataViewItem( i.get() ) );
}
void resortIfChanged( LIST_ITEM* aItem )
{
if( wxDataViewColumn* column = m_parent.m_netsList->GetSortingColumn() )
@ -585,7 +577,6 @@ public:
}
}
bool itemColumnChanged( const LIST_ITEM* aItem, unsigned int aCol ) const
{
if( aItem == nullptr || aCol >= columnDesc().size() )
@ -612,7 +603,6 @@ public:
return false;
}
// implementation of wxDataViewModel interface
// these are used to query the data model by the GUI view implementation.
// these are not supposed to be used to modify the data model. for that
@ -624,7 +614,6 @@ protected:
return columnCount();
}
void GetValue( wxVariant& aOutValue, const wxDataViewItem& aItem,
unsigned int aCol ) const override
{
@ -659,7 +648,6 @@ protected:
}
}
static int compareUInt( uint64_t aValue1, uint64_t aValue2, bool aAsc )
{
if( aAsc )
@ -668,7 +656,6 @@ protected:
return aValue2 < aValue1 ? -1 : 1;
}
int Compare( const wxDataViewItem& aItem1, const wxDataViewItem& aItem2,
unsigned int aCol, bool aAsc ) const override
{
@ -721,14 +708,12 @@ protected:
return aAsc ? id1 - id2 : id2 - id1;
}
bool SetValue( const wxVariant& aInValue, const wxDataViewItem& aItem,
unsigned int aCol ) override
{
return false;
}
wxDataViewItem GetParent( const wxDataViewItem& aItem ) const override
{
if( !aItem.IsOk() )
@ -737,7 +722,6 @@ protected:
return wxDataViewItem( static_cast<const LIST_ITEM*>( aItem.GetID() )->Parent() );
}
bool IsContainer( const wxDataViewItem& aItem ) const override
{
if( !aItem.IsOk() )
@ -746,13 +730,11 @@ protected:
return static_cast<const LIST_ITEM*>( aItem.GetID() )->GetIsGroup();
}
bool HasContainerColumns( const wxDataViewItem& aItem ) const override
{
return IsContainer( aItem );
}
unsigned int GetChildren( const wxDataViewItem& aParent,
wxDataViewItemArray& aChildren ) const override
{
@ -788,7 +770,6 @@ protected:
return 0;
}
wxString GetColumnType( unsigned int /* aCol */ ) const override
{
return wxS( "string" );
@ -1143,13 +1124,15 @@ void DIALOG_NET_INSPECTOR::OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardIt
// try to handle frequent operations quickly.
if( TRACK* track = dynamic_cast<TRACK*>( i ) )
{
const std::unique_ptr<LIST_ITEM>& list_item = *r.get();
int len = track->GetLength();
( **r )->AddBoardWireLength( len );
list_item->AddBoardWireLength( len );
if( track->Type() == PCB_VIA_T )
{
( **r )->AddViaCount( 1 );
( **r )->AddViaLength( calculateViaLength( track ) );
list_item->AddViaCount( 1 );
list_item->AddViaLength( calculateViaLength( track ) );
}
updateDisplayedRowValues( r );
@ -1179,11 +1162,13 @@ void DIALOG_NET_INSPECTOR::OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardIt
if( r )
{
const std::unique_ptr<LIST_ITEM>& list_item = *r.get();
int len = pad->GetPadToDieLength();
( **r )->AddPadCount( 1 );
( **r )->AddChipWireLength( len );
if( ( **r )->GetPadCount() == 0 && !m_cbShowZeroPad->IsChecked() )
list_item->AddPadCount( 1 );
list_item->AddChipWireLength( len );
if( list_item->GetPadCount() == 0 && !m_cbShowZeroPad->IsChecked() )
m_data_model->deleteItem( r );
else
updateDisplayedRowValues( r );
@ -1567,10 +1552,15 @@ void DIALOG_NET_INSPECTOR::buildNetsList()
auto r = m_data_model->findItem( nc );
if( r )
sel.Add( wxDataViewItem( &***r ) );
{
const std::unique_ptr<LIST_ITEM>& list_item = *r.get();
sel.Add( wxDataViewItem( list_item.get() ) );
}
else
{
nc = -1;
}
}
if( !sel.IsEmpty() )
{
@ -1578,10 +1568,12 @@ void DIALOG_NET_INSPECTOR::buildNetsList()
m_netsList->EnsureVisible( sel.Item( 0 ) );
}
else
{
m_netsList->UnselectAll();
}
prev_selected_netcodes.erase(
std::remove( prev_selected_netcodes.begin(), prev_selected_netcodes.end(), -1 ),
prev_selected_netcodes.erase( std::remove( prev_selected_netcodes.begin(),
prev_selected_netcodes.end(), -1 ),
prev_selected_netcodes.end() );
m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings()->SetHighlight( false );