\r
#include <QGraphicsScene>\r
#include <QEvent>\r
+#include <QGraphicsSceneContextMenuEvent>\r
+#include <QGraphicsSceneDragDropEvent>\r
+#include <QGraphicsSceneHelpEvent>\r
+#include <QGraphicsSceneHoverEvent>\r
#include <QGraphicsSceneMouseEvent>\r
+#include <QGraphicsSceneMoveEvent>\r
+#include <QGraphicsSceneResizeEvent>\r
+#include <QGraphicsSceneWheelEvent>\r
+#include <QInputDialog>\r
\r
#include "QNEPort.h"\r
#include "QNEConnection.h"\r
// -------------------------------------------------------------------------\r
PipelineEditor::QNodesEditor::\r
QNodesEditor( QObject* parent )\r
- : Superclass( parent )\r
+ : Superclass( parent ),\r
+ m_Conn( NULL ),\r
+ m_Workspace( NULL )\r
{\r
- this->m_Conn = NULL;\r
}\r
\r
// -------------------------------------------------------------------------\r
{\r
}\r
\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNodesEditor::\r
+TWorkspace* PipelineEditor::QNodesEditor::\r
+workspace( )\r
+{\r
+ return( this->m_Workspace );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+const PipelineEditor::QNodesEditor::\r
+TWorkspace* PipelineEditor::QNodesEditor::\r
+workspace( ) const\r
+{\r
+ return( this->m_Workspace );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNodesEditor::\r
+setWorkspace( TWorkspace* ws )\r
+{\r
+ this->m_Workspace = ws;\r
+ this->m_Graph = TGraph::New( );\r
+\r
+ // Create blocks\r
+ auto vIt = this->m_Workspace->GetGraph( )->BeginVertices( );\r
+ auto vIt_end = this->m_Workspace->GetGraph( )->EndVertices( );\r
+ for( ; vIt != vIt_end; ++vIt )\r
+ {\r
+ this->_CreateBlock(\r
+ dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ),\r
+ QPointF( vIt->second->GetViewX( ), vIt->second->GetViewY( ) )\r
+ );\r
+\r
+ } // rof\r
+\r
+ // Add edges\r
+ auto rIt = this->m_Workspace->GetGraph( )->BeginEdgesRows( );\r
+ auto rIt_end = this->m_Workspace->GetGraph( )->EndEdgesRows( );\r
+ for( ; rIt != rIt_end; ++rIt )\r
+ {\r
+ QNEBlock* orig = this->m_Graph->GetVertex( rIt->first );\r
+ auto cIt = rIt->second.begin( );\r
+ for( ; cIt != rIt->second.end( ); ++cIt )\r
+ {\r
+ QNEBlock* dest = this->m_Graph->GetVertex( cIt->first );\r
+ auto eIt = cIt->second.begin( );\r
+ for( ; eIt != cIt->second.end( ); ++eIt )\r
+ {\r
+ QNEOutputPort* op = orig->outputPort( eIt->first.c_str( ) );\r
+ QNEInputPort* ip = dest->inputPort( eIt->second.c_str( ) );\r
+ if( op == NULL || ip == NULL )\r
+ continue;\r
+\r
+ QNEConnection* c = new QNEConnection( 0, this->m_Scene );\r
+ c->setPort1( op );\r
+ c->setPort2( ip );\r
+ c->updatePosFromPorts( );\r
+ c->updatePath( );\r
+ this->m_Graph->AddConnection( rIt->first, cIt->first, c );\r
+\r
+ } // rof\r
+\r
+ } // rof\r
+\r
+ } // rof\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+std::string PipelineEditor::QNodesEditor::\r
+createFilter( const std::string& filter, const QPointF& pnt )\r
+{\r
+ std::string name = filter;\r
+ while( this->m_Workspace->HasFilter( name ) )\r
+ name += std::string( "_" );\r
+ if( this->m_Workspace->CreateFilter( filter, name ) )\r
+ {\r
+ this->_CreateBlock( this->m_Workspace->GetFilter( name ), pnt );\r
+ return( name );\r
+ }\r
+ else\r
+ return( "" );\r
+}\r
+\r
// -------------------------------------------------------------------------\r
void PipelineEditor::QNodesEditor::\r
install( QGraphicsScene* s )\r
}\r
\r
// -------------------------------------------------------------------------\r
-bool PipelineEditor::QNodesEditor::\r
-eventFilter( QObject* o, QEvent* e )\r
+void PipelineEditor::QNodesEditor::\r
+_CreateBlock( TFilter* f, const QPointF& pnt )\r
{\r
- QGraphicsSceneMouseEvent* me = ( QGraphicsSceneMouseEvent* ) e;\r
+ if( f == NULL )\r
+ return;\r
+\r
+ // Add block\r
+ QNEBlock* b = new QNEBlock( f, 0, this->m_Scene );\r
+ b->setPos( pnt );\r
\r
- switch ( ( int ) e->type( ) )\r
+ // Keep a trace of this visual graph\r
+ this->m_Graph->SetVertex( f->GetName( ), b );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNodesEditor::\r
+_DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item )\r
+{\r
+ switch( evt->button( ) )\r
{\r
- case QEvent::GraphicsSceneMousePress:\r
+ case Qt::LeftButton:\r
{\r
- switch ( ( int ) me->button( ) )\r
- {\r
- case Qt::LeftButton:\r
+ QNEBlock* block = dynamic_cast< QNEBlock* >( item );\r
+ QNEPort* port = dynamic_cast< QNEPort* >( item );\r
+ QNEConnection* conn = dynamic_cast< QNEConnection* >( item );\r
+\r
+ if( block != NULL )\r
{\r
- QGraphicsItem* item = this->itemAt( me->scenePos( ) );\r
- if( item && item->type( ) == QNEPort::Type )\r
+ QString old_name = block->namePort( );\r
+ bool ok;\r
+ QString new_name =\r
+ QInputDialog::getText(\r
+ dynamic_cast< QWidget* >( this->parent( ) ),\r
+ "Change filter name",\r
+ "Filter name:",\r
+ QLineEdit::Normal,\r
+ old_name,\r
+ &ok\r
+ );\r
+ if( ok && !new_name.isEmpty( ) && old_name != new_name )\r
{\r
- this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
- this->m_Conn->setPort1( ( QNEPort* ) item );\r
- this->m_Conn->setPos1( item->scenePos( ) );\r
- this->m_Conn->setPos2( me->scenePos( ) );\r
- this->m_Conn->updatePath( );\r
+ ok = this->m_Graph->RenameVertex(\r
+ old_name.toStdString( ),\r
+ new_name.toStdString( )\r
+ );\r
+ if( ok )\r
+ {\r
+ block->setNamePort( new_name );\r
+ this->m_Workspace->GetGraph( )->RenameVertex(\r
+ old_name.toStdString( ),\r
+ new_name.toStdString( )\r
+ );\r
\r
- return( true );\r
- }\r
- else if( item && item->type( ) == QNEBlock::Type )\r
- {\r
- /* if( selBlock )\r
- selBlock->setSelected( ); */\r
- // selBlock = ( QNEBlock* ) item;\r
+ } // fi\r
\r
} // fi\r
- break;\r
}\r
- case Qt::RightButton:\r
+ else if( port != NULL )\r
{\r
- QGraphicsItem* item = itemAt( me->scenePos( ) );\r
- if( item && ( item->type( ) == QNEConnection::Type || item->type( ) == QNEBlock::Type ) )\r
- delete item;\r
- // if( selBlock == ( QNEBlock* ) item )\r
- // selBlock = 0;\r
- break;\r
- }\r
}\r
+ else if( conn != NULL )\r
+ {\r
+ } // fi\r
+ }\r
+ break;\r
+ /* TODO:\r
+ case Qt::RightButton:\r
+ {\r
+ }\r
+ break;\r
+ case Qt::MiddleButton:\r
+ {\r
+ }\r
+ break;\r
+ */\r
+ default:\r
+ break;\r
+ } // hctiws\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+bool PipelineEditor::QNodesEditor::\r
+eventFilter( QObject* o, QEvent* e )\r
+{\r
+ // Event type\r
+ switch( int( e->type( ) ) )\r
+ {\r
+ case QEvent::GraphicsSceneContextMenu:\r
+ {\r
+ QGraphicsSceneContextMenuEvent* evt =\r
+ dynamic_cast< QGraphicsSceneContextMenuEvent* >( e );\r
+ if( evt != NULL )\r
+ {\r
+ } // fi\r
+ }\r
+ break;\r
+ case QEvent::GraphicsSceneDragEnter:\r
+ {\r
+ QGraphicsSceneDragDropEvent* evt =\r
+ dynamic_cast< QGraphicsSceneDragDropEvent* >( e );\r
+ if( evt != NULL )\r
+ {\r
+ } // fi\r
+ }\r
+ break;\r
+ case QEvent::GraphicsSceneDragLeave:\r
+ {\r
+ QGraphicsSceneDragDropEvent* evt =\r
+ dynamic_cast< QGraphicsSceneDragDropEvent* >( e );\r
+ if( evt != NULL )\r
+ {\r
+ } // fi\r
+ }\r
+ break;\r
+ case QEvent::GraphicsSceneDragMove:\r
+ {\r
+ QGraphicsSceneDragDropEvent* evt =\r
+ dynamic_cast< QGraphicsSceneDragDropEvent* >( e );\r
+ if( evt != NULL )\r
+ {\r
+ } // fi\r
+ }\r
+ break;\r
+ case QEvent::GraphicsSceneDrop:\r
+ {\r
+ QGraphicsSceneDragDropEvent* evt =\r
+ dynamic_cast< QGraphicsSceneDragDropEvent* >( e );\r
+ if( evt != NULL )\r
+ {\r
+ } // fi\r
+ }\r
+ break;\r
+ case QEvent::GraphicsSceneHelp:\r
+ {\r
+ QGraphicsSceneHelpEvent* evt =\r
+ dynamic_cast< QGraphicsSceneHelpEvent* >( e );\r
+ if( evt != NULL )\r
+ {\r
+ } // fi\r
+ }\r
+ break;\r
+ case QEvent::GraphicsSceneHoverEnter:\r
+ {\r
+ QGraphicsSceneHoverEvent* evt =\r
+ dynamic_cast< QGraphicsSceneHoverEvent* >( e );\r
+ if( evt != NULL )\r
+ {\r
+ } // fi\r
+ }\r
+ break;\r
+ case QEvent::GraphicsSceneHoverLeave:\r
+ {\r
+ QGraphicsSceneHoverEvent* evt =\r
+ dynamic_cast< QGraphicsSceneHoverEvent* >( e );\r
+ if( evt != NULL )\r
+ {\r
+ } // fi\r
+ }\r
+ break;\r
+ case QEvent::GraphicsSceneHoverMove:\r
+ {\r
+ QGraphicsSceneHoverEvent* evt =\r
+ dynamic_cast< QGraphicsSceneHoverEvent* >( e );\r
+ if( evt != NULL )\r
+ {\r
+ } // fi\r
}\r
+ break;\r
+ case QEvent::GraphicsSceneMouseDoubleClick:\r
+ {\r
+ QGraphicsSceneMouseEvent* evt =\r
+ dynamic_cast< QGraphicsSceneMouseEvent* >( e );\r
+ if( evt != NULL )\r
+ {\r
+ QGraphicsItem* item = this->itemAt( evt->scenePos( ) );\r
+ if( item != NULL )\r
+ {\r
+ this->_DoubleClick( evt, item );\r
+ return( true );\r
+\r
+ } // fi\r
+\r
+ } // fi\r
+ }\r
+ break;\r
case QEvent::GraphicsSceneMouseMove:\r
{\r
- if( this->m_Conn )\r
+ QGraphicsSceneMouseEvent* evt =\r
+ dynamic_cast< QGraphicsSceneMouseEvent* >( e );\r
+ if( evt != NULL )\r
{\r
- this->m_Conn->setPos2( me->scenePos( ) );\r
- this->m_Conn->updatePath( );\r
- return( true );\r
- }\r
- break;\r
+ if( this->m_Conn )\r
+ {\r
+ if( this->m_Conn->port1( ) == NULL )\r
+ this->m_Conn->setPos1( evt->scenePos( ) );\r
+ else if( this->m_Conn->port2( ) == NULL )\r
+ this->m_Conn->setPos2( evt->scenePos( ) );\r
+ this->m_Conn->updatePath( );\r
+ return( true );\r
+\r
+ } // fi\r
+\r
+ } // fi\r
}\r
- case QEvent::GraphicsSceneMouseRelease:\r
+ break;\r
+ case QEvent::GraphicsSceneMousePress:\r
{\r
- if( this->m_Conn && me->button( ) == Qt::LeftButton )\r
+ QGraphicsSceneMouseEvent* evt =\r
+ dynamic_cast< QGraphicsSceneMouseEvent* >( e );\r
+ if( evt != NULL )\r
{\r
- QGraphicsItem* item = itemAt( me->scenePos( ) );\r
- if( item && item->type( ) == QNEPort::Type )\r
+ switch( evt->button( ) )\r
{\r
- QNEPort* port1 = this->m_Conn->port1( );\r
- QNEPort* port2 = ( QNEPort* ) item;\r
+ case Qt::LeftButton:\r
+ {\r
+ QNEOutputPort* port =\r
+ dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) );\r
+ if( port != NULL )\r
+ {\r
+ if( port->block( ) != NULL )\r
+ {\r
+ this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
+ this->m_Conn->setPort1( port );\r
+ this->m_Conn->setPos1( port->scenePos( ) );\r
+ this->m_Conn->setPos2( evt->scenePos( ) );\r
+ this->m_Conn->updatePath( );\r
+ return( true );\r
\r
- if( port1->block( ) != port2->block( ) && port1->isOutput( ) != port2->isOutput( ) && !port1->isConnected( port2 ) )\r
+ } // fi\r
+\r
+ } // fi\r
+ }\r
+ break;\r
+ case Qt::RightButton:\r
+ {\r
+ QNEInputPort* in_port =\r
+ dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) );\r
+ QNEOutputPort* out_port =\r
+ dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) );\r
+ if( in_port != NULL )\r
{\r
- this->m_Conn->setPos2( port2->scenePos( ) );\r
- this->m_Conn->setPort2( port2 );\r
+ if( in_port->connection( ) == NULL && in_port->block( ) != NULL )\r
+ {\r
+ this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
+ this->m_Conn->setPort2( in_port );\r
+ this->m_Conn->setPos1( evt->scenePos( ) );\r
+ this->m_Conn->setPos2( in_port->scenePos( ) );\r
+ this->m_Conn->updatePath( );\r
+ return( true );\r
+\r
+ } // fi\r
+ }\r
+ else if( out_port != NULL && out_port->block( ) != NULL )\r
+ {\r
+ this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
+ this->m_Conn->setPort1( out_port );\r
+ this->m_Conn->setPos1( out_port->scenePos( ) );\r
+ this->m_Conn->setPos2( evt->scenePos( ) );\r
this->m_Conn->updatePath( );\r
- this->m_Conn = NULL;\r
return( true );\r
- }\r
+\r
+ } // fi\r
}\r
+ break;\r
+ default:\r
+ break;\r
\r
- delete this->m_Conn;\r
- this->m_Conn = NULL;\r
- return( true );\r
- }\r
- break;\r
- }\r
- }\r
- return( this->Superclass::eventFilter( o, e ) );\r
-}\r
+ } // hctiws\r
\r
-// -------------------------------------------------------------------------\r
-void PipelineEditor::QNodesEditor::\r
-save( QDataStream& ds )\r
-{\r
- foreach( QGraphicsItem* item, this->m_Scene->items( ) )\r
- if( item->type( ) == QNEBlock::Type )\r
+ } // fi\r
+ }\r
+ break;\r
+ case QEvent::GraphicsSceneMouseRelease:\r
+ {\r
+ QGraphicsSceneMouseEvent* evt =\r
+ dynamic_cast< QGraphicsSceneMouseEvent* >( e );\r
+ if( evt != NULL )\r
{\r
- ds << item->type( );\r
- ( ( QNEBlock* ) item )->save( ds );\r
- }\r
+ if( this->m_Conn != NULL && evt->button( ) == Qt::LeftButton )\r
+ {\r
+ QNEInputPort* port2 =\r
+ dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) );\r
+ if( port2 != NULL )\r
+ {\r
+ QNEOutputPort* port1 =\r
+ dynamic_cast< QNEOutputPort* >( this->m_Conn->port1( ) );\r
+ if( port1 != NULL )\r
+ {\r
+ if(\r
+ port1->block( ) != port2->block( ) &&\r
+ !port2->hasConnection( ) &&\r
+ !port1->isConnected( port2 )\r
+ )\r
+ {\r
+ this->m_Conn->setPos2( port2->scenePos( ) );\r
+ this->m_Conn->setPort2( port2 );\r
+ this->m_Conn->updatePath( );\r
\r
- foreach( QGraphicsItem* item, this->m_Scene->items( ) )\r
- if( item->type( ) == QNEConnection::Type )\r
- {\r
- ds << item->type( );\r
- ( ( QNEConnection* ) item )->save( ds );\r
- }\r
-}\r
+ this->m_Workspace->Connect(\r
+ port1->block( )->namePort( ).toStdString( ),\r
+ port2->block( )->namePort( ).toStdString( ),\r
+ port1->name( ).toStdString( ),\r
+ port2->name( ).toStdString( )\r
+ );\r
+ this->m_Graph->AddConnection(\r
+ port1->block( )->namePort( ).toStdString( ),\r
+ port2->block( )->namePort( ).toStdString( ),\r
+ this->m_Conn\r
+ );\r
\r
-// -------------------------------------------------------------------------\r
-void PipelineEditor::QNodesEditor::\r
-load( QDataStream& ds )\r
-{\r
- this->m_Scene->clear( );\r
+ this->m_Conn = NULL;\r
+ return( true );\r
+\r
+ } // fi\r
+\r
+ } // fi\r
+\r
+ } // fi\r
+ delete this->m_Conn;\r
+ this->m_Conn = NULL;\r
+ return( true );\r
+ }\r
+ else if( this->m_Conn != NULL && evt->button( ) == Qt::RightButton )\r
+ {\r
+ QNEOutputPort* port1 = this->m_Conn->port1( );\r
+ QNEInputPort* port2 = this->m_Conn->port2( );\r
+\r
+ if( port1 != NULL && port2 == NULL )\r
+ {\r
+ if(\r
+ dynamic_cast< QNEInputPort* >(\r
+ this->itemAt( evt->scenePos( ) )\r
+ ) == NULL\r
+ )\r
+ {\r
+ port2 = new QNEInputPort( NULL, this->m_Scene );\r
+ port2->setName( port1->name( ) );\r
+ port2->setPos( evt->scenePos( ) );\r
+ this->m_Conn->setPos2( evt->scenePos( ) );\r
+ this->m_Conn->setPort2( port2 );\r
+ this->m_Conn->updatePath( );\r
+ }\r
+ else\r
+ delete this->m_Conn;\r
+ this->m_Conn = NULL;\r
+ return( true );\r
+ }\r
+ else if( port1 == NULL && port2 != NULL )\r
+ {\r
+ if(\r
+ dynamic_cast< QNEOutputPort* >(\r
+ this->itemAt( evt->scenePos( ) )\r
+ ) == NULL\r
+ )\r
+ {\r
+ port1 = new QNEOutputPort( NULL, this->m_Scene );\r
+ port1->setName( port2->name( ) );\r
+ port1->setPos( evt->scenePos( ) );\r
+ this->m_Conn->setPos1( evt->scenePos( ) );\r
+ this->m_Conn->setPort1( port1 );\r
+ this->m_Conn->updatePath( );\r
+ }\r
+ else\r
+ delete this->m_Conn;\r
+ this->m_Conn = NULL;\r
+ return( true );\r
+\r
+ } // fi\r
\r
- QMap<quint64, QNEPort*> portMap;\r
+ } // fi\r
\r
- while ( !ds.atEnd( ) )\r
+ } // fi\r
+ }\r
+ break;\r
+ case QEvent::GraphicsSceneMove:\r
{\r
- int type;\r
- ds >> type;\r
- if( type == QNEBlock::Type )\r
+ QGraphicsSceneMoveEvent* evt =\r
+ dynamic_cast< QGraphicsSceneMoveEvent* >( e );\r
+ if( evt != NULL )\r
{\r
- QNEBlock* block = new QNEBlock( 0, this->m_Scene );\r
- block->load( ds, portMap );\r
- }\r
- else if( type == QNEConnection::Type )\r
+ } // fi\r
+ }\r
+ break;\r
+ case QEvent::GraphicsSceneResize:\r
+ {\r
+ QGraphicsSceneResizeEvent* evt =\r
+ dynamic_cast< QGraphicsSceneResizeEvent* >( e );\r
+ if( evt != NULL )\r
{\r
- this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
- this->m_Conn->load( ds, portMap );\r
- }\r
+ } // fi\r
}\r
+ break;\r
+ case QEvent::GraphicsSceneWheel:\r
+ {\r
+ QGraphicsSceneWheelEvent* evt =\r
+ dynamic_cast< QGraphicsSceneWheelEvent* >( e );\r
+ if( evt != NULL )\r
+ {\r
+ } // fi\r
+ }\r
+ break;\r
+ default:\r
+ break;\r
+ } // hctiws\r
+\r
+ // Mouse event\r
+ /*\r
+ QGraphicsSceneMouseEvent* me =\r
+ dynamic_cast< QGraphicsSceneMouseEvent* >( e );\r
+ if( me != NULL )\r
+ {\r
+ } // fi\r
+ */\r
+\r
+ /* TODO\r
+ switch( ( int ) e->type( ) )\r
+ {\r
+ case QEvent::GraphicsSceneMouseMove:\r
+ {\r
+ if( this->m_Conn )\r
+ {\r
+ this->m_Conn->setPos2( me->scenePos( ) );\r
+ this->m_Conn->updatePath( );\r
+ return( true );\r
+ }\r
+ break;\r
+ }\r
+ case QEvent::GraphicsSceneMouseRelease:\r
+ {\r
+ if( this->m_Conn && me->button( ) == Qt::LeftButton )\r
+ {\r
+ QGraphicsItem* item = itemAt( me->scenePos( ) );\r
+ if( item && item->type( ) == QNEPort::Type )\r
+ {\r
+ QNEPort* port1 = this->m_Conn->port1( );\r
+ QNEPort* port2 = ( QNEPort* ) item;\r
+ if( port1->block( ) != port2->block( ) && port1->isOutput( ) != port2->isOutput( ) && !port1->isConnected( port2 ) )\r
+ {\r
+ this->m_Conn->setPos2( port2->scenePos( ) );\r
+ this->m_Conn->setPort2( port2 );\r
+ this->m_Conn->updatePath( );\r
+ this->m_Conn = NULL;\r
+ return( true );\r
+ }\r
+ }\r
+\r
+ delete this->m_Conn;\r
+ this->m_Conn = NULL;\r
+ return( true );\r
+ }\r
+ break;\r
+ }\r
+ } // hctiws\r
+ */\r
+\r
+ return( this->Superclass::eventFilter( o, e ) );\r
}\r
\r
// eof - $RCSfile$\r