forked from qt-creator/qt-creator
QmlDesigner: Disable MCU unsupported workspace and views
This patch disable unsupported 3D workspace and some views from view menu and toolbar combobox Task-number: QDS-10336 Change-Id: Ic97baead8029a93ae95707b9349f81f02adb6335 Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Yasser Grimes <yasser.grimes@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="3D Advanced">
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="3D Advanced" mcusEnabled="false">
|
||||
<container floating="false">
|
||||
<splitter orientation="Vertical" count="2">
|
||||
<splitter orientation="Horizontal" count="3">
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="2D Animation">
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="2D Animation" mcusEnabled="true">
|
||||
<container floating="false">
|
||||
<splitter orientation="Vertical" count="2">
|
||||
<splitter orientation="Horizontal" count="3">
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="3D Animation">
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="3D Animation" mcusEnabled="false">
|
||||
<container floating="false">
|
||||
<splitter orientation="Horizontal" count="2">
|
||||
<splitter orientation="Vertical" count="2">
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="Default">
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="Default" mcusEnabled="true">
|
||||
<container floating="false">
|
||||
<splitter orientation="Horizontal" count="3">
|
||||
<splitter orientation="Vertical" count="3">
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="Code">
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="Code" mcusEnabled="true">
|
||||
<container floating="false">
|
||||
<splitter orientation="Horizontal" count="3">
|
||||
<splitter orientation="Vertical" count="3">
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="3D Essentials">
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="3D Essentials" mcusEnabled="false">
|
||||
<container floating="false">
|
||||
<splitter orientation="Horizontal" count="3">
|
||||
<splitter orientation="Vertical" count="3">
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<QtAdvancedDockingSystem version="1" containers="1" displayName="Essentials">
|
||||
<QtAdvancedDockingSystem version="1" containers="1" displayName="Essentials" mcusEnabled="true">
|
||||
<container floating="false">
|
||||
<splitter orientation="Horizontal" count="3">
|
||||
<splitter orientation="Vertical" count="3">
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="Design">
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="1" displayName="Design" mcusEnabled="true">
|
||||
<container floating="false">
|
||||
<splitter orientation="Vertical" count="2">
|
||||
<splitter orientation="Horizontal" count="3">
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="2" displayName="All Views">
|
||||
<QtAdvancedDockingSystem version="1" userVersion="0" containers="2" displayName="All Views" mcusEnabled="false">
|
||||
<container floating="false">
|
||||
<splitter orientation="Horizontal" count="3">
|
||||
<splitter orientation="Vertical" count="3">
|
||||
|
@@ -1578,6 +1578,55 @@ bool DockManager::writeDisplayName(const FilePath &filePath, const QString &disp
|
||||
return true;
|
||||
}
|
||||
|
||||
QString DockManager::readMcusEnabled(const FilePath &filePath)
|
||||
{
|
||||
auto data = loadFile(filePath);
|
||||
|
||||
if (data.isEmpty())
|
||||
return {};
|
||||
|
||||
auto tmp = data.startsWith("<?xml") ? data : qUncompress(data);
|
||||
|
||||
DockingStateReader reader(tmp);
|
||||
if (!reader.readNextStartElement())
|
||||
return {};
|
||||
|
||||
if (reader.name() != QLatin1String("QtAdvancedDockingSystem"))
|
||||
return {};
|
||||
|
||||
return reader.attributes().value(workspaceMcusEnabledAttribute.toString()).toString();
|
||||
}
|
||||
|
||||
bool DockManager::writeMcusEnabled(const FilePath &filePath, const QString &mcusEnabled)
|
||||
{
|
||||
const expected_str<QByteArray> content = filePath.fileContents();
|
||||
|
||||
QTC_ASSERT_EXPECTED(content, return false);
|
||||
|
||||
QDomDocument doc;
|
||||
QString error_msg;
|
||||
int error_line, error_col;
|
||||
if (!doc.setContent(*content, &error_msg, &error_line, &error_col)) {
|
||||
qWarning() << QString("XML error on line %1, col %2: %3")
|
||||
.arg(error_line)
|
||||
.arg(error_col)
|
||||
.arg(error_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement docElem = doc.documentElement();
|
||||
docElem.setAttribute(workspaceMcusEnabledAttribute.toString(), mcusEnabled);
|
||||
|
||||
const expected_str<void> result = write(filePath, doc.toByteArray(workspaceXmlFormattingIndent));
|
||||
if (!result) {
|
||||
qWarning() << "Could not write mcusEnabled" << mcusEnabled << "to" << filePath << ":"
|
||||
<< result.error();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
expected_str<void> DockManager::write(const FilePath &filePath, const QByteArray &data)
|
||||
{
|
||||
qCInfo(adsLog) << "Write" << filePath;
|
||||
@@ -1638,6 +1687,11 @@ void DockManager::syncWorkspacePresets()
|
||||
const QString name = readDisplayName(userFile);
|
||||
if (name.isEmpty())
|
||||
writeDisplayName(userFile, name);
|
||||
|
||||
const QString presetMcusEnabled = readMcusEnabled(filePath);
|
||||
const QString mcusEnabled = readMcusEnabled(userFile);
|
||||
if (mcusEnabled.isEmpty() || mcusEnabled != presetMcusEnabled)
|
||||
writeMcusEnabled(userFile, presetMcusEnabled);
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -1694,4 +1748,12 @@ void DockManager::saveLockWorkspace()
|
||||
d->m_settings->setValue(Constants::LOCK_WORKSPACE_SETTINGS_KEY, d->m_workspaceLocked);
|
||||
}
|
||||
|
||||
void DockManager::setMcusProject(bool value) {
|
||||
m_mcusProject = value;
|
||||
}
|
||||
|
||||
bool DockManager::mcusProject() const {
|
||||
return m_mcusProject;
|
||||
}
|
||||
|
||||
} // namespace ADS
|
||||
|
@@ -57,6 +57,7 @@ inline constexpr QStringView workspaceFolderName{u"workspaces"};
|
||||
inline constexpr QStringView workspaceFileExtension{u"wrk"};
|
||||
inline constexpr QStringView workspaceOrderFileName{u"order.json"};
|
||||
inline constexpr QStringView workspaceDisplayNameAttribute{u"displayName"};
|
||||
inline constexpr QStringView workspaceMcusEnabledAttribute{u"mcusEnabled"};
|
||||
inline const int workspaceXmlFormattingIndent = 2;
|
||||
|
||||
/**
|
||||
@@ -760,6 +761,8 @@ public:
|
||||
static QByteArray loadFile(const Utils::FilePath &filePath);
|
||||
static QString readDisplayName(const Utils::FilePath &filePath);
|
||||
static bool writeDisplayName(const Utils::FilePath &filePath, const QString &displayName);
|
||||
static QString readMcusEnabled(const Utils::FilePath &filePath);
|
||||
static bool writeMcusEnabled(const Utils::FilePath &filePath, const QString &mcusEnabled);
|
||||
|
||||
/**
|
||||
* This is used to limit saving of workspaces to only when they were actually presented ones,
|
||||
@@ -768,6 +771,9 @@ public:
|
||||
*/
|
||||
void aboutToShow();
|
||||
|
||||
void setMcusProject(bool value);
|
||||
bool mcusProject() const;
|
||||
|
||||
signals:
|
||||
void aboutToUnloadWorkspace(QString fileName);
|
||||
void aboutToLoadWorkspace(QString fileName);
|
||||
@@ -789,6 +795,8 @@ private:
|
||||
|
||||
void saveStartupWorkspace();
|
||||
void saveLockWorkspace();
|
||||
|
||||
bool m_mcusProject = false;
|
||||
}; // class DockManager
|
||||
|
||||
} // namespace ADS
|
||||
|
@@ -28,6 +28,12 @@ Workspace::Workspace(const Utils::FilePath &filePath, bool isPreset)
|
||||
} else {
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
QString mcusEnabled = DockManager::readMcusEnabled(m_filePath);
|
||||
if (mcusEnabled.isEmpty())
|
||||
setMcusEnabled(true);
|
||||
else
|
||||
m_mcusEnabled = QVariant::fromValue(mcusEnabled).toBool();
|
||||
}
|
||||
|
||||
void Workspace::setName(const QString &name)
|
||||
@@ -84,6 +90,18 @@ bool Workspace::isPreset() const
|
||||
return m_preset;
|
||||
}
|
||||
|
||||
void Workspace::setMcusEnabled(bool enabled)
|
||||
{
|
||||
QString mcusEnabled = QVariant::fromValue(enabled).toString();
|
||||
if (DockManager::writeMcusEnabled(filePath(), mcusEnabled))
|
||||
m_mcusEnabled = enabled;
|
||||
}
|
||||
|
||||
bool Workspace::isMcusEnabled() const
|
||||
{
|
||||
return m_mcusEnabled;
|
||||
}
|
||||
|
||||
Workspace::operator QString() const
|
||||
{
|
||||
return QString("Workspace %1 Preset[%2] %3")
|
||||
|
@@ -30,6 +30,9 @@ public:
|
||||
void setPreset(bool value);
|
||||
bool isPreset() const;
|
||||
|
||||
void setMcusEnabled(bool value);
|
||||
bool isMcusEnabled() const;
|
||||
|
||||
friend bool operator==(const Workspace &a, const Workspace &b)
|
||||
{
|
||||
return a.fileName() == b.fileName();
|
||||
@@ -50,6 +53,7 @@ private:
|
||||
QString m_name;
|
||||
Utils::FilePath m_filePath;
|
||||
bool m_preset = false;
|
||||
bool m_mcusEnabled = true;
|
||||
};
|
||||
|
||||
} // namespace ADS
|
||||
|
@@ -22,7 +22,7 @@ WorkspaceModel::WorkspaceModel(DockManager *manager, QObject *parent)
|
||||
connect(m_manager, &DockManager::workspaceLoaded, this, &WorkspaceModel::resetWorkspaces);
|
||||
}
|
||||
|
||||
int WorkspaceModel::indexOfWorkspace(const QString &fileName)
|
||||
int WorkspaceModel::indexOfWorkspace(const QString &fileName) const
|
||||
{
|
||||
return m_manager->workspaceIndex(fileName);
|
||||
}
|
||||
@@ -134,6 +134,10 @@ Qt::ItemFlags WorkspaceModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags defaultFlags = QAbstractTableModel::flags(index);
|
||||
|
||||
Workspace *workspace = m_manager->workspace(workspaceAt(index.row()));
|
||||
if (m_manager->mcusProject() && !workspace->isMcusEnabled())
|
||||
defaultFlags &= ~Qt::ItemIsEnabled;
|
||||
|
||||
if (index.isValid())
|
||||
return Qt::ItemIsDragEnabled | defaultFlags;
|
||||
|
||||
|
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
explicit WorkspaceModel(DockManager *manager, QObject *parent = nullptr);
|
||||
|
||||
int indexOfWorkspace(const QString &fileName);
|
||||
int indexOfWorkspace(const QString &fileName) const;
|
||||
QString workspaceAt(int row) const;
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
@@ -149,6 +149,14 @@ WorkspaceModel::WorkspaceModel(QObject *)
|
||||
};
|
||||
if (!connectDockManager())
|
||||
connect(designModeWidget(), &Internal::DesignModeWidget::initialized, this, connectDockManager);
|
||||
|
||||
connect(ProjectExplorer::ProjectManager::instance(),
|
||||
&ProjectExplorer::ProjectManager::projectFinishedParsing,
|
||||
this,
|
||||
[this]() {
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
});
|
||||
}
|
||||
|
||||
int WorkspaceModel::rowCount(const QModelIndex &) const
|
||||
@@ -162,7 +170,8 @@ int WorkspaceModel::rowCount(const QModelIndex &) const
|
||||
QHash<int, QByteArray> WorkspaceModel::roleNames() const
|
||||
{
|
||||
static QHash<int, QByteArray> roleNames{{DisplayNameRole, "displayName"},
|
||||
{FileNameRole, "fileName"}};
|
||||
{FileNameRole, "fileName"},
|
||||
{Enabled, "enabled"}};
|
||||
|
||||
return roleNames;
|
||||
}
|
||||
@@ -176,6 +185,9 @@ QVariant WorkspaceModel::data(const QModelIndex &index, int role) const
|
||||
return workspace.name();
|
||||
} else if (role == FileNameRole) {
|
||||
return workspace.fileName();
|
||||
} else if (role == Enabled) {
|
||||
if (QmlProjectManager::QmlProject::isMCUs())
|
||||
return workspace.isMcusEnabled();
|
||||
} else {
|
||||
qWarning() << Q_FUNC_INFO << "invalid role";
|
||||
}
|
||||
|
@@ -29,7 +29,8 @@ public:
|
||||
class WorkspaceModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
enum { DisplayNameRole = Qt::DisplayRole, FileNameRole = Qt::UserRole };
|
||||
|
||||
enum { DisplayNameRole = Qt::DisplayRole, FileNameRole = Qt::UserRole, Enabled };
|
||||
|
||||
public:
|
||||
explicit WorkspaceModel(QObject *parent = nullptr);
|
||||
|
@@ -34,6 +34,7 @@
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <coreplugin/inavigationwidgetfactory.h>
|
||||
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <qmlprojectmanager/qmlproject.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
@@ -219,6 +220,13 @@ void DesignModeWidget::setup()
|
||||
QString sheet = QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/dockwidgets.css"));
|
||||
m_dockManager->setStyleSheet(Theme::replaceCssColors(sheet));
|
||||
|
||||
connect(ProjectExplorer::ProjectManager::instance(),
|
||||
&ProjectExplorer::ProjectManager::projectFinishedParsing,
|
||||
m_dockManager,
|
||||
[this]() {
|
||||
this->m_dockManager->setMcusProject(QmlProjectManager::QmlProject::isMCUs());
|
||||
});
|
||||
|
||||
// Setup icons
|
||||
const QString closeUnicode = Theme::getIconUnicode(Theme::Icon::close_small);
|
||||
const QString maximizeUnicode = Theme::getIconUnicode(Theme::Icon::maxBar_small);
|
||||
@@ -273,6 +281,7 @@ void DesignModeWidget::setup()
|
||||
Core::ActionContainer *mview = Core::ActionManager::actionContainer(Core::Constants::M_VIEW);
|
||||
// View > Views
|
||||
Core::ActionContainer *mviews = Core::ActionManager::createMenu(Core::Constants::M_VIEW_VIEWS);
|
||||
connect(mviews->menu(), &QMenu::aboutToShow, this, &DesignModeWidget::aboutToShowViews);
|
||||
mviews->menu()->addSeparator();
|
||||
// View > Workspaces
|
||||
Core::ActionContainer *mworkspaces = Core::ActionManager::createMenu(QmlDesigner::Constants::M_VIEW_WORKSPACES);
|
||||
@@ -482,6 +491,29 @@ void DesignModeWidget::setup()
|
||||
show();
|
||||
}
|
||||
|
||||
static bool isMcuDisabledView(const QString viewId)
|
||||
{
|
||||
static const QStringList mcuDisabledViews = {"Editor3D", "MaterialEditor", "MaterialBrowser", "TextureEditor"};
|
||||
return mcuDisabledViews.contains(viewId);
|
||||
}
|
||||
|
||||
void DesignModeWidget::aboutToShowViews()
|
||||
{
|
||||
for (const WidgetInfo &widgetInfo : viewManager().widgetInfos()) {
|
||||
QString id = widgetInfo.uniqueId;
|
||||
ADS::DockWidget *dockWidget = m_dockManager->findDockWidget(id);
|
||||
QAction *action = dockWidget->toggleViewAction();
|
||||
|
||||
bool isMcuProject = currentDesignDocument() && currentDesignDocument()->isQtForMCUsProject();
|
||||
if (isMcuProject && isMcuDisabledView(id) && action->isEnabled()) {
|
||||
action->setChecked(false);
|
||||
action->setEnabled(false);
|
||||
} else if (!isMcuProject && !action->isEnabled()) {
|
||||
action->setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DesignModeWidget::aboutToShowWorkspaces()
|
||||
{
|
||||
Core::ActionContainer *aci = Core::ActionManager::actionContainer(
|
||||
@@ -520,6 +552,9 @@ void DesignModeWidget::aboutToShowWorkspaces()
|
||||
action->setCheckable(true);
|
||||
if (workspace == *m_dockManager->activeWorkspace())
|
||||
action->setChecked(true);
|
||||
|
||||
if (currentDesignDocument() && currentDesignDocument()->isQtForMCUsProject())
|
||||
action->setEnabled(workspace.isMcusEnabled());
|
||||
}
|
||||
menu->addActions(ag->actions());
|
||||
}
|
||||
|
@@ -93,6 +93,7 @@ private:
|
||||
QWidget *createCenterWidget();
|
||||
QWidget *createCrumbleBarFrame();
|
||||
|
||||
void aboutToShowViews();
|
||||
void aboutToShowWorkspaces();
|
||||
|
||||
QPointer<QWidget> m_bottomSideBar;
|
||||
|
@@ -238,4 +238,17 @@ bool QmlProject::allowOnlySingleProject()
|
||||
return !settings->value(key, false).toBool();
|
||||
}
|
||||
|
||||
bool QmlProject::isMCUs()
|
||||
{
|
||||
if (!ProjectExplorer::ProjectManager::startupTarget())
|
||||
return false;
|
||||
|
||||
const QmlProjectManager::QmlBuildSystem *buildSystem
|
||||
= qobject_cast<QmlProjectManager::QmlBuildSystem *>(
|
||||
ProjectExplorer::ProjectManager::startupTarget()->buildSystem());
|
||||
QTC_ASSERT(buildSystem, return false);
|
||||
|
||||
return buildSystem && buildSystem->qtForMCUs();
|
||||
}
|
||||
|
||||
} // namespace QmlProjectManager
|
||||
|
@@ -24,6 +24,8 @@ public:
|
||||
|
||||
ProjectExplorer::Tasks projectIssues(const ProjectExplorer::Kit *k) const final;
|
||||
|
||||
static bool isMCUs();
|
||||
|
||||
protected:
|
||||
RestoreResult fromMap(const Utils::Store &map, QString *errorMessage) override;
|
||||
|
||||
|
Reference in New Issue
Block a user