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
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "jsonfieldpage.h"
|
2015-09-21 15:22:31 +02:00
|
|
|
#include "jsonfieldpage_p.h"
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
#include "jsonwizard.h"
|
|
|
|
|
#include "jsonwizardfactory.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
2015-12-04 13:55:05 +01:00
|
|
|
#include <utils/fancylineedit.h>
|
2014-10-09 11:21:06 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/stringutils.h>
|
2015-05-08 16:27:10 +02:00
|
|
|
#include <utils/theme/theme.h>
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
#include <QComboBox>
|
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>
|
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>
|
2017-10-27 17:13:18 +02:00
|
|
|
#include <QListView>
|
|
|
|
|
#include <QStandardItem>
|
|
|
|
|
#include <QItemSelectionModel>
|
|
|
|
|
#include <QDir>
|
2014-10-09 11:21:06 +02:00
|
|
|
|
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
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
namespace {
|
|
|
|
|
QVariant consumeValue(QVariantMap &map, const QString &key, const QVariant &defaultValue = QVariant())
|
|
|
|
|
{
|
|
|
|
|
QVariantMap::iterator i = map.find(key);
|
|
|
|
|
if (i != map.end()) {
|
|
|
|
|
QVariant value = i.value();
|
|
|
|
|
map.erase(i);
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void warnAboutUnsupportedKeys(const QVariantMap &map, const QString &name, const QString &type = QString())
|
|
|
|
|
{
|
|
|
|
|
if (!map.isEmpty()) {
|
|
|
|
|
|
|
|
|
|
QString typeAndName = name;
|
|
|
|
|
if (!type.isEmpty() && !name.isEmpty())
|
2018-02-08 15:50:21 +01:00
|
|
|
typeAndName = QString("%1 (\"%2\")").arg(type, name);
|
2017-10-19 07:43:05 +02:00
|
|
|
|
|
|
|
|
qWarning().noquote() << QString("Field %1 has unsupported keys: %2").arg(typeAndName, map.keys().join(", "));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// Helper:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 22:17:17 +02:00
|
|
|
QValidator::State validate(QString &input, int &pos) const override
|
2014-11-13 15:54:26 +01:00
|
|
|
{
|
|
|
|
|
fixup(input);
|
|
|
|
|
return QRegularExpressionValidator::validate(input, pos);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 22:17:17 +02:00
|
|
|
void fixup(QString &fixup) const override
|
2014-11-13 15:54:26 +01:00
|
|
|
{
|
|
|
|
|
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:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
JsonFieldPage::Field::Field() : d(new FieldPrivate)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
JsonFieldPage::Field::~Field()
|
|
|
|
|
{
|
|
|
|
|
delete d->m_widget;
|
2016-05-28 11:23:30 -07:00
|
|
|
delete d->m_label;
|
2015-09-21 16:05:04 +02:00
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
QString JsonFieldPage::Field::type()
|
|
|
|
|
{
|
|
|
|
|
return d->m_type;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
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.");
|
2018-07-12 22:17:17 +02:00
|
|
|
return nullptr;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = input.toMap();
|
2017-10-19 07:43:05 +02:00
|
|
|
const QString name = consumeValue(tmp, NAME_KEY).toString();
|
2014-10-09 11:21:06 +02:00
|
|
|
if (name.isEmpty()) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
|
|
|
|
"Field has no name.");
|
2018-07-12 22:17:17 +02:00
|
|
|
return nullptr;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
2017-10-19 07:43:05 +02:00
|
|
|
const QString type = consumeValue(tmp, TYPE_KEY).toString();
|
2014-10-09 11:21:06 +02:00
|
|
|
if (type.isEmpty()) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2015-03-16 14:10:48 +01:00
|
|
|
"Field \"%1\" has no type.").arg(name);
|
2018-07-12 22:17:17 +02:00
|
|
|
return nullptr;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2018-07-12 22:17:17 +02:00
|
|
|
return nullptr;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
2015-09-21 16:05:04 +02:00
|
|
|
data->setTexts(name,
|
2017-10-19 07:43:05 +02:00
|
|
|
JsonWizardFactory::localizedString(consumeValue(tmp, DISPLAY_NAME_KEY).toString()),
|
|
|
|
|
consumeValue(tmp, TOOLTIP_KEY).toString());
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
data->setVisibleExpression(consumeValue(tmp, VISIBLE_KEY, true));
|
|
|
|
|
data->setEnabledExpression(consumeValue(tmp, ENABLED_KEY, true));
|
|
|
|
|
data->setIsMandatory(consumeValue(tmp, MANDATORY_KEY, true).toBool());
|
|
|
|
|
data->setHasSpan(consumeValue(tmp, SPAN_KEY, false).toBool());
|
|
|
|
|
data->setIsCompleteExpando(consumeValue(tmp, IS_COMPLETE_KEY, true),
|
|
|
|
|
consumeValue(tmp, IS_COMPLETE_MESSAGE_KEY).toString());
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
QVariant dataVal = consumeValue(tmp, DATA_KEY);
|
2014-10-09 11:21:06 +02:00
|
|
|
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;
|
2018-07-12 22:17:17 +02:00
|
|
|
return nullptr;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
warnAboutUnsupportedKeys(tmp, name);
|
2014-10-09 11:21:06 +02:00
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::Field::createWidget(JsonFieldPage *page)
|
|
|
|
|
{
|
2015-09-21 16:05:04 +02:00
|
|
|
QWidget *w = widget(displayName(), page);
|
|
|
|
|
w->setObjectName(name());
|
2014-10-09 11:21:06 +02:00
|
|
|
QFormLayout *layout = page->layout();
|
|
|
|
|
|
2016-05-28 11:23:30 -07:00
|
|
|
if (suppressName()) {
|
2014-10-09 11:21:06 +02:00
|
|
|
layout->addWidget(w);
|
2016-05-28 11:23:30 -07:00
|
|
|
} else if (hasSpan()) {
|
2017-09-26 11:01:34 +02:00
|
|
|
if (!suppressName()) {
|
|
|
|
|
d->m_label = new QLabel(displayName());
|
|
|
|
|
layout->addRow(d->m_label);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
layout->addRow(w);
|
2016-05-28 11:23:30 -07:00
|
|
|
} else {
|
|
|
|
|
d->m_label = new QLabel(displayName());
|
|
|
|
|
layout->addRow(d->m_label, w);
|
|
|
|
|
}
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
setup(page, name());
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:45:31 +02:00
|
|
|
void JsonFieldPage::Field::adjustState(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2015-09-21 16:05:04 +02:00
|
|
|
setVisible(JsonWizard::boolFromVariant(d->m_visibleExpression, expander));
|
|
|
|
|
setEnabled(JsonWizard::boolFromVariant(d->m_enabledExpression, expander));
|
|
|
|
|
QTC_ASSERT(d->m_widget, return);
|
|
|
|
|
d->m_widget->setToolTip(expander->expand(toolTip()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::Field::setEnabled(bool e)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d->m_widget, return);
|
|
|
|
|
d->m_widget->setEnabled(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::Field::setVisible(bool v)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d->m_widget, return);
|
2016-05-28 11:23:30 -07:00
|
|
|
if (d->m_label)
|
|
|
|
|
d->m_label->setVisible(v);
|
2015-09-21 16:05:04 +02:00
|
|
|
d->m_widget->setVisible(v);
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
void JsonFieldPage::Field::setType(const QString &type)
|
|
|
|
|
{
|
|
|
|
|
d->m_type = type;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 10:42:48 +02:00
|
|
|
bool JsonFieldPage::Field::validate(MacroExpander *expander, QString *message)
|
|
|
|
|
{
|
2015-09-21 16:05:04 +02:00
|
|
|
if (!JsonWizard::boolFromVariant(d->m_isCompleteExpando, expander)) {
|
2015-05-08 10:42:48 +02:00
|
|
|
if (message)
|
2015-09-21 16:05:04 +02:00
|
|
|
*message = expander->expand(d->m_isCompleteExpandoMessage);
|
2015-05-08 10:42:48 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
QWidget *JsonFieldPage::Field::widget(const QString &displayName, JsonFieldPage *page)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!d->m_widget, return d->m_widget);
|
|
|
|
|
|
|
|
|
|
d->m_widget = createWidget(displayName, page);
|
|
|
|
|
return d->m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString JsonFieldPage::Field::name()
|
|
|
|
|
{
|
|
|
|
|
return d->m_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString JsonFieldPage::Field::displayName()
|
|
|
|
|
{
|
|
|
|
|
return d->m_displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString JsonFieldPage::Field::toolTip()
|
|
|
|
|
{
|
|
|
|
|
return d->m_toolTip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool JsonFieldPage::Field::isMandatory()
|
|
|
|
|
{
|
|
|
|
|
return d->m_isMandatory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool JsonFieldPage::Field::hasSpan()
|
|
|
|
|
{
|
|
|
|
|
return d->m_hasSpan;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-19 11:59:56 +02:00
|
|
|
QVariant JsonFieldPage::value(const QString &key)
|
|
|
|
|
{
|
|
|
|
|
QVariant v = property(key.toUtf8());
|
|
|
|
|
if (v.isValid())
|
|
|
|
|
return v;
|
|
|
|
|
auto w = qobject_cast<JsonWizard *>(wizard());
|
|
|
|
|
QTC_ASSERT(w, return QVariant());
|
|
|
|
|
return w->value(key);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
QWidget *JsonFieldPage::Field::widget() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::Field::setTexts(const QString &n, const QString &dn, const QString &tt)
|
|
|
|
|
{
|
|
|
|
|
d->m_name = n;
|
|
|
|
|
d->m_displayName = dn;
|
|
|
|
|
d->m_toolTip = tt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::Field::setIsMandatory(bool b)
|
|
|
|
|
{
|
|
|
|
|
d->m_isMandatory = b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::Field::setHasSpan(bool b)
|
|
|
|
|
{
|
|
|
|
|
d->m_hasSpan = b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::Field::setVisibleExpression(const QVariant &v)
|
|
|
|
|
{
|
|
|
|
|
d->m_visibleExpression = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::Field::setEnabledExpression(const QVariant &v)
|
|
|
|
|
{
|
|
|
|
|
d->m_enabledExpression = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonFieldPage::Field::setIsCompleteExpando(const QVariant &v, const QString &m)
|
|
|
|
|
{
|
|
|
|
|
d->m_isCompleteExpando = v;
|
|
|
|
|
d->m_isCompleteExpandoMessage = m;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
// --------------------------------------------------------------------
|
2015-09-21 15:22:31 +02:00
|
|
|
// LabelFieldData:
|
2014-10-09 11:21:06 +02:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
bool LabelField::parseData(const QVariant &data, QString *errorMessage)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"Label (\"%1\") data is not an object.")
|
2017-10-19 07:43:05 +02:00
|
|
|
.arg(name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
m_wordWrap = consumeValue(tmp, "wordWrap", false).toBool();
|
|
|
|
|
m_text = JsonWizardFactory::localizedString(consumeValue(tmp, "trText"));
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
if (m_text.isEmpty()) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"Label (\"%1\") has no trText.")
|
2017-10-19 07:43:05 +02:00
|
|
|
.arg(name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2017-10-19 07:43:05 +02:00
|
|
|
warnAboutUnsupportedKeys(tmp, name(), type());
|
2014-10-09 11:21:06 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
QWidget *LabelField::createWidget(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);
|
2015-09-21 16:32:18 +02:00
|
|
|
auto w = new QLabel;
|
2014-10-09 11:21:06 +02:00
|
|
|
w->setWordWrap(m_wordWrap);
|
|
|
|
|
w->setText(m_text);
|
2015-09-21 16:05:04 +02:00
|
|
|
return w;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2015-09-21 15:22:31 +02:00
|
|
|
// SpacerFieldData:
|
2014-10-09 11:21:06 +02:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
bool SpacerField::parseData(const QVariant &data, QString *errorMessage)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
if (data.isNull())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"Spacer (\"%1\") data is not an object.")
|
2017-10-19 07:43:05 +02:00
|
|
|
.arg(name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
|
|
|
|
bool ok;
|
2017-10-19 07:43:05 +02:00
|
|
|
m_factor = consumeValue(tmp, "factor", 1).toInt(&ok);
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"Spacer (\"%1\") property \"factor\" is no integer value.")
|
2017-10-19 07:43:05 +02:00
|
|
|
.arg(name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2017-10-19 07:43:05 +02:00
|
|
|
warnAboutUnsupportedKeys(tmp, name(), type());
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
QWidget *SpacerField::createWidget(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);
|
2017-04-24 17:01:10 +02:00
|
|
|
int size = QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing) * m_factor;
|
2014-10-15 12:05:17 +02:00
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
auto w = new QWidget();
|
|
|
|
|
w->setMinimumSize(size, size);
|
|
|
|
|
w->setMaximumSize(size, size);
|
|
|
|
|
w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
|
return w;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2015-09-21 15:22:31 +02:00
|
|
|
// LineEditFieldData:
|
2014-10-09 11:21:06 +02:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
bool LineEditField::parseData(const QVariant &data, QString *errorMessage)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
if (data.isNull())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"LineEdit (\"%1\") data is not an object.")
|
2017-10-19 07:43:05 +02:00
|
|
|
.arg(name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
m_isPassword = consumeValue(tmp, "isPassword", false).toBool();
|
|
|
|
|
m_defaultText = JsonWizardFactory::localizedString(consumeValue(tmp, "trText").toString());
|
|
|
|
|
m_disabledText = JsonWizardFactory::localizedString(consumeValue(tmp, "trDisabledText").toString());
|
|
|
|
|
m_placeholderText = JsonWizardFactory::localizedString(consumeValue(tmp, "trPlaceholder").toString());
|
|
|
|
|
m_historyId = consumeValue(tmp, "historyId").toString();
|
|
|
|
|
m_restoreLastHistoryItem = consumeValue(tmp, "restoreLastHistoyItem", false).toBool();
|
|
|
|
|
QString pattern = consumeValue(tmp, "validator").toString();
|
2014-10-15 13:19:05 +02:00
|
|
|
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",
|
2018-02-08 15:50:21 +01:00
|
|
|
"LineEdit (\"%1\") has an invalid regular expression \"%2\" in \"validator\".")
|
2017-10-19 07:43:05 +02:00
|
|
|
.arg(name(), pattern);
|
2014-11-13 15:54:26 +01:00
|
|
|
m_validatorRegExp = QRegularExpression();
|
2014-10-15 13:19:05 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-19 07:43:05 +02:00
|
|
|
m_fixupExpando = consumeValue(tmp, "fixup").toString();
|
|
|
|
|
|
|
|
|
|
warnAboutUnsupportedKeys(tmp, name(), type());
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
QWidget *LineEditField::createWidget(const QString &displayName, JsonFieldPage *page)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(displayName);
|
2015-12-04 13:55:05 +01:00
|
|
|
auto w = new FancyLineEdit;
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2014-11-13 15:54:26 +01:00
|
|
|
if (m_validatorRegExp.isValid()) {
|
2015-09-21 16:32:18 +02:00
|
|
|
auto lv = new LineEditValidator(page->expander(), m_validatorRegExp, w);
|
2014-11-13 15:54:26 +01:00
|
|
|
lv->setFixupExpando(m_fixupExpando);
|
|
|
|
|
w->setValidator(lv);
|
|
|
|
|
}
|
2014-10-15 13:19:05 +02:00
|
|
|
|
2015-12-04 13:55:05 +01:00
|
|
|
if (!m_historyId.isEmpty())
|
|
|
|
|
w->setHistoryCompleter(m_historyId, m_restoreLastHistoryItem);
|
|
|
|
|
|
2016-10-09 11:55:09 +02:00
|
|
|
w->setEchoMode(m_isPassword ? QLineEdit::Password : QLineEdit::Normal);
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
return w;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
void LineEditField::setup(JsonFieldPage *page, const QString &name)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-06-29 12:37:34 +02:00
|
|
|
auto w = qobject_cast<FancyLineEdit *>(widget());
|
|
|
|
|
QTC_ASSERT(w, return);
|
2014-10-09 11:21:06 +02:00
|
|
|
page->registerFieldWithName(name, w);
|
2015-12-04 13:55:05 +01:00
|
|
|
QObject::connect(w, &FancyLineEdit::textChanged,
|
2015-09-21 15:22:31 +02:00
|
|
|
page, [this, page]() -> void { m_isModified = true; emit page->completeChanged(); });
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
bool 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;
|
|
|
|
|
|
2017-06-29 12:37:34 +02:00
|
|
|
auto w = qobject_cast<FancyLineEdit *>(widget());
|
|
|
|
|
QTC_ASSERT(w, return false);
|
2014-10-09 11:21:06 +02:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
void LineEditField::initializeData(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-06-29 12:37:34 +02:00
|
|
|
auto w = qobject_cast<FancyLineEdit *>(widget());
|
|
|
|
|
QTC_ASSERT(w, return);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2015-09-21 15:22:31 +02:00
|
|
|
// TextEditFieldData:
|
2014-10-09 11:21:06 +02:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
bool TextEditField::parseData(const QVariant &data, QString *errorMessage)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
if (data.isNull())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"TextEdit (\"%1\") data is not an object.")
|
2017-10-19 07:43:05 +02:00
|
|
|
.arg(name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
m_defaultText = JsonWizardFactory::localizedString(consumeValue(tmp, "trText").toString());
|
|
|
|
|
m_disabledText = JsonWizardFactory::localizedString(consumeValue(tmp, "trDisabledText").toString());
|
|
|
|
|
m_acceptRichText = consumeValue(tmp, "richText", true).toBool();
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
warnAboutUnsupportedKeys(tmp, name(), type());
|
2014-10-09 11:21:06 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
QWidget *TextEditField::createWidget(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);
|
2015-09-21 16:32:18 +02:00
|
|
|
auto w = new QTextEdit;
|
2014-10-09 11:21:06 +02:00
|
|
|
w->setAcceptRichText(m_acceptRichText);
|
2015-09-21 16:05:04 +02:00
|
|
|
return w;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
void TextEditField::setup(JsonFieldPage *page, const QString &name)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-06-29 12:37:34 +02:00
|
|
|
auto w = qobject_cast<QTextEdit *>(widget());
|
|
|
|
|
QTC_ASSERT(w, return);
|
2014-10-09 11:21:06 +02:00
|
|
|
page->registerFieldWithName(name, w, "plainText", SIGNAL(textChanged()));
|
2015-09-21 15:22:31 +02:00
|
|
|
QObject::connect(w, &QTextEdit::textChanged, page, &QWizardPage::completeChanged);
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
bool 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
|
|
|
|
2017-06-29 12:37:34 +02:00
|
|
|
auto w = qobject_cast<QTextEdit *>(widget());
|
|
|
|
|
QTC_ASSERT(w, return false);
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
void TextEditField::initializeData(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-06-29 12:37:34 +02:00
|
|
|
auto w = qobject_cast<QTextEdit *>(widget());
|
|
|
|
|
QTC_ASSERT(w, return);
|
2014-10-15 14:45:31 +02:00
|
|
|
w->setPlainText(expander->expand(m_defaultText));
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2015-09-21 15:22:31 +02:00
|
|
|
// PathChooserFieldData:
|
2014-10-09 11:21:06 +02:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
bool PathChooserField::parseData(const QVariant &data, QString *errorMessage)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
m_path = consumeValue(tmp, "path").toString();
|
|
|
|
|
m_basePath = consumeValue(tmp, "basePath").toString();
|
|
|
|
|
m_historyId = consumeValue(tmp, "historyId").toString();
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
QString kindStr = consumeValue(tmp, "kind", "existingDirectory").toString();
|
2017-06-15 10:39:41 +02:00
|
|
|
if (kindStr == "existingDirectory") {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::ExistingDirectory;
|
2017-06-15 10:39:41 +02:00
|
|
|
} else if (kindStr == "directory") {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::Directory;
|
2017-06-15 10:39:41 +02:00
|
|
|
} else if (kindStr == "file") {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::File;
|
2017-06-15 10:39:41 +02:00
|
|
|
} else if (kindStr == "saveFile") {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::SaveFile;
|
2017-06-15 10:39:41 +02:00
|
|
|
} else if (kindStr == "existingCommand") {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::ExistingCommand;
|
2017-06-15 10:39:41 +02:00
|
|
|
} else if (kindStr == "command") {
|
2014-10-15 14:45:31 +02:00
|
|
|
m_kind = PathChooser::Command;
|
2017-06-15 10:39:41 +02:00
|
|
|
} else if (kindStr == "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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
warnAboutUnsupportedKeys(tmp, name(), type());
|
2014-10-09 11:21:06 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
QWidget *PathChooserField::createWidget(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);
|
2015-12-04 13:55:05 +01:00
|
|
|
auto w = new PathChooser;
|
|
|
|
|
if (!m_historyId.isEmpty())
|
|
|
|
|
w->setHistoryCompleter(m_historyId);
|
|
|
|
|
return w;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
void PathChooserField::setEnabled(bool e)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-06-29 12:37:34 +02:00
|
|
|
auto w = qobject_cast<PathChooser *>(widget());
|
|
|
|
|
QTC_ASSERT(w, return);
|
2014-10-09 11:21:06 +02:00
|
|
|
w->setReadOnly(!e);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
void PathChooserField::setup(JsonFieldPage *page, const QString &name)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-06-29 12:37:34 +02:00
|
|
|
auto w = qobject_cast<PathChooser *>(widget());
|
|
|
|
|
QTC_ASSERT(w, return);
|
2015-08-20 14:56:30 +02:00
|
|
|
page->registerFieldWithName(name, w, "path", SIGNAL(rawPathChanged(QString)));
|
2015-09-21 15:22:31 +02:00
|
|
|
QObject::connect(w, &PathChooser::rawPathChanged,
|
|
|
|
|
page, [page](QString) { page->completeChanged(); });
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
bool 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;
|
|
|
|
|
|
2017-06-29 12:37:34 +02:00
|
|
|
auto w = qobject_cast<PathChooser *>(widget());
|
|
|
|
|
QTC_ASSERT(w, return false);
|
2014-10-09 11:21:06 +02:00
|
|
|
return w->isValid();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
void PathChooserField::initializeData(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-06-29 12:37:34 +02:00
|
|
|
auto w = qobject_cast<PathChooser *>(widget());
|
|
|
|
|
QTC_ASSERT(w, return);
|
2014-10-15 14:45:31 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2015-09-21 15:22:31 +02:00
|
|
|
// CheckBoxFieldData:
|
2014-10-09 11:21:06 +02:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
bool CheckBoxField::parseData(const QVariant &data, QString *errorMessage)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
if (data.isNull())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"CheckBox (\"%1\") data is not an object.")
|
2017-10-19 07:43:05 +02:00
|
|
|
.arg(name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
m_checkedValue = consumeValue(tmp, "checkedValue", true).toString();
|
|
|
|
|
m_uncheckedValue = consumeValue(tmp, "uncheckedValue", false).toString();
|
2014-10-09 11:21:06 +02:00
|
|
|
if (m_checkedValue == m_uncheckedValue) {
|
|
|
|
|
*errorMessage= QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"CheckBox (\"%1\") values for checked and unchecked state are identical.")
|
2017-10-19 07:43:05 +02:00
|
|
|
.arg(name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2017-10-19 07:43:05 +02:00
|
|
|
m_checkedExpression = consumeValue(tmp, "checked", false);
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
warnAboutUnsupportedKeys(tmp, name(), type());
|
2014-10-09 11:21:06 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 16:05:04 +02:00
|
|
|
QWidget *CheckBoxField::createWidget(const QString &displayName, JsonFieldPage *page)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2014-11-13 15:54:26 +01:00
|
|
|
Q_UNUSED(page);
|
2017-09-26 11:00:21 +02:00
|
|
|
return new QCheckBox(displayName);
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
void CheckBoxField::setup(JsonFieldPage *page, const QString &name)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-09-26 11:00:21 +02:00
|
|
|
auto w = qobject_cast<QCheckBox *>(widget());
|
2017-06-29 12:37:34 +02:00
|
|
|
QTC_ASSERT(w, return);
|
2017-09-26 11:00:21 +02:00
|
|
|
page->registerObjectAsFieldWithName<QCheckBox>(name, w, &QCheckBox::stateChanged, [this, page, w] () -> QString {
|
|
|
|
|
if (w->checkState() == Qt::Checked)
|
|
|
|
|
return page->expander()->expand(m_checkedValue);
|
|
|
|
|
return page->expander()->expand(m_uncheckedValue);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QObject::connect(w, &QCheckBox::stateChanged, page, [this, page]() {
|
|
|
|
|
m_isModified = true;
|
|
|
|
|
emit page->completeChanged();
|
|
|
|
|
});
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
bool 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) {
|
2017-09-26 11:00:21 +02:00
|
|
|
auto w = qobject_cast<QCheckBox *>(widget());
|
2017-06-29 12:37:34 +02:00
|
|
|
QTC_ASSERT(w, return false);
|
2014-10-09 11:21:06 +02:00
|
|
|
w->setChecked(JsonWizard::boolFromVariant(m_checkedExpression, expander));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
void CheckBoxField::initializeData(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-09-26 11:00:21 +02:00
|
|
|
auto w = qobject_cast<QCheckBox *>(widget());
|
2015-09-21 16:05:04 +02:00
|
|
|
QTC_ASSERT(widget(), return);
|
2014-10-09 11:21:06 +02:00
|
|
|
|
|
|
|
|
w->setChecked(JsonWizard::boolFromVariant(m_checkedExpression, expander));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2017-10-27 17:13:18 +02:00
|
|
|
// ListFieldData:
|
2014-10-09 11:21:06 +02:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
std::unique_ptr<QStandardItem> createStandardItemFromListItem(const QVariant &item, QString *errorMessage)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
if (item.type() == QVariant::List) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2017-10-27 17:13:18 +02:00
|
|
|
"No JSON lists allowed inside List items.");
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
auto standardItem = std::make_unique<QStandardItem>();
|
|
|
|
|
if (item.type() == QVariant::Map) {
|
2014-10-09 11:21:06 +02:00
|
|
|
QVariantMap tmp = item.toMap();
|
2017-10-27 17:13:18 +02:00
|
|
|
const QString key = JsonWizardFactory::localizedString(consumeValue(tmp, "trKey", QString()).toString());
|
|
|
|
|
const QString value = consumeValue(tmp, "value", key).toString();
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
if (key.isNull() || key.isEmpty()) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2017-10-27 17:13:18 +02:00
|
|
|
"No \"key\" found in List items.");
|
|
|
|
|
return {};
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
2017-10-27 17:13:18 +02:00
|
|
|
standardItem->setText(key);
|
|
|
|
|
standardItem->setData(value, ListField::ValueRole);
|
|
|
|
|
standardItem->setData(consumeValue(tmp, "condition", true), ListField::ConditionRole);
|
|
|
|
|
standardItem->setData(consumeValue(tmp, "icon"), ListField::IconStringRole);
|
|
|
|
|
standardItem->setToolTip(JsonWizardFactory::localizedString(consumeValue(tmp, "trToolTip", QString()).toString()));
|
|
|
|
|
warnAboutUnsupportedKeys(tmp, QString(), "List");
|
2014-10-09 11:21:06 +02:00
|
|
|
} else {
|
2017-10-27 17:13:18 +02:00
|
|
|
const QString keyvalue = item.toString();
|
|
|
|
|
standardItem->setText(keyvalue);
|
|
|
|
|
standardItem->setData(keyvalue, ListField::ValueRole);
|
|
|
|
|
standardItem->setData(true, ListField::ConditionRole);
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
2017-10-27 17:13:18 +02:00
|
|
|
return standardItem;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
ListField::ListField() = default;
|
|
|
|
|
|
|
|
|
|
ListField::~ListField() = default;
|
|
|
|
|
|
|
|
|
|
bool ListField::parseData(const QVariant &data, QString *errorMessage)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
|
|
|
|
if (data.type() != QVariant::Map) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"%1 (\"%2\") data is not an object.")
|
2017-10-27 17:13:18 +02:00
|
|
|
.arg(type(), name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap tmp = data.toMap();
|
|
|
|
|
|
|
|
|
|
bool ok;
|
2017-10-19 07:43:05 +02:00
|
|
|
m_index = consumeValue(tmp, "index", 0).toInt(&ok);
|
2014-10-09 11:21:06 +02:00
|
|
|
if (!ok) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"%1 (\"%2\") \"index\" is not an integer value.")
|
2017-10-27 17:13:18 +02:00
|
|
|
.arg(type(), name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2017-10-19 07:43:05 +02:00
|
|
|
m_disabledIndex = consumeValue(tmp, "disabledIndex", -1).toInt(&ok);
|
2014-10-09 11:21:06 +02:00
|
|
|
if (!ok) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"%1 (\"%2\") \"disabledIndex\" is not an integer value.")
|
2017-10-27 17:13:18 +02:00
|
|
|
.arg(type(), name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
const QVariant value = consumeValue(tmp, "items");
|
2014-10-09 11:21:06 +02:00
|
|
|
if (value.isNull()) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"%1 (\"%2\") \"items\" missing.")
|
2017-10-27 17:13:18 +02:00
|
|
|
.arg(type(), name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (value.type() != QVariant::List) {
|
|
|
|
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
2018-02-08 15:50:21 +01:00
|
|
|
"%1 (\"%2\") \"items\" is not a JSON list.")
|
2017-10-27 17:13:18 +02:00
|
|
|
.arg(type(), name());
|
2014-10-09 11:21:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
for (const QVariant &i : value.toList()) {
|
|
|
|
|
std::unique_ptr<QStandardItem> item = createStandardItemFromListItem(i, errorMessage);
|
|
|
|
|
QString test = item->text();
|
|
|
|
|
QTC_ASSERT(!item || !item->text().isEmpty(), continue);
|
|
|
|
|
m_itemList.emplace_back(std::move(item));
|
2015-05-20 10:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-19 07:43:05 +02:00
|
|
|
warnAboutUnsupportedKeys(tmp, name(), type());
|
2014-10-09 11:21:06 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
|
|
|
|
|
bool ListField::validate(MacroExpander *expander, QString *message)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-10-27 17:13:18 +02:00
|
|
|
if (!JsonFieldPage::Field::validate(expander, message))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
updateIndex();
|
|
|
|
|
if (selectionModel()->hasSelection())
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
void ListField::initializeData(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-10-27 17:13:18 +02:00
|
|
|
QTC_ASSERT(widget(), return);
|
|
|
|
|
|
2018-04-11 18:00:34 +02:00
|
|
|
if (m_index >= int(m_itemList.size())) {
|
2018-04-04 12:26:45 +02:00
|
|
|
qWarning().noquote() << QString("%1 (\"%2\") has an index of %3 which does not exist.").arg(type(), name(), QString::number(m_index));
|
|
|
|
|
m_index = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
QStandardItem *currentItem = m_index >= 0 ? m_itemList[uint(m_index)].get() : nullptr;
|
|
|
|
|
QList<QStandardItem*> expandedValuesItems;
|
|
|
|
|
expandedValuesItems.reserve(int(m_itemList.size()));
|
|
|
|
|
|
|
|
|
|
for (const std::unique_ptr<QStandardItem> &item : m_itemList) {
|
|
|
|
|
bool condition = JsonWizard::boolFromVariant(item->data(ConditionRole), expander);
|
|
|
|
|
if (!condition)
|
|
|
|
|
continue;
|
|
|
|
|
QStandardItem *expandedValuesItem = item->clone();
|
|
|
|
|
if (item.get() == currentItem)
|
|
|
|
|
currentItem = expandedValuesItem;
|
|
|
|
|
expandedValuesItem->setText(expander->expand(item->text()));
|
|
|
|
|
expandedValuesItem->setData(expander->expand(item->data(ValueRole).toString()), ValueRole);
|
|
|
|
|
expandedValuesItem->setData(expander->expand(item->data(IconStringRole).toString()), IconStringRole);
|
|
|
|
|
expandedValuesItem->setData(condition, ConditionRole);
|
|
|
|
|
|
|
|
|
|
QString iconPath = expandedValuesItem->data(IconStringRole).toString();
|
|
|
|
|
if (!iconPath.isEmpty()) {
|
2018-07-12 22:17:17 +02:00
|
|
|
if (auto *page = qobject_cast<JsonFieldPage*>(widget()->parentWidget())) {
|
2017-10-27 17:13:18 +02:00
|
|
|
const QString wizardDirectory = page->value("WizardDir").toString();
|
|
|
|
|
iconPath = QDir::cleanPath(QDir(wizardDirectory).absoluteFilePath(iconPath));
|
|
|
|
|
if (QFileInfo::exists(iconPath)) {
|
|
|
|
|
QIcon icon(iconPath);
|
|
|
|
|
expandedValuesItem->setIcon(icon);
|
|
|
|
|
addPossibleIconSize(icon);
|
|
|
|
|
} else {
|
|
|
|
|
qWarning().noquote() << QString("Icon file \"%1\" not found.").arg(QDir::toNativeSeparators(iconPath));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2018-02-08 15:50:21 +01:00
|
|
|
qWarning().noquote() << QString("%1 (\"%2\") has no parentWidget JsonFieldPage to get the icon path.").arg(type(), name());
|
2017-10-27 17:13:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
expandedValuesItems.append(expandedValuesItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itemModel()->clear();
|
|
|
|
|
itemModel()->appendColumn(expandedValuesItems); // inserts the first column
|
|
|
|
|
|
|
|
|
|
selectionModel()->setCurrentIndex(itemModel()->indexFromItem(currentItem), QItemSelectionModel::ClearAndSelect);
|
|
|
|
|
|
|
|
|
|
updateIndex();
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
QStandardItemModel *ListField::itemModel()
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-10-27 17:13:18 +02:00
|
|
|
if (!m_itemModel)
|
|
|
|
|
m_itemModel = new QStandardItemModel(widget());
|
|
|
|
|
return m_itemModel;
|
|
|
|
|
}
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
QItemSelectionModel *ListField::selectionModel()
|
|
|
|
|
{
|
|
|
|
|
return m_selectionModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ListField::setSelectionModel(QItemSelectionModel *selectionModel)
|
|
|
|
|
{
|
|
|
|
|
m_selectionModel = selectionModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize ListField::maxIconSize()
|
|
|
|
|
{
|
|
|
|
|
return m_maxIconSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ListField::addPossibleIconSize(const QIcon &icon)
|
|
|
|
|
{
|
|
|
|
|
const QSize iconSize = icon.availableSizes().value(0);
|
|
|
|
|
if (iconSize.height() > m_maxIconSize.height())
|
|
|
|
|
m_maxIconSize = iconSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ListField::updateIndex()
|
|
|
|
|
{
|
|
|
|
|
if (!widget()->isEnabled() && m_disabledIndex >= 0 && m_savedIndex < 0) {
|
|
|
|
|
m_savedIndex = selectionModel()->currentIndex().row();
|
|
|
|
|
selectionModel()->setCurrentIndex(itemModel()->index(m_disabledIndex, 0), QItemSelectionModel::ClearAndSelect);
|
|
|
|
|
} else if (widget()->isEnabled() && m_savedIndex >= 0) {
|
|
|
|
|
selectionModel()->setCurrentIndex(itemModel()->index(m_savedIndex, 0), QItemSelectionModel::ClearAndSelect);
|
2014-10-09 11:21:06 +02:00
|
|
|
m_savedIndex = -1;
|
|
|
|
|
}
|
2017-10-27 17:13:18 +02:00
|
|
|
}
|
2014-10-09 11:21:06 +02:00
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
void ComboBoxField::setup(JsonFieldPage *page, const QString &name)
|
|
|
|
|
{
|
|
|
|
|
auto w = qobject_cast<QComboBox*>(widget());
|
|
|
|
|
QTC_ASSERT(w, return);
|
|
|
|
|
w->setModel(itemModel());
|
|
|
|
|
w->setInsertPolicy(QComboBox::NoInsert);
|
|
|
|
|
|
|
|
|
|
QSizePolicy s = w->sizePolicy();
|
|
|
|
|
s.setHorizontalPolicy(QSizePolicy::Expanding);
|
|
|
|
|
w->setSizePolicy(s);
|
|
|
|
|
|
|
|
|
|
setSelectionModel(w->view()->selectionModel());
|
|
|
|
|
|
|
|
|
|
// the selectionModel does not behave like expected and wanted - so we block signals here
|
|
|
|
|
// (for example there was some losing focus thing when hovering over items, ...)
|
|
|
|
|
selectionModel()->blockSignals(true);
|
|
|
|
|
QObject::connect(w, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), [w, this](int index) {
|
|
|
|
|
w->blockSignals(true);
|
|
|
|
|
selectionModel()->clearSelection();
|
|
|
|
|
|
|
|
|
|
selectionModel()->blockSignals(false);
|
|
|
|
|
selectionModel()->setCurrentIndex(w->model()->index(index, 0),
|
|
|
|
|
QItemSelectionModel::ClearAndSelect);
|
|
|
|
|
selectionModel()->blockSignals(true);
|
|
|
|
|
w->blockSignals(false);
|
|
|
|
|
});
|
|
|
|
|
page->registerObjectAsFieldWithName<QItemSelectionModel>(name, selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
|
|
|
|
|
const QModelIndex i = selectionModel()->currentIndex();
|
|
|
|
|
if (i.isValid())
|
|
|
|
|
return i.data(ValueRole).toString();
|
|
|
|
|
return QString();
|
|
|
|
|
});
|
|
|
|
|
QObject::connect(selectionModel(), &QItemSelectionModel::selectionChanged, page, [page]() {
|
|
|
|
|
emit page->completeChanged();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *ComboBoxField::createWidget(const QString & /*displayName*/, JsonFieldPage * /*page*/)
|
|
|
|
|
{
|
|
|
|
|
return new QComboBox;
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:22:31 +02:00
|
|
|
void ComboBoxField::initializeData(MacroExpander *expander)
|
2014-10-09 11:21:06 +02:00
|
|
|
{
|
2017-10-27 17:13:18 +02:00
|
|
|
ListField::initializeData(expander);
|
|
|
|
|
// refresh also the current text of the combobox
|
|
|
|
|
auto w = qobject_cast<QComboBox*>(widget());
|
|
|
|
|
w->setCurrentIndex(selectionModel()->currentIndex().row());
|
|
|
|
|
}
|
2015-07-08 13:51:32 +02:00
|
|
|
|
2017-10-27 17:13:18 +02:00
|
|
|
void IconListField::setup(JsonFieldPage *page, const QString &name)
|
|
|
|
|
{
|
|
|
|
|
auto w = qobject_cast<QListView*>(widget());
|
|
|
|
|
QTC_ASSERT(w, return);
|
|
|
|
|
|
|
|
|
|
w->setViewMode(QListView::IconMode);
|
|
|
|
|
w->setMovement(QListView::Static);
|
|
|
|
|
w->setResizeMode(QListView::Adjust);
|
|
|
|
|
w->setSelectionRectVisible(false);
|
|
|
|
|
w->setWrapping(true);
|
|
|
|
|
w->setWordWrap(true);
|
|
|
|
|
|
|
|
|
|
w->setModel(itemModel());
|
|
|
|
|
setSelectionModel(w->selectionModel());
|
|
|
|
|
page->registerObjectAsFieldWithName<QItemSelectionModel>(name, selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
|
|
|
|
|
const QModelIndex i = selectionModel()->currentIndex();
|
|
|
|
|
if (i.isValid())
|
|
|
|
|
return i.data(ValueRole).toString();
|
|
|
|
|
return QString();
|
|
|
|
|
});
|
|
|
|
|
QObject::connect(selectionModel(), &QItemSelectionModel::selectionChanged, page, [page]() {
|
|
|
|
|
page->completeChanged();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *IconListField::createWidget(const QString & /*displayName*/, JsonFieldPage * /*page*/)
|
|
|
|
|
{
|
|
|
|
|
return new QListView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IconListField::initializeData(MacroExpander *expander)
|
|
|
|
|
{
|
|
|
|
|
ListField::initializeData(expander);
|
|
|
|
|
auto w = qobject_cast<QListView*>(widget());
|
|
|
|
|
const int spacing = 4;
|
|
|
|
|
w->setSpacing(spacing);
|
|
|
|
|
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
|
|
// adding a third hight of the icon to see following items if there are some
|
|
|
|
|
w->setMinimumHeight(maxIconSize().height() + maxIconSize().height() / 3);
|
|
|
|
|
w->setIconSize(maxIconSize());
|
2014-10-09 11:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// JsonFieldPage:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2015-09-21 16:28:48 +02:00
|
|
|
QHash<QString, JsonFieldPage::FieldFactory> JsonFieldPage::m_factories;
|
|
|
|
|
|
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);
|
|
|
|
|
|
2015-09-21 16:32:18 +02:00
|
|
|
auto vLayout = new QVBoxLayout;
|
2014-10-09 11:21:06 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 16:28:48 +02:00
|
|
|
void JsonFieldPage::registerFieldFactory(const QString &id, const JsonFieldPage::FieldFactory &ff)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!m_factories.contains(id), return);
|
|
|
|
|
m_factories.insert(id, ff);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2016-05-28 16:56:28 -07:00
|
|
|
if (f->isMandatory() && !f->widget()->isHidden())
|
2014-10-09 11:21:06 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 16:28:48 +02:00
|
|
|
JsonFieldPage::Field *JsonFieldPage::createFieldData(const QString &type)
|
|
|
|
|
{
|
2017-10-19 07:43:05 +02:00
|
|
|
if (auto factory = m_factories.value(type)) {
|
|
|
|
|
JsonFieldPage::Field *field = factory();
|
|
|
|
|
field->setType(type);
|
|
|
|
|
return field;
|
|
|
|
|
}
|
2017-09-26 11:18:54 +02:00
|
|
|
return nullptr;
|
2015-09-21 16:28:48 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-09 11:21:06 +02:00
|
|
|
} // namespace ProjectExplorer
|