QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgshttpheaderwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgshttpheaderswidget.cpp
3 This class implements simple UI for http header.
4
5 -------------------
6 begin : 2021-09-09
7 copyright : (C) 2021 B. De Mezzo
8 email : benoit dot de dot mezzo at oslandia dot com
9
10***************************************************************************/
11
12/***************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 ***************************************************************************/
20
21#include "qgshttpheaderwidget.h"
22#include "ui_qgshttpheaderwidget.h"
23#include "qgsapplication.h"
24
25
27 : QWidget( parent )
28{
29 setupUi( this );
30 btnAddQueryPair->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/symbologyAdd.svg" ) ) );
31 btnRemoveQueryPair->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/symbologyRemove.svg" ) ) );
32 grpbxAdvanced->setCollapsed( true );
33
34 // Action and interaction connections
35 connect( btnAddQueryPair, &QToolButton::clicked, this, &QgsHttpHeaderWidget::addQueryPair );
36 connect( btnRemoveQueryPair, &QToolButton::clicked, this, &QgsHttpHeaderWidget::removeQueryPair );
37}
38
40
41void QgsHttpHeaderWidget::addQueryPairRow( const QString &key, const QString &val )
42{
43 const int rowCnt = tblwdgQueryPairs->rowCount();
44 tblwdgQueryPairs->insertRow( rowCnt );
45
46 const Qt::ItemFlags itemFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable
47 | Qt::ItemIsEditable | Qt::ItemIsDropEnabled;
48
49 QTableWidgetItem *keyItem = new QTableWidgetItem( key );
50 keyItem->setFlags( itemFlags );
51 tblwdgQueryPairs->setItem( rowCnt, 0, keyItem );
52
53 QTableWidgetItem *valueItem = new QTableWidgetItem( val );
54 valueItem->setFlags( itemFlags );
55 tblwdgQueryPairs->setItem( rowCnt, 1, valueItem );
56}
57
59{
60 QgsHttpHeaders querypairs;
61 for ( int i = 0; i < tblwdgQueryPairs->rowCount(); ++i )
62 {
63 if ( tblwdgQueryPairs->item( i, 0 )->text().isEmpty() )
64 {
65 continue;
66 }
67 querypairs [ tblwdgQueryPairs->item( i, 0 )->text() ] = QVariant( tblwdgQueryPairs->item( i, 1 )->text() ) ;
68 }
69
70 if ( !mRefererLineEdit->text().isEmpty() )
71 {
72 querypairs [ "referer" ] = QVariant( mRefererLineEdit->text() ) ;
73 }
74
75#if 0
76 for ( auto k : querypairs.keys() )
77 {
78 QgsLogger::debug( QString( "httpHeaders called: %1=%2" ).arg( k, querypairs[k].toString() ) );
79 }
80#endif
81
82 return querypairs;
83}
84
85
86void QgsHttpHeaderWidget::addQueryPair()
87{
88 addQueryPairRow( QString(), QString() );
89 tblwdgQueryPairs->setFocus();
90 tblwdgQueryPairs->setCurrentCell( tblwdgQueryPairs->rowCount() - 1, 0 );
91}
92
93
94void QgsHttpHeaderWidget::removeQueryPair()
95{
96 tblwdgQueryPairs->removeRow( tblwdgQueryPairs->currentRow() );
97}
98
99
100void QgsHttpHeaderWidget::setFromSettings( const QgsSettings &settings, const QString &key )
101{
102 // load headers from settings
103 QgsHttpHeaders headers;
104 headers.setFromSettings( settings, key );
105
106 // clean table
107 for ( int i = tblwdgQueryPairs->rowCount(); i > 0; i-- )
108 tblwdgQueryPairs->removeRow( i - 1 );
109
110 // push headers to table
111 QList<QString> lst = headers.keys();
112 for ( auto ite = lst.constBegin(); ite != lst.constEnd(); ++ite )
113 {
114 if ( ite->compare( "referer" ) != 0 )
115 {
116 addQueryPairRow( *ite, headers[ *ite ].toString() );
117 }
118 else
119 {
120 mRefererLineEdit->setText( headers[ *ite ].toString() );
121 }
122 }
123}
124
125void QgsHttpHeaderWidget::updateSettings( QgsSettings &settings, const QString &key ) const
126{
128 h.updateSettings( settings, key );
129}
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
QgsHttpHeaderWidget(QWidget *parent=nullptr)
Default constructor.
QgsHttpHeaders httpHeaders() const
void updateSettings(QgsSettings &settings, const QString &key) const
update the settings with the http headers present in the inner map.
void setFromSettings(const QgsSettings &settings, const QString &key)
fill the inner header map from the settings defined at key
This class implements simple http header management.
bool updateSettings(QgsSettings &settings, const QString &key=QString()) const
Updates the settings by adding all the http headers in the path "key/PATH_PREFIX/".
QList< QString > keys() const
void setFromSettings(const QgsSettings &settings, const QString &key=QString())
Loads headers from the settings.
static void debug(const QString &msg, int debuglevel=1, const char *file=nullptr, const char *function=nullptr, int line=-1)
Goes to qDebug.
Definition: qgslogger.cpp:58
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62