inspector in progress
This commit is contained in:
parent
4e645a28aa
commit
b2329afd3d
|
@ -1,3 +1,4 @@
|
|||
#include <QKeyEvent>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#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<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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,12 +14,18 @@ class HInspectorWidget : public QWidget {
|
|||
|
||||
public:
|
||||
typedef map<Record*, RecordModel*> RecordModels;
|
||||
typedef list<RecordModel*> 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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue