-
Notifications
You must be signed in to change notification settings - Fork 3
/
colorhistorymodel.h
37 lines (27 loc) · 1.06 KB
/
colorhistorymodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
#include <QAbstractListModel>
#include <QQmlEngine>
#include <QColor>
class ColorHistoryModel : public QAbstractListModel {
Q_OBJECT
QML_ELEMENT
Q_PROPERTY( int historySize MEMBER m_historySize NOTIFY historySizeChanged FINAL )
public:
enum ColorHistoryRoles {
Color = Qt::UserRole + 1,
};
explicit ColorHistoryModel( QObject* parent = nullptr );
[[nodiscard]] int rowCount( const QModelIndex& parent ) const override;
[[nodiscard]] QVariant data( const QModelIndex& index, int role ) const override;
[[nodiscard]] bool setData( const QModelIndex& index, const QVariant& value, int role ) override;
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
[[nodiscard]] Qt::ItemFlags flags( const QModelIndex& index ) const override;
bool removeRows( int row, int count, const QModelIndex& parent ) override;
Q_INVOKABLE void append( const QColor& newColor );
Q_INVOKABLE void clear();
Q_SIGNALS:
void historySizeChanged();
private:
QList<QColor> m_colors;
int m_historySize;
};