Krita Source Code Documentation
Loading...
Searching...
No Matches
KisNodeFilterProxyModel Class Reference

#include <kis_node_filter_proxy_model.h>

+ Inheritance diagram for KisNodeFilterProxyModel:

Classes

struct  Private
 

Public Slots

void setActiveNode (KisNodeSP node)
 

Signals

void sigBeforeBeginRemoveRows (const QModelIndex &parent, int start, int end)
 

Public Member Functions

bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override
 
QModelIndex indexFromNode (KisNodeSP node) const
 
 KisNodeFilterProxyModel (QObject *parent)
 
KisNodeSP nodeFromIndex (const QModelIndex &index) const
 
void setAcceptedLabels (const QSet< int > &value)
 
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 
void setNodeModel (KisNodeModel *model)
 
void setTextFilter (const QString &text)
 
void unsetDummiesFacade ()
 
 ~KisNodeFilterProxyModel () override
 

Private Slots

void slotBeforeBeginRemoveRows (const QModelIndex &parent, int start, int end)
 
void slotUpdateCurrentNodeFilter ()
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

Definition at line 20 of file kis_node_filter_proxy_model.h.

Constructor & Destructor Documentation

◆ KisNodeFilterProxyModel()

KisNodeFilterProxyModel::KisNodeFilterProxyModel ( QObject * parent)

Definition at line 40 of file kis_node_filter_proxy_model.cpp.

41 : QSortFilterProxyModel(parent),
42 m_d(new Private)
43{
44 connect(&m_d->activeNodeCompressor, SIGNAL(timeout()), SLOT(slotUpdateCurrentNodeFilter()), Qt::QueuedConnection);
45}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
const QScopedPointer< Private > m_d

References connect(), m_d, and slotUpdateCurrentNodeFilter().

◆ ~KisNodeFilterProxyModel()

KisNodeFilterProxyModel::~KisNodeFilterProxyModel ( )
override

Definition at line 47 of file kis_node_filter_proxy_model.cpp.

48{
49}

Member Function Documentation

◆ filterAcceptsRow()

bool KisNodeFilterProxyModel::filterAcceptsRow ( int source_row,
const QModelIndex & source_parent ) const
override

Definition at line 102 of file kis_node_filter_proxy_model.cpp.

103{
104 KIS_ASSERT_RECOVER(m_d->nodeModel) { return true; }
105
106 const QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
107 if (!index.isValid()) return false;
108
109 KisNodeSP node = m_d->nodeModel->nodeFromIndex(index);
110
111 return !node ||
112 (m_d->acceptedColorLabels.isEmpty() && !m_d->activeTextFilter) ||
113 m_d->checkIndexAllowedRecursively(index);
114}
#define KIS_ASSERT_RECOVER(cond)
Definition kis_assert.h:55

References KIS_ASSERT_RECOVER, and m_d.

◆ indexFromNode()

QModelIndex KisNodeFilterProxyModel::indexFromNode ( KisNodeSP node) const

Definition at line 124 of file kis_node_filter_proxy_model.cpp.

125{
126 KIS_ASSERT_RECOVER(m_d->nodeModel) { return QModelIndex(); }
127
128 QModelIndex srcIndex = m_d->nodeModel->indexFromNode(node);
129 return mapFromSource(srcIndex);
130}

References KIS_ASSERT_RECOVER, and m_d.

◆ nodeFromIndex()

KisNodeSP KisNodeFilterProxyModel::nodeFromIndex ( const QModelIndex & index) const

Definition at line 116 of file kis_node_filter_proxy_model.cpp.

117{
118 KIS_ASSERT_RECOVER(m_d->nodeModel) { return 0; }
119
120 QModelIndex srcIndex = mapToSource(index);
121 return m_d->nodeModel->nodeFromIndex(srcIndex);
122}

References KIS_ASSERT_RECOVER, and m_d.

◆ setAcceptedLabels()

void KisNodeFilterProxyModel::setAcceptedLabels ( const QSet< int > & value)

Definition at line 132 of file kis_node_filter_proxy_model.cpp.

133{
134 m_d->acceptedColorLabels = value;
135 invalidateFilter();
136}
float value(const T *src, size_t ch)

References m_d, and value().

◆ setActiveNode

void KisNodeFilterProxyModel::setActiveNode ( KisNodeSP node)
slot

Definition at line 144 of file kis_node_filter_proxy_model.cpp.

145{
146 // NOTE: the current node might change due to beginRemoveRows, in such case
147 // we must ensure we don't trigger recursive model invalidation.
148
149 // the new node may temporary become null when the last layer
150 // of the document in removed
151 m_d->pendingActiveNode = node;
152 m_d->activeNodeCompressor.start();
153}

References m_d.

◆ setData()

bool KisNodeFilterProxyModel::setData ( const QModelIndex & index,
const QVariant & value,
int role )
override

Definition at line 61 of file kis_node_filter_proxy_model.cpp.

62{
63 if (m_d->isUpdatingFilter && role == KisNodeModel::ActiveRole) {
64 return false;
65 }
66
67 return QSortFilterProxyModel::setData(index, value, role);
68}
@ ActiveRole
Whether the section is the active one.

References KisNodeModel::ActiveRole, m_d, and value().

◆ setNodeModel()

void KisNodeFilterProxyModel::setNodeModel ( KisNodeModel * model)

Definition at line 51 of file kis_node_filter_proxy_model.cpp.

52{
53 m_d->modelConnections.clear();
54 m_d->modelConnections.addConnection(model, SIGNAL(sigBeforeBeginRemoveRows(const QModelIndex &, int, int)),
55 this, SLOT(slotBeforeBeginRemoveRows(const QModelIndex &, int, int)));
56
57 m_d->nodeModel = model;
58 setSourceModel(model);
59}
void sigBeforeBeginRemoveRows(const QModelIndex &parent, int start, int end)
void slotBeforeBeginRemoveRows(const QModelIndex &parent, int start, int end)

References m_d, sigBeforeBeginRemoveRows(), and slotBeforeBeginRemoveRows().

◆ setTextFilter()

void KisNodeFilterProxyModel::setTextFilter ( const QString & text)

Definition at line 138 of file kis_node_filter_proxy_model.cpp.

139{
140 m_d->activeTextFilter = !text.isEmpty() ? boost::make_optional(text) : boost::none;
141 invalidateFilter();
142}

References m_d.

◆ sigBeforeBeginRemoveRows

void KisNodeFilterProxyModel::sigBeforeBeginRemoveRows ( const QModelIndex & parent,
int start,
int end )
signal

◆ slotBeforeBeginRemoveRows

void KisNodeFilterProxyModel::slotBeforeBeginRemoveRows ( const QModelIndex & parent,
int start,
int end )
privateslot

Definition at line 172 of file kis_node_filter_proxy_model.cpp.

173{
174 for (int row = start; row <= end; row++) {
175 const QModelIndex sourceIndex = sourceModel()->index(row, 0, parent);
176 const QModelIndex mappedIndex = mapFromSource(sourceIndex);
177
178 if (mappedIndex.isValid()) {
179 Q_EMIT sigBeforeBeginRemoveRows(mappedIndex.parent(), mappedIndex.row(), mappedIndex.row());
180 }
181 }
182}

References sigBeforeBeginRemoveRows().

◆ slotUpdateCurrentNodeFilter

void KisNodeFilterProxyModel::slotUpdateCurrentNodeFilter ( )
privateslot

During the filter update the model might Q_EMIT "current changed" signals, which (in their turn) will issue setData(..., KisNodeModel::ActiveRole) call, leading to a double recursion. Which, obviously, crashes Krita.

Right now, just blocking the KisNodeModel::ActiveRole call is the most obvious solution for the problem.

Definition at line 155 of file kis_node_filter_proxy_model.cpp.

156{
157 m_d->activeNode = m_d->pendingActiveNode;
158
167 m_d->isUpdatingFilter = true;
168 invalidateFilter();
169 m_d->isUpdatingFilter = false;
170}

References m_d.

◆ unsetDummiesFacade()

void KisNodeFilterProxyModel::unsetDummiesFacade ( )

Definition at line 184 of file kis_node_filter_proxy_model.cpp.

185{
186 m_d->nodeModel->setDummiesFacade(0, 0, 0, 0, 0);
187 m_d->pendingActiveNode = 0;
188 m_d->activeNode = 0;
189}

References m_d.

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisNodeFilterProxyModel::m_d
private

Definition at line 52 of file kis_node_filter_proxy_model.h.


The documentation for this class was generated from the following files: