Expression can now be built.

--HG--
branch : dfighter-tools
hg/feature/qt5
dfighter1985 10 years ago
parent cbca49fcc0
commit 5f47f74431

@ -89,7 +89,6 @@ void ExpressionEditor::load()
void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
{
QMenu menu;
QAction *a = NULL;
if( m_selectionCount > 0 )
@ -129,6 +128,11 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
a = menu.addAction( "Unlink" );
connect( a, SIGNAL( triggered() ), this, SLOT( onUnLinkItems() ) );
}
else
{
a = menu.addAction( "Build expression" );
connect( a, SIGNAL( triggered() ), this, SLOT( onBuildExpression() ) );
}
menu.exec( e->globalPos() );
}
@ -295,6 +299,22 @@ void ExpressionEditor::onSetRoot()
node->setRoot( true );
}
void ExpressionEditor::onBuildExpression()
{
if( m_pvt->m_root == NULL )
{
QMessageBox::information( this,
tr( "Building expression" ),
tr( "Failed to build expression: You must set a root node." ) );
return;
}
QString result = m_pvt->m_root->build();
QMessageBox::information( this,
tr( "Building expression" ),
tr( "The result is\n" ) + result );
}
void ExpressionEditor::addExpression( const ExpressionInfo *info )
{

@ -48,6 +48,7 @@ private Q_SLOTS:
void onChangeSlotCount();
void onChangeValue();
void onSetRoot();
void onBuildExpression();
private:
void addExpression( const ExpressionInfo *info );

@ -36,6 +36,9 @@ public:
void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
ExpressionNode* from() const{ return m_from; }
ExpressionNode* to() const{ return m_to; }
private:
ExpressionNode *m_from;
ExpressionNode *m_to;

@ -286,6 +286,41 @@ void ExpressionNode::setRoot( bool b )
update();
}
QString ExpressionNode::build() const
{
QString result;
if( isValue() )
return m_value;
QStringList l = m_name.split( ' ' );
result = l[ 0 ];
result += "( ";
int c = m_links.count();
for( int i = 1; i < c; i++ )
{
ExpressionLink *link = m_links[ i ];
if( link == NULL )
continue;
ExpressionNode *node = NULL;
if( link->from() == this )
node = link->to();
else
node = link->from();
result += node->build();
if( i != ( c - 1 ) )
result += ", ";
}
result += " )";
return result;
}
void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e )
{
for( int i = 0; i < m_links.count(); i++ )

@ -65,6 +65,8 @@ public:
void setIsValue( bool b ){ m_isValue = b; }
void setRoot( bool b );
QString build() const;
protected:
void mouseMoveEvent( QGraphicsSceneMouseEvent *e );

Loading…
Cancel
Save