mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-14 03:09:08 +00:00
Allow to set and change values of value nodes.
This commit is contained in:
parent
754393064d
commit
83b6e2a18b
6 changed files with 82 additions and 0 deletions
|
@ -101,6 +101,12 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
|
||||||
a = menu.addAction( "Change slot count" );
|
a = menu.addAction( "Change slot count" );
|
||||||
connect( a, SIGNAL( triggered() ), this, SLOT( onChangeSlotCount() ) );
|
connect( a, SIGNAL( triggered() ), this, SLOT( onChangeSlotCount() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( node->isValue() )
|
||||||
|
{
|
||||||
|
a = menu.addAction( "Change value" );
|
||||||
|
connect( a, SIGNAL( triggered() ), this, SLOT( onChangeValue() ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -219,6 +225,11 @@ void ExpressionEditor::onItemDblClicked( QTreeWidgetItem *item )
|
||||||
node->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable );
|
node->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable );
|
||||||
node->setSlotNames( info->slotNames );
|
node->setSlotNames( info->slotNames );
|
||||||
node->setVariable( info->variable );
|
node->setVariable( info->variable );
|
||||||
|
node->setIsValue( info->value );
|
||||||
|
if( node->isValue() )
|
||||||
|
{
|
||||||
|
node->setValue( "Value" );
|
||||||
|
}
|
||||||
m_scene->addItem( node );
|
m_scene->addItem( node );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,6 +252,28 @@ void ExpressionEditor::onChangeSlotCount()
|
||||||
node->changeSlotCount( c );
|
node->changeSlotCount( c );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExpressionEditor::onChangeValue()
|
||||||
|
{
|
||||||
|
QList< QGraphicsItem* > l = m_scene->selectedItems();
|
||||||
|
ExpressionNode *node = static_cast< ExpressionNode* >( l[ 0 ] );
|
||||||
|
|
||||||
|
QString oldValue = node->getValue();
|
||||||
|
|
||||||
|
QString newValue = QInputDialog::getText( this,
|
||||||
|
tr( "Change value" ),
|
||||||
|
tr( "Enter new value" ),
|
||||||
|
QLineEdit::Normal,
|
||||||
|
oldValue );
|
||||||
|
|
||||||
|
if( newValue.isEmpty() )
|
||||||
|
return;
|
||||||
|
if( newValue == oldValue )
|
||||||
|
return;
|
||||||
|
|
||||||
|
node->setValue( newValue );
|
||||||
|
node->update();
|
||||||
|
}
|
||||||
|
|
||||||
void ExpressionEditor::addExpression( const ExpressionInfo *info )
|
void ExpressionEditor::addExpression( const ExpressionInfo *info )
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *item = findTopLevelItem( info->category );
|
QTreeWidgetItem *item = findTopLevelItem( info->category );
|
||||||
|
|
|
@ -46,6 +46,7 @@ private Q_SLOTS:
|
||||||
void onUnLinkItems();
|
void onUnLinkItems();
|
||||||
void onItemDblClicked( QTreeWidgetItem *item );
|
void onItemDblClicked( QTreeWidgetItem *item );
|
||||||
void onChangeSlotCount();
|
void onChangeSlotCount();
|
||||||
|
void onChangeValue();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addExpression( const ExpressionInfo *info );
|
void addExpression( const ExpressionInfo *info );
|
||||||
|
|
|
@ -25,9 +25,16 @@
|
||||||
struct ExpressionInfo
|
struct ExpressionInfo
|
||||||
{
|
{
|
||||||
QString name;
|
QString name;
|
||||||
|
bool value;
|
||||||
QString category;
|
QString category;
|
||||||
bool variable;
|
bool variable;
|
||||||
QStringList slotNames;
|
QStringList slotNames;
|
||||||
|
|
||||||
|
ExpressionInfo()
|
||||||
|
{
|
||||||
|
value = false;
|
||||||
|
variable = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,6 +37,20 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool parseValue()
|
||||||
|
{
|
||||||
|
QString text = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||||
|
if( reader.hasError() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( text.toLower() == "true" )
|
||||||
|
m_info->value = true;
|
||||||
|
else
|
||||||
|
m_info->value = false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool parseCategory()
|
bool parseCategory()
|
||||||
{
|
{
|
||||||
QString text = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
QString text = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||||
|
@ -136,6 +150,9 @@ public:
|
||||||
if( name == "name" )
|
if( name == "name" )
|
||||||
error = !parseName();
|
error = !parseName();
|
||||||
else
|
else
|
||||||
|
if( name == "value" )
|
||||||
|
error = !parseValue();
|
||||||
|
else
|
||||||
if( name == "category" )
|
if( name == "category" )
|
||||||
error = !parseCategory();
|
error = !parseCategory();
|
||||||
else
|
else
|
||||||
|
|
|
@ -106,6 +106,7 @@ QGraphicsItem( parent )
|
||||||
m_hh = 20.0;
|
m_hh = 20.0;
|
||||||
|
|
||||||
m_variable = false;
|
m_variable = false;
|
||||||
|
m_isValue = false;
|
||||||
|
|
||||||
m_name = name;
|
m_name = name;
|
||||||
|
|
||||||
|
@ -152,6 +153,20 @@ void ExpressionNode::paint( QPainter *painter, const QStyleOptionGraphicsItem *o
|
||||||
painter->setPen( p );
|
painter->setPen( p );
|
||||||
painter->drawText( header, Qt::AlignCenter, m_name );
|
painter->drawText( header, Qt::AlignCenter, m_name );
|
||||||
|
|
||||||
|
// Draw value if applicable
|
||||||
|
if( m_isValue )
|
||||||
|
{
|
||||||
|
QRectF vbox;
|
||||||
|
vbox.setTopLeft( QPoint( 0.0, 20.0 ) );
|
||||||
|
vbox.setWidth( header.width() );
|
||||||
|
vbox.setHeight( header.height() );
|
||||||
|
QPen vpen;
|
||||||
|
vpen.setColor( Qt::red );
|
||||||
|
painter->setPen( vpen );
|
||||||
|
painter->drawText( vbox, Qt::AlignCenter, m_value );
|
||||||
|
painter->setPen( p );
|
||||||
|
}
|
||||||
|
|
||||||
if( option->state & QStyle::State_Selected )
|
if( option->state & QStyle::State_Selected )
|
||||||
{
|
{
|
||||||
p.setStyle( Qt::DotLine );
|
p.setStyle( Qt::DotLine );
|
||||||
|
|
|
@ -58,6 +58,12 @@ public:
|
||||||
void setVariable( bool b ){ m_variable = b; }
|
void setVariable( bool b ){ m_variable = b; }
|
||||||
bool variable() const{ return m_variable; }
|
bool variable() const{ return m_variable; }
|
||||||
|
|
||||||
|
void setValue( const QString &value ){ m_value = value; }
|
||||||
|
QString getValue() const{ return m_value; }
|
||||||
|
|
||||||
|
bool isValue() const{ return m_isValue; }
|
||||||
|
void setIsValue( bool b ){ m_isValue = b; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent( QGraphicsSceneMouseEvent *e );
|
void mouseMoveEvent( QGraphicsSceneMouseEvent *e );
|
||||||
|
|
||||||
|
@ -75,6 +81,9 @@ private:
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
|
||||||
bool m_variable;
|
bool m_variable;
|
||||||
|
|
||||||
|
QString m_value;
|
||||||
|
bool m_isValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue