view ui/certificatelistwidget.cpp @ 754:27043d74dc90

(Issue25) Align header contents in their own column. We now also stretch column 3 so that the contents are aligned with the descriptive labels without a space in between. Sadly this causes the quit button to be resized to it's minimum instead of sharing the space with the installation button as the installation button is so large that it squeezes the push button.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 07 Jul 2014 12:38:33 +0200
parents a467204a35f5
children 9bfaced5cf59
line wrap: on
line source
/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU GPL (v>=2)
 * and comes with ABSOLUTELY NO WARRANTY!
 * See LICENSE.txt for details.
 */
#include "certificatelistwidget.h"
#include <QDebug>
#include <QVBoxLayout>
#include <QGroupBox>
#include <QLabel>
#include <QApplication>

#include "certificateitemwidget.h"

CertificateListWidget::CertificateListWidget(QWidget *parent, Qt::WindowFlags flags) :
    QWidget(parent, flags)
{
    setLayout(&mLayout);
}

void CertificateListWidget::addCertificate(
    const Certificate &certificate,
    bool state,
    bool editable,
    const QString &installLabel,
    const QString &removeLabel)
{
    CertificateItemWidget *widget =
        new CertificateItemWidget(this, certificate, state, editable,
                installLabel, removeLabel);
    connect(widget, SIGNAL(stateChanged(bool, const Certificate&)),
        this, SLOT(certStateChanged(bool, const Certificate&)));

    mCertificateWidgets << widget;
    mLayout.addWidget(widget);
    emit certListChanged(-1);
}

void CertificateListWidget::removeCertificate(const Certificate &cert)
{
    for (int i = 0; i < mCertificateWidgets.size(); i++) {
        if (mCertificateWidgets[i]->certificate() == cert) {
            mLayout.removeWidget(mCertificateWidgets[i]);
            delete(mCertificateWidgets[i]);
            mCertificateWidgets.removeAt(i);
            break;
        }
    }
    emit certListChanged(-1);
}

void CertificateListWidget::clear()
{
    foreach (CertificateItemWidget * item, mCertificateWidgets) {
        mLayout.removeWidget(item);
        delete item;
    }
    mCertificateWidgets.clear();
}

QStringList CertificateListWidget::certificates()
{
    QStringList list;
    foreach (CertificateItemWidget * item, mCertificateWidgets) {
        list <<  item->certificate().base64Line();
    }
    return list;
}

QStringList CertificateListWidget::selectedCertificates() {
    QStringList list;
    foreach (CertificateItemWidget * item, mCertificateWidgets) {
        if (item->state()) {
            list << item->certificate().base64Line();
        }
    }
    return list;
}

QStringList CertificateListWidget::unselectedCertificates() {
    QStringList list;
    foreach (CertificateItemWidget * item, mCertificateWidgets) {
        if (!item->state()) {
            list << item->certificate().base64Line();
        }
    }
    return list;
}

QList<Certificate> CertificateListWidget::certificateList()
{
    QList<Certificate> list;
    foreach (CertificateItemWidget * item, mCertificateWidgets) {
        list <<  item->certificate();
    }
    return list;
}

void CertificateListWidget::setCertState(bool state, const Certificate &cert)
{
    foreach (CertificateItemWidget * item, mCertificateWidgets) {
        if (item->certificate() == cert &&
            item->state() != state) {
            item->setState(state);
        }
    }
}


void CertificateListWidget::certStateChanged(bool state, const Certificate &cert)
{
    emit certListChanged(-1);
    emit certChanged(state, cert);
}

int CertificateListWidget::selectedCertCount()
{
    int selected = 0;
    foreach (CertificateItemWidget * item, mCertificateWidgets) {
        if (item->state()) {
            selected++;
        }
    }
    return selected;
}

bool CertificateListWidget::contains(const Certificate &cert)
{
    foreach (CertificateItemWidget * item, mCertificateWidgets) {
        if (item->certificate() == cert) {
            return true;
        }
    }
    return false;
}

http://wald.intevation.org/projects/trustbridge/