void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event) { if (selected_dive == -1) return; QMenu m; QMenu *gasChange = m.addMenu(tr("Add Gas Change")); GasSelectionModel *model = GasSelectionModel::instance(); model->repopulate(); int rowCount = model->rowCount(); for (int i = 0; i < rowCount; i++) { QAction *action = new QAction(&m); action->setText( model->data(model->index(i, 0),Qt::DisplayRole).toString()); connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); action->setData(event->globalPos()); gasChange->addAction(action); } QAction *action = m.addAction(tr("Add Bookmark"), this, SLOT(addBookmark())); action->setData(event->globalPos()); QList<QGraphicsItem*> itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos()))); Q_FOREACH(QGraphicsItem *i, itemsAtPos) { EventItem *item = dynamic_cast<EventItem*>(i); if (!item) continue; action = new QAction(&m); action->setText(tr("Remove Event")); action->setData(QVariant::fromValue<void*>(item)); // so we know what to remove. connect(action, SIGNAL(triggered(bool)), this, SLOT(removeEvent())); m.addAction(action); action = new QAction(&m); action->setText(tr("Hide similar events")); action->setData(QVariant::fromValue<void*>(item)); connect(action, SIGNAL(triggered(bool)), this, SLOT(hideEvents())); m.addAction(action); break; }
void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { QMenu m; // Don't have a gas selection for the last point QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS); if (index.sibling(index.row() + 1, index.column()).isValid()) { GasSelectionModel *model = GasSelectionModel::instance(); model->repopulate(); int rowCount = model->rowCount(); for (int i = 0; i < rowCount; i++) { QAction *action = new QAction(&m); action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString()); connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); m.addAction(action); } }
void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { QMenu m; GasSelectionModel *model = GasSelectionModel::instance(); model->repopulate(); int rowCount = model->rowCount(); for (int i = 0; i < rowCount; i++) { QAction *action = new QAction(&m); action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString()); connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); m.addAction(action); } // don't allow removing the last point if (plannerModel->rowCount() > 1) { m.addSeparator(); m.addAction(QObject::tr("Remove this point"), this, SLOT(selfRemove())); m.exec(event->screenPos()); } }