From c39d3e96e6e8725207eda830b9b5660bd2783a3e Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 12 Jun 2018 14:36:18 +0300 Subject: Fix datainput type issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - When adding a new data input the type is set correctly even if you don't touch the type combo. - When adding a new data input from popup menu for property, timeline, or slide panel, the corresponding data input is not changed if the new data input is of unsuitable type. - Correct default type is shown for each property when setting data input from inspector panel. Task-number: QT3DS-1913 Change-Id: I704cb704fb1ec9aca916ed7f7542ace404bba77c Reviewed-by: Mahmoud Badri Reviewed-by: Antti Määttä --- src/Authoring/Studio/Application/DataInputDlg.cpp | 45 ++++++++++++++++++---- src/Authoring/Studio/Application/DataInputDlg.h | 2 + .../Studio/Application/DataInputSelectView.cpp | 27 +++++++++++-- .../Studio/Application/DataInputSelectView.h | 6 ++- .../Palettes/Inspector/InspectorControlView.cpp | 5 ++- src/Authoring/Studio/Palettes/Slide/SlideView.cpp | 3 +- .../TimelineGraphicsView/ui/TimelineToolbar.cpp | 3 +- 7 files changed, 73 insertions(+), 18 deletions(-) diff --git a/src/Authoring/Studio/Application/DataInputDlg.cpp b/src/Authoring/Studio/Application/DataInputDlg.cpp index 57c16e4d..c110452d 100644 --- a/src/Authoring/Studio/Application/DataInputDlg.cpp +++ b/src/Authoring/Studio/Application/DataInputDlg.cpp @@ -89,12 +89,7 @@ void CDataInputDlg::initDialog() if (!m_dataInput->name.isEmpty()) { m_name = m_dataInput->name; - m_type = m_dataInput->type; - m_ui->comboBoxTypeList->setCurrentIndex(m_dataInput->type); - m_ui->lineEditInputName->setText(m_dataInput->name); - if (m_type == DataTypeRangedNumber) { - m_ui->doubleSpinBoxMin->setValue(m_dataInput->minValue); - m_ui->doubleSpinBoxMax->setValue(m_dataInput->maxValue); + if (m_dataInput->type == DataTypeRangedNumber) { m_min = m_dataInput->minValue; m_max = m_dataInput->maxValue; } @@ -105,8 +100,18 @@ void CDataInputDlg::initDialog() #endif } else { m_name = getUniqueId(tr("newDataInput")); - m_ui->comboBoxTypeList->setCurrentIndex(m_dataInput->type); - m_ui->lineEditInputName->setText(m_name); + if (m_dataInput->type == DataTypeRangedNumber) { + m_dataInput->minValue = m_min; + m_dataInput->maxValue = m_max; + } + } + + m_type = m_dataInput->type; + m_ui->comboBoxTypeList->setCurrentIndex(m_type); + m_ui->lineEditInputName->setText(m_name); + if (m_type == DataTypeRangedNumber) { + m_ui->doubleSpinBoxMin->setValue(m_dataInput->minValue); + m_ui->doubleSpinBoxMax->setValue(m_dataInput->maxValue); } updateVisibility(m_dataInput->type); @@ -234,3 +239,27 @@ const bool CDataInputDlg::isEquivalentDataType(int dlgType, return false; } + +QVector CDataInputDlg::getAcceptedTypes(qt3dsdm::DataModelDataType::Value dmType) +{ + // The order also specifies the priority for default type in case of multiple accepted types + static const QVector allDataTypes = { + EDataType::DataTypeString, + EDataType::DataTypeFloat, + EDataType::DataTypeVector3, + EDataType::DataTypeVector2, + EDataType::DataTypeRangedNumber, + EDataType::DataTypeBoolean, +#ifdef DATAINPUT_EVALUATOR_ENABLED + EDataType::DataTypeEvaluator, +#endif + EDataType::DataTypeVariant + }; + + QVector acceptedTypes; + for (auto candidate : allDataTypes) { + if (isEquivalentDataType(candidate, dmType)) + acceptedTypes.append(candidate); + } + return acceptedTypes; +} diff --git a/src/Authoring/Studio/Application/DataInputDlg.h b/src/Authoring/Studio/Application/DataInputDlg.h index e38ee8b8..838fcd2e 100644 --- a/src/Authoring/Studio/Application/DataInputDlg.h +++ b/src/Authoring/Studio/Application/DataInputDlg.h @@ -69,6 +69,8 @@ public: // Maps between DataModel datatypes and datainput dialog types static const bool isEquivalentDataType(int dlgType, qt3dsdm::DataModelDataType::Value dmType); + static QVector getAcceptedTypes(qt3dsdm::DataModelDataType::Value dmType); + protected: void initDialog(); QString getUniqueId(const QString &id); diff --git a/src/Authoring/Studio/Application/DataInputSelectView.cpp b/src/Authoring/Studio/Application/DataInputSelectView.cpp index 11c45e6e..40b8e0d8 100644 --- a/src/Authoring/Studio/Application/DataInputSelectView.cpp +++ b/src/Authoring/Studio/Application/DataInputSelectView.cpp @@ -38,12 +38,17 @@ #include "DataInputDlg.h" #include "StudioApp.h" -DataInputSelectView::DataInputSelectView(QWidget *parent, EDataType defaultType) +// Empty acceptedTypes vector means all types are accepted +DataInputSelectView::DataInputSelectView(const QVector &acceptedTypes, QWidget *parent) : QQuickWidget(parent) , m_model(new DataInputSelectModel(this)) - , m_defaultType(defaultType) + , m_defaultType(EDataType::DataTypeFloat) + , m_acceptedTypes(acceptedTypes) { + if (!m_acceptedTypes.isEmpty()) + m_defaultType = m_acceptedTypes[0]; + setWindowTitle(tr("Datainputs")); setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); setResizeMode(QQuickWidget::SizeRootObjectToView); @@ -60,6 +65,13 @@ void DataInputSelectView::setData(const QVector> &dataInputL updateData(dataInputList); } +void DataInputSelectView::setAcceptedTypes(const QVector &acceptedTypes) +{ + m_acceptedTypes = acceptedTypes; + if (!m_acceptedTypes.isEmpty()) + m_defaultType = m_acceptedTypes[0]; +} + void DataInputSelectView::updateData(const QVector> &dataInputList) { m_selection = -1; @@ -139,8 +151,15 @@ void DataInputSelectView::setSelection(int index) if (dataInputDlg.result() == QDialog::Accepted) { m_mostRecentlyAdded = dataInputDlg.getAddedDataInput(); - if (m_mostRecentlyAdded.size()) - Q_EMIT dataInputChanged(m_handle, m_instance, m_mostRecentlyAdded); + if (m_mostRecentlyAdded.size()) { + CDataInputDialogItem *diItem = g_StudioApp.m_dataInputDialogItems.value( + m_mostRecentlyAdded); + if (m_acceptedTypes.isEmpty() + || (diItem && m_acceptedTypes.contains( + static_cast(diItem->type)))) { + Q_EMIT dataInputChanged(m_handle, m_instance, m_mostRecentlyAdded); + } + } g_StudioApp.SaveUIAFile(false); } } diff --git a/src/Authoring/Studio/Application/DataInputSelectView.h b/src/Authoring/Studio/Application/DataInputSelectView.h index 92456972..6db29c13 100644 --- a/src/Authoring/Studio/Application/DataInputSelectView.h +++ b/src/Authoring/Studio/Application/DataInputSelectView.h @@ -40,11 +40,12 @@ class DataInputSelectView : public QQuickWidget Q_OBJECT Q_PROPERTY(int selected MEMBER m_selection NOTIFY selectedChanged) public: - explicit DataInputSelectView(QWidget *parent = nullptr, - EDataType defaultType = EDataType::DataTypeFloat); + explicit DataInputSelectView(const QVector &acceptedTypes, + QWidget *parent = nullptr); void setData(const QVector> &dataInputList, const QString ¤tController, int handle = 0, int instance = 0); + void setAcceptedTypes(const QVector &acceptedTypes); QString getAddNewDataInputString() { return tr("[Add New Datainput]"); } QString getNoneString() { return tr("[None]"); } @@ -69,6 +70,7 @@ private: QString m_currController; QString m_mostRecentlyAdded; EDataType m_defaultType; + QVector m_acceptedTypes; }; #endif // DATAINPUTSELECTDLG_H diff --git a/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.cpp b/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.cpp index 671a0f76..54ebf193 100644 --- a/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.cpp +++ b/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.cpp @@ -488,7 +488,8 @@ QObject *InspectorControlView::showObjectReference(int handle, int instance, con QObject *InspectorControlView::showDataInputChooser(int handle, int instance, const QPoint &point) { if (!m_dataInputChooserView) { - m_dataInputChooserView = new DataInputSelectView(this); + const QVector acceptedTypes; + m_dataInputChooserView = new DataInputSelectView(acceptedTypes); connect(m_dataInputChooserView, &DataInputSelectView::dataInputChanged, this, [this](int handle, int instance, const QString &controllerName) { bool controlled = @@ -511,7 +512,7 @@ QObject *InspectorControlView::showDataInputChooser(int handle, int instance, co if (CDataInputDlg::isEquivalentDataType(it->type, dataType)) dataInputList.append(QPair(it->name, it->type)); } - + m_dataInputChooserView->setAcceptedTypes(CDataInputDlg::getAcceptedTypes(dataType)); m_dataInputChooserView-> setData(dataInputList, m_inspectorControlModel->currentControllerValue(instance, handle), diff --git a/src/Authoring/Studio/Palettes/Slide/SlideView.cpp b/src/Authoring/Studio/Palettes/Slide/SlideView.cpp index 47fb154b..fd1a31bd 100644 --- a/src/Authoring/Studio/Palettes/Slide/SlideView.cpp +++ b/src/Authoring/Studio/Palettes/Slide/SlideView.cpp @@ -384,7 +384,8 @@ void SlideView::initialize() engine()->addImportPath(qmlImportPath()); setSource(QUrl("qrc:/Palettes/Slide/SlideView.qml"_L1)); - m_dataInputSelector = new DataInputSelectView(this, EDataType::DataTypeString); + const QVector acceptedTypes = { EDataType::DataTypeString }; + m_dataInputSelector = new DataInputSelectView(acceptedTypes, this); connect(m_dataInputSelector, &DataInputSelectView::dataInputChanged, this, &SlideView::onDataInputChange); } diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp index 8c4de2e4..12edb43e 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp @@ -146,7 +146,8 @@ TimelineToolbar::TimelineToolbar() : QToolBar() std::bind(&TimelineToolbar::onSelectionChange, this, std::placeholders::_1)); // make datainput indicator listen to selection dialog choice - m_dataInputSelector = new DataInputSelectView(this, EDataType::DataTypeRangedNumber); + const QVector acceptedTypes = { EDataType::DataTypeRangedNumber }; + m_dataInputSelector = new DataInputSelectView(acceptedTypes, this); g_StudioApp.GetCore()->GetDispatch()->AddDataModelListener(this); connect(m_dataInputSelector, &DataInputSelectView::dataInputChanged, this, &TimelineToolbar::onDataInputChange); -- cgit v1.2.3