We can select multiple items

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

View file

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

View file

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