#include <KisUniqueColorSet.h>
Definition at line 18 of file KisUniqueColorSet.h.
◆ KisUniqueColorSet()
| KisUniqueColorSet::KisUniqueColorSet |
( |
QObject * | parent = nullptr | ) |
|
|
explicit |
◆ ~KisUniqueColorSet()
| KisUniqueColorSet::~KisUniqueColorSet |
( |
| ) |
|
|
override |
Definition at line 45 of file KisUniqueColorSet.cpp.
46{
47 for (ColorEntry *entry:
d->history) {
48 delete entry;
49 }
50}
References d.
◆ addColor()
| void KisUniqueColorSet::addColor |
( |
const KoColor & | color | ) |
|
Definition at line 52 of file KisUniqueColorSet.cpp.
53{
54 auto hashEntry =
d->colorHash.find(
color);
55 if (hashEntry !=
d->colorHash.end()) {
56 auto historyEl = std::lower_bound(
d->history.begin(),
d->history.end(), *hashEntry, &
ColorEntry::less);
57 if (historyEl !=
d->history.end()) {
58 int oldPos = historyEl -
d->history.begin();
59 if (historyEl ==
d->history.begin()) {
61 return;
62 }
63 ColorEntry *node = *historyEl;
64 d->history.erase(historyEl);
66 d->history.push_front(node);
68 }
69 else {
70 qDebug() << "inconsistent color history state!";
71 }
72 }
73 else {
74 ColorEntry *entry;
75 if (
d->history.size() >=
d->maxSize) {
76 entry =
d->history.back();
77 d->history.pop_back();
80 entry->key = ++
d->key;
82 }
83 else {
84 entry =
new ColorEntry {
color, ++
d->key};
85 }
86 d->colorHash.insert(
color, entry);
87 d->history.push_front(entry);
89 }
90}
void sigColorRemoved(int position)
void sigColorAdded(int position)
KoColor color(int index) const
void sigColorMoved(int from, int to)
static bool less(const KisUniqueColorSet::ColorEntry *lhs, const KisUniqueColorSet::ColorEntry *rhs)
References KisUniqueColorSet::ColorEntry::color, color(), d, KisUniqueColorSet::ColorEntry::key, KIS_ASSERT, KisUniqueColorSet::ColorEntry::less(), sigColorAdded(), sigColorMoved(), and sigColorRemoved().
◆ clear
| void KisUniqueColorSet::clear |
( |
| ) |
|
|
slot |
Definition at line 105 of file KisUniqueColorSet.cpp.
106{
107 for (ColorEntry *entry:
d->history) {
108 delete entry;
109 }
111 d->colorHash.clear();
114}
References d, and sigReset().
◆ color()
| KoColor KisUniqueColorSet::color |
( |
int | index | ) |
const |
Definition at line 92 of file KisUniqueColorSet.cpp.
93{
94 if (index < 0 || index >=
static_cast<int>(
d->history.size())) {
96 }
97 return d->history.at(index)->color;
98}
References d.
◆ sigColorAdded
| void KisUniqueColorSet::sigColorAdded |
( |
int | position | ) |
|
|
signal |
◆ sigColorMoved
| void KisUniqueColorSet::sigColorMoved |
( |
int | from, |
|
|
int | to ) |
|
signal |
◆ sigColorRemoved
| void KisUniqueColorSet::sigColorRemoved |
( |
int | position | ) |
|
|
signal |
◆ sigReset
| void KisUniqueColorSet::sigReset |
( |
| ) |
|
|
signal |
◆ size()
| int KisUniqueColorSet::size |
( |
| ) |
const |
| QScopedPointer<Private> KisUniqueColorSet::d |
|
private |
The documentation for this class was generated from the following files: