78 lines
2.0 KiB
C++
Executable File
78 lines
2.0 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* A Frameless dialog to select parties
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Christian Ehrlicher, SLSE, 2017-06-22
|
|
*/
|
|
|
|
|
|
#include "ppm_party_selector.h"
|
|
#include <QCheckBox>
|
|
#include <QHBoxLayout>
|
|
#include <QPushButton>
|
|
#include <ParticipantManagement/ppm_translation.h>
|
|
|
|
namespace ParticipantManagement
|
|
{
|
|
|
|
PartySelector::PartySelector(QWidget *parent)
|
|
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
|
|
{
|
|
m_ui.setupUi(this);
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
}
|
|
|
|
PartySelector::~PartySelector()
|
|
{}
|
|
|
|
bool PartySelector::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
|
|
const QSet<int> &preselectedParties,
|
|
const QVector<int> &visibleParties)
|
|
{
|
|
qDeleteAll(findChildren<QCheckBox *>());
|
|
m_selectedParties = preselectedParties;
|
|
m_selectedPartiesOriginal = preselectedParties;
|
|
|
|
QMap<qint32, Party> parties;
|
|
if (!dtc->visibleParties(parties, visibleParties))
|
|
return false;
|
|
|
|
for (const Party &party : qAsConst(parties))
|
|
{
|
|
// TODO: add color
|
|
QCheckBox *cb = new QCheckBox;
|
|
cb->setText(ParticipantManagement::trPartyName(party.name()));
|
|
cb->setChecked(preselectedParties.contains(party.id()));
|
|
const int partyId = party.id();
|
|
connect(cb, &QCheckBox::clicked,
|
|
cb, [this, partyId](bool checked) {partyCheckBoxChanged(partyId, checked);});
|
|
m_ui.layParties->addWidget(cb);
|
|
}
|
|
|
|
connect(m_ui.pbOk, &QPushButton::clicked,
|
|
this, &PartySelector::accept);
|
|
connect(m_ui.pbCancel, &QPushButton::clicked,
|
|
this, &PartySelector::reject);
|
|
|
|
return true;
|
|
}
|
|
|
|
void PartySelector::partyCheckBoxChanged(int partyId, bool bChecked)
|
|
{
|
|
if (bChecked)
|
|
m_selectedParties += partyId;
|
|
else
|
|
m_selectedParties -= partyId;
|
|
emit partiesSelected(m_selectedParties);
|
|
}
|
|
|
|
void PartySelector::reject()
|
|
{
|
|
emit partiesSelected(m_selectedPartiesOriginal);
|
|
LtsWidgets::LtsFramelessDialog::reject();
|
|
}
|
|
|
|
} // namespace ParticipantManagement
|