Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
f6693f4e
Commit
f6693f4e
authored
Sep 07, 2012
by
Ilia Ryabokon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Undo-redo stack for eraising operations and Sankore 834
parent
8b0e41ea
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
93 additions
and
15 deletions
+93
-15
UBSvgSubsetAdaptor.cpp
src/adaptors/UBSvgSubsetAdaptor.cpp
+1
-1
UBGraphicsGroupContainerItem.cpp
src/domain/UBGraphicsGroupContainerItem.cpp
+4
-2
UBGraphicsGroupContainerItem.h
src/domain/UBGraphicsGroupContainerItem.h
+1
-1
UBGraphicsItemGroupUndoCommand.cpp
src/domain/UBGraphicsItemGroupUndoCommand.cpp
+2
-2
UBGraphicsItemUndoCommand.cpp
src/domain/UBGraphicsItemUndoCommand.cpp
+63
-3
UBGraphicsItemUndoCommand.h
src/domain/UBGraphicsItemUndoCommand.h
+3
-1
UBGraphicsScene.cpp
src/domain/UBGraphicsScene.cpp
+11
-4
UBGraphicsScene.h
src/domain/UBGraphicsScene.h
+1
-1
UBItem.cpp
src/domain/UBItem.cpp
+6
-0
UBItem.h
src/domain/UBItem.h
+1
-0
No files found.
src/adaptors/UBSvgSubsetAdaptor.cpp
View file @
f6693f4e
...
...
@@ -1084,7 +1084,7 @@ QGraphicsItem *UBSvgSubsetAdaptor::UBSvgSubsetReader::readElementFromGroup()
{
QGraphicsItem
*
result
=
0
;
result
=
mScene
->
item
By
Uuid
(
QUuid
(
mXmlReader
.
attributes
().
value
(
aId
).
toString
()));
result
=
mScene
->
item
For
Uuid
(
QUuid
(
mXmlReader
.
attributes
().
value
(
aId
).
toString
()));
mXmlReader
.
skipCurrentElement
();
mXmlReader
.
readNext
();
...
...
src/domain/UBGraphicsGroupContainerItem.cpp
View file @
f6693f4e
...
...
@@ -125,6 +125,8 @@ void UBGraphicsGroupContainerItem::removeFromGroup(QGraphicsItem *item)
pRemoveFromGroup
(
item
);
item
->
setFlags
(
ItemIsSelectable
|
ItemIsFocusable
);
}
void
UBGraphicsGroupContainerItem
::
deselectCurrentItem
()
...
...
@@ -219,7 +221,7 @@ void UBGraphicsGroupContainerItem::setUuid(const QUuid &pUuid)
setData
(
UBGraphicsItemData
::
ItemUuid
,
QVariant
(
pUuid
));
//store item uuid inside the QGraphicsItem to fast operations with Items on the scene
}
void
UBGraphicsGroupContainerItem
::
destroy
()
{
void
UBGraphicsGroupContainerItem
::
destroy
(
bool
canUndo
)
{
foreach
(
QGraphicsItem
*
item
,
childItems
())
{
pRemoveFromGroup
(
item
);
...
...
@@ -227,7 +229,7 @@ void UBGraphicsGroupContainerItem::destroy() {
item
->
setFlag
(
QGraphicsItem
::
ItemIsFocusable
,
true
);
}
remove
(
);
mDelegate
->
remove
(
canUndo
);
}
void
UBGraphicsGroupContainerItem
::
clearSource
()
...
...
src/domain/UBGraphicsGroupContainerItem.h
View file @
f6693f4e
...
...
@@ -37,7 +37,7 @@ public:
}
virtual
void
setUuid
(
const
QUuid
&
pUuid
);
void
destroy
();
void
destroy
(
bool
canUndo
=
true
);
virtual
void
clearSource
();
...
...
src/domain/UBGraphicsItemGroupUndoCommand.cpp
View file @
f6693f4e
...
...
@@ -22,7 +22,7 @@ UBGraphicsItemGroupUndoCommand::~UBGraphicsItemGroupUndoCommand()
void
UBGraphicsItemGroupUndoCommand
::
undo
()
{
mGroup
->
destroy
();
mGroup
->
destroy
(
false
);
foreach
(
QGraphicsItem
*
item
,
mItems
)
{
item
->
setSelected
(
true
);
}
...
...
@@ -41,7 +41,7 @@ void UBGraphicsItemGroupUndoCommand::redo()
QList
<
QGraphicsItem
*>
childItems
=
item
->
childItems
();
UBGraphicsGroupContainerItem
*
currentGroup
=
dynamic_cast
<
UBGraphicsGroupContainerItem
*>
(
item
);
if
(
currentGroup
)
{
currentGroup
->
destroy
();
currentGroup
->
destroy
(
false
);
}
foreach
(
QGraphicsItem
*
chItem
,
childItems
)
{
mGroup
->
addToGroup
(
chItem
);
...
...
src/domain/UBGraphicsItemUndoCommand.cpp
View file @
f6693f4e
...
...
@@ -27,10 +27,11 @@
#include "domain/UBGraphicsGroupContainerItem.h"
UBGraphicsItemUndoCommand
::
UBGraphicsItemUndoCommand
(
UBGraphicsScene
*
pScene
,
const
QSet
<
QGraphicsItem
*>&
pRemovedItems
,
const
QSet
<
QGraphicsItem
*>&
pAddedItems
)
const
QSet
<
QGraphicsItem
*>&
pAddedItems
,
const
QMultiMap
<
UBGraphicsGroupContainerItem
*
,
QUuid
>
&
groupsMap
)
:
mScene
(
pScene
)
,
mRemovedItems
(
pRemovedItems
-
pAddedItems
)
,
mAddedItems
(
pAddedItems
-
pRemovedItems
)
,
mRemovedItems
(
pRemovedItems
-
pAddedItems
)
,
mAddedItems
(
pAddedItems
-
pRemovedItems
)
,
mExcludedFromGroup
(
groupsMap
)
{
mFirstRedo
=
true
;
...
...
@@ -110,6 +111,36 @@ void UBGraphicsItemUndoCommand::undo()
}
}
QMapIterator
<
UBGraphicsGroupContainerItem
*
,
QUuid
>
curMapElement
(
mExcludedFromGroup
);
UBGraphicsGroupContainerItem
*
nextGroup
=
0
;
UBGraphicsGroupContainerItem
*
previousGroupItem
;
bool
groupChanged
=
false
;
while
(
curMapElement
.
hasNext
())
{
curMapElement
.
next
();
groupChanged
=
previousGroupItem
!=
curMapElement
.
key
();
//trying to find the group on the scene;
if
(
!
nextGroup
||
groupChanged
)
{
UBGraphicsGroupContainerItem
*
groupCandidate
=
curMapElement
.
key
();
if
(
groupCandidate
)
{
nextGroup
=
groupCandidate
;
if
(
!
mScene
->
items
().
contains
(
nextGroup
))
{
mScene
->
addItem
(
nextGroup
);
}
nextGroup
->
setVisible
(
true
);
}
}
QGraphicsItem
*
groupedItem
=
mScene
->
itemForUuid
(
curMapElement
.
value
());
if
(
groupedItem
)
{
nextGroup
->
addToGroup
(
groupedItem
);
}
previousGroupItem
=
curMapElement
.
key
();
UBGraphicsItem
::
Delegate
(
nextGroup
)
->
update
();
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
mScene
->
update
(
mScene
->
sceneRect
());
...
...
@@ -125,6 +156,35 @@ void UBGraphicsItemUndoCommand::redo()
return
;
}
QMapIterator
<
UBGraphicsGroupContainerItem
*
,
QUuid
>
curMapElement
(
mExcludedFromGroup
);
UBGraphicsGroupContainerItem
*
nextGroup
=
0
;
UBGraphicsGroupContainerItem
*
previousGroupItem
;
bool
groupChanged
=
false
;
while
(
curMapElement
.
hasNext
())
{
curMapElement
.
next
();
groupChanged
=
previousGroupItem
!=
curMapElement
.
key
();
//trying to find the group on the scene;
if
(
!
nextGroup
||
groupChanged
)
{
UBGraphicsGroupContainerItem
*
groupCandidate
=
curMapElement
.
key
();
if
(
groupCandidate
)
{
nextGroup
=
groupCandidate
;
}
}
QGraphicsItem
*
groupedItem
=
mScene
->
itemForUuid
(
curMapElement
.
value
());
if
(
groupedItem
)
{
if
(
nextGroup
->
childItems
().
count
()
==
1
)
{
nextGroup
->
destroy
(
false
);
break
;
}
nextGroup
->
removeFromGroup
(
groupedItem
);
}
previousGroupItem
=
curMapElement
.
key
();
UBGraphicsItem
::
Delegate
(
nextGroup
)
->
update
();
}
QSetIterator
<
QGraphicsItem
*>
itRemoved
(
mRemovedItems
);
while
(
itRemoved
.
hasNext
())
{
...
...
src/domain/UBGraphicsItemUndoCommand.h
View file @
f6693f4e
...
...
@@ -18,6 +18,7 @@
#include <QtGui>
#include "UBAbstractUndoCommand.h"
#include "UBGraphicsGroupContainerItem.h"
class
UBGraphicsScene
;
...
...
@@ -27,7 +28,7 @@ class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand
{
public
:
UBGraphicsItemUndoCommand
(
UBGraphicsScene
*
pScene
,
const
QSet
<
QGraphicsItem
*>&
pRemovedItems
,
const
QSet
<
QGraphicsItem
*>&
pAddedItems
);
const
QSet
<
QGraphicsItem
*>&
pAddedItems
,
const
QMultiMap
<
UBGraphicsGroupContainerItem
*
,
QUuid
>
&
groupsMap
=
QMultiMap
<
UBGraphicsGroupContainerItem
*
,
QUuid
>
()
);
UBGraphicsItemUndoCommand
(
UBGraphicsScene
*
pScene
,
QGraphicsItem
*
pRemovedItem
,
QGraphicsItem
*
pAddedItem
);
...
...
@@ -47,6 +48,7 @@ class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand
UBGraphicsScene
*
mScene
;
QSet
<
QGraphicsItem
*>
mRemovedItems
;
QSet
<
QGraphicsItem
*>
mAddedItems
;
QMultiMap
<
UBGraphicsGroupContainerItem
*
,
QUuid
>
mExcludedFromGroup
;
bool
mFirstRedo
;
};
...
...
src/domain/UBGraphicsScene.cpp
View file @
f6693f4e
...
...
@@ -1067,6 +1067,7 @@ UBItem* UBGraphicsScene::deepCopy() const
void
UBGraphicsScene
::
clearContent
(
clearCase
pCase
)
{
QSet
<
QGraphicsItem
*>
removedItems
;
QMultiMap
<
UBGraphicsGroupContainerItem
*
,
QUuid
>
groupsMap
;
switch
(
pCase
)
{
case
clearBackground
:
...
...
@@ -1106,8 +1107,13 @@ void UBGraphicsScene::clearContent(clearCase pCase)
if
(
shouldDelete
)
{
if
(
itemGroup
)
{
itemGroup
->
removeFromGroup
(
item
);
groupsMap
.
insert
(
itemGroup
,
UBGraphicsItem
::
getOwnUuid
(
item
));
if
(
itemGroup
->
childItems
().
count
()
==
1
)
{
itemGroup
->
destroy
();
groupsMap
.
insert
(
itemGroup
,
UBGraphicsItem
::
getOwnUuid
(
itemGroup
->
childItems
().
first
()));
QGraphicsItem
*
lastItem
=
itemGroup
->
childItems
().
first
();
bool
isSelected
=
itemGroup
->
isSelected
();
itemGroup
->
destroy
(
false
);
lastItem
->
setSelected
(
isSelected
);
}
itemGroup
->
Delegate
()
->
update
();
}
...
...
@@ -1123,7 +1129,7 @@ void UBGraphicsScene::clearContent(clearCase pCase)
update
(
sceneRect
());
if
(
enableUndoRedoStack
)
{
//should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand
*
uc
=
new
UBGraphicsItemUndoCommand
(
this
,
removedItems
,
QSet
<
QGraphicsItem
*>
());
UBGraphicsItemUndoCommand
*
uc
=
new
UBGraphicsItemUndoCommand
(
this
,
removedItems
,
QSet
<
QGraphicsItem
*>
()
,
groupsMap
);
UBApplication
::
undoStack
->
push
(
uc
);
}
...
...
@@ -1571,8 +1577,9 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item)
void
UBGraphicsScene
::
removeItems
(
const
QSet
<
QGraphicsItem
*>&
items
)
{
foreach
(
QGraphicsItem
*
item
,
items
)
foreach
(
QGraphicsItem
*
item
,
items
)
{
UBCoreGraphicsScene
::
removeItem
(
item
);
}
mItemCount
-=
items
.
size
();
...
...
@@ -1665,7 +1672,7 @@ QRectF UBGraphicsScene::normalizedSceneRect(qreal ratio)
return
normalizedRect
;
}
QGraphicsItem
*
UBGraphicsScene
::
item
By
Uuid
(
QUuid
uuid
)
QGraphicsItem
*
UBGraphicsScene
::
item
For
Uuid
(
QUuid
uuid
)
{
QGraphicsItem
*
result
=
0
;
...
...
src/domain/UBGraphicsScene.h
View file @
f6693f4e
...
...
@@ -174,7 +174,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
QRectF
normalizedSceneRect
(
qreal
ratio
=
-
1
.
0
);
QGraphicsItem
*
item
By
Uuid
(
QUuid
uuid
);
QGraphicsItem
*
item
For
Uuid
(
QUuid
uuid
);
void
moveTo
(
const
QPointF
&
pPoint
);
void
drawLineTo
(
const
QPointF
&
pEndPoint
,
const
qreal
&
pWidth
,
bool
bLineStyle
);
...
...
src/domain/UBItem.cpp
View file @
f6693f4e
...
...
@@ -54,6 +54,12 @@ bool UBGraphicsItem::isRotatable(QGraphicsItem *item)
return
item
->
data
(
UBGraphicsItemData
::
ItemRotatable
).
toBool
();
}
QUuid
UBGraphicsItem
::
getOwnUuid
(
QGraphicsItem
*
item
)
{
QString
idCandidate
=
item
->
data
(
UBGraphicsItemData
::
ItemUuid
).
toString
();
return
idCandidate
==
QUuid
().
toString
()
?
QUuid
()
:
QUuid
(
idCandidate
);
}
UBGraphicsItemDelegate
*
UBGraphicsItem
::
Delegate
(
QGraphicsItem
*
pItem
)
{
UBGraphicsItemDelegate
*
result
=
0
;
...
...
src/domain/UBItem.h
View file @
f6693f4e
...
...
@@ -107,6 +107,7 @@ public:
static
void
assignZValue
(
QGraphicsItem
*
,
qreal
value
);
static
bool
isRotatable
(
QGraphicsItem
*
item
);
static
bool
isFlippable
(
QGraphicsItem
*
item
);
static
QUuid
getOwnUuid
(
QGraphicsItem
*
item
);
static
UBGraphicsItemDelegate
*
Delegate
(
QGraphicsItem
*
pItem
);
virtual
UBGraphicsItemDelegate
*
Delegate
()
const
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment