Nullptr safety; performance; formatting.

This commit is contained in:
Jeff Young 2025-06-08 14:05:13 +01:00
parent 96dd1815ea
commit f3050bd7ed
4 changed files with 43 additions and 42 deletions

View File

@ -119,8 +119,8 @@ private:
PANEL_TOOLBAR_CUSTOMIZATION::PANEL_TOOLBAR_CUSTOMIZATION( wxWindow* aParent, APP_SETTINGS_BASE* aCfg,
TOOLBAR_SETTINGS* aTbSettings,
std::vector<TOOL_ACTION*> aTools,
std::vector<ACTION_TOOLBAR_CONTROL*> aControls ) :
const std::vector<TOOL_ACTION*>& aTools,
const std::vector<ACTION_TOOLBAR_CONTROL*>& aControls ) :
PANEL_TOOLBAR_CUSTOMIZATION_BASE( aParent ),
m_actionImageList( nullptr ),
m_appSettings( aCfg ),
@ -244,14 +244,14 @@ bool PANEL_TOOLBAR_CUSTOMIZATION::TransferDataFromWindow()
m_appSettings->m_CustomToolbars = m_customToolbars->GetValue();
// Store the current toolbar
auto currentTb = parseToolbarTree();
std::optional<TOOLBAR_CONFIGURATION> currentTb = parseToolbarTree();
if( currentTb.has_value() )
m_toolbars[m_currentToolbar] = currentTb.value();
// Write the shadow toolbars with changes back to the app toolbar settings
for( auto& tb : m_toolbars )
m_appTbSettings->SetStoredToolbarConfig( tb.first, tb.second );
for( const auto& [loc, config] : m_toolbars )
m_appTbSettings->SetStoredToolbarConfig( loc, config );
return true;
}
@ -361,7 +361,7 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateToolbarTree()
wxTreeItemId root = m_toolbarTree->AddRoot( "Toolbar" );
for( auto& item : toolbar.GetToolbarItems() )
for( const TOOLBAR_ITEM& item : toolbar.GetToolbarItems() )
{
switch( item.m_Type )
{
@ -388,8 +388,7 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateToolbarTree()
// Add a control
TOOLBAR_TREE_ITEM_DATA* controlTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_ITEM_TYPE::CONTROL );
controlTreeItem->SetName( item.m_ControlName );
m_toolbarTree->AppendItem( root, item.m_ControlName, -1, -1,
controlTreeItem );
m_toolbarTree->AppendItem( root, item.m_ControlName, -1, -1, controlTreeItem );
break;
}
@ -413,8 +412,7 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateToolbarTree()
if( imgMap != m_actionImageListMap.end() )
imgIdx = imgMap->second;
m_toolbarTree->AppendItem( root, toolMap->second->GetFriendlyName(),
imgIdx, -1, toolTreeItem );
m_toolbarTree->AppendItem( root, toolMap->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
break;
}
@ -428,7 +426,7 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateToolbarTree()
groupTreeItem );
// Add the elements below the group
for( auto& groupItem : item.m_GroupItems )
for( const TOOLBAR_ITEM& groupItem : item.m_GroupItems )
{
auto toolMap = m_availableTools.find( groupItem.m_ActionName );
@ -450,6 +448,7 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateToolbarTree()
m_toolbarTree->AppendItem( groupId, toolMap->second->GetFriendlyName(),
imgIdx, -1, toolTreeItem );
}
break;
}
}
@ -512,7 +511,7 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateActions()
// Populate the various image lists for the action icons, and the actual control
int itemIdx = 0;
for( auto [k, tool] : m_availableTools )
for( const auto& [k, tool] : m_availableTools )
{
if( tool->CheckToolbarState( TOOLBAR_STATE::HIDDEN ) )
continue;
@ -760,7 +759,6 @@ void PANEL_TOOLBAR_CUSTOMIZATION::onBtnAddAction( wxCommandEvent& event )
if( selItem.IsOk() )
{
TOOLBAR_TREE_ITEM_DATA* data =
dynamic_cast<TOOLBAR_TREE_ITEM_DATA*>( m_toolbarTree->GetItemData( selItem ) );
@ -802,8 +800,9 @@ void PANEL_TOOLBAR_CUSTOMIZATION::onTreeBeginLabelEdit( wxTreeEvent& event )
if( id.IsOk() )
{
wxTreeItemData* treeData = m_toolbarTree->GetItemData( id );
TOOLBAR_TREE_ITEM_DATA* tbData = dynamic_cast<TOOLBAR_TREE_ITEM_DATA*>( treeData );
if( TOOLBAR_TREE_ITEM_DATA* tbData = dynamic_cast<TOOLBAR_TREE_ITEM_DATA*>( treeData ) )
{
switch( tbData->GetType() )
{
case TOOLBAR_ITEM_TYPE::TOOL:
@ -819,6 +818,7 @@ void PANEL_TOOLBAR_CUSTOMIZATION::onTreeBeginLabelEdit( wxTreeEvent& event )
break;
}
}
}
}
@ -831,7 +831,7 @@ void PANEL_TOOLBAR_CUSTOMIZATION::onTreeEndLabelEdit( wxTreeEvent& event )
void PANEL_TOOLBAR_CUSTOMIZATION::onTbChoiceSelect( wxCommandEvent& event )
{
// Store the current toolbar
auto currentTb = parseToolbarTree();
std::optional<TOOLBAR_CONFIGURATION> currentTb = parseToolbarTree();
if( currentTb.has_value() )
m_toolbars[m_currentToolbar] = currentTb.value();

View File

@ -40,8 +40,8 @@ class PANEL_TOOLBAR_CUSTOMIZATION : public PANEL_TOOLBAR_CUSTOMIZATION_BASE
{
public:
PANEL_TOOLBAR_CUSTOMIZATION( wxWindow* aParent, APP_SETTINGS_BASE* aCfg, TOOLBAR_SETTINGS* aTbSettings,
std::vector<TOOL_ACTION*> aTools,
std::vector<ACTION_TOOLBAR_CONTROL*> aControls );
const std::vector<TOOL_ACTION*>& aTools,
const std::vector<ACTION_TOOLBAR_CONTROL*>& aControls );
~PANEL_TOOLBAR_CUSTOMIZATION();

View File

@ -50,7 +50,7 @@ public:
// Make the toolbar a friend so it can easily access everything inside here
friend class ACTION_TOOLBAR;
ACTION_GROUP(const std::string_view& aName );
ACTION_GROUP( const std::string_view& aName );
ACTION_GROUP( const std::string_view& aName, const std::vector<const TOOL_ACTION*>& aActions );
@ -427,7 +427,8 @@ typedef std::function<void ( ACTION_TOOLBAR* )> ACTION_TOOLBAR_CONTROL_FACTORY;
class ACTION_TOOLBAR_CONTROL
{
public:
ACTION_TOOLBAR_CONTROL( std::string aName, wxString aUiName, wxString aDescription ) :
ACTION_TOOLBAR_CONTROL( const std::string& aName, const wxString& aUiName,
const wxString& aDescription ) :
m_name( aName ),
m_uiname( aUiName ),
m_description( aDescription )

View File

@ -235,7 +235,7 @@ public:
/**
* Set the stored configuration for the given toolbar.
*/
void SetStoredToolbarConfig( TOOLBAR_LOC aToolbar, TOOLBAR_CONFIGURATION& aConfig )
void SetStoredToolbarConfig( TOOLBAR_LOC aToolbar, const TOOLBAR_CONFIGURATION& aConfig )
{
m_toolbars[aToolbar] = aConfig;
}