forked from qt-creator/qt-creator
QmlDesigner: Add "Create" submenu to the 3D Editor's context menu
Allow adding Quick3D Node-based items to the 3D scene using the contxt menu. Fixes: QDS-7397 Fixes: QDS-7399 Fixes: QDS-7400 Change-Id: Ib0a9b1c0243e3e945b4925262f68d80d2460f516 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Samuel Ghinet <samuel.ghinet@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "designersettings.h"
|
||||
#include "edit3dactions.h"
|
||||
#include "edit3dcanvas.h"
|
||||
#include "edit3dview.h"
|
||||
@@ -42,6 +41,7 @@
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <toolbox.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QActionGroup>
|
||||
@@ -193,6 +193,57 @@ 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)
|
||||
{
|
||||
if (!m_contextMenu)
|
||||
return;
|
||||
|
||||
if (m_createSubMenu) {
|
||||
m_contextMenu->removeAction(m_createSubMenu->menuAction());
|
||||
m_createSubMenu.clear();
|
||||
}
|
||||
|
||||
m_nameToEntry.clear();
|
||||
m_createSubMenu = m_contextMenu->addMenu(tr("Create"));
|
||||
|
||||
const QStringList categories = entriesMap.keys();
|
||||
for (const QString &cat : categories) {
|
||||
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());
|
||||
m_nameToEntry.insert(entry.name(), entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Action triggered from the "create" sub-menu
|
||||
void Edit3DWidget::onCreateAction()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
if (!action)
|
||||
return;
|
||||
|
||||
m_view->executeInTransaction(__FUNCTION__, [&] {
|
||||
int activeScene = m_view->rootModelNode().auxiliaryData("active3dScene@Internal").toInt();
|
||||
|
||||
auto modelNode = QmlVisualNode::createQml3DNode(m_view, m_nameToEntry.value(action->data().toString()),
|
||||
activeScene).modelNode();
|
||||
QTC_ASSERT(modelNode.isValid(), return);
|
||||
m_view->setSelectedModelNode(modelNode);
|
||||
|
||||
// if added node is a Model, assign it a material
|
||||
if (modelNode.isSubclassOf("QtQuick3D.Model"))
|
||||
m_view->assignMaterialTo3dModel(modelNode);
|
||||
});
|
||||
}
|
||||
|
||||
void Edit3DWidget::contextHelp(const Core::IContext::HelpCallback &callback) const
|
||||
{
|
||||
if (m_view)
|
||||
|
||||
Reference in New Issue
Block a user