MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QStandardItemModel *model = new QStandardItemModel(7, 4, this); for (int row = 0; row < 7; ++row) { for (int column = 0; column < 4; ++column) { QStandardItem *item = new QStandardItem(QString("%1") .arg(row * 4 + column)); model->setItem(row, column, item); } } tableView = new QTableView; tableView->setModel(model); setCentralWidget(tableView); // 获取视图的项目选择模型 QItemSelectionModel *selectionModel = tableView->selectionModel(); // 定义左上角和右下角的索引,然后使用这两个索引创建选择 QModelIndex topLeft; QModelIndex bottomRight; topLeft = model->index(1, 1, QModelIndex()); bottomRight = model->index(5, 2, QModelIndex()); QItemSelection selection(topLeft, bottomRight); // 使用指定的选择模式来选择项目 selectionModel->select(selection, QItemSelectionModel::Select); ui->mainToolBar->addAction(tr("当前项目"), this, SLOT(getCurrentItemData())); ui->mainToolBar->addAction(tr("切换选择"), this, SLOT(toggleSelection())); }
void EditInteraction::snapMousePressEvent(QMouseEvent * ev, Feature* aLast) { Qt::KeyboardModifiers modifiers = ev->modifiers(); if (!view()->isSelectionLocked()) { if (modifiers) { if (modifiersForToggle(modifiers) && aLast) PROPERTIES(toggleSelection(aLast)); if (modifiersForAdd(modifiers) && aLast) PROPERTIES(addSelection(aLast)); if (g_Merk_Segment_Mode && aLast) { PROPERTIES(setSelection(aLast)); } } else { StackSnap = SnapList; // if (aLast) // PROPERTIES(setSelection(aLast)); } if (!aLast && modifiersForDrag(modifiers)) { EndDrag = StartDrag = XY_TO_COORD(ev->pos()); Dragging = true; } PROPERTIES(checkMenuStatus()); view()->update(); } }
EDA_ITEM* PL_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, bool* aSelectionCancelledFlag ) { int threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); // locate items. COLLECTOR collector; for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() ) { for( WS_DRAW_ITEM_BASE* drawItem : dataItem->GetDrawItems() ) { if( drawItem->HitTest( (wxPoint) aWhere, threshold ) ) collector.Append( drawItem ); } } bool anyCollected = collector.GetCount() != 0; m_selection.ClearReferencePoint(); // Apply some ugly heuristics to avoid disambiguation menus whenever possible if( collector.GetCount() > 1 && !m_skip_heuristics ) { guessSelectionCandidates( collector, aWhere ); } // If still more than one item we're going to have to ask the user. if( collector.GetCount() > 1 ) { collector.m_MenuTitle = _( "Clarify Selection" ); // Must call selectionMenu via RunAction() to avoid event-loop contention m_toolMgr->RunAction( PL_ACTIONS::selectionMenu, true, &collector ); if( collector.m_MenuCancelled ) { if( aSelectionCancelledFlag ) *aSelectionCancelledFlag = true; return nullptr; } } if( collector.GetCount() == 1 ) { EDA_ITEM* item = collector[ 0 ]; toggleSelection( item ); return item; } if( !m_additive && anyCollected ) ClearSelection(); return nullptr; }
int SELECTION_TOOL::findMove( const TOOL_EVENT& aEvent ) { MODULE* module = m_frame->GetModuleByName(); if( module ) { clearSelection(); toggleSelection( module ); m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" ); } return 0; }
TestContextMenu::TestContextMenu(QObject *widget) { if (m_refCount++ == 0) m_instance = new TestContextMenuPrivate(widget); connect(m_instance->m_testToggleCurrentSelectAction, SIGNAL(triggered()), this, SIGNAL(toggleSelection())); connect(m_instance->m_testSelectAllTestsAction, SIGNAL(triggered()), this, SIGNAL(selectAllTests())); connect(m_instance->m_testDeselectAllTestsAction, SIGNAL(triggered()), this, SIGNAL(deselectAllTests())); connect(m_instance->m_testSelectAllManualTestsAction, SIGNAL(triggered()), this, SIGNAL(selectAllManualTests())); }
void hCheckBox::mousePressed(int xx, int yy, int btn) { toggleSelection(); bang(); }
bool SELECTION_TOOL::selectCursor( const VECTOR2I& aWhere, bool aOnDrag ) { BOARD_ITEM* item; GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide(); GENERAL_COLLECTOR collector; if( m_editModules ) collector.Collect( getModel<BOARD>(), GENERAL_COLLECTOR::ModuleItems, wxPoint( aWhere.x, aWhere.y ), guide ); else collector.Collect( getModel<BOARD>(), GENERAL_COLLECTOR::AllBoardItems, wxPoint( aWhere.x, aWhere.y ), guide ); bool anyCollected = collector.GetCount() != 0; // Remove unselectable items for( int i = collector.GetCount() - 1; i >= 0; --i ) { if( !selectable( collector[i] ) || ( aOnDrag && collector[i]->IsLocked() ) ) collector.Remove( i ); } switch( collector.GetCount() ) { case 0: if( !m_additive && anyCollected ) clearSelection(); return false; case 1: toggleSelection( collector[0] ); return true; default: // Apply some ugly heuristics to avoid disambiguation menus whenever possible guessSelectionCandidates( collector ); // Let's see if there is still disambiguation in selection.. if( collector.GetCount() == 1 ) { toggleSelection( collector[0] ); return true; } else if( collector.GetCount() > 1 ) { if( aOnDrag ) Wait( TOOL_EVENT( TC_ANY, TA_MOUSE_UP, BUT_LEFT ) ); item = disambiguationMenu( &collector ); if( item ) { toggleSelection( item ); return true; } } break; } return false; }
PublishDialog::PublishDialog(QWidget *parent) : QDialog(parent), select(true) { ui.setupUi(this); connect(ui.pushButton_select, SIGNAL(clicked()), this, SLOT(toggleSelection())); }
bool SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere, bool aAllowDisambiguation ) { BOARD_ITEM* item; GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide(); GENERAL_COLLECTOR collector; // Preferred types (they have the priority when if they are covered by a bigger item) const KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, PCB_LINE_T, PCB_MODULE_TEXT_T, EOT }; if( m_editModules ) collector.Collect( getModel<BOARD>(), GENERAL_COLLECTOR::ModuleItems, wxPoint( aWhere.x, aWhere.y ), guide ); else collector.Collect( getModel<BOARD>(), GENERAL_COLLECTOR::AllBoardItems, wxPoint( aWhere.x, aWhere.y ), guide ); switch( collector.GetCount() ) { case 0: if( !m_additive ) clearSelection(); return false; case 1: toggleSelection( collector[0] ); return true; default: // Remove unselectable items for( int i = collector.GetCount() - 1; i >= 0; --i ) { if( !selectable( collector[i] ) ) collector.Remove( i ); } // Check if among the selection candidates there is only one instance of preferred type item = prefer( collector, types ); if( item ) { toggleSelection( item ); return true; } // Let's see if there is still disambiguation in selection.. if( collector.GetCount() == 1 ) { toggleSelection( collector[0] ); return true; } else if( aAllowDisambiguation && collector.GetCount() > 1 ) { item = disambiguationMenu( &collector ); if( item ) { toggleSelection( item ); return true; } } break; } return false; }