Add QUrl::setQuery overload with QUrlQuery
authorThiago Macieira <thiago.macieira@intel.com>
Wed, 19 Oct 2011 23:23:14 +0000 (01:23 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 29 Mar 2012 23:19:59 +0000 (01:19 +0200)
Change-Id: I0cba92b6bf7f848f1918383b380c0444b8bead3a
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
src/corelib/io/qurl.cpp
src/corelib/io/qurl.h
src/corelib/io/qurlquery.h

index 36411a0..62d6092 100644 (file)
 #include "qdir.h"         // for QDir::fromNativeSeparators
 #include "qtldurl_p.h"
 #include "private/qipaddress_p.h"
+#include "qurlquery.h"
 #if defined(Q_OS_WINCE_WM)
 #pragma optimize("g", off)
 #endif
@@ -1725,6 +1726,18 @@ void QUrl::setQuery(const QString &query)
         d->sectionIsPresent &= ~QUrlPrivate::Query;
 }
 
+void QUrl::setQuery(const QUrlQuery &query)
+{
+    detach();
+
+    // we know the data is in the right format
+    d->query = query.toString();
+    if (query.isEmpty())
+        d->sectionIsPresent &= ~QUrlPrivate::Query;
+    else
+        d->sectionIsPresent |= QUrlPrivate::Query;
+}
+
 /*!
     Returns the query string of the URL in percent encoded form.
 */
index d96f9d1..a118a9d 100644 (file)
@@ -53,6 +53,7 @@ QT_BEGIN_HEADER
 QT_BEGIN_NAMESPACE
 
 
+class QUrlQuery;
 class QUrlPrivate;
 class QDataStream;
 
@@ -213,6 +214,7 @@ public:
 
     bool hasQuery() const;
     void setQuery(const QString &query);
+    void setQuery(const QUrlQuery &query);
     QString query(ComponentFormattingOptions = PrettyDecoded) const;
 
     bool hasFragment() const;
index 3e0baa3..ff66298 100644 (file)
@@ -116,9 +116,9 @@ Q_DECLARE_SHARED(QUrlQuery)
 
 #if QT_DEPRECATED_SINCE(5,0)
 inline void QUrl::setQueryItems(const QList<QPair<QString, QString> > &qry)
-{ QUrlQuery q(*this); q.setQueryItems(qry); setQuery(q.query()); }
+{ QUrlQuery q(*this); q.setQueryItems(qry); setQuery(q); }
 inline void QUrl::addQueryItem(const QString &key, const QString &value)
-{ QUrlQuery q(*this); q.addQueryItem(key, value); setQuery(q.query()); }
+{ QUrlQuery q(*this); q.addQueryItem(key, value); setQuery(q); }
 inline QList<QPair<QString, QString> > QUrl::queryItems() const
 { return QUrlQuery(*this).queryItems(); }
 inline bool QUrl::hasQueryItem(const QString &key) const
@@ -128,7 +128,7 @@ inline QString QUrl::queryItemValue(const QString &key) const
 inline QStringList QUrl::allQueryItemValues(const QString &key) const
 { return QUrlQuery(*this).allQueryItemValues(key); }
 inline void QUrl::removeQueryItem(const QString &key)
-{ QUrlQuery q(*this); q.removeQueryItem(key); setQuery(q.query()); }
+{ QUrlQuery q(*this); q.removeQueryItem(key); setQuery(q); }
 inline void QUrl::removeAllQueryItems(const QString &key)
 { QUrlQuery q(*this); q.removeAllQueryItems(key); }
 #endif