diff options
author | Jere Tuliniemi <jere.tuliniemi@qt.io> | 2018-11-30 14:38:25 +0200 |
---|---|---|
committer | Jere Tuliniemi <jere.tuliniemi@qt.io> | 2018-11-30 13:24:48 +0000 |
commit | 9404c3d06f72001a257d07cd258aec50dd5b33ee (patch) | |
tree | 9d540ea0cc990b8f979d5167632880ba0a9bd01a | |
parent | d64688f195cc340e3de3ac8d5423bd18c449a699 (diff) |
Fix case sensitive materialdef renaming
Rename wouldn't occur since QFileInfo::exists() would pass due to case
insensitivity. Fix also inspector checks for materialdef paths and names
to be case insensitive.
Task-number: QT3DS-2789
Change-Id: Ie6e9a0bea11f9eec4470714b2483b7c840cd2478
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r-- | src/Authoring/Client/Code/Core/Doc/Doc.cpp | 4 | ||||
-rw-r--r-- | src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp | 29 |
2 files changed, 25 insertions, 8 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/Doc.cpp b/src/Authoring/Client/Code/Core/Doc/Doc.cpp index 09e5910c..14f0a77a 100644 --- a/src/Authoring/Client/Code/Core/Doc/Doc.cpp +++ b/src/Authoring/Client/Code/Core/Doc/Doc.cpp @@ -1296,7 +1296,9 @@ void CDoc::onPropertyChanged(qt3dsdm::Qt3DSDMInstanceHandle inInstance, = sceneEditor->getFilePathFromMaterialName(materialRename.second); // If the newfile already exists ie. file was renamed manually by the user, // rename the referenced materials regardless - if (QFileInfo(newFile).exists() || QFile::rename(oldFile, newFile)) { + if (QFileInfo(oldFile).exists()) + QFile::rename(oldFile, newFile); + if (QFileInfo(newFile).exists()) { const QString newRelPath = QDir(dirPath).relativeFilePath(newFile); QVector<qt3dsdm::Qt3DSDMInstanceHandle> refMats; diff --git a/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp b/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp index d344eb47..701c06ab 100644 --- a/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp +++ b/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp @@ -730,8 +730,10 @@ InspectorControlBase *InspectorControlModel::createMaterialTypeItem( if (sourcePath == bridge->getDefaultMaterialName()) item->m_value = getBasicMaterialString(); for (int matIdx = 0, end = int(m_matDatas.size()); matIdx < end; ++matIdx) { - if (m_matDatas[matIdx].m_relativePath == sourcePath) + if (QString::compare(m_matDatas[matIdx].m_relativePath, + sourcePath, Qt::CaseInsensitive) == 0) { item->m_value = getBasicMaterialString(); + } } break; } @@ -794,8 +796,10 @@ InspectorControlBase *InspectorControlModel::createMatDataItem( item->m_value = getDefaultMaterialString(); for (int matIdx = 0, end = int(m_matDatas.size()); matIdx < end; ++matIdx) { - if (m_matDatas[matIdx].m_relativePath == sourcePath) - item->m_value = values[matIdx + 1]; // + 1 for Default shared material + if (QString::compare(m_matDatas[matIdx].m_relativePath, + sourcePath, Qt::CaseInsensitive) == 0) { + item->m_value = values[matIdx + 1]; // + 1 for Default basic material + } } return item; @@ -1507,7 +1511,7 @@ void InspectorControlModel::saveIfMaterial(qt3dsdm::Qt3DSDMInstanceHandle instan QString materialName = QString::fromWCharArray(namePtr->GetData(), namePtr->GetLength()); QString sourcePath; for (int i = 0; i < m_matDatas.size(); ++i) { - if (m_matDatas[i].m_name == materialName) { + if (QString::compare(m_matDatas[i].m_name, materialName, Qt::CaseInsensitive) == 0) { sourcePath = doc->GetDocumentDirectory().toQString() + QLatin1Char('/') + m_matDatas[i].m_relativePath; } @@ -1632,18 +1636,29 @@ void InspectorControlModel::setMatDataValue(long instance, int handle, const QVa srcPath = Q3DStudio::CString::fromQString(name); changeMaterialFile = true; } else { + const auto sceneEditor = doc->getSceneEditor(); for (size_t matIdx = 0, end = m_matDatas.size(); matIdx < end; ++matIdx) { QString shownName = m_matDatas[matIdx].m_name; int slashIndex = shownName.lastIndexOf(QLatin1Char('/')); if (slashIndex != -1) shownName = shownName.mid(slashIndex + 1); - if (shownName + QLatin1String(" (") - + m_matDatas[matIdx].m_relativePath + QLatin1Char(')') == typeValue - || shownName == typeValue) { + if (QString::compare(shownName + QLatin1String(" (") + + m_matDatas[matIdx].m_relativePath + QLatin1Char(')'), + typeValue, Qt::CaseInsensitive) == 0 + || QString::compare(shownName, typeValue, Qt::CaseInsensitive) == 0) { v = Q3DStudio::CString("Referenced Material"); changeMaterialFile = true; name = m_matDatas[matIdx].m_name; srcPath = Q3DStudio::CString::fromQString(m_matDatas[matIdx].m_relativePath); + const auto material = sceneEditor->getMaterial(srcPath.toQString()); + if (material.Valid()) { + // Get the correct case source path + const auto absPath = sceneEditor->getFilePathFromMaterialName( + sceneEditor->GetName(material).toQString()); + const auto relPath = QDir(doc->GetDocumentDirectory().toQString()) + .relativeFilePath(absPath); + srcPath = Q3DStudio::CString::fromQString(relPath); + } values = m_matDatas[matIdx].m_values; textureValues = m_matDatas[matIdx].m_textureValues; break; |