Fixed nonsensical context menu entries appearing in Qml inspector

This commit is contained in:
Lasse Holmstedt
2010-05-04 10:06:41 +02:00
parent 441db7c946
commit b9d8db2444
4 changed files with 51 additions and 32 deletions

View File

@@ -43,25 +43,27 @@ void ObjectTreeItem::setHasValidDebugId(bool value)
// ************************************************************************* // *************************************************************************
// PropertiesViewItem // PropertiesViewItem
// ************************************************************************* // *************************************************************************
PropertiesViewItem::PropertiesViewItem(QTreeWidget *widget, Type type) PropertiesViewItem::PropertiesViewItem(QTreeWidget *widget, int type)
: QTreeWidgetItem(widget), type(type) : QTreeWidgetItem(widget, type), m_disabled(false)
{ {
} }
PropertiesViewItem::PropertiesViewItem(QTreeWidgetItem *parent, Type type) PropertiesViewItem::PropertiesViewItem(QTreeWidgetItem *parent, int type)
: QTreeWidgetItem(parent), type(type) : QTreeWidgetItem(parent, type), m_disabled(false)
{ {
} }
QVariant PropertiesViewItem::data (int column, int role) const QVariant PropertiesViewItem::data (int column, int role) const
{ {
if (column == 1) { if (role == Qt::ForegroundRole) {
if (role == Qt::ForegroundRole) { bool makeDisabledColor = m_disabled;
bool canEdit = data(0, CanEditRole).toBool(); if (column == 1 && !data(0, CanEditRole).toBool())
return canEdit ? qApp->palette().color(QPalette::Foreground) : qApp->palette().color(QPalette::Disabled, QPalette::Foreground); makeDisabledColor = true;
} return makeDisabledColor ? qApp->palette().color(QPalette::Disabled, QPalette::Foreground) : qApp->palette().color(QPalette::Foreground);
} }
return QTreeWidgetItem::data(column, role); return QTreeWidgetItem::data(column, role);
} }
@@ -79,7 +81,15 @@ QString PropertiesViewItem::objectIdString() const
{ {
return data(0, ObjectIdStringRole).toString(); return data(0, ObjectIdStringRole).toString();
} }
void PropertiesViewItem::setWatchingDisabled(bool disabled)
{
m_disabled = disabled;
}
bool PropertiesViewItem::isWatchingDisabled() const
{
return m_disabled;
}
} // Internal } // Internal
} // Qml } // Qml

View File

@@ -28,25 +28,27 @@ class PropertiesViewItem : public QTreeWidgetItem
{ {
public: public:
enum Type { enum Type {
BindingType, BindingType = QTreeWidgetItem::UserType,
OtherType, OtherType = QTreeWidgetItem::UserType + 1,
ClassType, ClassType = QTreeWidgetItem::UserType + 2
}; };
enum DataRoles { enum DataRoles {
CanEditRole = Qt::UserRole + 1, CanEditRole = Qt::UserRole,
ObjectIdStringRole = Qt::UserRole + 50, ObjectIdStringRole = Qt::UserRole + 1,
ClassDepthRole = Qt::UserRole + 51 ClassDepthRole = Qt::UserRole + 2
}; };
PropertiesViewItem(QTreeWidget *widget, Type type = OtherType); PropertiesViewItem(QTreeWidget *widget, int type = OtherType);
PropertiesViewItem(QTreeWidgetItem *parent, Type type = OtherType); PropertiesViewItem(QTreeWidgetItem *parent, int type = OtherType);
QVariant data (int column, int role) const; QVariant data (int column, int role) const;
void setData (int column, int role, const QVariant & value); void setData (int column, int role, const QVariant & value);
void setWatchingDisabled(bool disabled);
bool isWatchingDisabled() const;
QDeclarativeDebugPropertyReference property; QDeclarativeDebugPropertyReference property;
Type type;
private: private:
QString objectIdString() const; QString objectIdString() const;
bool m_disabled;
}; };

View File

@@ -187,11 +187,13 @@ void ObjectPropertiesView::queryFinished()
setObject(obj); 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) { if (value.type() == QVariant::List || value.type() == QVariant::StringList) {
PropertiesViewItem *bindingItem = static_cast<PropertiesViewItem*>(item->takeChild(item->childCount() - 1)); PropertiesViewItem *bindingItem = static_cast<PropertiesViewItem*>(item->takeChild(item->childCount() - 1));
if (bindingItem && bindingItem->type != PropertiesViewItem::BindingType) { if (bindingItem && bindingItem->type() != PropertiesViewItem::BindingType) {
delete bindingItem; delete bindingItem;
bindingItem = 0; bindingItem = 0;
} }
@@ -205,7 +207,7 @@ void ObjectPropertiesView::setPropertyValue(PropertiesViewItem *item, const QVar
PropertiesViewItem *child; PropertiesViewItem *child;
for (int i=0; i<variants.count(); ++i) { for (int i=0; i<variants.count(); ++i) {
child = new PropertiesViewItem(item); child = new PropertiesViewItem(item);
setPropertyValue(child, variants[i], makeGray); setPropertyValue(child, variants[i], isDisabled);
} }
if (bindingItem) if (bindingItem)
@@ -217,10 +219,6 @@ void ObjectPropertiesView::setPropertyValue(PropertiesViewItem *item, const QVar
item->setExpanded(true); 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) 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(), m_clickedItem = m_tree->itemAt(QPoint(event->pos().x(),
event->pos().y() - m_tree->header()->height())); event->pos().y() - m_tree->header()->height()));
if (!m_clickedItem) if (!m_clickedItem)
return; return;
PropertiesViewItem *propItem = static_cast<PropertiesViewItem *>(m_clickedItem); PropertiesViewItem *propItem = static_cast<PropertiesViewItem *>(m_clickedItem);
bool isWatchableItem = propItem->type() != PropertiesViewItem::ClassType &&
propItem->type() != PropertiesViewItem::BindingType;
QMenu menu; QMenu menu;
if (!isWatched(m_clickedItem)) { if (isWatchableItem) {
m_addWatchAction->setText(tr("Watch expression '%1'").arg(propItem->property.name())); if (!isWatched(m_clickedItem)) {
menu.addAction(m_addWatchAction); m_addWatchAction->setText(tr("Watch expression '%1'").arg(propItem->property.name()));
} else { m_addWatchAction->setDisabled(propItem->isWatchingDisabled());
menu.addAction(m_removeWatchAction); menu.addAction(m_addWatchAction);
} else {
menu.addAction(m_removeWatchAction);
m_addWatchAction->setDisabled(propItem->isWatchingDisabled());
}
} }
menu.addSeparator(); menu.addSeparator();
if (m_showUnwatchableProperties) if (m_showUnwatchableProperties)
m_toggleUnwatchablePropertiesAction->setText(tr("Hide unwatchable properties")); m_toggleUnwatchablePropertiesAction->setText(tr("Hide unwatchable properties"));
else else

View File

@@ -90,7 +90,7 @@ private:
void setObject(const QDeclarativeDebugObjectReference &object); void setObject(const QDeclarativeDebugObjectReference &object);
bool isWatched(QTreeWidgetItem *item); 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 isDisabled);
QDeclarativeEngineDebug *m_client; QDeclarativeEngineDebug *m_client;
QDeclarativeDebugObjectQuery *m_query; QDeclarativeDebugObjectQuery *m_query;