Hurricane inspector in progress (sorting)
This commit is contained in:
parent
b2329afd3d
commit
357e9b4961
|
@ -1,4 +1,8 @@
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QTableView>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QGroupBox>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "RecordModel.h"
|
#include "RecordModel.h"
|
||||||
|
@ -6,58 +10,66 @@
|
||||||
|
|
||||||
HInspectorWidget::HInspectorWidget(QWidget* parent):
|
HInspectorWidget::HInspectorWidget(QWidget* parent):
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
recordModels(),
|
filterProxyModels(),
|
||||||
recordModelsHistory(),
|
filterProxyModelsHistory(),
|
||||||
slotsTableView(NULL)
|
slotsView(NULL)
|
||||||
{
|
{
|
||||||
slotsTableView = new QTableView;
|
slotsView = new QTableView(this);
|
||||||
slotsTableView->setAlternatingRowColors(true);
|
slotsView->setAlternatingRowColors(true);
|
||||||
slotsTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
slotsView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
slotsView->setSortingEnabled(true);
|
||||||
|
|
||||||
|
QVBoxLayout* inspectorLayout = new QVBoxLayout();
|
||||||
|
inspectorLayout->addWidget(slotsView);
|
||||||
|
|
||||||
|
filterPatternLineEdit = new QLineEdit(this);
|
||||||
|
inspectorLayout->addWidget(filterPatternLineEdit);
|
||||||
|
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
||||||
mainLayout->addWidget(slotsTableView);
|
|
||||||
|
QGroupBox* inspectorGroupBox = new QGroupBox(tr("Hurricane inspector"), this);
|
||||||
|
inspectorGroupBox->setLayout(inspectorLayout);
|
||||||
|
|
||||||
|
QVBoxLayout* mainLayout = new QVBoxLayout;
|
||||||
|
mainLayout->addWidget(inspectorGroupBox);
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
//setFocusPolicy(Qt::StrongFocus);
|
|
||||||
|
|
||||||
setWindowTitle(tr("Inspector"));
|
setWindowTitle(tr("Inspector"));
|
||||||
resize(1000, 500);
|
resize(1000, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
HInspectorWidget::~HInspectorWidget() {
|
|
||||||
for (RecordModels::iterator rmit = recordModels.begin();
|
|
||||||
rmit != recordModels.end();
|
|
||||||
++rmit) {
|
|
||||||
delete rmit->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HInspectorWidget::setRecord(Record* record) {
|
void HInspectorWidget::setRecord(Record* record) {
|
||||||
recordModelsHistory.clear();
|
filterProxyModelsHistory.clear();
|
||||||
internalSetRecord(record);
|
internalSetRecord(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HInspectorWidget::internalSetRecord(Record* record) {
|
void HInspectorWidget::internalSetRecord(Record* record) {
|
||||||
RecordModel* recordModel = NULL;
|
QSortFilterProxyModel* sortModel = NULL;
|
||||||
|
|
||||||
RecordModels::iterator rmit = recordModels.find(record);
|
FilterProxyModels::iterator fpmit = filterProxyModels.find(record);
|
||||||
if (rmit != recordModels.end()) {
|
if (fpmit != filterProxyModels.end()) {
|
||||||
recordModel = rmit->second;
|
sortModel = fpmit->second;
|
||||||
} else {
|
} else {
|
||||||
recordModel = new RecordModel(record);
|
RecordModel* recordModel = new RecordModel(record, this);
|
||||||
recordModels[record] = recordModel;
|
sortModel = new QSortFilterProxyModel(this);
|
||||||
|
sortModel->setSourceModel(recordModel);
|
||||||
|
filterProxyModels[record] = sortModel;
|
||||||
}
|
}
|
||||||
slotsTableView->setModel(recordModel);
|
slotsView->setModel(sortModel);
|
||||||
recordModelsHistory.push_back(recordModel);
|
slotsView->resizeColumnsToContents();
|
||||||
|
filterProxyModelsHistory.push_back(sortModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HInspectorWidget::keyPressEvent(QKeyEvent *event) {
|
void HInspectorWidget::keyPressEvent(QKeyEvent *event) {
|
||||||
if (event->matches(QKeySequence::MoveToNextChar)) {
|
if (event->matches(QKeySequence::MoveToNextChar)) {
|
||||||
QModelIndex index = slotsTableView->currentIndex();
|
QModelIndex index = slotsView->currentIndex();
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
unsigned row = index.row();
|
unsigned row = index.row();
|
||||||
RecordModel* recordModel = static_cast<RecordModel*>(slotsTableView->model());
|
QSortFilterProxyModel* sortModel =
|
||||||
|
static_cast<QSortFilterProxyModel*>(slotsView->model());
|
||||||
|
RecordModel* recordModel =
|
||||||
|
static_cast<RecordModel*>(sortModel->sourceModel());
|
||||||
Record* record = recordModel->getRecord();
|
Record* record = recordModel->getRecord();
|
||||||
Slot* slot = record->getSlot(row);
|
Slot* slot = record->getSlot(row);
|
||||||
if (slot) {
|
if (slot) {
|
||||||
|
@ -67,14 +79,14 @@ void HInspectorWidget::keyPressEvent(QKeyEvent *event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (event->matches(QKeySequence::MoveToPreviousChar)) {
|
//} else if (event->matches(QKeySequence::MoveToPreviousChar)) {
|
||||||
if (!recordModelsHistory.empty()) {
|
// if (!recordModelsHistory.empty()) {
|
||||||
recordModelsHistory.pop_back();
|
// recordModelsHistory.pop_back();
|
||||||
if (!recordModelsHistory.empty()) {
|
// if (!recordModelsHistory.empty()) {
|
||||||
RecordModel* recordModel = recordModelsHistory.back();
|
// QSortFilterProxyModel* proxyModel = recordModelsHistory.back();
|
||||||
slotsTableView->setModel(recordModel);
|
// slotsView->setModel(proxyModel);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} else {
|
} else {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,18 +5,17 @@
|
||||||
using namespace Hurricane;
|
using namespace Hurricane;
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QTableView>
|
class QSortFilterProxyModel;
|
||||||
|
class QTableView;
|
||||||
class RecordModel;
|
class QLineEdit;
|
||||||
|
|
||||||
class HInspectorWidget : public QWidget {
|
class HInspectorWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef map<Record*, RecordModel*> RecordModels;
|
typedef map<Record*, QSortFilterProxyModel*> FilterProxyModels;
|
||||||
typedef list<RecordModel*> RecordModelsHistory;
|
typedef list<QSortFilterProxyModel*> FilterProxyModelsHistory;
|
||||||
HInspectorWidget(QWidget* parent=0);
|
HInspectorWidget(QWidget* parent=0);
|
||||||
~HInspectorWidget();
|
|
||||||
void setRecord(Record* record);
|
void setRecord(Record* record);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -24,9 +23,10 @@ class HInspectorWidget : public QWidget {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void internalSetRecord(Record* record);
|
void internalSetRecord(Record* record);
|
||||||
RecordModels recordModels;
|
FilterProxyModels filterProxyModels;
|
||||||
RecordModelsHistory recordModelsHistory;
|
FilterProxyModelsHistory filterProxyModelsHistory;
|
||||||
QTableView* slotsTableView;
|
QTableView* slotsView;
|
||||||
|
QLineEdit* filterPatternLineEdit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue