Expression Editor is now a QMainWindow subclass. Also added an expression tree, with some sample nodes.

This commit is contained in:
dfighter1985 2014-09-14 21:00:40 +02:00
parent 4f79371896
commit 29176b7bc6
3 changed files with 110 additions and 30 deletions

View file

@ -30,7 +30,7 @@
#include <QMessageBox>
ExpressionEditor::ExpressionEditor( QWidget *parent ) :
QWidget( parent )
QMainWindow( parent )
{
m_ui.setupUi( this );
@ -40,6 +40,7 @@ QWidget( parent )
m_ui.view->setScene( m_scene );
connect( m_scene, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
connect( m_ui.tree, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( onItemDblClicked( QTreeWidgetItem* ) ) );
m_nodeCount = 0;
}
@ -169,30 +170,37 @@ void ExpressionEditor::onUnLinkItems()
}
}
void ExpressionEditor::addNode( int slotCount )
void ExpressionEditor::addNode( const QString &name, int slotCount )
{
QString name;
name = "node #";
name += QString::number( m_nodeCount );
QString n = name;
n += " #";
n += QString::number( m_nodeCount );
m_nodeCount++;
QGraphicsItem *item = new ExpressionNode( name, slotCount );
QGraphicsItem *item = new ExpressionNode( n, slotCount );
item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable );
m_scene->addItem( item );
}
void ExpressionEditor::onAddNode1()
{
addNode( 1 );
addNode( "node", 1 );
}
void ExpressionEditor::onAddNode2()
{
addNode( 2 );
addNode( "node", 2 );
}
void ExpressionEditor::onAddNode3()
{
addNode( 3 );
addNode( "node", 3 );
}
void ExpressionEditor::onItemDblClicked( QTreeWidgetItem *item )
{
QString name = item->text( 0 );
addNode( name, 3 );
}

View file

@ -24,7 +24,7 @@
class QGraphicsScene;
class ExpressionEditor : public QWidget
class ExpressionEditor : public QMainWindow
{
Q_OBJECT
public:
@ -39,10 +39,11 @@ private Q_SLOTS:
void onSelectionChanged();
void onLinkItems();
void onUnLinkItems();
void addNode( int slotCount );
void addNode( const QString &name, int slotCount );
void onAddNode1();
void onAddNode2();
void onAddNode3();
void onItemDblClicked( QTreeWidgetItem *item );
private:

View file

@ -1,34 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExpressionEditor</class>
<widget class="QWidget" name="ExpressionEditor">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<widget class="QMainWindow" name="ExpressionEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>724</width>
<height>522</height>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Expression Editor</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGraphicsView" name="view"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QDockWidget" name="dockWidget">
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGraphicsView" name="view">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
<widget class="QTreeWidget" name="tree">
<column>
<property name="text">
<string>Expressions</string>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</column>
<item>
<property name="text">
<string>Logical</string>
</property>
<item>
<property name="text">
<string>and</string>
</property>
</item>
<item>
<property name="text">
<string>or</string>
</property>
</item>
</item>
<item>
<property name="text">
<string>Mathematical</string>
</property>
<item>
<property name="text">
<string>add</string>
</property>
</item>
<item>
<property name="text">
<string>sub</string>
</property>
</item>
</item>
<item>
<property name="text">
<string>Value</string>
</property>
<item>
<property name="text">
<string>integer</string>
</property>
</item>
<item>
<property name="text">
<string>string</string>
</property>
</item>
<item>
<property name="text">
<string>boolean</string>
</property>
</item>
</item>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>