UI fixes to QML inspector

This commit is contained in:
Lasse Holmstedt
2010-04-16 10:20:01 +02:00
parent 5921289580
commit ae8a8a5c84
7 changed files with 119 additions and 35 deletions

View File

@@ -84,7 +84,7 @@ ExpressionQueryWidget::ExpressionQueryWidget(Mode mode, QDeclarativeEngineDebug
Utils::StyledBar *bar = new Utils::StyledBar; Utils::StyledBar *bar = new Utils::StyledBar;
m_lineEdit = new Utils::FilterLineEdit; m_lineEdit = new Utils::FilterLineEdit;
m_lineEdit->setPlaceholderText(tr("<Expression>")); m_lineEdit->setPlaceholderText(tr("<Type expression to evaluate>"));
m_lineEdit->setToolTip(tr("Write and evaluate QtScript expressions.")); m_lineEdit->setToolTip(tr("Write and evaluate QtScript expressions."));
m_clearButton = new QToolButton(); m_clearButton = new QToolButton();
@@ -119,7 +119,7 @@ void ExpressionQueryWidget::changeContextHelpId(const QString &)
void ExpressionQueryWidget::clearTextEditor() void ExpressionQueryWidget::clearTextEditor()
{ {
m_textEdit->clear(); m_textEdit->clear();
m_textEdit->appendPlainText(tr("Debug Console\n")); m_textEdit->appendPlainText(tr("Script Console\n"));
} }
void ExpressionQueryWidget::setFontSettings() void ExpressionQueryWidget::setFontSettings()

View File

@@ -34,6 +34,9 @@
#include <QtGui/QTreeWidget> #include <QtGui/QTreeWidget>
#include <QtGui/QLayout> #include <QtGui/QLayout>
#include <QtGui/QHeaderView> #include <QtGui/QHeaderView>
#include <QtGui/QMenu>
#include <QtGui/QContextMenuEvent>
namespace Qml { namespace Qml {
namespace Internal { namespace Internal {
@@ -68,7 +71,7 @@ ObjectPropertiesView::ObjectPropertiesView(QDeclarativeEngineDebug *client, QWid
: QWidget(parent), : QWidget(parent),
m_client(client), m_client(client),
m_query(0), m_query(0),
m_watch(0) m_watch(0), m_clickedItem(0)
{ {
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
@@ -83,9 +86,14 @@ ObjectPropertiesView::ObjectPropertiesView(QDeclarativeEngineDebug *client, QWid
m_tree->setHeaderLabels(QStringList() m_tree->setHeaderLabels(QStringList()
<< tr("Name") << tr("Value") << tr("Type")); << tr("Name") << tr("Value") << tr("Type"));
QObject::connect(m_tree, SIGNAL(itemActivated(QTreeWidgetItem *, int)), QObject::connect(m_tree, SIGNAL(itemActivated(QTreeWidgetItem *, int)),
this, SLOT(itemActivated(QTreeWidgetItem *))); this, SLOT(itemDoubleClicked(QTreeWidgetItem *, int)));
connect(m_tree, SIGNAL(itemSelectionChanged()), SLOT(changeItemSelection())); connect(m_tree, SIGNAL(itemSelectionChanged()), SLOT(changeItemSelection()));
m_addWatchAction = new QAction(tr("Watch expression"), this);
m_removeWatchAction = new QAction(tr("Remove watch"), this);
connect(m_addWatchAction, SIGNAL(triggered()), SLOT(addWatch()));
connect(m_removeWatchAction, SIGNAL(triggered()), SLOT(removeWatch()));
m_tree->setColumnCount(3); m_tree->setColumnCount(3);
m_tree->header()->setDefaultSectionSize(150); m_tree->header()->setDefaultSectionSize(150);
@@ -250,6 +258,11 @@ void ObjectPropertiesView::setWatched(const QString &property, bool watched)
} }
} }
bool ObjectPropertiesView::isWatched(QTreeWidgetItem *item)
{
return item->font(0).bold();
}
void ObjectPropertiesView::valueChanged(const QByteArray &name, const QVariant &value) void ObjectPropertiesView::valueChanged(const QByteArray &name, const QVariant &value)
{ {
for (int i=0; i<m_tree->topLevelItemCount(); ++i) { for (int i=0; i<m_tree->topLevelItemCount(); ++i) {
@@ -261,14 +274,51 @@ void ObjectPropertiesView::valueChanged(const QByteArray &name, const QVariant &
} }
} }
void ObjectPropertiesView::itemActivated(QTreeWidgetItem *i) void ObjectPropertiesView::itemDoubleClicked(QTreeWidgetItem *item, int /*column*/)
{ {
PropertiesViewItem *item = static_cast<PropertiesViewItem *>(i); toggleWatch(item);
if (!item->property.name().isEmpty())
emit activated(m_object, item->property);
} }
void ObjectPropertiesView::addWatch()
{
toggleWatch(m_clickedItem);
} }
void ObjectPropertiesView::removeWatch()
{
toggleWatch(m_clickedItem);
} }
void ObjectPropertiesView::toggleWatch(QTreeWidgetItem *item)
{
if (!item)
return;
PropertiesViewItem *propItem = static_cast<PropertiesViewItem *>(item);
if (!propItem->property.name().isEmpty())
emit watchToggleRequested(m_object, propItem->property);
}
void ObjectPropertiesView::contextMenuEvent(QContextMenuEvent *event)
{
m_clickedItem = m_tree->itemAt(QPoint(event->pos().x(),
event->pos().y() - m_tree->header()->height()));
if (!m_clickedItem)
return;
PropertiesViewItem *propItem = static_cast<PropertiesViewItem *>(m_clickedItem);
QMenu menu;
if (!isWatched(m_clickedItem)) {
m_addWatchAction->setText(tr("Watch expression '%1'").arg(propItem->property.name()));
menu.addAction(m_addWatchAction);
} else {
menu.addAction(m_removeWatchAction);
}
menu.exec(event->globalPos());
}
} // Internal
} // Qml
#include "objectpropertiesview.moc" #include "objectpropertiesview.moc"

View File

@@ -56,22 +56,30 @@ public:
void clear(); void clear();
signals: signals:
void activated(const QDeclarativeDebugObjectReference &, const QDeclarativeDebugPropertyReference &); void watchToggleRequested(const QDeclarativeDebugObjectReference &, const QDeclarativeDebugPropertyReference &);
void contextHelpIdChanged(const QString &contextHelpId); void contextHelpIdChanged(const QString &contextHelpId);
public slots: public slots:
void reload(const QDeclarativeDebugObjectReference &); void reload(const QDeclarativeDebugObjectReference &);
void watchCreated(QDeclarativeDebugWatch *); void watchCreated(QDeclarativeDebugWatch *);
protected:
void contextMenuEvent(QContextMenuEvent *);
private slots: private slots:
void changeItemSelection(); void changeItemSelection();
void queryFinished(); void queryFinished();
void watchStateChanged(); void watchStateChanged();
void valueChanged(const QByteArray &name, const QVariant &value); void valueChanged(const QByteArray &name, const QVariant &value);
void itemActivated(QTreeWidgetItem *i); void itemDoubleClicked(QTreeWidgetItem *i, int column);
void addWatch();
void removeWatch();
private: private:
void toggleWatch(QTreeWidgetItem *item);
void setObject(const QDeclarativeDebugObjectReference &object); void setObject(const QDeclarativeDebugObjectReference &object);
bool isWatched(QTreeWidgetItem *item);
void setWatched(const QString &property, bool watched); void setWatched(const QString &property, bool watched);
void setPropertyValue(PropertiesViewItem *item, const QVariant &value, bool makeGray); void setPropertyValue(PropertiesViewItem *item, const QVariant &value, bool makeGray);
@@ -79,6 +87,10 @@ private:
QDeclarativeDebugObjectQuery *m_query; QDeclarativeDebugObjectQuery *m_query;
QDeclarativeDebugWatch *m_watch; QDeclarativeDebugWatch *m_watch;
QAction *m_addWatchAction;
QAction *m_removeWatchAction;
QTreeWidgetItem *m_clickedItem;
QTreeWidget *m_tree; QTreeWidget *m_tree;
QDeclarativeDebugObjectReference m_object; QDeclarativeDebugObjectReference m_object;
}; };

View File

@@ -94,6 +94,7 @@ void WatchTableModel::removeWatch(QDeclarativeDebugWatch *watch)
m_entities.takeAt(column); m_entities.takeAt(column);
reset(); reset();
emit watchRemoved();
} }
void WatchTableModel::updateWatch(QDeclarativeDebugWatch *watch, const QVariant &value) void WatchTableModel::updateWatch(QDeclarativeDebugWatch *watch, const QVariant &value)
@@ -274,6 +275,7 @@ void WatchTableModel::removeAllWatches()
} }
m_entities.clear(); m_entities.clear();
reset(); reset();
emit watchRemoved();
} }
//---------------------------------------------- //----------------------------------------------
@@ -303,7 +305,7 @@ WatchTableView::WatchTableView(WatchTableModel *model, QWidget *parent)
setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed); setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
setFrameStyle(QFrame::NoFrame); setFrameStyle(QFrame::NoFrame);
connect(model, SIGNAL(watchRemoved()), SLOT(watchRemoved()));
connect(model, SIGNAL(watchCreated(QDeclarativeDebugWatch*)), SLOT(watchCreated(QDeclarativeDebugWatch*))); connect(model, SIGNAL(watchCreated(QDeclarativeDebugWatch*)), SLOT(watchCreated(QDeclarativeDebugWatch*)));
connect(this, SIGNAL(activated(QModelIndex)), SLOT(indexActivated(QModelIndex))); connect(this, SIGNAL(activated(QModelIndex)), SLOT(indexActivated(QModelIndex)));
} }
@@ -320,6 +322,9 @@ void WatchTableView::watchCreated(QDeclarativeDebugWatch *watch)
int row = m_model->rowForWatch(watch); int row = m_model->rowForWatch(watch);
resizeRowToContents(row); resizeRowToContents(row);
resizeColumnToContents(C_NAME); resizeColumnToContents(C_NAME);
if (!isVisible())
show();
} }
void WatchTableView::mousePressEvent(QMouseEvent *me) void WatchTableView::mousePressEvent(QMouseEvent *me)
@@ -332,12 +337,27 @@ void WatchTableView::mousePressEvent(QMouseEvent *me)
QAction action(tr("Stop watching"), 0); QAction action(tr("Stop watching"), 0);
QList<QAction *> actions; QList<QAction *> actions;
actions << &action; actions << &action;
if (QMenu::exec(actions, me->globalPos())) if (QMenu::exec(actions, me->globalPos())) {
m_model->removeWatchAt(row); m_model->removeWatchAt(row);
hideIfEmpty();
}
} }
} }
} }
void WatchTableView::hideIfEmpty()
{
if (m_model->rowCount() == 0) {
hide();
} else if (!isVisible())
show();
}
void WatchTableView::watchRemoved()
{
hideIfEmpty();
}
} // Internal } // Internal
} // Qml } // Qml

View File

@@ -74,6 +74,7 @@ public:
signals: signals:
void watchCreated(QDeclarativeDebugWatch *watch); void watchCreated(QDeclarativeDebugWatch *watch);
void watchRemoved();
public slots: public slots:
void togglePropertyWatch(const QDeclarativeDebugObjectReference &obj, const QDeclarativeDebugPropertyReference &prop); void togglePropertyWatch(const QDeclarativeDebugObjectReference &obj, const QDeclarativeDebugPropertyReference &prop);
@@ -130,7 +131,9 @@ protected:
private slots: private slots:
void indexActivated(const QModelIndex &index); void indexActivated(const QModelIndex &index);
void watchCreated(QDeclarativeDebugWatch *watch); void watchCreated(QDeclarativeDebugWatch *watch);
void watchRemoved();
private:
void hideIfEmpty();
private: private:
WatchTableModel *m_model; WatchTableModel *m_model;
}; };

View File

@@ -185,9 +185,9 @@ QmlInspector::QmlInspector(QObject *parent)
m_objectTreeWidget = new Internal::ObjectTree; m_objectTreeWidget = new Internal::ObjectTree;
m_propertiesWidget = new Internal::ObjectPropertiesView; m_propertiesWidget = new Internal::ObjectPropertiesView;
m_watchTableView = new Internal::WatchTableView(m_watchTableModel); m_watchTableView = new Internal::WatchTableView(m_watchTableModel);
m_expressionWidget = new Internal::ExpressionQueryWidget(Internal::ExpressionQueryWidget::SeparateEntryMode);
// m_frameRateWidget = new Internal::CanvasFrameRate; // m_frameRateWidget = new Internal::CanvasFrameRate;
// m_frameRateWidget->setObjectName(QLatin1String("QmlDebugFrameRate")); // m_frameRateWidget->setObjectName(QLatin1String("QmlDebugFrameRate"));
m_expressionWidget = new Internal::ExpressionQueryWidget(Internal::ExpressionQueryWidget::SeparateEntryMode);
connect(m_connectionTimer, SIGNAL(timeout()), SLOT(pollInspector())); connect(m_connectionTimer, SIGNAL(timeout()), SLOT(pollInspector()));
} }
@@ -383,7 +383,7 @@ void QmlInspector::createDockWidgets()
connect(m_objectTreeWidget, SIGNAL(expressionWatchRequested(QDeclarativeDebugObjectReference,QString)), connect(m_objectTreeWidget, SIGNAL(expressionWatchRequested(QDeclarativeDebugObjectReference,QString)),
m_watchTableModel, SLOT(expressionWatchRequested(QDeclarativeDebugObjectReference,QString))); m_watchTableModel, SLOT(expressionWatchRequested(QDeclarativeDebugObjectReference,QString)));
connect(m_propertiesWidget, SIGNAL(activated(QDeclarativeDebugObjectReference,QDeclarativeDebugPropertyReference)), connect(m_propertiesWidget, SIGNAL(watchToggleRequested(QDeclarativeDebugObjectReference,QDeclarativeDebugPropertyReference)),
m_watchTableModel, SLOT(togglePropertyWatch(QDeclarativeDebugObjectReference,QDeclarativeDebugPropertyReference))); m_watchTableModel, SLOT(togglePropertyWatch(QDeclarativeDebugObjectReference,QDeclarativeDebugPropertyReference)));
connect(m_watchTableModel, SIGNAL(watchCreated(QDeclarativeDebugWatch*)), connect(m_watchTableModel, SIGNAL(watchCreated(QDeclarativeDebugWatch*)),
@@ -399,42 +399,39 @@ void QmlInspector::createDockWidgets()
m_expressionWidget, SLOT(setCurrentObject(QDeclarativeDebugObjectReference))); m_expressionWidget, SLOT(setCurrentObject(QDeclarativeDebugObjectReference)));
Core::MiniSplitter *leftSplitter = new Core::MiniSplitter(Qt::Vertical); Core::MiniSplitter *propSplitter = new Core::MiniSplitter(Qt::Vertical);
leftSplitter->addWidget(m_propertiesWidget); propSplitter->addWidget(m_propertiesWidget);
leftSplitter->addWidget(m_watchTableView); propSplitter->addWidget(m_watchTableView);
leftSplitter->setStretchFactor(0, 2);
leftSplitter->setStretchFactor(1, 1);
Core::MiniSplitter *propSplitter = new Core::MiniSplitter(Qt::Horizontal);
propSplitter->setObjectName(QLatin1String("QmlDebugProperties"));
propSplitter->addWidget(leftSplitter);
propSplitter->addWidget(m_expressionWidget);
propSplitter->setStretchFactor(0, 2); propSplitter->setStretchFactor(0, 2);
propSplitter->setStretchFactor(1, 1); propSplitter->setStretchFactor(1, 1);
propSplitter->setWindowTitle(tr("Properties and Watchers")); propSplitter->setWindowTitle(tr("Properties and Watchers"));
propSplitter->setObjectName(QLatin1String("QmlDebugProperties"));
InspectorOutputWidget *inspectorOutput = new InspectorOutputWidget(); InspectorOutputWidget *inspectorOutput = new InspectorOutputWidget();
inspectorOutput->setObjectName(QLatin1String("QmlDebugInspectorOutput")); inspectorOutput->setObjectName(QLatin1String("QmlDebugInspectorOutput"));
connect(this, SIGNAL(statusMessage(QString)), connect(this, SIGNAL(statusMessage(QString)),
inspectorOutput, SLOT(addInspectorStatus(QString))); inspectorOutput, SLOT(addInspectorStatus(QString)));
m_objectTreeDock = Debugger::DebuggerUISwitcher::instance()->createDockWidget(Qml::Constants::LANG_QML, Debugger::DebuggerUISwitcher *uiSwitcher = Debugger::DebuggerUISwitcher::instance();
m_watchTableView->hide();
m_objectTreeDock = uiSwitcher->createDockWidget(Qml::Constants::LANG_QML,
treeWindow, Qt::BottomDockWidgetArea); treeWindow, Qt::BottomDockWidgetArea);
// m_frameRateDock = Debugger::DebuggerUISwitcher::instance()->createDockWidget(Qml::Constants::LANG_QML, // m_frameRateDock = uiSwitcher->createDockWidget(Qml::Constants::LANG_QML,
// m_frameRateWidget, Qt::BottomDockWidgetArea); // m_frameRateWidget, Qt::BottomDockWidgetArea);
m_propertyWatcherDock = Debugger::DebuggerUISwitcher::instance()->createDockWidget(Qml::Constants::LANG_QML, m_propertyWatcherDock = uiSwitcher->createDockWidget(Qml::Constants::LANG_QML,
propSplitter, Qt::BottomDockWidgetArea); propSplitter, Qt::BottomDockWidgetArea);
m_inspectorOutputDock = Debugger::DebuggerUISwitcher::instance()->createDockWidget(Qml::Constants::LANG_QML, m_inspectorOutputDock = uiSwitcher->createDockWidget(Qml::Constants::LANG_QML,
inspectorOutput, Qt::BottomDockWidgetArea); inspectorOutput, Qt::BottomDockWidgetArea);
m_objectTreeDock->setToolTip(tr("Contents of the scene.")); m_expressionWidget->setWindowTitle(tr("Script console"));
// m_frameRateDock->setToolTip(tr("Frame rate graph for analyzing performance.")); m_expressionQueryDock = uiSwitcher->createDockWidget(Qml::Constants::LANG_QML,
m_propertyWatcherDock->setToolTip(tr("Properties of the selected item.")); m_expressionWidget, Qt::BottomDockWidgetArea);
m_inspectorOutputDock->setToolTip(tr("Output of the QML inspector, such as information on connecting to the server.")); m_inspectorOutputDock->setToolTip(tr("Output of the QML inspector, such as information on connecting to the server."));
m_dockWidgets << m_objectTreeDock << /*m_frameRateDock << */ m_propertyWatcherDock << m_inspectorOutputDock; m_dockWidgets << m_objectTreeDock << /*m_frameRateDock << */ m_propertyWatcherDock
<< m_inspectorOutputDock << m_expressionQueryDock;
m_context = new Internal::InspectorContext(m_objectTreeDock); m_context = new Internal::InspectorContext(m_objectTreeDock);
m_propWatcherContext = new Internal::InspectorContext(m_propertyWatcherDock); m_propWatcherContext = new Internal::InspectorContext(m_propertyWatcherDock);
@@ -578,6 +575,7 @@ void QmlInspector::setSimpleDockWidgetArrangement()
} }
//mainWindow->tabifyDockWidget(m_frameRateDock, m_propertyWatcherDock); //mainWindow->tabifyDockWidget(m_frameRateDock, m_propertyWatcherDock);
mainWindow->tabifyDockWidget(m_propertyWatcherDock, m_expressionQueryDock);
mainWindow->tabifyDockWidget(m_propertyWatcherDock, m_inspectorOutputDock); mainWindow->tabifyDockWidget(m_propertyWatcherDock, m_inspectorOutputDock);
m_inspectorOutputDock->setVisible(false); m_inspectorOutputDock->setVisible(false);

View File

@@ -136,6 +136,7 @@ private:
QDockWidget *m_objectTreeDock; QDockWidget *m_objectTreeDock;
QDockWidget *m_frameRateDock; QDockWidget *m_frameRateDock;
QDockWidget *m_expressionQueryDock;
QDockWidget *m_propertyWatcherDock; QDockWidget *m_propertyWatcherDock;
QDockWidget *m_inspectorOutputDock; QDockWidget *m_inspectorOutputDock;
QList<QDockWidget*> m_dockWidgets; QList<QDockWidget*> m_dockWidgets;