forked from qt-creator/qt-creator
QmlDesigner: Allow adding imported 3D models using the context menu
Also some changes to support translation and avoid translation-related issues. Change-Id: Ie2cc491cf491ac4c14e12e8cf666d4b452b9e7c1 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include "metainfo.h"
|
||||
#include "seekerslider.h"
|
||||
#include "view3dactioncommand.h"
|
||||
#include "nodehints.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/messagebox.h>
|
||||
@@ -46,7 +47,6 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QToolButton>
|
||||
|
||||
namespace QmlDesigner {
|
||||
@@ -222,19 +222,40 @@ void Edit3DView::onEntriesChanged()
|
||||
|
||||
void Edit3DView::handleEntriesChanged()
|
||||
{
|
||||
QMap<QString, QList<ItemLibraryEntry>> entriesMap {
|
||||
{"Camera", {}},
|
||||
{"Lights", {}},
|
||||
{"Models", {}}
|
||||
if (!model())
|
||||
return;
|
||||
|
||||
const QString cameras = tr("Cameras");
|
||||
const QString lights = tr("Lights");
|
||||
const QString primitives = tr("Primitives");
|
||||
const QString importedModels = tr("Imported Models");
|
||||
const QStringList keys {cameras, lights, primitives, importedModels}; // used to maintain order
|
||||
|
||||
QHash<QString, QList<ItemLibraryEntry>> entriesMap {
|
||||
{cameras, {}},
|
||||
{lights, {}},
|
||||
{primitives, {}},
|
||||
{importedModels, {}}
|
||||
};
|
||||
|
||||
const QList<ItemLibraryEntry> itemLibEntries = model()->metaInfo().itemLibraryInfo()->entries();
|
||||
for (const ItemLibraryEntry &entry : itemLibEntries) {
|
||||
if (entry.typeName().startsWith("QtQuick3D.") && entriesMap.contains(entry.category()))
|
||||
entriesMap[entry.category()].append(entry);
|
||||
if (entry.typeName() == "QtQuick3D.Model") {
|
||||
entriesMap[primitives].append(entry);
|
||||
} else if (entry.typeName() == "QtQuick3D.DirectionalLight"
|
||||
|| entry.typeName() == "QtQuick3D.PointLight"
|
||||
|| entry.typeName() == "QtQuick3D.SpotLight") {
|
||||
entriesMap[lights].append(entry);
|
||||
} else if (entry.typeName() == "QtQuick3D.OrthographicCamera"
|
||||
|| entry.typeName() == "QtQuick3D.PerspectiveCamera") {
|
||||
entriesMap[cameras].append(entry);
|
||||
} else if (entry.typeName().startsWith("Quick3DAssets.")
|
||||
&& NodeHints::fromItemLibraryEntry(entry).canBeDroppedInView3D()) {
|
||||
entriesMap[importedModels].append(entry);
|
||||
}
|
||||
}
|
||||
|
||||
m_edit3DWidget->updateCreateSubMenu(entriesMap);
|
||||
m_edit3DWidget->updateCreateSubMenu(keys, entriesMap);
|
||||
}
|
||||
|
||||
void Edit3DView::modelAboutToBeDetached(Model *model)
|
||||
|
@@ -193,8 +193,9 @@ void Edit3DWidget::createContextMenu()
|
||||
});
|
||||
}
|
||||
|
||||
// Called by the view to update the "create" sub-menu when the Quick3D entries are ready
|
||||
void Edit3DWidget::updateCreateSubMenu(const QMap<QString, QList<ItemLibraryEntry>> &entriesMap)
|
||||
// Called by the view to update the "create" sub-menu when the Quick3D entries are ready.
|
||||
void Edit3DWidget::updateCreateSubMenu(const QStringList &keys,
|
||||
const QHash<QString, QList<ItemLibraryEntry>> &entriesMap)
|
||||
{
|
||||
if (!m_contextMenu)
|
||||
return;
|
||||
@@ -207,14 +208,17 @@ void Edit3DWidget::updateCreateSubMenu(const QMap<QString, QList<ItemLibraryEntr
|
||||
m_nameToEntry.clear();
|
||||
m_createSubMenu = m_contextMenu->addMenu(tr("Create"));
|
||||
|
||||
const QStringList categories = entriesMap.keys();
|
||||
for (const QString &cat : categories) {
|
||||
for (const QString &cat : keys) {
|
||||
QList<ItemLibraryEntry> entries = entriesMap.value(cat);
|
||||
if (entries.isEmpty())
|
||||
continue;
|
||||
|
||||
QMenu *catMenu = m_createSubMenu->addMenu(cat);
|
||||
|
||||
QList<ItemLibraryEntry> entries = entriesMap.value(cat);
|
||||
std::sort(entries.begin(), entries.end(), [](const ItemLibraryEntry &a, const ItemLibraryEntry &b) {
|
||||
return a.name() < b.name();
|
||||
});
|
||||
|
||||
for (const ItemLibraryEntry &entry : std::as_const(entries)) {
|
||||
QAction *action = catMenu->addAction(entry.name(), this, &Edit3DWidget::onCreateAction);
|
||||
action->setData(entry.name());
|
||||
|
@@ -58,7 +58,8 @@ public:
|
||||
void showBackgroundColorMenu(bool show, const QPoint &pos);
|
||||
|
||||
void showContextMenu(const QPoint &pos, const ModelNode &modelNode);
|
||||
void updateCreateSubMenu(const QMap<QString, QList<ItemLibraryEntry>> &entriesMap);
|
||||
void updateCreateSubMenu(const QStringList &keys,
|
||||
const QHash<QString, QList<ItemLibraryEntry>> &entriesMap);
|
||||
|
||||
private slots:
|
||||
void onCreateAction();
|
||||
|
Reference in New Issue
Block a user