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 issues in Palette/PaletteView script API
Freya Lupena27b3e803dba
diff --git a/libs/libkis/Palette.cpp b/libs/libkis/Palette.cppindex ac7e0aabe2..bbd526aed5 100644--- a/libs/libkis/Palette.cpp+++ b/libs/libkis/Palette.cpp@@ -91,6 +91,15 @@ int Palette::colorsCountTotal()return d->palette->colorCount();}+int Palette::colorsCountGroup(QString name)+{+ if (!d->palette) return 0;+ KisSwatchGroupSP group = d->palette->getGroup(name);+ if (!group) return 0;+ return group->colorCount();+}++Swatch *Palette::colorSetEntryByIndex(int index){warnScript << "DEPRECATED Palette.colorSetEntryByIndex() - use Palette.entryByIndex() instead";@@ -118,8 +127,8 @@ Swatch *Palette::entryByIndexFromGroup(int index, const QString &groupName)if (!d->palette || columnCount() == 0) {return new Swatch();}- int row = index % columnCount();- return new Swatch(d->palette->getSwatchFromGroup((index - row) / columnCount(), row, groupName));+ int col = index % columnCount();+ return new Swatch(d->palette->getSwatchFromGroup(col, (index - col) / columnCount(), groupName));}void Palette::addEntry(Swatch entry, QString groupName)diff --git a/libs/libkis/Palette.h b/libs/libkis/Palette.hindex 2401a26628..74e9398e59 100644--- a/libs/libkis/Palette.h+++ b/libs/libkis/Palette.h@@ -126,6 +126,13 @@ public Q_SLOTS:*/int colorsCountTotal();+ /**+ * @brief colorsCountGroup+ * @param name of the group to check. Empty is the default group.+ * @return the amount of colors within that group.+ */+ int colorsCountGroup(QString name);+/*** @brief colorSetEntryByIndex* get the colorsetEntry from the global index.diff --git a/libs/libkis/PaletteView.cpp b/libs/libkis/PaletteView.cppindex 54e6ef749d..7140eb1060 100644--- a/libs/libkis/PaletteView.cpp+++ b/libs/libkis/PaletteView.cpp@@ -25,14 +25,13 @@ PaletteView::PaletteView(QWidget *parent)layout->addWidget(d->widget);//forward signals.- connect(d->widget, SIGNAL(entrySelected(KisSwatch)),- this, SLOT(fgSelected(KisSwatch)));- connect(d->widget, SIGNAL(entrySelectedBackGround(KisSwatch)),- this, SLOT(bgSelected(KisSwatch)));+ connect(d->widget, SIGNAL(sigIndexSelected(QModelIndex)),+ this, SLOT(fgSelected(QModelIndex)));}PaletteView::~PaletteView(){+ delete d->widget;delete d->model;}@@ -71,12 +70,8 @@ void PaletteView::trySelectClosestColor(ManagedColor *color)d->widget->selectClosestColor(color->color());}-void PaletteView::fgSelected(KisSwatch swatch)+void PaletteView::fgSelected(QModelIndex index){+ KisSwatch swatch = d->model->getSwatch(index);Q_EMIT entrySelectedForeGround(Swatch(swatch));}--void PaletteView::bgSelected(KisSwatch swatch)-{- Q_EMIT entrySelectedBackGround(Swatch(swatch));-}diff --git a/libs/libkis/PaletteView.h b/libs/libkis/PaletteView.hindex 199907de3e..054c37cccb 100644--- a/libs/libkis/PaletteView.h+++ b/libs/libkis/PaletteView.h@@ -13,7 +13,6 @@#include "libkis.h"#include "Palette.h"#include "ManagedColor.h"-#include "KoColorSet.h"#include <kis_palette_view.h>#include <KisPaletteModel.h>@@ -85,8 +84,7 @@ Q_SIGNALS:private Q_SLOTS:- void fgSelected(KisSwatch swatch);- void bgSelected(KisSwatch swatch);+ void fgSelected(QModelIndex index);private:diff --git a/libs/widgets/KisPaletteModel.cpp b/libs/widgets/KisPaletteModel.cppindex 7b35b5294f..d00e712f77 100644--- a/libs/widgets/KisPaletteModel.cpp+++ b/libs/widgets/KisPaletteModel.cpp@@ -141,6 +141,8 @@ void KisPaletteModel::addSwatch(const KisSwatch &entry, const QString &groupNamevoid KisPaletteModel::removeSwatch(const QModelIndex &index, bool keepColors){+ if (!index.isValid()) { return; }+KisSwatchGroupSP group = m_colorSet->getGroup(index.row());if (!qvariant_cast<bool>(data(index, IsGroupNameRole))) {m_colorSet->removeSwatch(index.column(),diff --git a/plugins/extensions/pykrita/sip/krita/Palette.sip b/plugins/extensions/pykrita/sip/krita/Palette.sipindex 8b4e8b3c27..990bf0697b 100644--- a/plugins/extensions/pykrita/sip/krita/Palette.sip+++ b/plugins/extensions/pykrita/sip/krita/Palette.sip@@ -32,6 +32,7 @@ public Q_SLOTS:void addGroup(QString name);void removeGroup(QString name, bool keepColors);int colorsCountTotal();+ int colorsCountGroup(QString name);Swatch *colorSetEntryByIndex(int index) /Factory/;Swatch *entryByIndex(int index) /Factory/;Swatch *colorSetEntryFromGroup(int index, const QString &groupName) /Factory/;