KD Chart API Documentation 3.1
Loading...
Searching...
No Matches
KDChartPalette.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of the KD Chart library.
4**
5** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6**
7** SPDX-License-Identifier: MIT
8**
9****************************************************************************/
10
11#include "KDChartPalette.h"
12#include <QBrush>
13#include <QVector>
14
15#include <KDABLibFakes>
16
17using namespace KDChart;
18
19namespace {
20
21static Palette makeDefaultPalette()
22{
23 Palette p;
24
37
38 return p;
39}
40
41static Palette makeSubduedPalette()
42{
43 Palette p;
44
45 p.addBrush(QColor(0xe0, 0x7f, 0x70));
46 p.addBrush(QColor(0xe2, 0xa5, 0x6f));
47 p.addBrush(QColor(0xe0, 0xc9, 0x70));
48 p.addBrush(QColor(0xd1, 0xe0, 0x70));
49 p.addBrush(QColor(0xac, 0xe0, 0x70));
50 p.addBrush(QColor(0x86, 0xe0, 0x70));
51 p.addBrush(QColor(0x70, 0xe0, 0x7f));
52 p.addBrush(QColor(0x70, 0xe0, 0xa4));
53 p.addBrush(QColor(0x70, 0xe0, 0xc9));
54 p.addBrush(QColor(0x70, 0xd1, 0xe0));
55 p.addBrush(QColor(0x70, 0xac, 0xe0));
56 p.addBrush(QColor(0x70, 0x86, 0xe0));
57 p.addBrush(QColor(0x7f, 0x70, 0xe0));
58 p.addBrush(QColor(0xa4, 0x70, 0xe0));
59 p.addBrush(QColor(0xc9, 0x70, 0xe0));
60 p.addBrush(QColor(0xe0, 0x70, 0xd1));
61 p.addBrush(QColor(0xe0, 0x70, 0xac));
62 p.addBrush(QColor(0xe0, 0x70, 0x86));
63
64 return p;
65}
66
67static Palette makeRainbowPalette()
68{
69 Palette p;
70
71 p.addBrush(QColor(255, 0, 196));
72 p.addBrush(QColor(255, 0, 96));
73 p.addBrush(QColor(255, 128, 64));
77 p.addBrush(QColor(96, 96, 255));
78 p.addBrush(QColor(160, 0, 255));
79 for (int i = 8; i < 16; ++i) {
80 p.addBrush(p.getBrush(i - 8).color().lighter(), i);
81 }
82 return p;
83}
84}
85
86#define d d_func()
87
88class Palette::Private
89{
90public:
91 explicit Private()
92 {
93 }
94 ~Private()
95 {
96 }
97
98 QVector<QBrush> brushes;
99};
100
102{
103 static const Palette palette = makeDefaultPalette();
104 return palette;
105}
106
108{
109 static const Palette palette = makeSubduedPalette();
110 return palette;
111}
112
114{
115 static const Palette palette = makeRainbowPalette();
116 return palette;
117}
118
120 : QObject(parent)
121 , _d(new Private)
122{
123}
124
126{
127 delete _d;
128 _d = nullptr;
129}
130
132 : QObject()
133 , _d(new Private(*r.d))
134{
135}
136
138{
139 Palette copy(r);
140 copy.swap(*this);
141
142 // emit changed() ?
143 return *this;
144}
145
147{
148 return d->brushes.size() >= 1;
149}
150
151int Palette::size() const
152{
153 return d->brushes.size();
154}
155
156void Palette::addBrush(const QBrush &brush, int position)
157{
159 d->brushes.append(brush);
160 } else {
161 d->brushes.insert(position, brush);
162 }
163 Q_EMIT changed();
164}
165
166QBrush Palette::getBrush(int position) const
167{
168 if (!isValid())
169 return QBrush();
170 return d->brushes.at(position % size());
171}
172
173void Palette::removeBrush(int position)
174{
176 return;
177 d->brushes.remove(position);
178 Q_EMIT changed();
179}
A Palette is a set of brushes (or colors) to be used for painting data sets.
QBrush getBrush(int position) const
void removeBrush(int position)
void addBrush(const QBrush &brush, int position=-1)
Palette & operator=(const Palette &)
Palette(QObject *parent=nullptr)
static const Palette & subduedPalette()
static const Palette & defaultPalette()
static const Palette & rainbowPalette()
const QColor & color() const const
QColor lighter(int factor) const const
Q_EMITQ_EMIT
T qobject_cast(QObject *object)

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated on Wed May 1 2024 00:01:10 for KD Chart API Documentation by doxygen 1.9.8