From 196219283b4e7a19ad2c80f646d7db33873d0c24 Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Sat, 29 Mar 2025 17:35:26 +0100 Subject: [PATCH] Improve headerlist. Don't overload isNumeric isNumeric now is a virtual function of the dbheader class and overloaded by subclasses if needed. The strict connection isNumeric == AlignLeft is removed and a new virtual function alignment() is used to return the alignment. By default this is "isNumeric() ? Qt::AlignRight : Qt::AlignLeft;" but can now be overridden in sub-classes. the key_dbheader sub-class vanished an got replaced by the num_dbheader class with the capability to set the type to hd_key --- lib/db_base.cpp | 2 +- lib/db_x509super.cpp | 50 +++++++++++++++++------------------ lib/headerlist.h | 62 ++++++++++++++++++++++---------------------- 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/lib/db_base.cpp b/lib/db_base.cpp index 77b8ceaf..d8f1dcdc 100644 --- a/lib/db_base.cpp +++ b/lib/db_base.cpp @@ -449,7 +449,7 @@ QVariant db_base::data(const QModelIndex &index, int role) const case Qt::DecorationRole: return item->getIcon(hd); case Qt::TextAlignmentRole: - return int((hd->isNumeric() ? Qt::AlignRight : Qt::AlignLeft) | Qt::AlignVCenter); + return int(hd->alignment() | Qt::AlignVCenter); case Qt::BackgroundRole: return item->bg_color(hd); case Qt::UserRole: diff --git a/lib/db_x509super.cpp b/lib/db_x509super.cpp index 90db74a9..0cb4d516 100644 --- a/lib/db_x509super.cpp +++ b/lib/db_x509super.cpp @@ -54,34 +54,34 @@ void db_x509super::loadContainer() dbheaderList db_x509super::getHeaders() { dbheaderList h = db_x509name::getHeaders(); - NIDlist v3nid, v3ns_nid; - v3nid << - NID_subject_alt_name << - NID_issuer_alt_name << - NID_subject_key_identifier << - NID_authority_key_identifier << - NID_key_usage << - NID_ext_key_usage << - NID_crl_distribution_points << - NID_info_access; - v3ns_nid << - NID_netscape_cert_type << - NID_netscape_base_url << - NID_netscape_revocation_url << - NID_netscape_ca_revocation_url << - NID_netscape_renewal_url << - NID_netscape_ca_policy_url << - NID_netscape_ssl_server_name << - NID_netscape_comment; + static const NIDlist v3nid { + NID_subject_alt_name, + NID_issuer_alt_name, + NID_subject_key_identifier, + NID_authority_key_identifier, + NID_key_usage, + NID_ext_key_usage, + NID_crl_distribution_points, + NID_info_access + }, + v3ns_nid { + NID_netscape_cert_type, + NID_netscape_base_url, + NID_netscape_revocation_url, + NID_netscape_ca_revocation_url, + NID_netscape_renewal_url, + NID_netscape_ca_policy_url, + NID_netscape_ssl_server_name, + NID_netscape_comment + }; - h << new dbheader(HD_x509key_name, false, tr("Key name"), + h < #include #include +#include #include #include "settings.h" #include "pki_base.h" @@ -70,7 +71,6 @@ class dbheader hd_x509name, hd_v3ext, hd_v3ext_ns, - hd_number, hd_asn1time, hd_key, }; @@ -86,10 +86,10 @@ class dbheader virtual QString getName() { return name; } virtual QString getTooltip() { return tooltip; } - dbheader(QString aname = QString()) : name(aname) { } - dbheader(int aid, bool ashow = false, - QString aname = QString(), QString atip = QString()) - : name(aname), tooltip(atip), id(aid), show(ashow), showDefault(ashow) + dbheader(int aid, bool ashow = false, QString aname = QString(), + QString atip = QString(), enum hdr_type atype = hd_default) + : name(aname), tooltip(atip), id(aid), show(ashow), + showDefault(ashow), type(atype) { } virtual ~dbheader() { } @@ -107,15 +107,13 @@ class dbheader return name == h->name; return id == h->id; } - bool isNumeric() + virtual bool isNumeric() { - switch (id) { - case NID_subject_key_identifier: - case NID_authority_key_identifier: - case HD_key_size: - return true; - } - return type == hd_number; + return false; + } + virtual Qt::AlignmentFlag alignment() + { + return isNumeric() ? Qt::AlignRight : Qt::AlignLeft; } QString toData() { @@ -174,34 +172,43 @@ class nid_dbheader : public dbheader public: nid_dbheader(int aid, enum hdr_type atype) - : dbheader(aid, aid == NID_commonName) + : dbheader(aid, aid == NID_commonName, QString(), QString(), atype) { - type = atype; tooltip = dn_translations[id]; name = OBJ_nid2ln(id); sn = OBJ_nid2sn(id); if (tooltip.isEmpty()) tooltip = name; } - QString getName() + QString getName() override { return Settings["translate_dn"] ? tooltip : name; } - QString getTooltip() + QString getTooltip() override { return QString("[%1] %2").arg(sn) .arg(Settings["translate_dn"] ? name : tooltip); } + bool isNumeric() override + { + return id ==NID_subject_key_identifier || + id == NID_authority_key_identifier; + } }; class num_dbheader : public dbheader { public: - num_dbheader(int aid, bool ashow = false, - QString aname = QString(), QString atip = QString()) - : dbheader(aid, ashow, aname, atip) + num_dbheader(int aid, bool ashow = false, QString aname = QString(), + QString atip = QString(), enum hdr_type atype = hd_default) + : dbheader(aid, ashow, aname, atip, atype) + { } + num_dbheader(int aid, QString aname, enum hdr_type atype) + : dbheader(aid, false, aname, QString(), atype) + { } + bool isNumeric() override { - type = hd_number; + return true; } }; @@ -210,19 +217,12 @@ class date_dbheader : public dbheader public: date_dbheader(int aid, bool ashow = false, QString aname = QString(), QString atip = QString()) - : dbheader(aid, ashow, aname, atip) + : dbheader(aid, ashow, aname, atip, hd_asn1time) { - type = hd_asn1time; } -}; - -class key_dbheader : public dbheader -{ - public: - key_dbheader(int aid, QString aname) - : dbheader(aid, false, aname) + Qt::AlignmentFlag alignment() override { - type = hd_key; + return Qt::AlignRight; } };