Commit 877f9081 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Add more selection functions in SelectionContext



It is much smarter to use the view functions instead of generating the whole
list and pick the first item or ask if the list is empty.

Change-Id: Ifcd40784ddab75c505b5f7f2dfc7b11cbd11c69d
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 4b3e3aaa
......@@ -151,7 +151,7 @@ void toFront(const SelectionContext &selectionState)
return;
try {
QmlItemNode node = selectionState.selectedModelNodes().first();
QmlItemNode node = selectionState.firstSelectedModelNode();
if (node.isValid()) {
signed int maximumZ = getMaxZValue(siblingsForNode(node));
maximumZ++;
......@@ -168,7 +168,7 @@ void toBack(const SelectionContext &selectionState)
if (!selectionState.view())
return;
try {
QmlItemNode node = selectionState.selectedModelNodes().first();
QmlItemNode node = selectionState.firstSelectedModelNode();
if (node.isValid()) {
signed int minimumZ = getMinZValue(siblingsForNode(node));
minimumZ--;
......@@ -248,11 +248,11 @@ void setVisible(const SelectionContext &selectionState)
void setFillWidth(const SelectionContext &selectionState)
{
if (!selectionState.view()
|| selectionState.selectedModelNodes().isEmpty())
|| !selectionState.hasSingleSelectedModelNode())
return;
try {
selectionState.selectedModelNodes().first().variantProperty("Layout.fillWidth").setValue(selectionState.toggled());
selectionState.firstSelectedModelNode().variantProperty("Layout.fillWidth").setValue(selectionState.toggled());
} catch (RewritingException &e) { //better save then sorry
QMessageBox::warning(0, "Error", e.description());
}
......@@ -261,11 +261,11 @@ void setFillWidth(const SelectionContext &selectionState)
void setFillHeight(const SelectionContext &selectionState)
{
if (!selectionState.view()
|| selectionState.selectedModelNodes().isEmpty())
|| !selectionState.hasSingleSelectedModelNode())
return;
try {
selectionState.selectedModelNodes().first().variantProperty("Layout.fillHeight").setValue(selectionState.toggled());
selectionState.firstSelectedModelNode().variantProperty("Layout.fillHeight").setValue(selectionState.toggled());
} catch (RewritingException &e) { //better save then sorry
QMessageBox::warning(0, "Error", e.description());
}
......@@ -623,7 +623,7 @@ void layoutFlowPositioner(const SelectionContext &selectionState)
void layoutRowLayout(const SelectionContext &selectionState)
{
if (!selectionState.view()
|| selectionState.selectedModelNodes().isEmpty())
|| !selectionState.hasSingleSelectedModelNode())
return;
static TypeName rowLayoutType = "QtQuick.Layouts.RowLayout";
......@@ -671,7 +671,7 @@ void layoutRowLayout(const SelectionContext &selectionState)
void layoutColumnLayout(const SelectionContext &selectionState)
{
if (!selectionState.view()
|| selectionState.selectedModelNodes().isEmpty())
|| !selectionState.hasSingleSelectedModelNode())
return;
static TypeName columnLayoutType = "QtQuick.Layouts.ColumnLayout";
......@@ -719,7 +719,7 @@ void layoutColumnLayout(const SelectionContext &selectionState)
void layoutGridLayout(const SelectionContext &selectionState)
{
if (!selectionState.view()
|| selectionState.selectedModelNodes().isEmpty())
|| !selectionState.hasSingleSelectedModelNode())
return;
static TypeName gridLayoutType = "QtQuick.Layouts.GridLayout";
......
......@@ -69,11 +69,21 @@ ModelNode SelectionContext::currentSingleSelectedNode() const
return view()->singleSelectedModelNode();
}
ModelNode SelectionContext::firstSelectedModelNode() const
{
return view()->firstSelectedModelNode();
}
QList<ModelNode> SelectionContext::selectedModelNodes() const
{
return view()->selectedModelNodes();
}
bool SelectionContext::hasSingleSelectedModelNode() const
{
return view()->hasSelectedModelNodes();
}
AbstractView *SelectionContext::view() const
{
return m_view.data();
......
......@@ -48,7 +48,9 @@ public:
bool isInBaseState() const;
ModelNode currentSingleSelectedNode() const;
ModelNode firstSelectedModelNode() const;
QList<ModelNode> selectedModelNodes() const;
bool hasSingleSelectedModelNode() const;
AbstractView *view() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment