QmlDesigner: Remove the export popup

Task-number: QDS-11242
Change-Id: I3ef24a41e58162eeb34fcf0f220d5854410fbb73
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Ali Kianian
2023-11-15 10:24:01 +02:00
parent 38205996af
commit 414649e385
2 changed files with 23 additions and 34 deletions

View File

@@ -115,29 +115,7 @@ Item {
icon: StudioTheme.Constants.export_medium icon: StudioTheme.Constants.export_medium
tooltip: qsTr("Export the model to a new file") tooltip: qsTr("Export the model to a new file")
enabled: root.model.collectionName !== "" enabled: root.model.collectionName !== ""
onClicked: exportMenu.popup() onClicked: fileDialog.open()
}
StudioControls.Menu {
id: exportMenu
StudioControls.MenuItem {
text: qsTr("Export as JSON")
onTriggered:
{
fileDialog.defaultSuffix = "json"
fileDialog.open()
}
}
StudioControls.MenuItem {
text: qsTr("Export as CSV")
onTriggered:
{
fileDialog.defaultSuffix = "csv"
fileDialog.open()
}
}
} }
} }
} }
@@ -145,17 +123,19 @@ Item {
PlatformWidgets.FileDialog { PlatformWidgets.FileDialog {
id: fileDialog id: fileDialog
fileMode: PlatformWidgets.FileDialog.SaveFile fileMode: PlatformWidgets.FileDialog.SaveFile
onAccepted:
{
var fileAddress = file.toString()
if (fileAddress.indexOf("json") !== -1) nameFilters: ["JSON Files (*.json)",
root.model.exportCollection(fileAddress, root.model.collectionName, "JSON") "Comma-Separated Values (*.csv)"
else if (fileAddress.indexOf("csv") !== -1) ]
root.model.exportCollection(fileAddress, root.model.collectionName, "CSV")
fileDialog.reject() selectedNameFilter.index: 0
onAccepted: {
let filePath = fileDialog.file.toString()
let exportType = fileDialog.selectedNameFilter.index === 0 ? "JSON" : "CSV"
root.model.exportCollection(filePath, root.model.collectionName, exportType)
} }
} }

View File

@@ -10,6 +10,7 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QFile> #include <QFile>
#include <QFileInfo>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonParseError> #include <QJsonParseError>
@@ -409,14 +410,22 @@ void CollectionDetailsModel::loadCollection(const ModelNode &sourceNode, const Q
bool CollectionDetailsModel::exportCollection(const QString &path, const QString &collectionName, const QString &exportType) bool CollectionDetailsModel::exportCollection(const QString &path, const QString &collectionName, const QString &exportType)
{ {
QUrl url(path); QUrl url(path);
QString fileAddress = url.isLocalFile() ? url.toLocalFile() : path; QString filePath;
if (url.isLocalFile()) {
QFileInfo fileInfo(url.toLocalFile());
if (fileInfo.suffix().toLower() != exportType.toLower())
fileInfo.setFile(QString("%1.%2").arg(url.toLocalFile(), exportType.toLower()));
filePath = fileInfo.absoluteFilePath();
} else {
filePath = path;
}
if (exportType == "JSON") { if (exportType == "JSON") {
QJsonArray content = m_currentCollection.getJsonCollection(); QJsonArray content = m_currentCollection.getJsonCollection();
return saveCollectionAsJson(fileAddress, content, collectionName); return saveCollectionAsJson(filePath, content, collectionName);
} else if (exportType == "CSV") { } else if (exportType == "CSV") {
QString content = m_currentCollection.getCsvCollection(); QString content = m_currentCollection.getCsvCollection();
return saveCollectionAsCsv(fileAddress, content); return saveCollectionAsCsv(filePath, content);
} }
return false; return false;