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(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);
}
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

View File

@@ -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;
};

View File

@@ -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 (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

View File

@@ -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;