QmlDesigner: Fix for Toolbar layout buttons in MCU

- Replaced QtQuick.Layout usage in Designer Toolbar buttons with regular
 QtQuick.Row and Column in qt for mcu mode
 - deactivated "Add GridLayout" button in qt for mcu mode
 - fix for assert while creating Grid Layout with Toolbar button
 - comments typos

Task-number: QDS-4641
Change-Id: I33520988fb7bf5f3193fb914de93054ff97c31b1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Aleksei German
2021-08-12 17:34:23 +02:00
parent 2e652405cd
commit f1b2be3e1d
3 changed files with 44 additions and 18 deletions

View File

@@ -27,6 +27,7 @@
#include "changestyleaction.h" #include "changestyleaction.h"
#include "designeractionmanagerview.h" #include "designeractionmanagerview.h"
#include "designermcumanager.h"
#include "formatoperation.h" #include "formatoperation.h"
#include "modelnodecontextmenu_helper.h" #include "modelnodecontextmenu_helper.h"
#include "qmldesignerconstants.h" #include "qmldesignerconstants.h"
@@ -633,6 +634,11 @@ bool selectionCanBeLayoutedAndQtQuickLayoutPossible(const SelectionContext &cont
return selectionCanBeLayouted(context) && context.view()->majorQtQuickVersion() > 1; return selectionCanBeLayouted(context) && context.view()->majorQtQuickVersion() > 1;
} }
bool selectionCanBeLayoutedAndQtQuickLayoutPossibleAndNotMCU(const SelectionContext &context)
{
return selectionCanBeLayoutedAndQtQuickLayoutPossible(context) && !DesignerMcuManager::instance().isMCUProject();
}
bool selectionNotEmptyAndHasZProperty(const SelectionContext &context) bool selectionNotEmptyAndHasZProperty(const SelectionContext &context)
{ {
return selectionNotEmpty(context) && selectionHasProperty(context, zProperty); return selectionNotEmpty(context) && selectionHasProperty(context, zProperty);
@@ -1360,7 +1366,7 @@ void DesignerActionManager::createDefaultDesignerActions()
QKeySequence("shift+g"), QKeySequence("shift+g"),
60, 60,
&layoutGridLayout, &layoutGridLayout,
&selectionCanBeLayoutedAndQtQuickLayoutPossible)); &selectionCanBeLayoutedAndQtQuickLayoutPossibleAndNotMCU));
addDesignerAction(new SeperatorDesignerAction(layoutCategory, 50)); addDesignerAction(new SeperatorDesignerAction(layoutCategory, 50));

View File

@@ -325,7 +325,9 @@ void LayoutInGridLayout::calculateGridOffsets()
removeSimilarValues(m_yTopOffsets, heightTolerance); removeSimilarValues(m_yTopOffsets, heightTolerance);
//The first offset is not important, because it just defines the beginning of the layout //The first offset is not important, because it just defines the beginning of the layout
if (!m_xTopOffsets.isEmpty())
m_xTopOffsets.removeFirst(); m_xTopOffsets.removeFirst();
if (!m_yTopOffsets.isEmpty())
m_yTopOffsets.removeFirst(); m_yTopOffsets.removeFirst();
} }

View File

@@ -51,7 +51,7 @@
#include <componentcore_constants.h> #include <componentcore_constants.h>
#include <stylesheetmerger.h> #include <stylesheetmerger.h>
#include <limits> #include <designermcumanager.h>
#include <qmldesignerplugin.h> #include <qmldesignerplugin.h>
#include <coreplugin/messagebox.h> #include <coreplugin/messagebox.h>
@@ -88,6 +88,7 @@
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <cmath> #include <cmath>
#include <limits>
#include <bindingeditor/signallist.h> #include <bindingeditor/signallist.h>
@@ -187,7 +188,7 @@ void toFront(const SelectionContext &selectionState)
if (index != lastIndex) if (index != lastIndex)
parentProperty.slide(index, lastIndex); parentProperty.slide(index, lastIndex);
} }
} catch (const RewritingException &e) { //better save then sorry } catch (const RewritingException &e) { //better safe than sorry
e.showException(); e.showException();
} }
} }
@@ -208,7 +209,7 @@ void toBack(const SelectionContext &selectionState)
parentProperty.slide(index, 0); parentProperty.slide(index, 0);
} }
} catch (const RewritingException &e) { //better save then sorry } catch (const RewritingException &e) { //better safe than sorry
e.showException(); e.showException();
} }
} }
@@ -272,7 +273,7 @@ void setVisible(const SelectionContext &selectionState)
try { try {
selectionState.selectedModelNodes().constFirst().variantProperty("visible").setValue(selectionState.toggled()); selectionState.selectedModelNodes().constFirst().variantProperty("visible").setValue(selectionState.toggled());
} catch (const RewritingException &e) { //better save then sorry } catch (const RewritingException &e) { //better safe than sorry
e.showException(); e.showException();
} }
} }
@@ -285,7 +286,7 @@ void setFillWidth(const SelectionContext &selectionState)
try { try {
selectionState.firstSelectedModelNode().variantProperty("Layout.fillWidth").setValue(selectionState.toggled()); selectionState.firstSelectedModelNode().variantProperty("Layout.fillWidth").setValue(selectionState.toggled());
} catch (const RewritingException &e) { //better save then sorry } catch (const RewritingException &e) { //better safe than sorry
e.showException(); e.showException();
} }
} }
@@ -298,7 +299,7 @@ void setFillHeight(const SelectionContext &selectionState)
try { try {
selectionState.firstSelectedModelNode().variantProperty("Layout.fillHeight").setValue(selectionState.toggled()); selectionState.firstSelectedModelNode().variantProperty("Layout.fillHeight").setValue(selectionState.toggled());
} catch (const RewritingException &e) { //better save then sorry } catch (const RewritingException &e) { //better safe than sorry
e.showException(); e.showException();
} }
} }
@@ -522,9 +523,14 @@ void layoutFlowPositioner(const SelectionContext &selectionContext)
void layoutRowLayout(const SelectionContext &selectionContext) void layoutRowLayout(const SelectionContext &selectionContext)
{ {
try { try {
if (DesignerMcuManager::instance().isMCUProject()) {
layoutHelperFunction(selectionContext, "QtQuick.Row", compareByX);
}
else {
LayoutInGridLayout::ensureLayoutImport(selectionContext); LayoutInGridLayout::ensureLayoutImport(selectionContext);
layoutHelperFunction(selectionContext, "QtQuick.Layouts.RowLayout", compareByX); layoutHelperFunction(selectionContext, "QtQuick.Layouts.RowLayout", compareByX);
} catch (RewritingException &e) { //better save then sorry }
} catch (RewritingException &e) { //better safe than sorry
e.showException(); e.showException();
} }
} }
@@ -532,9 +538,14 @@ void layoutRowLayout(const SelectionContext &selectionContext)
void layoutColumnLayout(const SelectionContext &selectionContext) void layoutColumnLayout(const SelectionContext &selectionContext)
{ {
try { try {
if (DesignerMcuManager::instance().isMCUProject()) {
layoutHelperFunction(selectionContext, "QtQuick.Column", compareByX);
}
else {
LayoutInGridLayout::ensureLayoutImport(selectionContext); LayoutInGridLayout::ensureLayoutImport(selectionContext);
layoutHelperFunction(selectionContext, "QtQuick.Layouts.ColumnLayout", compareByY); layoutHelperFunction(selectionContext, "QtQuick.Layouts.ColumnLayout", compareByY);
} catch (RewritingException &e) { //better save then sorry }
} catch (RewritingException &e) { //better safe than sorry
e.showException(); e.showException();
} }
} }
@@ -542,9 +553,16 @@ void layoutColumnLayout(const SelectionContext &selectionContext)
void layoutGridLayout(const SelectionContext &selectionContext) void layoutGridLayout(const SelectionContext &selectionContext)
{ {
try { try {
Q_ASSERT(!DesignerMcuManager::instance().isMCUProject()); //remove this line when grids are finally supported
if (DesignerMcuManager::instance().isMCUProject()) {
//qt for mcu doesn't support any grids yet
}
else {
LayoutInGridLayout::ensureLayoutImport(selectionContext); LayoutInGridLayout::ensureLayoutImport(selectionContext);
LayoutInGridLayout::layout(selectionContext); LayoutInGridLayout::layout(selectionContext);
} catch (RewritingException &e) { //better save then sorry }
} catch (RewritingException &e) { //better safe than sorry
e.showException(); e.showException();
} }
} }