forked from qt-creator/qt-creator
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:
@@ -115,29 +115,7 @@ Item {
|
||||
icon: StudioTheme.Constants.export_medium
|
||||
tooltip: qsTr("Export the model to a new file")
|
||||
enabled: root.model.collectionName !== ""
|
||||
onClicked: exportMenu.popup()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
onClicked: fileDialog.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,17 +123,19 @@ Item {
|
||||
|
||||
PlatformWidgets.FileDialog {
|
||||
id: fileDialog
|
||||
|
||||
fileMode: PlatformWidgets.FileDialog.SaveFile
|
||||
onAccepted:
|
||||
{
|
||||
var fileAddress = file.toString()
|
||||
|
||||
if (fileAddress.indexOf("json") !== -1)
|
||||
root.model.exportCollection(fileAddress, root.model.collectionName, "JSON")
|
||||
else if (fileAddress.indexOf("csv") !== -1)
|
||||
root.model.exportCollection(fileAddress, root.model.collectionName, "CSV")
|
||||
nameFilters: ["JSON Files (*.json)",
|
||||
"Comma-Separated Values (*.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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#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)
|
||||
{
|
||||
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") {
|
||||
QJsonArray content = m_currentCollection.getJsonCollection();
|
||||
return saveCollectionAsJson(fileAddress, content, collectionName);
|
||||
return saveCollectionAsJson(filePath, content, collectionName);
|
||||
} else if (exportType == "CSV") {
|
||||
QString content = m_currentCollection.getCsvCollection();
|
||||
return saveCollectionAsCsv(fileAddress, content);
|
||||
return saveCollectionAsCsv(filePath, content);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user