Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSwatchGroup Class Reference

The KisSwatchGroup class stores a matrix of color swatches swatches can accessed using (x, y) coordinates. x is the column number from left to right and y is the row number from top to bottom. Both x and y start at 0 there could be empty entries, so the checkEntry(int, int) method must used whenever you want to get an entry from the matrix. More...

#include <KisSwatchGroup.h>

Classes

struct  Private
 

Public Member Functions

bool checkSwatchExists (int column, int row) const
 checkSwatch checks if position column and row has a valid entry both column and row start from 0
 
int colorCount () const
 
KisSwatch getSwatch (int column, int row) const
 getSwatch used to get the swatch entry at position (column, row) there is an assertion to make sure that this position isn't empty, so checkEntry(int, int) must be used before this method to ensure a valid entry can be found
 
QList< SwatchInfo > infoList () const
 getColors
 
 KisSwatchGroup (const KisSwatchGroup &rhs)
 
QString name () const
 
KisSwatchGroupoperator= (const KisSwatchGroup &rhs)
 
int rowCount () const
 
void setName (const QString &name)
 
void setRowCount (int newRowCount)
 
int slotCount () const
 
 ~KisSwatchGroup ()
 

Public Attributes

 : struct SwatchInfo { QString group
 
int column
 
int row
 
KisSwatch swatch
 

Static Public Attributes

static int DEFAULT_COLUMN_COUNT = 16
 
static int DEFAULT_ROW_COUNT = 20
 

Private Member Functions

QPair< int, int > addSwatch (const KisSwatch &e)
 addEntry adds the entry e to the right of the rightmost entry in the last row if the rightmost entry in the last row is in the right most column, add e to the leftmost column of a new row
 
void clear ()
 
int columnCount () const
 
 KisSwatchGroup ()
 
bool removeSwatch (int column, int row)
 removeSwatch removes the entry at position (column, row)
 
void setColumnCount (int columnCount)
 
void setSwatch (const KisSwatch &e, int column, int row)
 setSwatch sets the entry at position (column, row) to be e
 

Private Attributes

std::experimental::propagate_const< std::unique_ptr< Private > > d
 

Friends

struct AddGroupCommand
 
struct AddSwatchCommand
 
struct ClearCommand
 
class KisPaletteEditor
 
class KoColorSet
 
struct RemoveGroupCommand
 
struct RemoveSwatchCommand
 
struct SetColumnCountCommand
 
class TestKisSwatchGroup
 
class TestKoColorSet
 

Detailed Description

The KisSwatchGroup class stores a matrix of color swatches swatches can accessed using (x, y) coordinates. x is the column number from left to right and y is the row number from top to bottom. Both x and y start at 0 there could be empty entries, so the checkEntry(int, int) method must used whenever you want to get an entry from the matrix.

Definition at line 31 of file KisSwatchGroup.h.

Constructor & Destructor Documentation

◆ ~KisSwatchGroup()

KisSwatchGroup::~KisSwatchGroup ( )

Definition at line 29 of file KisSwatchGroup.cpp.

30{ }

◆ KisSwatchGroup() [1/2]

KisSwatchGroup::KisSwatchGroup ( const KisSwatchGroup & rhs)

Definition at line 32 of file KisSwatchGroup.cpp.

33 : d(new Private(*rhs.d))
34{ }
std::experimental::propagate_const< std::unique_ptr< Private > > d

◆ KisSwatchGroup() [2/2]

KisSwatchGroup::KisSwatchGroup ( )
private

Definition at line 25 of file KisSwatchGroup.cpp.

26 : d(new Private)
27{ }

Member Function Documentation

◆ addSwatch()

QPair< int, int > KisSwatchGroup::addSwatch ( const KisSwatch & e)
private

addEntry adds the entry e to the right of the rightmost entry in the last row if the rightmost entry in the last row is in the right most column, add e to the leftmost column of a new row

when column is set to 0, resize number of columns to default

Parameters
e

Definition at line 156 of file KisSwatchGroup.cpp.

157{
158 if (columnCount() == 0) {
160 }
161
162 int y = 0;
163 int x = 0;
164 while (checkSwatchExists(x, y))
165 {
166 if(++x == d->colorMatrix.size())
167 {
168 x = 0;
169 ++y;
170 }
171 }
172 // clear color metadata for now.
174
175 setSwatch(swatch, x, y);
176
177 return QPair<int, int> (x, y);
178}
bool checkSwatchExists(int column, int row) const
checkSwatch checks if position column and row has a valid entry both column and row start from 0
void setSwatch(const KisSwatch &e, int column, int row)
setSwatch sets the entry at position (column, row) to be e
int columnCount() const
void setColumnCount(int columnCount)
static int DEFAULT_COLUMN_COUNT
KoColor color() const
Definition KisSwatch.h:30
void clearMetadata()
clearMetadata clear th metadata map inside the KoColor.
Definition KoColor.cpp:676

References checkSwatchExists(), KoColor::clearMetadata(), KisSwatch::color(), columnCount(), d, DEFAULT_COLUMN_COUNT, setColumnCount(), setSwatch(), and swatch.

◆ checkSwatchExists()

bool KisSwatchGroup::checkSwatchExists ( int column,
int row ) const

checkSwatch checks if position column and row has a valid entry both column and row start from 0

Parameters
column
row
Returns
true if there is a valid entry at position (column, row)

Definition at line 58 of file KisSwatchGroup.cpp.

59{
60 if (row >= d->rowCount) {
61 return false;
62 }
63
64 if (column >= d->colorMatrix.size()){
65 return false;
66 }
67
68 if (column < 0) {
69 return false;
70 }
71
72 if (!d->colorMatrix[column].contains(row)) {
73 return false;
74 }
75
76 if (!d->colorMatrix[column][row].isValid()) {
77 return false;
78 }
79
80 return true;
81}

References column, d, and row.

◆ clear()

void KisSwatchGroup::clear ( )
private

Definition at line 180 of file KisSwatchGroup.cpp.

181{
182 d->colorMatrix.clear();
183}

References d.

◆ colorCount()

int KisSwatchGroup::colorCount ( ) const

Definition at line 203 of file KisSwatchGroup.cpp.

204{
205 return d->colorCount;
206}

References d.

◆ columnCount()

int KisSwatchGroup::columnCount ( ) const
private

Definition at line 140 of file KisSwatchGroup.cpp.

140 {
141 return d->colorMatrix.size();
142}

References d.

◆ getSwatch()

KisSwatch KisSwatchGroup::getSwatch ( int column,
int row ) const

getSwatch used to get the swatch entry at position (column, row) there is an assertion to make sure that this position isn't empty, so checkEntry(int, int) must be used before this method to ensure a valid entry can be found

Parameters
column
row
Returns
the swatch entry at position (column, row)

Definition at line 144 of file KisSwatchGroup.cpp.

145{
146 // This is perfectly normal when Krita gets initialized, so it needs an if, not an assert.
147 // Getting -1, -1 is not a coding error.
148 if (row < 0 || column < 0) return KisSwatch();
149
150 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(column >= 0 && column < d->colorMatrix.size(), KisSwatch());
152
153 return d->colorMatrix[column][row];
154}
int rowCount() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References column, d, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, row, and rowCount().

◆ infoList()

QList< KisSwatchGroup::SwatchInfo > KisSwatchGroup::infoList ( ) const

getColors

Returns
the list of colors in this SwatchGroup, in no specific order.

Definition at line 213 of file KisSwatchGroup.cpp.

214{
216 int column = 0;
217 for (const Private::Column &c : d->colorMatrix) {
218 int i = 0;
219 for (const KisSwatch &s : c.values()) {
220 SwatchInfo info = {d->name, s, c.keys()[i++], column};
221 res.append(info);
222 }
223 column++;
224 }
225 return res;
226}
QMap< int, KisSwatch > Column

References column, and d.

◆ name()

QString KisSwatchGroup::name ( ) const

Definition at line 233 of file KisSwatchGroup.cpp.

234{
235 return d->name;
236}

References d.

◆ operator=()

KisSwatchGroup & KisSwatchGroup::operator= ( const KisSwatchGroup & rhs)

Definition at line 36 of file KisSwatchGroup.cpp.

37{
38 if (&rhs == this) {
39 return *this;
40 }
41 *d = *rhs.d;
42 return *this;
43}

References d.

◆ removeSwatch()

bool KisSwatchGroup::removeSwatch ( int column,
int row )
private

removeSwatch removes the entry at position (column, row)

Parameters
column
row
Returns
true if these is an entry at (column, row)

Definition at line 83 of file KisSwatchGroup.cpp.

84{
85 if (d->colorCount == 0) {
86 return false;
87 }
88
89 if (row >= d->rowCount || column >= d->colorMatrix.size() || column < 0) {
90 return false;
91 }
92
93 // QMap::remove returns 1 if key found else 0
94 if (d->colorMatrix[column].remove(row)) {
95 d->colorCount -= 1;
96 return true;
97 } else {
98 return false;
99 }
100}

References column, d, and row.

◆ rowCount()

int KisSwatchGroup::rowCount ( ) const

Definition at line 198 of file KisSwatchGroup.cpp.

199{
200 return d->rowCount;
201}

References d.

◆ setColumnCount()

void KisSwatchGroup::setColumnCount ( int columnCount)
private

Definition at line 102 of file KisSwatchGroup.cpp.

103{
105
106
107 // Move 'removed' swatches into new row
108 QVector <KisSwatch> movedSwatches;
109
110 for (int r = 0; r < rowCount(); r++ ) {
111 for (int c = 0; c < d->colorMatrix.size(); c++ ) {
112
113 if (c >= columnCount && checkSwatchExists(c, r)) {
114 movedSwatches.push_back(getSwatch(c, r));
115 }
116 }
117 }
118 if ( !movedSwatches.isEmpty()) {
119 for (int i = 0; i< movedSwatches.size(); i++) {
120 int r = (i/columnCount) + d->rowCount;
121 int c = (i%columnCount);
122 d->colorMatrix[c][r] = movedSwatches.at(i);
123 }
124 d->rowCount += (movedSwatches.size()/columnCount);
125 if (movedSwatches.size()%columnCount > 0) {
126 d->rowCount += 1;
127 }
128 }
129
130 if (columnCount < d->colorMatrix.size()) {
131 int newColorCount = 0;
132 for (int i = 0; i < columnCount; i++ ) {
133 newColorCount += d->colorMatrix[i].size();
134 }
135 d->colorCount = newColorCount;
136 }
137 d->colorMatrix.resize(columnCount);
138}
KisSwatch getSwatch(int column, int row) const
getSwatch used to get the swatch entry at position (column, row) there is an assertion to make sure t...
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References checkSwatchExists(), columnCount(), d, getSwatch(), KIS_SAFE_ASSERT_RECOVER_RETURN, and rowCount().

◆ setName()

void KisSwatchGroup::setName ( const QString & name)

Definition at line 228 of file KisSwatchGroup.cpp.

229{
230 d->name = name;
231}
QString name() const

References d, and name().

◆ setRowCount()

void KisSwatchGroup::setRowCount ( int newRowCount)

Definition at line 185 of file KisSwatchGroup.cpp.

186{
187 d->rowCount = newRowCount;
188 for (Private::Column &c : d->colorMatrix) {
189 for (int k : c.keys()) {
190 if (k >= newRowCount) {
191 c.remove(k);
192 d->colorCount--;
193 }
194 }
195 }
196}

References d.

◆ setSwatch()

void KisSwatchGroup::setSwatch ( const KisSwatch & e,
int column,
int row )
private

setSwatch sets the entry at position (column, row) to be e

Parameters
e
column
row

Definition at line 45 of file KisSwatchGroup.cpp.

46{
47 Q_ASSERT(column < d->colorMatrix.size() && column >= 0 && row >= 0);
48
49 if (row + 1 >= d->rowCount) {
50 setRowCount(row + 1);
51 }
53 d->colorCount++;
54 }
55 d->colorMatrix[column][row] = e;
56}
void setRowCount(int newRowCount)

References checkSwatchExists(), column, d, row, and setRowCount().

◆ slotCount()

int KisSwatchGroup::slotCount ( ) const

Definition at line 208 of file KisSwatchGroup.cpp.

209{
210 return columnCount() * rowCount();
211}

References columnCount(), and rowCount().

Friends And Related Symbol Documentation

◆ AddGroupCommand

friend struct AddGroupCommand
friend

Definition at line 93 of file KisSwatchGroup.h.

◆ AddSwatchCommand

friend struct AddSwatchCommand
friend

Definition at line 90 of file KisSwatchGroup.h.

◆ ClearCommand

friend struct ClearCommand
friend

Definition at line 94 of file KisSwatchGroup.h.

◆ KisPaletteEditor

friend class KisPaletteEditor
friend

Definition at line 102 of file KisSwatchGroup.h.

◆ KoColorSet

friend class KoColorSet
friend

Definition at line 89 of file KisSwatchGroup.h.

◆ RemoveGroupCommand

friend struct RemoveGroupCommand
friend

Definition at line 91 of file KisSwatchGroup.h.

◆ RemoveSwatchCommand

friend struct RemoveSwatchCommand
friend

Definition at line 92 of file KisSwatchGroup.h.

◆ SetColumnCountCommand

friend struct SetColumnCountCommand
friend

Definition at line 95 of file KisSwatchGroup.h.

◆ TestKisSwatchGroup

friend class TestKisSwatchGroup
friend

Definition at line 96 of file KisSwatchGroup.h.

◆ TestKoColorSet

friend class TestKoColorSet
friend

Definition at line 97 of file KisSwatchGroup.h.

Member Data Documentation

◆ __pad0__

KisSwatchGroup::__pad0__

Definition at line 153 of file KisSwatchGroup.h.

◆ column

int KisSwatchGroup::column

Definition at line 38 of file KisSwatchGroup.h.

◆ d

std::experimental::propagate_const<std::unique_ptr<Private> > KisSwatchGroup::d
private

Definition at line 144 of file KisSwatchGroup.h.

◆ DEFAULT_COLUMN_COUNT

int KisSwatchGroup::DEFAULT_COLUMN_COUNT = 16
static

Definition at line 43 of file KisSwatchGroup.h.

◆ DEFAULT_ROW_COUNT

int KisSwatchGroup::DEFAULT_ROW_COUNT = 20
static

Definition at line 44 of file KisSwatchGroup.h.

◆ row

int KisSwatchGroup::row

Definition at line 37 of file KisSwatchGroup.h.

◆ swatch

KisSwatch KisSwatchGroup::swatch

Definition at line 36 of file KisSwatchGroup.h.


The documentation for this class was generated from the following files: