DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( wxWindow* parent, LIB_PART& aPart ) : DIALOG_LIB_EDIT_PIN_TABLE_BASE( parent ), m_Model( new DataViewModel( aPart ) ) { #ifdef REASSOCIATE_HACK m_Model->SetWidget( m_Pins ); #endif m_Pins->AssociateModel( m_Model.get() ); /// @todo wxFormBuilder bug #61 -- move to base once supported wxDataViewTextRenderer* rend0 = new wxDataViewTextRenderer( wxT( "string" ), wxDATAVIEW_CELL_INERT ); wxDataViewColumn* col0 = new wxDataViewColumn( _( "Number" ), rend0, DataViewModel::PIN_NUMBER, 100, wxAlignment( wxALIGN_LEFT | wxALIGN_TOP ), wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE ); wxDataViewTextRenderer* rend1 = new wxDataViewTextRenderer( wxT( "string" ), wxDATAVIEW_CELL_INERT ); wxDataViewColumn* col1 = new wxDataViewColumn( _( "Name" ), rend1, DataViewModel::PIN_NAME, 100, wxAlignment( wxALIGN_LEFT | wxALIGN_TOP ), wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE ); wxDataViewTextRenderer* rend2 = new wxDataViewTextRenderer( wxT( "string" ), wxDATAVIEW_CELL_INERT ); wxDataViewColumn* col2 = new wxDataViewColumn( _( "Type" ), rend2, DataViewModel::PIN_TYPE, 100, wxAlignment( wxALIGN_LEFT | wxALIGN_TOP ), wxDATAVIEW_COL_RESIZABLE ); wxDataViewTextRenderer* rend3 = new wxDataViewTextRenderer( wxT( "string" ), wxDATAVIEW_CELL_INERT ); wxDataViewColumn* col3 = new wxDataViewColumn( _( "Position" ), rend3, DataViewModel::PIN_POSITION, 100, wxAlignment( wxALIGN_LEFT | wxALIGN_TOP ), wxDATAVIEW_COL_RESIZABLE ); m_Pins->AppendColumn( col0 ); m_Pins->SetExpanderColumn( col0 ); m_Pins->AppendColumn( col1 ); m_Pins->AppendColumn( col2 ); m_Pins->AppendColumn( col3 ); GetSizer()->SetSizeHints(this); Centre(); }
wxDataViewColumn* BOM_TABLE_MODEL::AddColumn( BOM_COLUMN* aColumn, int aPosition ) { static const unsigned int flags = wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE; if( !m_widget || !aColumn || !aColumn->IsVisible() ) return nullptr; wxDataViewCellMode editFlag = aColumn->IsReadOnly() ? wxDATAVIEW_CELL_INERT : wxDATAVIEW_CELL_EDITABLE; auto renderer = new wxDataViewTextRenderer( "string" , editFlag ); auto column = new wxDataViewColumn( aColumn->Title(), renderer, aColumn->Id(), 150, //TODO - variable default width? wxAlignment( wxALIGN_LEFT ), flags ); // Work out where to insert the column std::set<unsigned int> columnsBefore; for( auto testCol : ColumnList.Columns ) { if( testCol->Id() == aColumn->Id() ) { break; } else { columnsBefore.insert( testCol->Id() ); } } bool found = false; for( unsigned int ii=0; ii<m_widget->GetColumnCount(); ii++ ) { auto col = m_widget->GetColumn( ii ); if( !col ) continue; // If the new column is already in the view, escape if( col->GetModelColumn() == aColumn->Id() ) { return col; } // If we should insert the new column BEFORE this one if( columnsBefore.count( col->GetModelColumn() ) == 0 ) { found = true; m_widget->InsertColumn( ii, column ); break; } } if( !found ) m_widget->AppendColumn( column ); column->SetResizeable( true ); return column; }