We can select multiple items

This commit is contained in:
dfighter1985 2014-09-12 19:47:28 +02:00
parent b300bb1ee7
commit 8f72f2d12f
2 changed files with 10 additions and 11 deletions

View file

@ -28,7 +28,7 @@ QWidget( parent )
{
m_ui.setupUi( this );
m_selection = NULL;
m_hasSelection = false;
m_scene = new QGraphicsScene( this );
m_ui.view->setScene( m_scene );
@ -51,7 +51,7 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
a = menu.addAction( "Add rect" );
connect( a, SIGNAL( triggered() ), this, SLOT( onAddRect() ) );
if( m_selection != NULL )
if( m_hasSelection )
{
a = menu.addAction( "Remove" );
connect( a, SIGNAL( triggered() ), this, SLOT( onDeleteSelection() ) );
@ -69,19 +69,19 @@ void ExpressionEditor::onAddRect()
void ExpressionEditor::onDeleteSelection()
{
m_scene->removeItem( m_selection );
QList< QGraphicsItem* > l = m_scene->selectedItems();
QListIterator< QGraphicsItem* > itr( l );
while( itr.hasNext() )
m_scene->removeItem( itr.next() );
}
void ExpressionEditor::onSelectionChanged()
{
QList< QGraphicsItem* > l = m_scene->selectedItems();
if( l.isEmpty() )
{
m_selection = NULL;
return;
}
m_selection = l[ 0 ];
m_hasSelection = false;
else
m_hasSelection = true;
}

View file

@ -23,7 +23,6 @@
#include "ui_expression_editor.h"
class QGraphicsScene;
class QGraphicsItem;
class ExpressionEditor : public QWidget
{
@ -44,7 +43,7 @@ private:
Ui::ExpressionEditor m_ui;
QGraphicsScene *m_scene;
QGraphicsItem *m_selection;
bool m_hasSelection;
};
#endif