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