KDescendantsProxyModel Class

Proxy Model for restructuring a Tree into a list. More...

Header: #include <KDescendantsProxyModel>
CMake: find_package(KF6 REQUIRED COMPONENTS ItemModels)
target_link_libraries(mytarget PRIVATE KF6::ItemModels)
Since: KDE Frameworks 4.6

Properties

Public Functions

KDescendantsProxyModel(QObject *parent = nullptr)
virtual ~KDescendantsProxyModel() override
QString ancestorSeparator() const
(since 5.74) void collapseSourceIndex(const QModelIndex &sourceIndex)
bool displayAncestorData() const
(since 5.74) void expandSourceIndex(const QModelIndex &sourceIndex)
(since 5.74) bool expandsByDefault() const
(since 5.74) bool isSourceIndexExpanded(const QModelIndex &sourceIndex) const
(since 5.74) bool isSourceIndexVisible(const QModelIndex &sourceIndex) const
void setAncestorSeparator(const QString &separator)
void setDisplayAncestorData(bool display)
(since 5.74) void setExpandsByDefault(bool expand)

Reimplemented Public Functions

virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const override
virtual void setSourceModel(QAbstractItemModel *model) override

Signals

Detailed Description

A KDescendantsProxyModel may be used to alter how the items in the tree are presented.

Given a model which is represented as a tree:

"A plain EntityTreeModel in a view"

The KDescendantsProxyModel restructures the sourceModel to represent it as a flat list.

// ... Create an entityTreeModel
KDescendantsProxyModel *descProxy = new KDescendantsProxyModel(this);
descProxy->setSourceModel(entityTree);
view->setModel(descProxy);

"A KDescendantsProxyModel."

KDescendantEntitiesProxyModel can also display the ancestors of the index in the source model as part of its display.

// ... Create an entityTreeModel
KDescendantsProxyModel *descProxy = new KDescendantsProxyModel(this);
descProxy->setSourceModel(entityTree);

// #### This is new
descProxy->setDisplayAncestorData(true);
descProxy->setAncestorSeparator(QString(" / "));

view->setModel(descProxy);

"A KDescendantsProxyModel with ancestor names."

@author Stephen Kelly <steveire@gmail.com>

Property Documentation

[since 5.62] ancestorSeparator : QString

This property was introduced in KDE Frameworks 5.62.

Access functions:

QString ancestorSeparator() const
void setAncestorSeparator(const QString &separator)

Notifier signal:

void ancestorSeparatorChanged()

[since 5.62] displayAncestorData : bool

This property was introduced in KDE Frameworks 5.62.

Access functions:

bool displayAncestorData() const
void setDisplayAncestorData(bool display)

Notifier signal:

void displayAncestorDataChanged()

[since 5.74] expandsByDefault : bool

If true, all the nodes in the whole tree will be expanded upon loading and all items of the source model will be shown in the proxy. The default value is true.

This property was introduced in KDE Frameworks 5.74.

Access functions:

bool expandsByDefault() const
void setExpandsByDefault(bool expand)

Notifier signal:

void expandsByDefaultChanged(bool expands)

[since 5.62] model : QAbstractItemModel*

This property was introduced in KDE Frameworks 5.62.

Access functions:

virtual void setSourceModel(QAbstractItemModel *model) override

Notifier signal:

void sourceModelChanged()

Member Function Documentation

[explicit] KDescendantsProxyModel::KDescendantsProxyModel(QObject *parent = nullptr)

Creates a new descendant entities proxy model.

parent The parent object.

[override virtual noexcept] KDescendantsProxyModel::~KDescendantsProxyModel()

Destroys the descendant entities proxy model.

QString KDescendantsProxyModel::ancestorSeparator() const

Separator used between data of ancestors.

Note: Getter function for property ancestorSeparator.

See also setAncestorSeparator().

[since 5.74] void KDescendantsProxyModel::collapseSourceIndex(const QModelIndex &sourceIndex)

Maps a source index as collapsed in the proxy, all its children will be hidden. sourceIndex an index of the source model.

This function was introduced in KDE Frameworks 5.74.

bool KDescendantsProxyModel::displayAncestorData() const

Whether ancestor data will be displayed.

Note: Getter function for property displayAncestorData.

See also setDisplayAncestorData().

[since 5.74] void KDescendantsProxyModel::expandSourceIndex(const QModelIndex &sourceIndex)

Maps a source index as expanded in the proxy, all its children will become visible. sourceIndex an index of the source model.

This function was introduced in KDE Frameworks 5.74.

[since 5.74] bool KDescendantsProxyModel::expandsByDefault() const

Returns true if all the tree nodes are expanded by default upon loading

Note: Getter function for property expandsByDefault.

This function was introduced in KDE Frameworks 5.74.

See also setExpandsByDefault().

[since 5.74] bool KDescendantsProxyModel::isSourceIndexExpanded(const QModelIndex &sourceIndex) const

Returns true if the source index is mapped in the proxy as expanded, therefore it will show its children

This function was introduced in KDE Frameworks 5.74.

[since 5.74] bool KDescendantsProxyModel::isSourceIndexVisible(const QModelIndex &sourceIndex) const

Returns true if the source index is visible in the proxy, meaning all its parent hierarchy is expanded.

This function was introduced in KDE Frameworks 5.74.

[override virtual] QModelIndexList KDescendantsProxyModel::match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const

Reimplemented to match all descendants.

void KDescendantsProxyModel::setAncestorSeparator(const QString &separator)

Sets the ancestor separator used between data of ancestors.

Note: Setter function for property ancestorSeparator.

See also ancestorSeparator().

void KDescendantsProxyModel::setDisplayAncestorData(bool display)

Set whether to show ancestor data in the model. If display is true, then a source model which is displayed as

-> "Item 0-0" (this is row-depth)
-> -> "Item 0-1"
-> -> "Item 1-1"
-> -> -> "Item 0-2"
-> -> -> "Item 1-2"
-> "Item 1-0"

will be displayed as

-> *Item 0-0"
-> "Item 0-0 / Item 0-1"
-> "Item 0-0 / Item 1-1"
-> "Item 0-0 / Item 1-1 / Item 0-2"
-> "Item 0-0 / Item 1-1 / Item 1-2"
-> "Item 1-0"

If display is false, the proxy will show

-> *Item 0-0"
-> "Item 0-1"
-> "Item 1-1"
-> "Item 0-2"
-> "Item 1-2"
-> "Item 1-0"

Default is false.

Note: Setter function for property displayAncestorData.

See also displayAncestorData().

[since 5.74] void KDescendantsProxyModel::setExpandsByDefault(bool expand)

If true, all the nodes in the whole tree will be expanded upon loading (default) expand whether we want everything expanded upon load

Note: Setter function for property expandsByDefault.

This function was introduced in KDE Frameworks 5.74.

See also expandsByDefault().

[override virtual] void KDescendantsProxyModel::setSourceModel(QAbstractItemModel *model)

Sets the source model of the proxy.

Note: Setter function for property model.