From 366c7096b38d7c4b4b7dd2762153050aa960cda6 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 6 Jan 2021 14:37:38 +0000 Subject: [PATCH] More double- and triple-pointer erradication. --- pcbnew/dialogs/dialog_net_inspector.cpp | 66 +++++++++++-------------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/pcbnew/dialogs/dialog_net_inspector.cpp b/pcbnew/dialogs/dialog_net_inspector.cpp index e23e47cd60..f7efd83a99 100644 --- a/pcbnew/dialogs/dialog_net_inspector.cpp +++ b/pcbnew/dialogs/dialog_net_inspector.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2020 Oleg Endo * 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 findItem( int aNetCode ) { auto i = std::lower_bound( @@ -523,10 +517,10 @@ public: && parent != nullptr && parent->ChildrenCount() == 0 ) { auto p = std::find_if( m_items.begin(), m_items.end(), - [&]( std::unique_ptr& x ) - { - return x.get() == parent; - } ); + [&]( std::unique_ptr& x ) + { + return x.get() == parent; + } ); wxASSERT( p != m_items.end() ); m_items.erase( p ); @@ -560,14 +554,12 @@ public: } } - void updateAllItems() { for( std::unique_ptr& 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( aItem.GetID() )->Parent() ); } - bool IsContainer( const wxDataViewItem& aItem ) const override { if( !aItem.IsOk() ) @@ -746,13 +730,11 @@ protected: return static_cast( 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" ); @@ -1056,9 +1037,9 @@ std::vector DIALOG_NET_INSPECTOR::relevantConnectivityItems() const // calculating the total length for each net. const auto type_bits = std::bitset() - .set( PCB_TRACE_T ) - .set( PCB_VIA_T ) - .set( PCB_PAD_T ); + .set( PCB_TRACE_T ) + .set( PCB_VIA_T ) + .set( PCB_PAD_T ); std::vector cn_items; cn_items.reserve( 1024 ); @@ -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( i ) ) { + const std::unique_ptr& 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 = *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,9 +1552,14 @@ void DIALOG_NET_INSPECTOR::buildNetsList() auto r = m_data_model->findItem( nc ); if( r ) - sel.Add( wxDataViewItem( &***r ) ); + { + const std::unique_ptr& list_item = *r.get(); + sel.Add( wxDataViewItem( list_item.get() ) ); + } else + { nc = -1; + } } if( !sel.IsEmpty() ) @@ -1578,11 +1568,13 @@ 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.end() ); + 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 );