QGIS API Documentation 3.41.0-Master (57ec4277f5e)
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#include "moc_qgsauthcerttrustpolicycombobox.cpp"
19
20#include <QLineEdit>
21
22#include "qgsauthcertutils.h"
23#include "qgsauthguiutils.h"
24#include "qgsauthmanager.h"
25#include "qgslogger.h"
26#include "qgsapplication.h"
27
28
30 : QComboBox( parent )
31{
32 QList<QPair<QgsAuthCertUtils::CertTrustPolicy, QString>> policies;
33 policies << qMakePair( QgsAuthCertUtils::DefaultTrust, defaultTrustText( defaultpolicy ) )
36
37 for ( int i = 0; i < policies.size(); i++ )
38 {
39 const QgsAuthCertUtils::CertTrustPolicy polcy = policies.at( i ).first;
40 const QString name = policies.at( i ).second;
41 addItem( name, QVariant( static_cast<int>( polcy ) ) );
42 }
43
44 setItemData( 1, QgsAuthGuiUtils::greenColor(), Qt::ForegroundRole );
45 setItemData( 2, QgsAuthGuiUtils::redColor(), Qt::ForegroundRole );
46
47 // for styling closed state of combobox
48 // setEditable( true );
49 // lineEdit()->setReadOnly( true );
50
51 connect( this, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAuthCertTrustPolicyComboBox::highlightCurrentIndex );
52
53 setTrustPolicy( policy );
54 setDefaultTrustPolicy( defaultpolicy );
55}
56
61
66
68{
69 const int idx = findData( QVariant( static_cast<int>( policy ) ) );
70 setCurrentIndex( idx == -1 ? 0 : idx );
71}
72
74{
75 const int idx = findData( QVariant( static_cast<int>( QgsAuthCertUtils::DefaultTrust ) ) );
76 setItemText( idx, defaultTrustText( defaultpolicy ) );
77}
78
79void QgsAuthCertTrustPolicyComboBox::highlightCurrentIndex( int indx )
80{
81 const QgsAuthCertUtils::CertTrustPolicy policy = ( QgsAuthCertUtils::CertTrustPolicy ) itemData( indx ).toInt();
82 QString ss;
83
84 // TODO: why are these widget state selectors backwards?
85 switch ( policy )
86 {
88 // ss = QgsAuthCertUtils::greenTextStyleSheet( "QLineEdit" );
89 ss = QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QComboBox:open" ) ) + "\nQComboBox:!open{}";
90 break;
92 // ss = QgsAuthCertUtils::redTextStyleSheet( "QLineEdit" );
93 ss = QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QComboBox:open" ) ) + "\nQComboBox:!open{}";
94 break;
96 default:
97 break;
98 }
99 QgsDebugMsgLevel( QStringLiteral( "Set Stylesheet to : %1" ).arg( ss ), 2 );
100 // lineEdit()->setStyleSheet( ss );
101 setStyleSheet( ss );
102}
103
104const QString QgsAuthCertTrustPolicyComboBox::defaultTrustText( QgsAuthCertUtils::CertTrustPolicy defaultpolicy )
105{
106 if ( defaultpolicy == QgsAuthCertUtils::DefaultTrust )
107 {
108 if ( !QgsApplication::authManager()->isDisabled() )
109 {
111 }
112 else
113 {
114 defaultpolicy = QgsAuthCertUtils::Trusted;
115 }
116 }
117 return QStringLiteral( "%1 (%2)" )
119}
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