| |   |
| 54 | 54 | |
| 55 | 55 | #include <QtCore/qdebug.h> |
| 56 | 56 | #include <QtCore/qcoreapplication.h> |
| #include <QtCore/qpointer.h> |
| 57 | 58 | #include <QtGui/qbrush.h> |
| 58 | 59 | #include <QtGui/qfont.h> |
| 59 | 60 | |
| … | … | |
| 371 | 371 | { |
| 372 | 372 | if (!m_index.isValid()) { |
| 373 | 373 | // nothing to do, the node has been removed |
| finish(); |
| 374 | 375 | return; |
| 375 | 376 | } |
| 376 | 377 | QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this); |
| … | … | |
| 477 | 477 | class InitModelJob : public QScriptDebuggerCommandSchedulerJob |
| 478 | 478 | { |
| 479 | 479 | public: |
| InitModelJob(QScriptDebuggerLocalsModelPrivate *model, |
| InitModelJob(QScriptDebuggerLocalsModel *model, |
| 481 | 481 | int frameIndex, |
| 482 | 482 | QScriptDebuggerCommandSchedulerInterface *scheduler) |
| 483 | 483 | : QScriptDebuggerCommandSchedulerJob(scheduler), |
| … | … | |
| 486 | 486 | |
| 487 | 487 | void start() |
| 488 | 488 | { |
| if (!m_model) { |
| // Model has been deleted. |
| finish(); |
| return; |
| } |
| 489 | 494 | QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this); |
| 490 | 495 | frontend.scheduleGetScopeChain(m_frameIndex); |
| 491 | 496 | } |
| … | … | |
| 498 | 498 | void handleResponse(const QScriptDebuggerResponse &response, |
| 499 | 499 | int) |
| 500 | 500 | { |
| if (!m_model) { |
| // Model has been deleted. |
| finish(); |
| return; |
| } |
| 501 | 506 | QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this); |
| QScriptDebuggerLocalsModelPrivate *model_d = QScriptDebuggerLocalsModelPrivate::get(m_model); |
| 502 | 508 | switch (m_state) { |
| 503 | 509 | case 0: { |
| 504 | 510 | QScriptDebuggerValueList scopeChain = response.resultAsScriptValueList(); |
| … | … | |
| 513 | 513 | QString name = QString::fromLatin1("Scope"); |
| 514 | 514 | if (i > 0) |
| 515 | 515 | name.append(QString::fromLatin1(" (%0)").arg(i)); |
| QModelIndex index = m_model->addTopLevelObject(name, scopeObject); |
| QModelIndex index = model_d->addTopLevelObject(name, scopeObject); |
| 517 | 517 | if (i == 0) |
| m_model->emitScopeObjectAvailable(index); |
| model_d->emitScopeObjectAvailable(index); |
| 519 | 519 | } |
| 520 | 520 | frontend.scheduleGetThisObject(m_frameIndex); |
| 521 | 521 | ++m_state; |
| 522 | 522 | } break; |
| 523 | 523 | case 1: { |
| 524 | 524 | QScriptDebuggerValue thisObject = response.resultAsScriptValue(); |
| m_model->addTopLevelObject(QLatin1String("this"), thisObject); |
| model_d->addTopLevelObject(QLatin1String("this"), thisObject); |
| 526 | 526 | finish(); |
| 527 | 527 | } break; |
| 528 | 528 | } |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | private: |
| QScriptDebuggerLocalsModelPrivate *m_model; |
| QPointer<QScriptDebuggerLocalsModel> m_model; |
| 533 | 533 | int m_frameIndex; |
| 534 | 534 | int m_state; |
| 535 | 535 | }; |
| … | … | |
| 540 | 540 | { |
| 541 | 541 | Q_D(QScriptDebuggerLocalsModel); |
| 542 | 542 | d->frameIndex = frameIndex; |
| QScriptDebuggerJob *job = new InitModelJob(d, frameIndex, d->commandScheduler); |
| QScriptDebuggerJob *job = new InitModelJob(this, frameIndex, d->commandScheduler); |
| 544 | 544 | d->jobScheduler->scheduleJob(job); |
| 545 | 545 | } |
| 546 | 546 | |
| … | … | |
| 549 | 549 | class SyncModelJob : public QScriptDebuggerCommandSchedulerJob |
| 550 | 550 | { |
| 551 | 551 | public: |
| SyncModelJob(QScriptDebuggerLocalsModelPrivate *model, |
| SyncModelJob(QScriptDebuggerLocalsModel *model, |
| 553 | 553 | int frameIndex, |
| 554 | 554 | QScriptDebuggerCommandSchedulerInterface *scheduler) |
| 555 | 555 | : QScriptDebuggerCommandSchedulerJob(scheduler), |
| … | … | |
| 558 | 558 | |
| 559 | 559 | void start() |
| 560 | 560 | { |
| if (!m_model) { |
| // Model has been deleted. |
| finish(); |
| return; |
| } |
| 561 | 566 | QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this); |
| 562 | 567 | frontend.scheduleGetScopeChain(m_frameIndex); |
| 563 | 568 | } |
| … | … | |
| 570 | 570 | void handleResponse(const QScriptDebuggerResponse &response, |
| 571 | 571 | int) |
| 572 | 572 | { |
| if (!m_model) { |
| // Model has been deleted. |
| finish(); |
| return; |
| } |
| 573 | 578 | QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this); |
| 574 | 579 | switch (m_state) { |
| 575 | 580 | case 0: { |
| … | … | |
| 584 | 584 | ++m_state; |
| 585 | 585 | } break; |
| 586 | 586 | case 1: { |
| QScriptDebuggerLocalsModelPrivate *model_d = QScriptDebuggerLocalsModelPrivate::get(m_model); |
| 587 | 588 | QScriptDebuggerValue thisObject = response.resultAsScriptValue(); |
| 588 | 589 | m_topLevelObjects.append(thisObject); |
| bool equal = (m_topLevelObjects.size() == m_model->invisibleRootNode->children.size()); |
| bool equal = (m_topLevelObjects.size() == model_d->invisibleRootNode->children.size()); |
| 590 | 591 | for (int i = 0; equal && (i < m_topLevelObjects.size()); ++i) { |
| 591 | 592 | const QScriptDebuggerValue &object = m_topLevelObjects.at(i); |
| equal = (object == m_model->invisibleRootNode->children.at(i)->property.value()); |
| equal = (object == model_d->invisibleRootNode->children.at(i)->property.value()); |
| 593 | 594 | } |
| 594 | 595 | if (!equal) { |
| 595 | 596 | // the scope chain and/or this-object changed, so invalidate the model. |
| 596 | 597 | // we could try to be more clever, i.e. figure out |
| 597 | 598 | // exactly which objects were popped/pushed |
| m_model->removeTopLevelNodes(); |
| model_d->removeTopLevelNodes(); |
| 599 | 600 | for (int j = 0; j < m_topLevelObjects.size(); ++j) { |
| 600 | 601 | const QScriptDebuggerValue &object = m_topLevelObjects.at(j); |
| 601 | 602 | QString name; |
| … | … | |
| 607 | 607 | if (j > 0) |
| 608 | 608 | name.append(QString::fromLatin1(" (%0)").arg(j)); |
| 609 | 609 | } |
| QModelIndex index = m_model->addTopLevelObject(name, object); |
| QModelIndex index = model_d->addTopLevelObject(name, object); |
| 611 | 611 | if (j == 0) |
| m_model->emitScopeObjectAvailable(index); |
| model_d->emitScopeObjectAvailable(index); |
| 613 | 613 | } |
| 614 | 614 | } else { |
| m_model->syncTopLevelNodes(); |
| model_d->syncTopLevelNodes(); |
| 616 | 616 | } |
| 617 | 617 | finish(); |
| 618 | 618 | } break; |
| … | … | |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | private: |
| QScriptDebuggerLocalsModelPrivate *m_model; |
| QPointer<QScriptDebuggerLocalsModel> m_model; |
| 624 | 624 | int m_frameIndex; |
| 625 | 625 | int m_state; |
| 626 | 626 | QScriptDebuggerValueList m_topLevelObjects; |
| … | … | |
| 632 | 632 | { |
| 633 | 633 | Q_D(QScriptDebuggerLocalsModel); |
| 634 | 634 | d->frameIndex = frameIndex; |
| QScriptDebuggerJob *job = new SyncModelJob(d, frameIndex, d->commandScheduler); |
| QScriptDebuggerJob *job = new SyncModelJob(this, frameIndex, d->commandScheduler); |
| 636 | 636 | d->jobScheduler->scheduleJob(job); |
| 637 | 637 | } |
| 638 | 638 | |
| … | … | |
| 660 | 660 | { |
| 661 | 661 | if (!m_index.isValid()) { |
| 662 | 662 | // nothing to do, the node has been removed |
| finish(); |
| 663 | 664 | return; |
| 664 | 665 | } |
| 665 | 666 | QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this); |