Commit dfaea178 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Removed KisSelection::getOrCreatePixelSelection()

Now it is deprecated. The pixel selection component is always present
in the selection.

This patch always fixes several unittests failures
parent bbe1dd76
......@@ -78,7 +78,7 @@ typedef QTime KisTimeCounter;
void KisFilterSelectionsBenchmark::initSelection()
{
m_selection = new KisSelection();
KisPixelSelectionSP pixelSelection = m_selection->getOrCreatePixelSelection();
KisPixelSelectionSP pixelSelection = m_selection->pixelSelection();
//67.2% deselected
......
......@@ -122,7 +122,7 @@ void KisPainterBenchmark::benchmarkBitBltSelection()
dst->fill(0,0,TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT, m_color.data());
KisSelectionSP selection = new KisSelection();
selection->getOrCreatePixelSelection()->select(QRect(0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT));
selection->pixelSelection()->select(QRect(0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT));
selection->updateProjection();
......@@ -174,7 +174,7 @@ void KisPainterBenchmark::benchmarkFixedBitBltSelection()
KisPaintDeviceSP dst = new KisPaintDevice(m_colorSpace);
KisSelectionSP selection = new KisSelection();
selection->getOrCreatePixelSelection()->select(QRect(0, 0, TEST_IMAGE_WIDTH , TEST_IMAGE_HEIGHT));
selection->pixelSelection()->select(QRect(0, 0, TEST_IMAGE_WIDTH , TEST_IMAGE_HEIGHT));
selection->updateProjection();
KisPainter gc(dst);
......
......@@ -285,7 +285,7 @@ KisSelectionSP KisFillPainter::createFloodSelection(int startX, int startY, KisP
m_size = m_width * m_height;
KisSelectionSP selection = new KisSelection(new KisSelectionDefaultBounds(device()));
KisPixelSelectionSP pSel = selection->getOrCreatePixelSelection();
KisPixelSelectionSP pSel = selection->pixelSelection();
const KoColorSpace * devColorSpace = sourceDevice->colorSpace();
......
......@@ -143,12 +143,12 @@ void KisMask::Private::initSelectionImpl(KisSelectionSP copyFrom, KisLayerSP par
selection = new KisSelection(*copyFrom);
selection->setDefaultBounds(new KisSelectionDefaultBounds(parentPaintDevice, parentLayer->image()));
if (copyFrom->hasShapeSelection()) {
selection->flatten();
delete selection->flatten();
}
} else if (copyFromDevice) {
selection = new KisSelection(new KisSelectionDefaultBounds(parentPaintDevice, parentLayer->image()));
KisPainter gc(selection->getOrCreatePixelSelection());
KisPainter gc(selection->pixelSelection());
gc.setCompositeOp(COMPOSITE_COPY);
QRect rc(copyFromDevice->extent());
gc.bitBlt(rc.topLeft(), copyFromDevice, rc);
......@@ -157,7 +157,7 @@ void KisMask::Private::initSelectionImpl(KisSelectionSP copyFrom, KisLayerSP par
selection = new KisSelection(new KisSelectionDefaultBounds(parentPaintDevice, parentLayer->image()));
quint8 newDefaultPixel = MAX_SELECTED;
selection->getOrCreatePixelSelection()->setDefaultPixel(&newDefaultPixel);
selection->pixelSelection()->setDefaultPixel(&newDefaultPixel);
}
selection->setParentNode(q);
selection->updateProjection();
......@@ -176,7 +176,7 @@ KisSelectionSP KisMask::selection() const
KisPaintDeviceSP KisMask::paintDevice() const
{
return selection()->getOrCreatePixelSelection();
return selection()->pixelSelection();
}
KisPaintDeviceSP KisMask::original() const
......@@ -202,7 +202,7 @@ void KisMask::setSelection(KisSelectionSP selection)
void KisMask::select(const QRect & rc, quint8 selectedness)
{
KisSelectionSP sel = selection();
KisPixelSelectionSP psel = sel->getOrCreatePixelSelection();
KisPixelSelectionSP psel = sel->pixelSelection();
psel->select(rc, selectedness);
sel->updateProjection(rc);
}
......@@ -321,7 +321,7 @@ QImage KisMask::createThumbnail(qint32 w, qint32 h)
void KisMask::testingInitSelection(const QRect &rect)
{
m_d->selection = new KisSelection();
m_d->selection->getOrCreatePixelSelection()->select(rect, OPACITY_OPAQUE_U8);
m_d->selection->pixelSelection()->select(rect, OPACITY_OPAQUE_U8);
m_d->selection->updateProjection(rect);
m_d->selection->setParentNode(this);
}
......
......@@ -165,11 +165,6 @@ void KisSelection::setShapeSelection(KisSelectionComponent* shapeSelection)
m_d->shapeSelection = shapeSelection;
}
KisPixelSelectionSP KisSelection::getOrCreatePixelSelection()
{
return m_d->pixelSelection;
}
KisPaintDeviceSP KisSelection::projection() const
{
return m_d->pixelSelection;
......
......@@ -96,8 +96,16 @@ public:
void recalculateOutlineCache();
/**
* return the pixel selection component of this selection or zero
* if hasPixelSelection() returns false.
* return the pixel selection component of this selection. Pixel
* selection component is always present in the selection. In case
* the user wants a vector selection, pixel selection will store
* the pixelated version of it.
*
* NOTE: use pixelSelection() for changing the selection only. For
* reading the selection and passing the data to bitBlt fuction use
* projection(). Although projection() and pixelSelection() currently
* point ot the same paint device, this behavior may change in the
* future.
*/
KisPixelSelectionSP pixelSelection() const;
......@@ -109,13 +117,6 @@ public:
void setShapeSelection(KisSelectionComponent* shapeSelection);
/**
* Return the pixel selection associated with this selection or
* create a new one if there is currently no pixel selection
* component in this selection.
*/
KisPixelSelectionSP getOrCreatePixelSelection();
/**
* Returns the projection of the selection. It may be the same
* as pixel selection. You must read selection data from this
......
......@@ -81,7 +81,7 @@ KisSelectionBasedLayer::~KisSelectionBasedLayer()
void KisSelectionBasedLayer::initSelection()
{
m_d->selection = new KisSelection();
m_d->selection->getOrCreatePixelSelection()->select(image()->bounds());
m_d->selection->pixelSelection()->select(image()->bounds());
m_d->selection->setParentNode(this);
m_d->selection->updateProjection();
}
......@@ -104,7 +104,7 @@ KisPaintDeviceSP KisSelectionBasedLayer::original() const
}
KisPaintDeviceSP KisSelectionBasedLayer::paintDevice() const
{
return m_d->selection->getOrCreatePixelSelection();
return m_d->selection->pixelSelection();
}
......@@ -131,7 +131,7 @@ void KisSelectionBasedLayer::copyOriginalToProjection(const KisPaintDeviceSP ori
*/
tempSelection = new KisSelection(*tempSelection);
KisPainter gc2(tempSelection->getOrCreatePixelSelection());
KisPainter gc2(tempSelection->pixelSelection());
gc2.setOpacity(temporaryOpacity());
gc2.setCompositeOp(temporaryCompositeOp());
gc2.bitBlt(rect.topLeft(), temporaryTarget(), rect);
......
......@@ -78,7 +78,7 @@ void KisSelectionMask::setSelection(KisSelectionSP selection)
KisMask::setSelection(new KisSelection());
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->alpha8();
KisFillPainter gc(KisPaintDeviceSP(this->selection()->getOrCreatePixelSelection().data()));
KisFillPainter gc(KisPaintDeviceSP(this->selection()->pixelSelection().data()));
gc.fillRect(image()->bounds(), KoColor(Qt::white, cs), MAX_SELECTED);
gc.end();
}
......
......@@ -167,7 +167,7 @@ private:
void transformMask(KisMask* mask) {
KisSelectionSP selection = mask->selection();
if(selection->hasPixelSelection() && !m_scaleOnlyShapes) {
KisPixelSelectionSP pixelSelection = selection->getOrCreatePixelSelection().data();
KisPixelSelectionSP pixelSelection = selection->pixelSelection().data();
KisSelectionTransaction transaction(QString(), pixelSelection);
KisTransformWorker tw(pixelSelection, m_sx, m_sy, 0.0, 0.0, 0.0, 0.0, m_angle, m_tx, m_ty, m_progress, m_filter);
......
......@@ -45,7 +45,7 @@ void KisAdjustmentLayerTest::testCreation()
KisFilterConfiguration * kfc = f->defaultConfiguration(0);
Q_ASSERT(kfc);
KisAdjustmentLayer test(image, "test", kfc, 0);
KisAdjustmentLayerSP test = new KisAdjustmentLayer(image, "test", kfc, 0);
}
void KisAdjustmentLayerTest::testSetSelection()
......@@ -57,7 +57,7 @@ void KisAdjustmentLayerTest::testSetSelection()
Q_ASSERT(f);
KisFilterConfiguration * kfc = f->defaultConfiguration(0);
Q_ASSERT(kfc);
sel->getOrCreatePixelSelection()->select(QRect(10, 10, 200, 200), 128);
sel->pixelSelection()->select(QRect(10, 10, 200, 200), 128);
KisAdjustmentLayerSP l1 = new KisAdjustmentLayer(image, "bla", kfc, sel);
QCOMPARE(sel->selectedExactRect(), l1->internalSelection()->selectedExactRect());
}
......@@ -72,12 +72,12 @@ void KisAdjustmentLayerTest::testInverted()
Q_ASSERT(kfc);
KisSelectionSP sel2 = new KisSelection();
sel2->getOrCreatePixelSelection()->invert();
sel2->pixelSelection()->invert();
KisAdjustmentLayerSP l2 = new KisAdjustmentLayer(image, "bla", kfc, sel2);
QCOMPARE(sel2->selectedExactRect(), l2->internalSelection()->selectedExactRect());
KisSelectionSP sel3 = new KisSelection();
sel3->getOrCreatePixelSelection()->select(QRect(50, -10, 800, 30), 128);
sel3->pixelSelection()->select(QRect(50, -10, 800, 30), 128);
l2->setInternalSelection(sel3);
}
......
......@@ -118,7 +118,7 @@ void KisFilterTest::testDifferentSrcAndDst()
KisPaintDeviceSP src = new KisPaintDevice(cs);
KisPaintDeviceSP dst = new KisPaintDevice(cs);
KisSelectionSP sel = new KisSelection(new KisSelectionDefaultBounds(src));
sel->getOrCreatePixelSelection()->invert(); // select everything
sel->pixelSelection()->invert(); // select everything
sel->updateProjection();
src->convertFromQImage(qimage, 0, 0, 0);
......
......@@ -48,34 +48,36 @@ public:
};
typedef KisSharedPtr<TestMask> TestMaskSP;
void KisMaskTest::testCreation()
{
TestUtil::MaskParent p;
TestMask mask;
mask.initSelection(p.layer);
TestMaskSP mask = new TestMask;
mask->initSelection(p.layer);
QCOMPARE(mask.extent(), QRect(0,0,512,512));
QCOMPARE(mask.exactBounds(), QRect(0,0,512,512));
QCOMPARE(mask->extent(), QRect(0,0,512,512));
QCOMPARE(mask->exactBounds(), QRect(0,0,512,512));
}
void KisMaskTest::testSelection()
{
TestUtil::MaskParent p;
TestMask mask;
TestMaskSP mask = new TestMask;
KisSelectionSP sel = new KisSelection();
sel->getOrCreatePixelSelection()->select(QRect(0,0,100,100), MAX_SELECTED);
sel->pixelSelection()->select(QRect(0,0,100,100), MAX_SELECTED);
mask.initSelection(sel, p.layer);
mask->initSelection(sel, p.layer);
QCOMPARE(mask.extent(), QRect(0,0,128,128));
QCOMPARE(mask.exactBounds(), QRect(0,0,100,100));
QCOMPARE(mask->extent(), QRect(0,0,128,128));
QCOMPARE(mask->exactBounds(), QRect(0,0,100,100));
mask.select(QRect(0,0,500,500), MAX_SELECTED);;
mask->select(QRect(0,0,500,500), MAX_SELECTED);;
QCOMPARE(mask.extent(), QRect(0,0,512,512));
QCOMPARE(mask.exactBounds(), QRect(0,0,500,500));
QCOMPARE(mask->extent(), QRect(0,0,512,512));
QCOMPARE(mask->exactBounds(), QRect(0,0,500,500));
}
void KisMaskTest::testCropUpdateBySelection()
......@@ -89,14 +91,14 @@ void KisMaskTest::testCropUpdateBySelection()
QRect selectionRect(10, 10, 20, 20);
QRect updateRect(64, 64, 20, 20);
TestMask mask;
TestMaskSP mask = new TestMask;
KisSelectionSP sel = new KisSelection();
sel->getOrCreatePixelSelection()->select(selectionRect, MAX_SELECTED);
sel->pixelSelection()->select(selectionRect, MAX_SELECTED);
mask.initSelection(sel, p.layer);
mask->initSelection(sel, p.layer);
mask.apply(p.layer->projection(), updateRect);
mask->apply(p.layer->projection(), updateRect);
// Here we crash! :)
/**
......
......@@ -52,7 +52,7 @@ void KisPaintLayerTest::testProjection()
KisTransparencyMaskSP transparencyMask = new KisTransparencyMask();
transparencyMask->initSelection(layer);
transparencyMask->selection()->getOrCreatePixelSelection()->invert();
transparencyMask->selection()->pixelSelection()->invert();
image->addNode(transparencyMask.data(), layer.data());
// Now there are masks. Verify that
......
......@@ -133,7 +133,7 @@ void KisPainterTest::testPaintDeviceBltSelection(const KoColorSpace * cs)
QCOMPARE(src->exactBounds(), QRect(0, 0, 20, 20));
KisSelectionSP selection = new KisSelection();
selection->getOrCreatePixelSelection()->select(QRect(10, 10, 20, 20));
selection->pixelSelection()->select(QRect(10, 10, 20, 20));
selection->updateProjection();
QCOMPARE(selection->selectedExactRect(), QRect(10, 10, 20, 20));
......@@ -180,7 +180,7 @@ void KisPainterTest::testPaintDeviceBltSelectionIrregular(const KoColorSpace * c
KisSelectionSP sel = new KisSelection();
KisPixelSelectionSP psel = sel->getOrCreatePixelSelection();
KisPixelSelectionSP psel = sel->pixelSelection();
psel->select(QRect(10, 15, 20, 15));
psel->select(QRect(15, 10, 15, 5));
......@@ -226,7 +226,7 @@ void KisPainterTest::testPaintDeviceBltSelectionInverted(const KoColorSpace * cs
QCOMPARE(src->exactBounds(), QRect(0, 0, 30, 30));
KisSelectionSP sel = new KisSelection();
KisPixelSelectionSP psel = sel->getOrCreatePixelSelection();
KisPixelSelectionSP psel = sel->pixelSelection();
psel->select(QRect(10, 10, 20, 20));
psel->invert();
sel->updateProjection();
......@@ -252,7 +252,7 @@ void KisPainterTest::testSelectionBltSelection()
KisSelectionSP sel = new KisSelection();
KisPixelSelectionSP Selection = sel->getOrCreatePixelSelection();
KisPixelSelectionSP Selection = sel->pixelSelection();
Selection->select(QRect(10, 10, 20, 20));
QCOMPARE(Selection->selectedExactRect(), QRect(10, 10, 20, 20));
......@@ -301,7 +301,7 @@ void KisPainterTest::testSelectionBltSelectionIrregular()
KisSelectionSP sel = new KisSelection();
KisPixelSelectionSP Selection = sel->getOrCreatePixelSelection();
KisPixelSelectionSP Selection = sel->pixelSelection();
Selection->select(QRect(10, 15, 20, 15));
Selection->select(QRect(15, 10, 15, 5));
QCOMPARE(Selection->selectedExactRect(), QRect(10, 10, 20, 20));
......@@ -384,7 +384,7 @@ void KisPainterTest::testSelectionBitBltEraseCompositeOp()
src->fill(50, 50, 50, 50, c2.data());
KisSelectionSP sel = new KisSelection();
KisPixelSelectionSP selection = sel->getOrCreatePixelSelection();
KisPixelSelectionSP selection = sel->pixelSelection();
selection->select(QRect(25, 25, 100, 100));
sel->updateProjection();
......@@ -429,7 +429,7 @@ void KisPainterTest::checkPerformance()
quint8 p = 128;
src->fill(0, 0, 10000, 5000, &p);
KisSelectionSP sel = new KisSelection();
sel->getOrCreatePixelSelection()->select(QRect(0, 0, 10000, 5000), 128);
sel->pixelSelection()->select(QRect(0, 0, 10000, 5000), 128);
sel->updateProjection();
QTime t;
......
......@@ -85,7 +85,7 @@ void KisPixelSelectionTest::testInvertWithImage()
KisImageSP image = new KisImage(0, 200, 200, cs, "merge test");
KisSetEmptyGlobalSelectionCommand(image).redo();
KisPixelSelectionSP selection = image->globalSelection()->getOrCreatePixelSelection();
KisPixelSelectionSP selection = image->globalSelection()->pixelSelection();
selection->select(QRect(5, 5, 10, 10));
selection->invert();
QCOMPARE(selection->selectedExactRect(), QRect(0, 0, 200, 200));
......@@ -198,7 +198,7 @@ void KisPixelSelectionTest::testExactRectWithImage()
KisImageSP image = new KisImage(0, 200, 200, cs, "merge test");
KisSetEmptyGlobalSelectionCommand(image).redo();
KisPixelSelectionSP selection = image->globalSelection()->getOrCreatePixelSelection();
KisPixelSelectionSP selection = image->globalSelection()->pixelSelection();
selection->select(QRect(100, 50, 200, 100));
QCOMPARE(selection->selectedExactRect(), QRect(100, 50, 200, 100));
}
......
......@@ -122,15 +122,12 @@ void KisSelectionTest::testGrayColorspaceOverComposition()
void KisSelectionTest::testSelectionComponents()
{
KisSelectionSP selection = new KisSelection();
QCOMPARE(selection->hasPixelSelection(), false);
QCOMPARE(selection->hasShapeSelection(), false);
QCOMPARE(selection->shapeSelection(), (void*)0);
KisPixelSelectionSP pixelSelection = selection->getOrCreatePixelSelection();
QCOMPARE(selection->pixelSelection(), pixelSelection);
QCOMPARE(selection->hasPixelSelection(), true);
pixelSelection->select(QRect(10,10,10,10));
selection->pixelSelection()->select(QRect(10,10,10,10));
QCOMPARE(selection->hasPixelSelection(), true);
QCOMPARE(selection->selectedExactRect(), QRect(10,10,10,10));
}
......@@ -141,7 +138,7 @@ void KisSelectionTest::testSelectionActions()
QVERIFY(selection->hasPixelSelection() == false);
QVERIFY(selection->hasShapeSelection() == false);
KisPixelSelectionSP pixelSelection = selection->getOrCreatePixelSelection();
KisPixelSelectionSP pixelSelection = selection->pixelSelection();
pixelSelection->select(QRect(0, 0, 20, 20));
KisPixelSelectionSP tmpSel = new KisPixelSelection();
......@@ -172,7 +169,7 @@ void KisSelectionTest::testInvertSelection()
KisImageSP image = new KisImage(0, 1024, 1024, cs, "stest");
KisSelectionSP selection = new KisSelection(new KisDefaultBounds(image));
KisPixelSelectionSP pixelSelection = selection->getOrCreatePixelSelection();
KisPixelSelectionSP pixelSelection = selection->pixelSelection();
pixelSelection->select(QRect(20, 20, 20, 20));
QCOMPARE(TestUtil::alphaDevicePixel(pixelSelection, 30, 30), MAX_SELECTED);
......@@ -207,7 +204,7 @@ void KisSelectionTest::testInvertSelectionSemi()
KisImageSP image = new KisImage(0, 1024, 1024, cs, "stest");
KisSelectionSP selection = new KisSelection(new KisDefaultBounds(image));
KisPixelSelectionSP pixelSelection = selection->getOrCreatePixelSelection();
KisPixelSelectionSP pixelSelection = selection->pixelSelection();
quint8 selectedness = 42;
pixelSelection->select(QRect(20, 20, 20, 20), selectedness);
......@@ -235,7 +232,7 @@ void KisSelectionTest::testInvertSelectionSemi()
void KisSelectionTest::testCopy()
{
KisSelectionSP sel = new KisSelection();
sel->getOrCreatePixelSelection()->select(QRect(10, 10, 200, 200), 128);
sel->pixelSelection()->select(QRect(10, 10, 200, 200), 128);
sel->updateProjection();
......@@ -281,7 +278,7 @@ void KisSelectionTest::testSetParentNodeAfterCreation()
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisImageSP image = new KisImage(0, 100, 100, cs, "stest");
KisSelectionSP selection = new KisSelection();
KisPixelSelectionSP pixelSelection = selection->getOrCreatePixelSelection();
KisPixelSelectionSP pixelSelection = selection->pixelSelection();
QCOMPARE(selection->parentNode(), KisNodeSP(0));
QCOMPARE(selection->pixelSelection()->parentNode(), KisNodeWSP(0));
......@@ -300,7 +297,7 @@ void KisSelectionTest::testSetParentNodeBeforeCreation()
selection->setParentNode(image->root());
KisPixelSelectionSP pixelSelection = selection->getOrCreatePixelSelection();
KisPixelSelectionSP pixelSelection = selection->pixelSelection();
QCOMPARE(selection->parentNode(), KisNodeSP(image->root()));
QCOMPARE(selection->pixelSelection()->parentNode(), KisNodeWSP(image->root()));
......
......@@ -83,7 +83,7 @@ void KisTransparencyMaskTest::testApply()
// Invert the mask, so that nothing will be selected, then select a rect
initImage(image, layer, dev, mask);
mask->initSelection(layer);
mask->selection()->getOrCreatePixelSelection()->invert();
mask->selection()->pixelSelection()->invert();
mask->apply(dev, QRect(0, 0, 200, 100));
qimage = dev->convertToQImage(0, 0, 0, 200, 100);
......@@ -95,7 +95,7 @@ void KisTransparencyMaskTest::testApply()
initImage(image, layer, dev, mask);
mask->initSelection(layer);
mask->selection()->getOrCreatePixelSelection()->invert();
mask->selection()->pixelSelection()->invert();
mask->select(QRect(50, 0, 100, 100));
mask->apply(dev, QRect(0, 0, 200, 100));
qimage = dev->convertToQImage(0, 0, 0, 200, 100);
......@@ -121,7 +121,7 @@ void KisTransparencyMaskTest::testMoveParentLayer()
initImage(image, layer, dev, mask);
mask->initSelection(layer);
mask->selection()->getOrCreatePixelSelection()->invert();
mask->selection()->pixelSelection()->invert();
mask->select(QRect(50, 50, 100, 100));
KisFullRefreshWalker walker(image->bounds());
......
......@@ -271,7 +271,7 @@ void DlgColorRange::slotSelectClicked()
KisSelectionSP selection = new KisSelection(new KisSelectionDefaultBounds(m_view->activeDevice(), m_view->image()));
KisHLineConstIteratorSP hiter = m_view->activeDevice()->createHLineConstIteratorNG(x, y, w);
KisHLineIteratorSP selIter = selection->getOrCreatePixelSelection()->createHLineIteratorNG(x, y, w);
KisHLineIteratorSP selIter = selection->pixelSelection()->createHLineIteratorNG(x, y, w);
QColor c;
for (int row = y; row < h - y; ++row) {
do {
......
......@@ -178,7 +178,7 @@ void ImageSize::slotSelectionScale()
QPointer<KoUpdater> u = pu->startSubtask();
if (dlgSize->exec() == QDialog::Accepted) {
KisPixelSelectionSP pixelSelection = selection->getOrCreatePixelSelection().data();
KisPixelSelectionSP pixelSelection = selection->pixelSelection().data();
KisSelectionTransaction transaction(i18n("Scale Selection"), pixelSelection);
qint32 w = dlgSize->width();
......
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