Skip to content

Commit

Permalink
fix: indent, doc, typo
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdm-oslandia authored and nyalldawson committed Dec 2, 2021
1 parent 345dd4d commit c1582ce
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 32 deletions.
36 changes: 28 additions & 8 deletions python/core/auto_generated/network/qgshttpheaders.sip.in
Expand Up @@ -26,38 +26,58 @@ This class implements simple http header management.

QgsHttpHeaders( const QMap<QString, QVariant> &headers );
%Docstring
Copy constructor
@param headers
constructor from map

:param headers:
%End

QgsHttpHeaders();
%Docstring
default constructor
%End

QgsHttpHeaders( const QgsSettings &settings, const QString &key = QString() );
%Docstring
constructor from ``:py:class:`QgsSettings```

:param settings:
:param key:
%End

virtual ~QgsHttpHeaders();

bool updateNetworkRequest( QNetworkRequest &request ) const;
%Docstring
update the ``request`` by adding all the http headers
@param request
@return true if the update succeed

:param request:

:return: true if the update succeed
%End

void updateSettings( QgsSettings &settings, const QString &key = QString() ) const;
%Docstring
update the ``settings`` by adding all the http headers in the path "key/KEY_PREFIX/"
@param settings
@param key sub group path

:param settings:
:param key: sub group path
%End

void setFromSettings( const QgsSettings &settings, const QString &key = QString() );
%Docstring
loads headers from the ``settings``
@param settings
@param key sub group path

:param settings:
:param key: sub group path
%End

QVariant &operator[]( const QString &key );

QList<QString> keys() const;
%Docstring

:return: the list of all http header key
%End


};
Expand Down
31 changes: 29 additions & 2 deletions python/gui/auto_generated/qgshttpheaderwidget.sip.in
Expand Up @@ -8,26 +8,53 @@





class QgsHttpHeaderWidget : QWidget
{
%Docstring(signature="appended")
Display referer http header field and collapsible table of key/value pairs

.. versionadded:: 3.22
%End

%TypeHeaderCode
#include "qgshttpheaderwidget.h"
%End
public:

explicit QgsHttpHeaderWidget( QWidget *parent = 0 );
%Docstring
Default constructor

:param parent: parent widget
%End
~QgsHttpHeaderWidget();

QgsHttpHeaders httpHeaders() const;
%Docstring

:return: build a new ``:py:class:`QgsHttpHeaders``` according to data in the UI
%End

void setFromSettings( const QgsSettings &settings, const QString &key );
%Docstring
mRefererLineEdit->setText( settings.value( key + "/referer" ).toString() ); */
fill the inner header map from the settings defined at ``key``

.. seealso:: :py:func:`QgsHttpHeaders.setFromSettings`

:param settings:
:param key:
%End

void updateSettings( QgsSettings &settings, const QString &key ) const;
%Docstring
settings.setValue( key + "/referer", mRefererLineEdit->:py:func:`~QgsHttpHeaderWidget.text` ); */
update the ``settings`` with the http headers present in the inner map.

.. seealso:: :py:func:`QgsHttpHeaders.updateSettings`

:param settings:
:param key:
%End

};
Expand Down
2 changes: 1 addition & 1 deletion src/core/network/qgshttpheaders.cpp
Expand Up @@ -5,7 +5,7 @@
-------------------
begin : 2021-09-09
copyright : (C) 2021 B. De Mezzo
email : benoit.de.mezzo@oslandia.com
email : benoit dot de dot mezzo at oslandia dot com
***************************************************************************/

Expand Down
46 changes: 34 additions & 12 deletions src/core/network/qgshttpheaders.h
Expand Up @@ -5,7 +5,7 @@
-------------------
begin : 2021-09-09
copyright : (C) 2021 B. De Mezzo
email : benoit.de.mezzo@oslandia.com
email : benoit dot de dot mezzo at oslandia dot com
***************************************************************************/

Expand Down Expand Up @@ -42,41 +42,63 @@ class CORE_EXPORT QgsHttpHeaders
static const QString KEY_PREFIX;

/**
* @brief Copy constructor
* @param headers
* \brief constructor from map
* \param headers
*/
QgsHttpHeaders( const QMap<QString, QVariant> &headers );

/**
* \brief default constructor
*/
QgsHttpHeaders();

/**
* \brief constructor from \a QgsSettings
* \param settings
* \param key
*/
QgsHttpHeaders( const QgsSettings &settings, const QString &key = QString() );

virtual ~QgsHttpHeaders();

/**
* @brief update the \a request by adding all the http headers
* @param request
* @return true if the update succeed
* \brief update the \a request by adding all the http headers
* \param request
* \return true if the update succeed
*/
bool updateNetworkRequest( QNetworkRequest &request ) const;

/**
* @brief update the \a settings by adding all the http headers in the path "key/KEY_PREFIX/"
* @param settings
* @param key sub group path
* \brief update the \a settings by adding all the http headers in the path "key/KEY_PREFIX/"
* \param settings
* \param key sub group path
*/
void updateSettings( QgsSettings &settings, const QString &key = QString() ) const;

/**
* @brief loads headers from the \a settings
* @param settings
* @param key sub group path
* \brief loads headers from the \a settings
* \param settings
* \param key sub group path
*/
void setFromSettings( const QgsSettings &settings, const QString &key = QString() );

/**
* \param key http header key name
* \return http header value
*/
QVariant &operator[]( const QString &key );

/**
* \return the list of all http header key
*/
QList<QString> keys() const;

#ifndef SIP_RUN

/**
* \param key http header key name
* \return http header value
*/
const QVariant operator[]( const QString &key ) const;
#endif

Expand Down
25 changes: 20 additions & 5 deletions src/gui/qgshttpheaderwidget.cpp
@@ -1,3 +1,23 @@
/***************************************************************************
qgshttpheaderswidget.cpp
This class implements simple UI for http header.
-------------------
begin : 2021-09-09
copyright : (C) 2021 B. De Mezzo
email : benoit dot de dot mezzo at oslandia dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgshttpheaderwidget.h"
#include "ui_qgshttpheaderwidget.h"

Expand Down Expand Up @@ -77,8 +97,6 @@ void QgsHttpHeaderWidget::setFromSettings( const QgsSettings &settings, const QS
// load headers from settings
QgsHttpHeaders headers;
headers.setFromSettings( settings, key );
printf("In QgsHttpHeaderWidget::setFromSettings: headers[referer]:'%s'\n",
headers["referer"].toString().toStdString().c_str());

// push headers to table
tblwdgQueryPairs->clearContents();
Expand All @@ -104,7 +122,4 @@ void QgsHttpHeaderWidget::updateSettings( QgsSettings &settings, const QString &
{
QgsHttpHeaders h = httpHeaders();
h.updateSettings( settings, key );
printf("In QgsHttpHeaderWidget::updateSettings: h[referer]:'%s', settings:'%s'\n",
h["referer"].toString().toStdString().c_str(),
settings.value( key + "referer" ).toString().toStdString().c_str());
}
61 changes: 59 additions & 2 deletions src/gui/qgshttpheaderwidget.h
@@ -1,3 +1,23 @@
/***************************************************************************
qgshttpheaderswidget.h
This class implements simple UI for http header.
-------------------
begin : 2021-09-09
copyright : (C) 2021 B. De Mezzo
email : benoit dot de dot mezzo at oslandia dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSHTTPHEADERWIDGET_H
#define QGSHTTPHEADERWIDGET_H

Expand All @@ -6,25 +26,62 @@
#include "qgshttpheaders.h"


/**
* \ingroup gui
* \class QgsHttpHeaderWidget
* \brief Display referer http header field and collapsible table of key/value pairs
*
* \since QGIS 3.22
*/
class GUI_EXPORT QgsHttpHeaderWidget : public QWidget, private Ui::QgsHttpHeaderWidget
{
Q_OBJECT

public:

/**
* Default constructor
* \param parent parent widget
*/
explicit QgsHttpHeaderWidget( QWidget *parent = nullptr );
~QgsHttpHeaderWidget();

/**
* \return build a new \a QgsHttpHeaders according to data in the UI
*/
QgsHttpHeaders httpHeaders() const;

/* mRefererLineEdit->setText( settings.value( key + "/referer" ).toString() ); */
/**
* \brief fill the inner header map from the settings defined at \a key
* \see QgsHttpHeaders::setFromSettings( const QgsSettings &settings, const QString &key )
* \param settings
* \param key
*/
void setFromSettings( const QgsSettings &settings, const QString &key );

/* settings.setValue( key + "/referer", mRefererLineEdit->text() ); */
/**
* \brief update the \a settings with the http headers present in the inner map.
* \see QgsHttpHeaders::updateSettings( QgsSettings &settings, const QString &key ) const
* \param settings
* \param key
*/
void updateSettings( QgsSettings &settings, const QString &key ) const;

private slots:

/**
* create qt signal/slot connections
*/
void setupConnections();

/**
* add a new key/value http header pair in the table
*/
void addQueryPair();

/**
* remove a key/value http header pair from the table
*/
void removeQueryPair();

private:
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgshttpheaders.cpp
Expand Up @@ -83,8 +83,8 @@ void TestQgsHttpheaders::updateSettings()
QCOMPARE( settings.value( keyBase + QgsHttpHeaders::KEY_PREFIX + "referer" ).toString(), "http://gg.com" );
QVERIFY( ! settings.contains( keyBase + "referer" ) );

// test backward compability
settings.setValue( keyBase + "referer", "paf" ) ; // legacy referer, should be overriden
// test backward compatibility
settings.setValue( keyBase + "referer", "paf" ) ; // legacy referer, should be overridden
h.updateSettings( settings, keyBase );
QVERIFY( settings.contains( keyBase + QgsHttpHeaders::KEY_PREFIX + "referer" ) );
QCOMPARE( settings.value( keyBase + QgsHttpHeaders::KEY_PREFIX + "referer" ).toString(), "http://gg.com" );
Expand Down

0 comments on commit c1582ce

Please sign in to comment.