qt5base-lts/tests/manual/dialogs/utils.cpp
Lucie Gérard 05fc3aef53 Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Task-number: QTBUG-67283
Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-05-16 16:37:38 +02:00

69 lines
1.9 KiB
C++

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "utils.h"
#include <QCheckBox>
#include <QVBoxLayout>
QComboBox *createCombo(QWidget *parent, const FlagData *d, size_t size)
{
QComboBox *c = new QComboBox(parent);
for (size_t i = 0; i < size; ++i)
c->addItem(QLatin1String(d[i].description), QVariant(d[i].value));
return c;
}
void populateCombo(QComboBox *combo, const FlagData *d, size_t size)
{
for (size_t i = 0; i < size; ++i)
combo->addItem(QLatin1String(d[i].description), QVariant(d[i].value));
}
void setComboBoxValue(QComboBox *c, int v)
{
c->setCurrentIndex(c->findData(QVariant(v)));
}
OptionsControl::OptionsControl(QWidget *parent)
: QGroupBox(parent)
{
setLayout(new QVBoxLayout(this));
}
OptionsControl::OptionsControl(const QString &title, const FlagData *data, size_t count, QWidget *parent)
: QGroupBox(title, parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
for (size_t i = 0; i < count; ++i) {
QCheckBox *box = new QCheckBox(QString::fromLatin1(data[i].description));
m_checkBoxes.push_back(CheckBoxFlagPair(box, data[i].value));
layout->addWidget(box);
}
}
void OptionsControl::populateOptions(const FlagData *data, size_t count)
{
for (size_t i = 0; i < count; ++i) {
QCheckBox *box = new QCheckBox(QString::fromLatin1(data[i].description));
m_checkBoxes.push_back(CheckBoxFlagPair(box, data[i].value));
layout()->addWidget(box);
}
}
void OptionsControl::setValue(int flags)
{
foreach (const CheckBoxFlagPair &cf, m_checkBoxes)
cf.first->setChecked(cf.second & flags);
}
int OptionsControl::intValue() const
{
int result = 0;
foreach (const CheckBoxFlagPair &cf, m_checkBoxes) {
if (cf.first->isChecked())
result |= cf.second;
}
return result;
}