KFileFilter Class

Header: #include <KFileFilter>
CMake: find_package(KF6 REQUIRED COMPONENTS KIO)
target_link_libraries(mytarget PRIVATE KF6::KIOCore)
Since: 5.101

Public Functions

KFileFilter()
KFileFilter(const QString &label, const QStringList &filePatterns, const QStringList &mimePatterns)
QStringList filePatterns() const
bool isEmpty() const
(since 6.0) bool isValid() const
QString label() const
QStringList mimePatterns() const
QString toFilterString() const
bool operator==(const KFileFilter &other) const

Static Public Members

KFileFilter fromMimeType(const QString &mimeType)
(since 6.0) QList<KFileFilter> fromMimeTypes(const QStringList &mimeTypes)

Detailed Description

Encapsulates rules to filter a list of files. Files can be filtered based on name patterns (e.g. *.cpp), MIME types, or both. Filters also optionally have a user-facing label.

Member Function Documentation

[explicit] KFileFilter::KFileFilter()

Creates an empty filter.

[explicit] KFileFilter::KFileFilter(const QString &label, const QStringList &filePatterns, const QStringList &mimePatterns)

Creates a filter with a given label, name patterns, and MIME types.

label The user-facing label for this filter.

filePatterns A list of file name patterns that should be included, e.g. ("*.cpp", "*.cxx").

mimePatterns A list of MIME types that should be included, e.g. ("text/plain", "image/png").

QStringList KFileFilter::filePatterns() const

List of file name patterns that are included by this filter.

[static] KFileFilter KFileFilter::fromMimeType(const QString &mimeType)

Creates a filter for one MIME type. The user-facing label is automatically determined from the MIME type.

[static, since 6.0] QList<KFileFilter> KFileFilter::fromMimeTypes(const QStringList &mimeTypes)

Creates filters from a list of MIME types. The user-facing label is automatically determined from the MIME type.

This function was introduced in 6.0.

bool KFileFilter::isEmpty() const

Whether the filer is empty, i.e. matches all files.

[since 6.0] bool KFileFilter::isValid() const

Whether the filter is valid.

Creating a filter from an invalid/unkown MIME type will result in an invalid filter.

This function was introduced in 6.0.

QString KFileFilter::label() const

The user-facing label for this filter.

If no label is passed on creation one is created based on the patterns.

QStringList KFileFilter::mimePatterns() const

List of MIME types that are included by this filter;

QString KFileFilter::toFilterString() const

Converts this filter to a string representation

bool KFileFilter::operator==(const KFileFilter &other) const

Checks whether two filters are equal.

Filters are considered equal if their file and name patters match. The label is ignored here.