QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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 "moc_qgshttpheaderwidget.cpp"
23#include "ui_qgshttpheaderwidget.h"
24#include "qgsapplication.h"
25
26
28 : QWidget( parent )
29{
30 setupUi( this );
31 btnAddQueryPair->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/symbologyAdd.svg" ) ) );
32 btnRemoveQueryPair->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/symbologyRemove.svg" ) ) );
33 grpbxAdvanced->setCollapsed( true );
34
35 // Action and interaction connections
36 connect( btnAddQueryPair, &QToolButton::clicked, this, &QgsHttpHeaderWidget::addQueryPair );
37 connect( btnRemoveQueryPair, &QToolButton::clicked, this, &QgsHttpHeaderWidget::removeQueryPair );
38}
39
41
42void QgsHttpHeaderWidget::addQueryPairRow( const QString &key, const QString &val )
43{
44 const int rowCnt = tblwdgQueryPairs->rowCount();
45 tblwdgQueryPairs->insertRow( rowCnt );
46
47 const Qt::ItemFlags itemFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable
48 | Qt::ItemIsEditable | Qt::ItemIsDropEnabled;
49
50 QTableWidgetItem *keyItem = new QTableWidgetItem( key );
51 keyItem->setFlags( itemFlags );
52 tblwdgQueryPairs->setItem( rowCnt, 0, keyItem );
53
54 QTableWidgetItem *valueItem = new QTableWidgetItem( val );
55 valueItem->setFlags( itemFlags );
56 tblwdgQueryPairs->setItem( rowCnt, 1, valueItem );
57}
58
60{
61 QgsHttpHeaders querypairs;
62 for ( int i = 0; i < tblwdgQueryPairs->rowCount(); ++i )
63 {
64 if ( tblwdgQueryPairs->item( i, 0 )->text().isEmpty() )
65 {
66 continue;
67 }
68 querypairs [ tblwdgQueryPairs->item( i, 0 )->text() ] = QVariant( tblwdgQueryPairs->item( i, 1 )->text() ) ;
69 }
70
71 if ( !mRefererLineEdit->text().isEmpty() )
72 {
73 querypairs [ "referer" ] = QVariant( mRefererLineEdit->text() ) ;
74 }
75
76#if 0
77 for ( auto k : querypairs.keys() )
78 {
79 QgsLogger::debug( QString( "httpHeaders called: %1=%2" ).arg( k, querypairs[k].toString() ) );
80 }
81#endif
82
83 return querypairs;
84}
85
86
87void QgsHttpHeaderWidget::addQueryPair()
88{
89 addQueryPairRow( QString(), QString() );
90 tblwdgQueryPairs->setFocus();
91 tblwdgQueryPairs->setCurrentCell( tblwdgQueryPairs->rowCount() - 1, 0 );
92}
93
94
95void QgsHttpHeaderWidget::removeQueryPair()
96{
97 tblwdgQueryPairs->removeRow( tblwdgQueryPairs->currentRow() );
98}
99
100
101void QgsHttpHeaderWidget::setFromSettings( const QgsSettings &settings, const QString &key )
102{
103 // load headers from settings
104 QgsHttpHeaders headers;
105 headers.setFromSettings( settings, key );
106 setHeaders( headers );
107}
108
110{
111 // clean table
112 for ( int i = tblwdgQueryPairs->rowCount(); i > 0; i-- )
113 tblwdgQueryPairs->removeRow( i - 1 );
114
115 // push headers to table
116 QList<QString> lst = headers.keys();
117 for ( auto ite = lst.constBegin(); ite != lst.constEnd(); ++ite )
118 {
119 if ( ite->compare( "referer" ) != 0 )
120 {
121 addQueryPairRow( *ite, headers[ *ite ].toString() );
122 }
123 else
124 {
125 mRefererLineEdit->setText( headers[ *ite ].toString() );
126 }
127 }
128}
129
130void QgsHttpHeaderWidget::updateSettings( QgsSettings &settings, const QString &key ) const
131{
134 h.updateSettings( settings, key );
136}
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.
void setHeaders(const QgsHttpHeaders &headers)
Sets the widget from the headers.
Q_DECL_DEPRECATED void updateSettings(QgsSettings &settings, const QString &key) const SIP_DEPRECATED
update the settings with the http headers present in the inner map.
Q_DECL_DEPRECATED void setFromSettings(const QgsSettings &settings, const QString &key) SIP_DEPRECATED
fill the inner header map from the settings defined at key
QgsHttpHeaders httpHeaders() const
This class implements simple http header management.
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:59
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:6494
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6493