All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | Static Public Member Functions
Qtilities::Core::QtilitiesFileInfo Class Reference

QtilitiesFileInfo is a class which extends QFileInfo with additional functionality. More...

#include <QtilitiesFileInfo.h>

List of all members.

Public Member Functions

QString absoluteToRelativeFilePath () const
 Gives the file path made absolute to relativeToPath().
QString absoluteToRelativePath () const
 Gives the path made absolute to relativeToPath().
QString actualFilePath () const
 Returns the actual file path without you needing to know if the file is relative or absolute.
QString actualPath () const
 Returns the actual path without you needing to know if the file is relative or absolute.
bool compareActualFilePaths (const QtilitiesFileInfo &ref) const
 Compares the actual file paths of QtilitiesFileInfo objects and returns true if they are the same, false otherwise.
bool hasRelativeToPath () const
 Indicates if a relative to path has been set.
bool operator!= (const QtilitiesFileInfo &ref) const
 Operator overload to compare two QtilitiesFileInfo objects are not equal.
bool operator== (const QtilitiesFileInfo &ref) const
 Operator overload to compare two QtilitiesFileInfo objects with each other.
 QtilitiesFileInfo (const QString &file=QString(), const QString &relative_to_path=QString())
 Constructs a new QtilitiesFileInfo that gives information about the given file.
QString relativeToPath () const
 Gets the relative to path of the file.
virtual void setFileName (const QString &new_file_name)
 Sets the the file name part of the file.
void setRelativeToPath (const QString &relative_to_path)
 Gets the relative to path of the file.
bool updateRelativeToPath (const QString &old_relative_to_path, const QString &new_relative_to_path)
 Replaces the relative to path if it matches the old relative to path.

Static Public Member Functions

static QString invalidFileNameCharacters ()
 Returns the invalid characters which are checked in isValidFileName() in a QString seperated by spaces.
static QString invalidFilePathCharacters ()
 Returns the invalid characters which are checked in isValidFilePath() in a QString seperated by spaces.
static bool isValidFileName (const QString file_name)
 Indicates if a file name is valid.
static bool isValidFilePath (const QString file_path)
 Indicates if a file path is valid.

Detailed Description

QtilitiesFileInfo is a class which extends QFileInfo with additional functionality.

QtilitiesFileInfo extends the way that QFileInfo handles relative files so that the path which relative to files are relative to can be specified. Normally QFileInfo::makeAbsolute() will make relative to paths relative to the application path. QtilitiesFileInfo allows you to specify the relative to path using setRelativeToPath() and provides a relativeToPath() access function. It is also possible to set the relativeToPath() as part of the constructor.

The actualPath() and actualFilePath() functions allows you to get the actual path of a file without needing to know if it is relative or not (for relative files, a relativeToPath must be specified to get the actual path).

Additional extended functions include:

The following example shows how the class works and you will notice that it is very close to QFileInfo, except for the additional functionality:

// Test 1: c:/relative_to_path/relative_path/file_name.tar.gz
QtilitiesFileInfo file_info("c:/relative_to_path/relative_path/file_name.tar.gz");
isAbsolute: true
isRelative: false
path: "c:/relative_to_path/relative_path"
filePath: "c:/relative_to_path/relative_path/file_name.tar.gz"
absolutePath: "C:/relative_to_path/relative_path"
canonicalPath: ""
actualPath: "c:/relative_to_path/relative_path"
baseName: "file_name"
completeBaseName: "file_name.tar"
suffix: "gz"
completeSuffix: "tar.gz"
// Test 2: relative_path/file_name.tar.gz
file_info.setFile("relative_path/file_name.tar.gz");
isAbsolute: false
isRelative: true
path: "relative_path"
filePath: "relative_path/file_name.tar.gz"
absolutePath: "D:/projects/Qt/Qtilities/trunk/bin/Examples/ConsoleLogging/relative_path"
canonicalPath: ""
absoluteToRelativePath: "/relative_path"
actualPath: "/relative_path"
baseName: "file_name"
completeBaseName: "file_name.tar"
suffix: "gz"
completeSuffix: "tar.gz"
// Test 3: relative_path/file_name.tar.gz with relative to path: c:/relative_to_path
file_info.setFile("relative_path/file_name.tar.gz");
file_info.setRelativeToPath("c:/relative_to_path");
isAbsolute: false
isRelative: true
path: "relative_path"
filePath: "relative_path/file_name.tar.gz"
absolutePath: "D:/projects/Qt/Qtilities/trunk/bin/Examples/ConsoleLogging/relative_path"
canonicalPath: ""
relativeToPath: "c:/relative_to_path"
absoluteToRelativePath: "c:/relative_to_path/relative_path"
actualPath: "c:/relative_to_path/relative_path"
baseName: "file_name"
completeBaseName: "file_name.tar"
suffix: "gz"
completeSuffix: "tar.gz"
// Test 4: ../relative_path/file_name.tar.gz with relative to path: c:/relative_to_path
file_info.setFile("../relative_path/file_name.tar.gz");
file_info.setRelativeToPath("c:/relative_to_path");
isAbsolute: false
isRelative: true
path: "../relative_path"
filePath: "../relative_path/file_name.tar.gz"
absolutePath: "D:/projects/Qt/Qtilities/trunk/bin/Examples/relative_path"
canonicalPath: ""
relativeToPath: "c:/relative_to_path"
absoluteToRelativePath: "c:/relative_path"
actualPath: "c:/relative_path"
baseName: "file_name"
completeBaseName: "file_name.tar"
suffix: "gz"
completeSuffix: "tar.gz"
// Test 5: ./relative_path/file_name.tar.gz with relative to path: c:/relative_to_path
file_info.setFile("./relative_path/file_name.tar.gz");
file_info.setRelativeToPath("c:/relative_to_path");
isAbsolute: false
isRelative: true
path: "./relative_path"
filePath: "./relative_path/file_name.tar.gz"
absolutePath: "D:/projects/Qt/Qtilities/trunk/bin/Examples/ConsoleLogging/relat
ive_path"
canonicalPath: ""
relativeToPath: "c:/relative_to_path"
absoluteToRelativePath: "c:/relative_to_path/relative_path"
actualPath: "c:/relative_to_path/relative_path"
baseName: "file_name"
completeBaseName: "file_name.tar"
suffix: "gz"
completeSuffix: "tar.gz"
// Test 6: .././relative_path/file_name.tar.gz with relative to path: c:/relative_to_path"
file_info.setFile(".././relative_path/file_name.tar.gz");
file_info.setRelativeToPath("c:/relative_to_path");
isAbsolute: false
isRelative: true
path: ".././relative_path"
filePath: ".././relative_path/file_name.tar.gz"
absolutePath: "D:/projects/Qt/Qtilities/trunk/bin/Examples/relative_path"
canonicalPath: ""
relativeToPath: "c:/relative_to_path"
absoluteToRelativePath: "c:/relative_path"
actualPath: "c:/relative_path"
baseName: "file_name"
completeBaseName: "file_name.tar"
suffix: "gz"
completeSuffix: "tar.gz"

In the same way that QFileInfo handles Unix file names, the above example will always begin with the root, '/', directory.

This class was added in Qtilities v1.0.


Constructor & Destructor Documentation

Qtilities::Core::QtilitiesFileInfo::QtilitiesFileInfo ( const QString &  file = QString(),
const QString &  relative_to_path = QString() 
)

Constructs a new QtilitiesFileInfo that gives information about the given file.

Parameters:
fileThe file for which information is required.
relative_to_pathA path that indicates to what file is relative to if it is a relative to path.

Member Function Documentation

QString Qtilities::Core::QtilitiesFileInfo::absoluteToRelativeFilePath ( ) const

Gives the file path made absolute to relativeToPath().

This function only does something is the file is relative.

See also:
absoluteToRelativePath()
QString Qtilities::Core::QtilitiesFileInfo::absoluteToRelativePath ( ) const

Gives the path made absolute to relativeToPath().

This function only does something is the file is relative.

See also:
absoluteToRelativeFilePath()
QString Qtilities::Core::QtilitiesFileInfo::actualFilePath ( ) const

Returns the actual file path without you needing to know if the file is relative or absolute.

This function will return the file actual path of the file in the following way:

See also:
actualPath()
QString Qtilities::Core::QtilitiesFileInfo::actualPath ( ) const

Returns the actual path without you needing to know if the file is relative or absolute.

This function will return the actual path of the file in the following way:

See also:
actualFilePath()
bool Qtilities::Core::QtilitiesFileInfo::hasRelativeToPath ( ) const

Indicates if a relative to path has been set.

See also:
setRelativeToPath(), relativeToPath()
static QString Qtilities::Core::QtilitiesFileInfo::invalidFileNameCharacters ( )
inlinestatic

Returns the invalid characters which are checked in isValidFileName() in a QString seperated by spaces.

See also:
isValidFileisValidFileNamePath()
static QString Qtilities::Core::QtilitiesFileInfo::invalidFilePathCharacters ( )
inlinestatic

Returns the invalid characters which are checked in isValidFilePath() in a QString seperated by spaces.

See also:
isValidFilePath()
bool Qtilities::Core::QtilitiesFileInfo::isValidFileName ( const QString  file_name)
static

Indicates if a file name is valid.

Checks if the file name is valid. Thus checks that it does not contain any of the following characters:

\ / : * ? " < > |
bool Qtilities::Core::QtilitiesFileInfo::isValidFilePath ( const QString  file_path)
static

Indicates if a file path is valid.

Checks if the file name is valid. Thus checks that it does not contain any of the following characters:

: * ? " < > |
bool Qtilities::Core::QtilitiesFileInfo::operator!= ( const QtilitiesFileInfo ref) const

Operator overload to compare two QtilitiesFileInfo objects are not equal.

Note:
This overload does a comparison using the actualFilePath() paths of the two objects being compared.

This function was added in Qtilities v1.2.

bool Qtilities::Core::QtilitiesFileInfo::operator== ( const QtilitiesFileInfo ref) const

Operator overload to compare two QtilitiesFileInfo objects with each other.

Note:
This overload does a comparison using the actualFilePath() paths of the two objects being compared.

This function was added in Qtilities v1.2.

QString Qtilities::Core::QtilitiesFileInfo::relativeToPath ( ) const

Gets the relative to path of the file.

See also:
setRelativeToPath(), hasRelativeToPath()
void Qtilities::Core::QtilitiesFileInfo::setFileName ( const QString &  new_file_name)
virtual

Sets the the file name part of the file.

See also:
QFileInfofileName()
void Qtilities::Core::QtilitiesFileInfo::setRelativeToPath ( const QString &  relative_to_path)

Gets the relative to path of the file.

See also:
relativeToPath(), hasRelativeToPath()
bool Qtilities::Core::QtilitiesFileInfo::updateRelativeToPath ( const QString &  old_relative_to_path,
const QString &  new_relative_to_path 
)

Replaces the relative to path if it matches the old relative to path.

updateRelateiveToPath

Parameters:
old_relative_to_pathThe old relative to path that must be matched in order for the update operation to happen.
new_relative_to_pathThe replacement relative to path.
Returns:
True if the update was performed, false otherwise.

This function was added in Qtilities v1.2.



Qtilities : Reference Documentation Back to top Copyright © 2009-2013, Jaco Naudé