24 #include <QtGui/QPixmap> 25 #include <QtCore/QDebug> 27 #include <kjs/object.h> 28 #include <kjs/interpreter.h> 29 #include <kjs/PropertyNameArray.h> 34 KJS::JSObject *instance;
56 return Qt::ItemIsEnabled;
57 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
63 KJS::ExecState *exec = m_js->globalExec();
64 KJS::PropertyNameArray props;
66 m_root->getPropertyNames(exec, props);
69 Node *item =
static_cast<Node*
>(
parent.internalPointer());
70 item->instance->getPropertyNames(exec, props);
83 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
95 KJS::JSObject *parentInstance = 0;
97 KJS::ExecState *exec = m_js->globalExec();
102 parentInstance = m_root;
104 return QModelIndex();
107 parentInstance =
static_cast<Node*
>(
parent.internalPointer())->instance;
109 KJS::PropertyNameArray props;
110 parentInstance->getPropertyNames(exec, props);
111 for( KJS::PropertyNameArrayIterator
ref = props.begin();
ref != props.end();
ref++)
115 childItem =
new Node;
116 childItem->name =
ref->ascii();
117 childItem->instance = parentInstance->get( exec,
118 childItem->name.constData() )->toObject(exec);
119 childItem->parent =
static_cast<Node*
>(
parent.internalPointer());
125 return createIndex(
row, column, childItem);
127 return QModelIndex();
132 if (!
index.isValid())
134 Node *
node =
new Node;
135 node->instance = m_root;
136 node->name =
"Objects";
138 return createIndex(0,
index.column(),
node);
141 Node *parentItem =
static_cast<Node*
>(
index.internalPointer())->
parent;
144 Node *
node =
new Node;
145 node->instance = parentItem->instance;
146 node->name = parentItem->name;
147 node->parent = parentItem->parent;
148 return createIndex(0,
index.column(),
node);
151 return QModelIndex();
156 if (!
index.isValid())
159 Node *item =
static_cast<Node*
>(
index.internalPointer());
160 KJS::JSObject *instance = item->instance;
162 if (role == Qt::DecorationRole )
164 if( instance->implementsConstruct() )
165 return QPixmap(
":/images/class.png");
166 else if( instance->implementsCall() )
167 return QPixmap(
":/images/method.png");
169 return QPixmap(
":/images/property.png");
171 if( role == Qt::TextColorRole )
173 if( instance->implementsConstruct() )
174 return QColor(
"blue");
175 else if( instance->implementsCall() )
176 return QColor(
"green");
178 return QColor(
"black");
180 if (role == Qt::DisplayRole)
185 #include "kjs_object_model.moc"
QModelIndex parent(const QModelIndex &index) const
Qt::ItemFlags flags(const QModelIndex &index) const
END_VALUE_METHOD QString name
KJSObjectModel(KJS::Interpreter *js, QObject *parent=0)
int columnCount(const QModelIndex &parent=QModelIndex()) const
QVariant data(const QModelIndex &index, int role) const
int rowCount(const QModelIndex &parent=QModelIndex()) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
void updateModel(KJS::JSObject *m_root)