QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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 "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 setHeaders( headers );
106}
107
109{
110 // clean table
111 for ( int i = tblwdgQueryPairs->rowCount(); i > 0; i-- )
112 tblwdgQueryPairs->removeRow( i - 1 );
113
114 // push headers to table
115 QList<QString> lst = headers.keys();
116 for ( auto ite = lst.constBegin(); ite != lst.constEnd(); ++ite )
117 {
118 if ( ite->compare( "referer" ) != 0 )
119 {
120 addQueryPairRow( *ite, headers[ *ite ].toString() );
121 }
122 else
123 {
124 mRefererLineEdit->setText( headers[ *ite ].toString() );
125 }
126 }
127}
128
129void QgsHttpHeaderWidget::updateSettings( QgsSettings &settings, const QString &key ) const
130{
133 h.updateSettings( settings, key );
135}
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:63
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:4916
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:4915