22#include <QStandardItem>
23#include <QApplication>
26#include <QContextMenuEvent>
27#include <QItemSelectionModel>
30#include <QMetaProperty>
53 lay->addWidget(&m_treeView);
56 &ObjectViewer::onSelectionChanged);
60 action = m_menu.
addAction(QStringLiteral(
"Dump Windows"));
63 action = m_menu.
addAction(QStringLiteral(
"Update"));
66 action = m_menu.
addAction(QStringLiteral(
"Print to png"));
69 action = m_menu.
addAction(QStringLiteral(
"Toggle Visible"));
73 action = m_menu.
addAction(QStringLiteral(
"Send WM_NCHITTEST"));
83 const auto hashCopy = m_itemMap;
84 for (
auto it = hashCopy.cbegin(), e = hashCopy.cend(); it != e; ++it)
89 const auto &topLevelWidgets = qApp->topLevelWidgets();
95void ObjectViewer::dumpSelectedWidgetToPng()
97 if (
auto w = selectedWidget()) {
100 px.save(QStringLiteral(
"px.png"));
105void ObjectViewer::updateSelectedWidget()
107 if (
auto w = selectedWidget())
111void ObjectViewer::toggleVisible()
113 if (
auto w = selectedWidget())
114 w->setVisible(!w->isVisible());
118void ObjectViewer::sendHitTest()
120 if (
auto w = selectedWidget()) {
121 qDebug() <<
"Sending hit test to" << w;
122 ::SendMessage(HWND(w->winId()), WM_NCHITTEST, 0, 0);
127void ObjectViewer::dumpWindows()
129 qDebug() <<
"Top Level QWidgets:";
130 const auto &topLevelWidgets = qApp->topLevelWidgets();
131 for (
QWidget *w : topLevelWidgets) {
132 if (qobject_cast<QMenu *>(w))
135 qDebug() <<
" QWidget=" << w;
138 qDebug() <<
"Top Level Windows:";
139 const auto &topLevelWindows = qGuiApp->topLevelWindows();
140 for (
QWindow *w : topLevelWindows) {
141 qDebug() <<
" QWindow=" << w <<
"; parent=" << w->parent()
142 <<
"; transientParent=" << w->transientParent() <<
"; hwnd=" << w->winId();
152 if (
auto w = qobject_cast<QWidget *>(o)) {
153 name += QStringLiteral(
" - %1,%2 %3x%4")
160 name += QStringLiteral(
" ;W");
161 if (w->window() !=
nullptr)
162 name += QStringLiteral(
" ;N");
170 if (obj ==
this || obj == &m_menu || obj ==
parentWidget() || !obj)
173 if (m_ignoreMenus && qobject_cast<QMenu *>(obj))
176 if (m_ignoreShortcuts && qobject_cast<QShortcut *>(obj))
179 if (m_ignoreToolBars && qobject_cast<QToolBar *>(obj))
186 m_itemMap.
insert(obj, item);
188 updateItemAppearence(item);
194void ObjectViewer::remove(
QObject *obj)
201void ObjectViewer::onSelectionChanged()
204 if (m_selectedObject == o)
207 if (m_selectedObject) {
208 m_selectedObject->removeEventFilter(
this);
209 if (
auto w = qobject_cast<QWidget *>(m_selectedObject))
213 m_selectedObject = o;
215 if (m_selectedObject) {
217 m_selectedObject->installEventFilter(
this);
218 if (m_highlightsWidget) {
219 if (
auto w = qobject_cast<QWidget *>(o))
225void ObjectViewer::printProperties(
QObject *obj)
const
227 qDebug() <<
"Printing properties for" << obj;
231 for (
int i = 0; i < count; ++i) {
233 qDebug() <<
" " << prop.
name() << prop.
read(obj);
236 if (
auto w = qobject_cast<QWidget *>(obj)) {
237 qDebug() <<
"Is a widget!";
238 qDebug() <<
"Window=" << w->window();
239 qDebug() <<
"flags=" << w->windowFlags();
240 qDebug() <<
"is native?" << (w->window() !=
nullptr);
244QObject *ObjectViewer::selectedObject()
const
247 if (indexes.isEmpty())
254QWidget *ObjectViewer::selectedWidget()
const
256 return qobject_cast<QWidget *>(selectedObject());
262 QWidget *widget = widgetForItem(item);
280 return qobject_cast<QWidget *>(objectForItem(item));
290 auto widget =
static_cast<QWidget *
>(watched);
292 updateItemAppearence(m_itemMap.
value(watched));
296 if (m_selectedObject != watched)
Tree Widget to show the object tree. Used for debugging only, for apps that don't support GammaRay.
QItemSelectionModel * selectionModel() const const
void triggered(bool checked)
QHash::iterator insert(const Key &key, const T &value)
int remove(const Key &key)
const T value(const Key &key) const const
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
QVariant data(int role) const const
const QObjectList & children() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void destroyed(QObject *obj)
void installEventFilter(QObject *filterObj)
QObject * parent() const const
void removeEventFilter(QObject *obj)
void fillRect(const QRectF &rectangle, const QBrush &brush)
virtual QVariant data(int role) const const
void setForeground(const QBrush &brush)
QStandardItem * invisibleRootItem() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
virtual void setModel(QAbstractItemModel *model) override
QVariant fromValue(const T &value)