alnmulti_model.cpp
来自「ncbi源码」· C++ 代码 · 共 647 行 · 第 1/2 页
CPP
647 行
delete *it; } m_RowToRec.clear(); m_pMasterRow = NULL; m_vVisibleRows.clear(); m_vVisibleRowPos.clear();}/// Creates IAlignRow objects for each row in the data source.void CAlnMultiModel::CreateRows(){ if(m_pDataSource) { _ASSERT(m_RowToRec.size() == 0 && m_pMasterRow == NULL); const int aln_rows_n = m_pDataSource->GetNumRows(); int pane_rows_n = aln_rows_n; // rows shown in align pane (Master row is not counted) TNumrow MasterRow = -1; if(m_pDataSource->IsSetAnchor()) { MasterRow = m_pDataSource->GetAnchor(); --pane_rows_n; } m_vVisibleRows.resize(pane_rows_n); m_vVisibleRowPos.resize(pane_rows_n); TLine i_line = 0; m_RowToRec.resize(aln_rows_n); for( TNumrow row = 0; row < aln_rows_n; row++ ) { // call a factory method to create a row instance IAlignRow* p_row = x_CreateRow(row); SRowRecord* p_rec = new SRowRecord(p_row, i_line); m_RowToRec[row] = p_rec; if(row == MasterRow) { m_pMasterRow = p_row; p_rec->SetState(IAlignRow::fItemHidden, true); } else { m_vVisibleRows[i_line] = p_rec; i_line++; } } if(m_bAutoSort) { x_DoUpdateRowsOrder(); // applying sorting } // updating CSelListModelImpl TNumrowModelImpl::TItemVector vItems(pane_rows_n); for( size_t i = 0; i < m_vVisibleRows.size(); i++ ) { vItems[i] = m_vVisibleRows[i]->m_pRow->GetRowNum(); } TNumrowModelImpl::SetItems(vItems, false, false); x_DoUpdateRowPositions(); }} bool CAlnMultiModel::x_SortRows(){ return true; // nothing has been changed}void CAlnMultiModel::x_DoUpdateRowsOrder(){ _ASSERT(m_bAutoSort); // msut be called only when auto sorting is enabled TIndex i_focused = SLM_GetFocusedItemIndex(); const SRowRecord* p_rec = (i_focused >= 0) ? m_vVisibleRows[i_focused] : NULL; if(x_SortRows()) { x_DoUpdateRowLines(); // restore focus int line = p_rec ? p_rec->m_Line : -1; SLM_FocusItem(line); }}void CAlnMultiModel::x_DoUpdateRowLines(){ for(size_t i = 0; i < m_vVisibleRows.size(); i++ ) { SRowRecord& rec = *m_vVisibleRows[i]; rec.m_Line = i; }}void CAlnMultiModel::UpdateOnRowHChanged(void){ x_DoUpdateRowPositions(); SetPortLimits();}/// recalculates vertical positions of row objects based on their order, /// visibility and heightvoid CAlnMultiModel::x_DoUpdateRowPositions(void){ int N = m_vVisibleRows.size(); m_vVisibleRowPos.resize(N); for( int total_H = 0, i = 0; i < N; i++ ) { IAlignRow* pRow = x_GetRowByLine(i); m_vVisibleRowPos[i] = total_H; total_H += pRow->GetHeightPixels(); }}void CAlnMultiModel::SetPortLimits(){ if (m_pDataSource) { double Start = m_pDataSource->GetAlnStart(); double Stop = m_pDataSource->GetAlnStop(); double H = 0; int iLast = m_vVisibleRows.size() - 1; if(iLast > 0) H = GetLinePosY(iLast) + GetLineHeight(iLast); m_Port.SetModelLimitsRect(TModelRect(Start, H - 1, Stop + 1, 0)); } else m_Port.SetModelLimitsRect(TModelRect(0, -1, 0, 0)); }void CAlnMultiModel::SetMasterRow(TNumrow new_master_row){ //Anchor the row to make it "Master" m_pDataSource->SetAnchor(new_master_row); // rearrange Row objects and items IAlignRow* pNewMaster = NULL; if(new_master_row != -1) { // remove row from the Align pane SRowRecord& rec = x_GetRecordByRow(new_master_row); pNewMaster = rec.m_pRow; rec.SetState(IAlignRow::fItemHidden, true); vector<int> vDelItems; vDelItems.push_back(rec.m_Line); DeleteItems(vDelItems, false); } if(m_pMasterRow) { // insert current Master into Align pane TNumrow row = m_pMasterRow->GetRowNum(); SRowRecord& rec = x_GetRecordByRow(row); TLine line = min(rec.m_Line, (TLine) m_vVisibleRows.size()); rec.SetState(IAlignRow::fItemHidden, false); InsertItem(line, m_pMasterRow->GetRowNum(), false); } m_pMasterRow = pNewMaster; if(m_bAutoSort) { x_DoUpdateRowsOrder(); // applying sorting } x_DoUpdateRowPositions(); SetPortLimits(); // set new limits}void CAlnMultiModel::x_UpdateOnDataChanged(){ ClearRows(); if (m_pDataSource) { CreateRows(); SetPortLimits(); }}IAlignRow* CAlnMultiModel::x_GetRowByLine(int index){ _ASSERT(index >= 0 && (size_t) index < m_vVisibleRows.size()); SRowRecord* p_rec = m_vVisibleRows[index]; return static_cast<IAlignRow*>(p_rec->m_pRow);}const IAlignRow* CAlnMultiModel::x_GetRowByLine(int index) const{ _ASSERT(index >= 0 && (size_t) index < m_vVisibleRows.size()); SRowRecord* p_rec = m_vVisibleRows[index]; return static_cast<IAlignRow*>(p_rec->m_pRow);}////////////////////////////////////////////////////////////////////////////////// CSelListModelImpl virtual functionsvoid CAlnMultiModel::x_SelectItem(TIndex index, bool b_sel){ m_vVisibleRows[index]->SetState(IAlignRow::fItemSelected, b_sel);}bool CAlnMultiModel::x_IsItemSelected(TIndex index) const{ return m_vVisibleRows[index]->IsSelected();}// returns number of visible rows (lines)CAlnMultiModel::TIndex CAlnMultiModel::x_GetItemsCount() const{ return m_vVisibleRows.size(); }CAlnMultiModel::TItem CAlnMultiModel::x_GetItem(TIndex index) const{ TNumrow row = x_GetRowByLine(index)->GetRowNum(); return row;}void CAlnMultiModel::x_SetEntries(const TEntryVector& v_entries){ size_t entries_n = v_entries.size(); m_vVisibleRows.resize(entries_n); for( size_t i = 0; i < entries_n; i++ ) { TNumrow row = v_entries[i].first; SRowRecord& rec = *m_RowToRec[row]; rec.m_Line = i; rec.SetState(IAlignRow::fItemSelected, v_entries[i].second); rec.SetState(IAlignRow::fItemHidden, false); m_vVisibleRows[i] = &rec; }}CAlnMultiModel::TIndex CAlnMultiModel::x_GetItemIndex(const TItem& item){ SRowRecord& rec = *m_RowToRec[item]; return rec.IsVisible() ? rec.m_Line : -1;}void CAlnMultiModel::x_InsertItem(TIndex index, const TItemEntry& entry){ TNumrow row = entry.first; SRowRecord* p_rec = m_RowToRec[row]; p_rec->SetState(IAlignRow::fItemSelected, entry.second); p_rec->m_Line = index; m_vVisibleRows.insert(m_vVisibleRows.begin() + index, p_rec);}void CAlnMultiModel::x_CompleteInsertion(){ x_DoUpdateRowLines();}void CAlnMultiModel::x_MarkItemForErase(TIndex index){ m_vVisibleRows[index]->SetState(IAlignRow::fItemHidden, true); m_vVisibleRows[index]->SetState(IAlignRow::fItemSelected, false); m_vVisibleRows[index] = NULL;}void CAlnMultiModel::x_EraseMarkedItems(){ int shift = 0; int count = m_vVisibleRows.size(); for(int i = 0; i < count; i++ ) { if(m_vVisibleRows[i]) { if(shift >0) { m_vVisibleRows[i - shift] = m_vVisibleRows[i]; m_vVisibleRows[i - shift]->m_Line = i - shift; } } else shift++; } m_vVisibleRows.resize(m_vVisibleRows.size() - shift);}void CAlnMultiModel::x_ClearItems(){ for( size_t i = 0; i < m_vVisibleRows.size(); i++ ) { m_vVisibleRows[i]->SetState(IAlignRow::fItemHidden, true); m_vVisibleRows[i]->SetState(IAlignRow::fItemSelected, false); } m_vVisibleRows.clear();}END_NCBI_SCOPE/* * =========================================================================== * $Log: alnmulti_model.cpp,v $ * Revision 1000.1 2004/06/01 21:07:07 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.11 * * Revision 1.11 2004/05/21 22:27:52 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.10 2004/05/10 17:46:35 yazhuk * Addressed GCC warnings * * Revision 1.9 2004/04/27 15:36:28 yazhuk * Fixed SetVisivle() so that it does not change rows order * * Revision 1.8 2004/04/23 14:09:13 johnson * removed invalid ASSERT * * Revision 1.7 2004/04/22 17:09:41 yazhuk * Enable Auto Sorting from UpdateSortOrder() * * Revision 1.6 2004/04/06 19:38:11 dicuccio * Tweak for GCC - cast NULL to pointer type for vector<*> * * Revision 1.5 2004/04/06 16:04:05 yazhuk * Implemented GetSelectedRows(), EnableAutoSorting(), SetRowOrder() * * Revision 1.4 2004/04/02 16:39:42 yazhuk * Selection/visibility handling fixes * * Revision 1.3 2004/03/18 17:08:26 yazhuk * Modified SetVisible() to support "b_invert_others" argument * * Revision 1.2 2004/03/17 20:15:37 yazhuk * Refactored CAlnMultiModel interface * * Revision 1.1 2004/03/09 20:59:14 yazhuk * Initial revision. Factored out from CAlnMultiWidget. * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?