diff options
author | Lasse Holmstedt <lasse.holmstedt@nokia.com> | 2010-05-04 10:06:41 +0200 |
---|---|---|
committer | Lasse Holmstedt <lasse.holmstedt@nokia.com> | 2010-05-04 10:07:12 +0200 |
commit | b9d8db24441e5a6fc7f7d3210fbd0dd1009368f0 (patch) | |
tree | e89aa925211358d68e26eeb89dc2db1a6423ab69 | |
parent | 441db7c946a2bb4e3d6c52cee94ed5887c1e57ec (diff) | |
download | qt-creator-b9d8db24441e5a6fc7f7d3210fbd0dd1009368f0.tar.gz |
Fixed nonsensical context menu entries appearing in Qml inspector
4 files changed, 51 insertions, 32 deletions
diff --git a/src/plugins/qmlinspector/components/inspectortreeitems.cpp b/src/plugins/qmlinspector/components/inspectortreeitems.cpp index 5527b0fc16..abbf2aaa31 100644 --- a/src/plugins/qmlinspector/components/inspectortreeitems.cpp +++ b/src/plugins/qmlinspector/components/inspectortreeitems.cpp @@ -43,25 +43,27 @@ void ObjectTreeItem::setHasValidDebugId(bool value) // ************************************************************************* // PropertiesViewItem // ************************************************************************* -PropertiesViewItem::PropertiesViewItem(QTreeWidget *widget, Type type) - : QTreeWidgetItem(widget), type(type) +PropertiesViewItem::PropertiesViewItem(QTreeWidget *widget, int type) + : QTreeWidgetItem(widget, type), m_disabled(false) { + } -PropertiesViewItem::PropertiesViewItem(QTreeWidgetItem *parent, Type type) - : QTreeWidgetItem(parent), type(type) +PropertiesViewItem::PropertiesViewItem(QTreeWidgetItem *parent, int type) + : QTreeWidgetItem(parent, type), m_disabled(false) { } QVariant PropertiesViewItem::data (int column, int role) const { - if (column == 1) { - if (role == Qt::ForegroundRole) { - bool canEdit = data(0, CanEditRole).toBool(); - return canEdit ? qApp->palette().color(QPalette::Foreground) : qApp->palette().color(QPalette::Disabled, QPalette::Foreground); - } + if (role == Qt::ForegroundRole) { + bool makeDisabledColor = m_disabled; + if (column == 1 && !data(0, CanEditRole).toBool()) + makeDisabledColor = true; + return makeDisabledColor ? qApp->palette().color(QPalette::Disabled, QPalette::Foreground) : qApp->palette().color(QPalette::Foreground); } + return QTreeWidgetItem::data(column, role); } @@ -79,7 +81,15 @@ QString PropertiesViewItem::objectIdString() const { return data(0, ObjectIdStringRole).toString(); } +void PropertiesViewItem::setWatchingDisabled(bool disabled) +{ + m_disabled = disabled; +} +bool PropertiesViewItem::isWatchingDisabled() const +{ + return m_disabled; +} } // Internal } // Qml diff --git a/src/plugins/qmlinspector/components/inspectortreeitems.h b/src/plugins/qmlinspector/components/inspectortreeitems.h index b09ff80d77..dbc0aaa7cc 100644 --- a/src/plugins/qmlinspector/components/inspectortreeitems.h +++ b/src/plugins/qmlinspector/components/inspectortreeitems.h @@ -28,25 +28,27 @@ class PropertiesViewItem : public QTreeWidgetItem { public: enum Type { - BindingType, - OtherType, - ClassType, + BindingType = QTreeWidgetItem::UserType, + OtherType = QTreeWidgetItem::UserType + 1, + ClassType = QTreeWidgetItem::UserType + 2 }; enum DataRoles { - CanEditRole = Qt::UserRole + 1, - ObjectIdStringRole = Qt::UserRole + 50, - ClassDepthRole = Qt::UserRole + 51 + CanEditRole = Qt::UserRole, + ObjectIdStringRole = Qt::UserRole + 1, + ClassDepthRole = Qt::UserRole + 2 }; - PropertiesViewItem(QTreeWidget *widget, Type type = OtherType); - PropertiesViewItem(QTreeWidgetItem *parent, Type type = OtherType); + PropertiesViewItem(QTreeWidget *widget, int type = OtherType); + PropertiesViewItem(QTreeWidgetItem *parent, int type = OtherType); QVariant data (int column, int role) const; void setData (int column, int role, const QVariant & value); - + void setWatchingDisabled(bool disabled); + bool isWatchingDisabled() const; QDeclarativeDebugPropertyReference property; - Type type; + private: QString objectIdString() const; + bool m_disabled; }; diff --git a/src/plugins/qmlinspector/components/objectpropertiesview.cpp b/src/plugins/qmlinspector/components/objectpropertiesview.cpp index 17a98d2aec..b0d1b1220e 100644 --- a/src/plugins/qmlinspector/components/objectpropertiesview.cpp +++ b/src/plugins/qmlinspector/components/objectpropertiesview.cpp @@ -187,11 +187,13 @@ void ObjectPropertiesView::queryFinished() setObject(obj); } -void ObjectPropertiesView::setPropertyValue(PropertiesViewItem *item, const QVariant &value, bool makeGray) +void ObjectPropertiesView::setPropertyValue(PropertiesViewItem *item, const QVariant &value, bool isDisabled) { + item->setWatchingDisabled(isDisabled); + if (value.type() == QVariant::List || value.type() == QVariant::StringList) { PropertiesViewItem *bindingItem = static_cast<PropertiesViewItem*>(item->takeChild(item->childCount() - 1)); - if (bindingItem && bindingItem->type != PropertiesViewItem::BindingType) { + if (bindingItem && bindingItem->type() != PropertiesViewItem::BindingType) { delete bindingItem; bindingItem = 0; } @@ -205,7 +207,7 @@ void ObjectPropertiesView::setPropertyValue(PropertiesViewItem *item, const QVar PropertiesViewItem *child; for (int i=0; i<variants.count(); ++i) { child = new PropertiesViewItem(item); - setPropertyValue(child, variants[i], makeGray); + setPropertyValue(child, variants[i], isDisabled); } if (bindingItem) @@ -217,10 +219,6 @@ void ObjectPropertiesView::setPropertyValue(PropertiesViewItem *item, const QVar item->setExpanded(true); } - if (makeGray) { - for (int i=0; i<m_tree->columnCount(); ++i) - item->setForeground(i, Qt::gray); - } } QString ObjectPropertiesView::propertyBaseClass(const QDeclarativeDebugObjectReference &object, const QDeclarativeDebugPropertyReference &property, int &depth) @@ -483,20 +481,29 @@ 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); + bool isWatchableItem = propItem->type() != PropertiesViewItem::ClassType && + propItem->type() != PropertiesViewItem::BindingType; + 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); + if (isWatchableItem) { + if (!isWatched(m_clickedItem)) { + m_addWatchAction->setText(tr("Watch expression '%1'").arg(propItem->property.name())); + m_addWatchAction->setDisabled(propItem->isWatchingDisabled()); + menu.addAction(m_addWatchAction); + } else { + menu.addAction(m_removeWatchAction); + m_addWatchAction->setDisabled(propItem->isWatchingDisabled()); + } } menu.addSeparator(); + if (m_showUnwatchableProperties) m_toggleUnwatchablePropertiesAction->setText(tr("Hide unwatchable properties")); else diff --git a/src/plugins/qmlinspector/components/objectpropertiesview.h b/src/plugins/qmlinspector/components/objectpropertiesview.h index c4e7e2857c..b86ef9dbb4 100644 --- a/src/plugins/qmlinspector/components/objectpropertiesview.h +++ b/src/plugins/qmlinspector/components/objectpropertiesview.h @@ -90,7 +90,7 @@ private: void setObject(const QDeclarativeDebugObjectReference &object); bool isWatched(QTreeWidgetItem *item); void setWatched(const QString &property, bool watched); - void setPropertyValue(PropertiesViewItem *item, const QVariant &value, bool makeGray); + void setPropertyValue(PropertiesViewItem *item, const QVariant &value, bool isDisabled); QDeclarativeEngineDebug *m_client; QDeclarativeDebugObjectQuery *m_query; |