LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
LC::Util::UrlOperator Class Reference

Manipulates query part of an QUrl object. More...

#include "urloperator.h"

Public Member Functions

 UrlOperator (QUrl &url)
 Constructs the object modifying the query of url. More...
 
 ~UrlOperator ()
 Flushes any pending changes to the QUrl query and destroys the UrlOperator. More...
 
void Flush ()
 Flushes any pending changes to the QUrl query. More...
 
UrlOperatoroperator() (const QString &key, const QString &value)
 Adds a new key = value parameters pair. More...
 
UrlOperatoroperator() (const QString &key, const QByteArray &value)
 Adds a new key = value parameters pair. More...
 
UrlOperatoroperator() (const QString &key, const char *value)
 Adds a new key = value parameters pair. More...
 
UrlOperatoroperator() (const QString &key, int value)
 Adds a new key = value parameters pair. More...
 
template<typename Key , typename Value >
UrlOperatoroperator() (bool condition, Key &&key, Value &&value)
 
UrlOperatoroperator-= (const QString &key)
 Returns the first query parameter under the key. More...
 
QUrl operator() ()
 Flushes any pending changes to the QUrl query. More...
 

Detailed Description

Manipulates query part of an QUrl object.

This class abstracts away differences between Qt4 and Qt5 QUrl and QUrlQuery handling, and it should be used in all new code instead of direct calls to Qt API.

This class is used as follows:

  1. An object of this class is constructed on a (named) QUrl object.
  2. New URL query parameters are added by calling this object with a pair of matching key and value.
  3. Existing URL query parameters are removed via the -= operator.
  4. The URL is updated on UrlOperator object destruction.

Intended usage:

QUrl someUrl { ... };
UrlOperator { someUrl }
("key1", "value1")
("key2", "value2");

Here, an unnamed UrlOperator object is created that is valid only inside the corresponding expression, thus the changes to someUrl are visible immediately after executing that line.

Note
The changes are guaranteed to be applied on UrlOperator object destruction. Nevertheless, they may still be applied earlier on during calls to operator()() and operator-=().

Definition at line 60 of file urloperator.h.

Constructor & Destructor Documentation

◆ UrlOperator()

LC::Util::UrlOperator::UrlOperator ( QUrl &  url)

Constructs the object modifying the query of url.

Parameters
[in]urlThe URL to modify.

Definition at line 27 of file urloperator.cpp.

◆ ~UrlOperator()

LC::Util::UrlOperator::~UrlOperator ( )

Flushes any pending changes to the QUrl query and destroys the UrlOperator.

See also
Flush()
operator()()

Definition at line 33 of file urloperator.cpp.

Member Function Documentation

◆ Flush()

void LC::Util::UrlOperator::Flush ( )

Flushes any pending changes to the QUrl query.

Definition at line 38 of file urloperator.cpp.

Referenced by operator()().

+ Here is the caller graph for this function:

◆ operator()() [1/6]

QUrl LC::Util::UrlOperator::operator() ( )

Flushes any pending changes to the QUrl query.

Definition at line 70 of file urloperator.cpp.

◆ operator()() [2/6]

template<typename Key , typename Value >
UrlOperator& LC::Util::UrlOperator::operator() ( bool  condition,
Key &&  key,
Value &&  value 
)
inline

Definition at line 148 of file urloperator.h.

◆ operator()() [3/6]

UrlOperator & LC::Util::UrlOperator::operator() ( const QString &  key,
const char *  value 
)

Adds a new key = value parameters pair.

If the URL already contains this key, a new value is added in addition to the already existing one.

The value is considered to be a Latin1-string.

This overload is provided for convenience and efficiency.

Parameters
[in]keyThe query parameter key.
[in]valueThe query parameter value (a Latin1-string).
Returns
This UrlOperator object.

Definition at line 54 of file urloperator.cpp.

◆ operator()() [4/6]

UrlOperator & LC::Util::UrlOperator::operator() ( const QString &  key,
const QByteArray &  value 
)

Adds a new key = value parameters pair.

If the URL already contains this key, a new value is added in addition to the already existing one.

This overload is provided for convenience and efficiency.

Parameters
[in]keyThe query parameter key.
[in]valueThe query parameter value.
Returns
This UrlOperator object.

Definition at line 49 of file urloperator.cpp.

◆ operator()() [5/6]

UrlOperator & LC::Util::UrlOperator::operator() ( const QString &  key,
const QString &  value 
)

Adds a new key = value parameters pair.

If the URL already contains this key, a new value is added in addition to the already existing one.

The key/value pair is encoded before it is added to the query. The key and value are also encoded into UTF-8. Both key and value are URL-encoded as well. So, this function is analogous in effect to standard relevant Qt APIs.

Parameters
[in]keyThe query parameter key.
[in]valueThe query parameter value.
Returns
This UrlOperator object.

Definition at line 43 of file urloperator.cpp.

◆ operator()() [6/6]

UrlOperator & LC::Util::UrlOperator::operator() ( const QString &  key,
int  value 
)

Adds a new key = value parameters pair.

If the URL already contains this key, a new value is added in addition to the already existing one.

This overload is provided for convenience and efficiency.

Parameters
[in]keyThe query parameter key.
[in]valueThe query parameter value.
Returns
This UrlOperator object.

Definition at line 59 of file urloperator.cpp.

References Flush().

+ Here is the call graph for this function:

◆ operator-=()

UrlOperator & LC::Util::UrlOperator::operator-= ( const QString &  key)

Returns the first query parameter under the key.

If no such parameters exist, this function does nothing.

Parameters
[in]keyThe query parameter key.
Returns
This UrlOperator object.

Definition at line 64 of file urloperator.cpp.


The documentation for this class was generated from the following files:
LC::Util::UrlOperator::UrlOperator
UrlOperator(QUrl &url)
Constructs the object modifying the query of url.
Definition: urloperator.cpp:27