QGIS API Documentation 3.39.0-Master (3783037d301)
Loading...
Searching...
No Matches
qgsauthcerttrustpolicycombobox.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsauthcerttrustpolicycombobox.cpp
3 ---------------------
4 begin : May 02, 2015
5 copyright : (C) 2015 by Boundless Spatial, Inc. USA
6 author : Larry Shaffer
7 email : lshaffer at boundlessgeo dot com
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
18
19#include <QLineEdit>
20
21#include "qgsauthcertutils.h"
22#include "qgsauthguiutils.h"
23#include "qgsauthmanager.h"
24#include "qgslogger.h"
25#include "qgsapplication.h"
26
27
31 : QComboBox( parent )
32{
33 QList < QPair<QgsAuthCertUtils::CertTrustPolicy, QString> > policies;
34 policies << qMakePair( QgsAuthCertUtils::DefaultTrust,
35 defaultTrustText( defaultpolicy ) )
36 << qMakePair( QgsAuthCertUtils::Trusted,
38 << qMakePair( QgsAuthCertUtils::Untrusted,
40
41 for ( int i = 0; i < policies.size(); i++ )
42 {
43 const QgsAuthCertUtils::CertTrustPolicy polcy = policies.at( i ).first;
44 const QString name = policies.at( i ).second;
45 addItem( name, QVariant( static_cast<int>( polcy ) ) );
46 }
47
48 setItemData( 1, QgsAuthGuiUtils::greenColor(), Qt::ForegroundRole );
49 setItemData( 2, QgsAuthGuiUtils::redColor(), Qt::ForegroundRole );
50
51 // for styling closed state of combobox
52// setEditable( true );
53// lineEdit()->setReadOnly( true );
54
55 connect( this, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
56 this, &QgsAuthCertTrustPolicyComboBox::highlightCurrentIndex );
57
58 setTrustPolicy( policy );
59 setDefaultTrustPolicy( defaultpolicy );
60}
61
66
71
73{
74 const int idx = findData( QVariant( static_cast<int>( policy ) ) );
75 setCurrentIndex( idx == -1 ? 0 : idx );
76}
77
79{
80 const int idx = findData( QVariant( static_cast<int>( QgsAuthCertUtils::DefaultTrust ) ) );
81 setItemText( idx, defaultTrustText( defaultpolicy ) );
82}
83
84void QgsAuthCertTrustPolicyComboBox::highlightCurrentIndex( int indx )
85{
86 const QgsAuthCertUtils::CertTrustPolicy policy = ( QgsAuthCertUtils::CertTrustPolicy )itemData( indx ).toInt();
87 QString ss;
88
89 // TODO: why are these widget state selectors backwards?
90 switch ( policy )
91 {
93 // ss = QgsAuthCertUtils::greenTextStyleSheet( "QLineEdit" );
94 ss = QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QComboBox:open" ) ) + "\nQComboBox:!open{}";
95 break;
97 // ss = QgsAuthCertUtils::redTextStyleSheet( "QLineEdit" );
98 ss = QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QComboBox:open" ) ) + "\nQComboBox:!open{}";
99 break;
101 default:
102 break;
103 }
104 QgsDebugMsgLevel( QStringLiteral( "Set Stylesheet to : %1" ).arg( ss ), 2 );
105 // lineEdit()->setStyleSheet( ss );
106 setStyleSheet( ss );
107}
108
109const QString QgsAuthCertTrustPolicyComboBox::defaultTrustText( QgsAuthCertUtils::CertTrustPolicy defaultpolicy )
110{
111 if ( defaultpolicy == QgsAuthCertUtils::DefaultTrust )
112 {
113 if ( !QgsApplication::authManager()->isDisabled() )
114 {
116 }
117 else
118 {
119 defaultpolicy = QgsAuthCertUtils::Trusted;
120 }
121 }
122 return QStringLiteral( "%1 (%2)" )
124 QgsAuthCertUtils::getCertTrustName( defaultpolicy ) );
125}
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
QgsAuthCertUtils::CertTrustPolicy trustPolicyForIndex(int indx)
Gets trust policy for a given index of combobox.
QgsAuthCertUtils::CertTrustPolicy trustPolicy()
Gets currently set trust policy.
void setDefaultTrustPolicy(QgsAuthCertUtils::CertTrustPolicy defaultpolicy)
Sets default trust policy.
void setTrustPolicy(QgsAuthCertUtils::CertTrustPolicy policy)
Sets current trust policy.
QgsAuthCertTrustPolicyComboBox(QWidget *parent=nullptr, QgsAuthCertUtils::CertTrustPolicy policy=QgsAuthCertUtils::DefaultTrust, QgsAuthCertUtils::CertTrustPolicy defaultpolicy=QgsAuthCertUtils::DefaultTrust)
Construct a combo box for defining certificate trust policy.
static QString getCertTrustName(QgsAuthCertUtils::CertTrustPolicy trust)
Gets the general name for certificate trust.
CertTrustPolicy
Type of certificate trust policy.
static QString greenTextStyleSheet(const QString &selector="*")
Green text stylesheet representing valid, trusted, etc. certificate.
static QColor greenColor()
Green color representing valid, trusted, etc. certificate.
static QString redTextStyleSheet(const QString &selector="*")
Red text stylesheet representing invalid, untrusted, etc. certificate.
static QColor redColor()
Red color representing invalid, untrusted, etc. certificate.
QgsAuthCertUtils::CertTrustPolicy defaultCertTrustPolicy()
Gets the default certificate trust policy preferred by user.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39