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

View File

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

View File

@@ -51,7 +51,7 @@
#include <componentcore_constants.h>
#include <stylesheetmerger.h>
#include <limits>
#include <designermcumanager.h>
#include <qmldesignerplugin.h>
#include <coreplugin/messagebox.h>
@@ -88,6 +88,7 @@
#include <algorithm>
#include <functional>
#include <cmath>
#include <limits>
#include <bindingeditor/signallist.h>
@@ -187,7 +188,7 @@ void toFront(const SelectionContext &selectionState)
if (index != lastIndex)
parentProperty.slide(index, lastIndex);
}
} catch (const RewritingException &e) { //better save then sorry
} catch (const RewritingException &e) { //better safe than sorry
e.showException();
}
}
@@ -208,7 +209,7 @@ void toBack(const SelectionContext &selectionState)
parentProperty.slide(index, 0);
}
} catch (const RewritingException &e) { //better save then sorry
} catch (const RewritingException &e) { //better safe than sorry
e.showException();
}
}
@@ -272,7 +273,7 @@ void setVisible(const SelectionContext &selectionState)
try {
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();
}
}
@@ -285,7 +286,7 @@ void setFillWidth(const SelectionContext &selectionState)
try {
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();
}
}
@@ -298,7 +299,7 @@ void setFillHeight(const SelectionContext &selectionState)
try {
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();
}
}
@@ -522,9 +523,14 @@ void layoutFlowPositioner(const SelectionContext &selectionContext)
void layoutRowLayout(const SelectionContext &selectionContext)
{
try {
LayoutInGridLayout::ensureLayoutImport(selectionContext);
layoutHelperFunction(selectionContext, "QtQuick.Layouts.RowLayout", compareByX);
} catch (RewritingException &e) { //better save then sorry
if (DesignerMcuManager::instance().isMCUProject()) {
layoutHelperFunction(selectionContext, "QtQuick.Row", compareByX);
}
else {
LayoutInGridLayout::ensureLayoutImport(selectionContext);
layoutHelperFunction(selectionContext, "QtQuick.Layouts.RowLayout", compareByX);
}
} catch (RewritingException &e) { //better safe than sorry
e.showException();
}
}
@@ -532,9 +538,14 @@ void layoutRowLayout(const SelectionContext &selectionContext)
void layoutColumnLayout(const SelectionContext &selectionContext)
{
try {
LayoutInGridLayout::ensureLayoutImport(selectionContext);
layoutHelperFunction(selectionContext, "QtQuick.Layouts.ColumnLayout", compareByY);
} catch (RewritingException &e) { //better save then sorry
if (DesignerMcuManager::instance().isMCUProject()) {
layoutHelperFunction(selectionContext, "QtQuick.Column", compareByX);
}
else {
LayoutInGridLayout::ensureLayoutImport(selectionContext);
layoutHelperFunction(selectionContext, "QtQuick.Layouts.ColumnLayout", compareByY);
}
} catch (RewritingException &e) { //better safe than sorry
e.showException();
}
}
@@ -542,9 +553,16 @@ void layoutColumnLayout(const SelectionContext &selectionContext)
void layoutGridLayout(const SelectionContext &selectionContext)
{
try {
LayoutInGridLayout::ensureLayoutImport(selectionContext);
LayoutInGridLayout::layout(selectionContext);
} catch (RewritingException &e) { //better save then sorry
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::layout(selectionContext);
}
} catch (RewritingException &e) { //better safe than sorry
e.showException();
}
}