summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/Inspector
diff options
context:
space:
mode:
Diffstat (limited to 'src/Authoring/Studio/Palettes/Inspector')
-rw-r--r--src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml4
-rw-r--r--src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.cpp52
-rw-r--r--src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.h2
3 files changed, 53 insertions, 5 deletions
diff --git a/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml b/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml
index 623af241..4ccff8ee 100644
--- a/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml
+++ b/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml
@@ -1124,7 +1124,7 @@ Rectangle {
height: 20
onClicked: {
- // TODO: implement
+ _variantsGroupModel.importVariants()
}
}
@@ -1136,7 +1136,7 @@ Rectangle {
enabled: !_variantsGroupModel.variantsEmpty
onClicked: {
- // TODO: implement
+ _variantsGroupModel.exportVariants()
}
}
}
diff --git a/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.cpp b/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.cpp
index ac0cc2b5..87219554 100644
--- a/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.cpp
+++ b/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.cpp
@@ -35,6 +35,9 @@
#include "ClientDataModelBridge.h"
#include "IDocumentEditor.h"
#include "VariantTagDialog.h"
+#include "StudioUtils.h"
+#include "Dialogs.h"
+#include <QtCore/qsavefile.h>
VariantsGroupModel::VariantsGroupModel(QObject *parent)
: QAbstractListModel(parent)
@@ -65,9 +68,9 @@ void VariantsGroupModel::refresh()
QString val = QString::fromWCharArray(
qt3dsdm::get<qt3dsdm::TDataStrPtr>(sValue)->GetData());
// TODO: remove qDebug when the variants work is fully done.
- qDebug() << "\x1b[42m \x1b[1m" << __FUNCTION__
- << ", val=" << val
- << "\x1b[m";
+// qDebug() << "\x1b[42m \x1b[1m" << __FUNCTION__
+// << ", val=" << val
+// << "\x1b[m";
QHash<QString, QStringList> propTags;
if (!val.isEmpty()) {
const QStringList propTagsList = val.split(QChar(','));
@@ -161,6 +164,49 @@ void VariantsGroupModel::addNewTag(const QString &group)
g_StudioApp.GetCore()->getProjectFile().addVariantTag(group, dlg.getNames().second);
}
+void VariantsGroupModel::importVariants()
+{
+ QString importFilePath = g_StudioApp.GetDialogs()->getImportVariantsDlg();
+
+ if (!importFilePath.isEmpty()) {
+ g_StudioApp.GetCore()->getProjectFile().loadVariants(importFilePath);
+ refresh();
+ }
+}
+
+void VariantsGroupModel::exportVariants()
+{
+ QString exportFilePath = g_StudioApp.GetDialogs()->getExportVariantsDlg();
+
+ if (exportFilePath.isEmpty())
+ return;
+
+ QDomDocument domDoc;
+ domDoc.appendChild(domDoc.createProcessingInstruction(QStringLiteral("xml"),
+ QStringLiteral("version=\"1.0\""
+ " encoding=\"utf-8\"")));
+
+ const auto variantsDef = g_StudioApp.GetCore()->getProjectFile().variantsDef();
+ QDomElement vElem = domDoc.createElement(QStringLiteral("variants"));
+ domDoc.appendChild(vElem);
+ for (auto &g : variantsDef) {
+ QDomElement gElem = domDoc.createElement(QStringLiteral("variantgroup"));
+ gElem.setAttribute(QStringLiteral("id"), g.m_title);
+ gElem.setAttribute(QStringLiteral("color"), g.m_color);
+ vElem.appendChild(gElem);
+
+ for (auto &t : qAsConst(g.m_tags)) {
+ QDomElement tElem = domDoc.createElement(QStringLiteral("variant"));;
+ tElem.setAttribute(QStringLiteral("id"), t);
+ gElem.appendChild(tElem);
+ }
+ }
+
+ QSaveFile file(exportFilePath);
+ if (StudioUtils::openTextSave(file))
+ StudioUtils::commitDomDocumentSave(file, domDoc);
+}
+
void VariantsGroupModel::addNewGroup()
{
VariantTagDialog dlg(VariantTagDialog::AddGroup);
diff --git a/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.h b/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.h
index fdebebfc..75a218f7 100644
--- a/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.h
+++ b/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.h
@@ -68,6 +68,8 @@ public:
Q_INVOKABLE void setTagState(const QString &group, const QString &tag, bool selected);
Q_INVOKABLE void addNewTag(const QString &group);
Q_INVOKABLE void addNewGroup();
+ Q_INVOKABLE void importVariants();
+ Q_INVOKABLE void exportVariants();
protected: