2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2014-08-25 17:21:49 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2014-08-25 17:21:49 +02:00
|
|
|
|
|
|
|
|
#include "utils_global.h"
|
|
|
|
|
|
|
|
|
|
#include <QSet>
|
|
|
|
|
#include <QString>
|
2019-04-16 16:46:36 +02:00
|
|
|
#include <QVariant>
|
2014-08-25 17:21:49 +02:00
|
|
|
#include <QWizardPage>
|
|
|
|
|
|
2017-09-26 11:00:21 +02:00
|
|
|
#include <functional>
|
|
|
|
|
|
2014-08-25 17:21:49 +02:00
|
|
|
namespace Utils {
|
|
|
|
|
|
|
|
|
|
class Wizard;
|
2017-09-26 11:00:21 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT ObjectToFieldWidgetConverter : public QWidget
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2019-04-16 16:46:36 +02:00
|
|
|
Q_PROPERTY(QVariant value READ value NOTIFY valueChanged)
|
2017-09-26 11:00:21 +02:00
|
|
|
|
|
|
|
|
public:
|
2019-04-16 16:46:36 +02:00
|
|
|
template<class T, typename... Arguments>
|
|
|
|
|
static ObjectToFieldWidgetConverter *create(T *sender,
|
|
|
|
|
void (T::*member)(Arguments...),
|
|
|
|
|
const std::function<QVariant()> &toVariantFunction)
|
2017-09-26 11:00:21 +02:00
|
|
|
{
|
|
|
|
|
auto widget = new ObjectToFieldWidgetConverter();
|
2019-04-16 16:46:36 +02:00
|
|
|
widget->toVariantFunction = toVariantFunction;
|
2017-09-26 11:00:21 +02:00
|
|
|
connect(sender, &QObject::destroyed, widget, &QObject::deleteLater);
|
2019-04-16 16:46:36 +02:00
|
|
|
connect(sender, member, widget, [widget]() { emit widget->valueChanged(widget->value()); });
|
2017-09-26 11:00:21 +02:00
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
signals:
|
2019-04-16 16:46:36 +02:00
|
|
|
void valueChanged(const QVariant &);
|
2017-09-26 11:00:21 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ObjectToFieldWidgetConverter () = default;
|
|
|
|
|
|
2019-04-16 16:46:36 +02:00
|
|
|
// is used by the property value
|
|
|
|
|
QVariant value() { return toVariantFunction(); }
|
|
|
|
|
std::function<QVariant()> toVariantFunction;
|
2017-09-26 11:00:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
|
2014-08-25 17:21:49 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT WizardPage : public QWizardPage
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2018-05-07 17:33:02 +02:00
|
|
|
explicit WizardPage(QWidget *parent = nullptr);
|
2014-08-25 17:21:49 +02:00
|
|
|
|
|
|
|
|
virtual void pageWasAdded(); // called when this page was added to a Utils::Wizard
|
|
|
|
|
|
2017-09-26 11:00:21 +02:00
|
|
|
template<class T, typename... Arguments>
|
2019-04-16 16:46:36 +02:00
|
|
|
void registerObjectAsFieldWithName(const QString &name,
|
|
|
|
|
T *sender,
|
|
|
|
|
void (T::*changeSignal)(Arguments...),
|
|
|
|
|
const std::function<QVariant()> &senderToVariant)
|
2017-09-26 11:00:21 +02:00
|
|
|
{
|
2019-04-16 16:46:36 +02:00
|
|
|
registerFieldWithName(name,
|
|
|
|
|
Internal::ObjectToFieldWidgetConverter::create(sender,
|
|
|
|
|
changeSignal,
|
|
|
|
|
senderToVariant),
|
|
|
|
|
"value",
|
|
|
|
|
SIGNAL(valueChanged(QValue)));
|
2017-09-26 11:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 17:21:49 +02:00
|
|
|
void registerFieldWithName(const QString &name, QWidget *widget,
|
2018-05-07 17:33:02 +02:00
|
|
|
const char *property = nullptr, const char *changedSignal = nullptr);
|
2014-08-25 17:21:49 +02:00
|
|
|
|
2015-05-05 16:34:49 +02:00
|
|
|
virtual bool handleReject();
|
|
|
|
|
virtual bool handleAccept();
|
|
|
|
|
|
2015-01-20 14:43:58 +01:00
|
|
|
signals:
|
|
|
|
|
// Emitted when there is something that the developer using this page should be aware of.
|
|
|
|
|
void reportError(const QString &errorMessage);
|
|
|
|
|
|
2014-08-25 17:21:49 +02:00
|
|
|
private:
|
2017-06-15 11:15:24 +02:00
|
|
|
void registerFieldName(const QString &name);
|
|
|
|
|
|
2014-08-25 17:21:49 +02:00
|
|
|
QSet<QString> m_toRegister;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Utils
|