Newer
Older
/**
* Sets group names and updates checkboxes on UI
* By default sets all unchecked
* @param groups :: [input] List of group names
*/
void MuonFitPropertyBrowser::setAvailableGroups(const QStringList &groups) {
m_enumManager->setValue(m_groupsToFit, 0);
// If it's the same list, do nothing
if (groups.size() == m_groupBoxes.size()) {
auto existingGroups = m_groupBoxes.keys();
auto newGroups = groups;
qSort(existingGroups);
qSort(newGroups);
if (existingGroups == newGroups) {
return;
}
}
clearGroupCheckboxes();
QSettings settings;
for (const auto group : groups) {
addGroupCheckbox(group);
}
}
/**
* Clears all group names and checkboxes
* (ready to add new ones)
*/
void MuonFitPropertyBrowser::clearGroupCheckboxes() {
for (const auto &checkbox : m_groupBoxes) {
delete(checkbox);
}
m_groupBoxes.clear();
}
/**
* Add a new checkbox to the list of groups with given name
* The new checkbox is unchecked by default
* @param name :: [input] Name of group to add
*/
void MuonFitPropertyBrowser::addGroupCheckbox(const QString &name) {
m_groupBoxes.insert(name, m_boolManager->addProperty(name));
int j = m_enumManager->value(m_groupsToFit);
auto option = m_groupsToFitOptions[j].toStdString();
if (option == "All groups") {
setAllGroups();
}
else if (option == "All Pairs") {
setAllPairs();
}
}
/**
* Returns a list of the selected groups (checked boxes)
* @returns :: list of selected groups
*/
QStringList MuonFitPropertyBrowser::getChosenGroups() const {
QStringList chosen;
for (auto iter = m_groupBoxes.constBegin(); iter != m_groupBoxes.constEnd();
++iter) {
if (m_boolManager->value(iter.value()) ==true) {
chosen.append(iter.key());
}
}
return chosen;
}
/**
* Clears the list of selected groups (unchecks boxes)
*/
void MuonFitPropertyBrowser::clearChosenGroups() const {
for (auto iter = m_groupBoxes.constBegin(); iter != m_groupBoxes.constEnd();
++iter) {
m_boolManager->setValue(iter.value(), false);
void MuonFitPropertyBrowser::setAllGroups() {
clearChosenGroups();
for (auto iter = m_groupBoxes.constBegin(); iter != m_groupBoxes.constEnd();
++iter) {
for (auto group : m_groupsList) {
if (iter.key().toStdString() == group) {
m_boolManager->setValue(iter.value(), true);
/*
* sets all pairs
*/
void MuonFitPropertyBrowser::setAllPairs() {
clearChosenGroups();
bool isItGroup = false;
for (auto iter = m_groupBoxes.constBegin(); iter != m_groupBoxes.constEnd();
++iter) {
isItGroup = false;
for (auto group : m_groupsList) {
if (iter.key().toStdString() == group) {
isItGroup = true;
}
}
if (!isItGroup) {
m_boolManager->setValue(iter.value(), true);
}
}
}
void MuonFitPropertyBrowser::setChosenGroup(QString &group) {
clearChosenGroups();
for (auto iter = m_groupBoxes.constBegin(); iter != m_groupBoxes.constEnd();
++iter) {
if (iter.key() == group) {
m_boolManager->setValue(iter.value(), true);
}
}
}
/*
* Create a popup window to select a custom
* selection of groups/pairs
*/
void MuonFitPropertyBrowser::genGroupWindow() {
QWidget *w = new QWidget;
QtGroupPropertyManager *groupManager = new QtGroupPropertyManager(w);
QVBoxLayout *layout = new QVBoxLayout(w);
QtTreePropertyBrowser *groupBrowser = new QtTreePropertyBrowser();
QtProperty *groupSettings = groupManager->addProperty("Group/Pair selection");
for (auto iter = m_groupBoxes.constBegin(); iter != m_groupBoxes.constEnd();
++iter){
groupSettings->addSubProperty(m_groupBoxes.value(iter.key()));
m_boolManager->setValue(iter.value(),m_boolManager->value(iter.value()));
}
QtCheckBoxFactory *checkBoxFactory = new QtCheckBoxFactory(w);
groupBrowser->setFactoryForManager(m_boolManager, checkBoxFactory);
groupBrowser->addProperty(groupSettings);
layout->addWidget(groupBrowser);
w->setLayout(layout);
w->show();
}
/**
* Sets checkboxes for periods
* and "combination" boxes.
* Hides control for single-period data.
* @param numPeriods :: [input] Number of periods
*/
void MuonFitPropertyBrowser::setNumPeriods(size_t numPeriods) {
for (size_t i = 0; i != numPeriods; i++) {
QString name = QString::number(i + 1);
addPeriodCheckbox(name);
}
if (m_periodsToFitOptions.size() == 1) {
m_generateBtn->setDisabled(true);
m_multiFitSettingsGroup->property()->removeSubProperty(m_periodsToFit);
m_multiFitSettingsGroup->property()->removeSubProperty(m_showPeriods);
m_enumManager->setValue(m_periodsToFit, 0);
clearChosenPeriods();
m_boolManager->setValue(m_periodBoxes.constBegin().value(), true);
}
else {
//add custom back into list
m_multiFitSettingsGroup->property()->insertSubProperty(m_periodsToFit,m_showGroup);
m_multiFitSettingsGroup->property()->addSubProperty(m_showPeriods);
m_generateBtn->setDisabled(false);
m_periodsToFitOptions << "Custom";
m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions);
}
}
/**
* Sets group names and updates checkboxes on UI
* By default sets all unchecked
* @param groups :: [input] List of group names
*/
void MuonFitPropertyBrowser::setAvailablePeriods(const QStringList &periods) {
// If it's the same list, do nothing
if (periods.size() == m_periodBoxes.size()) {
auto existingGroups = m_periodBoxes.keys();
auto newGroups = periods;
qSort(existingGroups);
qSort(newGroups);
if (existingGroups == newGroups) {
return;
}
}
clearPeriodCheckboxes();
for (const auto group : periods) {
addPeriodCheckbox(group);
}
}
/**
* Clears all group names and checkboxes
* (ready to add new ones)
*/
void MuonFitPropertyBrowser::clearPeriodCheckboxes() {
if (m_periodBoxes.size() > 1) {
for (auto iter = m_periodBoxes.constBegin(); iter != m_periodBoxes.constEnd();
++iter) {
if (iter != m_periodBoxes.constBegin()) {
delete(iter);
}
}
}
m_periodsToFitOptions.clear();
m_periodsToFitOptions << "1";
m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions);
}
/**
* Clears the list of selected groups (unchecks boxes)
*/
void MuonFitPropertyBrowser::clearChosenPeriods() const {
for (auto iter = m_periodBoxes.constBegin(); iter != m_periodBoxes.constEnd();
++iter) {
m_boolManager->setValue(iter.value(), false);
}
}
/**
* Add a new checkbox to the list of periods with given name
* The new checkbox is unchecked by default
* @param name :: [input] Name of period to add
*/
void MuonFitPropertyBrowser::addPeriodCheckbox(const QString &name) {
m_periodBoxes.insert(name, m_boolManager->addProperty(name));
int j = m_enumManager->value(m_periodsToFit);
//add new period to list will go after inital list
m_periodsToFitOptions << name;
auto active = getChosenPeriods();
m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions);
setChosenPeriods(active);
m_enumManager->setValue(m_periodsToFit, j);
}
/**
* Returns a list of the selected periods (checked boxes)
* @returns :: list of selected periods
*/
QStringList MuonFitPropertyBrowser::getChosenPeriods() const {
QStringList chosen;
if (m_periodsToFitOptions.size() == 1) {
chosen << "";
}
else {
for (auto iter = m_periodBoxes.constBegin(); iter != m_periodBoxes.constEnd();
++iter) {
if (m_boolManager->value(iter.value()) == true) {
chosen.append(iter.key());
}
/**
* Ticks the selected periods
* @param chsoenPeriods :: list of selected periods
*/
void MuonFitPropertyBrowser::setChosenPeriods(const QStringList &chosenPeriods){
clearChosenPeriods();
for (auto selected : chosenPeriods) {
for (auto iter = m_periodBoxes.constBegin(); iter != m_periodBoxes.constEnd();
++iter) {
auto tmp = iter.key();
if (iter.key() == selected) {
m_boolManager->setValue(iter.value(), true);
}
}
}
}
/**
* Ticks the selected periods
* @param chsoenPeriods :: list of selected periods
*/
void MuonFitPropertyBrowser::setChosenPeriods(const QString &period) {
clearChosenPeriods();
for (auto iter = m_periodBoxes.constBegin(); iter != m_periodBoxes.constEnd();
++iter) {
auto tmp = iter.key();
if (iter.key() == period) {
m_boolManager->setValue(iter.value(), true);
}
}
}
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
/*
* Create a popup window to select a custom
* selection of periods
*/
void MuonFitPropertyBrowser::genPeriodWindow() {
QWidget *w = new QWidget;
QtGroupPropertyManager *groupManager = new QtGroupPropertyManager(w);
QVBoxLayout *layout = new QVBoxLayout(w);
QtTreePropertyBrowser *groupBrowser = new QtTreePropertyBrowser();
QtProperty *groupSettings = groupManager->addProperty("Period selection");
for (auto iter = m_periodBoxes.constBegin(); iter != m_periodBoxes.constEnd();
++iter) {
groupSettings->addSubProperty(m_periodBoxes.value(iter.key()));
m_boolManager->setValue(iter.value(), m_boolManager->value(iter.value()));
}
QtCheckBoxFactory *checkBoxFactory = new QtCheckBoxFactory(w);
groupBrowser->setFactoryForManager(m_boolManager, checkBoxFactory);
groupBrowser->addProperty(groupSettings);
layout->addWidget(groupBrowser);
w->setLayout(layout);
w->show();
}
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
/*
* Create a popup window to create
* a combination of periods
*/
void MuonFitPropertyBrowser::genCombinePeriodWindow() {
QWidget *w = new QWidget;
QVBoxLayout *layout = new QVBoxLayout(w);
QFormLayout *formLayout = new QFormLayout;
m_positiveCombo = new QLineEdit();
m_negativeCombo = new QLineEdit();
formLayout->addRow(new QLabel(tr("Combine:")), m_positiveCombo);
formLayout->addRow(new QLabel(tr(" - ")), m_negativeCombo);
layout->addLayout(formLayout);
QPushButton *applyBtn = new QPushButton("Apply");
connect(applyBtn, SIGNAL(released()), this, SLOT(combineBtnPressed()));
layout->addWidget(applyBtn);
w->setLayout(layout);
w->show();
}
void MuonFitPropertyBrowser::combineBtnPressed() {
QString value = m_positiveCombo->text();
if (value.isEmpty()) {
g_log.error("There are no positive periods (top box)");
return;
}
if (!m_negativeCombo->text().isEmpty()) {
value.append("-").append(m_negativeCombo->text());
}
m_positiveCombo->clear();
m_negativeCombo->clear();
addPeriodCheckbox(value);
}