Skip to content

Commit

Permalink
fix: undo does not remove images anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Onetchou committed Apr 10, 2024
1 parent 8a71e72 commit 96fa6ed
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
19 changes: 18 additions & 1 deletion src/app/seamly2d/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,6 @@ void MainWindow::handleImportImage()
ui->importImage_ToolButton->setChecked(false);
return;
}
image.id = VContainer::getNextId();
image.name = f.baseName();
image.filename = filename;
image.units = qApp->patternUnit();
Expand All @@ -1667,6 +1666,8 @@ void MainWindow::addImage(DraftImage image)
static bool firstImportImage = false;
QImageReader imageReader(image.filename);

image.id = VContainer::getNextId();

if(!imageReader.canRead())
{
qCDebug(vMainWindow, "Can't read image");
Expand All @@ -1683,6 +1684,14 @@ void MainWindow::addImage(DraftImage image)
return;
}

if (image.width == 0 || image.height == 0)
{
image.width = image.pixmap.width();
image.height = image.pixmap.height();
image.xScale = 100;
image.yScale = 100;
}

ImageItem *item = new ImageItem(image);
m_ImageMap.insert(image.id, item);
draftScene->addItem(item);
Expand Down Expand Up @@ -4421,6 +4430,12 @@ void MainWindow::fullParseFile()
{
qCDebug(vMainWindow, "Full parsing file");

QList<DraftImage> allImages;
foreach (ImageItem *item, m_ImageMap.values()) {allImages.append(item->getImage());}
//we must wait until all the DraftImages are saved before deleting the images
//because deleting an image change the z order of the other
foreach (ImageItem *item, m_ImageMap.values()) {handleDeleteImage(item->getImage().id);}

toolProperties->clearPropertyBrowser();
try
{
Expand Down Expand Up @@ -4549,6 +4564,8 @@ void MainWindow::fullParseFile()

VMainGraphicsView::NewSceneRect(draftScene, qApp->getSceneView());
VMainGraphicsView::NewSceneRect(pieceScene, qApp->getSceneView());

foreach (DraftImage image, allImages) {addImage(image);}
}

//---------------------------------------------------------------------------------------------------------------------
Expand Down
36 changes: 20 additions & 16 deletions src/libs/tools/image_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,37 @@ ImageItem::ImageItem(DraftImage image, QGraphicsItem *parent)
, m_isHovered(false)
, m_selectionType(SelectionType::ByMouseRelease)
, m_transformationMode(Qt::SmoothTransformation)
, m_hasShape(false)
, m_image(image)
, m_pixmapWidth()
, m_pixmapHeight()
, m_selectable(true)
{
initializeItem();
setPixmap(m_image.pixmap);

m_boundingRect = QRectF(m_image.xPos, m_image.yPos, m_image.xPos + m_image.width, m_image.yPos + m_image.height);
m_handleRect = m_boundingRect.adjusted(HANDLE_SIZE/2, HANDLE_SIZE/2, -HANDLE_SIZE/2, -HANDLE_SIZE/2);

allImageItems.append(this);

if (m_image.order == 0)
{
qreal minZValue = maxImageZvalue+1;
foreach (ImageItem *item, allImageItems)
{
minZValue = qMin(minZValue, item->m_image.order);
}
m_image.order = minZValue-1;
moveToTop();
}

updateImage();

m_resizeHandles = new ResizeHandlesItem(this);
m_resizeHandles->setLockAspectRatio(m_image.aspectLocked);
m_resizeHandles->setParentRotation(m_image.rotation);
m_resizeHandles->hide();
connect(m_resizeHandles, &ResizeHandlesItem::sizeChanged, this, &ImageItem::updateFromHandles);
connect(m_resizeHandles, &ResizeHandlesItem::setStatusMessage, this, [this](QString message) {emit setStatusMessage(message);});

qreal minZValue = maxImageZvalue+1;
foreach (ImageItem *item, allImageItems)
{
minZValue = qMin(minZValue, item->m_image.order);
}
m_image.order = minZValue-1;

allImageItems.append(this);
moveToTop();

updateImage();
}


Expand All @@ -115,13 +119,13 @@ void ImageItem::setPixmap(const QPixmap &pixmap)
prepareGeometryChange();

m_image.pixmap = pixmap;

m_pixmapWidth = pixmap.width();
m_pixmapHeight = pixmap.height();
m_image.width = pixmap.width();
m_image.height = pixmap.height();
m_image.xScale = m_image.width / m_pixmapWidth * 100;
m_image.yScale = m_image.height / m_pixmapHeight * 100;
m_hasShape = false;

m_boundingRect = QRectF(m_image.xPos, m_image.yPos, m_image.xPos + m_pixmapWidth, m_image.yPos + m_pixmapHeight);

Expand Down Expand Up @@ -166,7 +170,7 @@ void ImageItem::setLock(bool checked)
{
setAcceptedMouseButtons(Qt::RightButton);
emit setStatusMessage("");
m_resizeHandles->hide();
if (m_resizeHandles != nullptr) {m_resizeHandles->hide();}
}
else
{
Expand Down
1 change: 0 additions & 1 deletion src/libs/tools/image_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ class ImageItem : public QObject, public QGraphicsItem
bool m_isHovered;
SelectionType m_selectionType;
bool m_transformationMode;
bool m_hasShape;
DraftImage m_image;
qreal m_pixmapWidth;
qreal m_pixmapHeight;
Expand Down

0 comments on commit 96fa6ed

Please sign in to comment.