mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 18:23:15 +02:00
Symbol Fields Table: add item number support
This commit is contained in:
parent
a8f628d0df
commit
e26dcbece4
@ -335,7 +335,8 @@ void DIALOG_SYMBOL_FIELDS_TABLE::SetupColumnProperties()
|
|||||||
attr->SetEditor( new GRID_CELL_URL_EDITOR( this, Prj().SchSearchS() ) );
|
attr->SetEditor( new GRID_CELL_URL_EDITOR( this, Prj().SchSearchS() ) );
|
||||||
m_grid->SetColAttr( col, attr );
|
m_grid->SetColAttr( col, attr );
|
||||||
}
|
}
|
||||||
else if( m_dataModel->GetColFieldName( col ) == wxS( "Quantity" ) )
|
else if( m_dataModel->GetColFieldName( col ) == wxS( "Quantity" )
|
||||||
|
|| m_dataModel->GetColFieldName( col ) == wxS( "Item Number" ) )
|
||||||
{
|
{
|
||||||
attr->SetReadOnly();
|
attr->SetReadOnly();
|
||||||
m_grid->SetColAttr( col, attr );
|
m_grid->SetColAttr( col, attr );
|
||||||
@ -566,6 +567,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::LoadFieldNames()
|
|||||||
|
|
||||||
// Generated field that isn't in any symbol
|
// Generated field that isn't in any symbol
|
||||||
AddField( wxS( "Quantity" ), _( "Qty" ), true, false );
|
AddField( wxS( "Quantity" ), _( "Qty" ), true, false );
|
||||||
|
AddField( wxS( "Item Number" ), _( "#" ), true, false );
|
||||||
|
|
||||||
// User fields second
|
// User fields second
|
||||||
std::set<wxString> userFieldNames;
|
std::set<wxString> userFieldNames;
|
||||||
@ -807,6 +809,14 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnColumnItemToggled( wxDataViewEvent& event )
|
|||||||
m_fieldsCtrl->SetToggleValue( value, row, col );
|
m_fieldsCtrl->SetToggleValue( value, row, col );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( m_dataModel->ColIsItemNumber( dataCol ) && value )
|
||||||
|
{
|
||||||
|
DisplayError( this, _( "The Item Number column cannot be grouped by." ) );
|
||||||
|
|
||||||
|
value = false;
|
||||||
|
m_fieldsCtrl->SetToggleValue( value, row, col );
|
||||||
|
}
|
||||||
|
|
||||||
wxString fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN );
|
wxString fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN );
|
||||||
|
|
||||||
m_dataModel->SetGroupColumn( m_dataModel->GetFieldNameCol( fieldName ), value );
|
m_dataModel->SetGroupColumn( m_dataModel->GetFieldNameCol( fieldName ), value );
|
||||||
@ -849,6 +859,13 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnColSort( wxGridEvent& aEvent )
|
|||||||
std::string key( m_dataModel->GetColFieldName( sortCol ).ToUTF8() );
|
std::string key( m_dataModel->GetColFieldName( sortCol ).ToUTF8() );
|
||||||
bool ascending;
|
bool ascending;
|
||||||
|
|
||||||
|
// Don't sort by item number, it is generated by the sort
|
||||||
|
if( m_dataModel->ColIsItemNumber( sortCol ) )
|
||||||
|
{
|
||||||
|
aEvent.Veto();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// This is bonkers, but wxWidgets doesn't tell us ascending/descending in the event, and
|
// This is bonkers, but wxWidgets doesn't tell us ascending/descending in the event, and
|
||||||
// if we ask it will give us pre-event info.
|
// if we ask it will give us pre-event info.
|
||||||
if( m_grid->IsSortingBy( sortCol ) )
|
if( m_grid->IsSortingBy( sortCol ) )
|
||||||
|
@ -125,7 +125,7 @@ wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetValue( const DATA_MODEL_ROW& group, i
|
|||||||
|
|
||||||
for( const SCH_REFERENCE& ref : group.m_Refs )
|
for( const SCH_REFERENCE& ref : group.m_Refs )
|
||||||
{
|
{
|
||||||
if( ColIsReference( aCol ) || ColIsQuantity( aCol ) )
|
if( ColIsReference( aCol ) || ColIsQuantity( aCol ) || ColIsItemNumber( aCol ) )
|
||||||
{
|
{
|
||||||
references.push_back( ref );
|
references.push_back( ref );
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetValue( const DATA_MODEL_ROW& group, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ColIsReference( aCol ) || ColIsQuantity( aCol ) )
|
if( ColIsReference( aCol ) || ColIsQuantity( aCol ) || ColIsItemNumber( aCol ) )
|
||||||
{
|
{
|
||||||
// Remove duplicates (other units of multi-unit parts)
|
// Remove duplicates (other units of multi-unit parts)
|
||||||
std::sort( references.begin(), references.end(),
|
std::sort( references.begin(), references.end(),
|
||||||
@ -189,6 +189,8 @@ wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetValue( const DATA_MODEL_ROW& group, i
|
|||||||
fieldValue = SCH_REFERENCE_LIST::Shorthand( references, refDelimiter, refRangeDelimiter );
|
fieldValue = SCH_REFERENCE_LIST::Shorthand( references, refDelimiter, refRangeDelimiter );
|
||||||
else if( ColIsQuantity( aCol ) )
|
else if( ColIsQuantity( aCol ) )
|
||||||
fieldValue = wxString::Format( wxT( "%d" ), (int) references.size() );
|
fieldValue = wxString::Format( wxT( "%d" ), (int) references.size() );
|
||||||
|
else if( ColIsItemNumber( aCol ) && group.m_Flag != CHILD_ITEM )
|
||||||
|
fieldValue = wxString::Format( wxT( "%d" ), group.m_ItemNumber );
|
||||||
|
|
||||||
return fieldValue;
|
return fieldValue;
|
||||||
}
|
}
|
||||||
@ -220,6 +222,12 @@ bool FIELDS_EDITOR_GRID_DATA_MODEL::ColIsQuantity( int aCol )
|
|||||||
return m_cols[aCol].m_fieldName == wxS( "Quantity" );
|
return m_cols[aCol].m_fieldName == wxS( "Quantity" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FIELDS_EDITOR_GRID_DATA_MODEL::ColIsItemNumber( int aCol )
|
||||||
|
{
|
||||||
|
wxCHECK( aCol >= 0 && aCol < (int) m_cols.size(), false );
|
||||||
|
return m_cols[aCol].m_fieldName == wxS( "Item Number" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool FIELDS_EDITOR_GRID_DATA_MODEL::cmp( const DATA_MODEL_ROW& lhGroup,
|
bool FIELDS_EDITOR_GRID_DATA_MODEL::cmp( const DATA_MODEL_ROW& lhGroup,
|
||||||
const DATA_MODEL_ROW& rhGroup,
|
const DATA_MODEL_ROW& rhGroup,
|
||||||
@ -284,6 +292,13 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::Sort()
|
|||||||
return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
|
return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// Time to renumber the item numbers
|
||||||
|
int itemNumber = 1;
|
||||||
|
for( DATA_MODEL_ROW& row : m_rows )
|
||||||
|
{
|
||||||
|
row.m_ItemNumber = itemNumber++;
|
||||||
|
}
|
||||||
|
|
||||||
ExpandAfterSort();
|
ExpandAfterSort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ struct DATA_MODEL_ROW
|
|||||||
m_Flag = aType;
|
m_Flag = aType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int m_ItemNumber;
|
||||||
GROUP_TYPE m_Flag;
|
GROUP_TYPE m_Flag;
|
||||||
std::vector<SCH_REFERENCE> m_Refs;
|
std::vector<SCH_REFERENCE> m_Refs;
|
||||||
};
|
};
|
||||||
@ -121,6 +122,7 @@ public:
|
|||||||
|
|
||||||
bool ColIsReference( int aCol );
|
bool ColIsReference( int aCol );
|
||||||
bool ColIsQuantity( int aCol );
|
bool ColIsQuantity( int aCol );
|
||||||
|
bool ColIsItemNumber( int aCol );
|
||||||
|
|
||||||
void SetSorting( int aCol, bool ascending )
|
void SetSorting( int aCol, bool ascending )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user