Commit dd5da17c authored by Boudewijn Rempt's avatar Boudewijn Rempt

Try to make the parts/document relation more robust in Krita

CCBUG:310310
parent 69847a93
......@@ -42,10 +42,7 @@ void KisProjectionBenchmark::cleanupTestCase()
void KisProjectionBenchmark::benchmarkProjection()
{
QBENCHMARK{
KisPart2 part;
KisDoc2 doc(&part);
part.setDocument(&doc);
KisDoc2 doc;
doc.loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra");
doc.image()->refreshGraph();
doc.saveNativeFormat(QString(FILES_OUTPUT_DIR) + QDir::separator() + "save_test.kra");
......@@ -55,9 +52,7 @@ void KisProjectionBenchmark::benchmarkProjection()
void KisProjectionBenchmark::benchmarkLoading()
{
QBENCHMARK{
KisPart2 part;
KisDoc2 doc(&part);
part.setDocument(&doc);
KisDoc2 doc;
doc.loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra");
}
......
......@@ -71,9 +71,7 @@ void KisDropButton::dropEvent(QDropEvent *event)
QByteArray ba = event->mimeData()->data("application/x-krita-node");
KisPart2 part;
KisDoc2 tmpDoc(&part);
part.setDocument(&tmpDoc);
KisDoc2 tmpDoc;
tmpDoc.loadNativeFormatFromStore(ba);
......
......@@ -61,10 +61,7 @@ void Imagesplit::saveAsImage(QRect imgSize,QString mimeType,KUrl url)
{
KisImageWSP image = m_view->image();
KisPart2 part;
KisDoc2 d(&part);
part.setDocument(&d);
KisDoc2 d;
d.prepareForImport();
KisImageWSP dst = new KisImage(d.createUndoStore(), imgSize.width(),imgSize.height(), image->colorSpace(), image->objectName());
......
......@@ -253,10 +253,7 @@ void KisChannelSeparator::separate(KoUpdater * progressUpdater, enumSepAlphaOpti
KisPaintLayerSP l = KisPaintLayerSP(new KisPaintLayer(image.data(), ch->name(), OPACITY_OPAQUE_U8, *deviceIt));
QRect r = l->exactBounds();
KisPart2 part;
KisDoc2 d(&part);
part.setDocument(&d);
KisDoc2 d;
d.prepareForImport();
KisImageWSP dst = KisImageWSP(new KisImage(d.createUndoStore(), r.width(), r.height(), (*deviceIt)->colorSpace(), l->name()));
......
......@@ -34,7 +34,6 @@
#include <kis_paint_device.h>
#include <kundo2command.h>
#include <KoColorSpaceRegistry.h>
#include <kis_part2.h>
#include "ui_wdgfastcolortransfer.h"
......@@ -71,9 +70,7 @@ KisPropertiesConfiguration* KisWdgFastColorTransfer::configuration() const
dbgPlugins << "Use as reference file : " << fileName;
KisPart2 part;
KisDoc2 d(&part);
part.setDocument(&d);
KisDoc2 d;
KoFilterManager manager(&d);
KoFilter::ConversionStatus status;
......
......@@ -36,6 +36,7 @@
#include <kis_transaction.h>
#include <kis_paint_device.h>
#include <kis_doc2.h>
#include <kis_part2.h>
#include <kis_image.h>
#include <kis_paint_layer.h>
#include <kis_node.h>
......
......@@ -34,7 +34,6 @@
#include <KoFilterManager.h>
#include <kis_doc2.h>
#include <kis_part2.h>
#include <KoPart.h>
#include <kis_image.h>
#include <KoColorSpace.h>
......@@ -65,9 +64,7 @@ void testFiles(const QString& _dirname, const QStringList& exclusions, const QSt
continue;
}
KisPart2 part;
KisDoc2 doc(&part);
part.setDocument(&doc);
KisDoc2 doc;
KoFilterManager manager(&doc);
manager.setBatchMode(true);
......
......@@ -29,7 +29,8 @@
#include "kis_selection_manager.h"
#include "kis_node_manager.h"
#include "kis_view2.h"
#include "kis_part2.h"
#include <KoDocument.h>
#include <KoPart.h>
#include <kis_action_manager.h>
#include "KoMainWindow.h"
......@@ -46,9 +47,7 @@ public:
undoStore = new KisSurrogateUndoStore();
image = createImage(undoStore);
part = new KisPart2(0);
doc = new KisDoc2(part);
part->setDocument(doc);
doc = new KisDoc2();
doc->setCurrentImage(image);
if(useSelection) addGlobalSelection(image);
......@@ -57,8 +56,8 @@ public:
QVERIFY(checkLayersInitial());
shell = new KoMainWindow(part->componentData());
view = new KisView2(part, doc, shell);
shell = new KoMainWindow(doc->documentPart()->componentData());
view = new KisView2(doc->documentPart(), doc, shell);
KisPattern *newPattern = new KisPattern(fetchDataFileLazy("HR_SketchPaper_01.pat"));
newPattern->load();
......@@ -91,7 +90,6 @@ public:
delete shell;
delete doc;
delete part;
/**
* The event queue may have up to 200k events
......@@ -159,7 +157,6 @@ public:
protected:
KisView2 *view;
KisDoc2 *doc;
KisPart2 *part;
KoMainWindow *shell;
};
......
......@@ -20,9 +20,12 @@
#include <klocale.h>
#include <kundo2command.h>
#include <KoMainWindow.h>
#include <KoDocumentEntry.h>
#include <KoServiceProvider.h>
#include <KoPart.h>
#include "kis_view2.h"
#include "kis_canvas_resource_provider.h"
#include "kis_clipboard.h"
......@@ -352,15 +355,8 @@ void KisPasteNewActionFactory::run(KisView2 *view)
QRect rect = clip->exactBounds();
if (rect.isEmpty()) return;
const QByteArray mimetype = KoServiceProvider::readNativeFormatMimeType();
KoDocumentEntry entry = KoDocumentEntry::queryByMimeType(mimetype);
QString error;
KisPart2* part = dynamic_cast<KisPart2*>(entry.createKoPart(&error));
if (!part) return;
KisDoc2 *doc = new KisDoc2(part);
KisDoc2 *doc = new KisDoc2();
if (!doc) return;
part->setDocument(doc);
KisImageSP image = new KisImage(doc->createUndoStore(),
rect.width(),
......@@ -379,7 +375,7 @@ void KisPasteNewActionFactory::run(KisView2 *view)
image->addNode(layer.data(), image->rootLayer());
doc->setCurrentImage(image);
KoMainWindow *win = new KoMainWindow(part->componentData());
KoMainWindow *win = new KoMainWindow(doc->documentPart()->componentData());
win->show();
win->setRootDocument(doc);
}
......
......@@ -141,18 +141,15 @@ public:
QList<KisPaintingAssistant*> assistants;
KisPart2 *part; // XXX: we shouldn't know about the part here!
QString flipbook;
};
KisDoc2::KisDoc2(KoPart *parent)
: KoDocument(parent, new UndoStack(this))
KisDoc2::KisDoc2()
: KoDocument(new KisPart2, new UndoStack(this))
, m_d(new KisDocPrivate())
{
m_d->part = qobject_cast<KisPart2*>(parent);
qobject_cast<KisPart2*>(documentPart())->setDocument(this);
// preload the krita resources
KisResourceServerProvider::instance();
......@@ -175,6 +172,8 @@ KisDoc2::~KisDoc2()
m_d->image.clear();
delete m_d;
documentPart()->deleteLater();
}
QByteArray KisDoc2::mimeType() const
......@@ -429,7 +428,7 @@ KoShapeLayer* KisDoc2::shapeForNode(KisNodeSP layer) const
vKisNodeSP KisDoc2::activeNodes() const
{
vKisNodeSP nodes;
foreach(KoView *v, m_d->part->views()) {
foreach(KoView *v, documentPart()->views()) {
KisView2 *view = qobject_cast<KisView2*>(v);
if (view) {
KisNodeSP activeNode = view->activeNode();
......@@ -447,7 +446,7 @@ vKisNodeSP KisDoc2::activeNodes() const
QList<KisPaintingAssistant*> KisDoc2::assistants()
{
QList<KisPaintingAssistant*> assistants;
foreach(KoView *v, m_d->part->views()) {
foreach(KoView *v, documentPart()->views()) {
KisView2 *view = qobject_cast<KisView2*>(v);
if (view) {
KisPaintingAssistantsManager* assistantsmanager = view->paintingAssistantManager();
......
......@@ -27,7 +27,6 @@
#include <KoDocument.h>
#include "kis_types.h"
#include "kis_part2.h"
#include <krita_export.h>
#include <kis_painting_assistant.h>
......@@ -35,7 +34,6 @@ class QString;
class KoColor;
class KoColorSpace;
class KoPart2;
class KoShapeBasedDocumentBase;
class KoShapeLayer;
......@@ -64,7 +62,7 @@ class KRITAUI_EXPORT KisDoc2 : public KoDocument
Q_OBJECT
public:
KisDoc2(KoPart* parent);
KisDoc2();
virtual ~KisDoc2();
public:
......
......@@ -80,11 +80,9 @@ QObject* KisFactory2::create( const char* /*iface*/, QWidget* /*parentWidget*/,
Q_UNUSED( args );
Q_UNUSED( keyword );
KisPart2 *part = new KisPart2(parent);
KisDoc2 *doc = new KisDoc2(part);
part->setDocument(doc);
KisDoc2 *doc = new KisDoc2();
return part;
return doc->documentPart();
}
......
......@@ -22,7 +22,6 @@
#include "kis_transform_worker.h"
#include "kis_filter_strategy.h"
#include "kis_doc2.h"
#include "kis_part2.h"
#include "kis_node_progress_proxy.h"
#include "kis_node_visitor.h"
......@@ -31,12 +30,10 @@
KisFileLayer::KisFileLayer(KisImageWSP image, const QString &filename, bool scaleToImageResolution, const QString &name, quint8 opacity)
: KisExternalLayer(image, name, opacity)
, m_part(new KisPart2(0))
, m_doc(new KisDoc2(m_part))
, m_doc(new KisDoc2())
, m_filename(filename)
, m_scaleToImageResolution(scaleToImageResolution)
{
m_part->setDocument(m_doc);
Q_ASSERT(QFile::exists(filename));
if (QFile::exists(filename)) {
m_fileWatcher.addPath(filename);
......@@ -48,15 +45,12 @@ KisFileLayer::KisFileLayer(KisImageWSP image, const QString &filename, bool scal
KisFileLayer::~KisFileLayer()
{
delete m_doc;
delete m_part;
}
KisFileLayer::KisFileLayer(const KisFileLayer &rhs)
: KisExternalLayer(rhs)
, m_part(new KisPart2(0))
, m_doc(new KisDoc2(m_part))
, m_doc(new KisDoc2())
{
m_part->setDocument(m_doc);
Q_ASSERT(QFile::exists(rhs.m_filename));
connect(&m_fileWatcher, SIGNAL(fileChanged(QString)), SLOT(reloadImage()));
......
......@@ -61,7 +61,6 @@ public slots:
void reloadImage();
private:
KisPart2 *m_part;
KisDoc2 *m_doc;
QString m_filename;
......
......@@ -64,21 +64,17 @@ KisFlipbookItem::KisFlipbookItem(const QString &filename)
KisFlipbookItem::~KisFlipbookItem()
{
delete m_part;
delete m_document;
}
KisDoc2 *KisFlipbookItem::document()
{
if (!m_document) {
KisPart2 *part = new KisPart2(0);
m_document = new KisDoc2(part);
part->setDocument(m_document);
m_document = new KisDoc2();
m_document->openUrl(KUrl(m_filename));
if (!m_document->image().isValid()) {
delete m_document;
delete part;
m_document = 0;
return 0;
}
......
......@@ -43,7 +43,6 @@
#include "kis_selection.h"
#include "kis_node_commands_adapter.h"
#include "kis_group_layer.h"
#include "kis_part2.h"
#include "kis_statusbar.h"
#include "kis_progress_widget.h"
......@@ -52,7 +51,6 @@
struct KisImportCatcher::Private
{
public:
KisPart2* part;
KisDoc2* doc;
KisView2* view;
KUrl url;
......@@ -116,9 +114,7 @@ void KisImportCatcher::Private::importAsTransparencyMask(KisPaintDeviceSP device
KisImportCatcher::KisImportCatcher(const KUrl & url, KisView2 * view, bool importAsLayer)
: m_d(new Private)
{
KisPart2 *part = new KisPart2(0);
m_d->doc = new KisDoc2(part);
part->setDocument(m_d->doc);
m_d->doc = new KisDoc2();
KoProgressProxy *progressProxy = view->statusBar()->progress()->progressProxy();
m_d->doc->setProgressProxy(progressProxy);
......
......@@ -72,7 +72,6 @@
#include <metadata/kis_meta_data_merge_strategy_registry.h>
#include <kis_file_layer.h>
#include "kis_part2.h"
#include "kis_config.h"
#include "kis_cursor.h"
#include "dialogs/kis_dlg_adj_layer_props.h"
......@@ -98,7 +97,6 @@
#include "kis_node_manager.h"
#include "kis_action.h"
#include "kis_action_manager.h"
#include "kis_part2.h"
class KisSaveGroupVisitor : public KisNodeVisitor
{
......@@ -183,9 +181,7 @@ public:
QRect r = m_image->bounds();
KisPart2 part;
KisDoc2 d(&part);
part.setDocument(&d);
KisDoc2 d;
d.prepareForImport();
......
......@@ -24,7 +24,6 @@
#include "kis_shared_ptr.h"
#include "kis_image.h"
#include "kis_doc2.h"
#include "kis_part2.h"
#include <KoStore.h>
#include <KoColorProfile.h>
......@@ -84,9 +83,7 @@ QVariant KisMimeData::retrieveData(const QString &mimetype, QVariant::Type prefe
Q_ASSERT(!store->bad());
store->disallowNameExpansion();
KisPart2 part;
KisDoc2 doc(&part);
part.setDocument(&doc);
KisDoc2 doc;
QRect rc = node->exactBounds();
......
......@@ -679,9 +679,7 @@ void KisNodeManager::saveNodeAsImage()
QRect savedRect = image->bounds() | node->exactBounds();
KisPart2 part;
KisDoc2 d(&part);
part.setDocument(&d);
KisDoc2 d;
d.prepareForImport();
......
......@@ -48,6 +48,7 @@ KisPart2::KisPart2(QObject *parent)
: KoPart(parent)
, m_flipbook(0)
, m_dieOnError(false)
, m_document(0)
{
setComponentData(KisFactory2::componentData(), false);
setTemplateType("krita_template");
......
......@@ -28,6 +28,7 @@ class KisDoc2;
class QGraphicsItem;
class KoView;
class KisFlipbook;
class KisDocument2;
class KRITAUI_EXPORT KisPart2 : public KoPart
{
......
......@@ -55,7 +55,6 @@
#include "kis_convolution_kernel.h"
#include "kis_debug.h"
#include "kis_doc2.h"
#include "kis_part2.h"
#include "kis_fill_painter.h"
#include "kis_group_layer.h"
#include "kis_image.h"
......
......@@ -79,6 +79,7 @@
#include <KoCanvasControllerWidget.h>
#include <KoDocumentEntry.h>
#include <KoProperties.h>
#include <KoPart.h>
#include <kis_image.h>
#include <kis_undo_adapter.h>
......@@ -107,7 +108,6 @@
#include "kis_painting_assistants_manager.h"
#include <kis_paint_layer.h>
#include "kis_paintop_box.h"
#include "kis_part2.h"
#include "kis_print_job.h"
#include "kis_progress_widget.h"
#include "kis_resource_server_provider.h"
......@@ -119,7 +119,6 @@
#include "kra/kis_kra_loader.h"
#include "widgets/kis_floating_message.h"
#include <QDebug>
#include <QPoint>
#include "kis_paintop_box.h"
......@@ -154,7 +153,6 @@ public:
KisView2Private()
: canvas(0)
, doc(0)
, part(0)
, viewConverter(0)
, canvasController(0)
, resourceProvider(0)
......@@ -196,7 +194,6 @@ public:
KisCanvas2 *canvas;
KisDoc2 *doc;
KisPart2 *part;
KisCoordinatesConverter *viewConverter;
KisCanvasController *canvasController;
KisCanvasResourceProvider *resourceProvider;
......@@ -221,7 +218,7 @@ public:
};
KisView2::KisView2(KisPart2 *part, KisDoc2 * doc, QWidget * parent)
KisView2::KisView2(KoPart *part, KisDoc2 * doc, QWidget * parent)
: KoView(part, doc, parent),
m_d(new KisView2Private())
{
......@@ -235,7 +232,6 @@ KisView2::KisView2(KisPart2 *part, KisDoc2 * doc, QWidget * parent)
}
m_d->doc = doc;
m_d->part = part;
m_d->viewConverter = new KisCoordinatesConverter();
KisCanvasController *canvasController = new KisCanvasController(this, actionCollection());
......@@ -466,10 +462,7 @@ void KisView2::dropEvent(QDropEvent *event)
QByteArray ba = event->mimeData()->data("application/x-krita-node");
KisPart2 part;
KisDoc2 tempDoc(&part);
part.setDocument(&tempDoc);
KisDoc2 tempDoc;
tempDoc.loadNativeFormatFromStore(ba);
KisImageWSP tempImage = tempDoc.image();
......@@ -567,8 +560,8 @@ void KisView2::dropEvent(QDropEvent *event)
m_d->imageManager->importImage(KUrl(url));
}
else if (action == replaceCurrentDocument) {
if (m_d->part->isModified()) {
m_d->part->save();
if (m_d->doc->isModified()) {
m_d->doc->documentPart()->save();
}
if (shell() != 0) {
shell()->openDocument(url);
......@@ -1150,7 +1143,7 @@ void KisView2::slotSaveIncremental()
return;
}
pDoc->setSaveInBatchMode(true);
m_d->part->saveAs(fileName);
m_d->doc->documentPart()->saveAs(fileName);
pDoc->setSaveInBatchMode(false);
shell()->updateCaption();
......@@ -1217,7 +1210,7 @@ void KisView2::slotSaveIncrementalBackup()
KMessageBox::error(this, "Alternative names exhausted, try manually saving with a higher number", "Couldn't save incremental backup");
return;
}
m_d->part->saveAs(fileName);
m_d->doc->documentPart()->saveAs(fileName);
shell()->updateCaption();
}
......@@ -1254,8 +1247,8 @@ void KisView2::slotSaveIncrementalBackup()
// Save both as backup and on current file for interapplication workflow
pDoc->setSaveInBatchMode(true);
m_d->part->saveAs(backupFileName);
m_d->part->saveAs(fileName);
m_d->doc->documentPart()->saveAs(backupFileName);
m_d->doc->documentPart()->saveAs(fileName);
pDoc->setSaveInBatchMode(false);
shell()->updateCaption();
......
......@@ -47,7 +47,6 @@ class KisImageManager;
class KisNodeManager;
class KisPaintingAssistantsManager;
class KisPaintopBox;
class KisPart2;
class KisPerspectiveGridManager;
class KisSelectionManager;
class KisStatusBar;
......@@ -73,7 +72,7 @@ public:
* @param document the document we show.
* @param parent a parent widget we show ourselves in.
*/
KisView2(KisPart2 *part, KisDoc2 *document, QWidget *parent);
KisView2(KoPart *part, KisDoc2 *document, QWidget *parent);
virtual ~KisView2();
public:
......
......@@ -20,8 +20,10 @@
#include "kis_action_manager_test.h"
#include <kdebug.h>
#include <KoPart.h>
#include <KoMainWindow.h>
#include <kis_doc2.h>
#include <kis_part2.h>
#include <kis_view2.h>
#include <util.h>
#include <kis_action.h>
......
......@@ -41,9 +41,7 @@ void KisDoc2Test::testOpenImageTwiceInSameDoc()
Q_ASSERT(!fname.isEmpty());
Q_ASSERT(!fname2.isEmpty());
KisPart2 part;
KisDoc2 doc(&part);
part.setDocument(&doc);
KisDoc2 doc;
doc.loadNativeFormat(fname);
doc.loadNativeFormat(fname2);
......
......@@ -26,14 +26,11 @@
#include <KoColorSpace.h>
#include "kis_doc2.h"
#include "kis_part2.h"
#include "kis_image.h"
void KisKraLoaderTest::testLoading()
{
KisPart2 part;
KisDoc2 doc(&part);
part.setDocument(&doc);
KisDoc2 doc;
doc.loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra");
KisImageWSP image = doc.image();
......
......@@ -47,7 +47,6 @@
#include "kis_fill_painter.h"
#include "kis_shape_selection.h"
#include "util.h"
#include "kis_part2.h"
void KisKraSaverTest::testRoundTrip()
{
......@@ -57,11 +56,7 @@ void KisKraSaverTest::testRoundTrip()
KisCountVisitor cv1(list, KoProperties());
doc->image()->rootLayer()->accept(cv1);
//delete doc;
KisPart2 part;
KisDoc2 doc2(&part);
part.setDocument(&doc2);
KisDoc2 doc2;
doc2.loadNativeFormat("roundtriptest.kra");
......@@ -78,12 +73,7 @@ void KisKraSaverTest::testSaveEmpty()
KisCountVisitor cv1(list, KoProperties());
doc->image()->rootLayer()->accept(cv1);
//delete doc;
KisPart2 part;
KisDoc2 doc2(&part);