Commit 1857fd38 authored by Florent D'Halluin's avatar Florent D'Halluin
Browse files

[yavgui] Enable transition deletion.

* yavgui/src/g_painter.hxx: Add vcsn_index (htransition)
* yavgui/src/g_scene.cc,
* yavgui/src/g_scene.hh,
* yavgui/src/g_transition.cc,
* yavgui/src/g_transition.hh: Add signals/slots/connections.
* yavgui/src/g_vcsn_handler.cc,
* yavgui/src/g_vcsn_handler.hh,
* yavgui/src/g_vcsn_handler.hxx: Implement deletion.
parent 92556a61
2009-08-04 d-halluin <d-halluin@lrde.epita.fr>
[yavgui] Enable transition deletion.
* yavgui/src/g_painter.hxx: Add vcsn_index (htransition)
* yavgui/src/g_scene.cc,
* yavgui/src/g_scene.hh,
* yavgui/src/g_transition.cc,
* yavgui/src/g_transition.hh: Add signals/slots/connections.
* yavgui/src/g_vcsn_handler.cc,
* yavgui/src/g_vcsn_handler.hh,
* yavgui/src/g_vcsn_handler.hxx: Implement deletion.
2009-08-04 d-halluin <d-halluin@lrde.epita.fr>
 
[yavgui] Do not add a state when a transition is highlighted.
......
......@@ -93,7 +93,8 @@ namespace gui
transition_index[std::make_pair (from, to)] += 1;
GTransition *transition =
new GTransition (*from, *to, label.str ().c_str (), index);
new GTransition (*itransition, *from, *to,
label.str ().c_str (), index);
(*scene_)->addItem (transition);
(*scene_)->connectTransition(transition);
}
......
......@@ -58,6 +58,8 @@ namespace gui
void
GScene::connectTransition(GTransition* transition)
{
connect(transition, SIGNAL(delTransition()),
this, SLOT(delTransition()));
connect(transition, SIGNAL(selected()),
this, SLOT(itemSelected()));
connect(transition, SIGNAL(deselected()),
......@@ -70,6 +72,12 @@ namespace gui
emit delState(dynamic_cast<GState*>(sender()));
}
void
GScene::delTransition()
{
emit delTransition(dynamic_cast<GTransition*>(sender()));
}
void
GScene::itemSelected()
{
......
......@@ -49,6 +49,7 @@ namespace gui
public slots:
// Connect GState::delState() to this.
void delState();
void delTransition();
// Used to ignore right click events.
void itemSelected();
......@@ -59,6 +60,7 @@ namespace gui
// Connect GVcsnHandler to those.
void delState(GState* state);
void addState(QPointF pos);
void delTransition(GTransition* transition);
private:
bool item_selected_;
......
......@@ -35,10 +35,11 @@ namespace gui
{
namespace display
{
GTransition::GTransition(GState& from,
GTransition::GTransition(int vcsn_index,
GState& from,
GState& to,
QString label,
int index)
int transition_index)
: state_from_ (from),
state_to_ (to),
quad_point_distance_ (1),
......@@ -50,7 +51,8 @@ namespace gui
color_ (default_color_),
label_ (label),
selected_ (false),
transition_index_ (index)
transition_index_ (transition_index),
vcsn_index_(vcsn_index)
{
setCursor (QCursor (Qt::ArrowCursor));
setAcceptsHoverEvents (true);
......@@ -94,6 +96,12 @@ namespace gui
return shape_;
}
int
GTransition::index () const
{
return vcsn_index_;
}
void
GTransition::paint (QPainter *painter,
const QStyleOptionGraphicsItem *,
......@@ -280,6 +288,18 @@ namespace gui
void
GTransition::mousePressEvent (QGraphicsSceneMouseEvent* event)
{
if (!selected_)
{
event->ignore();
return;
}
if (event->button () == Qt::RightButton)
{
event->accept();
emit delTransition();
return;
}
if (label_rect_.contains (event->pos ().toPoint ()))
{
label_grab_ = true;
......
......@@ -39,10 +39,11 @@ namespace gui
Q_OBJECT
public:
GTransition (GState& from,
GTransition (int vcsn_index,
GState& from,
GState& to,
QString label,
int index = 0);
int transition_index = 0);
QRectF boundingRect () const;
QPainterPath shape () const;
......@@ -57,6 +58,9 @@ namespace gui
void mouseMoveEvent (QGraphicsSceneMouseEvent* event);
void mousePressEvent (QGraphicsSceneMouseEvent* event);
// Return vcsn_index.
int index() const;
public slots:
// Refresh both hook points, the label point and the curve quad point.
void refresh ();
......@@ -70,6 +74,8 @@ namespace gui
void selected ();
void deselected ();
void delTransition();
private:
// The transition goes from state_from_ to state_to_
......@@ -111,6 +117,9 @@ namespace gui
// Index of the transition among transitions between the same states.
int transition_index_;
// Index of the transition in the vaucanson automaton.
int vcsn_index_;
};
} // ! namespace display
} // ! namespace gui
......
......@@ -64,6 +64,24 @@ namespace gui
boost::apply_visitor (op, **(info_.automaton));
}
GVcsnHandler::DelTransition::DelTransition(SceneInfo& i, GTransition* t)
: info(i),
transition(t)
{
}
void
GVcsnHandler::delTransition(GTransition* transition)
{
if (! *(info_.automaton))
throw exceptions::NoAutomatonStructure ();
if (!transition)
throw exceptions::NullParameter ();
DelTransition op(info_, transition);
boost::apply_visitor (op, **(info_.automaton));
}
GVcsnHandler::GVcsnHandler (GScene** scene,
GView** view,
automaton_variant** automaton)
......@@ -75,6 +93,8 @@ namespace gui
this, SLOT(addState(QPointF)));
connect(*scene, SIGNAL(delState(GState*)),
this, SLOT(delState(GState*)));
connect(*scene, SIGNAL(delTransition(GTransition*)),
this, SLOT(delTransition(GTransition*)));
}
GVcsnHandler::~GVcsnHandler ()
......
......@@ -64,6 +64,7 @@ namespace gui
public slots:
void addState(QPointF pos);
void delState(GState* state);
void delTransition(GTransition* transition);
private:
......@@ -91,6 +92,18 @@ namespace gui
GState* state;
};
struct DelTransition: public boost::static_visitor<>
{
DelTransition(SceneInfo& info,
GTransition* transition);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GTransition* transition;
};
SceneInfo info_;
};
} // ! namespace display
......
......@@ -63,6 +63,20 @@ namespace gui
(*(info.scene))->itemDeselected();
state = 0;
}
template<typename Automaton>
void
GVcsnHandler::DelTransition::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
// FIXME: this cast may be unsafe:
automaton.del_transition((htransition_t) transition->index());
delete (transition); // removes it from the scene properly.
(*(info.scene))->itemDeselected();
transition = 0;
}
} // ! namespace display
} // ! namespace gui
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment