Commit 3b37aa3d authored by Tusooa Zhu's avatar Tusooa Zhu 🔼

Make deep clones of palette list when creating snapshots

parent cdf99ef2
......@@ -338,6 +338,7 @@ public:
KisSharedPtr<KisReferenceImagesLayer> referenceImagesLayer;
QList<KoColorSet*> paletteList;
bool ownsPaletteList = false;
KisGridConfig gridConfig;
......@@ -394,7 +395,13 @@ void KisDocument::Private::copyFrom(const Private &rhs, KisDocument *q)
// XXX: the display properties will be shared between different snapshots
assistants = KisPaintingAssistant::cloneAssistantList(rhs.assistants);
globalAssistantsColor = rhs.globalAssistantsColor;
paletteList = rhs.paletteList;
QList<KoColorSet *> newPaletteList;
Q_FOREACH (KoColorSet *palette, rhs.paletteList) {
newPaletteList << new KoColorSet(*palette);
}
q->setPaletteList(newPaletteList, /* emitSignal = */ true);
q->setGridConfig(rhs.gridConfig);
batchMode = rhs.batchMode;
}
......@@ -547,6 +554,10 @@ KisDocument::~KisDocument()
KIS_SAFE_ASSERT_RECOVER_NOOP(!sanityCheckPointer.isValid());
}
if (d->ownsPaletteList) {
qDeleteAll(d->paletteList);
}
delete d;
}
......@@ -795,6 +806,19 @@ KisDocument* KisDocument::lockAndCloneForSaving()
return new KisDocument(*this);
}
KisDocument *KisDocument::lockAndCreateSnapshot()
{
KisDocument *doc = lockAndCloneForSaving();
if (doc) {
// clone palette list
for (KoColorSet *&cs : doc->d->paletteList) {
cs = new KoColorSet(*cs);
}
doc->d->ownsPaletteList = true;
}
return doc;
}
void KisDocument::copyFromDocument(const KisDocument &rhs)
{
d->copyFrom(*(rhs.d), this);
......@@ -1692,9 +1716,15 @@ QList<KoColorSet *> &KisDocument::paletteList()
return d->paletteList;
}
void KisDocument::setPaletteList(const QList<KoColorSet *> &paletteList)
void KisDocument::setPaletteList(const QList<KoColorSet *> &paletteList, bool emitSignal)
{
d->paletteList = paletteList;
if (d->paletteList != paletteList) {
QList<KoColorSet *> oldPaletteList = d->paletteList;
d->paletteList = paletteList;
if (emitSignal) {
emit sigPaletteListChanged(oldPaletteList, paletteList);
}
}
}
const KisGuidesConfig& KisDocument::guidesConfig() const
......
......@@ -360,7 +360,7 @@ public:
void setMirrorAxisConfig(const KisMirrorAxisConfig& config);
QList<KoColorSet *> &paletteList();
void setPaletteList(const QList<KoColorSet *> &paletteList);
void setPaletteList(const QList<KoColorSet *> &paletteList, bool emitSignal = false);
void clearUndoHistory();
......@@ -467,6 +467,12 @@ Q_SIGNALS:
void sigReferenceImagesLayerChanged(KisSharedPtr<KisReferenceImagesLayer> layer);
/**
* Emitted when the palette list has changed.
* The pointers in oldPaletteList are to be deleted by the resource server.
**/
void sigPaletteListChanged(const QList<KoColorSet *> &oldPaletteList, const QList<KoColorSet *> &newPaletteList);
private Q_SLOTS:
void finishExportInBackground();
void slotChildCompletedSavingInBackground(KisImportExportErrorCode status, const QString &errorMessage);
......@@ -644,7 +650,6 @@ private Q_SLOTS:
void slotConfigChanged();
public:
/**
* @brief try to clone the image. This method handles all the locking for you. If locking
* has failed, no cloning happens
......@@ -652,6 +657,10 @@ public:
*/
KisDocument *lockAndCloneForSaving();
public:
KisDocument *lockAndCreateSnapshot();
void copyFromDocument(const KisDocument &rhs);
private:
......
......@@ -203,6 +203,7 @@ void PaletteDockerDock::setCanvas(KoCanvasBase *canvas)
}
if (m_activeDocument) {
m_activeDocument->disconnect(this);
for (KoColorSet * &cs : m_activeDocument->paletteList()) {
KoColorSet *tmpAddr = cs;
cs = new KoColorSet(*cs);
......@@ -217,6 +218,7 @@ void PaletteDockerDock::setCanvas(KoCanvasBase *canvas)
for (KoColorSet *cs : m_activeDocument->paletteList()) {
m_rServer->addResource(cs);
}
connect(m_activeDocument, &KisDocument::sigPaletteListChanged, this, &PaletteDockerDock::slotUpdatePaletteList);
}
if (!m_currentColorSet) {
......@@ -382,3 +384,18 @@ void PaletteDockerDock::slotNameListSelection(const KoColor &color)
m_resourceProvider->setFGColor(color);
m_colorSelfUpdate = false;
}
void PaletteDockerDock::slotUpdatePaletteList(const QList<KoColorSet *> &oldPaletteList, const QList<KoColorSet *> &newPaletteList)
{
for (KoColorSet *cs : oldPaletteList) {
m_rServer->removeResourceFromServer(cs);
}
for (KoColorSet *cs : newPaletteList) {
m_rServer->addResource(cs);
}
if (!m_currentColorSet) {
slotSetColorSet(0);
}
}
......@@ -83,6 +83,7 @@ private Q_SLOTS:
void loadFromWorkspace(KisWorkspaceResource* workspace);
void slotFGColorResourceChanged(const KoColor& color);
void slotUpdatePaletteList(const QList<KoColorSet *> &oldPaletteList, const QList<KoColorSet *> &newPaletteList);
private:
void setEntryByForeground(const QModelIndex &index);
......
......@@ -163,7 +163,7 @@ void KisSnapshotModel::setCanvas(QPointer<KisCanvas2> canvas)
bool KisSnapshotModel::slotCreateSnapshot()
{
QPointer<KisDocument> clonedDoc(m_d->curDocument()->lockAndCloneForSaving());
QPointer<KisDocument> clonedDoc(m_d->curDocument()->lockAndCreateSnapshot());
if (clonedDoc) {
beginInsertRows(QModelIndex(), m_d->curDocList.size(), m_d->curDocList.size());
m_d->curDocList << qMakePair(i18n("Snapshot"), clonedDoc);
......
......@@ -30,6 +30,7 @@ KisSnapshotView::KisSnapshotView()
: QListView()
, m_d(new Private)
{
setEditTriggers(QAbstractItemView::SelectedClicked);
}
KisSnapshotView::~KisSnapshotView()
......
......@@ -63,8 +63,6 @@ SnapshotDocker::SnapshotDocker()
{
QWidget *widget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout(widget);
//connect(m_d->view, &QListView::activated, m_d->model.data(), &KisSnapshotModel::slotSwitchToActivatedSnapshot);
connect(m_d->view, &KisSnapshotView::doubleClicked, m_d->view, QOverload<const QModelIndex &>::of(&KisSnapshotView::edit));
m_d->view->setModel(m_d->model.data());
mainLayout->addWidget(m_d->view);
......
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