KFileFilter Class

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

Public Functions

KFileFilter()
KFileFilter(const QString &label, const QStringList &filePatterns, const QStringList &mimePatterns)
QStringList filePatterns() const
bool isEmpty() const
bool isValid() const
QString label() const
QStringList mimePatterns() const
QString toFilterString() const

Static Public Members

QList<KFileFilter> fromMimeTypes(const QStringList &mimeTypes)

Detailed Description

@class KFileFilter kfilefilter.h <KFileFilter>

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.

@since 5.101

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.

@param label The user-facing label for this filter. @param filePatterns A list of file name patterns that should be included, e.g. ("*.cpp", "*.cxx"). @param 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] 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.

@since 6.0

bool KFileFilter::isEmpty() const

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

bool KFileFilter::isValid() const

Whether the filter is valid.

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

@since 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