xca/widgets/ItemCombo.h
Christian Hohnstaedt 993da2d474 Use C++11 initializers for all non-static class members
When XCA started in 2002, there were no C++ initializers.
Drop explicit initializers from the constructors.

 - Fix indentations of section declarators.
 - Replace NULL by nullptr when feasible.
 - Sort private section: properties first, then methods.
2023-10-08 22:19:18 +02:00

49 lines
1.1 KiB
C++

/* vi: set sw=4 ts=4:
*
* Copyright (C) 2015 Christian Hohnstaedt.
*
* All rights reserved.
*/
#ifndef __ITEMCOMBO_H
#define __ITEMCOMBO_H
#include <QList>
#include <QComboBox>
#include "lib/pki_base.h"
#include "lib/pki_x509.h"
#include "lib/pki_x509req.h"
#include "lib/pki_temp.h"
template <class T> class itemCombo : public QComboBox
{
public:
itemCombo(QWidget *parent) : QComboBox(parent) { }
void insertPkiItems(QList<T*> items) {
clear();
foreach(T *p, items) {
addItem(p->comboText(), QVariant::fromValue(p));
}
}
T *currentPkiItem() {
return itemData(currentIndex()).template value<T*>();
}
void setNullItem(QString text) {
if (itemData(0).template value<T*>() == NULL)
removeItem(0);
insertItem(0, text, QVariant());
}
int setCurrentPkiItem(T *p) {
int idx = findData(QVariant::fromValue(p));
setCurrentIndex(idx);
return idx;
}
};
typedef class itemCombo<pki_temp> itemComboTemp;
typedef class itemCombo<pki_x509req> itemComboReq;
typedef class itemCombo<pki_x509> itemComboCert;
typedef class itemCombo<pki_key> itemComboKey;
#endif