Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPaletteModel.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2013 Sven Langkamp <sven.langkamp@gmail.com>
3 * SPDX-FileCopyrightText: 2022 Halla Rempt <halla@valdyas.org>
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef KIS_PALETTEMODEL_H
7#define KIS_PALETTEMODEL_H
8
9#include <QPointer>
10#include <QModelIndex>
11#include <QMap>
12
14
15#include "kritawidgets_export.h"
16#include <KoColorSet.h>
17#include <KisSwatchGroup.h>
18
19class KisPaletteView;
20
27class KRITAWIDGETS_EXPORT KisPaletteModel : public QAbstractTableModel
28{
29 Q_OBJECT
30public:
31 explicit KisPaletteModel(QObject* parent = 0);
32 ~KisPaletteModel() override;
33
39 void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer);
40
41
43 IsGroupNameRole = Qt::UserRole + 1,
46 RowInGroupRole
47 };
48
49public: // QAbstractTableModel
50
51 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
52
53 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
54
55 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
56
57 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
58
59 Qt::ItemFlags flags(const QModelIndex& index) const override;
60
61 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
62 int row, int column, const QModelIndex &parent) override;
63
64 QMimeData *mimeData(const QModelIndexList &indexes) const override;
65
66 QStringList mimeTypes() const override;
67
68 Qt::DropActions supportedDropActions() const override;
69
70Q_SIGNALS:
71
77
83
84public:
85
86 void setColorSet(KoColorSetSP colorSet);
87
88 KoColorSetSP colorSet() const;
89
90 void addSwatch(const KisSwatch &entry,
91 const QString &groupName = KoColorSet::GLOBAL_GROUP_NAME);
92
93 void setSwatch(const KisSwatch &entry, const QModelIndex &index);
94
95 void removeSwatch(const QModelIndex &index, bool keepColors=true);
96
97 void changeGroupName(const QString &groupName, const QString &newName);
98
99 void removeGroup(const QString &groupName, bool keepColors);
100
101 KisSwatchGroupSP addGroup(const QString &groupName, int columnCount = KisSwatchGroup::DEFAULT_COLUMN_COUNT, int rowCount = KisSwatchGroup::DEFAULT_ROW_COUNT);
102
103 void setRowCountForGroup(const QString &groupName, int rowCount);
104
105 void setColumnCount(int colCount);
106
107 void clear();
108
109 void clear(int defaultColumnsCount);
110
111 KisSwatch getSwatch(const QModelIndex &index) const;
112
113 QModelIndex indexForClosest(const KoColor &compare);
114
115
116 void slotExternalPaletteModified(QSharedPointer<KoColorSet> resource);
117
118private Q_SLOTS:
119
120 void slotDisplayConfigurationChanged();
121
122 void slotPaletteModified();
123 void slotLayoutAboutToChange();
124 void slotLayoutChanged();
125 void slotEntryChanged(int column, int row);
126
127private:
128
129 friend class TestKisPaletteModel;
130
131 int rowNumberInGroup(int rowInModel) const;
132 int indexRowForInfo(const KisSwatchGroup::SwatchInfo &info);
133
134 QVariant dataForGroupNameRow(const QModelIndex &idx, int role) const;
135 QVariant dataForSwatch(const QModelIndex &idx, int role) const;
136
137private /* member variables */:
138 KoColorSetSP m_colorSet;
140 bool m_editing {false};
141};
142
143#endif
The KisPaletteModel class This, together with KisPaletteView and KisPaletteDelegate forms a mvc way t...
void sigPaletteModified()
sigPaletteModified emitted when palette associated with the model is modified
QPointer< const KoColorDisplayRendererInterface > m_displayRenderer
void sigPaletteChanged()
sigPaletteChanged emitted when the palette associated with the model is changed for another palette
static int DEFAULT_ROW_COUNT
static int DEFAULT_COLUMN_COUNT
static const QString GLOBAL_GROUP_NAME
Definition KoColorSet.h:33