QVariant parse(const QString &value)
Try to convert a given value to a QPointF, QRectF, int or float.
-
function definition:
static QVariant parse(const QString &value);
-
parameters:
Parameter Type Description value const QString & String value to be converted. -
output: (QVariant) The converted file if a conversion was possible. Otherwise the unconverted string is returned.
- example:
QString point = "(1, 1)"; QString rect = "(1, 1, 5, 5)"; QString integer = "1"; QString fp = "1.0"; QString string = "Hello World"; File::parse(point); // returns QVariant(QPointF, QPointF(1, 1)) File::parse(rect); // returns QVariant(QRectF, QRectF(1, 1, 5x5)) File::parse(integer); // returns QVariant(int, 1) File::parse(fp); // returns QVariant(float, 1.0f) File::parse(string); // returns QVariant(QString, "Hello World")
QList<QVariant> values(const QList<U> &fileList, const QString &key)
Gather a list of QVariant values associated with a metadata key from a provided list of files.
-
function definition:
template<class U> static [QList<QVariant> values(const QList<U> &fileList, const QString &key)
-
parameters:
Parameter Type Description fileList const QList<U> & A list of files to parse for values. A type is required for U. Valid options are: key const QString & A metadata key used to lookup the values. -
output: (QList<QVariant>) A list of QVariant values associated with the given key in each of the provided files.
- example:
File f1, f2; f1.set("Key1", QVariant::fromValue<float>(1)); f1.set("Key2", QVariant::fromValue<float>(2)); f2.set("Key1", QVariant::fromValue<float>(3)); File::values<File>(QList<File>() << f1 << f2, "Key1"); // returns [QVariant(float, 1), // QVariant(float, 3)]
QList<T> get(const QList<U> &fileList, const QString &key)
Gather a list of T values associated with a metadata key from a provided list of files. T is a user provided type. If the key does not exist in the metadata of any file an error is thrown.
-
function definition:
template<class T, class U> static QList<T> get(const QList<U> &fileList, const QString &key)
-
parameters:
Parameter Type Description fileList const QList<U> & A list of files to parse for values. A type is required for U. Valid options are: key const QString & A metadata key used to lookup the values. -
output: (QList<T>) A list of the values of type T associated with the given key. A type is required for T.
- example:
File f1, f2; f1.set("Key1", QVariant::fromValue<float>(1)); f1.set("Key2", QVariant::fromValue<float>(2)); f2.set("Key1", QVariant::fromValue<float>(3)); File::get<float, File>(QList<File>() << f1 << f2, "Key1"); // returns [1., 3.] File::get<float, File>(QList<File>() << f1 << f2, "Key2"); // Error: Key doesn't exist in f2 File::get<QRectF, File>(QList<File>() << f1 << f2, "Key1"); // Error: float is not convertable to QRectF
QList<T> get(const QList<U> &fileList, const QString &key, const T &defaultValue)
Gather a list of T values associated with a metadata key from a provided list of files. T is a user provided type. If the key does not exist in the metadata of any file the provided defaultValue is used.
-
function definition:
template<class T, class U> static QList<T> get(const QList<U> &fileList, const QString &key, const T &defaultValue)
-
parameters:
Parameter Type Description fileList const QList<U> & A list of files to parse for values. A type is required for U. Valid options are: key const QString & A metadata key used to lookup the values. defaultValue const T & The default value if the key is not in a file's metadata. A type is required for T. All types are valid. -
output: (QList<T>) A list of the values of type T associated with the given key. A type is required for T.
-
example:
File f1, f2; f1.set("Key1", QVariant::fromValue
(1)); f1.set("Key2", QVariant::fromValue (2)); f2.set("Key1", QVariant::fromValue (3)); File::get
(QList () << f1 << f2, "Key1"); // returns [1., 3.] File::get (QList () << f1 << f2, "Key2", QList () << 1); // returns [1.] File::get (QList () << f1 << f2, "Key1, QList ()"); // returns []
QDebug operator <<(QDebug dbg, const File &file)
Calls flat on the given file and then streams that file to stderr.
-
function definition:
QDebug operator <<(QDebug dbg, const File &file)
-
parameter:
Parameter Type Description dbg QDebug The debug stream file const File & File to stream -
output: (QDebug &) returns a reference to the updated debug stream
- example:
File file("../path/to/pictures/picture.jpg"); file.set("Key", QString("Value")); qDebug() << file; // "../path/to/pictures/picture.jpg[Key=Value]" streams to stderr
QDataStream &operator <<(QDataStream &stream, const File &file)
Serialize a file to a data stream.
-
function definition:
QDataStream &operator <<(QDataStream &stream, const File &file)
-
parameters:
Parameter Type Description stream QDataStream The data stream file const File & File to stream -
output: (QDataStream &) returns a reference to the updated data stream
- example:
void store(QDataStream &stream) { File file("../path/to/pictures/picture.jpg"); file.set("Key", QString("Value")); stream << file; // "../path/to/pictures/picture.jpg[Key=Value]" serialized to the stream }
QDataStream &operator >>(QDataStream &stream, const File &file)
Deserialize a file from a data stream.
-
function definition:
QDataStream &operator >>(QDataStream &stream, const File &file)
-
parameters:
Parameter Type Description stream QDataStream The data stream file const File & File to stream -
output: (QDataStream &) returns a reference to the updated data stream
- example:
void load(QDataStream &stream) { File in("../path/to/pictures/picture.jpg"); in.set("Key", QString("Value")); stream << in; // "../path/to/pictures/picture.jpg[Key=Value]" serialized to the stream File out; stream >> out; out.name; // returns "../path/to/pictures/picture.jpg" out.flat(); // returns "../path/to/pictures/picture.jpg[Key=Value]" }