diff options
author | Thomas Sondergaard <ts@medical-insight.com> | 2011-04-04 09:40:46 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-04-04 10:21:50 (GMT) |
commit | 0cf75b4dd1cc25694de8ece4c25ecb97a3969a54 (patch) | |
tree | 0724f3cb6b84f5fcbec493860c084e2d5442bb2d /src/corelib/io | |
parent | 0c291498c3cf1aa254df41ce99f249e2116da025 (diff) | |
download | Qt-0cf75b4dd1cc25694de8ece4c25ecb97a3969a54.zip Qt-0cf75b4dd1cc25694de8ece4c25ecb97a3969a54.tar.gz Qt-0cf75b4dd1cc25694de8ece4c25ecb97a3969a54.tar.bz2 |
Add methods for traversing and combining QProcessEnvironment.
New methods that make QProcessEnvironment more friendly. With these
two new functions developers no longer have to resort to using
QStringList and use the deprecated QProcess::setEnvironment() method.
New methods:
- QStringList QProcessEnvironment::keys()
- void QProcessEnvironment::insert(const QProcessEnvironment &).
Merge-request: 1152
Reviewed-by: ossi
Reviewed-by: thiago
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qprocess.cpp | 45 | ||||
-rw-r--r-- | src/corelib/io/qprocess.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qprocess_p.h | 2 |
3 files changed, 51 insertions, 0 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index e11cef9..db41a55 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -221,6 +221,24 @@ QProcessEnvironment QProcessEnvironmentPrivate::fromList(const QStringList &list return env; } +QStringList QProcessEnvironmentPrivate::keys() const +{ + QStringList result; + QHash<Unit, Unit>::ConstIterator it = hash.constBegin(), + end = hash.constEnd(); + for ( ; it != end; ++it) + result << nameToString(it.key()); + return result; +} + +void QProcessEnvironmentPrivate::insert(const Hash &h) +{ + QHash<Unit, Unit>::ConstIterator it = h.constBegin(), + end = h.constEnd(); + for ( ; it != end; ++it) + hash.insert(it.key(), it.value()); +} + /*! Creates a new QProcessEnvironment object. This constructor creates an empty environment. If set on a QProcess, this will cause the current @@ -396,6 +414,33 @@ QStringList QProcessEnvironment::toStringList() const return d ? d->toList() : QStringList(); } +/*! + \since 4.8 + + Returns a list containing all the variable names in this QProcessEnvironment + object. +*/ +QStringList QProcessEnvironment::keys() const +{ + return d ? d->keys() : QStringList(); +} + +/*! + \overload + \since 4.8 + + Inserts the contents of \a e in this QProcessEnvironment object. Variables in + this object that also exist in \a e will be overwritten. +*/ +void QProcessEnvironment::insert(const QProcessEnvironment &e) +{ + if (!e.d) + return; + + // d detaches from null + d->insert(e.d->hash); +} + void QProcessPrivate::Channel::clear() { switch (type) { diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h index baa67f7..664992f 100644 --- a/src/corelib/io/qprocess.h +++ b/src/corelib/io/qprocess.h @@ -87,6 +87,10 @@ public: QStringList toStringList() const; + QStringList keys() const; + + void insert(const QProcessEnvironment &e); + static QProcessEnvironment systemEnvironment(); private: diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h index be4f2a0..7bfcb31 100644 --- a/src/corelib/io/qprocess_p.h +++ b/src/corelib/io/qprocess_p.h @@ -94,6 +94,8 @@ public: static QProcessEnvironment fromList(const QStringList &list); QStringList toList() const; + QStringList keys() const; + void insert(const Hash &hash); }; class QProcessPrivate : public QIODevicePrivate |