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
38032fb4
Commit
38032fb4
authored
Apr 01, 2019
by
Clément Fauconnier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed some issues where copying a page could result on images loss
parent
9c028255
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
7 deletions
+128
-7
UBPersistenceManager.cpp
src/core/UBPersistenceManager.cpp
+76
-0
UBDocumentController.cpp
src/document/UBDocumentController.cpp
+52
-7
No files found.
src/core/UBPersistenceManager.cpp
View file @
38032fb4
...
...
@@ -50,6 +50,11 @@
#include "adaptors/UBThumbnailAdaptor.h"
#include "adaptors/UBMetadataDcSubsetAdaptor.h"
#include "domain/UBGraphicsMediaItem.h"
#include "domain/UBGraphicsWidgetItem.h"
#include "domain/UBGraphicsPixmapItem.h"
#include "domain/UBGraphicsSvgItem.h"
#include "board/UBBoardController.h"
#include "board/UBBoardPaletteManager.h"
...
...
@@ -694,6 +699,77 @@ void UBPersistenceManager::duplicateDocumentScene(UBDocumentProxy* proxy, int in
copyPage
(
proxy
,
index
,
index
+
1
);
//TODO: write a proper way to handle object on disk
UBGraphicsScene
*
scene
=
loadDocumentScene
(
proxy
,
index
+
1
);
foreach
(
QGraphicsItem
*
item
,
scene
->
items
())
{
UBGraphicsMediaItem
*
mediaItem
=
qgraphicsitem_cast
<
UBGraphicsMediaItem
*>
(
item
);
if
(
mediaItem
){
QString
source
=
mediaItem
->
mediaFileUrl
().
toLocalFile
();
QString
destination
=
source
;
QUuid
newUuid
=
QUuid
::
createUuid
();
QString
fileName
=
QFileInfo
(
source
).
completeBaseName
();
destination
=
destination
.
replace
(
fileName
,
newUuid
.
toString
());
QFile
::
copy
(
source
,
destination
);
mediaItem
->
setMediaFileUrl
(
QUrl
::
fromLocalFile
(
destination
));
continue
;
}
UBGraphicsWidgetItem
*
widget
=
qgraphicsitem_cast
<
UBGraphicsWidgetItem
*>
(
item
);
if
(
widget
){
QUuid
newUUid
=
QUuid
::
createUuid
();
QString
newUUidString
=
newUUid
.
toString
().
remove
(
"{"
).
remove
(
"}"
);
QString
actualUuidString
=
widget
->
uuid
().
toString
().
remove
(
"{"
).
remove
(
"}"
);
QString
widgetSourcePath
=
proxy
->
persistencePath
()
+
"/"
+
UBPersistenceManager
::
widgetDirectory
+
"/{"
+
actualUuidString
+
"}.wgt"
;
QString
screenshotSourcePath
=
proxy
->
persistencePath
()
+
"/"
+
UBPersistenceManager
::
widgetDirectory
+
"/"
+
actualUuidString
+
".png"
;
QString
widgetDestinationPath
=
widgetSourcePath
;
widgetDestinationPath
=
widgetDestinationPath
.
replace
(
actualUuidString
,
newUUidString
);
QString
screenshotDestinationPath
=
screenshotSourcePath
;
screenshotDestinationPath
=
screenshotDestinationPath
.
replace
(
actualUuidString
,
newUUidString
);
UBFileSystemUtils
::
copyDir
(
widgetSourcePath
,
widgetDestinationPath
);
QFile
::
copy
(
screenshotSourcePath
,
screenshotDestinationPath
);
widget
->
setUuid
(
newUUid
);
widget
->
widgetUrl
(
QUrl
::
fromLocalFile
(
widgetDestinationPath
));
continue
;
}
UBGraphicsPixmapItem
*
pixmapItem
=
qgraphicsitem_cast
<
UBGraphicsPixmapItem
*>
(
item
);
if
(
pixmapItem
){
QString
source
=
proxy
->
persistencePath
()
+
"/"
+
UBPersistenceManager
::
imageDirectory
+
"/"
+
pixmapItem
->
uuid
().
toString
()
+
".png"
;
QString
destination
=
source
;
QUuid
newUuid
=
QUuid
::
createUuid
();
QString
fileName
=
QFileInfo
(
source
).
completeBaseName
();
destination
=
destination
.
replace
(
fileName
,
newUuid
.
toString
());
QFile
::
copy
(
source
,
destination
);
pixmapItem
->
setUuid
(
newUuid
);
continue
;
}
UBGraphicsSvgItem
*
svgItem
=
qgraphicsitem_cast
<
UBGraphicsSvgItem
*>
(
item
);
if
(
svgItem
){
QString
source
=
proxy
->
persistencePath
()
+
"/"
+
UBPersistenceManager
::
imageDirectory
+
"/"
+
svgItem
->
uuid
().
toString
()
+
".svg"
;
QString
destination
=
source
;
QUuid
newUuid
=
QUuid
::
createUuid
();
QString
fileName
=
QFileInfo
(
source
).
completeBaseName
();
destination
=
destination
.
replace
(
fileName
,
newUuid
.
toString
());
QFile
::
copy
(
source
,
destination
);
svgItem
->
setUuid
(
newUuid
);
continue
;
}
}
scene
->
setModified
(
true
);
persistDocumentScene
(
proxy
,
scene
,
index
+
1
);
proxy
->
incPageCount
();
emit
documentSceneCreated
(
proxy
,
index
+
1
);
...
...
src/document/UBDocumentController.cpp
View file @
38032fb4
...
...
@@ -1433,6 +1433,7 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event)
return
;
}
int
count
=
0
;
int
total
=
ubMime
->
items
().
size
();
QApplication
::
setOverrideCursor
(
QCursor
(
Qt
::
WaitCursor
));
...
...
@@ -1442,8 +1443,50 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event)
int
fromIndex
=
sourceItem
.
sceneIndex
();
int
toIndex
=
targetDocProxy
->
pageCount
();
UBPersistenceManager
::
persistenceManager
()
->
copyDocumentScene
(
fromProxy
,
fromIndex
,
targetDocProxy
,
toIndex
);
count
++
;
UBApplication
::
applicationController
->
showMessage
(
tr
(
"Copying page %1/%2"
).
arg
(
count
).
arg
(
total
),
true
);
// TODO UB 4.x Move following code to some controller class
UBGraphicsScene
*
scene
=
UBPersistenceManager
::
persistenceManager
()
->
loadDocumentScene
(
sourceItem
.
documentProxy
(),
sourceItem
.
sceneIndex
());
if
(
scene
)
{
UBGraphicsScene
*
sceneClone
=
scene
->
sceneDeepCopy
();
UBDocumentProxy
*
targetDocProxy
=
docModel
->
proxyForIndex
(
targetIndex
);
foreach
(
QUrl
relativeFile
,
scene
->
relativeDependencies
())
{
QString
source
=
scene
->
document
()
->
persistencePath
()
+
"/"
+
relativeFile
.
toString
();
QString
target
=
targetDocProxy
->
persistencePath
()
+
"/"
+
relativeFile
.
toString
();
QString
sourceDecoded
=
scene
->
document
()
->
persistencePath
()
+
"/"
+
relativeFile
.
toString
(
QUrl
::
DecodeReserved
);
QString
targetDecoded
=
targetDocProxy
->
persistencePath
()
+
"/"
+
relativeFile
.
toString
(
QUrl
::
DecodeReserved
);
if
(
QFileInfo
(
source
).
isDir
())
UBFileSystemUtils
::
copyDir
(
source
,
target
);
else
{
QFileInfo
fi
(
targetDecoded
);
QDir
d
=
fi
.
dir
();
d
.
mkpath
(
d
.
absolutePath
());
QFile
::
copy
(
sourceDecoded
,
targetDecoded
);
}
}
UBPersistenceManager
::
persistenceManager
()
->
insertDocumentSceneAt
(
targetDocProxy
,
sceneClone
,
targetDocProxy
->
pageCount
());
QString
thumbTmp
(
fromProxy
->
persistencePath
()
+
UBFileSystemUtils
::
digitFileFormat
(
"/page%1.thumbnail.jpg"
,
fromIndex
));
QString
thumbTo
(
targetDocProxy
->
persistencePath
()
+
UBFileSystemUtils
::
digitFileFormat
(
"/page%1.thumbnail.jpg"
,
toIndex
));
QFile
::
remove
(
thumbTo
);
QFile
::
copy
(
thumbTmp
,
thumbTo
);
Q_ASSERT
(
QFileInfo
(
thumbTmp
).
exists
());
Q_ASSERT
(
QFileInfo
(
thumbTo
).
exists
());
const
QPixmap
*
pix
=
new
QPixmap
(
thumbTmp
);
UBDocumentController
*
ctrl
=
UBApplication
::
documentController
;
ctrl
->
addPixmapAt
(
pix
,
toIndex
);
ctrl
->
TreeViewSelectionChanged
(
ctrl
->
firstSelectedTreeIndex
(),
QModelIndex
());
}
QApplication
::
restoreOverrideCursor
();
...
...
@@ -1451,6 +1494,8 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event)
docModel
->
setHighLighted
(
QModelIndex
());
}
}
else
{
if
(
targetIsInTrash
)
...
...
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