forked from qt-creator/qt-creator
QmlDesigner: Move the action for adding a collection to json
The action should be moved to the tool menu of the Json Collection Task-number: QDS-11256 Change-Id: Ieb2c9cc4f4b992f1ac3225bbbd90e3d14afdc711 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -131,6 +131,12 @@ Item {
|
|||||||
onDeleteItem: root.model.removeRow(index)
|
onDeleteItem: root.model.removeRow(index)
|
||||||
hasSelectedTarget: root.rootView.targetNodeSelected
|
hasSelectedTarget: root.rootView.targetNodeSelected
|
||||||
onAssignToSelected: root.rootView.assignSourceNodeToSelectedItem(sourceNode)
|
onAssignToSelected: root.rootView.assignSourceNodeToSelectedItem(sourceNode)
|
||||||
|
onAddCollection: (collectionName) => {
|
||||||
|
root.rootView.addCollection(collectionName,
|
||||||
|
sourceCollectionType,
|
||||||
|
"",
|
||||||
|
sourceNode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,10 +20,12 @@ Item {
|
|||||||
property var collectionModel
|
property var collectionModel
|
||||||
|
|
||||||
property bool expanded: false
|
property bool expanded: false
|
||||||
|
readonly property bool isJsonModel: sourceCollectionType === "json"
|
||||||
|
|
||||||
signal selectItem(int itemIndex)
|
signal selectItem(int itemIndex)
|
||||||
signal deleteItem()
|
signal deleteItem()
|
||||||
signal assignToSelected()
|
signal assignToSelected()
|
||||||
|
signal addCollection(string collectionName)
|
||||||
|
|
||||||
function toggleExpanded() {
|
function toggleExpanded() {
|
||||||
if (collectionListView.count > 0)
|
if (collectionListView.count > 0)
|
||||||
@@ -169,6 +171,12 @@ Item {
|
|||||||
|
|
||||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||||
|
|
||||||
|
StudioControls.MenuItem {
|
||||||
|
text: qsTr("Add a model")
|
||||||
|
visible: root.isJsonModel && internalModels !== undefined
|
||||||
|
onTriggered: newCollectionDialog.open()
|
||||||
|
}
|
||||||
|
|
||||||
StudioControls.MenuItem {
|
StudioControls.MenuItem {
|
||||||
text: qsTr("Delete")
|
text: qsTr("Delete")
|
||||||
shortcut: StandardKey.Delete
|
shortcut: StandardKey.Delete
|
||||||
@@ -193,6 +201,21 @@ Item {
|
|||||||
implicitHeight: StudioTheme.Values.sectionColumnSpacing
|
implicitHeight: StudioTheme.Values.sectionColumnSpacing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
component NameField: Text {
|
||||||
|
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
|
||||||
|
horizontalAlignment: Qt.AlignRight
|
||||||
|
verticalAlignment: Qt.AlignCenter
|
||||||
|
color: StudioTheme.Values.themeTextColor
|
||||||
|
font.family: StudioTheme.Constants.font.family
|
||||||
|
font.pixelSize: StudioTheme.Values.baseIconFontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
component ErrorField: Text {
|
||||||
|
color: StudioTheme.Values.themeError
|
||||||
|
font.family: StudioTheme.Constants.font.family
|
||||||
|
font.pixelSize: StudioTheme.Values.baseIconFontSize
|
||||||
|
}
|
||||||
|
|
||||||
StudioControls.Dialog {
|
StudioControls.Dialog {
|
||||||
id: deleteDialog
|
id: deleteDialog
|
||||||
|
|
||||||
@@ -292,6 +315,71 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StudioControls.Dialog {
|
||||||
|
id: newCollectionDialog
|
||||||
|
|
||||||
|
title: qsTr("Add a new model")
|
||||||
|
|
||||||
|
onOpened: newCollectionName.text = qsTr("Model")
|
||||||
|
|
||||||
|
onAccepted: root.addCollection(newCollectionName.text)
|
||||||
|
|
||||||
|
contentItem: ColumnLayout {
|
||||||
|
spacing: 2
|
||||||
|
|
||||||
|
NameField {
|
||||||
|
text: qsTr("The model name")
|
||||||
|
}
|
||||||
|
|
||||||
|
StudioControls.TextField {
|
||||||
|
id: newCollectionName
|
||||||
|
|
||||||
|
readonly property bool isValid: newCollectionName.text !== "" && !newCollectionName.alreadyExists
|
||||||
|
property bool alreadyExists
|
||||||
|
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
actionIndicator.visible: false
|
||||||
|
translationIndicator.visible: false
|
||||||
|
validator: RegularExpressionValidator {
|
||||||
|
regularExpression: /^\w+$/
|
||||||
|
}
|
||||||
|
|
||||||
|
Keys.onEnterPressed: createCollectionButton.onClicked()
|
||||||
|
Keys.onReturnPressed: createCollectionButton.onClicked()
|
||||||
|
Keys.onEscapePressed: newCollectionDialog.reject()
|
||||||
|
|
||||||
|
onTextChanged: newCollectionName.alreadyExists = internalModels.contains(newCollectionName.text)
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorField {
|
||||||
|
text: qsTr("The model name already exists %1").arg(newCollectionName.text)
|
||||||
|
visible: newCollectionName.alreadyExists
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer{}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
||||||
|
spacing: StudioTheme.Values.sectionRowSpacing
|
||||||
|
|
||||||
|
HelperWidgets.Button {
|
||||||
|
id: createCollectionButton
|
||||||
|
|
||||||
|
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
||||||
|
text: qsTr("Add")
|
||||||
|
enabled: newCollectionName.isValid
|
||||||
|
onClicked: newCollectionDialog.accept()
|
||||||
|
}
|
||||||
|
|
||||||
|
HelperWidgets.Button {
|
||||||
|
text: qsTr("Cancel")
|
||||||
|
onClicked: newCollectionDialog.reject()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RegularExpressionValidator {
|
RegularExpressionValidator {
|
||||||
id: newNameValidator
|
id: newNameValidator
|
||||||
regularExpression: /^\w+$/
|
regularExpression: /^\w+$/
|
||||||
|
@@ -14,7 +14,7 @@ import CollectionEditor 1.0
|
|||||||
StudioControls.Dialog {
|
StudioControls.Dialog {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
enum SourceType { NewJson, NewCsv, ExistingCollection, NewCollectionToJson }
|
enum SourceType { NewJson, NewCsv, ExistingCollection }
|
||||||
|
|
||||||
required property var backendValue
|
required property var backendValue
|
||||||
required property var sourceModel
|
required property var sourceModel
|
||||||
@@ -72,11 +72,6 @@ StudioControls.Dialog {
|
|||||||
newCollectionPath.enabled = true
|
newCollectionPath.enabled = true
|
||||||
jsonCollections.enabled = false
|
jsonCollections.enabled = false
|
||||||
typeMode.collectionType = "existing"
|
typeMode.collectionType = "existing"
|
||||||
} else if (typeMode.currentValue === NewCollectionDialog.SourceType.NewCollectionToJson) {
|
|
||||||
newCollectionFileDialog.nameFilters = [""]
|
|
||||||
newCollectionPath.enabled = false
|
|
||||||
jsonCollections.enabled = true
|
|
||||||
typeMode.collectionType = "json"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +130,6 @@ StudioControls.Dialog {
|
|||||||
ListElement { text: qsTr("New JSON model group"); value: NewCollectionDialog.SourceType.NewJson}
|
ListElement { text: qsTr("New JSON model group"); value: NewCollectionDialog.SourceType.NewJson}
|
||||||
ListElement { text: qsTr("New CSV model"); value: NewCollectionDialog.SourceType.NewCsv}
|
ListElement { text: qsTr("New CSV model"); value: NewCollectionDialog.SourceType.NewCsv}
|
||||||
ListElement { text: qsTr("Import an existing model group"); value: NewCollectionDialog.SourceType.ExistingCollection}
|
ListElement { text: qsTr("Import an existing model group"); value: NewCollectionDialog.SourceType.ExistingCollection}
|
||||||
ListElement { text: qsTr("Add a model to an available JSON model group"); value: NewCollectionDialog.SourceType.NewCollectionToJson}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
textRole: "text"
|
textRole: "text"
|
||||||
|
@@ -15,6 +15,8 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -125,4 +127,14 @@ QString getSourceCollectionPath(const ModelNode &node)
|
|||||||
.toFSPathString();
|
.toFSPathString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonArray defaultCollectionArray()
|
||||||
|
{
|
||||||
|
QJsonObject initialObject;
|
||||||
|
QJsonArray initialCollection;
|
||||||
|
|
||||||
|
initialObject.insert("Column1", "");
|
||||||
|
initialCollection.append(initialObject);
|
||||||
|
return initialCollection;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QmlDesigner::CollectionEditor
|
} // namespace QmlDesigner::CollectionEditor
|
||||||
|
@@ -5,6 +5,10 @@
|
|||||||
|
|
||||||
#include "collectiondetails.h"
|
#include "collectiondetails.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QJsonArray;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace QmlDesigner::CollectionEditor {
|
namespace QmlDesigner::CollectionEditor {
|
||||||
|
|
||||||
bool variantIslessThan(const QVariant &a, const QVariant &b, CollectionDetails::DataType type);
|
bool variantIslessThan(const QVariant &a, const QVariant &b, CollectionDetails::DataType type);
|
||||||
@@ -19,4 +23,6 @@ void assignCollectionSourceToNode(AbstractView *view,
|
|||||||
|
|
||||||
bool canAcceptCollectionAsModel(const ModelNode &node);
|
bool canAcceptCollectionAsModel(const ModelNode &node);
|
||||||
|
|
||||||
|
QJsonArray defaultCollectionArray();
|
||||||
|
|
||||||
} // namespace QmlDesigner::CollectionEditor
|
} // namespace QmlDesigner::CollectionEditor
|
||||||
|
@@ -305,7 +305,7 @@ bool CollectionSourceModel::addCollectionToSource(const ModelNode &node,
|
|||||||
|
|
||||||
if (document.isObject()) {
|
if (document.isObject()) {
|
||||||
QJsonObject sourceObject = document.object();
|
QJsonObject sourceObject = document.object();
|
||||||
sourceObject.insert(collectionName, QJsonArray{});
|
sourceObject.insert(collectionName, CollectionEditor::defaultCollectionArray());
|
||||||
document.setObject(sourceObject);
|
document.setObject(sourceObject);
|
||||||
if (!jsonFile.resize(0))
|
if (!jsonFile.resize(0))
|
||||||
return returnError(tr("Can't clean \"%1\".").arg(sourceFileInfo.absoluteFilePath()));
|
return returnError(tr("Can't clean \"%1\".").arg(sourceFileInfo.absoluteFilePath()));
|
||||||
|
@@ -201,12 +201,7 @@ bool CollectionWidget::addCollection(const QString &collectionName,
|
|||||||
|
|
||||||
if (collectionType == "json") {
|
if (collectionType == "json") {
|
||||||
QJsonObject jsonObject;
|
QJsonObject jsonObject;
|
||||||
QJsonObject initialObject;
|
jsonObject.insert(collectionName, CollectionEditor::defaultCollectionArray());
|
||||||
QJsonArray initialCollection;
|
|
||||||
|
|
||||||
initialObject.insert("Column1", "");
|
|
||||||
initialCollection.append(initialObject);
|
|
||||||
jsonObject.insert(collectionName, initialCollection);
|
|
||||||
|
|
||||||
QFile sourceFile(sourcePath);
|
QFile sourceFile(sourcePath);
|
||||||
if (!sourceFile.open(QFile::WriteOnly)) {
|
if (!sourceFile.open(QFile::WriteOnly)) {
|
||||||
|
Reference in New Issue
Block a user