mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Enable gas selection through a context menu
This patch re-enables gas selection through in the add dive profile. Good thing ( and I really didn't think of that before ) is that it is less than half of the code of the other implementation. :D Fixes #265 Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
25a52056c6
commit
82ac9ef9c6
2 changed files with 26 additions and 0 deletions
|
@ -675,9 +675,25 @@ DiveHandler::DiveHandler(): QGraphicsEllipseItem()
|
|||
setZValue(2);
|
||||
}
|
||||
|
||||
int DiveHandler::parentIndex()
|
||||
{
|
||||
DivePlannerGraphics *view = qobject_cast<DivePlannerGraphics*>(scene()->views().first());
|
||||
return view->handles.indexOf(this);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
m.addSeparator();
|
||||
m.addAction(QObject::tr("Remove this Point"), this, SLOT(selfRemove()));
|
||||
m.exec(event->screenPos());
|
||||
}
|
||||
|
@ -689,6 +705,13 @@ void DiveHandler::selfRemove()
|
|||
view->keyDeleteAction();
|
||||
}
|
||||
|
||||
void DiveHandler::changeGas()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction*>(sender());
|
||||
QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
|
||||
plannerModel->setData(index, action->text());
|
||||
}
|
||||
|
||||
void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton)
|
||||
|
|
|
@ -117,8 +117,11 @@ public:
|
|||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
|
||||
private:
|
||||
int parentIndex();
|
||||
public slots:
|
||||
void selfRemove();
|
||||
void changeGas();
|
||||
};
|
||||
|
||||
class Ruler : public QGraphicsLineItem{
|
||||
|
|
Loading…
Reference in a new issue