@ -1064,106 +1064,72 @@ UBItem* UBGraphicsScene::deepCopy() const
return sceneDeepCopy ( ) ;
return sceneDeepCopy ( ) ;
}
}
void UBGraphicsScene : : clearItemsAndAnnotations ( )
void UBGraphicsScene : : clearContent ( clearCase pCase )
{
{
deselectAllItems ( ) ;
QSet < QGraphicsItem * > emptyList ;
QSet < QGraphicsItem * > removedItems ;
QList < QGraphicsItem * > sceneItems = items ( ) ;
foreach ( QGraphicsItem * item , sceneItems )
{
if ( ! mTools . contains ( item ) & & ! isBackgroundObject ( item ) )
{
removeItem ( item ) ;
removedItems < < item ;
}
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
update ( sceneRect ( ) ) ;
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , removedItems , emptyList ) ;
UBApplication : : undoStack - > push ( uc ) ;
}
setDocumentUpdated ( ) ;
}
void UBGraphicsScene : : clearItems ( )
{
deselectAllItems ( ) ;
QSet < QGraphicsItem * > emptyList ;
QSet < QGraphicsItem * > removedItems ;
QSet < QGraphicsItem * > removedItems ;
QList < QGraphicsItem * > sceneItems = items ( ) ;
switch ( pCase ) {
foreach ( QGraphicsItem * item , sceneItems )
case clearBackground :
{
removeItem ( mBackgroundObject ) ;
bool isGroup = qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item ) ! = NULL ;
removedItems < < mBackgroundObject ;
bool isPolygon = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ! = NULL ;
break ;
bool isStrokesGroup = qgraphicsitem_cast < UBGraphicsStrokesGroup * > ( item ) ! = NULL ;
case clearItemsAndAnnotations :
if ( ! isGroup & & ! isPolygon & & ! isStrokesGroup & & ! mTools . contains ( item ) & & ! isBackgroundObject ( item ) )
case clearItems :
{
case clearAnnotations :
removeItem ( item ) ;
foreach ( QGraphicsItem * item , items ( ) ) {
removedItems < < item ;
}
bool isGroup = item - > type ( ) = = UBGraphicsGroupContainerItem : : Type ;
}
bool isStrokesGroup = item - > type ( ) = = UBGraphicsStrokesGroup : : Type ;
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
UBGraphicsGroupContainerItem * itemGroup = item - > parentItem ( )
update ( sceneRect ( ) ) ;
? qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item - > parentItem ( ) )
: 0 ;
UBGraphicsItemDelegate * curDelegate = UBGraphicsItem : : Delegate ( item ) ;
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
if ( ! curDelegate ) {
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , removedItems , emptyList ) ;
continue ;
UBApplication : : undoStack - > push ( uc ) ;
}
}
setDocumentUpdated ( ) ;
bool shouldDelete = false ;
}
switch ( static_cast < int > ( pCase ) ) {
case clearAnnotations :
shouldDelete = isStrokesGroup ;
break ;
case clearItems :
shouldDelete = ! isGroup & & ! isBackgroundObject ( item ) & & ! isStrokesGroup ;
break ;
case clearItemsAndAnnotations :
shouldDelete = ! isGroup & & ! isBackgroundObject ( item ) ;
break ;
}
void UBGraphicsScene : : clearAnnotations ( )
if ( shouldDelete ) {
{
if ( itemGroup ) {
QSet < QGraphicsItem * > emptyList ;
itemGroup - > removeFromGroup ( item ) ;
QSet < QGraphicsItem * > removedItems ;
if ( itemGroup - > childItems ( ) . count ( ) = = 1 ) {
itemGroup - > destroy ( ) ;
}
itemGroup - > Delegate ( ) - > update ( ) ;
}
QList < QGraphicsItem * > sceneItems = items ( ) ;
curDelegate - > remove ( false ) ;
foreach ( QGraphicsItem * item , sceneItems )
removedItems < < item ;
{
}
UBGraphicsStrokesGroup * pi = qgraphicsitem_cast < UBGraphicsStrokesGroup * > ( item ) ;
if ( pi )
{
removeItem ( item ) ;
removedItems < < item ;
}
}
break ;
}
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
update ( sceneRect ( ) ) ;
update ( sceneRect ( ) ) ;
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , removedItems , emptyList ) ;
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , removedItems , QSet < QGraphicsItem * > ( ) ) ;
UBApplication : : undoStack - > push ( uc ) ;
UBApplication : : undoStack - > push ( uc ) ;
}
}
setDocumentUpdated ( ) ;
if ( pCase = = clearBackground ) {
}
void UBGraphicsScene : : clearBackground ( )
{
if ( mBackgroundObject ) {
removeItem ( mBackgroundObject ) ;
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , mBackgroundObject , NULL ) ;
UBApplication : : undoStack - > push ( uc ) ;
}
mBackgroundObject = 0 ;
mBackgroundObject = 0 ;
}
}
update ( sceneRect ( ) ) ;
setDocumentUpdated ( ) ;
setDocumentUpdated ( ) ;
}
}
@ -1357,8 +1323,8 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, con
UBGraphicsGroupContainerItem * UBGraphicsScene : : createGroup ( QList < QGraphicsItem * > items )
UBGraphicsGroupContainerItem * UBGraphicsScene : : createGroup ( QList < QGraphicsItem * > items )
{
{
UBGraphicsGroupContainerItem * groupItem = new UBGraphicsGroupContainerItem ( ) ;
UBGraphicsGroupContainerItem * groupItem = new UBGraphicsGroupContainerItem ( ) ;
addItem ( groupItem ) ;
addItem ( groupItem ) ;
foreach ( QGraphicsItem * item , items ) {
foreach ( QGraphicsItem * item , items ) {
if ( item - > type ( ) = = UBGraphicsGroupContainerItem : : Type ) {
if ( item - > type ( ) = = UBGraphicsGroupContainerItem : : Type ) {
QList < QGraphicsItem * > childItems = item - > childItems ( ) ;
QList < QGraphicsItem * > childItems = item - > childItems ( ) ;