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() ) );
|
||||
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();
|
||||
m_grid->SetColAttr( col, attr );
|
||||
|
@ -566,6 +567,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::LoadFieldNames()
|
|||
|
||||
// Generated field that isn't in any symbol
|
||||
AddField( wxS( "Quantity" ), _( "Qty" ), true, false );
|
||||
AddField( wxS( "Item Number" ), _( "#" ), true, false );
|
||||
|
||||
// User fields second
|
||||
std::set<wxString> userFieldNames;
|
||||
|
@ -807,6 +809,14 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnColumnItemToggled( wxDataViewEvent& event )
|
|||
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 );
|
||||
|
||||
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() );
|
||||
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
|
||||
// if we ask it will give us pre-event info.
|
||||
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 )
|
||||
{
|
||||
if( ColIsReference( aCol ) || ColIsQuantity( aCol ) )
|
||||
if( ColIsReference( aCol ) || ColIsQuantity( aCol ) || ColIsItemNumber( aCol ) )
|
||||
{
|
||||
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)
|
||||
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 );
|
||||
else if( ColIsQuantity( aCol ) )
|
||||
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;
|
||||
}
|
||||
|
@ -220,6 +222,12 @@ bool FIELDS_EDITOR_GRID_DATA_MODEL::ColIsQuantity( int aCol )
|
|||
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,
|
||||
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 );
|
||||
} );
|
||||
|
||||
// Time to renumber the item numbers
|
||||
int itemNumber = 1;
|
||||
for( DATA_MODEL_ROW& row : m_rows )
|
||||
{
|
||||
row.m_ItemNumber = itemNumber++;
|
||||
}
|
||||
|
||||
ExpandAfterSort();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ struct DATA_MODEL_ROW
|
|||
m_Flag = aType;
|
||||
}
|
||||
|
||||
int m_ItemNumber;
|
||||
GROUP_TYPE m_Flag;
|
||||
std::vector<SCH_REFERENCE> m_Refs;
|
||||
};
|
||||
|
@ -121,6 +122,7 @@ public:
|
|||
|
||||
bool ColIsReference( int aCol );
|
||||
bool ColIsQuantity( int aCol );
|
||||
bool ColIsItemNumber( int aCol );
|
||||
|
||||
void SetSorting( int aCol, bool ascending )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue