From 1e1a86a4c113a5b0303dcb8d55a5c348e115f4f8 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 17 Sep 2014 14:41:57 +0200 Subject: [PATCH] A root node can now be set. The root node is where the evaluation will start. --- .../plugins/gui_editor/expression_editor.cpp | 25 ++++++++++++++++++- .../plugins/gui_editor/expression_editor.h | 1 + .../plugins/gui_editor/expression_node.cpp | 22 +++++++++++++--- .../src/plugins/gui_editor/expression_node.h | 2 ++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/expression_editor.cpp b/code/studio/src/plugins/gui_editor/expression_editor.cpp index 1a16762e7..0967b33e1 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.cpp +++ b/code/studio/src/plugins/gui_editor/expression_editor.cpp @@ -35,7 +35,14 @@ class ExpressionEditorPvt { public: + + ExpressionEditorPvt() + { + m_root = NULL; + } + ExpressionStore store; + ExpressionNode *m_root; }; ExpressionEditor::ExpressionEditor( QWidget *parent ) : @@ -101,12 +108,15 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e ) a = menu.addAction( "Change slot count" ); connect( a, SIGNAL( triggered() ), this, SLOT( onChangeSlotCount() ) ); } - + else if( node->isValue() ) { a = menu.addAction( "Change value" ); connect( a, SIGNAL( triggered() ), this, SLOT( onChangeValue() ) ); } + + a = menu.addAction( "Set as root" ); + connect( a, SIGNAL( triggered() ), this, SLOT( onSetRoot() ) ); } } else @@ -273,6 +283,19 @@ void ExpressionEditor::onChangeValue() node->setValue( newValue ); } +void ExpressionEditor::onSetRoot() +{ + QList< QGraphicsItem* > l = m_scene->selectedItems(); + ExpressionNode *node = static_cast< ExpressionNode* >( l[ 0 ] ); + + if( m_pvt->m_root != NULL ) + m_pvt->m_root->setRoot( false ); + + m_pvt->m_root = node; + node->setRoot( true ); +} + + void ExpressionEditor::addExpression( const ExpressionInfo *info ) { QTreeWidgetItem *item = findTopLevelItem( info->category ); diff --git a/code/studio/src/plugins/gui_editor/expression_editor.h b/code/studio/src/plugins/gui_editor/expression_editor.h index 9380c6b29..448ac536c 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.h +++ b/code/studio/src/plugins/gui_editor/expression_editor.h @@ -47,6 +47,7 @@ private Q_SLOTS: void onItemDblClicked( QTreeWidgetItem *item ); void onChangeSlotCount(); void onChangeValue(); + void onSetRoot(); private: void addExpression( const ExpressionInfo *info ); diff --git a/code/studio/src/plugins/gui_editor/expression_node.cpp b/code/studio/src/plugins/gui_editor/expression_node.cpp index d7a548dc4..17343c11c 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.cpp +++ b/code/studio/src/plugins/gui_editor/expression_node.cpp @@ -107,6 +107,7 @@ QGraphicsItem( parent ) m_variable = false; m_isValue = false; + m_isRoot = false; m_name = name; @@ -139,9 +140,18 @@ void ExpressionNode::paint( QPainter *painter, const QStyleOptionGraphicsItem *o header.setHeight( m_hh ); // Draw filled rectangle, header - c.setRed( 44 ); - c.setGreen( 169 ); - c.setBlue( 232 ); + if( !m_isRoot ) + { + c.setRed( 44 ); + c.setGreen( 169 ); + c.setBlue( 232 ); + } + else + { + c.setRed( 255 ); + c.setGreen( 0 ); + c.setBlue( 0 ); + } br.setColor( c ); br.setStyle( Qt::SolidPattern ); p.setColor( c ); @@ -270,6 +280,12 @@ void ExpressionNode::setValue( const QString &value ) update(); } +void ExpressionNode::setRoot( bool b ) +{ + m_isRoot = b; + update(); +} + void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e ) { for( int i = 0; i < m_links.count(); i++ ) diff --git a/code/studio/src/plugins/gui_editor/expression_node.h b/code/studio/src/plugins/gui_editor/expression_node.h index f4b75ca1a..ec1fb9c67 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.h +++ b/code/studio/src/plugins/gui_editor/expression_node.h @@ -63,6 +63,7 @@ public: bool isValue() const{ return m_isValue; } void setIsValue( bool b ){ m_isValue = b; } + void setRoot( bool b ); protected: void mouseMoveEvent( QGraphicsSceneMouseEvent *e ); @@ -84,6 +85,7 @@ private: QString m_value; bool m_isValue; + bool m_isRoot; }; #endif