forked from qt-creator/qt-creator
QmlDesigner: Improve raise and lower actions
Adjusting the z property is not what users frequently require. Instead we change the node order. Change-Id: Id98ea1ca28aa7b1ea2ccf56931e049f94c106369 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "modelnodecontextmenu_helper.h"
|
||||
#include <bindingproperty.h>
|
||||
#include <nodeproperty.h>
|
||||
#include <nodelistproperty.h>
|
||||
#include <nodehints.h>
|
||||
#include <nodemetainfo.h>
|
||||
#include "designeractionmanagerview.h"
|
||||
@@ -560,12 +561,55 @@ bool singleSelectedAndUiFile(const SelectionContext &context)
|
||||
== QLatin1String("ui.qml");
|
||||
}
|
||||
|
||||
bool lowerAvailable(const SelectionContext &selectionState)
|
||||
{
|
||||
if (!singleSelection(selectionState))
|
||||
return false;
|
||||
|
||||
ModelNode modelNode = selectionState.currentSingleSelectedNode();
|
||||
|
||||
if (modelNode.isRootNode())
|
||||
return false;
|
||||
|
||||
if (!modelNode.parentProperty().isNodeListProperty())
|
||||
return false;
|
||||
|
||||
NodeListProperty parentProperty = modelNode.parentProperty().toNodeListProperty();
|
||||
return parentProperty.indexOf(modelNode) > 0;
|
||||
}
|
||||
|
||||
bool raiseAvailable(const SelectionContext &selectionState)
|
||||
{
|
||||
if (!singleSelection(selectionState))
|
||||
return false;
|
||||
|
||||
ModelNode modelNode = selectionState.currentSingleSelectedNode();
|
||||
|
||||
if (modelNode.isRootNode())
|
||||
return false;
|
||||
|
||||
if (!modelNode.parentProperty().isNodeListProperty())
|
||||
return false;
|
||||
|
||||
NodeListProperty parentProperty = modelNode.parentProperty().toNodeListProperty();
|
||||
return parentProperty.indexOf(modelNode) < parentProperty.count() - 1;
|
||||
}
|
||||
|
||||
void DesignerActionManager::createDefaultDesignerActions()
|
||||
{
|
||||
using namespace SelectionContextFunctors;
|
||||
using namespace ComponentCoreConstants;
|
||||
using namespace ModelNodeOperations;
|
||||
|
||||
const Utils::Icon prevIcon({
|
||||
{QLatin1String(":/utils/images/prev.png"), Utils::Theme::QmlDesigner_FormEditorForegroundColor}}, Utils::Icon::MenuTintedStyle);
|
||||
|
||||
const Utils::Icon nextIcon({
|
||||
{QLatin1String(":/utils/images/next.png"), Utils::Theme::QmlDesigner_FormEditorForegroundColor}}, Utils::Icon::MenuTintedStyle);
|
||||
|
||||
const Utils::Icon addIcon({
|
||||
{QLatin1String(":/utils/images/plus.png"), Utils::Theme::QmlDesigner_FormEditorForegroundColor}}, Utils::Icon::MenuTintedStyle);
|
||||
|
||||
addDesignerAction(new SelectionModelNodeAction(
|
||||
selectionCategoryDisplayName,
|
||||
selectionCategory,
|
||||
@@ -600,10 +644,10 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
Utils::Icon({{":/qmldesigner/icon/designeractions/images/lower.png", Utils::Theme::IconsBaseColor}}).icon(),
|
||||
raiseToolTip,
|
||||
stackCategory,
|
||||
QKeySequence("Ctrl+Up"),
|
||||
QKeySequence(),
|
||||
160,
|
||||
&raise,
|
||||
&selectionNotEmpty));
|
||||
&raiseAvailable));
|
||||
|
||||
addDesignerAction(new ModelNodeAction(
|
||||
lowerCommandId,
|
||||
@@ -611,10 +655,10 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
Utils::Icon({{":/qmldesigner/icon/designeractions/images/raise.png", Utils::Theme::IconsBaseColor}}).icon(),
|
||||
lowerToolTip,
|
||||
stackCategory,
|
||||
QKeySequence("Ctrl+Down"),
|
||||
QKeySequence(),
|
||||
140,
|
||||
&lower,
|
||||
&selectionNotEmpty));
|
||||
&lowerAvailable));
|
||||
|
||||
addDesignerAction(new SeperatorDesignerAction(stackCategory, 120));
|
||||
|
||||
@@ -775,16 +819,6 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
&isLayout,
|
||||
&isLayout));
|
||||
|
||||
const Utils::Icon prevIcon({
|
||||
{QLatin1String(":/utils/images/prev.png"), Utils::Theme::QmlDesigner_FormEditorForegroundColor}}, Utils::Icon::MenuTintedStyle);
|
||||
|
||||
const Utils::Icon nextIcon({
|
||||
{QLatin1String(":/utils/images/next.png"), Utils::Theme::QmlDesigner_FormEditorForegroundColor}}, Utils::Icon::MenuTintedStyle);
|
||||
|
||||
const Utils::Icon addIcon({
|
||||
{QLatin1String(":/utils/images/plus.png"), Utils::Theme::QmlDesigner_FormEditorForegroundColor}}, Utils::Icon::MenuTintedStyle);
|
||||
|
||||
|
||||
addDesignerAction(new ModelNodeFormEditorAction(
|
||||
addItemToStackedContainerCommandId,
|
||||
addItemToStackedContainerDisplayName,
|
||||
@@ -848,7 +882,7 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
Utils::Icon({{":/qmldesigner/icon/designeractions/images/column.png", Utils::Theme::IconsBaseColor}}).icon(),
|
||||
layoutColumnLayoutToolTip,
|
||||
layoutCategory,
|
||||
QKeySequence("Ctrl+i"),
|
||||
QKeySequence("Ctrl+l"),
|
||||
80,
|
||||
&layoutColumnLayout,
|
||||
&selectionCanBeLayoutedAndQtQuickLayoutPossible));
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "addsignalhandlerdialog.h"
|
||||
|
||||
#include <bindingproperty.h>
|
||||
#include <nodeabstractproperty.h>
|
||||
#include <nodelistproperty.h>
|
||||
#include <nodehints.h>
|
||||
#include <nodemetainfo.h>
|
||||
#include <modelnode.h>
|
||||
@@ -219,47 +219,52 @@ void toBack(const SelectionContext &selectionState)
|
||||
}
|
||||
}
|
||||
|
||||
void raise(const SelectionContext &selectionState)
|
||||
enum OderAction {RaiseItem, LowerItem};
|
||||
|
||||
void changeOrder(const SelectionContext &selectionState, OderAction orderAction)
|
||||
{
|
||||
if (!selectionState.view())
|
||||
return;
|
||||
|
||||
QTC_ASSERT(selectionState.singleNodeIsSelected(), return);
|
||||
ModelNode modelNode = selectionState.currentSingleSelectedNode();
|
||||
|
||||
if (modelNode.isRootNode())
|
||||
return;
|
||||
if (!modelNode.parentProperty().isNodeListProperty())
|
||||
return;
|
||||
|
||||
try {
|
||||
RewriterTransaction transaction(selectionState.view(), QByteArrayLiteral("DesignerActionManager|raise"));
|
||||
foreach (ModelNode modelNode, selectionState.selectedModelNodes()) {
|
||||
QmlItemNode node = modelNode;
|
||||
if (node.isValid()) {
|
||||
signed int z = node.instanceValue("z").toInt();
|
||||
z++;
|
||||
node.setVariantProperty("z", z);
|
||||
}
|
||||
|
||||
ModelNode modelNode = selectionState.currentSingleSelectedNode();
|
||||
NodeListProperty parentProperty = modelNode.parentProperty().toNodeListProperty();
|
||||
const int index = parentProperty.indexOf(modelNode);
|
||||
|
||||
if (orderAction == RaiseItem) {
|
||||
|
||||
if (index < parentProperty.count() - 1)
|
||||
parentProperty.slide(index, index + 1);
|
||||
} else if (orderAction == LowerItem) {
|
||||
if (index > 0)
|
||||
parentProperty.slide(index, index - 1);
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
} catch (const RewritingException &e) { //better save then sorry
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
void raise(const SelectionContext &selectionState)
|
||||
{
|
||||
changeOrder(selectionState, RaiseItem);
|
||||
}
|
||||
|
||||
void lower(const SelectionContext &selectionState)
|
||||
{
|
||||
|
||||
if (!selectionState.view())
|
||||
return;
|
||||
|
||||
try {
|
||||
RewriterTransaction transaction(selectionState.view(), QByteArrayLiteral("DesignerActionManager|lower"));
|
||||
foreach (ModelNode modelNode, selectionState.selectedModelNodes()) {
|
||||
QmlItemNode node = modelNode;
|
||||
if (node.isValid()) {
|
||||
signed int z = node.instanceValue("z").toInt();
|
||||
z--;
|
||||
node.setVariantProperty("z", z);
|
||||
}
|
||||
}
|
||||
transaction.commit();
|
||||
} catch (const RewritingException &e) { //better save then sorry
|
||||
e.showException();
|
||||
}
|
||||
changeOrder(selectionState, LowerItem);
|
||||
}
|
||||
|
||||
void paste(const SelectionContext &)
|
||||
|
||||
Reference in New Issue
Block a user