Commit 5ac2f4a0 authored by Halla Rempt's avatar Halla Rempt Committed by Siddharth Sharma
Browse files

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

CCBUG:310310
parent 8d8238b4
......@@ -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;
......@@ -117,9 +115,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");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment