Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* A Frameless dialog to select parties
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2017-06-22
|
||||
*/
|
||||
|
||||
|
||||
#include "pdm_charge_selector.h"
|
||||
#include <QCheckBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <ProjectDataManagement/pdm_translation.h>
|
||||
#include <LtsUtils/LtsUtilsCore/json_object.h>
|
||||
|
||||
namespace ProjectDataManagement
|
||||
{
|
||||
|
||||
ChargeSelector::ChargeSelector(QWidget *parent)
|
||||
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
}
|
||||
|
||||
ChargeSelector::~ChargeSelector()
|
||||
{}
|
||||
|
||||
bool ChargeSelector::init(const std::shared_ptr<ProjectDataManagement::Interface::Dtc> &dtc,
|
||||
GearClass gearClass,
|
||||
const QSet<int> &preselectedCharges)
|
||||
{
|
||||
QString title = tr("Select %1 Charges").arg(toString(gearClass));
|
||||
m_ui.lblCharges->setText(title);
|
||||
setWindowTitle(title);
|
||||
qDeleteAll(findChildren<QCheckBox *>());
|
||||
m_selectedCharges = preselectedCharges;
|
||||
m_selectedChargesOriginal = preselectedCharges;
|
||||
|
||||
const auto cfgc = dtc->chargesForGearClass(gearClass);
|
||||
for (const ChargeType &charge : cfgc)
|
||||
{
|
||||
if (LtsUtils::JsonObject::fromJson(charge.properties()).valueOr<bool>("suppressVisibility", false))
|
||||
continue;
|
||||
const int chargeId = charge.id();
|
||||
QCheckBox *cb = new QCheckBox;
|
||||
cb->setText(dtc->trChargeTypeShortName(chargeId, true));
|
||||
cb->setChecked(preselectedCharges.contains(chargeId));
|
||||
connect(cb, &QCheckBox::clicked, cb, [this, chargeId](bool checked) { chargeCheckBoxChanged(chargeId, checked); });
|
||||
|
||||
m_ui.layParties->addWidget(cb);
|
||||
}
|
||||
|
||||
connect(m_ui.pbOk, &QPushButton::clicked,
|
||||
this, &ChargeSelector::accept);
|
||||
connect(m_ui.pbCancel, &QPushButton::clicked,
|
||||
this, &ChargeSelector::reject);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChargeSelector::chargeCheckBoxChanged(int chargeId, bool bChecked)
|
||||
{
|
||||
if (bChecked)
|
||||
m_selectedCharges += chargeId;
|
||||
else
|
||||
m_selectedCharges -= chargeId;
|
||||
emit chargesSelected(m_selectedCharges);
|
||||
}
|
||||
|
||||
void ChargeSelector::reject()
|
||||
{
|
||||
emit chargesSelected(m_selectedChargesOriginal);
|
||||
LtsWidgets::LtsFramelessDialog::reject();
|
||||
}
|
||||
|
||||
} // namespace ProjectDataManagement
|
||||
Reference in new issue
Block a user