Pages
API Documentation
On this page

KTreeWidgetSearchLine Class

This class makes it easy to add a search line for filtering the items in listviews based on a simple text search. More...

  • Header: #include <KTreeWidgetSearchLine>
  • CMake: find_package(KF6 REQUIRED COMPONENTS ItemViews)
    target_link_libraries(mytarget PRIVATE KF6::ItemViews)
  • Inherits: QLineEdit

List of all members, including inherited members

Properties

Public Functions

Public Slots

Signals

Protected Functions

Detailed Description

No changes to the application other than instantiating this class with appropriate QTreeWidgets should be needed.

Property Documentation

caseSensitity : Qt::CaseSensitivity

Access functions:

Notifier signal:

keepParentsVisible : bool

Access functions:

Notifier signal:

Member Function Documentation

[explicit] KTreeWidgetSearchLine::KTreeWidgetSearchLine(QWidget *parent = nullptr, QTreeWidget *treeWidget = nullptr)

Constructs a KTreeWidgetSearchLine with treeWidget being the QTreeWidget to be filtered.

If treeWidget is null then the widget will be disabled until listviews are set with setTreeWidget(), setTreeWidgets() or added with addTreeWidget().

KTreeWidgetSearchLine::KTreeWidgetSearchLine(QWidget *parent, const QList<QTreeWidget *> &treeWidgets)

Constructs a KTreeWidgetSearchLine with treeWidgets being the list of pointers to QTreeWidgets to be filtered.

If treeWidgets is empty then the widget will be disabled until listviews are set with setTreeWidget(), setTreeWidgets() or added with addTreeWidget().

[slot] void KTreeWidgetSearchLine::addTreeWidget(QTreeWidget *treeWidget)

Adds a QTreeWidget to the list of listviews filtered by this search line. If treeWidget is null then the widget will be disabled.

See also treeWidget(), setTreeWidgets(), removeTreeWidget()

[virtual protected] bool KTreeWidgetSearchLine::canChooseColumnsCheck()

Checks columns in all listviews and decides whether choosing columns to filter on makes any sense.

Returns false if either of the following is true: * there are no listviews connected, * the listviews have different numbers of columns, * the listviews have only one column, * the listviews differ in column labels.

Otherwise it returns true.

See also setSearchColumns()

Qt::CaseSensitivity KTreeWidgetSearchLine::caseSensitivity() const

Returns true if the search is case sensitive. This defaults to false.

Note: Getter function for property caseSensitity.

See also setCaseSensitivity()

[signal] void KTreeWidgetSearchLine::caseSensitivityChanged(Qt::CaseSensitivity caseSensitivity)

Note: Notifier signal for property caseSensitity.

[virtual protected] void KTreeWidgetSearchLine::connectTreeWidget(QTreeWidget *)

Connects signals of this listview to the appropriate slots of the search line.

[virtual protected] void KTreeWidgetSearchLine::disconnectTreeWidget(QTreeWidget *)

Disconnects signals of a listviews from the search line.

[signal] void KTreeWidgetSearchLine::hiddenChanged(QTreeWidgetItem *, bool)

This signal is emitted whenever an item gets hidden or unhidden due to it not matching or matching the search string.

[virtual protected] bool KTreeWidgetSearchLine::itemMatches(const QTreeWidgetItem *item, const QString &pattern) const

Returns true if item matches the search pattern. This will be evaluated based on the value of caseSensitive(). This can be overridden in subclasses to implement more complicated matching schemes.

bool KTreeWidgetSearchLine::keepParentsVisible() const

If this is true (the default) then the parents of matched items will also be shown.

Note: Getter function for property keepParentsVisible.

See also setKeepParentsVisible()

[signal] void KTreeWidgetSearchLine::keepParentsVisibleChanged(bool keepParentsVisible)

Note: Notifier signal for property keepParentsVisible.

[slot] void KTreeWidgetSearchLine::removeTreeWidget(QTreeWidget *treeWidget)

Removes a QTreeWidget from the list of listviews filtered by this search line. Does nothing if treeWidget is 0 or is not filtered by the quick search line.

See also setTreeWidgets(), addTreeWidget()

QList<int> KTreeWidgetSearchLine::searchColumns() const

Returns the current list of columns that will be searched. If the returned list is empty all visible columns will be searched.

See also setSearchColumns

[signal] void KTreeWidgetSearchLine::searchUpdated(const QString &searchString)

This signal is emitted when user finished entering filter text or when he made a pause long enough, after the QTreeWidget items got filtered

searchString is the text currently entered by the user

[slot] void KTreeWidgetSearchLine::setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)

Make the search case sensitive or case insensitive.

Note: Setter function for property caseSensitity.

See also caseSensitivity()

[slot] void KTreeWidgetSearchLine::setKeepParentsVisible(bool value)

When a search is active on a list that's organized into a tree view if a parent or ancesestor of an item is does not match the search then it will be hidden and as such so too will any children that match.

If this is set to true (the default) then the parents of matching items will be shown.

Warning: setKeepParentsVisible(true) does not have the expected effect on items being added to or removed from the view while a search is active. When a new search starts afterwards the behavior will be normal.

Note: Setter function for property keepParentsVisible.

See also keepParentsVisible

[slot] void KTreeWidgetSearchLine::setSearchColumns(const QList<int> &columns)

Sets the list of columns to be searched. The default is to search all, visible columns which can be restored by passing columns as an empty list. If listviews to be filtered have different numbers or labels of columns this method has no effect.

See also searchColumns

[slot] void KTreeWidgetSearchLine::setTreeWidget(QTreeWidget *treeWidget)

Sets the QTreeWidget that is filtered by this search line, replacing any previously filtered listviews. If treeWidget is null then the widget will be disabled.

See also treeWidget(), setTreeWidgets()

[slot] void KTreeWidgetSearchLine::setTreeWidgets(const QList<QTreeWidget *> &treeWidgets)

Sets QTreeWidgets that are filtered by this search line, replacing any previously filtered listviews. If treeWidgets is empty then the widget will be disabled.

See also treeWidgets(), addTreeWidget(), setTreeWidget()

QTreeWidget *KTreeWidgetSearchLine::treeWidget() const

Returns the listview that is currently filtered by the search. If there are multiple listviews filtered, it returns 0.

See also setTreeWidget(), treeWidgets()

QList<QTreeWidget *> KTreeWidgetSearchLine::treeWidgets() const

Returns the list of pointers to listviews that are currently filtered by the search.

See also setTreeWidgets(), addTreeWidget(), treeWidget()

[virtual protected] void KTreeWidgetSearchLine::updateSearch(QTreeWidget *treeWidget)

Updates search to only make visible appropriate items in treeWidget.

If treeWidget is null then nothing is done.

[virtual slot] void KTreeWidgetSearchLine::updateSearch(const QString &pattern = QString())

Updates search to only make visible the items that match pattern. If s is null then the line edit's text will be used.

Note: This slot is overloaded. To connect to this slot:

// Connect using qOverload:
connect(sender, &SenderClass::signal,
        kTreeWidgetSearchLine, qOverload<const QString &>(&KTreeWidgetSearchLine::updateSearch));

// Or using a lambda as wrapper:
connect(sender, &SenderClass::signal,
        kTreeWidgetSearchLine, [receiver = kTreeWidgetSearchLine](const QString &pattern) { receiver->updateSearch(pattern); });

For more examples and approaches, see connecting to overloaded slots.

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.