26 #include <QFileDialog>
27 #include <QMessageBox>
28 #include <QGraphicsView>
29 #include <QStandardItemModel>
51 connect(
_model, SIGNAL(prefixChanged(QString)),
62 QMapIterator<QString,Node*> iter(
_nodeMap);
63 while(iter.hasNext()) {
64 Node* n = iter.next().value();
85 QMapIterator<QString,Node*> iter(
_nodeMap);
86 while(iter.hasNext()) {
87 Node* m = iter.next().value();
97 QGraphicsScene::mousePressEvent(ev);
98 if (ev->button() == Qt::LeftButton) {
99 QGraphicsItem* itm = itemAt(ev->scenePos(),QTransform());
103 Node* np =
dynamic_cast<Node*
>(itm);
106 np =
dynamic_cast<Node*
>(itm->parentItem());
119 QPointF curPos(ev->scenePos().x(),ev->scenePos().y());
120 const bool isIn = prop->
isInput();
139 QGraphicsScene::mouseMoveEvent(ev);
145 QGraphicsScene::mouseReleaseEvent(ev);
156 }
catch (
const std::runtime_error& err) {
177 QStringList nodesout,nodesin;
178 QStringList slotout,slotin;
180 for (
int ii=0;ii<nodes.size();ii++) {
181 QString name = nodes[ii];
189 QStringList pdata =
_model->
getValue(name+
".editorinfo").split(
" ");
190 if (pdata.size() >= 2) {
191 float x = pdata.at(0).toFloat();
192 float y = pdata.at(1).toFloat();
199 node->setToolTip(
"");
201 node->setToolTip(
"<b>" + tr(
"Comment:") +
"</b><br/>" + str);
208 for (
int jj=0; jj < ins.size(); jj++) {
211 for (
int jj=0; jj < outs.size(); jj++) {
214 for (
int jj=0; jj < outs.size(); jj++) {
215 QString curO = name+
"."+outs[jj];
218 foreach (
const QString& con, conns) {
221 slotin << con.section(
".",-1,-1);
222 nodesin << con.section(
".",0,0);
227 for (
int ii=0; ii<slotout.size(); ii++) {
229 connectNodes(nodesout[ii],slotout[ii],nodesin[ii],slotin[ii]);
231 catch(
const std::exception& e) {
232 if (QMessageBox::question(
233 0,
"connection error",
235 "Failed to connect <em>%1.%2</em> "
236 "to <em>%3.%4</em>.<br>"
237 "This may happen after slot renaming<br>"
238 "and/or using old module descriptions.<br><br>"
239 "Exception message:<br>%5<br><br>"
240 "Remove this invalid connection from workflow?")
241 .arg(nodesout[ii]).arg(slotout[ii])
242 .arg(nodesin[ii]).arg(slotin[ii])
243 .arg(e.what()), QMessageBox::Yes, QMessageBox::No)
244 == QMessageBox::Yes) {
246 nodesout[ii]+
"."+slotout[ii],nodesin[ii]+
"."+slotin[ii]);
256 QString node0, QString prop0, QString node1, QString prop1) {
259 Q_ASSERT(out && in) ;
264 throw std::runtime_error(QString(
265 "Property <em>%1.%2</em> does not exist.")
266 .arg(node0).arg(prop0).toStdString());
269 throw std::runtime_error(QString(
270 "Property <em>%1.%2</em> does not exist.")
271 .arg(node1).arg(prop1).toStdString());
274 Q_ASSERT(outp && inp) ;
286 QString fname = QFileDialog::getSaveFileName(
287 0, tr(
"Select File to Write"),
288 "",tr(
"Images (*.png *.jpg *.bmp *.gif);;"
289 "PDF/Postscript (*.pdf *.ps)"));
290 if (fname.contains(QRegExp(
"\\.(pdf|ps)\\s*$",Qt::CaseInsensitive))) {
291 QPrinter printer(QPrinter::HighResolution);
292 printer.setPaperSize(sceneRect().size(),QPrinter::Point);
293 printer.setOutputFileName(fname);
294 printer.setFullPage(
true);
296 painter.begin(&printer);
300 else if (!fname.isEmpty()) {
301 QPixmap pixmap(sceneRect().size().toSize());
302 pixmap.fill(Qt::white);
303 QPainter painter(&pixmap);
304 painter.setRenderHint(QPainter::Antialiasing);
306 if(!pixmap.save(fname)) {
307 QMessageBox::warning(
308 0,tr(
"error writing file"),
309 tr(
"failed to save the workflow visualization to<br>"
311 "Perhaps the image file format is not supported.")
318 switch(keyEvent->key()) {
348 QGraphicsScene::keyPressEvent(keyEvent);
351 void NodeHandler::dragEnterEvent(QGraphicsSceneDragDropEvent* ev) {
352 if (ev->mimeData()->hasFormat(
"application/x-qstandarditemmodeldatalist"))
355 QGraphicsScene::dragEnterEvent(ev);
358 void NodeHandler::dragMoveEvent(QGraphicsSceneDragDropEvent* ev) {
359 if (ev->mimeData()->hasFormat(
"application/x-qstandarditemmodeldatalist"))
362 QGraphicsScene::dragMoveEvent(ev);
365 void NodeHandler::dropEvent(QGraphicsSceneDragDropEvent* ev) {
366 QStandardItemModel m;
367 bool res = m.dropMimeData(ev->mimeData(),Qt::CopyAction,0,0,QModelIndex());
368 if(res && m.rowCount() == 1 && m.columnCount() == 1) {
369 QString className = m.item(0)->text();
375 if(!instName.isEmpty()) {
378 QPointF pos = ev->scenePos();
379 QString posString = QString(
"%0 %1").arg(pos.x()).arg(pos.y());
389 QGraphicsScene::dropEvent(ev);
393 QString nodeName, propName;
396 QGraphicsItem* item = itemAt(ev->scenePos(),QTransform());
398 Node* node =
dynamic_cast<Node*
>(item);
402 node =
dynamic_cast<Node*
>(prop->parentItem());
410 if (nodeName.isEmpty()) {
411 QGraphicsScene::contextMenuEvent(ev);
420 QIcon disIco(
":/icons/disconnect.png");
421 QIcon renIco(
":/icons/rename.png");
422 QIcon delIco(
":/icons/delete.png");
426 if (!propName.isEmpty()) {
427 QAction* act = menu.addAction(
428 disIco, tr(
"disconnect %1").arg(propName.section(
".",1)));
429 act->setData(propName);
434 QAction* delAct = menu.addAction(delIco, tr(
"delete"));
435 QAction* renAct = menu.addAction(renIco, tr(
"rename"));
436 QAction* disAct = menu.addAction(disIco, tr(
"disconnect all slots"));
439 QStringList slotNames;
443 QMenu* dmenu = menu.addMenu(disIco, tr(
"disconnect slot"));
444 foreach (
const QString& cur, slotNames) {
446 dmenu->addAction(disIco, cur);
447 curAct->setData(QString(
"%1.%2").arg(nodeName).arg(cur));
451 QAction* selAct = menu.exec(ev->screenPos());
453 QString data = selAct->data().toString();
454 if (!data.isEmpty()) {
455 Q_ASSERT(data.contains(QRegExp(
"^[\\w_-]+\\.[\\w_-]+$")));
458 else if (selAct == delAct) {
461 else if (selAct == renAct) {
464 else if (selAct == disAct) {
474 if (comment.isEmpty()) {
478 "<b>" + tr(
"Comment:") +
"</b><br/>" + comment);
void setSelectedNode(bool s)
sets the node selected or not
Declaration of class FileManager.
This model wraps a ParameterFile instance and provides access to the data interpreted as a (directed)...
void setNodeActive()
sets the nodes active or inactive
QStringList nodes() const
Get nodes in current graph.
void _deselectAllNodes()
deselects all nodes
QGraphicsItem that contains nodeproperties and draws the node.
virtual QString setPrefix(const QString &prefix)
Change prefix.
void selectNode(QString name)
select some node
void disconnectAllSlots(QString node, bool draw=true)
disconnect all slots of given node
QString getValue(QString parName) const
Get a parameter from the underlying parameter file.
Declaration of class Node.
Node * _selectedNode
pointer to currently selected node (zero if none selected)
void loadFromModel()
loads the scene from the set GraphModel
Declaration of class GraphModel.
void addProperty(QString name, bool input)
adds a property to the node
virtual void keyPressEvent(QKeyEvent *keyEvent)
handles key press events
QPointF getSocketCenter() const
socket center including node position
QStringList getInputs(QString objName) const
Get input slots of object.
void setClassName(QString modname)
set node class name
Declaration of class QParameterFile.
QString prefix() const
Get property _prefix.
void updateTooltip(QString comment)
update tooltip of selected node
QStringList getOutputs(QString objName) const
Get output slots of object.
QStringList getOutputDisplayNames(QString objName) const
Get output slots of object.
QRectF boundingRect() const
bounding Rect, always 0 to be not selectable
void addConnection(ConnectionLine *cl)
add a connectionline to the property
QString getClass(QString objName, bool fixCase=false) const
get class of some given object
void selectNext(bool back=false)
select next item
ConnectionLine * _cline
buffered connection line for slot connection drawing
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
handles mouse movement
QStringList getInputDisplayNames(QString objName) const
Get input slots of object.
bool isInput() const
returns the PropType of the property
NodeHandler(GraphModel *model, QObject *parent=0)
default constructor
QString getClassName() const
get class name
NodeProperty * getProperty(QString propName) const
get node property
QString addNode(QString className, bool draw=true)
add new node of given kind
QString getFullName() const
property name including node instance name
void setStartPoint(int x, int y)
sets start point (for drawing)
Declaration of class ConnectionLine.
GraphModel * _model
current set GraphModel
bool prefixValid() const
Check prefix.
void moveBy(qreal dx, qreal dy)
moves the property and if connected all connectionlines
void disconnectSlot(QString source, QString target=QString(), bool draw=true)
disconnect slots
GraphModel * model()
get the current GraphModel
Line that connects two slots of two different nodes.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
handles all mousebutton release events
bool deleteNode(QString nodename, bool draw=true)
delete node
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
context menu
QMap< QString, Node * > _nodeMap
map for node lookup
void nodeTypeSelected(QString type) const
Send type of currently selected node.
virtual bool load(const QString &fName="")
Load model content from parameterFile.
bool active() const
Returns the bool value of the Active Parameter.
bool _addLine
state of slot connection mode
Property(/Parameter) of a node.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
handles mouse press events
void saveFlowchart()
save flowchart to file
bool load(QString fname)
load the GraphModel from the given filename and calls loadFromModel to fill the scene ...
void setActive(bool activeStatus)
changes the nodes activity
QString getInstanceName()
get node name
void setValue(QString parName, QString value)
Set a parameter in the underlying parameter file.
NodeProperty * _startProp
buffer that stores the slot connection start property
Declaration of class NodeHandler.
void connectSlot(QString source, QString target, bool draw=true)
connect slots
void renameNode(QString nodename, bool draw=true)
rename node
void statusMessage(QString msg) const
message to display on status bar
void setStartEndProp(NodeProperty *start, NodeProperty *end)
sets start and end property
virtual ~NodeHandler()
default destructor
void connectNodes(QString node0, QString prop0, QString node1, QString prop1)
connects two node with its slots: node0.prop0 to node1.prop1
void setEndPoint(int x, int y)
sets end point (for drawing)