QGIS API Documentation 3.41.0-Master (1deb1daf037)
Loading...
Searching...
No Matches
qgstiledsceneconnectiondialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgstiledsceneconnectiondialog.cpp
3 ---------------------
4 begin : June 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgstiledsceneconnectiondialog.cpp"
19#include "qgsgui.h"
20#include "qgssettings.h"
21
22#include <QMessageBox>
23#include <QPushButton>
24
26
27QgsTiledSceneConnectionDialog::QgsTiledSceneConnectionDialog( QWidget *parent )
28 : QDialog( parent )
29{
30 setupUi( this );
32
33 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
34
35 connect( mEditName, &QLineEdit::textChanged, this, &QgsTiledSceneConnectionDialog::updateOkButtonState );
36 connect( mEditUrl, &QLineEdit::textChanged, this, &QgsTiledSceneConnectionDialog::updateOkButtonState );
37}
38
39void QgsTiledSceneConnectionDialog::setConnection( const QString &name, const QString &uri )
40{
41 mEditName->setText( name );
42 mOriginalConnectionName = name;
43
45 mEditUrl->setText( conn.url );
46
47 mAuthSettings->setUsername( conn.username );
48 mAuthSettings->setPassword( conn.password );
49 mEditReferer->setText( conn.httpHeaders[QgsHttpHeaders::KEY_REFERER].toString() );
50 mAuthSettings->setConfigId( conn.authCfg );
51}
52
53QString QgsTiledSceneConnectionDialog::connectionUri() const
54{
56 conn.url = mEditUrl->text();
57
58 conn.username = mAuthSettings->username();
59 conn.password = mAuthSettings->password();
60 conn.httpHeaders[QgsHttpHeaders::KEY_REFERER] = mEditReferer->text();
61 conn.authCfg = mAuthSettings->configId();
62
64}
65
66QString QgsTiledSceneConnectionDialog::connectionName() const
67{
68 return mEditName->text();
69}
70
71void QgsTiledSceneConnectionDialog::updateOkButtonState()
72{
73 const bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
74 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
75}
76
77void QgsTiledSceneConnectionDialog::accept()
78{
79 const QString newConnectionName = mEditName->text();
80
81 // on rename delete original entry first
82 if ( !mOriginalConnectionName.isNull() && mOriginalConnectionName != newConnectionName )
83 {
84 QgsSettings settings;
85 QgsTiledSceneProviderConnection( QString() ).remove( mOriginalConnectionName );
86 settings.sync();
87 }
88
89 QDialog::accept();
90}
91
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition qgsgui.cpp:210
static const QString KEY_REFERER
Used in settings as the referer key.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
void sync()
Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in t...
Represents connections to tiled scene data sources.
virtual void remove(const QString &name) const override
Deletes the connection from the settings.
static Data decodedUri(const QString &uri)
Returns a connection uri decoded to a data structure.
static QString encodedUri(const Data &data)
Returns connection data encoded as a string.
Represents decoded data of a tiled scene connection.
QString authCfg
Authentication configuration ID.