1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "eventlistutils.h"
#include <QApplication>
#include <QKeyEvent>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QTableView>
namespace QmlDesigner {
TabWalker::TabWalker(QObject *parent)
: QObject(parent)
{}
bool TabWalker::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
auto *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab) {
keyEvent->accept();
int mapped = keyEvent->key() == Qt::Key_Tab ? Qt::Key_Down : Qt::Key_Up;
int modifiers = keyEvent->nativeModifiers() & (~Qt::ShiftModifier);
QApplication::postEvent(obj,
new QKeyEvent(QEvent::KeyPress,
mapped,
static_cast<Qt::KeyboardModifier>(modifiers),
keyEvent->nativeScanCode(),
keyEvent->nativeVirtualKey(),
keyEvent->nativeModifiers(),
keyEvent->text(),
keyEvent->isAutoRepeat(),
keyEvent->count()));
return true;
}
}
return QObject::eventFilter(obj, event);
}
QStandardItemModel *sourceModel(QAbstractItemModel *model)
{
if (auto *proxy = qobject_cast<QSortFilterProxyModel *>(model))
return sourceModel(proxy->sourceModel());
return qobject_cast<QStandardItemModel *>(model);
}
QString uniqueName(QAbstractItemModel *model, const QString &base)
{
if (auto *m = sourceModel(model)) {
QList<QStandardItem *> items = m->findItems(base);
if (items.empty())
return base;
int idx = 0;
while (true) {
QString tmp = base + QString::number(idx++);
items = m->findItems(tmp);
if (items.empty())
return tmp;
}
}
return QString();
}
std::string toString(AbstractView::PropertyChangeFlags flags)
{
if (flags == 0)
return std::string("NoAdditionalChanges");
std::string out;
if ((flags & AbstractView::NoAdditionalChanges) != 0)
out += "NoAdditionalChanges ";
if ((flags & AbstractView::PropertiesAdded) != 0) {
if (!out.empty())
out += "| ";
out += "PropertiesAdded ";
}
if ((flags & AbstractView::EmptyPropertiesRemoved) != 0) {
if (!out.empty())
out += "| ";
out += "EmptyPropertiesRemoved ";
}
return out;
}
void polishPalette(QTableView *view, const QColor &selectionColor)
{
QPalette p = view->palette();
p.setColor(QPalette::AlternateBase, p.color(QPalette::Base).lighter(120));
p.setColor(QPalette::Highlight, selectionColor);
view->setPalette(p);
view->setAlternatingRowColors(true);
}
void printPropertyType(const ModelNode &node, const PropertyName &name)
{
std::string sname = name.toStdString();
auto prop = node.property(name);
if (prop.isNodeProperty())
printf("Property %s is a node-property\n", sname.c_str());
if (prop.isVariantProperty())
printf("Property %s is a variant-property\n", sname.c_str());
if (prop.isNodeListProperty())
printf("Property %s is a node-list-property\n", sname.c_str());
if (prop.isNodeAbstractProperty())
printf("Property %s is a node-abstract-property\n", sname.c_str());
if (prop.isBindingProperty())
printf("Property %s is a binding-property\n", sname.c_str());
if (prop.isSignalHandlerProperty())
printf("Property %s is a signal-handler-property\n", sname.c_str());
}
} // namespace QmlDesigner.
|