QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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
32 : QComboBox( parent )
33{
34 QList < QPair<QgsAuthCertUtils::CertTrustPolicy, QString> > policies;
35 policies << qMakePair( QgsAuthCertUtils::DefaultTrust,
36 defaultTrustText( defaultpolicy ) )
37 << qMakePair( QgsAuthCertUtils::Trusted,
39 << qMakePair( QgsAuthCertUtils::Untrusted,
41
42 for ( int i = 0; i < policies.size(); i++ )
43 {
44 const QgsAuthCertUtils::CertTrustPolicy polcy = policies.at( i ).first;
45 const QString name = policies.at( i ).second;
46 addItem( name, QVariant( static_cast<int>( polcy ) ) );
47 }
48
49 setItemData( 1, QgsAuthGuiUtils::greenColor(), Qt::ForegroundRole );
50 setItemData( 2, QgsAuthGuiUtils::redColor(), Qt::ForegroundRole );
51
52 // for styling closed state of combobox
53// setEditable( true );
54// lineEdit()->setReadOnly( true );
55
56 connect( this, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
57 this, &QgsAuthCertTrustPolicyComboBox::highlightCurrentIndex );
58
59 setTrustPolicy( policy );
60 setDefaultTrustPolicy( defaultpolicy );
61}
62
67
72
74{
75 const int idx = findData( QVariant( static_cast<int>( policy ) ) );
76 setCurrentIndex( idx == -1 ? 0 : idx );
77}
78
80{
81 const int idx = findData( QVariant( static_cast<int>( QgsAuthCertUtils::DefaultTrust ) ) );
82 setItemText( idx, defaultTrustText( defaultpolicy ) );
83}
84
85void QgsAuthCertTrustPolicyComboBox::highlightCurrentIndex( int indx )
86{
87 const QgsAuthCertUtils::CertTrustPolicy policy = ( QgsAuthCertUtils::CertTrustPolicy )itemData( indx ).toInt();
88 QString ss;
89
90 // TODO: why are these widget state selectors backwards?
91 switch ( policy )
92 {
94 // ss = QgsAuthCertUtils::greenTextStyleSheet( "QLineEdit" );
95 ss = QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QComboBox:open" ) ) + "\nQComboBox:!open{}";
96 break;
98 // ss = QgsAuthCertUtils::redTextStyleSheet( "QLineEdit" );
99 ss = QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QComboBox:open" ) ) + "\nQComboBox:!open{}";
100 break;
102 default:
103 break;
104 }
105 QgsDebugMsgLevel( QStringLiteral( "Set Stylesheet to : %1" ).arg( ss ), 2 );
106 // lineEdit()->setStyleSheet( ss );
107 setStyleSheet( ss );
108}
109
110const QString QgsAuthCertTrustPolicyComboBox::defaultTrustText( QgsAuthCertUtils::CertTrustPolicy defaultpolicy )
111{
112 if ( defaultpolicy == QgsAuthCertUtils::DefaultTrust )
113 {
114 if ( !QgsApplication::authManager()->isDisabled() )
115 {
117 }
118 else
119 {
120 defaultpolicy = QgsAuthCertUtils::Trusted;
121 }
122 }
123 return QStringLiteral( "%1 (%2)" )
125 QgsAuthCertUtils::getCertTrustName( defaultpolicy ) );
126}
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