QmlDesigner: Remove the options from adding model dialog

Task-number: QDS-11234
Change-Id: I064d2fed81a8f2592cfefae2c603b2d790b6bfb3
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Ali Kianian
2023-11-20 15:04:15 +02:00
parent 9a55e5c3de
commit 96ddb5da8b
3 changed files with 25 additions and 159 deletions

View File

@@ -19,10 +19,7 @@ StudioControls.Dialog {
required property var backendValue
required property var sourceModel
readonly property alias collectionType: typeMode.collectionType
readonly property bool isValid: collectionName.isValid
&& jsonCollections.isValid
&& newCollectionPath.isValid
title: qsTr("Add a new Model")
anchors.centerIn: parent
@@ -31,8 +28,6 @@ StudioControls.Dialog {
onOpened: {
collectionName.text = qsTr("Model")
updateType()
updateJsonSourceIndex()
updateCollectionExists()
}
@@ -41,52 +36,12 @@ StudioControls.Dialog {
}
onAccepted: {
if (root.isValid) {
root.backendValue.addCollection(collectionName.text,
root.collectionType,
newCollectionPath.text,
jsonCollections.currentValue)
}
}
function updateType() {
newCollectionPath.text = ""
if (typeMode.currentValue === NewCollectionDialog.SourceType.NewJson) {
newCollectionFileDialog.nameFilters = ["JSON Files (*.json)"]
newCollectionFileDialog.fileMode = PlatformWidgets.FileDialog.SaveFile
newCollectionPath.enabled = true
jsonCollections.enabled = false
typeMode.collectionType = "json"
} else if (typeMode.currentValue === NewCollectionDialog.SourceType.NewCsv) {
newCollectionFileDialog.nameFilters = ["Comma-Separated Values (*.csv)"]
newCollectionFileDialog.fileMode = PlatformWidgets.FileDialog.SaveFile
newCollectionPath.enabled = true
jsonCollections.enabled = false
typeMode.collectionType = "csv"
} else if (typeMode.currentValue === NewCollectionDialog.SourceType.ExistingCollection) {
newCollectionFileDialog.nameFilters = ["All Model Group Files (*.json *.csv)",
"JSON Files (*.json)",
"Comma-Separated Values (*.csv)"]
newCollectionFileDialog.fileMode = PlatformWidgets.FileDialog.OpenFile
newCollectionPath.enabled = true
jsonCollections.enabled = false
typeMode.collectionType = "existing"
}
}
function updateJsonSourceIndex() {
if (!jsonCollections.enabled) {
jsonCollections.currentIndex = -1
return
}
if (jsonCollections.currentIndex === -1 && jsonCollections.model.rowCount())
jsonCollections.currentIndex = 0
if (root.isValid)
root.backendValue.addCollectionToDataStore(collectionName.text);
}
function updateCollectionExists() {
collectionName.alreadyExists = sourceModel.collectionExists(jsonCollections.currentValue,
collectionName.alreadyExists = sourceModel.collectionExists(backendValue.dataStoreNode(),
collectionName.text)
}
@@ -114,117 +69,6 @@ StudioControls.Dialog {
contentItem: ColumnLayout {
spacing: 5
NameField {
text: qsTr("Type")
}
StudioControls.ComboBox {
id: typeMode
property string collectionType
Layout.minimumWidth: 300
Layout.fillWidth: true
model: ListModel {
ListElement { text: qsTr("New JSON model group"); value: NewCollectionDialog.SourceType.NewJson}
ListElement { text: qsTr("New CSV model"); value: NewCollectionDialog.SourceType.NewCsv}
ListElement { text: qsTr("Import an existing model group"); value: NewCollectionDialog.SourceType.ExistingCollection}
}
textRole: "text"
valueRole: "value"
actionIndicatorVisible: false
onCurrentValueChanged: root.updateType()
}
Spacer {}
RowLayout {
visible: newCollectionPath.enabled
NameField {
text: qsTr("File location")
visible: newCollectionPath.enabled
}
Text {
id: newCollectionPath
readonly property bool isValid: !newCollectionPath.enabled || newCollectionPath.text !== ""
Layout.fillWidth: true
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
elide: Text.ElideRight
font.family: StudioTheme.Constants.font.family
font.pixelSize: StudioTheme.Values.baseIconFontSize
color: StudioTheme.Values.themePlaceholderTextColor
}
HelperWidgets.Button {
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
text: qsTr("Select")
onClicked: newCollectionFileDialog.open()
PlatformWidgets.FileDialog {
id: newCollectionFileDialog
title: qsTr("Select source file")
fileMode: PlatformWidgets.FileDialog.OpenFile
acceptLabel: newCollectionFileDialog.fileMode === PlatformWidgets.FileDialog.OpenFile
? qsTr("Open")
: qsTr("Add")
onAccepted: newCollectionPath.text = newCollectionFileDialog.currentFile
}
}
}
ErrorField {
visible: !newCollectionPath.isValid
text: qsTr("Select a file to continue")
}
Spacer { visible: newCollectionPath.enabled }
NameField {
text: qsTr("JSON model group")
visible: jsonCollections.enabled
}
StudioControls.ComboBox {
id: jsonCollections
readonly property bool isValid: !jsonCollections.enabled || jsonCollections.currentIndex !== -1
Layout.fillWidth: true
implicitWidth: 300
textRole: "sourceName"
valueRole: "sourceNode"
visible: jsonCollections.enabled
actionIndicatorVisible: false
model: CollectionJsonSourceFilterModel {
sourceModel: root.sourceModel
onRowsInserted: root.updateJsonSourceIndex()
onModelReset: root.updateJsonSourceIndex()
onRowsRemoved: root.updateJsonSourceIndex()
}
onEnabledChanged: root.updateJsonSourceIndex()
onCurrentValueChanged: root.updateCollectionExists()
}
ErrorField {
visible: !jsonCollections.isValid
text: qsTr("Add a JSON resource to continue")
}
Spacer {visible: jsonCollections.visible }
NameField {
text: qsTr("The model name")
visible: collectionName.enabled

View File

@@ -314,6 +314,26 @@ bool CollectionWidget::importCollectionToDataStore(const QString &collectionName
return false;
}
bool CollectionWidget::addCollectionToDataStore(const QString &collectionName)
{
const ModelNode node = dataStoreNode();
if (!node.isValid()) {
warn(tr("Can not import to the main model"), tr("The default model node is not available."));
return false;
}
QString errorMsg;
bool added = m_sourceModel->addCollectionToSource(node,
generateUniqueCollectionName(node,
collectionName),
CollectionEditor::defaultCollectionArray(),
&errorMsg);
if (!added)
warn(tr("Failed to add a model to the default model group"), errorMsg);
return added;
}
void CollectionWidget::assignSourceNodeToSelectedItem(const QVariant &sourceNode)
{
ModelNode sourceModel = sourceNode.value<ModelNode>();

View File

@@ -50,6 +50,8 @@ public:
Q_INVOKABLE bool importCollectionToDataStore(const QString &collectionName, const QUrl &url);
Q_INVOKABLE bool addCollectionToDataStore(const QString &collectionName);
Q_INVOKABLE void assignSourceNodeToSelectedItem(const QVariant &sourceNode);
Q_INVOKABLE ModelNode dataStoreNode() const;