summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2019-02-13 10:14:56 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2019-02-18 16:08:04 +0000
commit33764aa97c0f176d54c2e02817e533c0c0be6903 (patch)
tree7719f348869319a5501573a48de2ca96d6ee094f
parentae1f591fc67b05768fb4f4a587c05d25707ac630 (diff)
Fix variants tags property update issue
- update the in-memory variants property after renaming or deleting a tag or group to prevent the old value from being saved to the uip if the user saves. - refresh the 'variants empty text' and 'export button enabled' states when the groups empty state change - refresh the variants when creating a new presentation Task-number: QT3DS-2983 Change-Id: I2910dd6f5b69607e29ffa0c60d90ab33a2a0fc8b Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--src/Authoring/Client/Code/Core/Core/Core.cpp1
-rw-r--r--src/Authoring/Studio/Application/ProjectFile.cpp70
-rw-r--r--src/Authoring/Studio/Palettes/Inspector/InspectorControlView.cpp2
-rw-r--r--src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml5
-rw-r--r--src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.cpp6
-rw-r--r--src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.h6
6 files changed, 75 insertions, 15 deletions
diff --git a/src/Authoring/Client/Code/Core/Core/Core.cpp b/src/Authoring/Client/Code/Core/Core/Core.cpp
index 10374d4d..6d375843 100644
--- a/src/Authoring/Client/Code/Core/Core/Core.cpp
+++ b/src/Authoring/Client/Code/Core/Core/Core.cpp
@@ -272,6 +272,7 @@ bool CCore::OnNewDocument(const QString &inDocument, bool isNewProject, bool sil
// write a new presentation node to the uia file
m_projectFile.addPresentationNode(theDocument);
m_projectFile.updateDocPresentationId();
+ m_projectFile.loadVariants();
m_projectFile.loadSubpresentationsAndDatainputs(g_StudioApp.m_subpresentations,
g_StudioApp.m_dataInputDialogItems);
g_StudioApp.getRenderer().RegisterSubpresentations(g_StudioApp.m_subpresentations);
diff --git a/src/Authoring/Studio/Application/ProjectFile.cpp b/src/Authoring/Studio/Application/ProjectFile.cpp
index af80556d..dd8c8fa5 100644
--- a/src/Authoring/Studio/Application/ProjectFile.cpp
+++ b/src/Authoring/Studio/Application/ProjectFile.cpp
@@ -1075,6 +1075,27 @@ void ProjectFile::renameVariantTag(const QString &group, const QString &oldTag,
}
}
+ // update the property
+ CDoc *doc = g_StudioApp.GetCore()->GetDoc();
+ auto propertySystem = doc->GetStudioSystem()->GetPropertySystem();
+ int instance = doc->GetSelectedInstance();
+ auto bridge = doc->GetStudioSystem()->GetClientDataModelBridge();
+
+ if (instance != 0 && bridge->IsLayerInstance(instance)) {
+ int property = propertySystem->GetAggregateInstancePropertyByName(instance, L"variants");
+ qt3dsdm::SValue sValue;
+ if (propertySystem->GetInstancePropertyValue(instance, property, sValue)) {
+ QString val = QString::fromWCharArray(
+ qt3dsdm::get<qt3dsdm::TDataStrPtr>(sValue)->GetData());
+ if (val.contains(group + QLatin1Char(':') + oldTag)) {
+ val.replace(group + QLatin1Char(':') + oldTag, group + QLatin1Char(':') + newTag);
+ qt3dsdm::SValue sVal
+ = std::make_shared<qt3dsdm::CDataStr>(Q3DStudio::CString::fromQString(val));
+ propertySystem->SetInstancePropertyValue(instance, property, sVal);
+ }
+ }
+ }
+
// update m_variantsDef
renamed = false;
for (auto &g : m_variantsDef) {
@@ -1124,6 +1145,27 @@ void ProjectFile::renameVariantGroup(const QString &oldGroup, const QString &new
}
}
+ // update the property
+ CDoc *doc = g_StudioApp.GetCore()->GetDoc();
+ auto propertySystem = doc->GetStudioSystem()->GetPropertySystem();
+ int instance = doc->GetSelectedInstance();
+ auto bridge = doc->GetStudioSystem()->GetClientDataModelBridge();
+
+ if (instance != 0 && bridge->IsLayerInstance(instance)) {
+ int property = propertySystem->GetAggregateInstancePropertyByName(instance, L"variants");
+ qt3dsdm::SValue sValue;
+ if (propertySystem->GetInstancePropertyValue(instance, property, sValue)) {
+ QString val = QString::fromWCharArray(
+ qt3dsdm::get<qt3dsdm::TDataStrPtr>(sValue)->GetData());
+ if (val.contains(oldGroup + QLatin1Char(':'))) {
+ val.replace(oldGroup + QLatin1Char(':'), newGroup + QLatin1Char(':'));
+ qt3dsdm::SValue sVal
+ = std::make_shared<qt3dsdm::CDataStr>(Q3DStudio::CString::fromQString(val));
+ propertySystem->SetInstancePropertyValue(instance, property, sVal);
+ }
+ }
+ }
+
// update m_variantsDef
for (auto &g : m_variantsDef) {
if (g.m_title == oldGroup) {
@@ -1156,21 +1198,20 @@ void ProjectFile::deleteVariantGroup(const QString &group)
}
}
- // check that the group is in use in the current doc (could be set in the property but not saved
+ // check that the group is in use in the current doc (could be set in the property but not saved)
+ auto propertySystem = doc->GetStudioSystem()->GetPropertySystem();
+ auto bridge = doc->GetStudioSystem()->GetClientDataModelBridge();
+ int instance = doc->GetSelectedInstance();
+ int property = propertySystem->GetAggregateInstancePropertyByName(instance, L"variants");
+ QString propVal;
if (inUseIdx == -1) {
- auto propertySystem = doc->GetStudioSystem()->GetPropertySystem();
- int instance = doc->GetSelectedInstance();
- auto bridge = doc->GetStudioSystem()->GetClientDataModelBridge();
-
if (instance != 0 && bridge->IsLayerInstance(instance)) {
- int property = propertySystem->GetAggregateInstancePropertyByName(instance,
- L"variants");
qt3dsdm::SValue sValue;
if (propertySystem->GetInstancePropertyValue(instance, property, sValue)) {
- QString val = QString::fromWCharArray(
- qt3dsdm::get<qt3dsdm::TDataStrPtr>(sValue)->GetData());
- if (val.contains(group + QLatin1Char(':'))) {
- // this big value will trigger the in-use warning, but will skip updaing the
+ propVal = QString::fromWCharArray(qt3dsdm::get<qt3dsdm::TDataStrPtr>(sValue)
+ ->GetData());
+ if (propVal.contains(group + QLatin1Char(':'))) {
+ // this big value will trigger the in-use warning, but will skip updating the
// uips which is not needed.
inUseIdx = 9999;
}
@@ -1198,8 +1239,11 @@ void ProjectFile::deleteVariantGroup(const QString &group)
if (inUseIdx == 9999) {
// property has the deleted group, need to update it, else the deleted group
// will be saved the uip if the user saves the presentation.
-
- // TODO: implement
+ QRegExp rgx(group + ":\\w*,|," + group + ":\\w*");
+ propVal.replace(rgx, {});
+ qt3dsdm::SValue sVal = std::make_shared<qt3dsdm::CDataStr>(
+ Q3DStudio::CString::fromQString(propVal));
+ propertySystem->SetInstancePropertyValue(instance, property, sVal);
}
break;
diff --git a/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.cpp b/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.cpp
index 6252c0ea..10222fcd 100644
--- a/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.cpp
+++ b/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.cpp
@@ -458,6 +458,7 @@ void InspectorControlView::showContextMenu(int x, int y, int handle, int instanc
m_handle = 0;
}
+// context menu for the variants tags
void InspectorControlView::showTagContextMenu(int x, int y, const QString &group,
const QString &tag)
{
@@ -480,6 +481,7 @@ void InspectorControlView::showTagContextMenu(int x, int y, const QString &group
theContextMenu.exec(mapToGlobal({x, y}));
}
+// context menu for the variants groups
void InspectorControlView::showGroupContextMenu(int x, int y, const QString &group)
{
QMenu theContextMenu;
diff --git a/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml b/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml
index 833bbd65..623af241 100644
--- a/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml
+++ b/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml
@@ -1133,6 +1133,7 @@ Rectangle {
text: qsTr("Export...")
width: 70
height: 20
+ enabled: !_variantsGroupModel.variantsEmpty
onClicked: {
// TODO: implement
@@ -1141,9 +1142,9 @@ Rectangle {
}
Text {
- text: qsTr("There are no variant tags yet. Click [+ Group] to add a new tag group and start adding tags.")
+ text: qsTr("There are no variant tags yet. Click [+ Group] to add a new tags group and start adding tags.")
color: "#ffffff"
- visible: _variantsGroupModel.rowCount() === 0
+ visible: _variantsGroupModel.variantsEmpty
}
Repeater {
diff --git a/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.cpp b/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.cpp
index 3a2a2a45..ac0cc2b5 100644
--- a/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.cpp
+++ b/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.cpp
@@ -96,6 +96,12 @@ void VariantsGroupModel::refresh()
}
endResetModel();
+
+ bool isVariantsEmpty = rowCount() == 0;
+ if (m_variantsEmpty != isVariantsEmpty) {
+ m_variantsEmpty = isVariantsEmpty;
+ Q_EMIT varaintsEmptyChanged();
+ }
}
}
diff --git a/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.h b/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.h
index 695e3fb0..fdebebfc 100644
--- a/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.h
+++ b/src/Authoring/Studio/Palettes/Inspector/VariantsGroupModel.h
@@ -36,6 +36,11 @@ class VariantsTagModel;
class VariantsGroupModel : public QAbstractListModel
{
Q_OBJECT
+ Q_PROPERTY(bool variantsEmpty MEMBER m_variantsEmpty NOTIFY varaintsEmptyChanged)
+
+public:
+Q_SIGNALS:
+ void varaintsEmptyChanged();
public:
explicit VariantsGroupModel(QObject *parent = nullptr);
@@ -72,6 +77,7 @@ private:
QVector<TagGroupData> m_data;
int m_instance = 0; // selected layer instance
int m_property = 0; // variant tags property handler
+ bool m_variantsEmpty = true; // no groups (nor tags)
};
#endif // VARIANTSGROUPMODEL_H