ADDED: Implement sorting for search panes.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/12614
This commit is contained in:
parent
4a54ea3b11
commit
da86593625
|
@ -21,12 +21,15 @@
|
|||
#include <widgets/search_pane.h>
|
||||
#include <kiway.h>
|
||||
#include <vector>
|
||||
#include <string_utils.h>
|
||||
|
||||
SEARCH_PANE_LISTVIEW::SEARCH_PANE_LISTVIEW( SEARCH_HANDLER* handler, wxWindow* parent,
|
||||
wxWindowID winid, const wxPoint& pos,
|
||||
const wxSize& size ) :
|
||||
wxListView( parent, winid, pos, size, wxLC_REPORT | wxLC_VIRTUAL ),
|
||||
m_handler( handler )
|
||||
m_handler( handler ),
|
||||
m_sortCol( -1 ),
|
||||
m_sortAscending( true )
|
||||
{
|
||||
SetItemCount( 0 );
|
||||
|
||||
|
@ -36,6 +39,7 @@ SEARCH_PANE_LISTVIEW::SEARCH_PANE_LISTVIEW( SEARCH_HANDLER* handler, wxWindow* p
|
|||
Bind( wxEVT_LIST_ITEM_ACTIVATED, &SEARCH_PANE_LISTVIEW::OnItemActivated, this );
|
||||
Bind( wxEVT_LIST_ITEM_FOCUSED, &SEARCH_PANE_LISTVIEW::OnItemSelected, this );
|
||||
Bind( wxEVT_LIST_ITEM_DESELECTED, &SEARCH_PANE_LISTVIEW::OnItemDeselected, this );
|
||||
Bind( wxEVT_LIST_COL_CLICK, &SEARCH_PANE_LISTVIEW::OnColClicked, this );
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,6 +116,29 @@ void SEARCH_PANE_LISTVIEW::OnItemDeselected( wxListEvent& aEvent )
|
|||
}
|
||||
|
||||
|
||||
void SEARCH_PANE_LISTVIEW::OnColClicked( wxListEvent& aEvent )
|
||||
{
|
||||
if( aEvent.GetColumn() == m_sortCol )
|
||||
{
|
||||
m_sortAscending = !m_sortAscending;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_sortAscending = true;
|
||||
m_sortCol = aEvent.GetColumn();
|
||||
}
|
||||
|
||||
Sort();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
void SEARCH_PANE_LISTVIEW::Sort()
|
||||
{
|
||||
m_handler->Sort( m_sortCol, m_sortAscending );
|
||||
}
|
||||
|
||||
|
||||
void SEARCH_PANE_LISTVIEW::RefreshColumnNames()
|
||||
{
|
||||
Freeze();
|
||||
|
@ -158,6 +185,7 @@ void SEARCH_PANE_TAB::Search( wxString& query )
|
|||
{
|
||||
int results = m_handler->Search( query );
|
||||
m_listView->SetItemCount( results );
|
||||
m_listView->Sort();
|
||||
m_listView->Refresh();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,6 @@
|
|||
#include "search_handlers.h"
|
||||
|
||||
|
||||
SCH_SEARCH_HANDLER::SCH_SEARCH_HANDLER( wxString aName, SCH_EDIT_FRAME* aFrame ) :
|
||||
SEARCH_HANDLER( aName ), m_frame( aFrame )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SCH_SEARCH_HANDLER::ActivateItem( long aItemRow )
|
||||
{
|
||||
std::vector<long> item = { aItemRow };
|
||||
|
@ -63,14 +57,27 @@ void SCH_SEARCH_HANDLER::FindAll( const std::function<bool( SCH_ITEM*, SCH_SHEET
|
|||
for( SCH_ITEM* item : sheet->LastScreen()->Items() )
|
||||
{
|
||||
if( aCollector( item, sheet ) )
|
||||
{
|
||||
m_hitlist.push_back( { item, sheet } );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SCH_SEARCH_HANDLER::Sort( int aCol, bool aAscending )
|
||||
{
|
||||
std::sort( m_hitlist.begin(), m_hitlist.end(),
|
||||
[&]( const SCH_SEARCH_HIT& a, const SCH_SEARCH_HIT& b ) -> bool
|
||||
{
|
||||
// N.B. To meet the iterator sort conditions, we cannot simply invert the truth
|
||||
// to get the opposite sort. i.e. ~(a<b) != (a>b)
|
||||
if( aAscending )
|
||||
return StrNumCmp( getResultCell( a, aCol ), getResultCell( b, aCol ), true ) < 0;
|
||||
else
|
||||
return StrNumCmp( getResultCell( b, aCol ), getResultCell( a, aCol ), true ) < 0;
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
void SCH_SEARCH_HANDLER::SelectItems( std::vector<long>& aItemRows )
|
||||
{
|
||||
EDA_ITEMS selectedItems;
|
||||
|
@ -161,22 +168,21 @@ int SYMBOL_SEARCH_HANDLER::Search( const wxString& aQuery )
|
|||
}
|
||||
|
||||
|
||||
wxString SYMBOL_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
||||
wxString SYMBOL_SEARCH_HANDLER::getResultCell( const SCH_SEARCH_HIT& aHit, int aCol )
|
||||
{
|
||||
SCH_SEARCH_HIT hit = m_hitlist[aRow];
|
||||
SCH_SYMBOL* sym = dynamic_cast<SCH_SYMBOL*>( hit.item );
|
||||
SCH_SYMBOL*sym = dynamic_cast<SCH_SYMBOL*>( aHit.item );
|
||||
|
||||
if( !sym )
|
||||
return wxEmptyString;
|
||||
|
||||
if( aCol == 0 )
|
||||
return sym->GetRef( hit.sheetPath, true );
|
||||
return sym->GetRef( aHit.sheetPath, true );
|
||||
else if( aCol == 1 )
|
||||
return sym->GetField( VALUE_FIELD )->GetShownText( hit.sheetPath, false );
|
||||
return sym->GetField( VALUE_FIELD )->GetShownText( aHit.sheetPath, false );
|
||||
else if( aCol == 2 )
|
||||
return sym->GetField( FOOTPRINT_FIELD )->GetShownText( hit.sheetPath, false );
|
||||
return sym->GetField( FOOTPRINT_FIELD )->GetShownText( aHit.sheetPath, false );
|
||||
else if( aCol == 3 )
|
||||
return hit.sheetPath->GetPageNumber();
|
||||
return aHit.sheetPath->GetPageNumber();
|
||||
else if( aCol == 4 )
|
||||
return m_frame->MessageTextFromValue( sym->GetPosition().x );
|
||||
else if( aCol == 5 )
|
||||
|
@ -227,13 +233,11 @@ int TEXT_SEARCH_HANDLER::Search( const wxString& aQuery )
|
|||
}
|
||||
|
||||
|
||||
wxString TEXT_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
||||
wxString TEXT_SEARCH_HANDLER::getResultCell( const SCH_SEARCH_HIT& aHit, int aCol )
|
||||
{
|
||||
SCH_SEARCH_HIT hit = m_hitlist[aRow];
|
||||
|
||||
if( hit.item->Type() == SCH_TEXT_T )
|
||||
if( aHit.item->Type() == SCH_TEXT_T )
|
||||
{
|
||||
SCH_TEXT* txt = dynamic_cast<SCH_TEXT*>( hit.item );
|
||||
SCH_TEXT* txt = dynamic_cast<SCH_TEXT*>( aHit.item );
|
||||
|
||||
if( !txt )
|
||||
return wxEmptyString;
|
||||
|
@ -243,15 +247,15 @@ wxString TEXT_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
|||
else if( aCol == 1 )
|
||||
return txt->GetShownText( false );
|
||||
else if( aCol == 2 )
|
||||
return hit.sheetPath->GetPageNumber();
|
||||
return aHit.sheetPath->GetPageNumber();
|
||||
else if( aCol == 3 )
|
||||
return m_frame->MessageTextFromValue( txt->GetPosition().x );
|
||||
else if( aCol == 4 )
|
||||
return m_frame->MessageTextFromValue( txt->GetPosition().y );
|
||||
}
|
||||
else if( hit.item->Type() == SCH_TEXTBOX_T )
|
||||
else if( aHit.item->Type() == SCH_TEXTBOX_T )
|
||||
{
|
||||
SCH_TEXTBOX* txt = dynamic_cast<SCH_TEXTBOX*>( hit.item );
|
||||
SCH_TEXTBOX* txt = dynamic_cast<SCH_TEXTBOX*>( aHit.item );
|
||||
|
||||
if( !txt )
|
||||
return wxEmptyString;
|
||||
|
@ -261,7 +265,7 @@ wxString TEXT_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
|||
else if( aCol == 1 )
|
||||
return txt->GetShownText( false );
|
||||
else if( aCol == 2 )
|
||||
return hit.sheetPath->GetPageNumber();
|
||||
return aHit.sheetPath->GetPageNumber();
|
||||
else if( aCol == 3 )
|
||||
return m_frame->MessageTextFromValue( txt->GetPosition().x );
|
||||
else if( aCol == 4 )
|
||||
|
@ -317,11 +321,9 @@ int LABEL_SEARCH_HANDLER::Search( const wxString& aQuery )
|
|||
}
|
||||
|
||||
|
||||
wxString LABEL_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
||||
wxString LABEL_SEARCH_HANDLER::getResultCell( const SCH_SEARCH_HIT& aHit, int aCol )
|
||||
{
|
||||
SCH_SEARCH_HIT hit = m_hitlist[aRow];
|
||||
|
||||
SCH_LABEL_BASE* lbl = dynamic_cast<SCH_LABEL_BASE*>( hit.item );
|
||||
SCH_LABEL_BASE* lbl = dynamic_cast<SCH_LABEL_BASE*>( aHit.item );
|
||||
|
||||
if( !lbl )
|
||||
return wxEmptyString;
|
||||
|
@ -338,7 +340,7 @@ wxString LABEL_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
|||
else if( aCol == 1 )
|
||||
return lbl->GetShownText( false );
|
||||
else if( aCol == 2 )
|
||||
return hit.sheetPath->GetPageNumber();
|
||||
return aHit.sheetPath->GetPageNumber();
|
||||
else if( aCol == 3 )
|
||||
return m_frame->MessageTextFromValue( lbl->GetPosition().x );
|
||||
else if( aCol == 4 )
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2022-2023 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
|
||||
|
@ -28,7 +28,6 @@
|
|||
#include <widgets/search_pane.h>
|
||||
|
||||
class SCH_ITEM;
|
||||
class SCH_TEXT;
|
||||
class SCH_EDIT_FRAME;
|
||||
|
||||
struct SCH_SEARCH_HIT
|
||||
|
@ -40,12 +39,25 @@ struct SCH_SEARCH_HIT
|
|||
class SCH_SEARCH_HANDLER : public SEARCH_HANDLER
|
||||
{
|
||||
public:
|
||||
SCH_SEARCH_HANDLER( wxString aName, SCH_EDIT_FRAME* aFrame );
|
||||
SCH_SEARCH_HANDLER( const wxString& aName, SCH_EDIT_FRAME* aFrame ) :
|
||||
SEARCH_HANDLER( aName ),
|
||||
m_frame( aFrame )
|
||||
{}
|
||||
|
||||
void ActivateItem( long aItemRow ) override;
|
||||
|
||||
wxString GetResultCell( int aRow, int aCol ) override
|
||||
{
|
||||
return getResultCell( m_hitlist[aRow], aCol );
|
||||
}
|
||||
|
||||
void FindAll( const std::function<bool( SCH_ITEM*, SCH_SHEET_PATH* )>& aCollector );
|
||||
void Sort( int aCol, bool aAscending ) override;
|
||||
void SelectItems( std::vector<long>& aItemRows ) override;
|
||||
|
||||
protected:
|
||||
virtual wxString getResultCell( const SCH_SEARCH_HIT& hit, int aCol ) = 0;
|
||||
|
||||
protected:
|
||||
SCH_EDIT_FRAME* m_frame;
|
||||
std::vector<SCH_SEARCH_HIT> m_hitlist;
|
||||
|
@ -57,8 +69,9 @@ public:
|
|||
SYMBOL_SEARCH_HANDLER( SCH_EDIT_FRAME* aFrame );
|
||||
|
||||
int Search( const wxString& aQuery ) override;
|
||||
wxString GetResultCell( int aRow, int aCol ) override;
|
||||
|
||||
protected:
|
||||
wxString getResultCell( const SCH_SEARCH_HIT& aHit, int aCol ) override;
|
||||
};
|
||||
|
||||
class TEXT_SEARCH_HANDLER : public SCH_SEARCH_HANDLER
|
||||
|
@ -66,9 +79,10 @@ class TEXT_SEARCH_HANDLER : public SCH_SEARCH_HANDLER
|
|||
public:
|
||||
TEXT_SEARCH_HANDLER( SCH_EDIT_FRAME* aFrame );
|
||||
|
||||
int Search( const wxString& aQuery ) override;
|
||||
wxString GetResultCell( int aRow, int aCol ) override;
|
||||
int Search( const wxString& aQuery ) override;
|
||||
|
||||
protected:
|
||||
wxString getResultCell( const SCH_SEARCH_HIT& hit, int aCol ) override;
|
||||
};
|
||||
|
||||
class LABEL_SEARCH_HANDLER : public SCH_SEARCH_HANDLER
|
||||
|
@ -76,9 +90,10 @@ class LABEL_SEARCH_HANDLER : public SCH_SEARCH_HANDLER
|
|||
public:
|
||||
LABEL_SEARCH_HANDLER( SCH_EDIT_FRAME* aFrame );
|
||||
|
||||
int Search( const wxString& aQuery ) override;
|
||||
wxString GetResultCell( int aRow, int aCol ) override;
|
||||
int Search( const wxString& aQuery ) override;
|
||||
|
||||
protected:
|
||||
wxString getResultCell( const SCH_SEARCH_HIT& hit, int aCol ) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2022-2023 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 as published by the
|
||||
|
@ -29,8 +29,9 @@ class SEARCH_PANE_TAB;
|
|||
class SEARCH_HANDLER
|
||||
{
|
||||
public:
|
||||
SEARCH_HANDLER( wxString aName ) :
|
||||
m_name( aName ) {}
|
||||
SEARCH_HANDLER( const wxString& aName ) :
|
||||
m_name( aName )
|
||||
{}
|
||||
|
||||
wxString GetName() const { return m_name; }
|
||||
|
||||
|
@ -38,6 +39,7 @@ public:
|
|||
|
||||
virtual int Search( const wxString& string ) = 0;
|
||||
virtual wxString GetResultCell( int row, int col ) = 0;
|
||||
virtual void Sort( int aCol, bool aAscending ) = 0;
|
||||
|
||||
virtual void SelectItems( std::vector<long>& aItemRows ) {}
|
||||
virtual void ActivateItem( long aItemRow ) {}
|
||||
|
|
|
@ -40,16 +40,21 @@ public:
|
|||
|
||||
void RefreshColumnNames();
|
||||
|
||||
void Sort();
|
||||
|
||||
protected:
|
||||
wxString OnGetItemText( long item, long column ) const override;
|
||||
void OnItemSelected( wxListEvent& aEvent );
|
||||
void OnItemActivated( wxListEvent& aEvent );
|
||||
void OnItemDeselected( wxListEvent& aEvent );
|
||||
void OnColClicked( wxListEvent& aEvent );
|
||||
|
||||
void GetSelectRowsList( std::vector<long>& aSelectedList );
|
||||
|
||||
private:
|
||||
SEARCH_HANDLER* m_handler;
|
||||
int m_sortCol;
|
||||
bool m_sortAscending;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -30,12 +30,6 @@
|
|||
#include "search_handlers.h"
|
||||
|
||||
|
||||
PCB_SEARCH_HANDLER::PCB_SEARCH_HANDLER( wxString aName, PCB_EDIT_FRAME* aFrame ) :
|
||||
SEARCH_HANDLER( aName ), m_frame( aFrame )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void PCB_SEARCH_HANDLER::ActivateItem( long aItemRow )
|
||||
{
|
||||
std::vector<long> item = { aItemRow };
|
||||
|
@ -45,6 +39,40 @@ void PCB_SEARCH_HANDLER::ActivateItem( long aItemRow )
|
|||
}
|
||||
|
||||
|
||||
void PCB_SEARCH_HANDLER::Sort( int aCol, bool aAscending )
|
||||
{
|
||||
std::sort( m_hitlist.begin(), m_hitlist.end(),
|
||||
[&]( BOARD_ITEM* a, BOARD_ITEM* b ) -> bool
|
||||
{
|
||||
// N.B. To meet the iterator sort conditions, we cannot simply invert the truth
|
||||
// to get the opposite sort. i.e. ~(a<b) != (a>b)
|
||||
if( aAscending )
|
||||
return StrNumCmp( getResultCell( a, aCol ), getResultCell( b, aCol ), true ) < 0;
|
||||
else
|
||||
return StrNumCmp( getResultCell( b, aCol ), getResultCell( a, aCol ), true ) < 0;
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
void PCB_SEARCH_HANDLER::SelectItems( std::vector<long>& aItemRows )
|
||||
{
|
||||
std::vector<EDA_ITEM*> selectedItems;
|
||||
|
||||
for( long row : aItemRows )
|
||||
{
|
||||
if( row >= 0 && row < (long) m_hitlist.size() )
|
||||
selectedItems.push_back( m_hitlist[row] );
|
||||
}
|
||||
|
||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear );
|
||||
|
||||
if( selectedItems.size() )
|
||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItems, &selectedItems );
|
||||
|
||||
m_frame->GetCanvas()->Refresh( false );
|
||||
}
|
||||
|
||||
|
||||
FOOTPRINT_SEARCH_HANDLER::FOOTPRINT_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ) :
|
||||
PCB_SEARCH_HANDLER( wxT( "Footprints" ), aFrame )
|
||||
{
|
||||
|
@ -81,9 +109,9 @@ int FOOTPRINT_SEARCH_HANDLER::Search( const wxString& aQuery )
|
|||
}
|
||||
|
||||
|
||||
wxString FOOTPRINT_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
||||
wxString FOOTPRINT_SEARCH_HANDLER::getResultCell( BOARD_ITEM* aItem, int aCol )
|
||||
{
|
||||
FOOTPRINT* fp = m_hitlist[aRow];
|
||||
FOOTPRINT* fp = static_cast<FOOTPRINT*>( aItem );
|
||||
|
||||
if( aCol == 0 )
|
||||
return fp->GetReference();
|
||||
|
@ -100,31 +128,6 @@ wxString FOOTPRINT_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
|||
}
|
||||
|
||||
|
||||
void FOOTPRINT_SEARCH_HANDLER::SelectItems( std::vector<long>& aItemRows )
|
||||
{
|
||||
std::vector<EDA_ITEM*> selectedItems;
|
||||
|
||||
for( long row : aItemRows )
|
||||
{
|
||||
if( row >= 0 && row < (long) m_hitlist.size() )
|
||||
{
|
||||
FOOTPRINT* fp = m_hitlist[row];
|
||||
selectedItems.push_back( fp );
|
||||
}
|
||||
}
|
||||
|
||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear );
|
||||
|
||||
if( selectedItems.size() )
|
||||
{
|
||||
EDA_ITEMS selItems( selectedItems.begin(), selectedItems.end() );
|
||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItems, &selItems );
|
||||
}
|
||||
|
||||
m_frame->GetCanvas()->Refresh( false );
|
||||
}
|
||||
|
||||
|
||||
ZONE_SEARCH_HANDLER::ZONE_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ) :
|
||||
PCB_SEARCH_HANDLER( wxT( "Zones" ), aFrame )
|
||||
{
|
||||
|
@ -160,9 +163,9 @@ int ZONE_SEARCH_HANDLER::Search( const wxString& aQuery )
|
|||
}
|
||||
|
||||
|
||||
wxString ZONE_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
||||
wxString ZONE_SEARCH_HANDLER::getResultCell( BOARD_ITEM* aItem, int aCol )
|
||||
{
|
||||
ZONE* zone = m_hitlist[aRow];
|
||||
ZONE* zone = static_cast<ZONE*>( aItem );
|
||||
|
||||
if( aCol == 0 )
|
||||
return zone->GetZoneName();
|
||||
|
@ -189,31 +192,6 @@ wxString ZONE_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
|||
}
|
||||
|
||||
|
||||
void ZONE_SEARCH_HANDLER::SelectItems( std::vector<long>& aItemRows )
|
||||
{
|
||||
std::vector<EDA_ITEM*> selectedItems;
|
||||
|
||||
for( long row : aItemRows )
|
||||
{
|
||||
if( row >= 0 && row < (long) m_hitlist.size() )
|
||||
{
|
||||
ZONE* zone = m_hitlist[row];
|
||||
selectedItems.push_back( zone );
|
||||
}
|
||||
}
|
||||
|
||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear );
|
||||
|
||||
if( selectedItems.size() )
|
||||
{
|
||||
EDA_ITEMS selItems( selectedItems.begin(), selectedItems.end() );
|
||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItems, &selItems );
|
||||
}
|
||||
|
||||
m_frame->GetCanvas()->Refresh( false );
|
||||
}
|
||||
|
||||
|
||||
TEXT_SEARCH_HANDLER::TEXT_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ) :
|
||||
PCB_SEARCH_HANDLER( wxT( "Text" ), aFrame )
|
||||
{
|
||||
|
@ -251,60 +229,33 @@ int TEXT_SEARCH_HANDLER::Search( const wxString& aQuery )
|
|||
}
|
||||
|
||||
|
||||
wxString TEXT_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
||||
wxString TEXT_SEARCH_HANDLER::getResultCell( BOARD_ITEM* aItem, int aCol )
|
||||
{
|
||||
BOARD_ITEM* text = m_hitlist[aRow];
|
||||
|
||||
if( aCol == 0 )
|
||||
{
|
||||
if( PCB_TEXT::ClassOf( text ) )
|
||||
if( PCB_TEXT::ClassOf( aItem ) )
|
||||
return _( "Text" );
|
||||
else if( PCB_TEXTBOX::ClassOf( text ) )
|
||||
else if( PCB_TEXTBOX::ClassOf( aItem ) )
|
||||
return _( "Textbox" );
|
||||
}
|
||||
else if( aCol == 1 )
|
||||
{
|
||||
if( PCB_TEXT::ClassOf( text ) )
|
||||
return UnescapeString( static_cast<PCB_TEXT*>( text )->GetText() );
|
||||
else if( PCB_TEXTBOX::ClassOf( text ) )
|
||||
return UnescapeString( static_cast<PCB_TEXTBOX*>( text )->GetText() );
|
||||
if( PCB_TEXT::ClassOf( aItem ) )
|
||||
return UnescapeString( static_cast<PCB_TEXT*>( aItem )->GetText() );
|
||||
else if( PCB_TEXTBOX::ClassOf( aItem ) )
|
||||
return UnescapeString( static_cast<PCB_TEXTBOX*>( aItem )->GetText() );
|
||||
}
|
||||
if( aCol == 2 )
|
||||
return text->GetLayerName();
|
||||
return aItem->GetLayerName();
|
||||
else if( aCol == 3 )
|
||||
return m_frame->MessageTextFromValue( text->GetX() );
|
||||
return m_frame->MessageTextFromValue( aItem->GetX() );
|
||||
else if( aCol == 4 )
|
||||
return m_frame->MessageTextFromValue( text->GetY() );
|
||||
return m_frame->MessageTextFromValue( aItem->GetY() );
|
||||
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
void TEXT_SEARCH_HANDLER::SelectItems( std::vector<long>& aItemRows )
|
||||
{
|
||||
std::vector<EDA_ITEM*> selectedItems;
|
||||
|
||||
for( long row : aItemRows )
|
||||
{
|
||||
if( row >= 0 && row < (long) m_hitlist.size() )
|
||||
{
|
||||
BOARD_ITEM* text = m_hitlist[row];
|
||||
selectedItems.push_back( text );
|
||||
}
|
||||
}
|
||||
|
||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear );
|
||||
|
||||
if( selectedItems.size() )
|
||||
{
|
||||
EDA_ITEMS selItems( selectedItems.begin(), selectedItems.end() );
|
||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItems, &selItems );
|
||||
}
|
||||
|
||||
m_frame->GetCanvas()->Refresh( false );
|
||||
}
|
||||
|
||||
|
||||
NETS_SEARCH_HANDLER::NETS_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ) :
|
||||
PCB_SEARCH_HANDLER( wxT( "Nets" ), aFrame )
|
||||
{
|
||||
|
@ -335,9 +286,9 @@ int NETS_SEARCH_HANDLER::Search( const wxString& aQuery )
|
|||
}
|
||||
|
||||
|
||||
wxString NETS_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
||||
wxString NETS_SEARCH_HANDLER::getResultCell( BOARD_ITEM* aItem, int aCol )
|
||||
{
|
||||
NETINFO_ITEM* net = m_hitlist[aRow];
|
||||
NETINFO_ITEM* net = static_cast<NETINFO_ITEM*>( aItem );
|
||||
|
||||
if( net->GetNetCode() == 0 )
|
||||
{
|
||||
|
@ -367,7 +318,7 @@ void NETS_SEARCH_HANDLER::SelectItems( std::vector<long>& aItemRows )
|
|||
{
|
||||
if( row >= 0 && row < (long) m_hitlist.size() )
|
||||
{
|
||||
NETINFO_ITEM* net = m_hitlist[row];
|
||||
NETINFO_ITEM* net = static_cast<NETINFO_ITEM*>( m_hitlist[row] );
|
||||
|
||||
ps->SetHighlight( true, net->GetNetCode(), true );
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2022-2023 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
|
||||
|
@ -26,20 +26,33 @@
|
|||
|
||||
#include <widgets/search_pane.h>
|
||||
|
||||
class ZONE;
|
||||
class FOOTPRINT;
|
||||
class PCB_TEXT;
|
||||
class PCB_EDIT_FRAME;
|
||||
|
||||
|
||||
class PCB_SEARCH_HANDLER : public SEARCH_HANDLER
|
||||
{
|
||||
public:
|
||||
PCB_SEARCH_HANDLER( wxString aName, PCB_EDIT_FRAME* aFrame );
|
||||
PCB_SEARCH_HANDLER( const wxString& aName, PCB_EDIT_FRAME* aFrame ) :
|
||||
SEARCH_HANDLER( aName ),
|
||||
m_frame( aFrame )
|
||||
{}
|
||||
|
||||
wxString GetResultCell( int aRow, int aCol ) override
|
||||
{
|
||||
return getResultCell( m_hitlist[aRow], aCol );
|
||||
}
|
||||
|
||||
void Sort( int aCol, bool aAscending ) override;
|
||||
|
||||
void SelectItems( std::vector<long>& aItemRows ) override;
|
||||
void ActivateItem( long aItemRow ) override;
|
||||
|
||||
protected:
|
||||
PCB_EDIT_FRAME* m_frame;
|
||||
virtual wxString getResultCell( BOARD_ITEM* aItem, int aCol ) = 0;
|
||||
|
||||
protected:
|
||||
PCB_EDIT_FRAME* m_frame;
|
||||
std::vector<BOARD_ITEM*> m_hitlist;
|
||||
};
|
||||
|
||||
|
||||
|
@ -49,11 +62,9 @@ public:
|
|||
FOOTPRINT_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame );
|
||||
|
||||
int Search( const wxString& aQuery ) override;
|
||||
wxString GetResultCell( int aRow, int aCol ) override;
|
||||
void SelectItems( std::vector<long>& aItemRows ) override;
|
||||
|
||||
private:
|
||||
std::vector<FOOTPRINT*> m_hitlist;
|
||||
wxString getResultCell( BOARD_ITEM* aItem, int aCol ) override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -62,12 +73,10 @@ class ZONE_SEARCH_HANDLER : public PCB_SEARCH_HANDLER
|
|||
public:
|
||||
ZONE_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame );
|
||||
|
||||
int Search( const wxString& aQuery ) override;
|
||||
wxString GetResultCell( int aRow, int aCol ) override;
|
||||
void SelectItems( std::vector<long>& aItemRows ) override;
|
||||
int Search( const wxString& aQuery ) override;
|
||||
|
||||
private:
|
||||
std::vector<ZONE*> m_hitlist;
|
||||
wxString getResultCell( BOARD_ITEM* aItem, int aCol ) override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -76,12 +85,10 @@ class TEXT_SEARCH_HANDLER : public PCB_SEARCH_HANDLER
|
|||
public:
|
||||
TEXT_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame );
|
||||
|
||||
int Search( const wxString& aQuery ) override;
|
||||
wxString GetResultCell( int aRow, int aCol ) override;
|
||||
void SelectItems( std::vector<long>& aItemRows ) override;
|
||||
int Search( const wxString& aQuery ) override;
|
||||
|
||||
private:
|
||||
std::vector<BOARD_ITEM*> m_hitlist;
|
||||
wxString getResultCell( BOARD_ITEM* aItem, int aCol ) override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -91,12 +98,11 @@ public:
|
|||
NETS_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame );
|
||||
|
||||
int Search( const wxString& aQuery ) override;
|
||||
wxString GetResultCell( int aRow, int aCol ) override;
|
||||
void SelectItems( std::vector<long>& aItemRows ) override;
|
||||
void ActivateItem( long aItemRow ) override;
|
||||
void SelectItems( std::vector<long>& aItemRows ) override;
|
||||
void ActivateItem( long aItemRow ) override;
|
||||
|
||||
private:
|
||||
std::vector<NETINFO_ITEM*> m_hitlist;
|
||||
wxString getResultCell( BOARD_ITEM* aItem, int aCol ) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue