DebuggableViewer.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "DebuggableViewer.h"
  2. #include "HexViewer.h"
  3. #include <QComboBox>
  4. #include <QVBoxLayout>
  5. DebuggableViewer::DebuggableViewer(QWidget* parent)
  6. : QWidget(parent)
  7. {
  8. // create selection list and viewer
  9. debuggableList = new QComboBox();
  10. debuggableList->setEditable(false);
  11. hexView = new HexViewer();
  12. hexView->setIsInteractive(true);
  13. hexView->setIsEditable(true);
  14. QVBoxLayout* vbox = new QVBoxLayout();
  15. vbox->setMargin(0);
  16. vbox->addWidget(debuggableList);
  17. vbox->addWidget(hexView);
  18. setLayout(vbox);
  19. connect(hexView, SIGNAL(locationChanged(int)),
  20. this, SLOT(locationChanged(int)));
  21. }
  22. void DebuggableViewer::settingsChanged()
  23. {
  24. hexView->settingsChanged();
  25. }
  26. void DebuggableViewer::refresh()
  27. {
  28. hexView->refresh();
  29. }
  30. void DebuggableViewer::debuggableSelected(int index)
  31. {
  32. QString name = debuggableList->itemText(index);
  33. int size = debuggableList->itemData(index).toInt();
  34. if (index >= 0)
  35. lastSelected = name;
  36. // add braces when the name contains a space
  37. if (name.contains(QChar(' '))) {
  38. name.append(QChar('}'));
  39. name.prepend(QChar('{'));
  40. }
  41. hexView->setDebuggable(name, size);
  42. }
  43. void DebuggableViewer::locationChanged(int loc)
  44. {
  45. lastLocation = loc;
  46. }
  47. void DebuggableViewer::setDebuggables(const QMap<QString, int>& list)
  48. {
  49. int select = -1;
  50. // disconnect signal to prevent updates
  51. debuggableList->disconnect(this, SLOT(debuggableSelected(int)));
  52. debuggableList->clear();
  53. for (QMap<QString, int>::const_iterator it = list.begin();
  54. it != list.end(); ++it) {
  55. // set name and strip braces if necessary
  56. QString name = it.key();
  57. if (name.contains(QChar(' '))) {
  58. name = name.mid(1, name.size() - 2);
  59. }
  60. // check if this was the previous selection
  61. if (name == lastSelected)
  62. select = debuggableList->count();
  63. debuggableList->addItem(name, it.value());
  64. }
  65. // reconnect signal before selecting item
  66. connect(debuggableList, SIGNAL(currentIndexChanged(int)),
  67. this, SLOT(debuggableSelected(int)));
  68. if (!list.empty() && select >= 0) {
  69. debuggableList->setCurrentIndex(select);
  70. hexView->setLocation(lastLocation);
  71. }
  72. }