diff options
author | Janne Kangas <janne.kangas@qt.io> | 2018-08-22 10:31:47 +0300 |
---|---|---|
committer | Janne Kangas <janne.kangas@qt.io> | 2018-08-31 09:48:12 +0000 |
commit | b369f0e12959129e8b92569879d40004113ea90b (patch) | |
tree | 9c22a9c12e6057519fc70465d797cba25530ef03 /src/Authoring | |
parent | db7502ca4e8d5a6d153b557cc81f3c24192e3ec8 (diff) |
Check allowable datainput types when changing existing datainput type
Property datatypes are now stored when datainput is bound as a controller
to a property, and allowable datatypes are checked when entering the
datainput edit dialog. User is given a clarification on why certain
datatypes are grayed out.
Change-Id: I1cfec1d3c1b2d656e51596e557b400789399b121
Task-Id: QT3DS-1916
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/Authoring')
-rw-r--r-- | src/Authoring/Client/Code/Core/Doc/Doc.cpp | 30 | ||||
-rw-r--r-- | src/Authoring/Client/Code/Core/Doc/Doc.h | 7 | ||||
-rw-r--r-- | src/Authoring/Studio/Application/DataInputDlg.cpp | 69 | ||||
-rw-r--r-- | src/Authoring/Studio/Application/DataInputDlg.h | 23 | ||||
-rw-r--r-- | src/Authoring/Studio/Application/DataInputDlg.ui | 50 | ||||
-rw-r--r-- | src/Authoring/Studio/Application/DataInputListDlg.cpp | 35 | ||||
-rw-r--r-- | src/Authoring/Studio/Application/DataInputListDlg.h | 4 | ||||
-rw-r--r-- | src/Authoring/Studio/Application/DataInputSelectView.cpp | 2 | ||||
-rw-r--r-- | src/Authoring/Studio/style.qss | 3 |
9 files changed, 178 insertions, 45 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/Doc.cpp b/src/Authoring/Client/Code/Core/Doc/Doc.cpp index e487e052..6ad06e00 100644 --- a/src/Authoring/Client/Code/Core/Doc/Doc.cpp +++ b/src/Authoring/Client/Code/Core/Doc/Doc.cpp @@ -1276,8 +1276,10 @@ void CDoc::onPropertyChanged(qt3dsdm::Qt3DSDMInstanceHandle inInstance, // TODO: implement a pre-change signal that can be used to extract // controlledproperty string before and after the change, so we know exactly // what happened to the element - for (auto &it : qAsConst(g_StudioApp.m_dataInputDialogItems)) + for (auto &it : qAsConst(g_StudioApp.m_dataInputDialogItems)) { it->controlledElems.clear(); + it->boundTypes.clear(); + } UpdateDatainputMap(m_Core->GetDoc()->GetActiveRootInstance()); } @@ -2881,6 +2883,8 @@ QString CDoc::GetDocumentUIAFile(bool master) return file.isEmpty() ? masterFile : file; } +// TODO: use ProjectFile class framework to parse subpresentations and add datainput use +// information from them to the map as well void CDoc::UpdateDatainputMap( const qt3dsdm::Qt3DSDMInstanceHandle inInstance, QMultiMap<QString, @@ -2899,12 +2903,34 @@ void CDoc::UpdateDatainputMap( QStringList splitStr = currCtrldPropsStr.toQString().split(' '); for (int i = 0; i < splitStr.size() - 1; i += 2) { QString diName = splitStr[i].startsWith('$') ? splitStr[i].remove(0, 1) : splitStr[i]; + QString propName = splitStr[i+1]; + + auto propHandle = propSystem->GetAggregateInstancePropertyByName( + inInstance, propName.toStdWString().c_str()); + auto propType = propSystem->GetDataType(propHandle); + // Update the controlled elements and property types for + // verified, existing datainputs. Note that for @timeline and + // @slide controllers the property type is not found as these + // are pseudo-properties, and return from GetDataType will be invalid. + // For slide control, type is strictly set to String. For timeline, + // the datainput is strictly Ranged Number which cannot be represented + // with object property datatypes, so will be handled separately + // when allowable datainput types are checked. if (g_StudioApp.m_dataInputDialogItems.contains(diName)) { g_StudioApp.m_dataInputDialogItems[diName]-> controlledElems.append(inInstance); + if (propType) { + g_StudioApp.m_dataInputDialogItems[diName]->boundTypes.append( + QPair<qt3dsdm::DataModelDataType::Value, bool>(propType, false)); + } else if (propName == QLatin1String("@slide")) { + g_StudioApp.m_dataInputDialogItems[diName] + ->boundTypes.append(QPair<qt3dsdm::DataModelDataType::Value, bool> + (qt3dsdm::DataModelDataType::Value::String, true)); + + } } else if (outMap != nullptr) { // Do multi insert as single datainput name can - // be found in several elements + // be found in several elements. qt3dsdm::Qt3DSDMPropertyHandle prop = propSystem->GetAggregateInstancePropertyByName( inInstance, splitStr[i+1].toStdWString().c_str()); diff --git a/src/Authoring/Client/Code/Core/Doc/Doc.h b/src/Authoring/Client/Code/Core/Doc/Doc.h index 9909f921..5b11acd7 100644 --- a/src/Authoring/Client/Code/Core/Doc/Doc.h +++ b/src/Authoring/Client/Code/Core/Doc/Doc.h @@ -161,6 +161,13 @@ public: QString name; int type; QVector<qt3dsdm::Qt3DSDMInstanceHandle> controlledElems; + // The type of property/properties that this datainput controls + // for the purposes of limiting allowed datainput type changes. + // Note that there can be more than one type being controlled + // f.ex with Variant type. Boolean signifies "strict" type requirement + // i.e. only the exact equivalent mapping from datainput type to + // property type is allowed (float to float, string to string etc.) + QVector<QPair<qt3dsdm::DataModelDataType::Value, bool>> boundTypes; }; //============================================================================== diff --git a/src/Authoring/Studio/Application/DataInputDlg.cpp b/src/Authoring/Studio/Application/DataInputDlg.cpp index c110452d..2f7cfa8f 100644 --- a/src/Authoring/Studio/Application/DataInputDlg.cpp +++ b/src/Authoring/Studio/Application/DataInputDlg.cpp @@ -34,7 +34,7 @@ #include <QtWidgets/qstyleditemdelegate.h> CDataInputDlg::CDataInputDlg(CDataInputDialogItem **datainput, QStandardItemModel *data, - QWidget *parent) + QWidget *parent, const QVector<EDataType> acceptedTypes) : QDialog(parent, Qt::MSWindowsFixedSizeDialogHint) , m_ui(new Ui::DataInputDlg) , m_data(data) @@ -43,6 +43,7 @@ CDataInputDlg::CDataInputDlg(CDataInputDialogItem **datainput, QStandardItemMode , m_type(0) , m_min(0.0) , m_max(10.0) + , m_acceptedTypes(acceptedTypes) { m_ui->setupUi(this); @@ -50,16 +51,31 @@ CDataInputDlg::CDataInputDlg(CDataInputDialogItem **datainput, QStandardItemMode QStyledItemDelegate *itemDelegate = new QStyledItemDelegate(); m_ui->comboBoxTypeList->setItemDelegate(itemDelegate); - m_ui->comboBoxTypeList->addItem(tr("Boolean")); + m_ui->comboBoxTypeList->addItem(tr("Boolean"), QVariant(DataTypeBoolean)); #ifdef DATAINPUT_EVALUATOR_ENABLED - m_ui->comboBoxTypeList->addItem(tr("Evaluator")); + m_ui->comboBoxTypeList->addItem(tr("Evaluator"), QVariant(DataTypeEvaluator)); #endif - m_ui->comboBoxTypeList->addItem(tr("Float")); - m_ui->comboBoxTypeList->addItem(tr("Ranged Number")); - m_ui->comboBoxTypeList->addItem(tr("String")); - m_ui->comboBoxTypeList->addItem(tr("Variant")); - m_ui->comboBoxTypeList->addItem(tr("Vector2")); - m_ui->comboBoxTypeList->addItem(tr("Vector3")); + m_ui->comboBoxTypeList->addItem(tr("Float"), QVariant(DataTypeFloat)); + m_ui->comboBoxTypeList->addItem(tr("Ranged Number"), QVariant(DataTypeRangedNumber)); + m_ui->comboBoxTypeList->addItem(tr("String"), QVariant(DataTypeString)); + m_ui->comboBoxTypeList->addItem(tr("Variant"), QVariant(DataTypeVariant)); + m_ui->comboBoxTypeList->addItem(tr("Vector2"), QVariant(DataTypeVector2)); + m_ui->comboBoxTypeList->addItem(tr("Vector3"), QVariant(DataTypeVector3)); + + QStandardItemModel *model + = qobject_cast<QStandardItemModel *>(m_ui->comboBoxTypeList->model()); + const QBrush transparent(Qt::transparent); + for (int i = 0; i < m_ui->comboBoxTypeList->model()->rowCount(); ++i) + { + QStandardItem *item = model->item(i, 0); + // We need special handling for Ranged Number as it is + // not a studio property datatype, but relevant only for datainput. + if (!acceptedTypes.contains((EDataType)i) + && !(m_dataInput->type == DataTypeRangedNumber + && item->data(Qt::UserRole) == DataTypeRangedNumber)) { + item->setEnabled(false); + } + } initDialog(); @@ -207,19 +223,29 @@ void CDataInputDlg::updateVisibility(int type) m_ui->lineEditEvaluation->setVisible(false); m_ui->labelEvaluation->setVisible(false); #endif + // Adjust text label positioning according to the + // visibility of info text warning about allowed datatypes. + if (m_dataInput->controlledElems.size()) { + m_ui->labelInfoText->setVisible(true); + m_ui->infoTxtSpacer->changeSize(20, 18); + } else { + m_ui->labelInfoText->setVisible(false); + m_ui->infoTxtSpacer->changeSize(20, 0); + } } const bool CDataInputDlg::isEquivalentDataType(int dlgType, - qt3dsdm::DataModelDataType::Value dmType) + qt3dsdm::DataModelDataType::Value dmType, + bool strict) { if ((dlgType == EDataType::DataTypeString && dmType == qt3dsdm::DataModelDataType::String) || (dlgType == EDataType::DataTypeRangedNumber && (dmType == qt3dsdm::DataModelDataType::Float - || dmType == qt3dsdm::DataModelDataType::String)) + || dmType == qt3dsdm::DataModelDataType::String) && !strict) || (dlgType == EDataType::DataTypeFloat && (dmType == qt3dsdm::DataModelDataType::Float - || dmType == qt3dsdm::DataModelDataType::String)) + || (dmType == qt3dsdm::DataModelDataType::String && !strict))) || (dlgType == EDataType::DataTypeBoolean && dmType == qt3dsdm::DataModelDataType::Bool) || (dlgType == EDataType::DataTypeVector3 @@ -240,25 +266,12 @@ const bool CDataInputDlg::isEquivalentDataType(int dlgType, return false; } -QVector<EDataType> CDataInputDlg::getAcceptedTypes(qt3dsdm::DataModelDataType::Value dmType) +QVector<EDataType> CDataInputDlg::getAcceptedTypes(qt3dsdm::DataModelDataType::Value dmType, + bool strict) { - // The order also specifies the priority for default type in case of multiple accepted types - static const QVector<EDataType> allDataTypes = { - EDataType::DataTypeString, - EDataType::DataTypeFloat, - EDataType::DataTypeVector3, - EDataType::DataTypeVector2, - EDataType::DataTypeRangedNumber, - EDataType::DataTypeBoolean, -#ifdef DATAINPUT_EVALUATOR_ENABLED - EDataType::DataTypeEvaluator, -#endif - EDataType::DataTypeVariant - }; - QVector<EDataType> acceptedTypes; for (auto candidate : allDataTypes) { - if (isEquivalentDataType(candidate, dmType)) + if (isEquivalentDataType(candidate, dmType, strict)) acceptedTypes.append(candidate); } return acceptedTypes; diff --git a/src/Authoring/Studio/Application/DataInputDlg.h b/src/Authoring/Studio/Application/DataInputDlg.h index 838fcd2e..7e84e4b0 100644 --- a/src/Authoring/Studio/Application/DataInputDlg.h +++ b/src/Authoring/Studio/Application/DataInputDlg.h @@ -59,17 +59,33 @@ enum EDataType { DataTypeVector3 }; +// The order also specifies the priority for default type in case of multiple accepted types +static const QVector<EDataType> allDataTypes { + EDataType::DataTypeString, + EDataType::DataTypeFloat, + EDataType::DataTypeVector3, + EDataType::DataTypeVector2, + EDataType::DataTypeRangedNumber, + EDataType::DataTypeBoolean, + #ifdef DATAINPUT_EVALUATOR_ENABLED + EDataType::DataTypeEvaluator, + #endif + EDataType::DataTypeVariant +}; + class CDataInputDlg : public QDialog { Q_OBJECT public: CDataInputDlg(CDataInputDialogItem **datainput, QStandardItemModel *data, - QWidget* parent = nullptr); + QWidget* parent = nullptr, const QVector<EDataType> acceptedTypes = allDataTypes); ~CDataInputDlg(); // Maps between DataModel datatypes and datainput dialog types - static const bool isEquivalentDataType(int dlgType, qt3dsdm::DataModelDataType::Value dmType); - static QVector<EDataType> getAcceptedTypes(qt3dsdm::DataModelDataType::Value dmType); + static const bool isEquivalentDataType(int dlgType, qt3dsdm::DataModelDataType::Value dmType, + bool strict = false); + static QVector<EDataType> getAcceptedTypes(qt3dsdm::DataModelDataType::Value dmType, + bool strict = false); protected: void initDialog(); @@ -94,6 +110,7 @@ private: float m_min; int m_type; QString m_text; + QVector<EDataType> m_acceptedTypes; }; #endif diff --git a/src/Authoring/Studio/Application/DataInputDlg.ui b/src/Authoring/Studio/Application/DataInputDlg.ui index a61130d0..6f48437c 100644 --- a/src/Authoring/Studio/Application/DataInputDlg.ui +++ b/src/Authoring/Studio/Application/DataInputDlg.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>329</width> - <height>169</height> + <width>533</width> + <height>244</height> </rect> </property> <property name="windowTitle"> @@ -20,8 +20,8 @@ <property name="geometry"> <rect> <x>10</x> - <y>130</y> - <width>311</width> + <y>210</y> + <width>511</width> <height>31</height> </rect> </property> @@ -59,8 +59,8 @@ <rect> <x>10</x> <y>10</y> - <width>311</width> - <height>121</height> + <width>511</width> + <height>197</height> </rect> </property> <layout class="QHBoxLayout" name="horizontalLayout_4"> @@ -86,6 +86,22 @@ </widget> </item> <item> + <spacer name="infoTxtSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Preferred</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>18</height> + </size> + </property> + </spacer> + </item> + <item> <widget class="QLabel" name="labelNodeType"> <property name="minimumSize"> <size> @@ -103,6 +119,9 @@ <property name="orientation"> <enum>Qt::Vertical</enum> </property> + <property name="sizeType"> + <enum>QSizePolicy::Expanding</enum> + </property> <property name="sizeHint" stdset="0"> <size> <width>20</width> @@ -187,7 +206,26 @@ </widget> </item> <item> + <widget class="QLabel" name="labelInfoText"> + <property name="font"> + <font> + <pointsize>7</pointsize> + <italic>true</italic> + </font> + </property> + <property name="text"> + <string>Only datatypes compatible with existing controlled properties are allowed</string> + </property> + </widget> + </item> + <item> <widget class="QComboBox" name="comboBoxTypeList"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="toolTip"> <string>The type of the data input</string> </property> diff --git a/src/Authoring/Studio/Application/DataInputListDlg.cpp b/src/Authoring/Studio/Application/DataInputListDlg.cpp index c5fba701..238e3f3f 100644 --- a/src/Authoring/Studio/Application/DataInputListDlg.cpp +++ b/src/Authoring/Studio/Application/DataInputListDlg.cpp @@ -42,7 +42,8 @@ const int columnCount = 3; CDataInputListDlg::CDataInputListDlg(QMap<QString, CDataInputDialogItem *> *datainputs, - bool goToAdd, QWidget *parent, EDataType defaultType) + bool goToAdd, QWidget *parent, EDataType defaultType, + const QVector<EDataType> &acceptedTypes) : QDialog(parent, Qt::MSWindowsFixedSizeDialogHint) , m_ui(new Ui::DataInputListDlg) , m_actualDataInputs(datainputs) @@ -51,6 +52,7 @@ CDataInputListDlg::CDataInputListDlg(QMap<QString, CDataInputDialogItem *> *data , m_currentDataInputIndex(-1) , m_tableContents(new QStandardItemModel(0, columnCount, this)) , m_sortColumn(-1) + , m_acceptedTypes(acceptedTypes) { m_ui->setupUi(this); @@ -232,7 +234,7 @@ void CDataInputListDlg::onAddDataInput() // Create a new data input dialog item and give it to dialog CDataInputDialogItem *dataInput = new CDataInputDialogItem(); dataInput->type = m_defaultType; - CDataInputDlg datainputdialog(&dataInput, m_tableContents, this); + CDataInputDlg datainputdialog(&dataInput, m_tableContents, this, m_acceptedTypes); datainputdialog.setWindowTitle("Add Data Input"); if (datainputdialog.exec() == QDialog::Accepted) { m_dataInputs.insert(dataInput->name, dataInput); @@ -287,7 +289,34 @@ void CDataInputListDlg::onEditDataInput() { if (m_currentDataInputIndex >= 0) { CDataInputDialogItem *di = m_dataInputs.value(m_currentDataInputName); - CDataInputDlg datainputdialog(&di, m_tableContents, this); + + // Only show types that are ok for _all_ currently controlled properties. + // If datainput is not controlling any elements, all types are ok. + QVector<EDataType> allowedTypes; + if (di->controlledElems.size()) { + for (auto type : qAsConst(di->boundTypes)) { + // If we hit strict type requirement for a certain bound datatype, set allowed types + // to only this data type (and Variant) and exit after appending it to + // allowedTypes vector. + // We should never have strict requirement for two different datatypes, obviously. + if (type.second) + allowedTypes.clear(); + + auto acceptedTypes = CDataInputDlg::getAcceptedTypes(type.first, type.second); + + for (auto t : qAsConst(acceptedTypes)) { + if (!allowedTypes.contains(t)) + allowedTypes.append(t); + } + // if we just hit a strict type requirement we are finished + if (type.second) + break; + } + } else { + allowedTypes = allDataTypes; + } + + CDataInputDlg datainputdialog(&di, m_tableContents, this, allowedTypes); datainputdialog.exec(); // insert replaces the previous key - value pair diff --git a/src/Authoring/Studio/Application/DataInputListDlg.h b/src/Authoring/Studio/Application/DataInputListDlg.h index 4ad1c7e7..db791a43 100644 --- a/src/Authoring/Studio/Application/DataInputListDlg.h +++ b/src/Authoring/Studio/Application/DataInputListDlg.h @@ -54,7 +54,8 @@ class CDataInputListDlg : public QDialog public: CDataInputListDlg(QMap<QString, CDataInputDialogItem *> *datainputs, bool goToAdd = false, QWidget *parent = nullptr, - EDataType defaultType = EDataType::DataTypeFloat); + EDataType defaultType = EDataType::DataTypeFloat, + const QVector<EDataType> &acceptedTypes = allDataTypes); ~CDataInputListDlg(); QString getAddedDataInput() { return m_mostRecentlyAdded; } @@ -88,6 +89,7 @@ private: Qt::SortOrder m_sortOrder; QString m_mostRecentlyAdded; EDataType m_defaultType; + QVector<EDataType> m_acceptedTypes; }; #endif diff --git a/src/Authoring/Studio/Application/DataInputSelectView.cpp b/src/Authoring/Studio/Application/DataInputSelectView.cpp index f0d0f4a9..0165ed08 100644 --- a/src/Authoring/Studio/Application/DataInputSelectView.cpp +++ b/src/Authoring/Studio/Application/DataInputSelectView.cpp @@ -149,7 +149,7 @@ void DataInputSelectView::setSelection(int index) } } else { CDataInputListDlg dataInputDlg(&(g_StudioApp.m_dataInputDialogItems), true, - nullptr, m_defaultType); + nullptr, m_defaultType, m_acceptedTypes); dataInputDlg.exec(); if (dataInputDlg.result() == QDialog::Accepted) { diff --git a/src/Authoring/Studio/style.qss b/src/Authoring/Studio/style.qss index 7956e964..a5b4bab9 100644 --- a/src/Authoring/Studio/style.qss +++ b/src/Authoring/Studio/style.qss @@ -387,7 +387,8 @@ QDialog#DataInputListDlg QPushButton#DataInputListButton:pressed { } QDialog#SubPresentationDlg QPushButton:!enabled, -QDialog#DataInputDlg QPushButton:!enabled { +QDialog#DataInputDlg QPushButton:!enabled, +QDialog#DataInputDlg QComboBox QAbstractItemView::item:disabled { background: transparent; color: #727476; } |