Allow to set and change values of value nodes.
--HG-- branch : dfighter-tools
This commit is contained in:
parent
142d82d788
commit
f0e78b5fbb
6 changed files with 82 additions and 0 deletions
|
@ -101,6 +101,12 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
|
|||
a = menu.addAction( "Change slot count" );
|
||||
connect( a, SIGNAL( triggered() ), this, SLOT( onChangeSlotCount() ) );
|
||||
}
|
||||
|
||||
if( node->isValue() )
|
||||
{
|
||||
a = menu.addAction( "Change value" );
|
||||
connect( a, SIGNAL( triggered() ), this, SLOT( onChangeValue() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -219,6 +225,11 @@ void ExpressionEditor::onItemDblClicked( QTreeWidgetItem *item )
|
|||
node->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable );
|
||||
node->setSlotNames( info->slotNames );
|
||||
node->setVariable( info->variable );
|
||||
node->setIsValue( info->value );
|
||||
if( node->isValue() )
|
||||
{
|
||||
node->setValue( "Value" );
|
||||
}
|
||||
m_scene->addItem( node );
|
||||
}
|
||||
|
||||
|
@ -241,6 +252,28 @@ void ExpressionEditor::onChangeSlotCount()
|
|||
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 )
|
||||
{
|
||||
QTreeWidgetItem *item = findTopLevelItem( info->category );
|
||||
|
|
|
@ -46,6 +46,7 @@ private Q_SLOTS:
|
|||
void onUnLinkItems();
|
||||
void onItemDblClicked( QTreeWidgetItem *item );
|
||||
void onChangeSlotCount();
|
||||
void onChangeValue();
|
||||
|
||||
private:
|
||||
void addExpression( const ExpressionInfo *info );
|
||||
|
|
|
@ -25,9 +25,16 @@
|
|||
struct ExpressionInfo
|
||||
{
|
||||
QString name;
|
||||
bool value;
|
||||
QString category;
|
||||
bool variable;
|
||||
QStringList slotNames;
|
||||
|
||||
ExpressionInfo()
|
||||
{
|
||||
value = false;
|
||||
variable = false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -37,6 +37,20 @@ public:
|
|||
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()
|
||||
{
|
||||
QString text = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||
|
@ -136,6 +150,9 @@ public:
|
|||
if( name == "name" )
|
||||
error = !parseName();
|
||||
else
|
||||
if( name == "value" )
|
||||
error = !parseValue();
|
||||
else
|
||||
if( name == "category" )
|
||||
error = !parseCategory();
|
||||
else
|
||||
|
|
|
@ -106,6 +106,7 @@ QGraphicsItem( parent )
|
|||
m_hh = 20.0;
|
||||
|
||||
m_variable = false;
|
||||
m_isValue = false;
|
||||
|
||||
m_name = name;
|
||||
|
||||
|
@ -152,6 +153,20 @@ void ExpressionNode::paint( QPainter *painter, const QStyleOptionGraphicsItem *o
|
|||
painter->setPen( p );
|
||||
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 )
|
||||
{
|
||||
p.setStyle( Qt::DotLine );
|
||||
|
|
|
@ -58,6 +58,12 @@ public:
|
|||
void setVariable( bool b ){ m_variable = b; }
|
||||
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:
|
||||
void mouseMoveEvent( QGraphicsSceneMouseEvent *e );
|
||||
|
||||
|
@ -75,6 +81,9 @@ private:
|
|||
QString m_name;
|
||||
|
||||
bool m_variable;
|
||||
|
||||
QString m_value;
|
||||
bool m_isValue;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue