inspector in progress

This commit is contained in:
Christophe Alexandre 2008-04-25 15:39:33 +00:00
parent 4e645a28aa
commit b2329afd3d
3 changed files with 45 additions and 1 deletions

View File

@ -1,3 +1,4 @@
#include <QKeyEvent>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "RecordModel.h" #include "RecordModel.h"
@ -6,9 +7,9 @@
HInspectorWidget::HInspectorWidget(QWidget* parent): HInspectorWidget::HInspectorWidget(QWidget* parent):
QWidget(parent), QWidget(parent),
recordModels(), recordModels(),
recordModelsHistory(),
slotsTableView(NULL) slotsTableView(NULL)
{ {
slotsTableView = new QTableView; slotsTableView = new QTableView;
slotsTableView->setAlternatingRowColors(true); slotsTableView->setAlternatingRowColors(true);
slotsTableView->setSelectionBehavior(QAbstractItemView::SelectRows); slotsTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
@ -18,6 +19,8 @@ HInspectorWidget::HInspectorWidget(QWidget* parent):
mainLayout->addWidget(slotsTableView); mainLayout->addWidget(slotsTableView);
setLayout(mainLayout); setLayout(mainLayout);
//setFocusPolicy(Qt::StrongFocus);
setWindowTitle(tr("Inspector")); setWindowTitle(tr("Inspector"));
resize(1000, 500); resize(1000, 500);
} }
@ -31,6 +34,11 @@ HInspectorWidget::~HInspectorWidget() {
} }
void HInspectorWidget::setRecord(Record* record) { void HInspectorWidget::setRecord(Record* record) {
recordModelsHistory.clear();
internalSetRecord(record);
}
void HInspectorWidget::internalSetRecord(Record* record) {
RecordModel* recordModel = NULL; RecordModel* recordModel = NULL;
RecordModels::iterator rmit = recordModels.find(record); RecordModels::iterator rmit = recordModels.find(record);
@ -41,4 +49,33 @@ void HInspectorWidget::setRecord(Record* record) {
recordModels[record] = recordModel; recordModels[record] = recordModel;
} }
slotsTableView->setModel(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<RecordModel*>(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();
}
} }

View File

@ -14,12 +14,18 @@ class HInspectorWidget : public QWidget {
public: public:
typedef map<Record*, RecordModel*> RecordModels; typedef map<Record*, RecordModel*> RecordModels;
typedef list<RecordModel*> RecordModelsHistory;
HInspectorWidget(QWidget* parent=0); HInspectorWidget(QWidget* parent=0);
~HInspectorWidget(); ~HInspectorWidget();
void setRecord(Record* record); void setRecord(Record* record);
protected:
void keyPressEvent(QKeyEvent * event);
private: private:
void internalSetRecord(Record* record);
RecordModels recordModels; RecordModels recordModels;
RecordModelsHistory recordModelsHistory;
QTableView* slotsTableView; QTableView* slotsTableView;
}; };

View File

@ -14,6 +14,7 @@ class RecordModel : public QAbstractTableModel {
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
Record* getRecord() { return record; }
private: private:
Record* record; Record* record;
}; };