2014-10-09 11:21:06 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-10-09 11:21:06 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-10-09 11:21:06 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-10-09 11:21:06 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
#include "../projectexplorer_export.h"
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
#include <utils/pathchooser.h>
|
|
|
|
|
#include <utils/wizardpage.h>
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
#include <QRegularExpression>
|
2014-10-09 11:21:06 +02:00
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QFormLayout;
|
|
|
|
|
class QLabel;
|
|
|
|
|
class QLineEdit;
|
|
|
|
|
class QTextEdit;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace Utils {
|
2014-10-15 14:45:31 +02:00
|
|
|
class MacroExpander;
|
2014-10-09 11:21:06 +02:00
|
|
|
} // namespace Utils
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
// Documentation inside.
|
2015-09-21 16:05:04 +02:00
|
|
|
class PROJECTEXPLORER_EXPORT JsonFieldPage : public Utils::WizardPage
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2015-09-21 16:05:04 +02:00
|
|
|
class PROJECTEXPLORER_EXPORT Field
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2015-09-21 16:05:04 +02:00
|
|
|
class FieldPrivate;
|
|
|
|
|
|
|
|
|
|
Field();
|
|
|
|
|
virtual ~Field();
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
static Field *parse(const QVariant &input, QString *errorMessage);
|
|
|
|
|
void createWidget(JsonFieldPage *page);
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
void adjustState(Utils::MacroExpander *expander);
|
2015-09-21 16:05:04 +02:00
|
|
|
virtual void setEnabled(bool e);
|
|
|
|
|
void setVisible(bool v);
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
void setType(const QString &type);
|
|
|
|
|
|
2015-05-08 10:42:48 +02:00
|
|
|
virtual bool validate(Utils::MacroExpander *expander, QString *message);
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
void initialize(Utils::MacroExpander *expander);
|
|
|
|
|
virtual void cleanup(Utils::MacroExpander *expander) { Q_UNUSED(expander); }
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
virtual bool suppressName() const { return false; }
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
QWidget *widget(const QString &displayName, JsonFieldPage *page);
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
QString name();
|
|
|
|
|
QString displayName();
|
|
|
|
|
QString toolTip();
|
|
|
|
|
bool isMandatory();
|
|
|
|
|
bool hasSpan();
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
protected:
|
|
|
|
|
QWidget *widget() const;
|
2014-10-09 11:21:06 +02:00
|
|
|
virtual bool parseData(const QVariant &data, QString *errorMessage) = 0;
|
2014-10-15 14:45:31 +02:00
|
|
|
virtual void initializeData(Utils::MacroExpander *expander) { Q_UNUSED(expander); }
|
2015-09-21 16:05:04 +02:00
|
|
|
virtual QWidget *createWidget(const QString &displayName, JsonFieldPage *page) = 0;
|
2014-10-09 11:21:06 +02:00
|
|
|
virtual void setup(JsonFieldPage *page, const QString &name)
|
|
|
|
|
{ Q_UNUSED(page); Q_UNUSED(name); }
|
|
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
QString type();
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
private:
|
|
|
|
|
void setTexts(const QString &n, const QString &dn, const QString &tt);
|
|
|
|
|
void setIsMandatory(bool b);
|
|
|
|
|
void setHasSpan(bool b);
|
|
|
|
|
|
|
|
|
|
void setVisibleExpression(const QVariant &v);
|
|
|
|
|
void setEnabledExpression(const QVariant &v);
|
|
|
|
|
void setIsCompleteExpando(const QVariant &v, const QString &m);
|
|
|
|
|
|
|
|
|
|
friend class JsonFieldPage;
|
|
|
|
|
|
|
|
|
|
FieldPrivate *const d;
|
2014-10-09 11:21:06 +02:00
|
|
|
};
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
JsonFieldPage(Utils::MacroExpander *expander, QWidget *parent = 0);
|
2016-04-13 15:52:14 +02:00
|
|
|
~JsonFieldPage() override;
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2015-09-21 16:28:48 +02:00
|
|
|
typedef std::function<Field *()> FieldFactory;
|
|
|
|
|
static void registerFieldFactory(const QString &id, const FieldFactory &ff);
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
bool setup(const QVariant &data);
|
|
|
|
|
|
2016-04-13 15:52:14 +02:00
|
|
|
bool isComplete() const override;
|
|
|
|
|
void initializePage() override;
|
|
|
|
|
void cleanupPage() override;
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
QFormLayout *layout() const { return m_formLayout; }
|
|
|
|
|
|
|
|
|
|
void showError(const QString &m) const;
|
|
|
|
|
void clearError() const;
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
Utils::MacroExpander *expander();
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2017-09-19 11:59:56 +02:00
|
|
|
QVariant value(const QString &key);
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
private:
|
2015-09-21 16:28:48 +02:00
|
|
|
static QHash<QString, FieldFactory> m_factories;
|
|
|
|
|
|
|
|
|
|
static Field *createFieldData(const QString &type);
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
QFormLayout *m_formLayout;
|
|
|
|
|
QLabel *m_errorLabel;
|
|
|
|
|
|
|
|
|
|
QList<Field *> m_fields;
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
Utils::MacroExpander *m_expander;
|
2014-10-09 11:21:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace ProjectExplorer
|