mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-25 02:10:53 +00:00
Expression can now be built.
This commit is contained in:
parent
aa1ac95aae
commit
f3fbfdcb83
5 changed files with 62 additions and 1 deletions
|
@ -89,7 +89,6 @@ void ExpressionEditor::load()
|
||||||
void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
|
void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
|
||||||
{
|
{
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
|
|
||||||
QAction *a = NULL;
|
QAction *a = NULL;
|
||||||
|
|
||||||
if( m_selectionCount > 0 )
|
if( m_selectionCount > 0 )
|
||||||
|
@ -129,6 +128,11 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
|
||||||
a = menu.addAction( "Unlink" );
|
a = menu.addAction( "Unlink" );
|
||||||
connect( a, SIGNAL( triggered() ), this, SLOT( onUnLinkItems() ) );
|
connect( a, SIGNAL( triggered() ), this, SLOT( onUnLinkItems() ) );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
a = menu.addAction( "Build expression" );
|
||||||
|
connect( a, SIGNAL( triggered() ), this, SLOT( onBuildExpression() ) );
|
||||||
|
}
|
||||||
|
|
||||||
menu.exec( e->globalPos() );
|
menu.exec( e->globalPos() );
|
||||||
}
|
}
|
||||||
|
@ -295,6 +299,22 @@ void ExpressionEditor::onSetRoot()
|
||||||
node->setRoot( true );
|
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 )
|
void ExpressionEditor::addExpression( const ExpressionInfo *info )
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,6 +48,7 @@ private Q_SLOTS:
|
||||||
void onChangeSlotCount();
|
void onChangeSlotCount();
|
||||||
void onChangeValue();
|
void onChangeValue();
|
||||||
void onSetRoot();
|
void onSetRoot();
|
||||||
|
void onBuildExpression();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addExpression( const ExpressionInfo *info );
|
void addExpression( const ExpressionInfo *info );
|
||||||
|
|
|
@ -36,6 +36,9 @@ public:
|
||||||
|
|
||||||
void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
|
void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
|
||||||
|
|
||||||
|
ExpressionNode* from() const{ return m_from; }
|
||||||
|
ExpressionNode* to() const{ return m_to; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ExpressionNode *m_from;
|
ExpressionNode *m_from;
|
||||||
ExpressionNode *m_to;
|
ExpressionNode *m_to;
|
||||||
|
|
|
@ -286,6 +286,41 @@ void ExpressionNode::setRoot( bool b )
|
||||||
update();
|
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 )
|
void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e )
|
||||||
{
|
{
|
||||||
for( int i = 0; i < m_links.count(); i++ )
|
for( int i = 0; i < m_links.count(); i++ )
|
||||||
|
|
|
@ -65,6 +65,8 @@ public:
|
||||||
void setIsValue( bool b ){ m_isValue = b; }
|
void setIsValue( bool b ){ m_isValue = b; }
|
||||||
void setRoot( bool b );
|
void setRoot( bool b );
|
||||||
|
|
||||||
|
QString build() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent( QGraphicsSceneMouseEvent *e );
|
void mouseMoveEvent( QGraphicsSceneMouseEvent *e );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue