From b2329afd3d340259bae6c0a3b4663ae9e63c8fe3 Mon Sep 17 00:00:00 2001 From: Christophe Alexandre Date: Fri, 25 Apr 2008 15:39:33 +0000 Subject: [PATCH] inspector in progress --- hurricane/src/hinspector/HInspectorWidget.cpp | 39 ++++++++++++++++++- hurricane/src/hinspector/HInspectorWidget.h | 6 +++ hurricane/src/hinspector/RecordModel.h | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/hurricane/src/hinspector/HInspectorWidget.cpp b/hurricane/src/hinspector/HInspectorWidget.cpp index b785cc50..6fc210b4 100644 --- a/hurricane/src/hinspector/HInspectorWidget.cpp +++ b/hurricane/src/hinspector/HInspectorWidget.cpp @@ -1,3 +1,4 @@ +#include #include #include "RecordModel.h" @@ -6,9 +7,9 @@ HInspectorWidget::HInspectorWidget(QWidget* parent): QWidget(parent), recordModels(), + recordModelsHistory(), slotsTableView(NULL) { - slotsTableView = new QTableView; slotsTableView->setAlternatingRowColors(true); slotsTableView->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -18,6 +19,8 @@ HInspectorWidget::HInspectorWidget(QWidget* parent): mainLayout->addWidget(slotsTableView); setLayout(mainLayout); + //setFocusPolicy(Qt::StrongFocus); + setWindowTitle(tr("Inspector")); resize(1000, 500); } @@ -31,6 +34,11 @@ HInspectorWidget::~HInspectorWidget() { } void HInspectorWidget::setRecord(Record* record) { + recordModelsHistory.clear(); + internalSetRecord(record); +} + +void HInspectorWidget::internalSetRecord(Record* record) { RecordModel* recordModel = NULL; RecordModels::iterator rmit = recordModels.find(record); @@ -41,4 +49,33 @@ void HInspectorWidget::setRecord(Record* record) { recordModels[record] = recordModel; } slotsTableView->setModel(recordModel); + recordModelsHistory.push_back(recordModel); +} + +void HInspectorWidget::keyPressEvent(QKeyEvent *event) { + if (event->matches(QKeySequence::MoveToNextChar)) { + QModelIndex index = slotsTableView->currentIndex(); + if (index.isValid()) { + unsigned row = index.row(); + RecordModel* recordModel = static_cast(slotsTableView->model()); + Record* record = recordModel->getRecord(); + Slot* slot = record->getSlot(row); + if (slot) { + Record* newRecord = slot->getDataRecord(); + if (newRecord) { + internalSetRecord(newRecord); + } + } + } + } else if (event->matches(QKeySequence::MoveToPreviousChar)) { + if (!recordModelsHistory.empty()) { + recordModelsHistory.pop_back(); + if (!recordModelsHistory.empty()) { + RecordModel* recordModel = recordModelsHistory.back(); + slotsTableView->setModel(recordModel); + } + } + } else { + event->ignore(); + } } diff --git a/hurricane/src/hinspector/HInspectorWidget.h b/hurricane/src/hinspector/HInspectorWidget.h index cdcab180..1762a436 100644 --- a/hurricane/src/hinspector/HInspectorWidget.h +++ b/hurricane/src/hinspector/HInspectorWidget.h @@ -14,12 +14,18 @@ class HInspectorWidget : public QWidget { public: typedef map RecordModels; + typedef list RecordModelsHistory; HInspectorWidget(QWidget* parent=0); ~HInspectorWidget(); void setRecord(Record* record); + protected: + void keyPressEvent(QKeyEvent * event); + private: + void internalSetRecord(Record* record); RecordModels recordModels; + RecordModelsHistory recordModelsHistory; QTableView* slotsTableView; }; diff --git a/hurricane/src/hinspector/RecordModel.h b/hurricane/src/hinspector/RecordModel.h index 7261708e..4190b866 100644 --- a/hurricane/src/hinspector/RecordModel.h +++ b/hurricane/src/hinspector/RecordModel.h @@ -14,6 +14,7 @@ class RecordModel : public QAbstractTableModel { int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + Record* getRecord() { return record; } private: Record* record; };