Fix edit detection for formats not supporting edit

In the buggy implementation, cropped always returned True in case the
current rect was empty due to the format not supporting editing.
This commit is contained in:
karlch 2023-07-13 18:53:59 +02:00
parent 39f7be230a
commit 5e10abf0ad
4 changed files with 32 additions and 0 deletions

View File

@ -173,6 +173,13 @@ def start_vector_graphic(svg):
start([svg])
@bdd.given("I open an image and an animated gif")
def start_image_and_animated_gif(tmp_path, gif):
imagename = str(tmp_path / "image.png")
create_image(imagename)
start([imagename, gif])
@bdd.given("I open images from multiple directories")
def start_multiple_directories(tmp_path):
dir1 = tmp_path / "dir1"

View File

@ -8,6 +8,19 @@ import pytest
import pytest_bdd as bdd
from vimiv.parser import geometry
from vimiv.imutils import _ImageFileHandler
@pytest.fixture()
def file_handler():
"""Fixture to retrieve the current instance of the edit handler."""
return _ImageFileHandler.instance
@pytest.fixture()
def edit_handler(file_handler):
"""Fixture to retrieve the current instance of the edit handler."""
return file_handler._edit_handler
@bdd.then(bdd.parsers.parse("the image size should be {size}"))
@ -25,3 +38,8 @@ def ensure_size_not(size, image):
width_neq = expected.width() != image_rect.width()
height_neq = expected.height() != image_rect.height()
assert width_neq or height_neq
@bdd.then("the image should not be edited")
def ensure_not_edited(edit_handler):
assert not edit_handler.changed

View File

@ -41,3 +41,8 @@ Feature: Crop an image.
| 10 | -100 | 150x100+85+0 |
# Ignored as dx/dy are outside of the image
| 1000 | 1000 | 150x100+75+50 |
Scenario: Crop does not automatically consider a gif edited
Given I open an image and an animated gif
When I run next
Then the image should not be edited

View File

@ -188,6 +188,8 @@ class Transform(QTransform):
@property
def changed(self):
"""True if transformations have been applied."""
if self.current.rect().isNull():
return False
transformed = not self.isIdentity()
if self._original is None:
return transformed