2014-10-09 11:21:06 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-15 14:46:23 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2014-10-09 11:21:06 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-15 14:46:23 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2014-10-09 11:21:06 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2014-10-09 11:21:06 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "jsonfieldpage.h"
|
|
|
|
|
|
|
|
|
|
#include "jsonwizard.h"
|
|
|
|
|
#include "jsonwizardfactory.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/stringutils.h>
|
|
|
|
|
#include <utils/textfieldcheckbox.h>
|
|
|
|
|
#include <utils/textfieldcombobox.h>
|
2015-05-08 16:27:10 +02:00
|
|
|
#include <utils/theme/theme.h>
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
#include <QCheckBox>
|
2014-10-15 12:05:17 +02:00
|
|
|
#include <QApplication>
|
2014-10-09 11:21:06 +02:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QLineEdit>
|
2014-10-15 13:19:05 +02:00
|
|
|
#include <QRegularExpressionValidator>
|
2014-10-09 11:21:06 +02:00
|
|
|
#include <QTextEdit>
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
#include <QVariantMap>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
using namespace Utils;
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
const char NAME_KEY[] = "name";
|
|
|
|
|
const char DISPLAY_NAME_KEY[] = "trDisplayName";
|
2015-05-12 14:36:10 +02:00
|
|
|
const char TOOLTIP_KEY[] = "trToolTip";
|
2014-10-15 14:45:31 +02:00
|
|
|
const char MANDATORY_KEY[] = "mandatory";
|
|
|
|
|
const char VISIBLE_KEY[] = "visible";
|
|
|
|
|
const char ENABLED_KEY[] = "enabled";
|
|
|
|
|
const char SPAN_KEY[] = "span";
|
|
|
|
|
const char TYPE_KEY[] = "type";
|
|
|
|
|
const char DATA_KEY[] = "data";
|
2015-05-08 10:42:48 +02:00
|
|
|
const char IS_COMPLETE_KEY[] = "isComplete";
|
|
|
|
|
const char IS_COMPLETE_MESSAGE_KEY[] = "trIncompleteMessage";
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// Helper:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
static JsonFieldPage::Field *createFieldData(const QString &type)
|
|
|
|
|
{
|
|
|
|
|
if (type == QLatin1String("Label"))
|
|
|
|
|
return new JsonFieldPage::LabelField;
|
|
|
|
|
else if (type == QLatin1String("Spacer"))
|
|
|
|
|
return new JsonFieldPage::SpacerField;
|
|
|
|
|
else if (type == QLatin1String("LineEdit"))
|
|
|
|
|
return new JsonFieldPage::LineEditField;
|
|
|
|
|
else if (type == QLatin1String("TextEdit"))
|
|
|
|
|
return new JsonFieldPage::TextEditField;
|
|
|
|
|
else if (type == QLatin1String("PathChooser"))
|
|
|
|
|
return new JsonFieldPage::PathChooserField;
|
|
|
|
|
else if (type == QLatin1String("CheckBox"))
|
|
|
|
|
return new JsonFieldPage::CheckBoxField;
|
|
|
|
|
else if (type == QLatin1String("ComboBox"))
|
|
|
|
|
return new JsonFieldPage::ComboBoxField;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
class LineEditValidator : public QRegularExpressionValidator
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
LineEditValidator(MacroExpander *expander, const QRegularExpression &pattern, QObject *parent) :
|
|
|
|
|
QRegularExpressionValidator(pattern, parent)
|
|
|
|
|
{
|
2015-03-23 12:41:06 +03:00
|
|
|
m_expander.setDisplayName(JsonFieldPage::tr("Line Edit Validator Expander"));
|
2014-11-13 15:54:26 +01:00
|
|
|
m_expander.setAccumulating(true);
|
2015-03-23 12:41:06 +03:00
|
|
|
m_expander.registerVariable("INPUT", JsonFieldPage::tr("The text edit input to fix up."),
|
2014-11-13 15:54:26 +01:00
|
|
|
[this]() { return m_currentInput; });
|
2015-02-03 23:59:04 +02:00
|
|
|
m_expander.registerSubProvider([expander]() -> MacroExpander * { return expander; });
|
2014-11-13 15:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setFixupExpando(const QString &expando)
|
|
|
|
|
{
|
|
|
|
|
m_fixupExpando = expando;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QValidator::State validate(QString &input, int &pos) const
|
|
|
|
|
{
|
|
|
|
|
fixup(input);
|
|
|
|
|
return QRegularExpressionValidator::validate(input, pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fixup(QString &fixup) const
|
|
|
|
|
{
|
|
|
|
|
if (m_fixupExpando.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_currentInput = fixup;
|
|
|
|
|
fixup = m_expander.expand(m_fixupExpando);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MacroExpander m_expander;
|
|
|
|
|
QString m_fixupExpando;
|
|
|
|
|
mutable QString m_currentInput;
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// JsonFieldPage::FieldData:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
JsonFieldPage::Field *JsonFieldPage::Field::parse(const QVariant &input, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (input.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"Field is not an object.");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = input.toMap();
|
|
|
|
|
const QString name = tmp.value(QLatin1String(NAME_KEY)).toString();
|
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"Field has no name.");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
const QString type = tmp.value(QLatin1String(TYPE_KEY)).toString();
|
|
|
|
|
if (type.isEmpty()) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-03-16 14:10:48 +01:00
|
|
|
"Field \"%1\" has no type.").arg(name);
|
2014-10-09 11:21:06 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Field *data = createFieldData(type);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-03-16 14:10:48 +01:00
|
|
|
"Field \"%1\" has unsupported type \"%2\".")
|
2014-10-09 11:21:06 +02:00
|
|
|
.arg(name).arg(type);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
data->name = name;
|
2015-05-12 14:36:10 +02:00
|
|
|
data->toolTip = tmp.value(QLatin1String(TOOLTIP_KEY)).toString();
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
data->m_visibleExpression = tmp.value(QLatin1String(VISIBLE_KEY), true);
|
|
|
|
|
data->m_enabledExpression = tmp.value(QLatin1String(ENABLED_KEY), true);
|
|
|
|
|
data->mandatory = tmp.value(QLatin1String(MANDATORY_KEY), true).toBool();
|
|
|
|
|
data->span = tmp.value(QLatin1String(SPAN_KEY), false).toBool();
|
2015-05-08 10:42:48 +02:00
|
|
|
data->m_isCompleteExpando = tmp.value(QLatin1String(IS_COMPLETE_KEY), true);
|
|
|
|
|
data->m_isCompleteExpandoMessage = tmp.value(QLatin1String(IS_COMPLETE_MESSAGE_KEY)).toString();
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
data->displayName = JsonWizardFactory::localizedString(tmp.value(QLatin1String(DISPLAY_NAME_KEY)).toString());
|
|
|
|
|
|
|
|
|
|
QVariant dataVal = tmp.value(QLatin1String(DATA_KEY));
|
|
|
|
|
if (!data->parseData(dataVal, errorMessage)) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-03-16 14:10:48 +01:00
|
|
|
"When parsing Field \"%1\": %2")
|
2014-10-09 11:21:06 +02:00
|
|
|
.arg(name).arg(*errorMessage);
|
|
|
|
|
delete data;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::Field::createWidget(JsonFieldPage *page)
|
|
|
|
|
{
|
2014-11-13 15:54:26 +01:00
|
|
|
QWidget *w = widget(displayName, page);
|
2014-10-09 11:21:06 +02:00
|
|
|
w->setObjectName(name);
|
|
|
|
|
QFormLayout *layout = page->layout();
|
|
|
|
|
|
|
|
|
|
if (suppressName())
|
|
|
|
|
layout->addWidget(w);
|
|
|
|
|
else if (span)
|
|
|
|
|
layout->addRow(w);
|
|
|
|
|
else
|
|
|
|
|
layout->addRow(displayName, w);
|
|
|
|
|
|
|
|
|
|
setup(page, name);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
void JsonFieldPage::Field::adjustState(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
setVisible(JsonWizard::boolFromVariant(m_visibleExpression, expander));
|
|
|
|
|
setEnabled(JsonWizard::boolFromVariant(m_enabledExpression, expander));
|
2015-05-12 14:36:10 +02:00
|
|
|
QTC_ASSERT(m_widget, return);
|
|
|
|
|
m_widget->setToolTip(expander->expand(toolTip));
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-08 10:42:48 +02:00
|
|
|
bool JsonFieldPage::Field::validate(MacroExpander *expander, QString *message)
|
|
|
|
|
{
|
|
|
|
|
if (!JsonWizard::boolFromVariant(m_isCompleteExpando, expander)) {
|
|
|
|
|
if (message)
|
|
|
|
|
*message = expander->expand(m_isCompleteExpandoMessage);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
void JsonFieldPage::Field::initialize(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
adjustState(expander);
|
|
|
|
|
initializeData(expander);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// JsonFieldPage::LabelFieldData:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
JsonFieldPage::LabelField::LabelField() :
|
|
|
|
|
m_wordWrap(false)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
bool JsonFieldPage::LabelField::parseData(const QVariant &data, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"Label data is not an object.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
|
|
|
|
m_wordWrap = tmp.value(QLatin1String("wordWrap"), false).toBool();
|
|
|
|
|
m_text = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trText")));
|
|
|
|
|
|
|
|
|
|
if (m_text.isEmpty()) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"No text given for Label.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
QWidget *JsonFieldPage::LabelField::widget(const QString &displayName, JsonFieldPage *page)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(displayName);
|
2014-11-13 15:54:26 +01:00
|
|
|
Q_UNUSED(page);
|
2014-10-09 11:21:06 +02:00
|
|
|
QTC_ASSERT(!m_widget, return m_widget);
|
|
|
|
|
|
|
|
|
|
QLabel *w = new QLabel();
|
|
|
|
|
w->setWordWrap(m_wordWrap);
|
|
|
|
|
w->setText(m_text);
|
|
|
|
|
|
|
|
|
|
m_widget = w;
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// JsonFieldPage::SpacerFieldData:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
JsonFieldPage::SpacerField::SpacerField() :
|
2014-10-15 12:05:17 +02:00
|
|
|
m_factor(1)
|
2014-10-09 11:21:06 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
bool JsonFieldPage::SpacerField::parseData(const QVariant &data, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (data.isNull())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"Spacer data is not an object.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
|
|
|
|
bool ok;
|
2014-10-15 12:05:17 +02:00
|
|
|
m_factor = tmp.value(QLatin1String("factor"), 1).toInt(&ok);
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-03-16 14:10:48 +01:00
|
|
|
"\"factor\" is no integer value.");
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
QWidget *JsonFieldPage::SpacerField::widget(const QString &displayName, JsonFieldPage *page)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(displayName);
|
2014-11-13 15:54:26 +01:00
|
|
|
Q_UNUSED(page);
|
2014-10-09 11:21:06 +02:00
|
|
|
QTC_ASSERT(!m_widget, return m_widget);
|
|
|
|
|
|
2014-10-15 12:05:17 +02:00
|
|
|
int size = qApp->style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing) * m_factor;
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
m_widget = new QWidget();
|
|
|
|
|
m_widget->setMinimumSize(size, size);
|
|
|
|
|
m_widget->setMaximumSize(size, size);
|
|
|
|
|
m_widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// JsonFieldPage::LineEditFieldData:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
JsonFieldPage::LineEditField::LineEditField() : m_isModified(false), m_isValidating(false)
|
2014-10-09 11:21:06 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
bool JsonFieldPage::LineEditField::parseData(const QVariant &data, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (data.isNull())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"LineEdit data is not an object.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
|
|
|
|
m_defaultText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trText")).toString());
|
|
|
|
|
m_disabledText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trDisabledText")).toString());
|
|
|
|
|
m_placeholderText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trPlaceholder")).toString());
|
2014-10-15 13:19:05 +02:00
|
|
|
QString pattern = tmp.value(QLatin1String("validator")).toString();
|
|
|
|
|
if (!pattern.isEmpty()) {
|
2014-11-13 15:54:26 +01:00
|
|
|
m_validatorRegExp = QRegularExpression(pattern);
|
|
|
|
|
if (!m_validatorRegExp.isValid()) {
|
2014-10-15 13:19:05 +02:00
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"Invalid regular expression \"%1\" in \"validator\".")
|
|
|
|
|
.arg(pattern);
|
2014-11-13 15:54:26 +01:00
|
|
|
m_validatorRegExp = QRegularExpression();
|
2014-10-15 13:19:05 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-13 15:54:26 +01:00
|
|
|
m_fixupExpando = tmp.value(QLatin1String("fixup")).toString();
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
QWidget *JsonFieldPage::LineEditField::widget(const QString &displayName, JsonFieldPage *page)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(displayName);
|
|
|
|
|
QTC_ASSERT(!m_widget, return m_widget);
|
|
|
|
|
QLineEdit *w = new QLineEdit;
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
if (m_validatorRegExp.isValid()) {
|
|
|
|
|
LineEditValidator *lv = new LineEditValidator(page->expander(), m_validatorRegExp, w);
|
|
|
|
|
lv->setFixupExpando(m_fixupExpando);
|
|
|
|
|
w->setValidator(lv);
|
|
|
|
|
}
|
2014-10-15 13:19:05 +02:00
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
m_widget = w;
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::LineEditField::setup(JsonFieldPage *page, const QString &name)
|
|
|
|
|
{
|
|
|
|
|
QLineEdit *w = static_cast<QLineEdit *>(m_widget);
|
|
|
|
|
page->registerFieldWithName(name, w);
|
2014-11-13 15:54:26 +01:00
|
|
|
connect(w, &QLineEdit::textChanged,
|
|
|
|
|
page, [this, page]() -> void { m_isModified = true; emit page->completeChanged(); });
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
bool JsonFieldPage::LineEditField::validate(MacroExpander *expander, QString *message)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2015-05-08 10:42:48 +02:00
|
|
|
if (!JsonFieldPage::Field::validate(expander, message))
|
|
|
|
|
return false;
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
if (m_isValidating)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
m_isValidating = true;
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
QLineEdit *w = static_cast<QLineEdit *>(m_widget);
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
if (w->isEnabled()) {
|
|
|
|
|
if (m_isModified) {
|
|
|
|
|
if (!m_currentText.isNull()) {
|
|
|
|
|
w->setText(m_currentText);
|
|
|
|
|
m_currentText.clear();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
w->setText(expander->expand(m_defaultText));
|
|
|
|
|
m_isModified = false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!m_disabledText.isNull() && m_currentText.isNull())
|
|
|
|
|
m_currentText = w->text();
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
m_isValidating = false;
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
return !w->text().isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
void JsonFieldPage::LineEditField::initializeData(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_widget, return);
|
|
|
|
|
|
|
|
|
|
QLineEdit *w = static_cast<QLineEdit *>(m_widget);
|
2014-11-13 15:54:26 +01:00
|
|
|
m_isValidating = true;
|
2014-10-15 14:45:31 +02:00
|
|
|
w->setText(expander->expand(m_defaultText));
|
2014-10-09 11:21:06 +02:00
|
|
|
w->setPlaceholderText(m_placeholderText);
|
2014-11-13 15:54:26 +01:00
|
|
|
m_isModified = false;
|
|
|
|
|
m_isValidating = false;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// JsonFieldPage::TextEditFieldData:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JsonFieldPage::TextEditField::TextEditField() :
|
|
|
|
|
m_acceptRichText(false)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
bool JsonFieldPage::TextEditField::parseData(const QVariant &data, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (data.isNull())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"TextEdit data is not an object.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
|
|
|
|
m_defaultText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trText")).toString());
|
|
|
|
|
m_disabledText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trDisabledText")).toString());
|
|
|
|
|
m_acceptRichText = tmp.value(QLatin1String("richText"), true).toBool();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
QWidget *JsonFieldPage::TextEditField::widget(const QString &displayName, JsonFieldPage *page)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
// TODO: Set up modification monitoring...
|
|
|
|
|
Q_UNUSED(displayName);
|
2014-11-13 15:54:26 +01:00
|
|
|
Q_UNUSED(page);
|
2014-10-09 11:21:06 +02:00
|
|
|
QTC_ASSERT(!m_widget, return m_widget);
|
|
|
|
|
QTextEdit *w = new QTextEdit;
|
|
|
|
|
w->setAcceptRichText(m_acceptRichText);
|
|
|
|
|
m_widget = w;
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::TextEditField::setup(JsonFieldPage *page, const QString &name)
|
|
|
|
|
{
|
|
|
|
|
QTextEdit *w = static_cast<QTextEdit *>(m_widget);
|
|
|
|
|
page->registerFieldWithName(name, w, "plainText", SIGNAL(textChanged()));
|
|
|
|
|
connect(w, &QTextEdit::textChanged, page, &QWizardPage::completeChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
bool JsonFieldPage::TextEditField::validate(MacroExpander *expander, QString *message)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2015-05-08 10:42:48 +02:00
|
|
|
if (!JsonFieldPage::Field::validate(expander, message))
|
|
|
|
|
return false;
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
QTextEdit *w = static_cast<QTextEdit *>(m_widget);
|
|
|
|
|
|
|
|
|
|
if (!w->isEnabled() && !m_disabledText.isNull() && m_currentText.isNull()) {
|
|
|
|
|
m_currentText = w->toHtml();
|
2014-10-15 14:45:31 +02:00
|
|
|
w->setPlainText(expander->expand(m_disabledText));
|
2014-10-09 11:21:06 +02:00
|
|
|
} else if (w->isEnabled() && !m_currentText.isNull()) {
|
|
|
|
|
w->setText(m_currentText);
|
|
|
|
|
m_currentText.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !w->toPlainText().isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
void JsonFieldPage::TextEditField::initializeData(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
QTextEdit *w = static_cast<QTextEdit *>(m_widget);
|
2014-10-15 14:45:31 +02:00
|
|
|
w->setPlainText(expander->expand(m_defaultText));
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// JsonFieldPage::PathChooserFieldData:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
JsonFieldPage::PathChooserField::PathChooserField() :
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind(PathChooser::ExistingDirectory)
|
2014-10-09 11:21:06 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
bool JsonFieldPage::PathChooserField::parseData(const QVariant &data, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (data.isNull())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"PathChooser data is not an object.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
|
|
|
|
m_path = tmp.value(QLatin1String("path")).toString();
|
|
|
|
|
m_basePath = tmp.value(QLatin1String("basePath")).toString();
|
|
|
|
|
|
|
|
|
|
QString kindStr = tmp.value(QLatin1String("kind"), QLatin1String("existingDirectory")).toString();
|
|
|
|
|
if (kindStr == QLatin1String("existingDirectory")) {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::ExistingDirectory;
|
2014-10-09 11:21:06 +02:00
|
|
|
} else if (kindStr == QLatin1String("directory")) {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::Directory;
|
2014-10-09 11:21:06 +02:00
|
|
|
} else if (kindStr == QLatin1String("file")) {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::File;
|
2014-10-09 11:21:06 +02:00
|
|
|
} else if (kindStr == QLatin1String("saveFile")) {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::SaveFile;
|
2014-10-09 11:21:06 +02:00
|
|
|
} else if (kindStr == QLatin1String("existingCommand")) {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::ExistingCommand;
|
2014-10-09 11:21:06 +02:00
|
|
|
} else if (kindStr == QLatin1String("command")) {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::Command;
|
2014-10-09 11:21:06 +02:00
|
|
|
} else if (kindStr == QLatin1String("any")) {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::Any;
|
2014-10-09 11:21:06 +02:00
|
|
|
} else {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-03-16 14:10:48 +01:00
|
|
|
"kind \"%1\" is not one of the supported \"existingDirectory\", "
|
|
|
|
|
"\"directory\", \"file\", \"saveFile\", \"existingCommand\", "
|
|
|
|
|
"\"command\", \"any\".")
|
2014-10-09 11:21:06 +02:00
|
|
|
.arg(kindStr);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
QWidget *JsonFieldPage::PathChooserField::widget(const QString &displayName, JsonFieldPage *page)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(displayName);
|
2014-11-13 15:54:26 +01:00
|
|
|
Q_UNUSED(page);
|
2014-10-09 11:21:06 +02:00
|
|
|
QTC_ASSERT(!m_widget, return m_widget);
|
2014-10-15 14:45:31 +02:00
|
|
|
m_widget = new PathChooser;
|
2014-10-09 11:21:06 +02:00
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::PathChooserField::setEnabled(bool e)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_widget, return);
|
2014-10-15 14:45:31 +02:00
|
|
|
PathChooser *w = static_cast<PathChooser *>(m_widget);
|
2014-10-09 11:21:06 +02:00
|
|
|
w->setReadOnly(!e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::PathChooserField::setup(JsonFieldPage *page, const QString &name)
|
|
|
|
|
{
|
2014-10-15 14:45:31 +02:00
|
|
|
PathChooser *w = static_cast<PathChooser *>(m_widget);
|
2014-10-09 11:21:06 +02:00
|
|
|
page->registerFieldWithName(name, w, "path", SIGNAL(changed(QString)));
|
2014-10-15 14:45:31 +02:00
|
|
|
connect(w, &PathChooser::changed, page, [page](QString) { page->completeChanged(); });
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
bool JsonFieldPage::PathChooserField::validate(MacroExpander *expander, QString *message)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2015-05-08 10:42:48 +02:00
|
|
|
if (!JsonFieldPage::Field::validate(expander, message))
|
|
|
|
|
return false;
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
PathChooser *w = static_cast<PathChooser *>(m_widget);
|
2014-10-09 11:21:06 +02:00
|
|
|
return w->isValid();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
void JsonFieldPage::PathChooserField::initializeData(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_widget, return);
|
2014-10-15 14:45:31 +02:00
|
|
|
PathChooser *w = static_cast<PathChooser *>(m_widget);
|
|
|
|
|
w->setBaseDirectory(expander->expand(m_basePath));
|
2014-10-09 11:21:06 +02:00
|
|
|
w->setExpectedKind(m_kind);
|
|
|
|
|
|
|
|
|
|
if (m_currentPath.isNull())
|
2014-10-15 14:45:31 +02:00
|
|
|
w->setPath(expander->expand(m_path));
|
2014-10-09 11:21:06 +02:00
|
|
|
else
|
|
|
|
|
w->setPath(m_currentPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// JsonFieldPage::CheckBoxFieldData:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
JsonFieldPage::CheckBoxField::CheckBoxField() :
|
|
|
|
|
m_checkedValue(QLatin1String("0")),
|
|
|
|
|
m_uncheckedValue(QLatin1String("1")),
|
|
|
|
|
m_isModified(false)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
bool JsonFieldPage::CheckBoxField::parseData(const QVariant &data, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (data.isNull())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"CheckBox data is not an object.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
2015-05-28 15:51:05 +02:00
|
|
|
m_checkedValue = tmp.value(QLatin1String("checkedValue"), true).toString();
|
|
|
|
|
m_uncheckedValue = tmp.value(QLatin1String("uncheckedValue"), false).toString();
|
2014-10-09 11:21:06 +02:00
|
|
|
if (m_checkedValue == m_uncheckedValue) {
|
|
|
|
|
*errorMessage= QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"CheckBox values for checked and unchecked state are identical.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
m_checkedExpression = tmp.value(QLatin1String("checked"), false);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
QWidget *JsonFieldPage::CheckBoxField::widget(const QString &displayName, JsonFieldPage *page)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2014-11-13 15:54:26 +01:00
|
|
|
Q_UNUSED(page);
|
2014-10-09 11:21:06 +02:00
|
|
|
QTC_ASSERT(!m_widget, return m_widget);
|
2014-10-15 14:45:31 +02:00
|
|
|
TextFieldCheckBox *w = new TextFieldCheckBox(displayName);
|
2014-10-09 11:21:06 +02:00
|
|
|
m_widget = w;
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::CheckBoxField::setup(JsonFieldPage *page, const QString &name)
|
|
|
|
|
{
|
2014-10-15 14:45:31 +02:00
|
|
|
TextFieldCheckBox *w = static_cast<TextFieldCheckBox *>(m_widget);
|
2015-05-11 17:15:41 +02:00
|
|
|
connect(w, &TextFieldCheckBox::clicked, [this, page]() { m_isModified = true; page->completeChanged();});
|
2014-10-09 11:21:06 +02:00
|
|
|
page->registerFieldWithName(name, w, "text", SIGNAL(textChanged(QString)));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
bool JsonFieldPage::CheckBoxField::validate(MacroExpander *expander, QString *message)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2015-05-08 10:42:48 +02:00
|
|
|
if (!JsonFieldPage::Field::validate(expander, message))
|
|
|
|
|
return false;
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
if (!m_isModified) {
|
2014-10-15 14:45:31 +02:00
|
|
|
TextFieldCheckBox *w = static_cast<TextFieldCheckBox *>(m_widget);
|
2014-10-09 11:21:06 +02:00
|
|
|
w->setChecked(JsonWizard::boolFromVariant(m_checkedExpression, expander));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
void JsonFieldPage::CheckBoxField::initializeData(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_widget, return);
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
TextFieldCheckBox *w = static_cast<TextFieldCheckBox *>(m_widget);
|
|
|
|
|
w->setTrueText(expander->expand(m_checkedValue));
|
|
|
|
|
w->setFalseText(expander->expand(m_uncheckedValue));
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
w->setChecked(JsonWizard::boolFromVariant(m_checkedExpression, expander));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// JsonFieldPage::ComboBoxFieldData:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
JsonFieldPage::ComboBoxField::ComboBoxField() :
|
2015-05-19 17:36:16 +02:00
|
|
|
m_index(-1), m_disabledIndex(-1), m_savedIndex(-1)
|
2014-10-09 11:21:06 +02:00
|
|
|
{ }
|
|
|
|
|
|
2015-05-20 10:10:13 +02:00
|
|
|
struct ComboBoxItem {
|
|
|
|
|
ComboBoxItem(const QString &k = QString(), const QString &v = QString(), const QVariant &c = true) :
|
|
|
|
|
key(k), value(v), condition(c)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
QString key;
|
|
|
|
|
QString value;
|
|
|
|
|
QVariant condition;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ComboBoxItem parseComboBoxItem(const QVariant &item, QString *errorMessage)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
if (item.type() == QVariant::List) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"No lists allowed inside ComboBox items list.");
|
2015-05-20 10:10:13 +02:00
|
|
|
return ComboBoxItem();
|
2014-10-09 11:21:06 +02:00
|
|
|
} else if (item.type() == QVariant::Map) {
|
|
|
|
|
QVariantMap tmp = item.toMap();
|
|
|
|
|
QString key = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trKey"), QString()).toString());
|
|
|
|
|
QString value = tmp.value(QLatin1String("value"), QString()).toString();
|
2015-05-20 10:10:13 +02:00
|
|
|
QVariant condition = tmp.value(QLatin1String("condition"), true);
|
2014-10-09 11:21:06 +02:00
|
|
|
if (key.isNull() || key.isEmpty()) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-03-16 14:10:48 +01:00
|
|
|
"No \"key\" found in ComboBox items.");
|
2015-05-20 10:10:13 +02:00
|
|
|
return ComboBoxItem();
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
if (value.isNull())
|
|
|
|
|
value = key;
|
2015-05-20 10:10:13 +02:00
|
|
|
return ComboBoxItem(key, value, condition);
|
2014-10-09 11:21:06 +02:00
|
|
|
} else {
|
|
|
|
|
QString keyvalue = item.toString();
|
2015-05-20 10:10:13 +02:00
|
|
|
return ComboBoxItem(keyvalue, keyvalue);
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool JsonFieldPage::ComboBoxField::parseData(const QVariant &data, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"ComboBox data is not an object.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
|
m_index = tmp.value(QLatin1String("index"), 0).toInt(&ok);
|
|
|
|
|
if (!ok) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-03-16 14:10:48 +01:00
|
|
|
"ComboBox \"index\" is not an integer value.");
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
m_disabledIndex = tmp.value(QLatin1String("disabledIndex"), -1).toInt(&ok);
|
|
|
|
|
if (!ok) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-03-16 14:10:48 +01:00
|
|
|
"ComboBox \"disabledIndex\" is not an integer value.");
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant value = tmp.value(QLatin1String("items"));
|
|
|
|
|
if (value.isNull()) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-03-16 14:10:48 +01:00
|
|
|
"ComboBox \"items\" missing.");
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (value.type() != QVariant::List) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-03-16 14:10:48 +01:00
|
|
|
"ComboBox \"items\" is not a list.");
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (const QVariant &i, value.toList()) {
|
2015-05-20 10:10:13 +02:00
|
|
|
ComboBoxItem keyValue = parseComboBoxItem(i, errorMessage);
|
|
|
|
|
if (keyValue.key.isNull())
|
2014-10-09 11:21:06 +02:00
|
|
|
return false; // an error happened...
|
2015-05-20 10:10:13 +02:00
|
|
|
m_itemList.append(keyValue.key);
|
|
|
|
|
m_itemDataList.append(keyValue.value);
|
|
|
|
|
m_itemConditionList.append(keyValue.condition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_itemConditionList.count() != m_itemDataList.count()
|
|
|
|
|
|| m_itemConditionList.count() != m_itemList.count()) {
|
|
|
|
|
m_itemConditionList.clear();
|
|
|
|
|
m_itemDataList.clear();
|
|
|
|
|
m_itemList.clear();
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-07-03 10:20:21 +02:00
|
|
|
"Internal Error: ComboBox items lists got mixed up.");
|
2015-05-20 10:10:13 +02:00
|
|
|
return false;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
QWidget *JsonFieldPage::ComboBoxField::widget(const QString &displayName, JsonFieldPage *page)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(displayName);
|
2014-11-13 15:54:26 +01:00
|
|
|
Q_UNUSED(page);
|
2014-10-09 11:21:06 +02:00
|
|
|
QTC_ASSERT(!m_widget, return m_widget);
|
2014-10-15 14:45:31 +02:00
|
|
|
m_widget = new TextFieldComboBox;
|
2014-10-09 11:21:06 +02:00
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::ComboBoxField::setup(JsonFieldPage *page, const QString &name)
|
|
|
|
|
{
|
2014-10-15 14:45:31 +02:00
|
|
|
TextFieldComboBox *w = static_cast<TextFieldComboBox *>(m_widget);
|
2014-10-09 11:21:06 +02:00
|
|
|
page->registerFieldWithName(name, w, "text", SIGNAL(text4Changed(QString)));
|
2014-10-15 14:45:31 +02:00
|
|
|
connect(w, &TextFieldComboBox::text4Changed, page, [page](QString) { page->completeChanged(); });
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
bool JsonFieldPage::ComboBoxField::validate(MacroExpander *expander, QString *message)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2015-05-08 10:42:48 +02:00
|
|
|
if (!JsonFieldPage::Field::validate(expander, message))
|
|
|
|
|
return false;
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
TextFieldComboBox *w = static_cast<TextFieldComboBox *>(m_widget);
|
2014-10-09 11:21:06 +02:00
|
|
|
if (!w->isEnabled() && m_disabledIndex >= 0 && m_savedIndex < 0) {
|
|
|
|
|
m_savedIndex = w->currentIndex();
|
|
|
|
|
w->setCurrentIndex(m_disabledIndex);
|
|
|
|
|
} else if (w->isEnabled() && m_savedIndex >= 0) {
|
|
|
|
|
w->setCurrentIndex(m_savedIndex);
|
|
|
|
|
m_savedIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
void JsonFieldPage::ComboBoxField::initializeData(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2014-10-15 14:45:31 +02:00
|
|
|
TextFieldComboBox *w = static_cast<TextFieldComboBox *>(m_widget);
|
2014-10-09 11:21:06 +02:00
|
|
|
QStringList tmpItems
|
|
|
|
|
= Utils::transform(m_itemList,
|
2014-10-15 14:45:31 +02:00
|
|
|
[expander](const QString &i) { return expander->expand(i); });
|
2014-10-09 11:21:06 +02:00
|
|
|
QStringList tmpData
|
|
|
|
|
= Utils::transform(m_itemDataList,
|
2014-10-15 14:45:31 +02:00
|
|
|
[expander](const QString &i) { return expander->expand(i); });
|
2015-05-20 10:10:13 +02:00
|
|
|
QList<bool> tmpConditions
|
|
|
|
|
= Utils::transform(m_itemConditionList,
|
|
|
|
|
[expander](const QVariant &v) { return JsonWizard::boolFromVariant(v, expander); });
|
|
|
|
|
|
|
|
|
|
int index = m_index;
|
|
|
|
|
for (int i = tmpConditions.count() - 1; i >= 0; --i) {
|
|
|
|
|
if (!tmpConditions.at(i)) {
|
|
|
|
|
tmpItems.removeAt(i);
|
|
|
|
|
tmpData.removeAt(i);
|
2015-07-08 13:51:32 +02:00
|
|
|
if (i < index && index > 0)
|
2015-05-20 10:10:13 +02:00
|
|
|
--index;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-08 13:51:32 +02:00
|
|
|
|
|
|
|
|
if (index < 0 || index >= tmpData.count())
|
|
|
|
|
index = 0;
|
2014-10-09 11:21:06 +02:00
|
|
|
w->setItems(tmpItems, tmpData);
|
|
|
|
|
w->setInsertPolicy(QComboBox::NoInsert);
|
2015-05-20 10:10:13 +02:00
|
|
|
w->setCurrentIndex(index);
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// JsonFieldPage:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
JsonFieldPage::JsonFieldPage(MacroExpander *expander, QWidget *parent) :
|
|
|
|
|
WizardPage(parent),
|
2014-10-09 11:21:06 +02:00
|
|
|
m_formLayout(new QFormLayout),
|
|
|
|
|
m_errorLabel(new QLabel),
|
|
|
|
|
m_expander(expander)
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(m_expander);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *vLayout = new QVBoxLayout;
|
|
|
|
|
m_formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
|
|
|
|
vLayout->addLayout(m_formLayout);
|
|
|
|
|
m_errorLabel->setVisible(false);
|
2015-05-08 16:27:10 +02:00
|
|
|
QPalette palette = m_errorLabel->palette();
|
|
|
|
|
palette.setColor(QPalette::WindowText, creatorTheme()->color(Theme::TextColorError));
|
|
|
|
|
m_errorLabel->setPalette(palette);
|
2014-10-09 11:21:06 +02:00
|
|
|
vLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
|
|
|
|
|
vLayout->addWidget(m_errorLabel);
|
|
|
|
|
setLayout(vLayout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JsonFieldPage::~JsonFieldPage()
|
|
|
|
|
{
|
|
|
|
|
// Do not delete m_expander, it belongs to the wizard!
|
|
|
|
|
qDeleteAll(m_fields);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool JsonFieldPage::setup(const QVariant &data)
|
|
|
|
|
{
|
|
|
|
|
QString errorMessage;
|
|
|
|
|
QList<QVariant> fieldList = JsonWizardFactory::objectOrList(data, &errorMessage);
|
|
|
|
|
foreach (const QVariant &field, fieldList) {
|
|
|
|
|
Field *f = JsonFieldPage::Field::parse(field, &errorMessage);
|
|
|
|
|
if (!f)
|
|
|
|
|
continue;
|
|
|
|
|
f->createWidget(this);
|
|
|
|
|
m_fields.append(f);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool JsonFieldPage::isComplete() const
|
|
|
|
|
{
|
|
|
|
|
QString message;
|
|
|
|
|
|
|
|
|
|
bool result = true;
|
|
|
|
|
bool hasErrorMessage = false;
|
|
|
|
|
foreach (Field *f, m_fields) {
|
|
|
|
|
f->adjustState(m_expander);
|
|
|
|
|
if (!f->validate(m_expander, &message)) {
|
|
|
|
|
if (!message.isEmpty()) {
|
|
|
|
|
showError(message);
|
|
|
|
|
hasErrorMessage = true;
|
|
|
|
|
}
|
|
|
|
|
if (f->mandatory)
|
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hasErrorMessage)
|
|
|
|
|
clearError();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::initializePage()
|
|
|
|
|
{
|
|
|
|
|
foreach (Field *f, m_fields)
|
|
|
|
|
f->initialize(m_expander);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::cleanupPage()
|
|
|
|
|
{
|
|
|
|
|
foreach (Field *f, m_fields)
|
|
|
|
|
f->cleanup(m_expander);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::showError(const QString &m) const
|
|
|
|
|
{
|
|
|
|
|
m_errorLabel->setText(m);
|
|
|
|
|
m_errorLabel->setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::clearError() const
|
|
|
|
|
{
|
|
|
|
|
m_errorLabel->setText(QString());
|
|
|
|
|
m_errorLabel->setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
MacroExpander *JsonFieldPage::expander()
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
return m_expander;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ProjectExplorer
|