Krita Source Code Documentation
Loading...
Searching...
No Matches
TextPropertyConfigModel.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef TEXTPROPERTYCONFIGMODEL_H
7#define TEXTPROPERTYCONFIGMODEL_H
8
9#include <QAbstractListModel>
10#include <QSortFilterProxyModel>
11#include <QObject>
12
13// This model helps to keep track of the relevant properties.
14
15class TextPropertyConfigModel : public QAbstractListModel
16{
17 Q_OBJECT
19 Q_PROPERTY(bool shouldFilter READ shouldFilter NOTIFY shouldFilterChanged)
20public:
21
29 Q_ENUM(VisibilityState)
30
36 Q_ENUM(PropertyType)
37
38 enum Roles {
39 Visibility = Qt::UserRole + 1,
43 };
44
45 explicit TextPropertyConfigModel(QObject *parent = nullptr);
47
50
51 bool shouldFilter() const;
52
53 // Call this after adding all the properties.
54 Q_INVOKABLE void loadFromConfiguration();
55
56 Q_INVOKABLE void addProperty(const QString &name,
57 const int propertyType = 0,
58 const QString title = QString(),
59 const QString toolTip = QString(),
60 const QString searchTerms = QString(),
61 const int visibilityState = -1);
62
63 Q_INVOKABLE int visibilityStateForName(const QString &name) const;
64
65 void saveConfiguration();
66 // QAbstractItemModel interface
67public:
68 int rowCount(const QModelIndex &parent) const override;
69 QVariant data(const QModelIndex &index, int role) const override;
70 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
71 bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
72 QHash<int, QByteArray> roleNames() const override;
73
74Q_SIGNALS:
77private:
78
79 struct Private;
80 struct TextPropertyData;
81 const QScopedPointer<Private> d;
82};
83
84class TextPropertyConfigFilterModel : public QSortFilterProxyModel
85{
86 Q_OBJECT
88 Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setProxySourceModel NOTIFY proxySourceModelChanged)
90public:
91 TextPropertyConfigFilterModel(QObject *parent = nullptr);
92 // QSortFilterProxyModel interface
93
94 bool showParagraphProperties() const;
95
96 void setShowParagraphProperties(const bool show);
97
98 void setProxySourceModel(QAbstractItemModel *model);
99
101
102Q_SIGNALS:
106protected:
107 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
108
110};
111
112#endif // TEXTPROPERTYCONFIGMODEL_H
float value(const T *src, size_t ch)
void setShowParagraphProperties(const bool show)
void setProxySourceModel(QAbstractItemModel *model)
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
int rowCount(const QModelIndex &parent) const override
const QScopedPointer< Private > d
@ Character
This property can be applied on a character level.
@ Paragraph
This property only does something when applied to a paragraph.
@ Mixed
This property can be in either.
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Q_INVOKABLE void addProperty(const QString &name, const int propertyType=0, const QString title=QString(), const QString toolTip=QString(), const QString searchTerms=QString(), const int visibilityState=-1)
Q_INVOKABLE int visibilityStateForName(const QString &name) const
void setDefaultVisibilityState(const VisibilityState state)
@ NeverVisible
Never show property.
@ FollowDefault
Follow the default property.
@ AlwaysVisible
Always show property.
@ WhenRelevant
Show when either set or inherited.
TextPropertyConfigModel(QObject *parent=nullptr)
QVariant data(const QModelIndex &index, int role) const override
QHash< int, QByteArray > roleNames() const override
void defaultVisibilityStateChanged()