Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix crash in color palette when the palette is not initialized
Dmitry Kazakov9735e24058ed
diff --git a/libs/ui/KisPaletteEditor.cpp b/libs/ui/KisPaletteEditor.cppindex 5973a5c20e..89b238c8f3 100644--- a/libs/ui/KisPaletteEditor.cpp+++ b/libs/ui/KisPaletteEditor.cpp@@ -353,6 +353,7 @@ void KisPaletteEditor::setEntry(const KoColor &color, const QModelIndex &index)Q_ASSERT(m_d->model);if (!m_d->view) { return; }if (!m_d->view->document()) { return; }+ if (!m_d->model->colorSet()) { return; }KisSwatch c = KisSwatch(color);c.setId(QString::number(m_d->model->colorSet()->colorCount() + 1));c.setName(i18nc("Default name for a color swatch","Color %1", QString::number(m_d->model->colorSet()->colorCount()+1)));@@ -386,6 +387,7 @@ void KisPaletteEditor::modifyEntry(const QModelIndex &index){if (!m_d->view) { return; }if (!m_d->view->document()) { return; }+ if (!m_d->model->colorSet()) { return; }KoDialog dialog;dialog.setCaption(i18nc("@title:dialog", "Add a new Color Swatch"));diff --git a/libs/widgets/KisPaletteModel.cpp b/libs/widgets/KisPaletteModel.cppindex 4df771cb48..e99113af23 100644--- a/libs/widgets/KisPaletteModel.cpp+++ b/libs/widgets/KisPaletteModel.cpp@@ -275,6 +275,8 @@ Qt::DropActions KisPaletteModel::supportedDropActions() constvoid KisPaletteModel::setSwatch(const KisSwatch &entry, const QModelIndex &index){+ KIS_SAFE_ASSERT_RECOVER_RETURN(m_colorSet);+if (m_colorSet->isGroupTitleRow(index.row())) return;Q_ASSERT(index.column() < m_colorSet->columnCount());@@ -466,8 +468,9 @@ void KisPaletteModel::slotExternalPaletteModified(QSharedPointer<KoColorSet> resQModelIndex KisPaletteModel::indexForClosest(const KoColor &compare){- KisSwatchGroup::SwatchInfo info = colorSet()->getClosestSwatchInfo(compare);- return createIndex(indexRowForInfo(info), info.column, colorSet()->getGroup(info.group).data());+ if (!m_colorSet) return {};+ KisSwatchGroup::SwatchInfo info = m_colorSet->getClosestSwatchInfo(compare);+ return createIndex(indexRowForInfo(info), info.column, m_colorSet->getGroup(info.group).data());}int KisPaletteModel::indexRowForInfo(const KisSwatchGroup::SwatchInfo &info)diff --git a/plugins/dockers/palettedocker/palettedocker_dock.cpp b/plugins/dockers/palettedocker/palettedocker_dock.cppindex a2a433b251..db8fec9bd7 100644--- a/plugins/dockers/palettedocker/palettedocker_dock.cpp+++ b/plugins/dockers/palettedocker/palettedocker_dock.cpp@@ -446,12 +446,14 @@ void PaletteDockerDock::setRedoToolTip(const QString &text)void PaletteDockerDock::undo(){+ if (!m_currentColorSet) return;m_currentColorSet->undoStack()->undo();slotUpdateLblPaletteName();}void PaletteDockerDock::redo(){+ if (!m_currentColorSet) return;m_currentColorSet->undoStack()->redo();slotUpdateLblPaletteName();}