Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtgradientmanager.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QtGui/QPixmap>
6#include <QtCore/QMetaEnum>
7
9
14
15QMap<QString, QGradient> QtGradientManager::gradients() const
16{
17 return m_idToGradient;
18}
19
20QString QtGradientManager::uniqueId(const QString &id) const
21{
22 if (!m_idToGradient.contains(id))
23 return id;
24
25 QString base = id;
26 while (base.size() > 0 && base.at(base.size() - 1).isDigit())
27 base = base.left(base.size() - 1);
28 QString newId = base;
29 int counter = 0;
30 while (m_idToGradient.contains(newId)) {
31 ++counter;
32 newId = base + QString::number(counter);
33 }
34 return newId;
35}
36
37QString QtGradientManager::addGradient(const QString &id, const QGradient &gradient)
38{
39 QString newId = uniqueId(id);
40
41 m_idToGradient[newId] = gradient;
42
43 emit gradientAdded(newId, gradient);
44
45 return newId;
46}
47
48void QtGradientManager::removeGradient(const QString &id)
49{
50 if (!m_idToGradient.contains(id))
51 return;
52
53 emit gradientRemoved(id);
54
55 m_idToGradient.remove(id);
56}
57
58void QtGradientManager::renameGradient(const QString &id, const QString &newId)
59{
60 if (!m_idToGradient.contains(id))
61 return;
62
63 if (newId == id)
64 return;
65
66 QString changedId = uniqueId(newId);
67 QGradient gradient = m_idToGradient.value(id);
68
69 emit gradientRenamed(id, changedId);
70
71 m_idToGradient.remove(id);
72 m_idToGradient[changedId] = gradient;
73}
74
75void QtGradientManager::changeGradient(const QString &id, const QGradient &newGradient)
76{
77 if (!m_idToGradient.contains(id))
78 return;
79
80 if (m_idToGradient.value(id) == newGradient)
81 return;
82
83 emit gradientChanged(id, newGradient);
84
85 m_idToGradient[id] = newGradient;
86}
87
89{
90 const QMap<QString, QGradient> grads = gradients();
91 for (auto it = grads.cbegin(), end = grads.cend(); it != end; ++it)
92 removeGradient(it.key());
93}
94
95QT_END_NAMESPACE
QObject * parent
Definition qobject.h:73
\inmodule QtCore
Definition qobject.h:103
void changeGradient(const QString &id, const QGradient &newGradient)
void removeGradient(const QString &id)
void renameGradient(const QString &id, const QString &newId)
QString uniqueId(const QString &id) const
Combined button and popup list for selecting options.