@ -1071,115 +1071,72 @@ UBItem* UBGraphicsScene::deepCopy() const
return sceneDeepCopy ( ) ;
return sceneDeepCopy ( ) ;
}
}
void UBGraphicsScene : : clearItemsAndAnnotations ( )
void UBGraphicsScene : : clearContent ( clearCase pCase )
{
{
deselectAllItems ( ) ;
QSet < QGraphicsItem * > emptyList ;
QSet < QGraphicsItem * > removedItems ;
QSet < QGraphicsItem * > removedItems ;
QList < QGraphicsItem * > sceneItems = items ( ) ;
switch ( pCase ) {
foreach ( QGraphicsItem * item , sceneItems )
case clearBackground :
{
removeItem ( mBackgroundObject ) ;
if ( ! mTools . contains ( item ) & & ! isBackgroundObject ( item ) )
removedItems < < mBackgroundObject ;
{
break ;
removeItem ( item ) ;
removedItems < < item ;
}
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
case clearItemsAndAnnotations :
update ( sceneRect ( ) ) ;
case clearItems :
case clearAnnotations :
foreach ( QGraphicsItem * item , items ( ) ) {
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
bool isGroup = item - > type ( ) = = UBGraphicsGroupContainerItem : : Type ;
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , removedItems , emptyList ) ;
bool isStrokesGroup = item - > type ( ) = = UBGraphicsStrokesGroup : : Type ;
UBApplication : : undoStack - > push ( uc ) ;
}
setDocumentUpdated ( ) ;
UBGraphicsGroupContainerItem * itemGroup = item - > parentItem ( )
}
? qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item - > parentItem ( ) )
: 0 ;
bool isService ( QGraphicsItem * item ) {
UBGraphicsItemDelegate * curDelegate = UBGraphicsItem : : Delegate ( item ) ;
return ( item - > type ( ) = = UBGraphicsDelegateFrame : : Type )
if ( ! curDelegate ) {
| | ( item - > parentItem ( ) & & item - > parentItem ( ) - > Type = = UBGraphicsDelegateFrame : : Type ) ;
continue ;
}
}
void UBGraphicsScene : : clearItems ( )
bool shouldDelete = false ;
{
switch ( static_cast < int > ( pCase ) ) {
deselectAllItems ( ) ;
case clearAnnotations :
shouldDelete = isStrokesGroup ;
QSet < QGraphicsItem * > emptyList ;
break ;
QSet < QGraphicsItem * > removedItems ;
case clearItems :
shouldDelete = ! isGroup & & ! isBackgroundObject ( item ) & & ! isStrokesGroup ;
QList < QGraphicsItem * > sceneItems = items ( ) ;
break ;
foreach ( QGraphicsItem * item , sceneItems )
case clearItemsAndAnnotations :
{
shouldDelete = ! isGroup & & ! isBackgroundObject ( item ) ;
bool isGroup = qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item ) ! = NULL ;
break ;
bool isPolygon = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ! = NULL ;
bool isStrokesGroup = qgraphicsitem_cast < UBGraphicsStrokesGroup * > ( item ) ! = NULL ;
bool inGroup = ( item - > parentItem ( )
& & ( item - > parentItem ( ) - > type ( ) = = UBGraphicsGroupContainerItem : : Type ) ) ;
if ( ! isGroup & & ! isPolygon & & ! isStrokesGroup & & ! mTools . contains ( item ) & & ! isBackgroundObject ( item ) ) {
removeItem ( item ) ;
}
if ( ! inGroup | | ! isService ( item ) ) {
removedItems < < item ;
}
}
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
if ( shouldDelete ) {
update ( sceneRect ( ) ) ;
if ( itemGroup ) {
itemGroup - > removeFromGroup ( item ) ;
if ( itemGroup - > childItems ( ) . count ( ) = = 1 ) {
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
itemGroup - > destroy ( ) ;
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , removedItems , emptyList ) ;
UBApplication : : undoStack - > push ( uc ) ;
}
}
itemGroup - > Delegate ( ) - > update ( ) ;
setDocumentUpdated ( ) ;
}
}
void UBGraphicsScene : : clearAnnotations ( )
curDelegate - > remove ( false ) ;
{
QSet < QGraphicsItem * > emptyList ;
QSet < QGraphicsItem * > removedItems ;
QList < QGraphicsItem * > sceneItems = items ( ) ;
foreach ( QGraphicsItem * item , sceneItems )
{
UBGraphicsStrokesGroup * pi = qgraphicsitem_cast < UBGraphicsStrokesGroup * > ( item ) ;
if ( pi )
{
removeItem ( item ) ;
removedItems < < 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 ( ) ;
}
}
@ -1373,8 +1330,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 ( ) ;
@ -1609,8 +1566,6 @@ void UBGraphicsScene::addItems(const QSet<QGraphicsItem*>& items)
void UBGraphicsScene : : removeItem ( QGraphicsItem * item )
void UBGraphicsScene : : removeItem ( QGraphicsItem * item )
{
{
UBGraphicsGroupContainerItem * group = qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item - > parentItem ( ) ) ;
item - > setSelected ( false ) ;
item - > setSelected ( false ) ;
UBCoreGraphicsScene : : removeItem ( item ) ;
UBCoreGraphicsScene : : removeItem ( item ) ;
UBApplication : : boardController - > freezeW3CWidget ( item , true ) ;
UBApplication : : boardController - > freezeW3CWidget ( item , true ) ;
@ -1619,15 +1574,6 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item)
- - mItemCount ;
- - mItemCount ;
mFastAccessItems . removeAll ( item ) ;
mFastAccessItems . removeAll ( item ) ;
// if (group)
// {
// if (group->childItems().empty())
// {
// group->Delegate()->remove();
// UBCoreGraphicsScene::removeItemFromDeletion(group);
// }
// }
}
}
void UBGraphicsScene : : removeItems ( const QSet < QGraphicsItem * > & items )
void UBGraphicsScene : : removeItems ( const QSet < QGraphicsItem * > & items )