Commit 727b0f03 authored by Halla Rempt's avatar Halla Rempt

For now, document and part go hand in hand

One day we'll be able to use a document without its attendant part,
but that day is not now. This should fix quite a number of tests and
bugs.
parent 98734ee2
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
void KisProjectionBenchmark::initTestCase() void KisProjectionBenchmark::initTestCase()
{ {
} }
void KisProjectionBenchmark::cleanupTestCase() void KisProjectionBenchmark::cleanupTestCase()
...@@ -42,7 +42,10 @@ void KisProjectionBenchmark::cleanupTestCase() ...@@ -42,7 +42,10 @@ void KisProjectionBenchmark::cleanupTestCase()
void KisProjectionBenchmark::benchmarkProjection() void KisProjectionBenchmark::benchmarkProjection()
{ {
QBENCHMARK{ QBENCHMARK{
KisDoc2 doc; KisPart2 *p = new KisPart2();
KisDoc2 doc(p);
p->setDocument(&doc);
doc.loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra"); doc.loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra");
doc.image()->refreshGraph(); doc.image()->refreshGraph();
doc.saveNativeFormat(QString(FILES_OUTPUT_DIR) + QDir::separator() + "save_test.kra"); doc.saveNativeFormat(QString(FILES_OUTPUT_DIR) + QDir::separator() + "save_test.kra");
...@@ -52,7 +55,9 @@ void KisProjectionBenchmark::benchmarkProjection() ...@@ -52,7 +55,9 @@ void KisProjectionBenchmark::benchmarkProjection()
void KisProjectionBenchmark::benchmarkLoading() void KisProjectionBenchmark::benchmarkLoading()
{ {
QBENCHMARK{ QBENCHMARK{
KisDoc2 doc; KisPart2 *p = new KisPart2();
KisDoc2 doc(p);
p->setDocument(&doc);
doc.loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra"); doc.loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra");
} }
} }
......
...@@ -56,9 +56,9 @@ void KisDropButton::dragEnterEvent(QDragEnterEvent *event) ...@@ -56,9 +56,9 @@ void KisDropButton::dragEnterEvent(QDragEnterEvent *event)
void KisDropButton::dropEvent(QDropEvent *event) void KisDropButton::dropEvent(QDropEvent *event)
{ {
qDebug() << "DROP EVENT" << event->mimeData()->formats(); qDebug() << "DROP EVENT" << event->mimeData()->formats();
KisNodeSP node; KisNodeSP node;
const KisMimeData *mimedata = qobject_cast<const KisMimeData*>(event->mimeData()); const KisMimeData *mimedata = qobject_cast<const KisMimeData*>(event->mimeData());
if (mimedata) { if (mimedata) {
...@@ -66,33 +66,36 @@ void KisDropButton::dropEvent(QDropEvent *event) ...@@ -66,33 +66,36 @@ void KisDropButton::dropEvent(QDropEvent *event)
node = mimedata->node(); node = mimedata->node();
} }
else if (event->mimeData()->hasFormat("application/x-krita-node") ) { else if (event->mimeData()->hasFormat("application/x-krita-node") ) {
qDebug() << "going to deserialize the dropped node"; qDebug() << "going to deserialize the dropped node";
QByteArray ba = event->mimeData()->data("application/x-krita-node"); QByteArray ba = event->mimeData()->data("application/x-krita-node");
KisDoc2 tmpDoc; KisPart2 *p = new KisPart2();
KisDoc2 tmpDoc(p);
p->setDocument(&tmpDoc);
tmpDoc.loadNativeFormatFromStore(ba); tmpDoc.loadNativeFormatFromStore(ba);
node = tmpDoc.image()->rootLayer()->firstChild(); node = tmpDoc.image()->rootLayer()->firstChild();
} }
else if (event->mimeData()->hasImage()) { else if (event->mimeData()->hasImage()) {
qDebug() << "got an image"; qDebug() << "got an image";
QImage qimage = qvariant_cast<QImage>(event->mimeData()->imageData()); QImage qimage = qvariant_cast<QImage>(event->mimeData()->imageData());
KisPaintDeviceSP device = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); KisPaintDeviceSP device = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8());
device->convertFromQImage(qimage, 0); device->convertFromQImage(qimage, 0);
node = new KisPaintLayer(0, "node creaed from dropped image", OPACITY_OPAQUE_U8, device); node = new KisPaintLayer(0, "node creaed from dropped image", OPACITY_OPAQUE_U8, device);
} }
if (node) { if (node) {
if (event->keyboardModifiers() & Qt::ShiftModifier) { if (event->keyboardModifiers() & Qt::ShiftModifier) {
replaceFromNode(node); replaceFromNode(node);
} }
else { else {
createFromNode(node); createFromNode(node);
} }
} }
} }
...@@ -72,7 +72,10 @@ void Imagesplit::saveAsImage(QRect imgSize,QString mimeType,KUrl url) ...@@ -72,7 +72,10 @@ void Imagesplit::saveAsImage(QRect imgSize,QString mimeType,KUrl url)
{ {
KisImageWSP image = m_view->image(); KisImageWSP image = m_view->image();
KisDoc2 d; KisPart2 *p = new KisPart2();
KisDoc2 d(p);
p->setDocument(&d);
d.prepareForImport(); d.prepareForImport();
KisImageWSP dst = new KisImage(d.createUndoStore(), imgSize.width(),imgSize.height(), image->colorSpace(), image->objectName()); KisImageWSP dst = new KisImage(d.createUndoStore(), imgSize.width(),imgSize.height(), image->colorSpace(), image->objectName());
......
...@@ -253,7 +253,9 @@ void KisChannelSeparator::separate(KoUpdater * progressUpdater, enumSepAlphaOpti ...@@ -253,7 +253,9 @@ void KisChannelSeparator::separate(KoUpdater * progressUpdater, enumSepAlphaOpti
KisPaintLayerSP l = KisPaintLayerSP(new KisPaintLayer(image.data(), ch->name(), OPACITY_OPAQUE_U8, *deviceIt)); KisPaintLayerSP l = KisPaintLayerSP(new KisPaintLayer(image.data(), ch->name(), OPACITY_OPAQUE_U8, *deviceIt));
QRect r = l->exactBounds(); QRect r = l->exactBounds();
KisDoc2 d; KisPart2 *p = new KisPart2();
KisDoc2 d(p);
p->setDocument(&d);
d.prepareForImport(); d.prepareForImport();
KisImageWSP dst = KisImageWSP(new KisImage(d.createUndoStore(), r.width(), r.height(), (*deviceIt)->colorSpace(), l->name())); KisImageWSP dst = KisImageWSP(new KisImage(d.createUndoStore(), r.width(), r.height(), (*deviceIt)->colorSpace(), l->name()));
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <kis_paint_device.h> #include <kis_paint_device.h>
#include <kundo2command.h> #include <kundo2command.h>
#include <KoColorSpaceRegistry.h> #include <KoColorSpaceRegistry.h>
#include <kis_part2.h>
#include "ui_wdgfastcolortransfer.h" #include "ui_wdgfastcolortransfer.h"
...@@ -63,13 +64,16 @@ KisPropertiesConfiguration* KisWdgFastColorTransfer::configuration() const ...@@ -63,13 +64,16 @@ KisPropertiesConfiguration* KisWdgFastColorTransfer::configuration() const
{ {
KisFilterConfiguration* config = new KisFilterConfiguration("colortransfer", 1); KisFilterConfiguration* config = new KisFilterConfiguration("colortransfer", 1);
QString fileName = this->widget()->fileNameURLRequester->url().url(); QString fileName = this->widget()->fileNameURLRequester->url().url();
if (fileName.isEmpty()) return config; if (fileName.isEmpty()) return config;
KisPaintDeviceSP ref; KisPaintDeviceSP ref;
dbgPlugins << "Use as reference file : " << fileName; dbgPlugins << "Use as reference file : " << fileName;
KisDoc2 d; KisPart2 *p = new KisPart2();
KisDoc2 d(p);
p->setDocument(&d);
KoFilterManager manager(&d); KoFilterManager manager(&d);
KoFilter::ConversionStatus status; KoFilter::ConversionStatus status;
QString s = manager.importDocument(fileName, QString(), status); QString s = manager.importDocument(fileName, QString(), status);
...@@ -83,22 +87,22 @@ KisPropertiesConfiguration* KisWdgFastColorTransfer::configuration() const ...@@ -83,22 +87,22 @@ KisPropertiesConfiguration* KisWdgFastColorTransfer::configuration() const
dbgPlugins << "No reference image was specified."; dbgPlugins << "No reference image was specified.";
return config; return config;
} }
// Convert ref to LAB // Convert ref to LAB
const KoColorSpace* labCS = KoColorSpaceRegistry::instance()->lab16(); const KoColorSpace* labCS = KoColorSpaceRegistry::instance()->lab16();
if (!labCS) { if (!labCS) {
dbgPlugins << "The LAB colorspace is not available."; dbgPlugins << "The LAB colorspace is not available.";
return config; return config;
} }
dbgPlugins << "convert ref to lab"; dbgPlugins << "convert ref to lab";
KUndo2Command* cmd = ref->convertTo(labCS, KoColorConversionTransformation::IntentPerceptual, KoColorConversionTransformation::BlackpointCompensation); KUndo2Command* cmd = ref->convertTo(labCS, KoColorConversionTransformation::IntentPerceptual, KoColorConversionTransformation::BlackpointCompensation);
delete cmd; delete cmd;
// Compute the means and sigmas of ref // Compute the means and sigmas of ref
double meanL_ref = 0., meanA_ref = 0., meanB_ref = 0.; double meanL_ref = 0., meanA_ref = 0., meanB_ref = 0.;
double sigmaL_ref = 0., sigmaA_ref = 0., sigmaB_ref = 0.; double sigmaL_ref = 0., sigmaA_ref = 0., sigmaB_ref = 0.;
KisRectConstIteratorSP refIt = ref->createRectConstIteratorNG(0, 0, importedImage->width(), importedImage->height()); KisRectConstIteratorSP refIt = ref->createRectConstIteratorNG(0, 0, importedImage->width(), importedImage->height());
do { do {
const quint16* data = reinterpret_cast<const quint16*>(refIt->oldRawData()); const quint16* data = reinterpret_cast<const quint16*>(refIt->oldRawData());
...@@ -125,7 +129,7 @@ KisPropertiesConfiguration* KisWdgFastColorTransfer::configuration() const ...@@ -125,7 +129,7 @@ KisPropertiesConfiguration* KisWdgFastColorTransfer::configuration() const
sigmaL_ref *= totalSize; sigmaL_ref *= totalSize;
sigmaA_ref *= totalSize; sigmaA_ref *= totalSize;
sigmaB_ref *= totalSize; sigmaB_ref *= totalSize;
dbgPlugins << totalSize << "" << meanL_ref << "" << meanA_ref << "" << meanB_ref << "" << sigmaL_ref << "" << sigmaA_ref << "" << sigmaB_ref; dbgPlugins << totalSize << "" << meanL_ref << "" << meanA_ref << "" << meanB_ref << "" << sigmaL_ref << "" << sigmaA_ref << "" << sigmaB_ref;
config->setProperty("filename", fileName); config->setProperty("filename", fileName);
...@@ -135,6 +139,6 @@ KisPropertiesConfiguration* KisWdgFastColorTransfer::configuration() const ...@@ -135,6 +139,6 @@ KisPropertiesConfiguration* KisWdgFastColorTransfer::configuration() const
config->setProperty("sigmaL", sigmaL_ref); config->setProperty("sigmaL", sigmaL_ref);
config->setProperty("sigmaA", sigmaA_ref); config->setProperty("sigmaA", sigmaA_ref);
config->setProperty("sigmaB", sigmaB_ref); config->setProperty("sigmaB", sigmaB_ref);
return config; return config;
} }
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <KoFilterManager.h> #include <KoFilterManager.h>
#include <kis_doc2.h> #include <kis_doc2.h>
#include <kis_part2.h>
#include <KoPart.h> #include <KoPart.h>
#include <kis_image.h> #include <kis_image.h>
#include <KoColorSpace.h> #include <KoColorSpace.h>
...@@ -64,7 +65,10 @@ void testFiles(const QString& _dirname, const QStringList& exclusions, const QSt ...@@ -64,7 +65,10 @@ void testFiles(const QString& _dirname, const QStringList& exclusions, const QSt
continue; continue;
} }
KisDoc2 doc; KisPart2 *p = new KisPart2();
KisDoc2 doc(p);
p->setDocument(&doc);
KoFilterManager manager(&doc); KoFilterManager manager(&doc);
manager.setBatchMode(true); manager.setBatchMode(true);
QByteArray nativeFormat = doc.nativeFormatMimeType(); QByteArray nativeFormat = doc.nativeFormatMimeType();
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <KoDocument.h> #include <KoDocument.h>
#include "kis_types.h" #include "kis_types.h"
#include "kis_part2.h"
#include <krita_export.h> #include <krita_export.h>
#include <kis_painting_assistant.h> #include <kis_painting_assistant.h>
...@@ -64,7 +64,7 @@ class KRITAUI_EXPORT KisDoc2 : public KoDocument ...@@ -64,7 +64,7 @@ class KRITAUI_EXPORT KisDoc2 : public KoDocument
Q_OBJECT Q_OBJECT
public: public:
KisDoc2(KoPart* parent = 0); KisDoc2(KoPart* parent);
virtual ~KisDoc2(); virtual ~KisDoc2();
public: public:
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
#include <metadata/kis_meta_data_store.h> #include <metadata/kis_meta_data_store.h>
#include <metadata/kis_meta_data_merge_strategy_registry.h> #include <metadata/kis_meta_data_merge_strategy_registry.h>
#include "kis_part2.h"
#include "kis_config.h" #include "kis_config.h"
#include "kis_cursor.h" #include "kis_cursor.h"
#include "dialogs/kis_dlg_adj_layer_props.h" #include "dialogs/kis_dlg_adj_layer_props.h"
...@@ -174,9 +175,12 @@ public: ...@@ -174,9 +175,12 @@ public:
} }
else if (layer->visible() || m_saveInvisible) { else if (layer->visible() || m_saveInvisible) {
QRect r = m_image->bounds(); QRect r = m_image->bounds();
KisDoc2 d; KisPart2 *p = new KisPart2();
KisDoc2 d(p);
p->setDocument(&d);
d.prepareForImport(); d.prepareForImport();
KisImageWSP dst = new KisImage(d.createUndoStore(), r.width(), r.height(), m_image->colorSpace(), layer->name()); KisImageWSP dst = new KisImage(d.createUndoStore(), r.width(), r.height(), m_image->colorSpace(), layer->name());
...@@ -909,7 +913,10 @@ void KisLayerManager::saveLayerAsImage() ...@@ -909,7 +913,10 @@ void KisLayerManager::saveLayerAsImage()
QRect r = image->bounds(); QRect r = image->bounds();
KisDoc2 d; KisPart2 *p = new KisPart2();
KisDoc2 d(p);
p->setDocument(&d);
d.prepareForImport(); d.prepareForImport();
KisImageWSP dst = new KisImage(d.createUndoStore(), r.width(), r.height(), image->colorSpace(), l->name()); KisImageWSP dst = new KisImage(d.createUndoStore(), r.width(), r.height(), image->colorSpace(), l->name());
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "kis_shared_ptr.h" #include "kis_shared_ptr.h"
#include "kis_image.h" #include "kis_image.h"
#include "kis_doc2.h" #include "kis_doc2.h"
#include "kis_part2.h"
#include <KoStore.h> #include <KoStore.h>
#include <KoColorProfile.h> #include <KoColorProfile.h>
...@@ -81,7 +82,9 @@ QVariant KisMimeData::retrieveData(const QString &mimetype, QVariant::Type prefe ...@@ -81,7 +82,9 @@ QVariant KisMimeData::retrieveData(const QString &mimetype, QVariant::Type prefe
Q_ASSERT(!store->bad()); Q_ASSERT(!store->bad());
store->disallowNameExpansion(); store->disallowNameExpansion();
KisDoc2 doc; KisPart2 *p = new KisPart2();
KisDoc2 doc(p);
p->setDocument(&doc);
QRect rc = node->exactBounds(); QRect rc = node->exactBounds();
......
...@@ -33,7 +33,7 @@ class KRITAUI_EXPORT KisPart2 : public KoPart ...@@ -33,7 +33,7 @@ class KRITAUI_EXPORT KisPart2 : public KoPart
Q_OBJECT Q_OBJECT
public: public:
KisPart2(QObject *parent); KisPart2(QObject *parent = 0);
virtual ~KisPart2(); virtual ~KisPart2();
......
...@@ -462,7 +462,10 @@ void KisView2::dropEvent(QDropEvent *event) ...@@ -462,7 +462,10 @@ void KisView2::dropEvent(QDropEvent *event)
QByteArray ba = event->mimeData()->data("application/x-krita-node"); QByteArray ba = event->mimeData()->data("application/x-krita-node");
KisDoc2 tempDoc; KisPart2 *p = new KisPart2();
KisDoc2 tempDoc(p);
p->setDocument(&tempDoc);
tempDoc.loadNativeFormatFromStore(ba); tempDoc.loadNativeFormatFromStore(ba);
KisImageWSP tempImage = tempDoc.image(); KisImageWSP tempImage = tempDoc.image();
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "kis_undo_store.h" #include "kis_undo_store.h"
#include "kis_factory2.h" #include "kis_factory2.h"
#include <KoDocumentEntry.h> #include <KoDocumentEntry.h>
#include "kis_part2.h"
#include <KoMainWindow.h> #include <KoMainWindow.h>
class KisCommandHistoryListenerFake : public KisCommandHistoryListener class KisCommandHistoryListenerFake : public KisCommandHistoryListener
...@@ -87,7 +88,10 @@ public: ...@@ -87,7 +88,10 @@ public:
void KisDoc2Test::testUndoRedoNotify() void KisDoc2Test::testUndoRedoNotify()
{ {
KisDoc2 doc; KisPart2 *p = new KisPart2();
KisDoc2 doc(p);
p->setDocument(&doc);
doc.initEmpty(); doc.initEmpty();
KUndo2Command *testCommand1 = new TestCommand(); KUndo2Command *testCommand1 = new TestCommand();
...@@ -159,7 +163,10 @@ void KisDoc2Test::testOpenImageTwiceInSameDoc() ...@@ -159,7 +163,10 @@ void KisDoc2Test::testOpenImageTwiceInSameDoc()
Q_ASSERT(!fname.isEmpty()); Q_ASSERT(!fname.isEmpty());
Q_ASSERT(!fname2.isEmpty()); Q_ASSERT(!fname2.isEmpty());
KisDoc2 doc; KisPart2 *p = new KisPart2();
KisDoc2 doc(p);
p->setDocument(&doc);
doc.loadNativeFormat(fname); doc.loadNativeFormat(fname);
doc.loadNativeFormat(fname2); doc.loadNativeFormat(fname2);
} }
......
...@@ -26,11 +26,15 @@ ...@@ -26,11 +26,15 @@
#include <KoColorSpace.h> #include <KoColorSpace.h>
#include "kis_doc2.h" #include "kis_doc2.h"
#include "kis_part2.h"
#include "kis_image.h" #include "kis_image.h"
void KisKraLoaderTest::testLoading() void KisKraLoaderTest::testLoading()
{ {
KisDoc2 doc; KisPart2 *p = new KisPart2();
KisDoc2 doc(p);
p->setDocument(&doc);
doc.loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra"); doc.loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra");
KisImageWSP image = doc.image(); KisImageWSP image = doc.image();
image->lock(); image->lock();
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "kis_fill_painter.h" #include "kis_fill_painter.h"
#include "kis_shape_selection.h" #include "kis_shape_selection.h"
#include "util.h" #include "util.h"
#include "kis_part2.h"
void KisKraSaverTest::testRoundTrip() void KisKraSaverTest::testRoundTrip()
{ {
...@@ -58,7 +59,11 @@ void KisKraSaverTest::testRoundTrip() ...@@ -58,7 +59,11 @@ void KisKraSaverTest::testRoundTrip()
delete doc; delete doc;
KisDoc2 doc2;
KisPart2 *p = new KisPart2();
KisDoc2 doc2(p);
p->setDocument(&doc2);
doc2.loadNativeFormat("roundtriptest.kra"); doc2.loadNativeFormat("roundtriptest.kra");
KisCountVisitor cv2(list, KoProperties()); KisCountVisitor cv2(list, KoProperties());
......
...@@ -33,7 +33,10 @@ ...@@ -33,7 +33,10 @@
void KisNodeModelTest::init() void KisNodeModelTest::init()
{ {
m_doc = new KisDoc2; KisPart2 *p = new KisPart2();
KisDoc2 *doc = new KisDoc2(p);
p->setDocument(doc);
m_nameServer = new KisNameServer(); m_nameServer = new KisNameServer();
m_shapeController = new KisShapeController(m_doc, m_nameServer); m_shapeController = new KisShapeController(m_doc, m_nameServer);
m_nodeModel = new KisNodeModel(0); m_nodeModel = new KisNodeModel(0);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <qtest_kde.h> #include <qtest_kde.h>
#include "kis_doc2.h" #include "kis_doc2.h"
#include "kis_part2.h"
#include "kis_name_server.h" #include "kis_name_server.h"
#include "flake/kis_shape_controller.h" #include "flake/kis_shape_controller.h"
...@@ -31,7 +32,10 @@ KisShapeControllerTest::~KisShapeControllerTest() ...@@ -31,7 +32,10 @@ KisShapeControllerTest::~KisShapeControllerTest()
KisDummiesFacadeBase* KisShapeControllerTest::dummiesFacadeFactory() KisDummiesFacadeBase* KisShapeControllerTest::dummiesFacadeFactory()
{ {
m_doc = new KisDoc2;
KisPart2 *p = new KisPart2();
KisDoc2 *doc = new KisDoc2(p);
p->setDocument(doc);
m_nameServer = new KisNameServer(); m_nameServer = new KisNameServer();
return new KisShapeController(m_doc, m_nameServer); return new KisShapeController(m_doc, m_nameServer);
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <KoColorSpace.h> #include <KoColorSpace.h>
#include <KoPathShape.h> #include <KoPathShape.h>
#include "kis_part2.h"
#include <kis_count_visitor.h> #include <kis_count_visitor.h>
#include "kis_types.h" #include "kis_types.h"
#include "filter/kis_filter_registry.h" #include "filter/kis_filter_registry.h"
...@@ -84,7 +85,11 @@ KisSelectionSP createVectorSelection(KisPaintDeviceSP paintDevice, KisImageWSP i ...@@ -84,7 +85,11 @@ KisSelectionSP createVectorSelection(KisPaintDeviceSP paintDevice, KisImageWSP i
KisDoc2* createCompleteDocument() KisDoc2* createCompleteDocument()
{