Qt 4.8
qscriptdebuggerlocalsmodel.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSCriptTools module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
44 #include "qscriptdebuggervalue_p.h"
46 #include "qscriptdebuggerevent_p.h"
52 
53 #include "private/qabstractitemmodel_p.h"
54 
55 #include <QtCore/qdebug.h>
56 #include <QtCore/qcoreapplication.h>
57 #include <QtCore/qpointer.h>
58 #include <QtGui/qbrush.h>
59 #include <QtGui/qfont.h>
60 
62 
64 
66 {
71  };
72 
75 
77  const QScriptDebuggerValueProperty &prop,
79  : property(prop), parent(par),
81  {
82  parent->children.append(this);
83  }
84 
86 
88  {
89  for (int i = 0; i < children.size(); ++i) {
91  if (child->property.name() == name)
92  return child;
93  }
94  return 0;
95  }
96 
102  bool changed;
103 };
104 
107 {
109 public:
112 
114 
115  QModelIndex addTopLevelObject(const QString &name, const QScriptDebuggerValue &object);
116 
117  QScriptDebuggerLocalsModelNode *nodeFromIndex(const QModelIndex &index) const;
118  QModelIndex indexFromNode(QScriptDebuggerLocalsModelNode *node) const;
119  bool isTopLevelNode(QScriptDebuggerLocalsModelNode *node) const;
120 
121  void populateIndex(const QModelIndex &index);
122  void reallyPopulateIndex(const QModelIndex &index,
123  const QScriptDebuggerValuePropertyList &props);
124  void syncIndex(const QModelIndex &index);
125  void reallySyncIndex(const QModelIndex &index,
127  void syncTopLevelNodes();
128  void removeTopLevelNodes();
129  void emitScopeObjectAvailable(const QModelIndex &index);
130 
131  void emitDataChanged(const QModelIndex &tl, const QModelIndex &br);
132  void removeChild(const QModelIndex &parentIndex,
133  QScriptDebuggerLocalsModelNode *parentNode, int row);
134  void depopulate(QScriptDebuggerLocalsModelNode *node);
135  void repopulate(QScriptDebuggerLocalsModelNode *node);
136  void addChildren(const QModelIndex &parentIndex,
137  QScriptDebuggerLocalsModelNode *parentNode,
138  const QScriptDebuggerValuePropertyList &props);
139 
140  void deleteObjectSnapshots(const QList<qint64> &snapshotIds);
141  void deleteAllObjectSnapshots();
142 
147 };
148 
150 {
151  invisibleRootNode = new QScriptDebuggerLocalsModelNode();
152  frameIndex = -1;
153 }
154 
156 {
157  delete invisibleRootNode;
158 }
159 
161 {
162  q_func()->dataChanged(tl, br);
163 }
164 
166 {
167  QList<qint64> result;
168  if (root->snapshotId == -1) {
169  Q_ASSERT(root->children.isEmpty());
170  return result;
171  }
173  nodeStack.append(root);
174  while (!nodeStack.isEmpty()) {
175  QScriptDebuggerLocalsModelNode *node = nodeStack.takeFirst();
176  result.append(node->snapshotId);
177  for (int i = 0; i < node->children.count(); ++i) {
178  QScriptDebuggerLocalsModelNode *child = node->children.at(i);
179  if (child->snapshotId != -1)
180  nodeStack.prepend(child);
181  }
182  }
183  return result;
184 }
185 
187  QScriptDebuggerLocalsModelNode *parentNode,
188  int row)
189 {
191  q->beginRemoveRows(parentIndex, row, row);
192  QScriptDebuggerLocalsModelNode *child = parentNode->children.takeAt(row);
193  QList<qint64> snapshotIds = findSnapshotIdsRecursively(child);
194  delete child;
195  q->endRemoveRows();
196  deleteObjectSnapshots(snapshotIds);
197 }
198 
200 {
202  bool hasChildren = !node->children.isEmpty();
203  if (hasChildren)
204  q->beginRemoveRows(indexFromNode(node), 0, node->children.count() - 1);
205  QList<qint64> snapshotIds = findSnapshotIdsRecursively(node);
206  qDeleteAll(node->children);
207  node->children.clear();
208  node->snapshotId = -1;
210  if (hasChildren)
211  q->endRemoveRows();
212  deleteObjectSnapshots(snapshotIds);
213 }
214 
216 {
218  return;
219  depopulate(node);
221  populateIndex(indexFromNode(node));
222 }
223 
225  QScriptDebuggerLocalsModelNode *parentNode,
227 {
229  if (props.isEmpty())
230  return;
231  int first = parentNode->children.size();
232  int last = first + props.size() - 1;
233  q->beginInsertRows(parentIndex, first, last);
234  for (int i = 0; i < props.size(); ++i)
235  new QScriptDebuggerLocalsModelNode(props.at(i), parentNode);
236  q->endInsertRows();
237 }
238 
240 {
241  QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler, 0);
242  for (int i = 0; i < snapshotIds.size(); ++i)
243  frontend.scheduleDeleteScriptObjectSnapshot(snapshotIds.at(i));
244 }
245 
247 {
248  QList<qint64> snapshotIds;
249  for (int i = 0; i < invisibleRootNode->children.count(); ++i)
250  snapshotIds += findSnapshotIdsRecursively(invisibleRootNode->children.at(i));
251  deleteObjectSnapshots(snapshotIds);
252 }
253 
255 {
256  return q->d_func();
257 }
258 
259 namespace {
260 
261 class SetPropertyJob : public QScriptDebuggerCommandSchedulerJob
262 {
263 public:
264  SetPropertyJob(const QPersistentModelIndex &index,
265  const QString &expression,
268  m_index(index), m_expression(expression), m_state(0) {}
269 
270  QScriptDebuggerLocalsModelPrivate *model() const
271  {
272  if (!m_index.isValid())
273  return 0;
274  QAbstractItemModel *m = const_cast<QAbstractItemModel*>(m_index.model());
277  }
278 
279  void start()
280  {
281  if (!m_index.isValid()) {
282  // nothing to do, the node has been removed
283  return;
284  }
285  QScriptDebuggerLocalsModelNode *node = model()->nodeFromIndex(m_index);
286  QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this);
287  frontend.scheduleEvaluate(model()->frameIndex, m_expression,
288  QString::fromLatin1("set property '%0' (%1)")
289  .arg(node->property.name())
291  }
292 
293  void handleResponse(const QScriptDebuggerResponse &, int)
294  {
295  switch (m_state) {
296  case 0:
297  hibernateUntilEvaluateFinished();
298  ++m_state;
299  break;
300  case 1:
301  finish();
302  break;
303  }
304  }
305 
306  void evaluateFinished(const QScriptDebuggerValue &result)
307  {
308  if (!m_index.isValid()) {
309  // nothing to do, the node has been removed
310  return;
311  }
312  QScriptDebuggerLocalsModelNode *node = model()->nodeFromIndex(m_index);
313  Q_ASSERT(node->parent != 0);
314  QScriptDebuggerValue object = node->parent->property.value();
315  QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this);
316  frontend.scheduleSetScriptValueProperty(object, node->property.name(), result);
317  }
318 
319 private:
320  QPersistentModelIndex m_index;
321  QString m_expression;
322  int m_state;
323 };
324 
325 } // namespace
326 
328  const QModelIndex &index) const
329 {
330  if (!index.isValid())
331  return invisibleRootNode;
332  return static_cast<QScriptDebuggerLocalsModelNode*>(index.internalPointer());
333 }
334 
336  QScriptDebuggerLocalsModelNode *node) const
337 {
338  if (!node || (node == invisibleRootNode))
339  return QModelIndex();
341  int row = par ? par->children.indexOf(node) : 0;
342  return createIndex(row, 0, node);
343 }
344 
346 {
347  return node && (node->parent == invisibleRootNode);
348 }
349 
350 namespace {
351 
352 class PopulateModelIndexJob : public QScriptDebuggerCommandSchedulerJob
353 {
354 public:
355  PopulateModelIndexJob(const QPersistentModelIndex &index,
358  m_index(index), m_state(0)
359  { }
360 
361  QScriptDebuggerLocalsModelPrivate *model() const
362  {
363  if (!m_index.isValid())
364  return 0;
365  QAbstractItemModel *m = const_cast<QAbstractItemModel*>(m_index.model());
368  }
369 
370  void start()
371  {
372  if (!m_index.isValid()) {
373  // nothing to do, the node has been removed
374  finish();
375  return;
376  }
377  QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this);
379  }
380 
381  void handleResponse(const QScriptDebuggerResponse &response,
382  int)
383  {
384  if (!m_index.isValid()) {
385  // the node has been removed
386  finish();
387  return;
388  }
389  switch (m_state) {
390  case 0: {
391  QScriptDebuggerLocalsModelNode *node = model()->nodeFromIndex(m_index);
393  node->snapshotId = response.resultAsInt();
394  QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this);
396  ++m_state;
397  } break;
398  case 1: {
404  model()->reallyPopulateIndex(m_index, props);
405  finish();
406  } break;
407  }
408  }
409 
410 private:
411  QPersistentModelIndex m_index;
412  int m_state;
413 };
414 
415 } // namespace
416 
418  const QModelIndex &index)
419 {
420  if (!index.isValid())
421  return;
422  QScriptDebuggerLocalsModelNode *node = nodeFromIndex(index);
424  return;
426  return;
428  QScriptDebuggerJob *job = new PopulateModelIndexJob(index, commandScheduler);
429  jobScheduler->scheduleJob(job);
430 }
431 
433  const QModelIndex &index,
435 {
436  if (!index.isValid())
437  return;
438  QScriptDebuggerLocalsModelNode *node = nodeFromIndex(index);
441  addChildren(index, node, props);
442 }
443 
447  QObject *parent)
449 {
451  d->jobScheduler = jobScheduler;
452  d->commandScheduler = commandScheduler;
453 }
454 
456 {
457 }
458 
460 {
462  QScriptDebuggerLocalsModelNode *node = invisibleRootNode->findChild(name);
463  if (node)
464  return indexFromNode(node);
465  QScriptDebuggerValueProperty prop(name, object,
466  QString::fromLatin1(""), // ### string representation of object
467  /*flags=*/0);
468  int rowIndex = invisibleRootNode->children.size();
469  q->beginInsertRows(QModelIndex(), rowIndex, rowIndex);
470  node = new QScriptDebuggerLocalsModelNode(prop, invisibleRootNode);
471  q->endInsertRows();
472  return indexFromNode(node);
473 }
474 
475 namespace {
476 
477 class InitModelJob : public QScriptDebuggerCommandSchedulerJob
478 {
479 public:
480  InitModelJob(QScriptDebuggerLocalsModel *model,
481  int frameIndex,
484  m_model(model), m_frameIndex(frameIndex), m_state(0)
485  { }
486 
487  void start()
488  {
489  if (!m_model) {
490  // Model has been deleted.
491  finish();
492  return;
493  }
494  QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this);
495  frontend.scheduleGetScopeChain(m_frameIndex);
496  }
497 
498  void handleResponse(const QScriptDebuggerResponse &response,
499  int)
500  {
501  if (!m_model) {
502  // Model has been deleted.
503  finish();
504  return;
505  }
506  QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this);
508  switch (m_state) {
509  case 0: {
510  QScriptDebuggerValueList scopeChain = response.resultAsScriptValueList();
511  for (int i = 0; i < scopeChain.size(); ++i) {
512  const QScriptDebuggerValue &scopeObject = scopeChain.at(i);
513  QString name = QString::fromLatin1("Scope");
514  if (i > 0)
515  name.append(QString::fromLatin1(" (%0)").arg(i));
516  QModelIndex index = model_d->addTopLevelObject(name, scopeObject);
517  if (i == 0)
518  model_d->emitScopeObjectAvailable(index);
519  }
520  frontend.scheduleGetThisObject(m_frameIndex);
521  ++m_state;
522  } break;
523  case 1: {
524  QScriptDebuggerValue thisObject = response.resultAsScriptValue();
525  model_d->addTopLevelObject(QLatin1String("this"), thisObject);
526  finish();
527  } break;
528  }
529  }
530 
531 private:
533  int m_frameIndex;
534  int m_state;
535 };
536 
537 } // namespace
538 
540 {
542  d->frameIndex = frameIndex;
543  QScriptDebuggerJob *job = new InitModelJob(this, frameIndex, d->commandScheduler);
544  d->jobScheduler->scheduleJob(job);
545 }
546 
547 namespace {
548 
549 class SyncModelJob : public QScriptDebuggerCommandSchedulerJob
550 {
551 public:
552  SyncModelJob(QScriptDebuggerLocalsModel *model,
553  int frameIndex,
556  m_model(model), m_frameIndex(frameIndex), m_state(0)
557  { }
558 
559  void start()
560  {
561  if (!m_model) {
562  // Model has been deleted.
563  finish();
564  return;
565  }
566  QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this);
567  frontend.scheduleGetScopeChain(m_frameIndex);
568  }
569 
570  void handleResponse(const QScriptDebuggerResponse &response,
571  int)
572  {
573  if (!m_model) {
574  // Model has been deleted.
575  finish();
576  return;
577  }
578  QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this);
579  switch (m_state) {
580  case 0: {
581  QScriptDebuggerValueList scopeChain = response.resultAsScriptValueList();
582  m_topLevelObjects << scopeChain;
583  frontend.scheduleGetThisObject(m_frameIndex);
584  ++m_state;
585  } break;
586  case 1: {
588  QScriptDebuggerValue thisObject = response.resultAsScriptValue();
589  m_topLevelObjects.append(thisObject);
590  bool equal = (m_topLevelObjects.size() == model_d->invisibleRootNode->children.size());
591  for (int i = 0; equal && (i < m_topLevelObjects.size()); ++i) {
592  const QScriptDebuggerValue &object = m_topLevelObjects.at(i);
593  equal = (object == model_d->invisibleRootNode->children.at(i)->property.value());
594  }
595  if (!equal) {
596  // the scope chain and/or this-object changed, so invalidate the model.
597  // we could try to be more clever, i.e. figure out
598  // exactly which objects were popped/pushed
599  model_d->removeTopLevelNodes();
600  for (int j = 0; j < m_topLevelObjects.size(); ++j) {
601  const QScriptDebuggerValue &object = m_topLevelObjects.at(j);
602  QString name;
603  if (j == m_topLevelObjects.size()-1) {
604  name = QString::fromLatin1("this");
605  } else {
606  name = QString::fromLatin1("Scope");
607  if (j > 0)
608  name.append(QString::fromLatin1(" (%0)").arg(j));
609  }
610  QModelIndex index = model_d->addTopLevelObject(name, object);
611  if (j == 0)
612  model_d->emitScopeObjectAvailable(index);
613  }
614  } else {
615  model_d->syncTopLevelNodes();
616  }
617  finish();
618  } break;
619  }
620  }
621 
622 private:
624  int m_frameIndex;
625  int m_state;
626  QScriptDebuggerValueList m_topLevelObjects;
627 };
628 
629 } // namespace
630 
632 {
634  d->frameIndex = frameIndex;
635  QScriptDebuggerJob *job = new SyncModelJob(this, frameIndex, d->commandScheduler);
636  d->jobScheduler->scheduleJob(job);
637 }
638 
639 namespace {
640 
641 class SyncModelIndexJob : public QScriptDebuggerCommandSchedulerJob
642 {
643 public:
644  SyncModelIndexJob(const QPersistentModelIndex &index,
647  m_index(index)
648  { }
649 
650  QScriptDebuggerLocalsModelPrivate *model() const
651  {
652  if (!m_index.isValid())
653  return 0;
654  QAbstractItemModel *m = const_cast<QAbstractItemModel*>(m_index.model());
657  }
658 
659  void start()
660  {
661  if (!m_index.isValid()) {
662  // nothing to do, the node has been removed
663  finish();
664  return;
665  }
666  QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this);
667  QScriptDebuggerLocalsModelNode *node = model()->nodeFromIndex(m_index);
669  }
670 
671  void handleResponse(const QScriptDebuggerResponse &response,
672  int)
673  {
676  model()->reallySyncIndex(m_index, delta);
677  finish();
678  }
679 
680 private:
681  QPersistentModelIndex m_index;
682 };
683 
684 } // namespace
685 
687 {
688  if (!index.isValid())
689  return;
690  QScriptDebuggerLocalsModelNode *node = nodeFromIndex(index);
692  return;
693  QScriptDebuggerJob *job = new SyncModelIndexJob(index, commandScheduler);
694  jobScheduler->scheduleJob(job);
695 }
696 
699 {
700  if (!index.isValid())
701  return;
702  QScriptDebuggerLocalsModelNode *node = nodeFromIndex(index);
703  // update or remove existing children
704  for (int i = 0; i < node->children.count(); ++i) {
705  QScriptDebuggerLocalsModelNode *child = node->children.at(i);
706  int j;
707  for (j = 0; j < delta.changedProperties.count(); ++j) {
708  if (child->property.name() == delta.changedProperties.at(j).name()) {
709  child->property = delta.changedProperties.at(j);
710  child->changed = true;
711  emitDataChanged(index, index.sibling(0, 1));
712  repopulate(child);
713  break;
714  }
715  }
716  if (j != delta.changedProperties.count())
717  continue; // was changed
718  for (j = 0; j < delta.removedProperties.count(); ++j) {
719  if (child->property.name() == delta.removedProperties.at(j)) {
720  removeChild(index, node, i);
721  --i;
722  break;
723  }
724  }
725  if (j != delta.removedProperties.count())
726  continue; // was removed
727  // neither changed nor removed, but its children might be
729  QScriptDebuggerJob *job = new SyncModelIndexJob(indexFromNode(child), commandScheduler);
730  jobScheduler->scheduleJob(job);
731  }
732  }
733  addChildren(index, node, delta.addedProperties);
734 }
735 
737 {
739  for (int i = 0; i < invisibleRootNode->children.count(); ++i) {
740  QModelIndex index = q->index(i, 0, QModelIndex());
741  syncIndex(index);
742  if (i == 0)
743  emit q->scopeObjectAvailable(index);
744  }
745 }
746 
748 {
749  while (!invisibleRootNode->children.isEmpty())
750  removeChild(QModelIndex(), invisibleRootNode, 0);
751 }
752 
754 {
755  emit q_func()->scopeObjectAvailable(index);
756 }
757 
759 {
761  return d->frameIndex;
762 }
763 
768 {
770  QScriptDebuggerLocalsModelNode *node = d->nodeFromIndex(parent);
771  if ((row < 0) || (row >= node->children.count()))
772  return QModelIndex();
773  return createIndex(row, column, node->children.at(row));
774 }
775 
780 {
782  if (!index.isValid())
783  return QModelIndex();
784  QScriptDebuggerLocalsModelNode *node = d->nodeFromIndex(index);
785  return d->indexFromNode(node->parent);
786 }
787 
792 {
793  return 2;
794 }
795 
800 {
802  // ### need this to make it work with a sortfilterproxymodel (QSFPM is too eager)
803  const_cast<QScriptDebuggerLocalsModel*>(this)->fetchMore(parent);
804  QScriptDebuggerLocalsModelNode *node = d->nodeFromIndex(parent);
805  return node ? node->children.count() : 0;
806 }
807 
812 {
814  if (!index.isValid())
815  return QVariant();
816  QScriptDebuggerLocalsModelNode *node = d->nodeFromIndex(index);
817  if (role == Qt::DisplayRole) {
818  if (index.column() == 0)
819  return node->property.name();
820  else if (index.column() == 1) {
821  QString str = node->property.valueAsString();
822  if (str.indexOf(QLatin1Char('\n')) != -1) {
823  QStringList lines = str.split(QLatin1Char('\n'));
824  int lineCount = lines.size();
825  if (lineCount > 1) {
826  lines = lines.mid(0, 1);
827  lines.append(QString::fromLatin1("(... %0 more lines ...)").arg(lineCount - 1));
828  }
829  str = lines.join(QLatin1String("\n"));
830  }
831  return str;
832  }
833  } else if (role == Qt::EditRole) {
834  if ((index.column() == 1) && !d->isTopLevelNode(node)) {
835  QString str = node->property.valueAsString();
837  // escape
838  str.replace(QLatin1Char('\"'), QLatin1String("\\\""));
839  str.prepend(QLatin1Char('\"'));
840  str.append(QLatin1Char('\"'));
841  }
842  return str;
843  }
844  } else if (role == Qt::ToolTipRole) {
845  if (index.column() == 1) {
846  QString str = node->property.valueAsString();
847  if (str.indexOf(QLatin1Char('\n')) != -1)
848  return str;
849  }
850  }
851  // ### do this in the delegate
852  else if (role == Qt::BackgroundRole) {
853  if (d->isTopLevelNode(node))
854  return QBrush(Qt::darkGray);
855  } else if (role == Qt::TextColorRole) {
856  if (d->isTopLevelNode(node))
857  return QColor(Qt::white);
858  } else if (role == Qt::FontRole) {
859  if (d->isTopLevelNode(node) || node->changed) {
860  QFont fnt;
861  fnt.setBold(true);
862  return fnt;
863  }
864  }
865  return QVariant();
866 }
867 
871 bool QScriptDebuggerLocalsModel::setData(const QModelIndex &index, const QVariant &value, int role)
872 {
874  if (!index.isValid())
875  return false;
876  if (role != Qt::EditRole)
877  return false;
878  QScriptDebuggerLocalsModelNode *node = d->nodeFromIndex(index);
879  if (!node)
880  return false;
881  QString expr = value.toString().trimmed();
882  if (expr.isEmpty())
883  return false;
884  QScriptDebuggerJob *job = new SetPropertyJob(index, expr, d->commandScheduler);
885  d->jobScheduler->scheduleJob(job);
886  return true;
887 }
888 
893 {
894  if (orient == Qt::Horizontal) {
895  if (role == Qt::DisplayRole) {
896  if (section == 0)
897  return QCoreApplication::translate("QScriptDebuggerLocalsModel", "Name");
898  else if (section == 1)
899  return QCoreApplication::translate("QScriptDebuggerLocalsModel", "Value");
900  }
901  }
902  return QVariant();
903 }
904 
909 {
911  if (!index.isValid())
912  return 0;
913  Qt::ItemFlags ret = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
914  if ((index.column() == 1) && index.parent().isValid()) {
915  QScriptDebuggerLocalsModelNode *node = d->nodeFromIndex(index);
916  if (!(node->property.flags() & QScriptValue::ReadOnly))
917  ret |= Qt::ItemIsEditable;
918  }
919  return ret;
920 }
921 
926 {
928  QScriptDebuggerLocalsModelNode *node = d->nodeFromIndex(parent);
929  if (!node)
930  return false;
931  return !node->children.isEmpty()
934 }
935 
940 {
942  if (!parent.isValid())
943  return false;
944  QScriptDebuggerLocalsModelNode *node = d->nodeFromIndex(parent);
945  return node
948 }
949 
954 {
956  d->populateIndex(parent);
957 }
958 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
T qobject_cast(QObject *object)
Definition: qobject.h:375
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
QScriptDebuggerCommandSchedulerInterface * commandScheduler
Qt::ItemFlags flags(const QModelIndex &index) const
Reimplemented Function
bool isTopLevelNode(QScriptDebuggerLocalsModelNode *node) const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QScriptDebuggerValueProperty property
QScriptDebuggerValue resultAsScriptValue() const
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
QScriptDebuggerLocalsModelNode * nodeFromIndex(const QModelIndex &index) const
void emitDataChanged(const QModelIndex &tl, const QModelIndex &br)
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
The QScriptDebuggerResponse class represents a front-end&#39;s response to a QScriptDebuggerCommand.
QScriptDebuggerLocalsModelNode(const QScriptDebuggerValueProperty &prop, QScriptDebuggerLocalsModelNode *par)
int rowCount(const QModelIndex &parent) const
Reimplemented Function
QString & prepend(QChar c)
Definition: qstring.h:261
QString name() const
Returns the name of this QScriptDebuggerValueProperty.
QScriptDebuggerLocalsModel(QScriptDebuggerJobSchedulerInterface *jobScheduler, QScriptDebuggerCommandSchedulerInterface *commandScheduler, QObject *parent=0)
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
bool hasChildren(const QModelIndex &parent) const
Reimplemented Function
void fetchMore(const QModelIndex &parent)
Reimplemented Function
QScriptDebuggerValue value() const
Returns the value of this QScriptDebuggerValueProperty.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static QList< qint64 > findSnapshotIdsRecursively(QScriptDebuggerLocalsModelNode *root)
QVariant headerData(int section, Qt::Orientation, int role=Qt::DisplayRole) const
Reimplemented Function
void removeChild(const QModelIndex &parentIndex, QScriptDebuggerLocalsModelNode *parentNode, int row)
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Reimplemented Function
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the datetime as a string in the format given.
Definition: qdatetime.cpp:2628
The QPointer class is a template class that provides guarded pointers to QObject. ...
Definition: qpointer.h:54
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QScriptValue::PropertyFlags flags() const
Returns the flags of this QScriptDebuggerValueProperty.
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
QList< T > mid(int pos, int length=-1) const
Returns a list whose elements are copied from this list, starting at position pos.
Definition: qlist.h:637
#define Q_Q(Class)
Definition: qglobal.h:2483
static QScriptDebuggerLocalsModelPrivate * get(QScriptDebuggerLocalsModel *q)
QScriptDebuggerJobSchedulerInterface * jobScheduler
int scheduleSetScriptValueProperty(const QScriptDebuggerValue &object, const QString &name, const QScriptDebuggerValue &value)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void reallyPopulateIndex(const QModelIndex &index, const QScriptDebuggerValuePropertyList &props)
void reallySyncIndex(const QModelIndex &index, const QScriptDebuggerObjectSnapshotDelta &delta)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void deleteObjectSnapshots(const QList< qint64 > &snapshotIds)
void setBold(bool)
If enable is true sets the font&#39;s weight to QFont::Bold ; otherwise sets the weight to QFont::Normal...
Definition: qfont.h:352
void populateIndex(const QModelIndex &index)
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool canFetchMore(const QModelIndex &parent) const
Reimplemented Function
void emitScopeObjectAvailable(const QModelIndex &index)
const char * name
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
QScriptDebuggerLocalsModelNode * invisibleRootNode
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QScriptDebuggerLocalsModelNode * parent
QScriptDebuggerLocalsModelNode * findChild(const QString &name)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
void repopulate(QScriptDebuggerLocalsModelNode *node)
void clear()
Removes all items from the list.
Definition: qlist.h:764
QList< QScriptDebuggerLocalsModelNode * > children
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
#define Q_DECLARE_METATYPE(TYPE)
This macro makes the type Type known to QMetaType as long as it provides a public default constructor...
Definition: qmetatype.h:265
The QAbstractItemModel class provides the abstract interface for item model classes.
int scheduleScriptObjectSnapshotCapture(int id, const QScriptDebuggerValue &object)
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
ValueType type() const
Returns the type of this value.
QModelIndex indexFromNode(QScriptDebuggerLocalsModelNode *node) const
The QScriptDebuggerValue class represents a script value.
QScriptDebuggerValueList resultAsScriptValueList() const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QString & append(QChar c)
Definition: qstring.cpp:1777
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Reimplemented Function
The QPersistentModelIndex class is used to locate data in a data model.
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void addChildren(const QModelIndex &parentIndex, QScriptDebuggerLocalsModelNode *parentNode, const QScriptDebuggerValuePropertyList &props)
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
Definition: qdatetime.cpp:3138
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
void syncIndex(const QModelIndex &index)
quint16 index
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
QModelIndex addTopLevelObject(const QString &name, const QScriptDebuggerValue &object)
int scheduleEvaluate(int contextIndex, const QString &program, const QString &fileName=QString(), int lineNumber=1)
Orientation
Definition: qnamespace.h:174
int columnCount(const QModelIndex &parent) const
Reimplemented Function
QVariant result() const
Returns the result of this response.
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void depopulate(QScriptDebuggerLocalsModelNode *node)
static bool equal(const QChar *a, int l, const char *b)
Definition: qurl.cpp:3270
int column() const
Returns the column this model index refers to.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62