Fix issue with delete.
This commit is contained in:
parent
fe5fcdce3e
commit
fbccb7206d
|
@ -80,6 +80,7 @@
|
||||||
#include "../vtools/undocommands/image/deletebackgroundimage.h"
|
#include "../vtools/undocommands/image/deletebackgroundimage.h"
|
||||||
#include "../ifc/xml/utils.h"
|
#include "../ifc/xml/utils.h"
|
||||||
#include "dialogs/vwidgetbackgroundimages.h"
|
#include "dialogs/vwidgetbackgroundimages.h"
|
||||||
|
#include "../ifc/xml/vbackgroundpatternimage.h"
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
|
||||||
#include "../vmisc/backport/qscopeguard.h"
|
#include "../vmisc/backport/qscopeguard.h"
|
||||||
|
@ -2385,20 +2386,9 @@ void MainWindow::NewBackgroundImageItem(const VBackgroundPatternImage &image)
|
||||||
if (item != nullptr)
|
if (item != nullptr)
|
||||||
{
|
{
|
||||||
item->SetImage(image);
|
item->SetImage(image);
|
||||||
|
item->setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_deletedBackgroundImageItems.contains(image.Id()))
|
|
||||||
{
|
|
||||||
VBackgroundImageItem *item = m_deletedBackgroundImageItems.value(image.Id());
|
|
||||||
if (item != nullptr)
|
|
||||||
{
|
|
||||||
item->SetImage(image);
|
|
||||||
sceneDraw->addItem(item);
|
|
||||||
m_backgroundImages.insert(image.Id(), item);
|
|
||||||
}
|
|
||||||
m_deletedBackgroundImageItems.remove(image.Id());
|
|
||||||
m_deletedBackgroundImages.remove(image.Id());
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VBackgroundImageItem *item = InitBackgroundImageItem(image);
|
VBackgroundImageItem *item = InitBackgroundImageItem(image);
|
||||||
|
@ -4363,14 +4353,11 @@ void MainWindow::DeleteBackgroundImageItem(const QUuid &id)
|
||||||
{
|
{
|
||||||
VBackgroundImageItem *item = m_backgroundImages.value(id);
|
VBackgroundImageItem *item = m_backgroundImages.value(id);
|
||||||
emit ui->view->itemClicked(nullptr); // Hide visualization to avoid a crash
|
emit ui->view->itemClicked(nullptr); // Hide visualization to avoid a crash
|
||||||
sceneDraw->removeItem(item);
|
item->setVisible(false); // Do not remove the item from scene to prevent crashes.
|
||||||
if (m_backgroudcontrols != nullptr && m_backgroudcontrols->Id() == id)
|
if (m_backgroudcontrols != nullptr && m_backgroudcontrols->Id() == id)
|
||||||
{
|
{
|
||||||
m_backgroudcontrols->ActivateControls(QUuid());
|
m_backgroudcontrols->ActivateControls(QUuid());
|
||||||
}
|
}
|
||||||
m_backgroundImages.remove(id);
|
|
||||||
m_deletedBackgroundImageItems.insert(id, item);
|
|
||||||
m_deletedBackgroundImages.insert(id, item->Image());
|
|
||||||
|
|
||||||
if (backgroundImagesWidget != nullptr)
|
if (backgroundImagesWidget != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -4451,24 +4438,6 @@ void MainWindow::ParseBackgroundImages()
|
||||||
NewBackgroundImageItem(image);
|
NewBackgroundImageItem(image);
|
||||||
}
|
}
|
||||||
backgroundImagesWidget->UpdateImages();
|
backgroundImagesWidget->UpdateImages();
|
||||||
|
|
||||||
// Undostack rely on m_deletedBackgroundImageItems to prevent crashes
|
|
||||||
QMap<QUuid, VBackgroundImageItem *> deletedBackgroundImageItems;
|
|
||||||
QMap<QUuid, VBackgroundImageItem *>::const_iterator i;
|
|
||||||
for (i = m_deletedBackgroundImageItems.constBegin(); i != m_deletedBackgroundImageItems.constEnd(); ++i)
|
|
||||||
{
|
|
||||||
if (m_deletedBackgroundImages.contains(i.key()))
|
|
||||||
{
|
|
||||||
VBackgroundPatternImage image = m_deletedBackgroundImages.value(i.key());
|
|
||||||
VBackgroundImageItem *item = InitBackgroundImageItem(image);
|
|
||||||
if (item != nullptr)
|
|
||||||
{
|
|
||||||
deletedBackgroundImageItems.insert(image.Id(), item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_deletedBackgroundImageItems = deletedBackgroundImageItems;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -5622,8 +5591,6 @@ MainWindow::~MainWindow()
|
||||||
|
|
||||||
delete doc;
|
delete doc;
|
||||||
delete ui;
|
delete ui;
|
||||||
|
|
||||||
qDeleteAll(m_deletedBackgroundImageItems);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -5884,7 +5851,6 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
|
||||||
/* Collect garbage only after successfully parse. This way wrongly accused items have one more time to restore
|
/* Collect garbage only after successfully parse. This way wrongly accused items have one more time to restore
|
||||||
* a reference. */
|
* a reference. */
|
||||||
QTimer::singleShot(100, Qt::CoarseTimer, this, [this](){doc->GarbageCollector(true);});
|
QTimer::singleShot(100, Qt::CoarseTimer, this, [this](){doc->GarbageCollector(true);});
|
||||||
QTimer::singleShot(500, Qt::CoarseTimer, this, &MainWindow::ParseBackgroundImages);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
patternReadOnly = doc->IsReadOnly();
|
patternReadOnly = doc->IsReadOnly();
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
#include "core/vcmdexport.h"
|
#include "core/vcmdexport.h"
|
||||||
#include "../vmisc/vlockguard.h"
|
#include "../vmisc/vlockguard.h"
|
||||||
#include "../vformat/vdimensions.h"
|
#include "../vformat/vdimensions.h"
|
||||||
#include "../ifc/xml/vbackgroundpatternimage.h"
|
|
||||||
|
|
||||||
#include <QDoubleSpinBox>
|
#include <QDoubleSpinBox>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
@ -325,9 +324,7 @@ private:
|
||||||
QTimer *m_gradation;
|
QTimer *m_gradation;
|
||||||
|
|
||||||
QMap<QUuid, VBackgroundImageItem *> m_backgroundImages{};
|
QMap<QUuid, VBackgroundImageItem *> m_backgroundImages{};
|
||||||
QMap<QUuid, VBackgroundImageItem *> m_deletedBackgroundImageItems{};
|
|
||||||
VBackgroundImageControls* m_backgroudcontrols{nullptr};
|
VBackgroundImageControls* m_backgroudcontrols{nullptr};
|
||||||
QMap<QUuid, VBackgroundPatternImage> m_deletedBackgroundImages{};
|
|
||||||
|
|
||||||
bool m_groupsActive{false};
|
bool m_groupsActive{false};
|
||||||
bool m_toolOptionsActive{false};
|
bool m_toolOptionsActive{false};
|
||||||
|
|
|
@ -541,7 +541,7 @@ void VBackgroundImageItem::keyReleaseEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
if (ConfirmDeletion() == QMessageBox::Yes)
|
if (ConfirmDeletion() == QMessageBox::Yes)
|
||||||
{
|
{
|
||||||
DeleteToolWithConfirm(false);
|
DeleteToolWithConfirm();
|
||||||
event->accept();
|
event->accept();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user