Workspace 6.21.5
Public Member Functions | Static Public Member Functions | List of all members
DirectoryFilter Class Reference

Provides a platform-independent way to get a filtered directory listing.

#include <Workspace/Application/System/directoryfilter.h>

Public Member Functions

 DirectoryFilter (const DirectoryFilter &dirFilter)
 
 DirectoryFilter (const QString &dir="", const QString &filter="", bool isRegex=false)
 
 ~DirectoryFilter ()
 
const QString & getDirectory () const
 
const QString & getEntry (unsigned index) const
 
QString getEntrySubExpression (unsigned entryIndex, unsigned subexpressionIndex) const
 
const QString & getFilter () const
 
QString getFullPath (unsigned index) const
 
bool getIncludeHidden () const
 
unsigned getNumEntries () const
 
bool isDirectory (const QString &fileName) const
 
bool isFile (const QString &fileName) const
 
bool isReadable (const QString &fileName) const
 
bool isRegex () const
 
bool isSymbolicLink (const QString &fileName) const
 
bool isWritable (const QString &fileName) const
 
DirectoryFilteroperator= (const DirectoryFilter &dirFilter)
 
bool refresh ()
 
void setDirectory (const QString &dir)
 
void setFilter (const QString &filter, bool isRegex)
 
void setIncludeHidden (bool b)
 
void sort ()
 

Static Public Member Functions

static char getPathSeparator ()
 
static QString platformDependentPath (const QString &path)
 

Constructor & Destructor Documentation

◆ DirectoryFilter() [1/2]

DirectoryFilter ( const QString &  dir = "",
const QString &  filter = "",
bool  isRegex = false 
)
Parameters
dirThe directory to filter. The default value results in the current directory being used.
filterThe filter to use when reading the directory entries. If left unspecified, all entries will be returned (this is the default).
isRegexIf true, then filter should be treated as a regular expression. Otherwise, filter can only contain valid file name characters and the * and ? wildcards.

◆ DirectoryFilter() [2/2]

DirectoryFilter ( const DirectoryFilter dirFilter)

◆ ~DirectoryFilter()

Member Function Documentation

◆ getDirectory()

const QString & getDirectory ( ) const
Returns
The currently set directory. If this is an empty string, it is equivalent to using the current directory.

◆ getEntry()

const QString & getEntry ( unsigned  index) const
Parameters
indexThe array index to retrieve. No check is performed on whether this refers to a valid entry. It is the caller's responsibility to ensure that this is less than the value returned from getNumEntries().
Returns
The directory entry at the specified index.

◆ getEntrySubExpression()

QString getEntrySubExpression ( unsigned  entryIndex,
unsigned  subexpressionIndex 
) const
Parameters
entryIndexIndex of the entry to analyze.
subexpressionIndexIndex of the subexpression to return.
Returns
The string corresponding to the subexpressionIndex captured subexpression in the string for entry entryIndex. If no such entry exists or there is no subexpression at the specified subexpressionIndex, an empty string is returned. In debug mode, both of these conditions are protected by assertions, since it is considered a programming error to ask for an index which does not exists (either an entry or a subexpression index).

◆ getFilter()

const QString & getFilter ( ) const
Returns
The currently set filter. If this is an empty string, all directory entries will be returned.
See also
setFilter()

◆ getFullPath()

QString getFullPath ( unsigned  index) const
Parameters
indexThe array index to retrieve. No check is performed on whether this refers to a valid entry. It is the caller's responsibility to ensure that this is less than the value returned from getNumEntries().
Returns
The path of the directory entry at the specified index. This is essentially the same as concatenating the currently set directory with the file name at the specified entry index. An appropriate directory separator is inserted between the two. The path returned is guaranteed to use the correct path separators for the current platform.

◆ getIncludeHidden()

bool getIncludeHidden ( ) const

◆ getNumEntries()

unsigned getNumEntries ( ) const
Returns
The number of directory entries read in by the last call to refresh(). This will be zero if refresh() has not yet been called or if the last call to refresh() failed for some reason.

◆ getPathSeparator()

char getPathSeparator ( )
static
Returns
The platform-specific path separator.

◆ isDirectory()

bool isDirectory ( const QString &  fileName) const
Parameters
fileNameName of an entry in the currently set directory.
Returns
True if fileName is a subdirectory in the currently set directory.
Note
It is not necessary to have called refresh() before calling this function, although it will usually be used after such a call to test the entries found by refresh().

◆ isFile()

bool isFile ( const QString &  fileName) const
Parameters
fileNameName of an entry in the currently set directory.
Returns
True if fileName is a file or symbolic link in the currently set directory.
Note
It is not necessary to have called refresh() before calling this function, although it will usually be used after such a call to test the entries found by refresh().

◆ isReadable()

bool isReadable ( const QString &  fileName) const
Parameters
fileNameName of an entry in the currently set directory.
Returns
True if fileName is readable.
Note
It is not necessary to have called refresh() before calling this function, although it will usually be used after such a call to test the entries found by refresh().

◆ isRegex()

bool isRegex ( ) const
Returns
True if the currently set filter should be treated as a regular expression.
See also
setFilter()

◆ isSymbolicLink()

bool isSymbolicLink ( const QString &  fileName) const
Parameters
fileNameName of an entry in the currently set directory.
Returns
True if fileName is a symbolic link in the currently set directory (under Windows, this is a *.lnk file).
Note
It is not necessary to have called refresh() before calling this function, although it will usually be used after such a call to test the entries found by refresh().

◆ isWritable()

bool isWritable ( const QString &  fileName) const
Parameters
fileNameName of an entry in the currently set directory.
Returns
True if fileName is writable.
Note
It is not necessary to have called refresh() before calling this function, although it will usually be used after such a call to test the entries found by refresh().

◆ operator=()

DirectoryFilter & operator= ( const DirectoryFilter dirFilter)

◆ platformDependentPath()

QString platformDependentPath ( const QString &  path)
static
Parameters
pathThe path string to return as a platform dependent string.
Returns
The path with path separators converted to their platform-specific representation.

◆ refresh()

bool refresh ( )

Reads the currently set directory and fills the internal data cache with all directory entries which match the current filter.

Returns
True if the directory could be read, or false if there was an error (such as the directory didn't exist). If false is returned, the current contents cached internally will always be set to an empty list.
See also
getNumEntries(), getEntry()

◆ setDirectory()

void setDirectory ( const QString &  dir)
Parameters
dirThe new directory to use.

No check is performed on whether or not dir exists.

Postcondition
Entries from a previous call to refresh() will still be available.

◆ setFilter()

void setFilter ( const QString &  filter,
bool  isRegex 
)
Parameters
filterThe new directory filter to use.
isRegexIf true, then filter will be treated as a regular expression. Otherwise, it is assumed that it can only contain valid file name characters plus the * and ? wildcards.
Postcondition
Entries from a previous call to refresh() will still be available.

◆ setIncludeHidden()

void setIncludeHidden ( bool  b)

◆ sort()

void sort ( )

Sorts the last set of entries in ascending alphabetical order, with all uppercase appearing before lowercase entries as per the usual ASCII character ordering.