11d6932560
The density of Q_FOREACH uses in this and some other modules is still extremely high, too high for anyone to tackle in a short amount of time. Even if they're not concentrated in just a few TUs, we need to make progress on a global QT_NO_FOREACH default, so grab the nettle and stick to our strategy: Mark the whole of Qt with QT_NO_FOREACH, to prevent new uses from creeping in, and whitelist the affected TUs by #undef'ing QT_NO_FOREACH locally, at the top of each file. For TUs that are part of a larger executable, this requires these files to be compiled separately, so add them to NO_PCH_SOURCES (which implies NO_UNITY_BUILD_SOURCES, too). In tst_qglobal.cpp and tst_qcollections.cpp change the comment on the #undef QT_NO_FOREACH to indicate that these actually test the macro. Task-number: QTBUG-115839 Change-Id: Iecc444eb7d43d7e4d037f6e155abe0e14a00a5d6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
108 lines
3.3 KiB
C++
108 lines
3.3 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
|
|
|
|
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
|
|
|
|
#include "utils.h"
|
|
|
|
#include <QCheckBox>
|
|
#include <QGridLayout>
|
|
#include <QPushButton>
|
|
#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;
|
|
}
|
|
|
|
QPushButton *addButton(const QString &description, QGridLayout *layout, int &row, int column,
|
|
QObject *receiver, const char *slotFunc)
|
|
{
|
|
QPushButton *button = new QPushButton(description);
|
|
QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc);
|
|
layout->addWidget(button, row++, column);
|
|
return button;
|
|
}
|
|
|
|
QPushButton *addButton(const QString &description, QGridLayout *layout, int &row, int column,
|
|
std::function<void()> fn)
|
|
{
|
|
QPushButton *button = new QPushButton(description);
|
|
QObject::connect(button, &QPushButton::clicked, fn);
|
|
layout->addWidget(button, row++, column);
|
|
return button;
|
|
}
|
|
|
|
QPushButton *addButton(const QString &description, QVBoxLayout *layout, QObject *receiver,
|
|
const char *slotFunc)
|
|
{
|
|
QPushButton *button = new QPushButton(description);
|
|
QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc);
|
|
layout->addWidget(button);
|
|
return button;
|
|
}
|
|
|
|
QPushButton *addButton(const QString &description, QVBoxLayout *layout, std::function<void()> fn)
|
|
{
|
|
QPushButton *button = new QPushButton(description);
|
|
QObject::connect(button, &QPushButton::clicked, fn);
|
|
layout->addWidget(button);
|
|
return button;
|
|
}
|